1974: more typesafty in the graphics. introduced the IGraphics::CTextureHandle r=def- a=ChillerDragon

Edited by @ChillerDragon to fit in ddnet
(cherry picked from commit cb95e8dfe8)

Co-authored-by: Magnus Auvinen <magnus.auvinen@gmail.com>
This commit is contained in:
bors[bot] 2019-11-27 17:55:45 +00:00 committed by GitHub
commit 33d88f647c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 263 additions and 262 deletions

View file

@ -64,6 +64,9 @@ if gen_server_content_header:
if gen_client_content_header or gen_server_content_header:
# print some includes
print('#include <engine/graphics.h>')
# emit the type declarations
contentlines = open("datasrc/content.py", "rb").readlines()
order = []

View file

@ -21,7 +21,7 @@ class Image(Struct):
Struct.__init__(self, "CDataImage")
self.name = String(name)
self.filename = String(filename)
self.id = Int(-1)
self.id = TextureHandle()
class SpriteSet(Struct):
def __init__(self, name="", image=None, gridx=0, gridy=0):

View file

@ -168,6 +168,12 @@ class Pointer(BaseType):
def EmitDefinition(self, name):
return ["&"+self.target.TargetName()]
class TextureHandle(BaseType):
def __init__(self):
BaseType.__init__(self, "IGraphics::CTextureHandle")
def EmitDefinition(self, name):
return ["IGraphics::CTextureHandle()"]
# helper functions
def EmitTypeDeclaration(root):

View file

@ -5,6 +5,7 @@
#include "kernel.h"
#include "message.h"
#include "graphics.h"
#include <engine/friends.h>
#include <engine/shared/config.h>
@ -177,7 +178,7 @@ public:
virtual bool SoundInitFailed() = 0;
virtual int GetDebugFont() = 0;
virtual IGraphics::CTextureHandle GetDebugFont() = 0; // TODO: remove this function
//DDRace

View file

@ -114,12 +114,12 @@ void CGraph::Add(float v, float r, float g, float b)
m_aColors[m_Index][2] = b;
}
void CGraph::Render(IGraphics *pGraphics, int Font, float x, float y, float w, float h, const char *pDescription)
void CGraph::Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, float x, float y, float w, float h, const char *pDescription)
{
//m_pGraphics->BlendNormal();
pGraphics->TextureSet(-1);
pGraphics->TextureClear();
pGraphics->QuadsBegin();
pGraphics->SetColor(0, 0, 0, 0.75f);
@ -156,7 +156,7 @@ void CGraph::Render(IGraphics *pGraphics, int Font, float x, float y, float w, f
}
pGraphics->LinesEnd();
pGraphics->TextureSet(Font);
pGraphics->TextureSet(FontTexture);
pGraphics->QuadsBegin();
pGraphics->QuadsText(x+2, y+h-16, 16, pDescription);

View file

@ -30,7 +30,7 @@ public:
void ScaleMin();
void Add(float v, float r, float g, float b);
void Render(IGraphics *pGraphics, int Font, float x, float y, float w, float h, const char *pDescription);
void Render(IGraphics *pGraphics, IGraphics::CTextureHandle FontTexture, float x, float y, float w, float h, const char *pDescription);
};
@ -106,7 +106,7 @@ class CClient : public IClient, public CDemoPlayer::IListener
unsigned m_SnapshotParts[2];
int64 m_LocalStartTime;
int m_DebugFont;
IGraphics::CTextureHandle m_DebugFont;
int m_DebugSoundIndex = 0;
int64 m_LastRenderTime;
@ -267,7 +267,7 @@ public:
virtual bool SoundInitFailed() { return m_SoundInitFailed; }
virtual int GetDebugFont() { return m_DebugFont; }
virtual IGraphics::CTextureHandle GetDebugFont() { return m_DebugFont; }
void DirectInput(int *pInput, int Size);
void SendInput();

View file

@ -229,7 +229,6 @@ CGraphics_Threaded::CGraphics_Threaded()
m_Rotation = 0;
m_Drawing = 0;
m_InvalidTexture = 0;
m_TextureMemoryUsage = 0;
@ -341,7 +340,7 @@ void CGraphics_Threaded::LinesDraw(const CLineItem *pArray, int Num)
AddVertices(2*Num);
}
int CGraphics_Threaded::UnloadTexture(int Index)
int CGraphics_Threaded::UnloadTexture(CTextureHandle Index)
{
if(Index == m_InvalidTexture)
return 0;
@ -377,7 +376,7 @@ static int ImageFormatToPixelSize(int Format)
}
int CGraphics_Threaded::LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData)
int CGraphics_Threaded::LoadTextureRawSub(CTextureHandle TextureID, int x, int y, int Width, int Height, int Format, const void *pData)
{
CCommandBuffer::SCommand_Texture_Update Cmd;
Cmd.m_Slot = TextureID;
@ -405,7 +404,7 @@ int CGraphics_Threaded::LoadTextureRawSub(int TextureID, int x, int y, int Width
return 0;
}
int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags)
IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags)
{
// don't waste memory on texture if we are stress testing
#ifdef CONF_DEBUG
@ -449,18 +448,18 @@ int CGraphics_Threaded::LoadTextureRaw(int Width, int Height, int Format, const
m_pCommandBuffer->AddCommand(Cmd);
}
return Tex;
return CreateTextureHandle(Tex);
}
// simple uncompressed RGBA loaders
int CGraphics_Threaded::LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags)
IGraphics::CTextureHandle CGraphics_Threaded::LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags)
{
int l = str_length(pFilename);
int ID;
CImageInfo Img;
if(l < 3)
return -1;
return CTextureHandle();
if(LoadPNG(&Img, pFilename, StorageType))
{
if(StoreFormat == CImageInfo::FORMAT_AUTO)
@ -470,7 +469,7 @@ int CGraphics_Threaded::LoadTexture(const char *pFilename, int StorageType, int
free(Img.m_pData);
if(ID != m_InvalidTexture && g_Config.m_Debug)
dbg_msg("graphics/texture", "loaded %s", pFilename);
return ID;
return CreateTextureHandle(ID);
}
return m_InvalidTexture;
@ -570,7 +569,7 @@ void CGraphics_Threaded::ScreenshotDirect()
}
}
void CGraphics_Threaded::TextureSet(int TextureID)
void CGraphics_Threaded::TextureSet(CTextureHandle TextureID)
{
dbg_assert(m_Drawing == 0, "called Graphics()->TextureSet within begin");
m_State.m_Texture = TextureID;

View file

@ -632,7 +632,7 @@ class CGraphics_Threaded : public IEngineGraphics
bool m_DoScreenshot;
char m_aScreenshotName[128];
int m_InvalidTexture;
CTextureHandle m_InvalidTexture;
int m_aTextureIndices[MAX_TEXTURES];
int m_FirstFreeTexture;
@ -716,17 +716,17 @@ public:
virtual void LinesEnd();
virtual void LinesDraw(const CLineItem *pArray, int Num);
virtual int UnloadTexture(int Index);
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags);
virtual int LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData);
virtual int UnloadTexture(IGraphics::CTextureHandle Index);
virtual IGraphics::CTextureHandle LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags);
virtual int LoadTextureRawSub(IGraphics::CTextureHandle TextureID, int x, int y, int Width, int Height, int Format, const void *pData);
// simple uncompressed RGBA loaders
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags);
virtual IGraphics::CTextureHandle LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags);
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType);
void ScreenshotDirect();
virtual void TextureSet(int TextureID);
virtual void TextureSet(CTextureHandle TextureID);
virtual void Clear(float r, float g, float b);

View file

@ -102,7 +102,7 @@ public:
FT_Face m_FtFace;
CFontSizeData m_aFontSizes[NUM_FONT_SIZES];
int m_aTextures[2];
IGraphics::CTextureHandle m_aTextures[2];
// keep the full texture, because opengl doesn't provide texture copying
unsigned char *m_TextureData[2];
@ -275,7 +275,7 @@ class CTextRender : public IEngineTextRender
}
}
int InitTexture(int Width, int Height, void *pUploadData = NULL)
IGraphics::CTextureHandle InitTexture(int Width, int Height, void *pUploadData = NULL)
{
void *pMem = NULL;
if(pUploadData)
@ -287,17 +287,17 @@ class CTextRender : public IEngineTextRender
pMem = calloc(Width * Height, 1);
}
int TextureID = Graphics()->LoadTextureRaw(Width, Height, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS | IGraphics::TEXLOAD_NO_COMPRESSION);
IGraphics::CTextureHandle Texture = Graphics()->LoadTextureRaw(Width, Height, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS | IGraphics::TEXLOAD_NO_COMPRESSION);
if(!pUploadData)
free(pMem);
return TextureID;
return Texture;
}
void UnloadTexture(int TextureIndex)
void UnloadTexture(IGraphics::CTextureHandle Index)
{
Graphics()->UnloadTexture(TextureIndex);
Graphics()->UnloadTexture(Index);
}
void IncreaseFontTexture(CFont *pFont, int TextureIndex)
@ -848,7 +848,7 @@ public:
if(Graphics()->IsBufferingEnabled())
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->TextQuadsBegin();
Graphics()->SetColor(m_Color);
}
@ -1620,7 +1620,7 @@ public:
if(Graphics()->IsBufferingEnabled())
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
// render buffered text
Graphics()->RenderText(TextContainer.m_StringInfo.m_QuadBufferContainerIndex, TextContainer.m_StringInfo.m_QuadNum, pFont->m_CurTextureDimensions[0], pFont->m_aTextures[0], pFont->m_aTextures[1], (float*)pTextColor, (float*)pTextOutlineColor);
}
@ -1698,11 +1698,11 @@ public:
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
virtual void UploadEntityLayerText(int TextureID, const char *pText, int Length, float x, float y, int FontSize)
virtual void UploadEntityLayerText(IGraphics::CTextureHandle Texture, const char *pText, int Length, float x, float y, int FontSize)
{
if (FontSize < 1)
{
dbg_msg("pFont", "texture with id '%d' will not be updated. Reason - font is too small", TextureID);
dbg_msg("pFont", "texture with id '%d' will not be updated. Reason - font is too small", (int)Texture);
return;
}
@ -1748,7 +1748,7 @@ public:
}
}
Graphics()->LoadTextureRawSub(TextureID, x + WidthLastChars, y, SlotW, SlotH, CImageInfo::FORMAT_ALPHA, ms_aGlyphData);
Graphics()->LoadTextureRawSub(Texture, x + WidthLastChars, y, SlotW, SlotH, CImageInfo::FORMAT_ALPHA, ms_aGlyphData);
WidthLastChars += (SlotW + 1);
}

