From 8136dc084e9739d62f5b3c89c6cfe8ea2c9c9591 Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Fri, 14 Jun 2024 17:15:46 +0200 Subject: [PATCH] Revert "Possible approach for tile map rendering" This reverts commit b5f28dcab98c6aefc5ba7b3f705d88c0915ebb62. --- Source/Render/tilemap/TileMap.cpp | 45 +++++-------------- Source/Render/tilemap/TileMap.h | 53 +++++------------------ Source/Render/tilemap/TileMapBumpTile.cpp | 14 +++--- Source/Render/tilemap/TileMapBumpTile.h | 3 +- Source/Render/tilemap/TileMapRender.cpp | 51 +++++++++------------- Source/Render/tilemap/TileMapRender.h | 14 ------ 6 files changed, 51 insertions(+), 129 deletions(-) diff --git a/Source/Render/tilemap/TileMap.cpp b/Source/Render/tilemap/TileMap.cpp index efb0bc445..6255402ad 100644 --- a/Source/Render/tilemap/TileMap.cpp +++ b/Source/Render/tilemap/TileMap.cpp @@ -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); @@ -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() @@ -253,19 +250,10 @@ 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) @@ -273,7 +261,7 @@ 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)) @@ -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)) { diff --git a/Source/Render/tilemap/TileMap.h b/Source/Render/tilemap/TileMap.h index 6622ae5ba..890205f0e 100644 --- a/Source/Render/tilemap/TileMap.h +++ b/Source/Render/tilemap/TileMap.h @@ -1,8 +1,6 @@ #ifndef PERIMETER_TILEMAP_H #define PERIMETER_TILEMAP_H -#include - class cScene; typedef std::vector Vect2sVect; @@ -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* > CurrentRegion; @@ -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; @@ -71,7 +52,7 @@ class cTileMap : public cUnkObj Vect3d tilesize; - std::array pTileMapRender{}; + cTileMapRender* pTileMapRender = nullptr; cCamera* ShadowDrawNode; cCamera* LightDrawNode; @@ -136,23 +117,11 @@ class cTileMap : public cUnkObj zeroplast_color[player]=color; } - void SetTilemapRender(RenderType type, cTileMapRender* p) - { - const auto index = static_cast(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(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;} diff --git a/Source/Render/tilemap/TileMapBumpTile.cpp b/Source/Render/tilemap/TileMapBumpTile.cpp index b53655615..4047cc053 100644 --- a/Source/Render/tilemap/TileMapBumpTile.cpp +++ b/Source/Render/tilemap/TileMapBumpTile.cpp @@ -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(); @@ -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(); @@ -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(); @@ -69,7 +68,7 @@ uint8_t* sBumpTile::LockTex(int& Pitch) uint8_t *sBumpTile::LockVB() { - return static_cast(render->GetVertexPool()->LockPage(vtx)); + return static_cast(tilemap->GetTilemapRender()->GetVertexPool()->LockPage(vtx)); } void sBumpTile::UnlockTex() @@ -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) @@ -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(); diff --git a/Source/Render/tilemap/TileMapBumpTile.h b/Source/Render/tilemap/TileMapBumpTile.h index f4319b88b..744011195 100644 --- a/Source/Render/tilemap/TileMapBumpTile.h +++ b/Source/Render/tilemap/TileMapBumpTile.h @@ -51,7 +51,6 @@ struct sBumpTile int age, LOD; class cTileMap *tilemap; - cTileMapRender* render; class cTilemapTexturePool* texPool; int texPage = 0; @@ -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(); diff --git a/Source/Render/tilemap/TileMapRender.cpp b/Source/Render/tilemap/TileMapRender.cpp index 84c758c8f..ae40fc598 100644 --- a/Source/Render/tilemap/TileMapRender.cpp +++ b/Source/Render/tilemap/TileMapRender.cpp @@ -1,4 +1,3 @@ -#include #include "StdAfxRD.h" #include "PoolManager.h" #include "TileMap.h" @@ -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; @@ -49,8 +41,6 @@ cTileMapRender::cTileMapRender(cTileMap *pTileMap) for(int i=0;iGetTileNumber().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; } } @@ -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)) { @@ -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) @@ -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]) { @@ -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( @@ -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 считается всегда по отгошению к прямой камере для @@ -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); @@ -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]; @@ -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; diff --git a/Source/Render/tilemap/TileMapRender.h b/Source/Render/tilemap/TileMapRender.h index 518be7154..136990c1d 100644 --- a/Source/Render/tilemap/TileMapRender.h +++ b/Source/Render/tilemap/TileMapRender.h @@ -24,26 +24,12 @@ class cTileMapRender char* update_stat; bool update_in_frame; - struct sRenderTile final : public sAttribute - { - int bumpTileID = -1; - - 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); } - }; - std::vector renderTiles; - void SaveUpdateStat(); VectDelta* delta_buffer; std::vector> index_buffer; cTilemapTexturePool* FindFreeTexturePool(int tex_width, int tex_height); - sRenderTile& GetRenderTile(int i, int j) { return renderTiles[i + j*tilemap->GetTileNumber().x]; } public: void IncUpdate(sBumpTile* pbump);