[Gcblue-commits] gcb_wx/src/graphics tc3DTerrain.cpp,1.11,1.12 tcConsoleBox.cpp,1.4,1.5 tcEditBox.cp
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-05-14 23:37:17
|
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1674/src/graphics Modified Files: tc3DTerrain.cpp tcConsoleBox.cpp tcEditBox.cpp tcTerrainTextureFactory.cpp Log Message: Index: tcConsoleBox.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcConsoleBox.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcConsoleBox.cpp 9 May 2004 20:40:22 -0000 1.4 --- tcConsoleBox.cpp 14 May 2004 23:37:07 -0000 1.5 *************** *** 166,169 **** --- 166,170 ---- int width; int height; + int wrap = 50; current->Attribute("X", &x); *************** *** 171,178 **** --- 172,183 ---- current->Attribute("Width", &width); current->Attribute("Height", &height); + current->Attribute("Wrap", &wrap); SetSize(x, y, width, height); // set all size params nyzero = height - 20; + if (wrap < 10) wrap = 50; + SetWrap(wrap); + double fontSize; current->Attribute("FontSize", &fontSize); Index: tc3DTerrain.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DTerrain.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tc3DTerrain.cpp 11 Apr 2004 21:59:16 -0000 1.11 --- tc3DTerrain.cpp 14 May 2004 23:37:07 -0000 1.12 *************** *** 37,40 **** --- 37,41 ---- #include "tcMapData.h" #include "tcTerrainTextureFactory.h" + #include "tcTime.h" #ifdef _DEBUG *************** *** 83,90 **** } void tc3DTerrain::UpdateElevations() { wxASSERT(mapData); ! for(int i=0;i<GRID_DIM;i++) { --- 84,100 ---- } + /** + * Call every frame to support gradual terrain loading + */ + void tc3DTerrain::Update() + { + wxASSERT(texFactory); + if (texFactory) texFactory->Update(); + } + void tc3DTerrain::UpdateElevations() { wxASSERT(mapData); ! for(int i=0;i<GRID_DIM;i++) { *************** *** 100,109 **** } } texFactory->BuildTextures(); ! terrain->SetAllElevations(&elevationArray[0],GRID_DIM,GRID_DIM,gridSpacing); //terrain->SetMaximumVisibleBlockSize(64); } float tc3DTerrain::GetElevation(float x, float y) { --- 110,146 ---- } } + texFactory->BuildTextures(); ! terrain->SetAllElevations(&elevationArray[0], GRID_DIM, GRID_DIM, gridSpacing); ! unsigned t3 = tcTime::Get()->GetUpdated30HzCount(); ! //terrain->SetMaximumVisibleBlockSize(64); + } + void tc3DTerrain::UpdateElevationsSlowly() + { + wxASSERT(mapData); + /* + for(int i=0;i<GRID_DIM;i++) + { + float y = (float)i * gridSpacing + gridOffset; + float lat_deg = C_180OVERPI*YToLat(y); + for(int j=0;j<GRID_DIM;j++) + { + float x = (float)j * gridSpacing + gridOffset; + float lon_deg = C_180OVERPI*XToLon(x); + float height = mapData->GetTerrainHeight(lon_deg, lat_deg, gameTime); + long idx = i*GRID_DIM + j; + elevationArray[idx] = (height < 0) ? 0.001f*height : height; + } + } + texFactory->BuildTextures(); + terrain->SetAllElevations(&elevationArray[0],GRID_DIM,GRID_DIM,gridSpacing); + */ + //terrain->SetMaximumVisibleBlockSize(64); } + + float tc3DTerrain::GetElevation(float x, float y) { *************** *** 169,173 **** } ! tc3DTerrain::tc3DTerrain() { mapData = NULL; --- 206,213 ---- } ! tc3DTerrain::tc3DTerrain() : ! updateScheduled(false), ! updating(false), ! doGradualUpdate(true) { mapData = NULL; Index: tcTerrainTextureFactory.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcTerrainTextureFactory.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcTerrainTextureFactory.cpp 11 Apr 2004 22:18:19 -0000 1.7 --- tcTerrainTextureFactory.cpp 14 May 2004 23:37:07 -0000 1.8 *************** *** 48,62 **** #define USE_TERRAIN_TEXTURES ! //const float texelsPerMeter = 0.001f; ! //const float texelSpacing = 1.0f / texelsPerMeter; ! const float textureSize = 128.0f; ! const int textureSizeInt = 128; ! const float textureSizeMed = 64.0f; // medium resolution texture size ! const int textureSizeMedInt = 64; ! const float textureSizeLow = 32.0f; // low resolution texture size ! const int textureSizeLowInt = 32; ! void tcTerrainTextureFactory::BuildTextures() { float gridWidth = terrain->GetWidth(); float gridHeight = terrain->GetHeight(); --- 48,64 ---- #define USE_TERRAIN_TEXTURES ! /** ! * Create empty textures and update procedural texture data ! * if doGradualUpdate is true, set updateScheduled to true and ! * return instead. ! */ void tcTerrainTextureFactory::BuildTextures() { + if (doGradualUpdate) + { + updateScheduled = true; + return; + } + float gridWidth = terrain->GetWidth(); float gridHeight = terrain->GetHeight(); *************** *** 65,107 **** int nY = 0; ! const int edgeDepthLow = 2; ! const int edgeDepthMed = 3; for (float y = 0; y < gridHeight; y += gridStepY) { - bool edgeYLow = (nY < edgeDepthLow)||(nY >= gridDimension - edgeDepthLow); - bool edgeYMed = ((nY < edgeDepthMed)||(nY >= gridDimension - edgeDepthMed))&&(!edgeYLow); nY++; int nX = 0; for (float x = 0; x < gridWidth; x += gridStepX) { - bool edgeXLow = (nX < edgeDepthLow)||(nX >= gridDimension - edgeDepthLow); - bool edgeXMed = ((nX < edgeDepthMed)||(nX >= gridDimension - edgeDepthMed))&&(!edgeXLow); nX++; ! // select resolution for texture based on position of tile in grid ! int currentTextureSize; ! if (edgeXLow || edgeYLow) ! { ! currentTextureSize = textureSizeLowInt; ! } ! else if (edgeXMed || edgeYMed) ! { ! currentTextureSize = textureSizeMedInt; ! } ! else ! { ! currentTextureSize = textureSizeInt; ! } ! ! int cacheIdx = GetTextureIndex(x,y); Demeter::Texture* pTexture = m_Textures[cacheIdx]; // create a new texture if one doesn't exist ("lazy init") if (pTexture == NULL) { ! Uint8* pImage = new Uint8[currentTextureSize*currentTextureSize*3]; ! pTexture = new Demeter::Texture(pImage,currentTextureSize,currentTextureSize,currentTextureSize,0,true,false,false); ! pTexture->SetBufferPersistent(TRUE); ///< keeps tex in system memory for dynamic modification ! m_Textures[cacheIdx] = pTexture; ! delete pImage; //fprintf(stdout,"created tex:%d (x,y):(%.0f,%.0f)\n",cacheIdx,x,y); } --- 67,86 ---- int nY = 0; ! for (float y = 0; y < gridHeight; y += gridStepY) { nY++; int nX = 0; for (float x = 0; x < gridWidth; x += gridStepX) { nX++; ! int cacheIdx = GetTextureIndex(x, y); Demeter::Texture* pTexture = m_Textures[cacheIdx]; // create a new texture if one doesn't exist ("lazy init") if (pTexture == NULL) { ! m_Textures[cacheIdx] = CreateEmptyTexture(nX, nY); ! pTexture = m_Textures[cacheIdx]; //fprintf(stdout,"created tex:%d (x,y):(%.0f,%.0f)\n",cacheIdx,x,y); } *************** *** 113,116 **** --- 92,131 ---- } + + Demeter::Texture* tcTerrainTextureFactory::CreateEmptyTexture(int nX, int nY) + { + Demeter::Texture* pTexture; + + // determine position of texture tile in grid + bool edgeYLow = (nY < edgeDepthLow)||(nY >= gridDimension - edgeDepthLow); + bool edgeYMed = ((nY < edgeDepthMed)||(nY >= gridDimension - edgeDepthMed))&&(!edgeYLow); + + bool edgeXLow = (nX < edgeDepthLow)||(nX >= gridDimension - edgeDepthLow); + bool edgeXMed = ((nX < edgeDepthMed)||(nX >= gridDimension - edgeDepthMed))&&(!edgeXLow); + + // select resolution for texture based on position + int currentTextureSize; + if (edgeXLow || edgeYLow) + { + currentTextureSize = textureSizeLowInt; + } + else if (edgeXMed || edgeYMed) + { + currentTextureSize = textureSizeMedInt; + } + else + { + currentTextureSize = textureSizeInt; + } + + Uint8* pImage = new Uint8[currentTextureSize*currentTextureSize*3]; + pTexture = new Demeter::Texture(pImage,currentTextureSize,currentTextureSize,currentTextureSize,0,true,false,false); + pTexture->SetBufferPersistent(TRUE); ///< keeps tex in system memory for dynamic modification + delete pImage; + + return pTexture; + } + + void tcTerrainTextureFactory::FreeTextureCache() { *************** *** 168,172 **** // calculate alpha for each texture bool searching = true; ! int nTex = 0; for (nTex=0;(nTex<NUM_TEXTURES)&& searching;nTex++) { --- 183,187 ---- // calculate alpha for each texture bool searching = true; ! int nTex = 0; for (nTex=0;(nTex<NUM_TEXTURES)&& searching;nTex++) { *************** *** 203,207 **** blue += (int)floorf(alpha[nTex]*(float)textureInfo[nTex].texData[srcIndex+2]); } ! pImage[imageIndex] = red; pImage[imageIndex + 1] = green; --- 218,222 ---- blue += (int)floorf(alpha[nTex]*(float)textureInfo[nTex].texData[srcIndex+2]); } ! pImage[imageIndex] = red; pImage[imageIndex + 1] = green; *************** *** 365,369 **** else { ! return tex; } } --- 380,384 ---- else { ! return (updating) ? defaultTexture : tex; } } *************** *** 379,384 **** --- 394,465 ---- } + /** + * Update one grid square every time through + */ + void tcTerrainTextureFactory::Update() + { + if (updateScheduled) + { + updateX = 0; + updateY = 0; + updateScheduled = false; + updating = true; + } + + if (!updating) return; + + float gridWidth = terrain->GetWidth(); + float gridHeight = terrain->GetHeight(); + float gridStepX = gridWidth / (float)gridDimension; + float gridStepY = gridHeight / (float)gridDimension; + + if (updateY < gridHeight) + { + if (updateX < gridWidth) + { + int cacheIdx = GetTextureIndex(updateX, updateY); + Demeter::Texture* pTexture = m_Textures[cacheIdx]; + + // create a new texture if one doesn't exist ("lazy init") + if (pTexture == NULL) + { + int nX = (int)floorf((updateX / gridStepX) + 0.1f); + int nY = (int)floorf((updateY / gridStepY) + 0.1f); + + m_Textures[cacheIdx] = CreateEmptyTexture(nX, nY); + pTexture = m_Textures[cacheIdx]; + } + + UpdateTexture(pTexture, updateX, updateY, gridStepX, gridStepY); + + updateX += gridStepX; + } + else + { + updateX = 0; + updateY += gridStepY; + } + } + else + { + updating = false; + } + + + } + tcTerrainTextureFactory::tcTerrainTextureFactory(Demeter::Terrain* pTerrain, tc3DTerrain *tm, int griddimension) + : edgeDepthLow(2), + edgeDepthMed(3), + textureSize(128.0f), + textureSizeInt(128), + textureSizeMed(64.0f), + textureSizeMedInt(64), + textureSizeLow(32.0f), + textureSizeLowInt(32), + updateScheduled(false), + updating(false), + doGradualUpdate(true) { terrain = pTerrain; Index: tcEditBox.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcEditBox.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcEditBox.cpp 24 Mar 2004 21:09:26 -0000 1.4 --- tcEditBox.cpp 14 May 2004 23:37:07 -0000 1.5 *************** *** 88,92 **** SizeF size; MeasureText(graphics, font, mzBuffer, size); ! if (tcTime::Get30HzCount() % 30 >= 15) { pen->SetColor(Color(254,0,0,0)); --- 88,92 ---- SizeF size; MeasureText(graphics, font, mzBuffer, size); ! if (tcTime::Get()->Get30HzCount() % 30 >= 15) { pen->SetColor(Color(254,0,0,0)); |