View file

@ -113,6 +113,19 @@ public:
TEXLOAD_NO_COMPRESSION = 1<<2,
};
class CTextureHandle
{
friend class IGraphics;
int m_Id;
public:
CTextureHandle()
: m_Id(-1)
{}
operator int() const { return m_Id; }
};
int ScreenWidth() const { return m_ScreenWidth; }
int ScreenHeight() const { return m_ScreenHeight; }
float ScreenAspect() const { return (float)ScreenWidth()/(float)ScreenHeight(); }
@ -142,11 +155,13 @@ public:
virtual int MemoryUsage() const = 0;
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) = 0;
virtual int UnloadTexture(int Index) = 0;
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) = 0;
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) = 0;
virtual int LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData) = 0;
virtual void TextureSet(int TextureID) = 0;
virtual int UnloadTexture(CTextureHandle Index) = 0;
virtual CTextureHandle LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) = 0;
virtual int LoadTextureRawSub(CTextureHandle TextureID, int x, int y, int Width, int Height, int Format, const void *pData) = 0;
virtual CTextureHandle LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) = 0;
virtual void TextureSet(CTextureHandle Texture) = 0;
void TextureClear() { TextureSet(CTextureHandle()); }
virtual void FlushVertices(bool KeepVertices = false) = 0;
virtual void FlushTextVertices(int TextureSize, int TextTextureIndex, int TextOutlineTextureIndex, float *pOutlineTextColor) = 0;
@ -260,6 +275,14 @@ public:
virtual void SetWindowGrab(bool Grab) = 0;
virtual void NotifyWindow() = 0;
protected:
inline CTextureHandle CreateTextureHandle(int Index)
{
CTextureHandle Tex;
Tex.m_Id = Index;
return Tex;
}
};
class IEngineGraphics : public IGraphics

View file

@ -5,6 +5,7 @@
#include "kernel.h"
#include <base/color.h>
#include <engine/graphics.h>
enum
{
@ -98,7 +99,7 @@ public:
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor) = 0;
virtual void RenderTextContainer(int TextContainerIndex, STextRenderColor *pTextColor, STextRenderColor *pTextOutlineColor, float X, float Y) = 0;
virtual void UploadEntityLayerText(int TextureID, const char *pText, int Length, float x, float y, int FontHeight) = 0;
virtual void UploadEntityLayerText(IGraphics::CTextureHandle Texture, const char *pText, int Length, float x, float y, int FontHeight) = 0;
virtual int AdjustFontSize(const char *pText, int TextLength, int MaxSize = -1) = 0;
virtual int CalculateTextWidth(const char *pText, int TextLength, int FontWidth, int FontHeight) = 0;

View file

@ -405,7 +405,7 @@ void CGameConsole::PossibleCommandsRenderCallback(const char *pStr, void *pUser)
if(pInfo->m_EnumCount == pInfo->m_WantedCompletion)
{
float tw = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_pFont, pInfo->m_Cursor.m_FontSize, pStr, -1);
pInfo->m_pSelf->Graphics()->TextureSet(-1);
pInfo->m_pSelf->Graphics()->TextureClear();
pInfo->m_pSelf->Graphics()->QuadsBegin();
pInfo->m_pSelf->Graphics()->SetColor(229.0f/255.0f,185.0f/255.0f,4.0f/255.0f,0.85f);
pInfo->m_pSelf->RenderTools()->DrawRoundRect(pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, tw + 5.f, pInfo->m_Cursor.m_FontSize + 4.f, pInfo->m_Cursor.m_FontSize / 3.f);
@ -485,7 +485,7 @@ void CGameConsole::OnRender()
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
// do console shadow
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
IGraphics::CColorVertex Array[4] = {
IGraphics::CColorVertex(0, 0,0,0, 0.5f),
@ -509,7 +509,7 @@ void CGameConsole::OnRender()
Graphics()->QuadsEnd();
// do small bar shadow
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Array[0] = IGraphics::CColorVertex(0, 0,0,0, 0.0f);
Array[1] = IGraphics::CColorVertex(1, 0,0,0, 0.0f);

View file

@ -80,8 +80,7 @@ void CCountryFlags::LoadCountryflagsIndexfile()
CountryFlag.m_Texture = Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0);
free(Info.m_pData);
}
else
CountryFlag.m_Texture = -1;
if(g_Config.m_Debug)
{
str_format(aBuf, sizeof(aBuf), "loaded country flag '%s'", aOrigin);
@ -121,7 +120,6 @@ void CCountryFlags::OnInit()
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "countryflags", "failed to load country flags. folder='countryflags/'");
CCountryFlag DummyEntry;
DummyEntry.m_CountryCode = -1;
DummyEntry.m_Texture = -1;
mem_zero(DummyEntry.m_aCountryCodeString, sizeof(DummyEntry.m_aCountryCodeString));
m_aCountryFlags.add(DummyEntry);
}

View file

@ -13,7 +13,7 @@ public:
{
int m_CountryCode;
char m_aCountryCodeString[8];
int m_Texture;
IGraphics::CTextureHandle m_Texture;
bool operator<(const CCountryFlag &Other) { return str_comp(m_aCountryCodeString, Other.m_aCountryCodeString) < 0; }
};

View file

@ -119,7 +119,7 @@ void CDebugHud::RenderTuning()
y = y+Count*6;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->BlendNormal();
Graphics()->LinesBegin();
float Height = 50.0f;

View file

@ -107,7 +107,7 @@ void CEmoticon::OnRender()
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.3f);
DrawCircle(Screen.w/2, Screen.h/2, 190.0f, 64);
@ -137,7 +137,7 @@ void CEmoticon::OnRender()
if(GameClient()->m_GameInfo.m_AllowEyeWheel && g_Config.m_ClEyeWheel)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0,1.0,1.0,0.3f);
DrawCircle(Screen.w/2, Screen.h/2, 100.0f, 64);
@ -163,7 +163,7 @@ void CEmoticon::OnRender()
pTeeInfo->m_Size = 64.0f;
}
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.3f);
DrawCircle(Screen.w/2, Screen.h/2, 30.0f, 64);

View file

@ -20,7 +20,7 @@ void CFlow::DbgRender()
IGraphics::CLineItem Array[1024];
int NumItems = 0;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
for(int y = 0; y < m_Height; y++)
for(int x = 0; x < m_Width; x++)

View file

@ -225,7 +225,7 @@ void CHud::RenderScoreHud()
Graphics()->SetColor(0.0f, 0.0f, 1.0f, 0.25f);
m_aScoreInfo[t].m_RoundRectQuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Whole - ScoreWidthMax - ImageSize - 2 * Split, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split, 18.0f, 5.0f, CUI::CORNER_L);
}
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
if(m_aScoreInfo[t].m_RoundRectQuadContainerIndex != -1)
Graphics()->RenderQuadContainer(m_aScoreInfo[t].m_RoundRectQuadContainerIndex, -1);
@ -399,7 +399,7 @@ void CHud::RenderScoreHud()
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.25f);
m_aScoreInfo[t].m_RoundRectQuadContainerIndex = RenderTools()->CreateRoundRectQuadContainer(Whole - ScoreWidthMax - ImageSize - 2 * Split - PosSize, StartY + t * 20, ScoreWidthMax + ImageSize + 2 * Split + PosSize, 18.0f, 5.0f, CUI::CORNER_L);
}
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
if(m_aScoreInfo[t].m_RoundRectQuadContainerIndex != -1)
Graphics()->RenderQuadContainer(m_aScoreInfo[t].m_RoundRectQuadContainerIndex, -1);
@ -603,7 +603,7 @@ void CHud::RenderVoting()
if((!g_Config.m_ClShowVotesAfterVoting && !m_pClient->m_pScoreboard->Active() && m_pClient->m_pVoting->TakenChoice()) || !m_pClient->m_pVoting->IsVoting() || Client()->State() == IClient::STATE_DEMOPLAYBACK)
return;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.40f);
@ -729,7 +729,7 @@ void CHud::RenderHealthAndAmmo(const CNetObj_Character *pCharacter)
void CHud::RenderSpectatorHud()
{
// draw the box
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.4f);
RenderTools()->DrawRoundRectExt(m_Width-180.0f, m_Height-15.0f, 180.0f, 15.0f, 5.0f, CUI::CORNER_TL);
@ -749,7 +749,7 @@ void CHud::RenderLocalTime(float x)
//draw the box
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.4f);
RenderTools()->DrawRoundRectExt(x-30.0f, 0.0f, 25.0f, 12.5f, 3.75f, CUI::CORNER_B);

