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* 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)
|
if(t)
|
||||||
{
|
{
|
||||||
|
tileEffects.assignEffect(*t, effidx);
|
||||||
TileStorage& ts = tilestore[layer];
|
TileStorage& ts = tilestore[layer];
|
||||||
ts.refreshAll();
|
ts.refreshAll();
|
||||||
}
|
}
|
||||||
|
@ -115,7 +116,7 @@ void TileMgr::createTiles(const TileDef* defs, size_t n)
|
||||||
for(size_t i = 0; i < n; ++i)
|
for(size_t i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
const TileDef& d = defs[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)
|
if(t)
|
||||||
{
|
{
|
||||||
used[d.layer] = 1;
|
used[d.layer] = 1;
|
||||||
|
@ -130,9 +131,10 @@ void TileMgr::createTiles(const TileDef* defs, size_t n)
|
||||||
t->scalex = d.sx;
|
t->scalex = d.sx;
|
||||||
t->scaley = d.sy;
|
t->scaley = d.sy;
|
||||||
|
|
||||||
// must be done last
|
|
||||||
if(d.repeat)
|
if(d.repeat)
|
||||||
t->setRepeatOn(d.rsx, d.rsy);
|
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))
|
if(layer >= Countof(tilestore))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -186,14 +188,11 @@ TileData* TileMgr::_createTile(unsigned tilesetID, unsigned layer, float x, flo
|
||||||
t.rotation = 0;
|
t.rotation = 0;
|
||||||
t.scalex = 1;
|
t.scalex = 1;
|
||||||
t.scaley = 1;
|
t.scaley = 1;
|
||||||
//t.beforeScaleOffsetX = 0;
|
|
||||||
//t.beforeScaleOffsetY = 0;
|
|
||||||
t.flags = GetTileFlags(ef);
|
t.flags = GetTileFlags(ef);
|
||||||
t.tag = 0;
|
t.tag = 0;
|
||||||
t.rep = NULL;
|
t.rep = NULL;
|
||||||
t.et = tileset.getByIdx(tilesetID);
|
t.et = tileset.getByIdx(tilesetID);
|
||||||
assert(t.et);
|
assert(t.et);
|
||||||
/* t.eff = */ tileEffects.assignEffect(t, effidx);
|
|
||||||
|
|
||||||
TileStorage& ts = tilestore[layer];
|
TileStorage& ts = tilestore[layer];
|
||||||
ts.tiles.push_back(t);
|
ts.tiles.push_back(t);
|
||||||
|
|
|
@ -76,7 +76,7 @@ public:
|
||||||
static ElementFlag GetElementFlag(TileFlags tf);
|
static ElementFlag GetElementFlag(TileFlags tf);
|
||||||
|
|
||||||
private:
|
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
|
TileMgr(const TileMgr&); // no-copy
|
||||||
};
|
};
|
||||||
|
|
|
@ -333,10 +333,25 @@ 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)
|
if(ownGrid)
|
||||||
|
{
|
||||||
|
ownGrid = false;
|
||||||
delete grid;
|
delete grid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TileEffectData::~TileEffectData()
|
||||||
|
{
|
||||||
|
deleteGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicRenderGrid *TileEffectData::_ensureGrid(size_t w, size_t h, const TileData *t)
|
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)
|
if(t && t->rep)
|
||||||
{
|
{
|
||||||
assert(!shared); // a shared instance MUST have its own grid and MUST NOT refer to the grid of any tile
|
assert(!shared); // a shared instance MUST have its own grid and MUST NOT refer to the grid of any tile
|
||||||
if(ownGrid)
|
deleteGrid();
|
||||||
delete g;
|
|
||||||
g = &t->rep->grid;
|
g = &t->rep->grid;
|
||||||
ownGrid = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!g)
|
if(!g)
|
||||||
|
@ -613,7 +626,7 @@ TexCoordBox TileRepeatData::calcTexCoords(const TileData& t) const
|
||||||
tc.u2 = (et.w*t.scalex*texscaleX)/tw + texOffX;
|
tc.u2 = (et.w*t.scalex*texscaleX)/tw + texOffX;
|
||||||
tc.v2 = (et.h*t.scaley*texscaleY)/th + texOffY;
|
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.
|
// 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.
|
// 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.
|
// 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->texOffY = offy;
|
||||||
rep->refresh(*this);
|
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;
|
return rep;
|
||||||
}
|
}
|
||||||
|
@ -693,12 +723,12 @@ const TexCoordBox& TileData::getTexcoords() const
|
||||||
|
|
||||||
const RenderGrid *TileData::getGrid() 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)
|
if(flags & TILEFLAG_REPEAT)
|
||||||
return &rep->getGrid();
|
return &rep->getGrid();
|
||||||
|
|
||||||
if(eff && eff->grid)
|
|
||||||
return eff->grid;
|
|
||||||
|
|
||||||
return et->grid;
|
return et->grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,10 +112,13 @@ enum TileFlags
|
||||||
|
|
||||||
struct TileEffectData
|
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(const TileEffectConfig& cfg, const TileData *t); // NULL is passed in during global prepare, when we don't have a tile
|
||||||
~TileEffectData();
|
~TileEffectData();
|
||||||
void update(float dt, const TileData *t); // optional t needed for EFX_WAVY
|
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 doInteraction(const TileData& t, const Vector& pos, const Vector& vel, float mult, float touchWidth);
|
||||||
|
void deleteGrid();
|
||||||
|
|
||||||
const EFXType efxtype;
|
const EFXType efxtype;
|
||||||
const unsigned efxidx; // index of TileEffect
|
const unsigned efxidx; // index of TileEffect
|
||||||
|
@ -138,8 +141,8 @@ struct TileEffectData
|
||||||
Wavy wavy;
|
Wavy wavy;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
TileEffectData(const TileEffectData&); // internal use only
|
||||||
DynamicRenderGrid *_ensureGrid(size_t w, size_t h, const TileData *t);
|
DynamicRenderGrid *_ensureGrid(size_t w, size_t h, const TileData *t);
|
||||||
TileEffectData(const TileEffectData&); // no-copy
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TileRepeatData
|
struct TileRepeatData
|
||||||
|
|
Loading…
Add table
Reference in a new issue