Skip to content

Commit

Permalink
Revert "Possible approach for tile map rendering"
Browse files Browse the repository at this point in the history
This reverts commit b5f28dc.
  • Loading branch information
IonAgorria committed Jun 14, 2024
1 parent 23c3453 commit 8136dc0
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 129 deletions.
45 changes: 12 additions & 33 deletions Source/Render/tilemap/TileMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ cTileMap::cTileMap(cScene* pScene,TerraInterface* terra_) : cUnkObj(KIND_TILEMAP
TexturePoolSize = 512;

tilesize.set(0,0,0);
pTileMapRender=NULL;

ShadowDrawNode=pScene->CreateCamera();
LightDrawNode=new cCameraPlanarLight(pScene);
Expand All @@ -198,11 +199,7 @@ cTileMap::~cTileMap()
gb_RenderDevice->DeleteTilemap(this);
if(Tile) { delete [] Tile; Tile=nullptr; }
MTDONE(lock_update_rect);

for (auto& p : pTileMapRender)
{
xassert(p == nullptr);
}
xassert(pTileMapRender == nullptr);
}

int cTileMap::CheckLightMapType()
Expand Down Expand Up @@ -253,27 +250,18 @@ void cTileMap::PreDraw(cCamera *DrawNode)

DrawNode->Attach(SCENENODE_OBJECT_TILEMAP,this);

for (auto& render : pTileMapRender)
{
if (render) {
render->PreDraw(DrawNode);
}
}

for (int y=0; y < GetTileNumber().y; y++) {
for (int x = 0; x < GetTileNumber().x; x++) {
auto& Tile = GetTile(x, y);
Tile.ClearAttribute(ATTRTILE_UPDATELOD);
}
}
cTileMapRender* render = GetTilemapRender();
if (render) {
render->PreDraw(DrawNode);
}
}