View file

@ -231,7 +231,7 @@ void CItems::RenderLaser(const struct CNetObj_Laser *pCurrent, bool IsPredicted)
vec2 Out, Border;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
// do outline

View file

@ -17,11 +17,8 @@ CMapImages::CMapImages() : CMapImages(100)
CMapImages::CMapImages(int TextureSize)
{
m_Count = 0;
m_EntitiesTextures = -1;
m_OverlayBottomTexture = -1;
m_OverlayTopTexture = -1;
m_OverlayCenterTexture = -1;
m_TextureScale = TextureSize;
m_EntitiesIsLoaded = false;
}
void CMapImages::OnInit()
@ -37,7 +34,7 @@ void CMapImages::OnMapLoad()
for(int i = 0; i < m_Count; i++)
{
Graphics()->UnloadTexture(m_aTextures[i]);
m_aTextures[i] = -1;
m_aTextures[i] = IGraphics::CTextureHandle();
}
m_Count = 0;
@ -47,8 +44,6 @@ void CMapImages::OnMapLoad()
// load new textures
for(int i = 0; i < m_Count; i++)
{
m_aTextures[i] = 0;
CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
if(pImg->m_External)
{
@ -72,7 +67,7 @@ void CMapImages::LoadBackground(class IMap *pMap)
for(int i = 0; i < m_Count; i++)
{
Graphics()->UnloadTexture(m_aTextures[i]);
m_aTextures[i] = -1;
m_aTextures[i] = IGraphics::CTextureHandle();
}
m_Count = 0;
@ -82,8 +77,6 @@ void CMapImages::LoadBackground(class IMap *pMap)
// load new textures
for(int i = 0; i < m_Count; i++)
{
m_aTextures[i] = 0;
CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
if(pImg->m_External)
{
@ -101,7 +94,7 @@ void CMapImages::LoadBackground(class IMap *pMap)
}
}
int CMapImages::GetEntities()
IGraphics::CTextureHandle CMapImages::GetEntities()
{
// DDNet default to prevent delay in seeing entities
const char *pEntities = "ddnet";
@ -116,7 +109,7 @@ int CMapImages::GetEntities()
else if(GameClient()->m_GameInfo.m_EntitiesVanilla)
pEntities = "vanilla";
if(m_EntitiesTextures == -1 || m_pEntitiesGameType != pEntities)
if(!m_EntitiesIsLoaded || m_pEntitiesGameType != pEntities)
{
char aPath[64];
str_format(aPath, sizeof(aPath), "editor/entities_clear/%s.png", pEntities);
@ -124,23 +117,23 @@ int CMapImages::GetEntities()
if(m_EntitiesTextures >= 0)
Graphics()->UnloadTexture(m_EntitiesTextures);
m_EntitiesTextures = Graphics()->LoadTexture(aPath, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
m_EntitiesIsLoaded = true;
m_pEntitiesGameType = pEntities;
}
return m_EntitiesTextures;
}
int CMapImages::GetOverlayBottom()
IGraphics::CTextureHandle CMapImages::GetOverlayBottom()
{
return m_OverlayBottomTexture;
}
int CMapImages::GetOverlayTop()
IGraphics::CTextureHandle CMapImages::GetOverlayTop()
{
return m_OverlayTopTexture;
}
int CMapImages::GetOverlayCenter()
IGraphics::CTextureHandle CMapImages::GetOverlayCenter()
{
return m_OverlayCenterTexture;
}
@ -158,7 +151,6 @@ void CMapImages::SetTextureScale(int Scale)
Graphics()->UnloadTexture(m_OverlayBottomTexture);
Graphics()->UnloadTexture(m_OverlayTopTexture);
Graphics()->UnloadTexture(m_OverlayCenterTexture);
m_OverlayBottomTexture = m_OverlayTopTexture = m_OverlayCenterTexture = -1;
InitOverlayTextures();
}
@ -169,20 +161,20 @@ int CMapImages::GetTextureScale()
return m_TextureScale;
}
int CMapImages::UploadEntityLayerText(int TextureSize, int YOffset)
IGraphics::CTextureHandle CMapImages::UploadEntityLayerText(int TextureSize, int YOffset)
{
void *pMem = calloc(1024 * 1024, 1);
int TextureID = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS);
IGraphics::CTextureHandle Texture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_ALPHA, pMem, CImageInfo::FORMAT_ALPHA, IGraphics::TEXLOAD_NOMIPMAPS);
free(pMem);
UpdateEntityLayerText(TextureID, TextureSize, YOffset, 0);
UpdateEntityLayerText(TextureID, TextureSize, YOffset, 1);
UpdateEntityLayerText(TextureID, TextureSize, YOffset, 2, 255);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 0);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 1);
UpdateEntityLayerText(Texture, TextureSize, YOffset, 2, 255);
return TextureID;
return Texture;
}
void CMapImages::UpdateEntityLayerText(int TextureID, int TextureSize, int YOffset, int NumbersPower, int MaxNumber)
void CMapImages::UpdateEntityLayerText(IGraphics::CTextureHandle Texture, int TextureSize, int YOffset, int NumbersPower, int MaxNumber)
{
char aBuf[4];
int DigitsCount = NumbersPower+1;
@ -199,7 +191,7 @@ void CMapImages::UpdateEntityLayerText(int TextureID, int TextureSize, int YOffs
if (UniversalSuitableFontSize < 1)
{
dbg_msg("pFont", "texture with id '%d' will not be loaded. Reason - font is too small", TextureID);
dbg_msg("pFont", "texture with id '%d' will not be loaded. Reason - font is too small", (int)Texture);
}
int ApproximateTextWidth = TextRender()->CalculateTextWidth(aBuf, DigitsCount, 0, UniversalSuitableFontSize);
@ -213,7 +205,7 @@ void CMapImages::UpdateEntityLayerText(int TextureID, int TextureSize, int YOffs
float x = (CurrentNumber%16)*64;
float y = (CurrentNumber/16)*64;
TextRender()->UploadEntityLayerText(TextureID, aBuf, DigitsCount, x+XOffSet, y+YOffset, UniversalSuitableFontSize);
TextRender()->UploadEntityLayerText(Texture, aBuf, DigitsCount, x+XOffSet, y+YOffset, UniversalSuitableFontSize);
}
}

View file

@ -8,7 +8,7 @@ class CMapImages : public CComponent
{
friend class CBackground;
int m_aTextures[64];
IGraphics::CTextureHandle m_aTextures[64];
int m_Count;
const char *m_pEntitiesGameType;
@ -16,7 +16,7 @@ public:
CMapImages();
CMapImages(int ImageSize);
int Get(int Index) const { return m_aTextures[Index]; }
IGraphics::CTextureHandle Get(int Index) const { return m_aTextures[Index]; }
int Num() const { return m_Count; }
virtual void OnMapLoad();
@ -24,26 +24,27 @@ public:
void LoadBackground(class IMap *pMap);
// DDRace
int GetEntities();
IGraphics::CTextureHandle GetEntities();
int GetOverlayBottom();
int GetOverlayTop();
int GetOverlayCenter();
IGraphics::CTextureHandle GetOverlayBottom();
IGraphics::CTextureHandle GetOverlayTop();
IGraphics::CTextureHandle GetOverlayCenter();
void SetTextureScale(int Size);
int GetTextureScale();
private:
int m_EntitiesTextures;
int m_OverlayBottomTexture;
int m_OverlayTopTexture;
int m_OverlayCenterTexture;
bool m_EntitiesIsLoaded;
IGraphics::CTextureHandle m_EntitiesTextures;
IGraphics::CTextureHandle m_OverlayBottomTexture;
IGraphics::CTextureHandle m_OverlayTopTexture;
IGraphics::CTextureHandle m_OverlayCenterTexture;
int m_TextureScale;
void InitOverlayTextures();
int UploadEntityLayerText(int TextureSize, int YOffset);
void UpdateEntityLayerText(int TextureID, int TextureSize, int YOffset, int NumbersPower, int MaxNumber = -1);
IGraphics::CTextureHandle UploadEntityLayerText(int TextureSize, int YOffset);
void UpdateEntityLayerText(IGraphics::CTextureHandle Texture, int TextureSize, int YOffset, int NumbersPower, int MaxNumber = -1);
};
#endif

View file

@ -1721,7 +1721,7 @@ void CMapLayers::OnRender()
if(pTMap->m_Image == -1)
{
if(!IsGameLayer)
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
else
Graphics()->TextureSet(m_pImages->GetEntities());
}
@ -1782,7 +1782,7 @@ void CMapLayers::OnRender()
{
CMapItemLayerQuads *pQLayer = (CMapItemLayerQuads *)pLayer;
if(pQLayer->m_Image == -1)
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
else
Graphics()->TextureSet(m_pImages->Get(pQLayer->m_Image));

View file

@ -864,7 +864,7 @@ void CMenus::RenderLoading()
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.50f);
RenderTools()->DrawRoundRect(x, y, w, h, 40.0f);
@ -880,7 +880,7 @@ void CMenus::RenderLoading()
r.h = h - 130;
UI()->DoLabel(&r, pCaption, 48.0f, 0, -1);
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,0.75f);
RenderTools()->DrawRoundRect(x+40, y+h-75, (w-80)*Percent, 25, 5.0f);
@ -927,6 +927,8 @@ void CMenus::OnInit()
Console()->Chain("add_friend", ConchainFriendlistUpdate, this);
Console()->Chain("remove_friend", ConchainFriendlistUpdate, this);
m_TextureBlob = Graphics()->LoadTexture("blob.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
// setup load amount
m_LoadCurrent = 0;
m_LoadTotal = g_pData->m_NumImages;
@ -1835,20 +1837,14 @@ void CMenus::OnRender()
m_NumInputEvents = 0;
}
static int gs_TextureBlob = -1;
void CMenus::RenderBackground()
{
if(gs_TextureBlob == -1)
gs_TextureBlob = Graphics()->LoadTexture("blob.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
float sw = 300*Graphics()->ScreenAspect();
float sh = 300;
Graphics()->MapScreen(0, 0, sw, sh);
// render background color
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
ColorRGBA Bottom(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f);
ColorRGBA Top(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f);
@ -1863,7 +1859,7 @@ void CMenus::RenderBackground()
Graphics()->QuadsEnd();
// render the tiles
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
float Size = 15.0f;
float OffsetTime = fmod(Client()->LocalTime()*0.15f, 2.0f);
@ -1877,7 +1873,7 @@ void CMenus::RenderBackground()
Graphics()->QuadsEnd();
// render border fade
Graphics()->TextureSet(gs_TextureBlob);
Graphics()->TextureSet(m_TextureBlob);
Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,1);
QuadItem = IGraphics::CQuadItem(-100, -100, sw+200, sh+200);
@ -1927,7 +1923,7 @@ void CMenus::RenderUpdating(const char *pCaption, int current, int total)
float x = Screen.w/2-w/2;
float y = Screen.h/2-h/2;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.50f);
RenderTools()->DrawRoundRect(0, y, Screen.w, h, 0.0f);
@ -1943,7 +1939,7 @@ void CMenus::RenderUpdating(const char *pCaption, int current, int total)
if(total>0)
{
float Percent = current/(float)total;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0.15f,0.15f,0.15f,0.75f);
RenderTools()->DrawRoundRect(x+40, y+h-75, w-80, 30, 5.0f);

