some cleanup

This commit is contained in:
oy 2014-02-18 18:02:42 +01:00
parent c66f646ae6
commit b668f7faab
10 changed files with 32 additions and 75 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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
{

View file

@ -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)
{

View file

@ -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,

View file

@ -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);
}

View file

@ -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();

View file

@ -359,7 +359,7 @@ public:
}
void Clean();
void CreateDefault(IGraphics::CTextureHandle EntitiesTexture);
void CreateDefault();
// io
int Save(class IStorage *pStorage, const char *pFilename);

View file

@ -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

View file

@ -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); }