From b668f7faab737a77051abb0b9a539aeaa0a126b7 Mon Sep 17 00:00:00 2001 From: oy Date: Tue, 18 Feb 2014 18:02:42 +0100 Subject: [PATCH] some cleanup --- src/engine/client/graphics_threaded.cpp | 10 ++-- src/engine/client/graphics_threaded.h | 4 +- src/engine/graphics.h | 4 +- src/game/client/components/maplayers.cpp | 4 +- src/game/client/render.h | 2 +- src/game/client/render_map.cpp | 59 ++++-------------------- src/game/editor/editor.cpp | 14 ++---- src/game/editor/editor.h | 2 +- src/game/editor/io.cpp | 4 +- src/game/editor/layer_tiles.cpp | 4 +- 10 files changed, 32 insertions(+), 75 deletions(-) diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 3ecdc18ea..f50d5b92f 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -504,7 +504,7 @@ void CGraphics_Threaded::QuadsBegin() dbg_assert(m_Drawing == 0, "called Graphics()->QuadsBegin twice"); m_Drawing = DRAWING_QUADS; - QuadsSetSubset(0,0,1,1,0); + QuadsSetSubset(0,0,1,1,-1); QuadsSetRotation(0); SetColor(1,1,1,1); } @@ -557,7 +557,7 @@ void CGraphics_Threaded::SetColor4(vec4 TopLeft, vec4 TopRight, vec4 BottomLeft, SetColorVertex(Array, 4); } -void CGraphics_Threaded::QuadsSetSubset(float TlU, float TlV, float BrU, float BrV, int TextureIndex, bool Use3DTexture) +void CGraphics_Threaded::QuadsSetSubset(float TlU, float TlV, float BrU, float BrV, int TextureIndex) { dbg_assert(m_Drawing == DRAWING_QUADS, "called Graphics()->QuadsSetSubset without begin"); @@ -568,12 +568,12 @@ void CGraphics_Threaded::QuadsSetSubset(float TlU, float TlV, float BrU, float B m_aTexture[3].v = BrV; m_aTexture[2].v = BrV; m_aTexture[0].i = m_aTexture[1].i = m_aTexture[2].i = m_aTexture[3].i = (0.5f + TextureIndex) / 256.0f; - m_State.m_Dimension = Use3DTexture ? 3 : 2; + m_State.m_Dimension = (TextureIndex < 0) ? 2 : 3; } void CGraphics_Threaded::QuadsSetSubsetFree( float x0, float y0, float x1, float y1, - float x2, float y2, float x3, float y3, int TextureIndex, bool Use3DTexture) + float x2, float y2, float x3, float y3, int TextureIndex) { m_aTexture[0].u = x0; m_aTexture[0].v = y0; m_aTexture[1].u = x1; m_aTexture[1].v = y1; @@ -581,7 +581,7 @@ void CGraphics_Threaded::QuadsSetSubsetFree( m_aTexture[3].u = x3; m_aTexture[3].v = y3; m_aTexture[0].i = m_aTexture[1].i = m_aTexture[2].i = m_aTexture[3].i = (0.5f + TextureIndex) / 256.0f; - m_State.m_Dimension = Use3DTexture ? 3 : 2; + m_State.m_Dimension = (TextureIndex < 0) ? 2 : 3; } void CGraphics_Threaded::QuadsDraw(CQuadItem *pArray, int Num) diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index 708093423..54d3c60cb 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -415,10 +415,10 @@ public: virtual void SetColor(float r, float g, float b, float a); virtual void SetColor4(vec4 TopLeft, vec4 TopRight, vec4 BottomLeft, vec4 BottomRight); - virtual void QuadsSetSubset(float TlU, float TlV, float BrU, float BrV, int TextureIndex = 0, bool Use3DTexture = false); + virtual void QuadsSetSubset(float TlU, float TlV, float BrU, float BrV, int TextureIndex = -1); virtual void QuadsSetSubsetFree( float x0, float y0, float x1, float y1, - float x2, float y2, float x3, float y3, int TextureIndex = 0, bool Use3DTexture = false); + float x2, float y2, float x3, float y3, int TextureIndex = -1); virtual void QuadsDraw(CQuadItem *pArray, int Num); virtual void QuadsDrawTL(const CQuadItem *pArray, int Num); diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 1c6c389b6..4c16de01c 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -124,8 +124,8 @@ public: virtual void QuadsBegin() = 0; virtual void QuadsEnd() = 0; virtual void QuadsSetRotation(float Angle) = 0; - virtual void QuadsSetSubset(float TopLeftY, float TopLeftV, float BottomRightU, float BottomRightV, int TextureIndex = 0, bool Use3DTexture = 0) = 0; - virtual void QuadsSetSubsetFree(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, int TextureIndex = 0, bool Use3DTexture = 0) = 0; + virtual void QuadsSetSubset(float TopLeftY, float TopLeftV, float BottomRightU, float BottomRightV, int TextureIndex = -1) = 0; + virtual void QuadsSetSubsetFree(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, int TextureIndex = -1) = 0; struct CQuadItem { diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 9b31bda0e..f7b56035d 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -258,10 +258,10 @@ void CMapLayers::OnRender() Graphics()->BlendNone(); vec4 Color = vec4(pTMap->m_Color.r/255.0f, pTMap->m_Color.g/255.0f, pTMap->m_Color.b/255.0f, pTMap->m_Color.a/255.0f); RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE, - EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset, true); + EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset); Graphics()->BlendNormal(); RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT, - EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset, true); + EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset); } else if(pLayer->m_Type == LAYERTYPE_QUADS) { diff --git a/src/game/client/render.h b/src/game/client/render.h index 1567e8470..9c46c4ccd 100644 --- a/src/game/client/render.h +++ b/src/game/client/render.h @@ -72,7 +72,7 @@ public: // map render methods (gc_render_map.cpp) static void RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Channels, float Time, float *pResult); void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser); - void RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset, bool UseArray); + void RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset); // helpers void MapscreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY, diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index bd5c681e7..8fc333db9 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -164,17 +164,10 @@ void CRenderTools::RenderQuads(CQuad *pQuads, int NumQuads, int RenderFlags, ENV } void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags, - ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset, bool UseArray) + ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset) { - //Graphics()->TextureSet(img_get(tmap->image)); float ScreenX0, ScreenY0, ScreenX1, ScreenY1; Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); - //Graphics()->MapScreen(screen_x0-50, screen_y0-50, screen_x1+50, screen_y1+50); - - // calculate the final pixelsize for the tiles - float TilePixelSize = 1024/32.0f; - float FinalTileSize = Scale/(ScreenX1-ScreenX0) * Graphics()->ScreenWidth(); - float FinalTilesetScale = FinalTileSize/TilePixelSize; float r=1, g=1, b=1, a=1; if(ColorEnv >= 0) @@ -195,11 +188,6 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 int EndY = (int)(ScreenY1/Scale)+1; int EndX = (int)(ScreenX1/Scale)+1; - // adjust the texture shift according to mipmap level - float TexSize = 1024.0f; - float Frac = (1.25f/TexSize) * (1/FinalTilesetScale); - float Nudge = (0.5f/TexSize) * (1/FinalTilesetScale); - for(int y = StartY; y < EndY; y++) for(int x = StartX; x < EndX; x++) { @@ -250,41 +238,14 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 if(Render) { - - int tx = Index%16; - int ty = Index/16; - int Px0 = tx*(1024/16); - int Py0 = ty*(1024/16); - int Px1 = Px0+(1024/16)-1; - int Py1 = Py0+(1024/16)-1; - /* - - */ - - float x0, y0, x1, y1, x2, y2, x3, y3; - - if(UseArray) - { - x0 = 0; - y0 = 0; - x1 = 1; - y1 = 0; - x2 = 1; - y2 = 1; - x3 = 0; - y3 = 1; - } - else - { - x0 = Nudge + Px0/TexSize+Frac; - y0 = Nudge + Py0/TexSize+Frac; - x1 = Nudge + Px1/TexSize-Frac; - y1 = Nudge + Py0/TexSize+Frac; - x2 = Nudge + Px1/TexSize-Frac; - y2 = Nudge + Py1/TexSize-Frac; - x3 = Nudge + Px0/TexSize+Frac; - y3 = Nudge + Py1/TexSize-Frac; - } + float x0 = 0; + float y0 = 0; + float x1 = 1; + float y1 = 0; + float x2 = 1; + float y2 = 1; + float x3 = 0; + float y3 = 1; if(Flags&TILEFLAG_VFLIP) { @@ -316,7 +277,7 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 y1 = Tmp; } - Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3, Index, UseArray); + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3, Index); IGraphics::CQuadItem QuadItem(x*Scale, y*Scale, Scale, Scale); Graphics()->QuadsDrawTL(&QuadItem, 1); } diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 1ebd49cb8..0bbcdaf7c 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -2532,7 +2532,7 @@ void CEditor::ReplaceImage(const char *pFileName, int StorageType, void *pUser) pImg->m_External = External; pEditor->ExtractName(pFileName, pImg->m_aName, sizeof(pImg->m_aName)); pImg->LoadAutoMapper(); - pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0); + pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_MULTI_DIMENSION); ImgInfo.m_pData = 0; pEditor->SortImages(); for(int i = 0; i < pEditor->m_Map.m_lImages.size(); ++i) @@ -2561,7 +2561,7 @@ void CEditor::AddImage(const char *pFileName, int StorageType, void *pUser) CEditorImage *pImg = new CEditorImage(pEditor); *pImg = ImgInfo; - pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0); + pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_MULTI_DIMENSION); ImgInfo.m_pData = 0; pImg->m_External = 1; // external by default str_copy(pImg->m_aName, aBuf, sizeof(pImg->m_aName)); @@ -3902,11 +3902,7 @@ void CEditor::Reset(bool CreateDefault) // create default layers if(CreateDefault) - m_Map.CreateDefault(m_EntitiesTexture); - - /* - { - }*/ + m_Map.CreateDefault(); m_SelectedLayer = 0; m_SelectedGroup = 0; @@ -4018,7 +4014,7 @@ void CEditorMap::Clean() m_Modified = false; } -void CEditorMap::CreateDefault(IGraphics::CTextureHandle EntitiesTexture) +void CEditorMap::CreateDefault() { // add background CLayerGroup *pGroup = NewGroup(); @@ -4064,7 +4060,7 @@ void CEditor::Init() m_CheckerTexture = Graphics()->LoadTexture("editor/checker.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); m_BackgroundTexture = Graphics()->LoadTexture("editor/background.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); m_CursorTexture = Graphics()->LoadTexture("editor/cursor.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); - m_EntitiesTexture = Graphics()->LoadTexture("editor/entities.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0); + m_EntitiesTexture = Graphics()->LoadTexture("editor/entities.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_MULTI_DIMENSION); m_TilesetPicker.m_pEditor = this; m_TilesetPicker.MakePalette(); diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index bbf9be0fb..185b79d5e 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -359,7 +359,7 @@ public: } void Clean(); - void CreateDefault(IGraphics::CTextureHandle EntitiesTexture); + void CreateDefault(); // io int Save(class IStorage *pStorage, const char *pFilename); diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp index 97d06e6d0..2033cc647 100644 --- a/src/game/editor/io.cpp +++ b/src/game/editor/io.cpp @@ -484,7 +484,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag if(m_pEditor->Graphics()->LoadPNG(&ImgInfo, aBuf, IStorage::TYPE_ALL)) { *pImg = ImgInfo; - pImg->m_Texture = m_pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0); + pImg->m_Texture = m_pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_MULTI_DIMENSION); ImgInfo.m_pData = 0; pImg->m_External = 1; } @@ -500,7 +500,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag void *pData = DataFile.GetData(pItem->m_ImageData); pImg->m_pData = mem_alloc(pImg->m_Width*pImg->m_Height*PixelSize, 1); mem_copy(pImg->m_pData, pData, pImg->m_Width*pImg->m_Height*PixelSize); - pImg->m_Texture = m_pEditor->Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, pImg->m_Format, pImg->m_pData, CImageInfo::FORMAT_AUTO, 0); + pImg->m_Texture = m_pEditor->Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, pImg->m_Format, pImg->m_pData, CImageInfo::FORMAT_AUTO, IGraphics::TEXLOAD_MULTI_DIMENSION); } // copy image name diff --git a/src/game/editor/layer_tiles.cpp b/src/game/editor/layer_tiles.cpp index 237673100..edb80f0d1 100644 --- a/src/game/editor/layer_tiles.cpp +++ b/src/game/editor/layer_tiles.cpp @@ -68,10 +68,10 @@ void CLayerTiles::Render() vec4 Color = vec4(m_Color.r/255.0f, m_Color.g/255.0f, m_Color.b/255.0f, m_Color.a/255.0f); Graphics()->BlendNone(); m_pEditor->RenderTools()->RenderTilemap(m_pTiles, m_Width, m_Height, 32.0f, Color, LAYERRENDERFLAG_OPAQUE, - m_pEditor->EnvelopeEval, m_pEditor, m_ColorEnv, m_ColorEnvOffset, false); + m_pEditor->EnvelopeEval, m_pEditor, m_ColorEnv, m_ColorEnvOffset); Graphics()->BlendNormal(); m_pEditor->RenderTools()->RenderTilemap(m_pTiles, m_Width, m_Height, 32.0f, Color, LAYERRENDERFLAG_TRANSPARENT, - m_pEditor->EnvelopeEval, m_pEditor, m_ColorEnv, m_ColorEnvOffset, false); + m_pEditor->EnvelopeEval, m_pEditor, m_ColorEnv, m_ColorEnvOffset); } int CLayerTiles::ConvertX(float x) const { return (int)(x/32.0f); }