View file

@ -306,6 +306,8 @@ class CMenus : public CComponent
void RenderSettings(CUIRect MainView);
void SetActive(bool Active);
IGraphics::CTextureHandle m_TextureBlob;
public:
void RenderBackground();

View file

@ -283,7 +283,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
for(int i = 0; i < pInfo->m_NumTimelineMarkers; i++)
{
float Ratio = (pInfo->m_aTimelineMarkers[i]-pInfo->m_FirstTick) / (float)TotalTicks;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
IGraphics::CQuadItem QuadItem(SeekBar.x + (SeekBar.w-10.0f)*Ratio, SeekBar.y, UI()->PixelSize(), SeekBar.h);
@ -296,7 +296,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
if(g_Config.m_ClDemoSliceBegin != -1)
{
float Ratio = (g_Config.m_ClDemoSliceBegin-pInfo->m_FirstTick) / (float)TotalTicks;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 0.0f, 0.0f, 1.0f);
IGraphics::CQuadItem QuadItem(10.0f + SeekBar.x + (SeekBar.w-10.0f)*Ratio, SeekBar.y, UI()->PixelSize(), SeekBar.h);
@ -308,7 +308,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
if(g_Config.m_ClDemoSliceEnd != -1)
{
float Ratio = (g_Config.m_ClDemoSliceEnd-pInfo->m_FirstTick) / (float)TotalTicks;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 0.0f, 0.0f, 1.0f);
IGraphics::CQuadItem QuadItem(10.0f + SeekBar.x + (SeekBar.w-10.0f)*Ratio, SeekBar.y, UI()->PixelSize(), SeekBar.h);

View file

@ -615,7 +615,7 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
if(g_Config.m_Debug)
{
ColorRGBA BloodColor = *UseCustomColor ? color_cast<ColorRGBA>(ColorHSLA(*ColorBody)) : s->m_BloodColor;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(BloodColor.r, BloodColor.g, BloodColor.b, 1.0f);
IGraphics::CQuadItem QuadItem(Item.m_Rect.x, Item.m_Rect.y, 12.0f, 12.0f);
@ -1906,7 +1906,7 @@ void CMenus::RenderSettingsHUD(CUIRect MainView)
vec2 Out, Border;
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
// do outline

View file

@ -43,7 +43,7 @@ void CMotd::OnRender()
float y = 150.0f;
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.5f);
RenderTools()->DrawRoundRect(x, y, w, h, 40.0f);

View file

@ -287,7 +287,7 @@ void CPlayers::RenderPlayer(
if(Local && Client()->State() != IClient::STATE_DEMOPLAYBACK)
ExDirection = normalize(vec2(m_pClient->m_pControls->m_InputData[g_Config.m_ClDummy].m_TargetX, m_pClient->m_pControls->m_InputData[g_Config.m_ClDummy].m_TargetY));
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
vec2 InitPos = Position;
vec2 FinishPos = InitPos + ExDirection * (m_pClient->m_Tuning[g_Config.m_ClDummy].m_HookLength-42.0f);

View file

@ -64,7 +64,7 @@ void CScoreboard::RenderGoals(float x, float y, float w)
float h = 50.0f;
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.5f);
RenderTools()->DrawRoundRect(x, y, w, h, 10.0f);
@ -101,7 +101,7 @@ void CScoreboard::RenderSpectators(float x, float y, float w)
// background
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.5f);
RenderTools()->DrawRoundRect(x, y, w, h, 10.0f);
@ -180,7 +180,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
// background
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.5f);
if(upper16 || upper32 || upper24)
@ -372,7 +372,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
if (DDTeam != TEAM_FLOCK)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
ColorRGBA rgb = color_cast<ColorRGBA>(ColorHSLA(DDTeam / 64.0f, 1.0f, 0.5f, 0.5f));
Graphics()->SetColor(rgb);
@ -413,7 +413,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
// background so it's easy to find the local player or the followed one in spectator mode
if(pInfo->m_Local || (m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientID == m_pClient->m_Snap.m_SpecInfo.m_SpectatorID))
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
RenderTools()->DrawRoundRect(x, y, w-20.0f, LineHeight, RoundRadius);
@ -572,7 +572,7 @@ void CScoreboard::RenderRecordingNotification(float x)
//draw the box
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.4f);
RenderTools()->DrawRoundRectExt(x, 0.0f, w+60.0f, 50.0f, 15.0f, CUI::CORNER_B);

View file

@ -172,8 +172,6 @@ void CSkins::OnInit()
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "gameclient", "failed to load skins. folder='skins/'");
CSkin DummySkin;
DummySkin.m_IsVanilla = true;
DummySkin.m_OrgTexture = -1;
DummySkin.m_ColorTexture = -1;
str_copy(DummySkin.m_aName, "dummy", sizeof(DummySkin.m_aName));
DummySkin.m_BloodColor = ColorRGBA(1.0f, 1.0f, 1.0f);
m_aSkins.add(DummySkin);

View file

@ -14,8 +14,8 @@ public:
struct CSkin
{
bool m_IsVanilla;
int m_OrgTexture;
int m_ColorTexture;
IGraphics::CTextureHandle m_OrgTexture;
IGraphics::CTextureHandle m_ColorTexture;
char m_aName[24];
ColorRGBA m_BloodColor;

View file

@ -225,7 +225,7 @@ void CSpectator::OnRender()
Graphics()->MapScreen(0, 0, Width, Height);
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.3f);
RenderTools()->DrawRoundRect(Width/2.0f-ObjWidth, Height/2.0f-300.0f, ObjWidth*2, 600.0f, 20.0f);
@ -239,7 +239,7 @@ void CSpectator::OnRender()
if((Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == SPEC_FREEVIEW) ||
m_pClient->m_Snap.m_SpecInfo.m_SpectatorID == SPEC_FREEVIEW)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
RenderTools()->DrawRoundRect(Width/2.0f-(ObjWidth - 20.0f), Height/2.0f-280.0f, 270.0f, 60.0f, 20.0f);
@ -248,7 +248,7 @@ void CSpectator::OnRender()
if(Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == SPEC_FOLLOW)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
RenderTools()->DrawRoundRect(Width/2.0f-(ObjWidth - 310.0f), Height/2.0f-280.0f, 270.0f, 60.0f, 20.0f);
@ -325,7 +325,7 @@ void CSpectator::OnRender()
if (DDTeam != TEAM_FLOCK)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
ColorRGBA rgb = color_cast<ColorRGBA>(ColorHSLA(DDTeam / 64.0f, 1.0f, 0.5f, 0.5f));
Graphics()->SetColor(rgb);
@ -347,7 +347,7 @@ void CSpectator::OnRender()
if((Client()->State() == IClient::STATE_DEMOPLAYBACK && m_pClient->m_DemoSpecID == m_pClient->m_Snap.m_paInfoByDDTeam[i]->m_ClientID)
|| (Client()->State() != IClient::STATE_DEMOPLAYBACK && m_pClient ->m_Snap.m_SpecInfo.m_SpectatorID == m_pClient->m_Snap.m_paInfoByDDTeam[i]->m_ClientID))
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
RenderTools()->DrawRoundRect(Width/2.0f+x-10.0f, Height/2.0f+y+BoxMove, 270.0f, LineHeight, RoundRadius);