void cTileMap::Draw(cCamera *DrawNode)
{
if(!Option_ShowType[SHOW_TILEMAP])
return;

cTileMapRender* render = GetTilemapRender(RenderType::DIRECT);
cTileMapRender* render = GetTilemapRender();
if (!render) return;

if(DrawNode->GetAttribute(ATTRCAMERA_SHADOW))
Expand All @@ -283,23 +271,14 @@ void cTileMap::Draw(cCamera *DrawNode)
else if(DrawNode->GetAttribute(ATTRCAMERA_SHADOWMAP))
{
if(Option_ShadowType==SHADOW_MAP_SELF) {
cTileMapRender* shadowRender = GetTilemapRender(RenderType::SHADOW);
if (shadowRender)
{
shadowRender->DrawBump(DrawNode, ALPHA_TEST, TILEMAP_ALL, true);
}
render->DrawBump(DrawNode, ALPHA_TEST, TILEMAP_ALL, true);
}
}
else if(DrawNode->GetAttribute(ATTRCAMERA_REFLECTION))
{
// рисовать отражение
cTileMapRender* reflectionRender = GetTilemapRender(RenderType::REFLECTION);
if (reflectionRender)
{
gb_RenderDevice->SetRenderState(RS_ALPHA_TEST_MODE, ALPHATEST_GT_254/*GetRefSurface()*/);
reflectionRender->DrawBump(DrawNode, ALPHA_TEST, TILEMAP_NOZEROPLAST, false);
gb_RenderDevice->SetRenderState(RS_ALPHA_TEST_MODE, ALPHATEST_GT_0);
}
{ // рисовать отражение
gb_RenderDevice->SetRenderState(RS_ALPHA_TEST_MODE, ALPHATEST_GT_254/*GetRefSurface()*/);
render->DrawBump(DrawNode, ALPHA_TEST, TILEMAP_NOZEROPLAST, false);
gb_RenderDevice->SetRenderState(RS_ALPHA_TEST_MODE, ALPHATEST_GT_0);
}else
{
if(GetAttribute(ATTRUNKOBJ_REFLECTION)) {
Expand Down
53 changes: 11 additions & 42 deletions Source/Render/tilemap/TileMap.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef PERIMETER_TILEMAP_H
#define PERIMETER_TILEMAP_H

#include <array>

class cScene;

typedef std::vector<Vect2s> Vect2sVect;
Expand Down Expand Up @@ -30,7 +28,12 @@ struct sTile : public sAttribute
zmin=255;zmax=0;
}

inline int GetDraw() { return GetAttribute(ATTRTILE_DRAWLOD); }
inline int GetUpdate() { return GetAttribute(ATTRTILE_UPDATELOD); }
inline void SetDraw() { SetAttribute(ATTRTILE_DRAWLOD); }

inline void ClearDraw() { ClearAttribute(ATTRTILE_DRAWLOD); }
inline void ClearUpdate() { ClearAttribute(ATTRTILE_UPDATELOD); }
};

typedef std::vector<std::vector<Vect2s>* > CurrentRegion;
Expand All @@ -40,28 +43,6 @@ class cTileMapRender;
class Column;
class cTileMap : public cUnkObj
{
public:
#ifdef PERIMETER_SOKOL
enum class RenderType
{
REFLECTION, SHADOW, DIRECT
};
static inline const std::array RenderTypes{
RenderType::REFLECTION,
RenderType::SHADOW,
RenderType::DIRECT
};
#else
enum class RenderType
{
DIRECT
};
static inline const std::array RenderTypes{
RenderType::DIRECT
};
#endif

private:
friend class cScene;

sTile* Tile;
Expand All @@ -71,7 +52,7 @@ class cTileMap : public cUnkObj

Vect3d tilesize;

std::array<cTileMapRender*, RenderTypes.size()> pTileMapRender{};
cTileMapRender* pTileMapRender = nullptr;

cCamera* ShadowDrawNode;
cCamera* LightDrawNode;
Expand Down Expand Up @@ -136,23 +117,11 @@ class cTileMap : public cUnkObj
zeroplast_color[player]=color;
}

void SetTilemapRender(RenderType type, cTileMapRender* p)
{
const auto index = static_cast<size_t>(type);
VISASSERT(index < pTileMapRender.size());
VISASSERT(p == nullptr || pTileMapRender[index] == nullptr);
pTileMapRender[index] = p;
};
cTileMapRender* GetTilemapRender(RenderType type)
{
#ifdef PERIMETER_SOKOL
const auto index = static_cast<size_t>(type);
VISASSERT(index < pTileMapRender.size());
return pTileMapRender[index];
#else
return pTileMapRender[0];
#endif
}
void SetTilemapRender(cTileMapRender* p) {
VISASSERT(p == nullptr || pTileMapRender == nullptr);
pTileMapRender=p;
};
cTileMapRender* GetTilemapRender(){return pTileMapRender;}

TerraInterface* GetTerra(){return terra;}

Expand Down
14 changes: 7 additions & 7 deletions Source/Render/tilemap/TileMapBumpTile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ float sBumpTile::SetVertexZ(TerraInterface* terra,int x,int y)
return zi;
}

sBumpTile::sBumpTile(cTileMap* tilemap, cTileMapRender* render, cTilemapTexturePool* pool, int lod, int xpos, int ypos)
sBumpTile::sBumpTile(cTileMap* tilemap, cTilemapTexturePool* pool, int lod, int xpos, int ypos)
{
this->tilemap = tilemap;
this->render = render;

cTileMapRender* render = tilemap->GetTilemapRender();
tile_pos.set(xpos,ypos);
texPool = pool;
texPage = texPool->allocPage();
Expand All @@ -46,7 +45,7 @@ sBumpTile::sBumpTile(cTileMap* tilemap, cTileMapRender* render, cTilemapTexture

sBumpTile::~sBumpTile()
{
render->GetVertexPool()->DeletePage(vtx);
tilemap->GetTilemapRender()->GetVertexPool()->DeletePage(vtx);
texPool->freePage(texPage);

DeleteIndex();
Expand All @@ -56,7 +55,7 @@ void sBumpTile::DeleteIndex()
{
for (auto& i : index) {
if (i.index.page >= 0) {
render->GetIndexPool()->DeletePage(i.index);
tilemap->GetTilemapRender()->GetIndexPool()->DeletePage(i.index);
}
}
index.clear();
Expand All @@ -69,7 +68,7 @@ uint8_t* sBumpTile::LockTex(int& Pitch)

uint8_t *sBumpTile::LockVB()
{
return static_cast<uint8_t*>(render->GetVertexPool()->LockPage(vtx));
return static_cast<uint8_t*>(tilemap->GetTilemapRender()->GetVertexPool()->LockPage(vtx));
}

void sBumpTile::UnlockTex()
Expand All @@ -79,7 +78,7 @@ void sBumpTile::UnlockTex()

void sBumpTile::UnlockVB()
{
render->GetVertexPool()->UnlockPage(vtx);
tilemap->GetTilemapRender()->GetVertexPool()->UnlockPage(vtx);
}

inline int IUCLAMP(int val,int clamp)
Expand Down Expand Up @@ -128,6 +127,7 @@ void sBumpTile::CalcPoint()
Column** columns = tilemap->GetColumn();
Vect2i pos=tile_pos;

cTileMapRender* render = tilemap->GetTilemapRender();
render->IncUpdate(this);

int tilenumber = tilemap->GetZeroplastNumber();
Expand Down
3 changes: 1 addition & 2 deletions Source/Render/tilemap/TileMapBumpTile.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ struct sBumpTile
int age, LOD;

class cTileMap *tilemap;
cTileMapRender* render;
class cTilemapTexturePool* texPool;
int texPage = 0;

Expand All @@ -71,7 +70,7 @@ struct sBumpTile
protected:
float vStart, vStep, uStart, uStep;
public:
sBumpTile(cTileMap* TileMap, cTileMapRender* render, cTilemapTexturePool* pool, int lod, int xpos, int ypos);
sBumpTile(cTileMap* TileMap, cTilemapTexturePool* pool, int lod, int xpos, int ypos);
~sBumpTile();
uint8_t* LockTex(int& Pitch);
uint8_t* LockVB();
Expand Down
51 changes: 20 additions & 31 deletions Source/Render/tilemap/TileMapRender.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <array>
#include "StdAfxRD.h"
#include "PoolManager.h"
#include "TileMap.h"
Expand All @@ -13,27 +12,20 @@

int cInterfaceRenderDevice::CreateTilemap(cTileMap *TileMap)
{
for (auto type : cTileMap::RenderTypes)
{
cTileMapRender* p = new cTileMapRender(TileMap);
TileMap->SetTilemapRender(type, p);
p->RestoreTilemapPool();
}

cTileMapRender* p = new cTileMapRender(TileMap);
TileMap->SetTilemapRender(p);
p->RestoreTilemapPool();
return 0;
}

int cInterfaceRenderDevice::DeleteTilemap(cTileMap *TileMap)
{
for (auto type : cTileMap::RenderTypes)
{
cTileMapRender* p = TileMap->GetTilemapRender(type);
cTileMapRender* p = TileMap->GetTilemapRender();

if (p) {
p->ClearTilemapPool();
TileMap->SetTilemapRender(type, nullptr);
delete p;
}
if (p) {
p->ClearTilemapPool();
TileMap->SetTilemapRender(nullptr);
delete p;
}

return true;
Expand All @@ -49,8 +41,6 @@ cTileMapRender::cTileMapRender(cTileMap *pTileMap)
for(int i=0;i<dxy;i++)
vis_lod[i]=-1;

renderTiles.resize(dxy);

update_stat=NULL;
// update_stat=new char[dxy*TILEMAP_LOD];
update_in_frame=false;
Expand All @@ -74,8 +64,9 @@ void cTileMapRender::ClearTilemapPool()
{
for (int y=0; y < tilemap->GetTileNumber().y; y++) {
for (int x = 0; x < tilemap->GetTileNumber().x; x++) {
auto& Tile = GetRenderTile(x, y);
Tile.bumpTileID = -1;
sTile& Tile = tilemap->GetTile(x, y);
int& bumpTileID = Tile.bumpTileID;
bumpTileID = -1;
}
}

Expand Down Expand Up @@ -162,7 +153,7 @@ void cTileMapRender::PreDraw(cCamera* DrawNode)
for(int y=0; y < tilemap->GetTileNumber().y; y++)
for(int x=0; x < tilemap->GetTileNumber().x; x++)
{
sRenderTile &Tile = GetRenderTile(x, y);
sTile &Tile = tilemap->GetTile(x, y);
int &bumpTileID = Tile.bumpTileID;
if(!Tile.GetAttribute(ATTRTILE_DRAWLOD))
{
Expand All @@ -171,10 +162,6 @@ void cTileMapRender::PreDraw(cCamera* DrawNode)
}

Tile.ClearAttribute(ATTRTILE_DRAWLOD);

if (tilemap->GetTile(x, y).GetAttribute(ATTRTILE_UPDATELOD)) {
Tile.SetAttribute(ATTRTILE_UPDATELOD);
}
}

if(update_stat)
Expand Down Expand Up @@ -231,7 +218,7 @@ int cTileMapRender::bumpTileAlloc(int lod,int xpos,int ypos)
int w = tilemap->GetTileSize().x >> bumpTexScale[lod];
int h = tilemap->GetTileSize().y >> bumpTexScale[lod];
cTilemapTexturePool* pool = FindFreeTexturePool(w, h);
sBumpTile* tile = new sBumpTile(tilemap, this, pool, lod, xpos, ypos);
sBumpTile* tile = new sBumpTile(tilemap, pool, lod, xpos, ypos);
int i;
for (i = 0; i < bumpTiles.size(); i++) {
if (!bumpTiles[i]) {
Expand Down Expand Up @@ -323,6 +310,7 @@ void cTileMapRender::DrawBump(cCamera* DrawNode,eBlendMode MatMode,TILEMAP_DRAW
cCamera* pShadowMapCamera=DrawNode->FindCildCamera(ATTRCAMERA_SHADOWMAP);
int reflection = DrawNode->GetAttribute(ATTRCAMERA_REFLECTION);
cCamera* pNormalCamera=DrawNode->GetRoot();
cTileMapRender* render=tilemap->GetTilemapRender();
bool use_shadow_map=false;

Vect3f dcoord(
Expand Down Expand Up @@ -460,7 +448,7 @@ void cTileMapRender::DrawBump(cCamera* DrawNode,eBlendMode MatMode,TILEMAP_DRAW
/**/
{
// process visible tile
sRenderTile &Tile = GetRenderTile(k, n);
sTile &Tile = tilemap->GetTile(k, n);
int &bumpTileID = Tile.bumpTileID;

// calc LOD считается всегда по отгошению к прямой камере для
Expand All @@ -473,7 +461,8 @@ void cTileMapRender::DrawBump(cCamera* DrawNode,eBlendMode MatMode,TILEMAP_DRAW
vis_lod[k+n*dk]=iLod;

// create/update render tile
if (bumpTileValid(bumpTileID) && bumpTiles[bumpTileID]->LOD != iLod && !shadow)
if (render->bumpTileValid(bumpTileID)
&& render->bumpTiles[bumpTileID]->LOD != iLod && !shadow)
{
// LOD changed, free old tile and allocate new
bumpTileFree(bumpTileID);
Expand Down Expand Up @@ -515,7 +504,7 @@ void cTileMapRender::DrawBump(cCamera* DrawNode,eBlendMode MatMode,TILEMAP_DRAW
for (n = 0; n < dn; n++)
for (k = 0; k < dk; k++)
{
sRenderTile &Tile = GetRenderTile(k, n);
sTile &Tile = tilemap->GetTile(k, n);
int bumpTileID = Tile.bumpTileID;
if(bumpTileID<0)continue;
sBumpTile *bumpTile = bumpTiles[bumpTileID];
Expand Down Expand Up @@ -597,8 +586,8 @@ void cTileMapRender::DrawBump(cCamera* DrawNode,eBlendMode MatMode,TILEMAP_DRAW
int nTiles = 0;
VertexBuffer* lastVB = nullptr;
#endif
VertexPoolManager* vtxPoolMan = GetVertexPool();
IndexPoolManager* idxPoolMan = GetIndexPool();
VertexPoolManager* vtxPoolMan = render->GetVertexPool();
IndexPoolManager* idxPoolMan = render->GetIndexPool();
for (cTilemapTexturePool* curpool : bumpTexPools) {
if (curpool->tileRenderList.empty()) {
continue;
Expand Down
Loading

0 comments on commit 8136dc0

Please sign in to comment.