mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-03 18:14:01 +00:00
tile repeat with grid effects works again
This commit is contained in:
parent
f9a91e87e4
commit
7e040ea354
4 changed files with 50 additions and 18 deletions
|
@ -100,9 +100,10 @@ void TileMgr::doTileInteraction(const Vector& pos, const Vector& vel, float mult
|
|||
|
||||
TileData* TileMgr::createOneTile(unsigned tilesetID, unsigned layer, float x, float y, ElementFlag ef, int effidx)
|
||||
{
|
||||
TileData *t = _createTile(tilesetID, layer, x, y, ef, effidx);
|
||||
TileData *t = _createTile(tilesetID, layer, x, y, ef);
|
||||
if(t)
|
||||
{
|
||||
tileEffects.assignEffect(*t, effidx);
|
||||
TileStorage& ts = tilestore[layer];
|
||||
ts.refreshAll();
|
||||
}
|
||||
|
@ -115,7 +116,7 @@ void TileMgr::createTiles(const TileDef* defs, size_t n)
|
|||
for(size_t i = 0; i < n; ++i)
|
||||
{
|
||||
const TileDef& d = defs[i];
|
||||
TileData *t = _createTile(d.idx, d.layer, d.x, d.y, (ElementFlag)d.ef, d.efxIdx);
|
||||
TileData *t = _createTile(d.idx, d.layer, d.x, d.y, (ElementFlag)d.ef);
|
||||
if(t)
|
||||
{
|
||||
used[d.layer] = 1;
|
||||
|
@ -130,9 +131,10 @@ void TileMgr::createTiles(const TileDef* defs, size_t n)
|
|||
t->scalex = d.sx;
|
||||
t->scaley = d.sy;
|
||||
|
||||
// must be done last
|
||||
if(d.repeat)
|
||||
t->setRepeatOn(d.rsx, d.rsy);
|
||||
|
||||
tileEffects.assignEffect(*t, d.efxIdx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +177,7 @@ void TileMgr::exportGridFillers(std::vector<GridFiller>& fillers) const
|
|||
}
|
||||
}
|
||||
|
||||
TileData* TileMgr::_createTile(unsigned tilesetID, unsigned layer, float x, float y, ElementFlag ef, int effidx)
|
||||
TileData* TileMgr::_createTile(unsigned tilesetID, unsigned layer, float x, float y, ElementFlag ef)
|
||||
{
|
||||
if(layer >= Countof(tilestore))
|
||||
return NULL;
|
||||
|
@ -186,14 +188,11 @@ TileData* TileMgr::_createTile(unsigned tilesetID, unsigned layer, float x, flo
|
|||
t.rotation = 0;
|
||||
t.scalex = 1;
|
||||
t.scaley = 1;
|
||||
//t.beforeScaleOffsetX = 0;
|
||||
//t.beforeScaleOffsetY = 0;
|
||||
t.flags = GetTileFlags(ef);
|
||||
t.tag = 0;
|
||||
t.rep = NULL;
|
||||
t.et = tileset.getByIdx(tilesetID);
|
||||
assert(t.et);
|
||||
/* t.eff = */ tileEffects.assignEffect(t, effidx);
|
||||
|
||||
TileStorage& ts = tilestore[layer];
|
||||
ts.tiles.push_back(t);
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
static ElementFlag GetElementFlag(TileFlags tf);
|
||||
|
||||
private:
|
||||
TileData *_createTile(unsigned tilesetID, unsigned layer, float x, float y, ElementFlag ef = EF_NONE, int effidx = -1);
|
||||
TileData *_createTile(unsigned tilesetID, unsigned layer, float x, float y, ElementFlag ef = EF_NONE);
|
||||
|
||||
TileMgr(const TileMgr&); // no-copy
|
||||
};
|
||||
|
|
|
@ -333,11 +333,26 @@ TileEffectData::TileEffectData(const TileEffectConfig& cfg, const TileData *t)
|
|||
}
|
||||
}
|
||||
|
||||
TileEffectData::~TileEffectData()
|
||||
TileEffectData::TileEffectData(const TileEffectData& o)
|
||||
: efxtype(o.efxtype), efxidx(o.efxidx), grid(NULL)
|
||||
, alpha(o.alpha), blend(o.blend)
|
||||
, ownGrid(false), shared(false), wavy(o.wavy)
|
||||
{
|
||||
}
|
||||
|
||||
void TileEffectData::deleteGrid()
|
||||
{
|
||||
if(ownGrid)
|
||||
{
|
||||
ownGrid = false;
|
||||
delete grid;
|
||||
}
|
||||
}
|
||||
|
||||
TileEffectData::~TileEffectData()
|
||||
{
|
||||
deleteGrid();
|
||||
}
|
||||
|
||||
DynamicRenderGrid *TileEffectData::_ensureGrid(size_t w, size_t h, const TileData *t)
|
||||
{
|
||||
|
@ -351,10 +366,8 @@ DynamicRenderGrid *TileEffectData::_ensureGrid(size_t w, size_t h, const TileDat
|
|||
if(t && t->rep)
|
||||
{
|
||||
assert(!shared); // a shared instance MUST have its own grid and MUST NOT refer to the grid of any tile
|
||||
if(ownGrid)
|
||||
delete g;
|
||||
deleteGrid();
|
||||
g = &t->rep->grid;
|
||||
ownGrid = false;
|
||||
}
|
||||
|
||||
if(!g)
|
||||
|
@ -613,7 +626,7 @@ TexCoordBox TileRepeatData::calcTexCoords(const TileData& t) const
|
|||
tc.u2 = (et.w*t.scalex*texscaleX)/tw + texOffX;
|
||||
tc.v2 = (et.h*t.scaley*texscaleY)/th + texOffY;
|
||||
|
||||
// HACK: partially repeated textures have a weird Y axis. assuming a repeat factor of 0.5,
|
||||
// HACK: partially repeated textures have a weird Y axis. assuming a repeat factor of 0.4,
|
||||
// instead of texcoords from 0 -> 0.4 everything is biased towards the opposite end, ie. 0.6 -> 1.
|
||||
// This is especially true for partial repeats, we always need to bias towards the other end.
|
||||
// I have no idea why this has to be like this for tiles, but this is NOT the case for fonts.
|
||||
|
@ -658,7 +671,24 @@ TileRepeatData* TileData::setRepeatOn(float texscalex, float texscaley, float of
|
|||
rep->texOffY = offy;
|
||||
rep->refresh(*this);
|
||||
|
||||
// FIXME: if eff, link eff->grid to rep->grid
|
||||
// link eff->grid to rep->grid. create own instance if necessary.
|
||||
/*if(eff)
|
||||
{
|
||||
const unsigned char gridtype = eff->grid ? eff->grid->gridType : GRID_UNDEFINED;
|
||||
if(flags & TILEFLAG_OWN_EFFDATA)
|
||||
{
|
||||
assert(!eff->shared);
|
||||
eff->deleteGrid();
|
||||
}
|
||||
else
|
||||
{
|
||||
eff = new TileEffectData(*eff);
|
||||
flags |= TILEFLAG_OWN_EFFDATA;
|
||||
}
|
||||
assert(!eff->ownGrid);
|
||||
eff->grid = &rep->grid;
|
||||
eff->grid->gridType = gridtype;
|
||||
}*/
|
||||
|
||||
return rep;
|
||||
}
|
||||
|
@ -693,12 +723,12 @@ const TexCoordBox& TileData::getTexcoords() const
|
|||
|
||||
const RenderGrid *TileData::getGrid() const
|
||||
{
|
||||
if(eff && eff->grid)
|
||||
return eff->grid; // this points to rep.grid if eff is present and repeat is on
|
||||
|
||||
if(flags & TILEFLAG_REPEAT)
|
||||
return &rep->getGrid();
|
||||
|
||||
if(eff && eff->grid)
|
||||
return eff->grid;
|
||||
|
||||
return et->grid;
|
||||
}
|
||||
|
||||
|
|
|
@ -112,10 +112,13 @@ enum TileFlags
|
|||
|
||||
struct TileEffectData
|
||||
{
|
||||
friend struct TileData;
|
||||
|
||||
TileEffectData(const TileEffectConfig& cfg, const TileData *t); // NULL is passed in during global prepare, when we don't have a tile
|
||||
~TileEffectData();
|
||||
void update(float dt, const TileData *t); // optional t needed for EFX_WAVY
|
||||
void doInteraction(const TileData& t, const Vector& pos, const Vector& vel, float mult, float touchWidth);
|
||||
void deleteGrid();
|
||||
|
||||
const EFXType efxtype;
|
||||
const unsigned efxidx; // index of TileEffect
|
||||
|
@ -138,8 +141,8 @@ struct TileEffectData
|
|||
Wavy wavy;
|
||||
|
||||
private:
|
||||
TileEffectData(const TileEffectData&); // internal use only
|
||||
DynamicRenderGrid *_ensureGrid(size_t w, size_t h, const TileData *t);
|
||||
TileEffectData(const TileEffectData&); // no-copy
|
||||
};
|
||||
|
||||
struct TileRepeatData
|
||||
|
|
Loading…
Add table
Reference in a new issue