View file

@ -192,7 +192,7 @@ void CStatboard::RenderGlobalStats()
Graphics()->MapScreen(0, 0, StatboardWidth, StatboardHeight);
Graphics()->BlendNormal();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.5f);
RenderTools()->DrawRoundRect(x-10.f, y-10.f, StatboardContentWidth, StatboardContentHeight, 17.0f);
@ -272,7 +272,7 @@ void CStatboard::RenderGlobalStats()
|| (m_pClient->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientID == m_pClient->m_Snap.m_SpecInfo.m_SpectatorID))
{
// background so it's easy to find the local player
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,0.25f);
RenderTools()->DrawRoundRect(x, y, StatboardContentWidth-20, LineHeight*0.95f, 17.0f);

View file

@ -286,7 +286,7 @@ void CRenderTools::DrawRoundRect(float x, float y, float w, float h, float r)
void CRenderTools::DrawUIRect(const CUIRect *r, ColorRGBA Color, int Corners, float Rounding)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
// TODO: FIX US
Graphics()->QuadsBegin();

View file

@ -3,25 +3,24 @@
#ifndef GAME_CLIENT_RENDER_H
#define GAME_CLIENT_RENDER_H
#include <engine/graphics.h>
#include <base/vmath.h>
#include <base/color.h>
#include <game/mapitems.h>
#include "ui.h"
class CTeeRenderInfo
{
public:
CTeeRenderInfo()
{
m_Texture = -1;
m_ColorBody = ColorRGBA(1,1,1);
m_ColorFeet = ColorRGBA(1,1,1);
m_Size = 1.0f;
m_GotAirJump = 1;
};
int m_Texture;
IGraphics::CTextureHandle m_Texture;
ColorRGBA m_ColorBody;
ColorRGBA m_ColorFeet;
float m_Size;

View file

@ -74,18 +74,8 @@ static bool IsVanillaImage(const char *pImage)
return false;
}
int CEditor::ms_CheckerTexture;
int CEditor::ms_BackgroundTexture;
int CEditor::ms_CursorTexture;
int CEditor::ms_EntitiesTexture;
const void* CEditor::ms_pUiGotContext;
int CEditor::ms_FrontTexture;
int CEditor::ms_TeleTexture;
int CEditor::ms_SpeedupTexture;
int CEditor::ms_SwitchTexture;
int CEditor::ms_TuneTexture;
ColorHSVA CEditor::ms_PickerColor;
int CEditor::ms_SVPicker;
int CEditor::ms_HuePicker;
@ -98,7 +88,7 @@ enum
CEditorImage::~CEditorImage()
{
m_pEditor->Graphics()->UnloadTexture(m_TexID);
m_pEditor->Graphics()->UnloadTexture(m_Texture);
if(m_pData)
{
free(m_pData);
@ -717,7 +707,7 @@ void CEditor::RenderGrid(CLayerGroup *pGroup)
int XGridOffset = XOffset % m_GridFactor;
int YGridOffset = YOffset % m_GridFactor;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
for(int i = 0; i < (int)w; i++)
@ -742,7 +732,7 @@ void CEditor::RenderGrid(CLayerGroup *pGroup)
Graphics()->LinesEnd();
}
void CEditor::RenderBackground(CUIRect View, int Texture, float Size, float Brightness)
void CEditor::RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness)
{
Graphics()->TextureSet(Texture);
Graphics()->BlendNormal();
@ -2084,7 +2074,7 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
Graphics()->QuadsDraw(&QuadItem, 1);
}
void CEditor::DoQuadEnvelopes(const array<CQuad> &lQuads, int TexID)
void CEditor::DoQuadEnvelopes(const array<CQuad> &lQuads, IGraphics::CTextureHandle Texture)
{
int Num = lQuads.size();
CEnvelope **apEnvelope = new CEnvelope*[Num];
@ -2097,7 +2087,7 @@ void CEditor::DoQuadEnvelopes(const array<CQuad> &lQuads, int TexID)
}
//Draw Lines
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
Graphics()->SetColor(80.0f/255, 150.0f/255, 230.f/255, 0.5f);
for(int j = 0; j < Num; j++)
@ -2125,7 +2115,7 @@ void CEditor::DoQuadEnvelopes(const array<CQuad> &lQuads, int TexID)
Graphics()->LinesEnd();
//Draw Quads
Graphics()->TextureSet(TexID);
Graphics()->TextureSet(Texture);
Graphics()->QuadsBegin();
for(int j = 0; j < Num; j++)
@ -2186,7 +2176,7 @@ void CEditor::DoQuadEnvelopes(const array<CQuad> &lQuads, int TexID)
}
}
Graphics()->QuadsEnd();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
// Draw QuadPoints
@ -2413,7 +2403,7 @@ void CEditor::DoMapEditor(CUIRect View)
{
Graphics()->MapScreen(x, y, x+w, y+h);
m_TilesetPicker.m_Image = t->m_Image;
m_TilesetPicker.m_TexID = t->m_TexID;
m_TilesetPicker.m_Texture = t->m_Texture;
if (m_BrushColorEnabled)
{
m_TilesetPicker.m_Color = t->m_Color;
@ -2516,7 +2506,7 @@ void CEditor::DoMapEditor(CUIRect View)
IGraphics::CLineItem(w, 0, w, h),
IGraphics::CLineItem(w, h, 0, h),
IGraphics::CLineItem(0, h, 0, 0)};
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
Graphics()->LinesDraw(Array, 4);
Graphics()->LinesEnd();
@ -2754,7 +2744,7 @@ void CEditor::DoMapEditor(CUIRect View)
IGraphics::CLineItem(w, 0, w, h),
IGraphics::CLineItem(w, h, 0, h),
IGraphics::CLineItem(0, h, 0, 0)};
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
Graphics()->LinesDraw(Array, 4);
Graphics()->LinesEnd();
@ -2781,7 +2771,7 @@ void CEditor::DoMapEditor(CUIRect View)
if(!m_ShowEnvelopePreview)
m_ShowEnvelopePreview = 2;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
for(int i = 0; i < pLayer->m_lQuads.size(); i++)
{
@ -2797,7 +2787,7 @@ void CEditor::DoMapEditor(CUIRect View)
{
CLayerSounds *pLayer = (CLayerSounds *)pEditLayers[k];
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
for(int i = 0; i < pLayer->m_lSources.size(); i++)
{
@ -2853,7 +2843,7 @@ void CEditor::DoMapEditor(CUIRect View)
CLayerGroup *g = m_Map.m_pGameGroup;
g->MapScreen();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
CUIRect r;
@ -2879,7 +2869,7 @@ void CEditor::DoMapEditor(CUIRect View)
CLayerGroup *g = m_Map.m_pGameGroup;
g->MapScreen();
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
// possible screen sizes (white border)
@ -2957,7 +2947,7 @@ void CEditor::DoMapEditor(CUIRect View)
// tee position (blue circle)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,1,0.3f);
RenderTools()->DrawCircle(m_WorldOffsetX, m_WorldOffsetY, 20.0f, 32);
@ -2970,11 +2960,11 @@ void CEditor::DoMapEditor(CUIRect View)
GetSelectedGroup()->MapScreen();
CLayerQuads *pLayer = (CLayerQuads*)GetSelectedLayer(0);
int TexID = -1;
IGraphics::CTextureHandle Texture;
if(pLayer->m_Image >= 0 && pLayer->m_Image < m_Map.m_lImages.size())
TexID = m_Map.m_lImages[pLayer->m_Image]->m_TexID;
Texture = m_Map.m_lImages[pLayer->m_Image]->m_Texture;
DoQuadEnvelopes(pLayer->m_lQuads, TexID);
DoQuadEnvelopes(pLayer->m_lQuads, Texture);
m_ShowEnvelopePreview = 0;
}
@ -3479,7 +3469,7 @@ void CEditor::ReplaceImage(const char *pFileName, int StorageType, void *pUser)
return;
CEditorImage *pImg = pEditor->m_Map.m_lImages[pEditor->m_SelectedImage];
pEditor->Graphics()->UnloadTexture(pImg->m_TexID);
pEditor->Graphics()->UnloadTexture(pImg->m_Texture);
if(pImg->m_pData)
{
free(pImg->m_pData);
@ -3489,7 +3479,7 @@ void CEditor::ReplaceImage(const char *pFileName, int StorageType, void *pUser)
IStorage::StripPathAndExtension(pFileName, pImg->m_aName, sizeof(pImg->m_aName));
pImg->m_External = IsVanillaImage(pImg->m_aName);
pImg->m_AutoMapper.Load(pImg->m_aName);
pImg->m_TexID = 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, 0);
ImgInfo.m_pData = 0;
pEditor->SortImages();
for(int i = 0; i < pEditor->m_Map.m_lImages.size(); ++i)
@ -3518,7 +3508,7 @@ void CEditor::AddImage(const char *pFileName, int StorageType, void *pUser)
CEditorImage *pImg = new CEditorImage(pEditor);
*pImg = ImgInfo;
pImg->m_TexID = 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, 0);
ImgInfo.m_pData = 0;
pImg->m_External = IsVanillaImage(aBuf);
str_copy(pImg->m_aName, aBuf, sizeof(pImg->m_aName));
@ -3926,7 +3916,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View)
ToolBox.HSplitTop(5.0f, &Slot, &ToolBox);
ImageCur += 5.0f;
IGraphics::CLineItem LineItem(Slot.x, Slot.y+Slot.h/2, Slot.x+Slot.w, Slot.y+Slot.h/2);
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
Graphics()->LinesDraw(&LineItem, 1);
Graphics()->LinesEnd();
@ -3945,7 +3935,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View)
float Max = (float)(maximum(m_Map.m_lImages[i]->m_Width, m_Map.m_lImages[i]->m_Height));
r.w *= m_Map.m_lImages[i]->m_Width/Max;
r.h *= m_Map.m_lImages[i]->m_Height/Max;
Graphics()->TextureSet(m_Map.m_lImages[i]->m_TexID);
Graphics()->TextureSet(m_Map.m_lImages[i]->m_Texture);
Graphics()->BlendNormal();
Graphics()->WrapClamp();
Graphics()->QuadsBegin();
@ -4080,7 +4070,7 @@ void CEditor::RenderSounds(CUIRect ToolBox, CUIRect View)
ToolBox.HSplitTop(5.0f, &Slot, &ToolBox);
SoundCur += 5.0f;
IGraphics::CLineItem LineItem(Slot.x, Slot.y+Slot.h/2, Slot.x+Slot.w, Slot.y+Slot.h/2);
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
Graphics()->LinesDraw(&LineItem, 1);
Graphics()->LinesEnd();
@ -4153,7 +4143,7 @@ void CEditor::AddFileDialogEntry(int Index, CUIRect *pView)
else
m_aFileDialogFileName[0] = 0;
m_FilesSelectedIndex = Index;
m_FilePreviewImage = 0;
m_PreviewImageIsLoaded = false;
if(Input()->MouseDoubleClick())
m_aFileDialogActivate = true;
@ -4321,11 +4311,11 @@ void CEditor::RenderFileDialog()
else
m_aFileDialogFileName[0] = 0;
m_FilesSelectedIndex = NewIndex;
m_FilePreviewImage = 0;
m_PreviewImageIsLoaded = false;
}
}
if(m_FileDialogFileType == CEditor::FILETYPE_IMG && m_FilePreviewImage == 0 && m_FilesSelectedIndex > -1)
if(m_FileDialogFileType == CEditor::FILETYPE_IMG && !m_PreviewImageIsLoaded && m_FilesSelectedIndex > -1)
{
if(str_endswith(m_FileList[m_FilesSelectedIndex].m_aFilename, ".png"))
{
@ -4336,10 +4326,11 @@ void CEditor::RenderFileDialog()
{
m_FilePreviewImage = Graphics()->LoadTextureRaw(m_FilePreviewImageInfo.m_Width, m_FilePreviewImageInfo.m_Height, m_FilePreviewImageInfo.m_Format, m_FilePreviewImageInfo.m_pData, m_FilePreviewImageInfo.m_Format, IGraphics::TEXLOAD_NORESAMPLE);
free(m_FilePreviewImageInfo.m_pData);
m_PreviewImageIsLoaded = true;
}
}
}
if(m_FilePreviewImage)
if(m_PreviewImageIsLoaded)
{
int w = m_FilePreviewImageInfo.m_Width;
int h = m_FilePreviewImageInfo.m_Height;
@ -4501,7 +4492,7 @@ void CEditor::FilelistPopulate(int StorageType)
}
Storage()->ListDirectory(StorageType, m_pFileDialogPath, EditorListdirCallback, this);
m_FilesSelectedIndex = m_FileList.size() ? 0 : -1;
m_FilePreviewImage = 0;
m_PreviewImageIsLoaded = false;
m_aFileDialogActivate = false;
if(m_FilesSelectedIndex >= 0 && !m_FileList[m_FilesSelectedIndex].m_IsDir)
@ -4526,7 +4517,7 @@ void CEditor::InvokeFileDialog(int StorageType, int FileType, const char *pTitle
m_pFileDialogPath = m_aFileDialogCurrentFolder;
m_FileDialogFileType = FileType;
m_FileDialogScrollValue = 0.0f;
m_FilePreviewImage = 0;
m_PreviewImageIsLoaded = false;
if(pDefaultName)
str_copy(m_aFileDialogFileName, pDefaultName, sizeof(m_aFileDialogFileName));
@ -4685,13 +4676,14 @@ void CEditor::RenderUndoList(CUIRect View)
}
if(HoveredIndex != -1)
{
if(m_lUndoSteps[HoveredIndex].m_PreviewImage == 0)
if(!m_lUndoSteps[HoveredIndex].m_PreviewImageIsLoaded)
{
char aBuffer[1024];
str_format(aBuffer, sizeof(aBuffer), "editor/undo_%i.png", m_lUndoSteps[HoveredIndex].m_FileNum);
m_lUndoSteps[HoveredIndex].m_PreviewImage = Graphics()->LoadTexture(aBuffer, IStorage::TYPE_SAVE, CImageInfo::FORMAT_RGB, IGraphics::TEXLOAD_NORESAMPLE);
m_lUndoSteps[HoveredIndex].m_PreviewImageIsLoaded = true;
}
if(m_lUndoSteps[HoveredIndex].m_PreviewImage)
if(m_lUndoSteps[HoveredIndex].m_PreviewImageIsLoaded)
{
Graphics()->TextureSet(m_lUndoSteps[HoveredIndex].m_PreviewImage);
Graphics()->BlendNormal();
@ -4886,10 +4878,10 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
ShowColorBar = true;
View.HSplitTop(20.0f, &ColorBar, &View);
ColorBar.Margin(2.0f, &ColorBar);
RenderBackground(ColorBar, ms_CheckerTexture, 16.0f, 1.0f);
RenderBackground(ColorBar, m_CheckerTexture, 16.0f, 1.0f);
}
RenderBackground(View, ms_CheckerTexture, 32.0f, 0.1f);
RenderBackground(View, m_CheckerTexture, 32.0f, 0.1f);
if(pEnvelope)
{
@ -4992,7 +4984,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
// render lines
{
UI()->ClipEnable(&View);
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
for(int c = 0; c < pEnvelope->m_Channels; c++)
{
@ -5052,7 +5044,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
// render colorbar
if(ShowColorBar)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
for(int i = 0; i < pEnvelope->m_lPoints.size()-1; i++)
{
@ -5108,7 +5100,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
{
int CurrentValue = 0, CurrentTime = 0;
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
for(int c = 0; c < pEnvelope->m_Channels; c++)
{
@ -5338,7 +5330,7 @@ void CEditor::RenderServerSettingsEditor(CUIRect View)
}
View.HSplitTop(2.0f, 0, &View);
RenderBackground(View, ms_CheckerTexture, 32.0f, 0.1f);
RenderBackground(View, m_CheckerTexture, 32.0f, 0.1f);
CUIRect ListBox;
View.Margin(1.0f, &ListBox);
@ -5580,7 +5572,7 @@ void CEditor::Render()
--m_EditBoxActive;
// render checker
RenderBackground(View, ms_CheckerTexture, 32.0f, 1.0f);
RenderBackground(View, m_CheckerTexture, 32.0f, 1.0f);
CUIRect MenuBar, CModeBar, ToolBar, StatusBar, ExtraEditor, UndoList, ToolBox;
m_ShowPicker = Input()->KeyIsPressed(KEY_SPACE) != 0 && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && UI()->LastActiveItem() != &m_CommandBox && m_lSelectedLayers.size() == 1;
@ -5699,17 +5691,17 @@ void CEditor::Render()
if(m_GuiActive)
{
RenderBackground(MenuBar, ms_BackgroundTexture, 128.0f, Brightness*0);
RenderBackground(MenuBar, m_BackgroundTexture, 128.0f, Brightness*0);
MenuBar.Margin(2.0f, &MenuBar);
RenderBackground(ToolBox, ms_BackgroundTexture, 128.0f, Brightness);
RenderBackground(ToolBox, m_BackgroundTexture, 128.0f, Brightness);
ToolBox.Margin(2.0f, &ToolBox);
RenderBackground(ToolBar, ms_BackgroundTexture, 128.0f, Brightness);
RenderBackground(ToolBar, m_BackgroundTexture, 128.0f, Brightness);
ToolBar.Margin(2.0f, &ToolBar);
ToolBar.VSplitLeft(100.0f, &CModeBar, &ToolBar);
RenderBackground(StatusBar, ms_BackgroundTexture, 128.0f, Brightness);
RenderBackground(StatusBar, m_BackgroundTexture, 128.0f, Brightness);
StatusBar.Margin(2.0f, &StatusBar);
}
@ -5745,12 +5737,12 @@ void CEditor::Render()
{
if(m_ShowEnvelopeEditor || m_ShowServerSettingsEditor)
{
RenderBackground(ExtraEditor, ms_BackgroundTexture, 128.0f, Brightness);
RenderBackground(ExtraEditor, m_BackgroundTexture, 128.0f, Brightness);
ExtraEditor.Margin(2.0f, &ExtraEditor);
}
if(m_ShowUndo)
{
RenderBackground(UndoList, ms_BackgroundTexture, 128.0f, Brightness);
RenderBackground(UndoList, m_BackgroundTexture, 128.0f, Brightness);
UndoList.Margin(2.0f, &UndoList);
}
}
@ -5827,7 +5819,7 @@ void CEditor::Render()
// render butt ugly mouse cursor
float mx = UI()->MouseX();
float my = UI()->MouseY();
Graphics()->TextureSet(ms_CursorTexture);
Graphics()->TextureSet(m_CursorTexture);
Graphics()->QuadsBegin();
if(ms_pUiGotContext == UI()->HotItem())
Graphics()->SetColor(1,0,0,1);
@ -5864,7 +5856,7 @@ void CEditor::Reset(bool CreateDefault)
// create default layers
if(CreateDefault)
m_Map.CreateDefault(ms_EntitiesTexture);
m_Map.CreateDefault(m_EntitiesTexture);
SelectLayer(0);
m_lSelectedQuads.clear();
@ -5981,7 +5973,7 @@ void CEditorMap::MakeGameLayer(CLayer *pLayer)
{
m_pGameLayer = (CLayerGame *)pLayer;
m_pGameLayer->m_pEditor = m_pEditor;
m_pGameLayer->m_TexID = m_pEditor->ms_EntitiesTexture;
m_pGameLayer->m_Texture = m_pEditor->m_EntitiesTexture;
}
void CEditorMap::MakeGameGroup(CLayerGroup *pGroup)
@ -6016,7 +6008,7 @@ void CEditorMap::Clean()
m_pTuneLayer = 0x0;
}
void CEditorMap::CreateDefault(int EntitiesTexture)
void CEditorMap::CreateDefault(IGraphics::CTextureHandle EntitiesTexture)
{
// add background
CLayerGroup *pGroup = NewGroup();
@ -6058,16 +6050,16 @@ void CEditor::Init()
m_UI.SetGraphics(m_pGraphics, m_pTextRender);
m_Map.m_pEditor = this;
ms_CheckerTexture = Graphics()->LoadTexture("editor/checker.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
ms_BackgroundTexture = Graphics()->LoadTexture("editor/background.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
ms_CursorTexture = Graphics()->LoadTexture("editor/cursor.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
ms_EntitiesTexture = Graphics()->LoadTexture("editor/entities/DDNet.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
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/DDNet.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
ms_FrontTexture = Graphics()->LoadTexture("editor/front.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
ms_TeleTexture = Graphics()->LoadTexture("editor/tele.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
ms_SpeedupTexture = Graphics()->LoadTexture("editor/speedup.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
ms_SwitchTexture = Graphics()->LoadTexture("editor/switch.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
ms_TuneTexture = Graphics()->LoadTexture("editor/tune.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
m_FrontTexture = Graphics()->LoadTexture("editor/front.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
m_TeleTexture = Graphics()->LoadTexture("editor/tele.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
m_SpeedupTexture = Graphics()->LoadTexture("editor/speedup.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
m_SwitchTexture = Graphics()->LoadTexture("editor/switch.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
m_TuneTexture = Graphics()->LoadTexture("editor/tune.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
m_TilesetPicker.m_pEditor = this;
m_TilesetPicker.MakePalette();
@ -6119,7 +6111,7 @@ void CEditor::CreateUndoStepThread(void *pUser)
NewStep.m_FileNum = pEditor->m_lUndoSteps[pEditor->m_lUndoSteps.size() - 1].m_FileNum + 1;
else
NewStep.m_FileNum = 0;
NewStep.m_PreviewImage = 0;
NewStep.m_PreviewImageIsLoaded = false;
char aBuffer[1024];
str_format(aBuffer, sizeof(aBuffer), "editor/undo_%i.png", NewStep.m_FileNum);
@ -6235,33 +6227,33 @@ void CEditorMap::MakeTeleLayer(CLayer *pLayer)
{
m_pTeleLayer = (CLayerTele *)pLayer;
m_pTeleLayer->m_pEditor = m_pEditor;
m_pTeleLayer->m_TexID = m_pEditor->ms_TeleTexture;
m_pTeleLayer->m_Texture = m_pEditor->m_TeleTexture;
}
void CEditorMap::MakeSpeedupLayer(CLayer *pLayer)
{
m_pSpeedupLayer = (CLayerSpeedup *)pLayer;
m_pSpeedupLayer->m_pEditor = m_pEditor;
m_pSpeedupLayer->m_TexID = m_pEditor->ms_SpeedupTexture;
m_pSpeedupLayer->m_Texture = m_pEditor->m_SpeedupTexture;
}
void CEditorMap::MakeFrontLayer(CLayer *pLayer)
{
m_pFrontLayer = (CLayerFront *)pLayer;
m_pFrontLayer->m_pEditor = m_pEditor;
m_pFrontLayer->m_TexID = m_pEditor->ms_FrontTexture;
m_pFrontLayer->m_Texture = m_pEditor->m_FrontTexture;
}
void CEditorMap::MakeSwitchLayer(CLayer *pLayer)
{
m_pSwitchLayer = (CLayerSwitch *)pLayer;
m_pSwitchLayer->m_pEditor = m_pEditor;
m_pSwitchLayer->m_TexID = m_pEditor->ms_SwitchTexture;
m_pSwitchLayer->m_Texture = m_pEditor->m_SwitchTexture;
}
void CEditorMap::MakeTuneLayer(CLayer *pLayer)
{
m_pTuneLayer = (CLayerTune *)pLayer;
m_pTuneLayer->m_pEditor = m_pEditor;
m_pTuneLayer->m_TexID = m_pEditor->ms_TuneTexture;
m_pTuneLayer->m_Texture = m_pEditor->m_TuneTexture;
}

View file

@ -281,7 +281,6 @@ public:
: m_AutoMapper(pEditor)
{
m_pEditor = pEditor;
m_TexID = -1;
m_aName[0] = 0;
m_External = 0;
m_Width = 0;
@ -294,7 +293,7 @@ public:
void AnalyseTileFlags();
int m_TexID;
IGraphics::CTextureHandle m_Texture;
int m_External;
char m_aName[128];
unsigned char m_aTileFlags[256];
@ -454,7 +453,7 @@ public:
}
void Clean();
void CreateDefault(int EntitiesTexture);
void CreateDefault(IGraphics::CTextureHandle EntitiesTexture);
// io
int Save(class IStorage *pStorage, const char *pFilename);
@ -547,7 +546,7 @@ public:
void FlagModified(int x, int y, int w, int h);
int m_TexID;
IGraphics::CTextureHandle m_Texture;
int m_Game;
int m_Image;
int m_Width;
@ -709,20 +708,10 @@ public:
m_CommandBox = 0.0f;
m_aSettingsCommand[0] = 0;
ms_CheckerTexture = 0;
ms_BackgroundTexture = 0;
ms_CursorTexture = 0;
ms_EntitiesTexture = 0;
ms_pUiGotContext = 0;
// DDRace
ms_FrontTexture = 0;
ms_TeleTexture = 0;
ms_SpeedupTexture = 0;
ms_SwitchTexture = 0;
ms_TuneTexture = 0;
m_TeleNumber = 1;
m_SwitchNum = 1;
m_TuningNum = 1;
@ -754,7 +743,8 @@ public:
int m_FileNum;
int m_ButtonId;
char m_aName[128];
int m_PreviewImage;
IGraphics::CTextureHandle m_PreviewImage;
bool m_PreviewImageIsLoaded;
};
array<CUndo> m_lUndoSteps;
bool m_Undo;
@ -848,7 +838,8 @@ public:
int m_FilesSelectedIndex;
char m_FileDialogNewFolderName[64];
char m_FileDialogErrString[64];
int m_FilePreviewImage;
IGraphics::CTextureHandle m_FilePreviewImage;
bool m_PreviewImageIsLoaded;
CImageInfo m_FilePreviewImageInfo;
@ -913,10 +904,10 @@ public:
int m_SelectedSound;
int m_SelectedSource;
static int ms_CheckerTexture;
static int ms_BackgroundTexture;
static int ms_CursorTexture;
static int ms_EntitiesTexture;
IGraphics::CTextureHandle m_CheckerTexture;
IGraphics::CTextureHandle m_BackgroundTexture;
IGraphics::CTextureHandle m_CursorTexture;
IGraphics::CTextureHandle m_EntitiesTexture;
CLayerGroup m_Brush;
CLayerTiles m_TilesetPicker;
@ -951,7 +942,7 @@ public:
int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden=false, int Corners=CUI::CORNER_ALL);
void RenderBackground(CUIRect View, int Texture, float Size, float Brightness);
void RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness);
void RenderGrid(CLayerGroup *pGroup);
@ -997,7 +988,7 @@ public:
float ButtonColorMul(const void *pID);
void DoQuadEnvelopes(const array<CQuad> &m_lQuads, int TexID = -1);
void DoQuadEnvelopes(const array<CQuad> &m_lQuads, IGraphics::CTextureHandle Texture = IGraphics::CTextureHandle());
void DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int pIndex);
void DoQuadPoint(CQuad *pQuad, int QuadIndex, int v);
@ -1041,11 +1032,11 @@ public:
// DDRace
static int ms_FrontTexture;
static int ms_TeleTexture;
static int ms_SpeedupTexture;
static int ms_SwitchTexture;
static int ms_TuneTexture;
IGraphics::CTextureHandle m_FrontTexture;
IGraphics::CTextureHandle m_TeleTexture;
IGraphics::CTextureHandle m_SpeedupTexture;
IGraphics::CTextureHandle m_SwitchTexture;
IGraphics::CTextureHandle m_TuneTexture;
static int PopupTele(CEditor *pEditor, CUIRect View);
static int PopupSpeedup(CEditor *pEditor, CUIRect View);
static int PopupSwitch(CEditor *pEditor, CUIRect View);

View file

@ -677,7 +677,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_TexID = 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, 0);
ImgInfo.m_pData = 0;
pImg->m_External = 1;
}
@ -692,7 +692,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
void *pData = DataFile.GetData(pItem->m_ImageData);
pImg->m_pData = malloc(pImg->m_Width*pImg->m_Height*4);
mem_copy(pImg->m_pData, pData, pImg->m_Width*pImg->m_Height*4);
pImg->m_TexID = 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, 0);
}
// copy image name

View file

@ -23,9 +23,9 @@ CLayerQuads::~CLayerQuads()
void CLayerQuads::Render(bool QuadPicker)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size())
Graphics()->TextureSet(m_pEditor->m_Map.m_lImages[m_Image]->m_TexID);
Graphics()->TextureSet(m_pEditor->m_Map.m_lImages[m_Image]->m_Texture);
Graphics()->BlendNone();
m_pEditor->RenderTools()->ForceRenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_OPAQUE, m_pEditor->EnvelopeEval, m_pEditor);
@ -93,7 +93,7 @@ void CLayerQuads::BrushSelecting(CUIRect Rect)
IGraphics::CLineItem(Rect.x+Rect.w, Rect.y, Rect.x+Rect.w, Rect.y+Rect.h),
IGraphics::CLineItem(Rect.x+Rect.w, Rect.y+Rect.h, Rect.x, Rect.y+Rect.h),
IGraphics::CLineItem(Rect.x, Rect.y+Rect.h, Rect.x, Rect.y)};
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
Graphics()->LinesDraw(Array, 4);
Graphics()->LinesEnd();

View file

@ -19,7 +19,7 @@ CLayerSounds::~CLayerSounds()
void CLayerSounds::Render(bool Tileset)
{
// TODO: nice texture
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->BlendNormal();
Graphics()->QuadsBegin();
@ -139,7 +139,7 @@ void CLayerSounds::BrushSelecting(CUIRect Rect)
IGraphics::CLineItem(Rect.x+Rect.w, Rect.y, Rect.x+Rect.w, Rect.y+Rect.h),
IGraphics::CLineItem(Rect.x+Rect.w, Rect.y+Rect.h, Rect.x, Rect.y+Rect.h),
IGraphics::CLineItem(Rect.x, Rect.y+Rect.h, Rect.x, Rect.y)};
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
Graphics()->LinesBegin();
Graphics()->LinesDraw(Array, 4);
Graphics()->LinesEnd();

View file

@ -22,7 +22,6 @@ CLayerTiles::CLayerTiles(int w, int h)
m_Width = w;
m_Height = h;
m_Image = -1;
m_TexID = -1;
m_Game = 0;
m_Color.r = 255;
m_Color.g = 255;
@ -83,8 +82,8 @@ void CLayerTiles::MakePalette()
void CLayerTiles::Render(bool Tileset)
{
if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size())
m_TexID = m_pEditor->m_Map.m_lImages[m_Image]->m_TexID;
Graphics()->TextureSet(m_TexID);
m_Texture = m_pEditor->m_Map.m_lImages[m_Image]->m_Texture;
Graphics()->TextureSet(m_Texture);
ColorRGBA Color = ColorRGBA(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,
@ -182,7 +181,7 @@ bool CLayerTiles::IsEmpty(CLayerTiles *pLayer)
void CLayerTiles::BrushSelecting(CUIRect Rect)
{
Graphics()->TextureSet(-1);
Graphics()->TextureClear();
m_pEditor->Graphics()->QuadsBegin();
m_pEditor->Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.4f);
Snap(&Rect);
@ -208,7 +207,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect)
{
CLayerTele *pGrabbed = new CLayerTele(r.w, r.h);
pGrabbed->m_pEditor = m_pEditor;
pGrabbed->m_TexID = m_TexID;
pGrabbed->m_Texture = m_Texture;
pGrabbed->m_Image = m_Image;
pGrabbed->m_Game = m_Game;
if (m_pEditor->m_BrushColorEnabled)
@ -240,7 +239,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect)
{
CLayerSpeedup *pGrabbed = new CLayerSpeedup(r.w, r.h);
pGrabbed->m_pEditor = m_pEditor;
pGrabbed->m_TexID = m_TexID;
pGrabbed->m_Texture = m_Texture;
pGrabbed->m_Image = m_Image;
pGrabbed->m_Game = m_Game;
if (m_pEditor->m_BrushColorEnabled)
@ -278,7 +277,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect)
{
CLayerSwitch *pGrabbed = new CLayerSwitch(r.w, r.h);
pGrabbed->m_pEditor = m_pEditor;
pGrabbed->m_TexID = m_TexID;
pGrabbed->m_Texture = m_Texture;
pGrabbed->m_Image = m_Image;
pGrabbed->m_Game = m_Game;
if (m_pEditor->m_BrushColorEnabled)
@ -329,7 +328,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect)
{
CLayerTune *pGrabbed = new CLayerTune(r.w, r.h);
pGrabbed->m_pEditor = m_pEditor;
pGrabbed->m_TexID = m_TexID;
pGrabbed->m_Texture = m_Texture;
pGrabbed->m_Image = m_Image;
pGrabbed->m_Game = m_Game;
if (m_pEditor->m_BrushColorEnabled)
@ -363,7 +362,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect)
{
CLayerFront *pGrabbed = new CLayerFront(r.w, r.h);
pGrabbed->m_pEditor = m_pEditor;
pGrabbed->m_TexID = m_TexID;
pGrabbed->m_Texture = m_Texture;
pGrabbed->m_Image = m_Image;
pGrabbed->m_Game = m_Game;
if (m_pEditor->m_BrushColorEnabled)
@ -384,7 +383,7 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect)
{
CLayerTiles *pGrabbed = new CLayerTiles(r.w, r.h);
pGrabbed->m_pEditor = m_pEditor;
pGrabbed->m_TexID = m_TexID;
pGrabbed->m_Texture = m_Texture;
pGrabbed->m_Image = m_Image;
pGrabbed->m_Game = m_Game;
if (m_pEditor->m_BrushColorEnabled)
@ -913,7 +912,7 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox)
{
if (NewVal == -1)
{
m_TexID = -1;
m_Texture = IGraphics::CTextureHandle();
m_Image = -1;
}
else

View file

@ -1215,7 +1215,7 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View)
float Max = (float)(maximum(pEditor->m_Map.m_lImages[ShowImage]->m_Width, pEditor->m_Map.m_lImages[ShowImage]->m_Height));
ImageView.w *= pEditor->m_Map.m_lImages[ShowImage]->m_Width/Max;
ImageView.h *= pEditor->m_Map.m_lImages[ShowImage]->m_Height/Max;
pEditor->Graphics()->TextureSet(pEditor->m_Map.m_lImages[ShowImage]->m_TexID);
pEditor->Graphics()->TextureSet(pEditor->m_Map.m_lImages[ShowImage]->m_Texture);
pEditor->Graphics()->BlendNormal();
pEditor->Graphics()->WrapClamp();
pEditor->Graphics()->QuadsBegin();
@ -1581,7 +1581,7 @@ int CEditor::PopupColorPicker(CEditor *pEditor, CUIRect View)
View.VSplitRight(20.0f, &SVPicker, &HuePicker);
HuePicker.VSplitLeft(4.0f, 0x0, &HuePicker);
pEditor->Graphics()->TextureSet(-1);
pEditor->Graphics()->TextureClear();
pEditor->Graphics()->QuadsBegin();
// base: white - hue
@ -1695,8 +1695,8 @@ int CEditor::PopupEntities(CEditor *pEditor, CUIRect View)
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "editor/entities/%s.png", Name);
pEditor->Graphics()->UnloadTexture(ms_EntitiesTexture);
ms_EntitiesTexture = pEditor->Graphics()->LoadTexture(aBuf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
pEditor->Graphics()->UnloadTexture(pEditor->m_EntitiesTexture);
pEditor->m_EntitiesTexture = pEditor->Graphics()->LoadTexture(aBuf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
}
}
}