Bye Bye Client-Side Front Layer T.T ( getting ready for a full rework of the front layer )

Signed-off-by: GreYFoXGTi <GreYFoXGTi@GMaiL.CoM>
This commit is contained in:
GreYFoXGTi 2010-08-27 06:23:34 +02:00
parent 1c491666fa
commit b3736dded4
8 changed files with 8 additions and 315 deletions

View file

@ -369,118 +369,4 @@ void CRenderTools::RenderSpeedupmap(CSpeedupTile *pSpeedup, int w, int h, float
}
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
void CRenderTools::RenderFrontmap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags)
{
//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 pixel size for the tiles
float TilePixelSize = 1024/32.0f;
float FinalTileSize = Scale/(ScreenX1-ScreenX0) * Graphics()->ScreenWidth();
float FinalTilesetScale = FinalTileSize/TilePixelSize;
Graphics()->QuadsBegin();
Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
int StartY = (int)(ScreenY0/Scale)-1;
int StartX = (int)(ScreenX0/Scale)-1;
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++)
{
int mx = x;
int my = y;
if(RenderFlags&TILERENDERFLAG_EXTEND)
{
if(mx<0)
mx = 0;
if(mx>=w)
mx = w-1;
if(my<0)
my = 0;
if(my>=h)
my = h-1;
}
else
{
if(mx<0)
continue; // mx = 0;
if(mx>=w)
continue; // mx = w-1;
if(my<0)
continue; // my = 0;
if(my>=h)
continue; // my = h-1;
}
int c = mx + my*w;
unsigned char Index = pTiles[c].m_Index;
if(Index)
{
unsigned char Flags = pTiles[c].m_Flags;
bool Render = false;
if(Flags&TILEFLAG_OPAQUE)
{
if(RenderFlags&LAYERRENDERFLAG_OPAQUE)
Render = true;
}
else
{
if(RenderFlags&LAYERRENDERFLAG_TRANSPARENT)
Render = true;
}
if(Render)
{
int tx = Index%16;
int ty = Index/16;
int Px0 = tx*(1024/16);
int Py0 = ty*(1024/16);
int Px1 = (tx+1)*(1024/16)-1;
int Py1 = (ty+1)*(1024/16)-1;
float u0 = Nudge + Px0/TexSize+Frac;
float v0 = Nudge + Py0/TexSize+Frac;
float u1 = Nudge + Px1/TexSize-Frac;
float v1 = Nudge + Py1/TexSize-Frac;
if(Flags&TILEFLAG_VFLIP)
{
float Tmp = u0;
u0 = u1;
u1 = Tmp;
}
if(Flags&TILEFLAG_HFLIP)
{
float Tmp = v0;
v0 = v1;
v1 = Tmp;
}
Graphics()->QuadsSetSubset(u0,v0,u1,v1);
IGraphics::CQuadItem QuadItem(x*Scale, y*Scale, Scale, Scale);
Graphics()->QuadsDrawTL(&QuadItem, 1);
}
}
x += pTiles[c].m_Skip;
}
Graphics()->QuadsEnd();
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
}

View file

@ -786,7 +786,7 @@ void CEditor::DoToolbar(CUIRect ToolBar)
static int s_BorderBut = 0;
CLayerTiles *pT = (CLayerTiles *)GetSelectedLayerType(0, LAYERTYPE_TILES);
// no border for tele layer, speedup
// no border for tele layer and speedup
if(pT && (pT->m_Tele || pT->m_Speedup))
pT = 0;
@ -1134,7 +1134,7 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
//UI()->ClipEnable(&view);
}
// render the game, tele, speedup and front above everything else
// render the game, tele and speedup above everything else
if(m_Map.m_pGameGroup->m_Visible)
{
m_Map.m_pGameGroup->MapScreen();
@ -1144,8 +1144,6 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
m_Map.m_pTeleLayer->Render();
if(m_Map.m_pSpeedupLayer && m_Map.m_pSpeedupLayer->m_Visible)
m_Map.m_pSpeedupLayer->Render();
if(m_Map.m_pFrontLayer && m_Map.m_pFrontLayer->m_Visible)
m_Map.m_pFrontLayer->Render();
}
}
@ -3018,13 +3016,6 @@ void CEditorMap::MakeSpeedupLayer(CLayer *pLayer)
m_pSpeedupLayer->m_TexId = m_pEditor->ms_EntitiesTexture;
}
void CEditorMap::MakeFrontLayer(CLayer *pLayer)
{
m_pFrontLayer = (CLayerFront *)pLayer;
m_pFrontLayer->m_pEditor = m_pEditor;
m_pFrontLayer->m_TexId = m_pEditor->ms_EntitiesTexture;
}
void CEditorMap::MakeGameGroup(CLayerGroup *pGroup)
{
m_pGameGroup = pGroup;
@ -3043,7 +3034,6 @@ void CEditorMap::Clean()
m_pGameLayer = 0x0;
m_pTeleLayer = 0x0;
m_pSpeedupLayer = 0x0;
m_pFrontLayer = 0x0;
m_pGameGroup = 0x0;
}
@ -3076,7 +3066,6 @@ void CEditorMap::CreateDefault(int EntitiesTexture)
m_pGameGroup->AddLayer(m_pGameLayer);
m_pTeleLayer = 0x0;
m_pSpeedupLayer = 0x0;
m_pFrontLayer = 0x0;
}
void CEditor::Init()

View file

@ -265,7 +265,6 @@ public:
class CLayerGame *m_pGameLayer;
class CLayerTele *m_pTeleLayer;
class CLayerSpeedup *m_pSpeedupLayer;
class CLayerFront *m_pFrontLayer;
CLayerGroup *m_pGameGroup;
CEnvelope *NewEnvelope(int Channels)
@ -322,7 +321,6 @@ public:
void MakeTeleLayer(CLayer *pLayer);
void MakeSpeedupLayer(CLayer *pLayer);
void MakeFrontLayer(CLayer *pLayer);
};
@ -389,7 +387,6 @@ public:
int m_Game;
int m_Tele;
int m_Speedup;
int m_Front;
int m_Image;
int m_Width;
int m_Height;
@ -458,19 +455,6 @@ public:
virtual void FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect);
};
class CLayerFront : public CLayerTiles
{
public:
CLayerFront(int w, int h);
~CLayerFront();
CTile *m_pFrontTile;
virtual void Resize(int NewW, int NewH);
virtual void BrushDraw(CLayer *pBrush, float wx, float wy);
virtual void FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect);
};
class CEditor : public IEditor
{
class IInput *m_pInput;

View file

@ -286,8 +286,6 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
Item.m_Flags = 2;
else if(pLayer->m_Speedup)
Item.m_Flags = 4;
else if(pLayer->m_Front)
Item.m_Flags = 8;
else
Item.m_Flags = pLayer->m_Game;
Item.m_Image = pLayer->m_Image;
@ -307,14 +305,6 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
Item.m_Speedup = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSpeedupTile), ((CLayerSpeedup *)pLayer)->m_pSpeedupTile);
delete[] Tiles;
}
else if(pLayer->m_Front)
{
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
Item.m_Front = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);//Thanks Sushi Tee
delete[] Tiles;
}
else
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);
df.AddItem(MAPITEMTYPE_LAYER, LayerCount, sizeof(Item), &Item);
@ -532,11 +522,6 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName)
pTiles = new CLayerSpeedup(pTilemapItem->m_Width, pTilemapItem->m_Height);
MakeSpeedupLayer(pTiles);
}
else if(pTilemapItem->m_Flags&8)
{
pTiles = new CLayerFront(pTilemapItem->m_Width, pTilemapItem->m_Height);
MakeFrontLayer(pTiles);
}
else
{
pTiles = new CLayerTiles(pTilemapItem->m_Width, pTilemapItem->m_Height);
@ -583,7 +568,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName)
{
void *pSpeedupData = DataFile.GetData(pTilemapItem->m_Speedup);
mem_copy(((CLayerSpeedup*)pTiles)->m_pSpeedupTile, pSpeedupData, pTiles->m_Width*pTiles->m_Height*sizeof(CSpeedupTile));
for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
{
if(((CLayerSpeedup*)pTiles)->m_pSpeedupTile[i].m_Force > 0)
@ -591,22 +576,9 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName)
else
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = 0;
}
DataFile.UnloadData(pTilemapItem->m_Speedup);
}
else if(pTiles->m_Front)
{
void *pFrontData = DataFile.GetData(pTilemapItem->m_Front);
mem_copy(((CLayerFront*)pTiles)->m_pTiles, pFrontData, pTiles->m_Width*pTiles->m_Height*sizeof(CTile));
/*for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
{
if(((CLayerFront*)pTiles)->m_pFrontTile[i].m_Index)
((CLayerFront*)pTiles)->m_pFrontTile[i].m_Index += ENTITY_OFFSET;
}*/
DataFile.UnloadData(pTilemapItem->m_Front);
}
}
else if(pLayerItem->m_Type == LAYERTYPE_QUADS)
{

View file

@ -22,7 +22,6 @@ CLayerTiles::CLayerTiles(int w, int h)
m_Game = 0;
m_Tele = 0;
m_Speedup = 0;
m_Front = 0;
m_pTiles = new CTile[m_Width*m_Height];
mem_zero(m_pTiles, m_Width*m_Height*sizeof(CTile));
@ -64,8 +63,6 @@ void CLayerTiles::Render()
m_pEditor->RenderTools()->RenderTelemap(((CLayerTele*)this)->m_pTeleTile, m_Width, m_Height, 32.0f);
if(m_Speedup)
m_pEditor->RenderTools()->RenderSpeedupmap(((CLayerSpeedup*)this)->m_pSpeedupTile, m_Width, m_Height, 32.0f);
if(m_Front)
m_pEditor->RenderTools()->RenderFrontmap(((CLayerFront*)this)->m_pFrontTile, m_Width, m_Height, 32.0f, vec4(1,1,1,1), LAYERRENDERFLAG_OPAQUE|LAYERRENDERFLAG_TRANSPARENT);
}
int CLayerTiles::ConvertX(float x) const { return (int)(x/32.0f); }
@ -179,20 +176,6 @@ int CLayerTiles::BrushGrab(CLayerGroup *pBrush, CUIRect Rect)
for(int x = 0; x < r.w; x++)
pGrabbed->m_pSpeedupTile[y*pGrabbed->m_Width+x] = ((CLayerSpeedup*)this)->m_pSpeedupTile[(r.y+y)*m_Width+(r.x+x)];
}
else if(m_pEditor->GetSelectedLayer(0) == m_pEditor->m_Map.m_pFrontLayer)
{
CLayerFront *pGrabbed = new CLayerFront(r.w, r.h);
pGrabbed->m_pEditor = m_pEditor;
pGrabbed->m_TexId = m_TexId;
pGrabbed->m_Image = m_Image;
pBrush->AddLayer(pGrabbed);
// copy the tiles
for(int y = 0; y < r.h; y++)
for(int x = 0; x < r.w; x++)
pGrabbed->m_pTiles[y*pGrabbed->m_Width+x] = m_pTiles[(r.y+y)*m_Width+(r.x+x)];
}
else
{
CLayerTiles *pGrabbed = new CLayerTiles(r.w, r.h);
@ -319,10 +302,6 @@ void CLayerTiles::Resize(int NewW, int NewH)
// resize speedup layer if available
if(m_Game && m_pEditor->m_Map.m_pSpeedupLayer && (m_pEditor->m_Map.m_pSpeedupLayer->m_Width != NewW || m_pEditor->m_Map.m_pSpeedupLayer->m_Height != NewH))
m_pEditor->m_Map.m_pSpeedupLayer->Resize(NewW, NewH);
// resize front layer if available
if(m_Game && m_pEditor->m_Map.m_pFrontLayer && (m_pEditor->m_Map.m_pFrontLayer->m_Width != NewW || m_pEditor->m_Map.m_pFrontLayer->m_Height != NewH))
m_pEditor->m_Map.m_pFrontLayer->Resize(NewW, NewH);
}
@ -332,7 +311,7 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox)
pToolBox->HSplitBottom(12.0f, pToolBox, &Button);
bool InGameGroup = !find_linear(m_pEditor->m_Map.m_pGameGroup->m_lLayers.all(), this).empty();
if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this || m_pEditor->m_Map.m_pFrontLayer == this)
if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this)
InGameGroup = false;
static int s_ColclButton = 0;
if(m_pEditor->DoButton_Editor(&s_ColclButton, Localize("Clear collision"), InGameGroup?0:-1, &Button, 0, Localize("Removes collision from this layer")))
@ -383,7 +362,7 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox)
{0},
};
if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this || m_pEditor->m_Map.m_pFrontLayer == this) // remove the image from the selection if this is the game layer
if(m_pEditor->m_Map.m_pGameLayer == this || m_pEditor->m_Map.m_pTeleLayer == this || m_pEditor->m_Map.m_pSpeedupLayer == this) // remove the image from the selection if this is the game layer
aProps[2].m_pName = 0;
static int s_aIds[NUM_PROPS] = {0};
@ -663,96 +642,3 @@ void CLayerSpeedup::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)
}
}
}
CLayerFront::CLayerFront(int w, int h)
: CLayerTiles(w, h)
{
m_pTypeName = "Front";
m_Front = 1;
m_pFrontTile = new CTile[w*h];
mem_zero(m_pFrontTile, w*h*sizeof(CTile));
}
CLayerFront::~CLayerFront()
{
delete[] m_pFrontTile;
}
void CLayerFront::Resize(int NewW, int NewH)
{
// resize Front data
CTile *pNewFrontData = new CTile[NewW*NewH];
mem_zero(pNewFrontData, NewW*NewH*sizeof(CTile));
// copy old data
for(int y = 0; y < min(NewH, m_Height); y++)
mem_copy(&pNewFrontData[y*NewW], &m_pFrontTile[y*m_Width], min(m_Width, NewW)*sizeof(CTile));
// replace old
delete [] m_pFrontTile;
m_pFrontTile = pNewFrontData;
// resize tile data
CLayerTiles::Resize(NewW, NewH);
// resize gamelayer too
if(m_pEditor->m_Map.m_pGameLayer->m_Width != NewW || m_pEditor->m_Map.m_pGameLayer->m_Height != NewH)
m_pEditor->m_Map.m_pGameLayer->Resize(NewW, NewH);
}
void CLayerFront::BrushDraw(CLayer *pBrush, float wx, float wy)
{
if(m_Readonly)
return;
//
CLayerTiles *l = (CLayerTiles *)pBrush;
int sx = ConvertX(wx);
int sy = ConvertY(wy);
for(int y = 0; y < l->m_Height; y++)
for(int x = 0; x < l->m_Width; x++)
{
int fx = x+sx;
int fy = y+sy;
if(fx<0 || fx >= m_Width || fy < 0 || fy >= m_Height)
continue;
// dont allow tele in and out tiles... same with speedup tile
if(m_pEditor->GetSelectedLayer(0) == m_pEditor->m_Map.m_pFrontLayer && (l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEIN || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_TELEOUT || l->m_pTiles[y*l->m_Width+x].m_Index == TILE_BOOST))
continue;
m_pTiles[fy*m_Width+fx] = l->m_pTiles[y*l->m_Width+x];
}
}
void CLayerFront::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)
{
if(m_Readonly)
return;
int sx = ConvertX(Rect.x);
int sy = ConvertY(Rect.y);
int w = ConvertX(Rect.w);
int h = ConvertY(Rect.h);
CLayerTiles *pLt = static_cast<CLayerTiles*>(pBrush);
for(int y = 0; y <= h; y++)
{
for(int x = 0; x <= w; x++)
{
int fx = x+sx;
int fy = y+sy;
if(fx < 0 || fx >= m_Width || fy < 0 || fy >= m_Height)
continue;
if(Empty)
m_pTiles[fy*m_Width+fx].m_Index = 0;
else
m_pTiles[fy*m_Width+fx] = pLt->m_pTiles[(y*pLt->m_Width + x%pLt->m_Width) % (pLt->m_Width*pLt->m_Height)];
}
}
}

View file

@ -126,23 +126,6 @@ int CEditor::PopupGroup(CEditor *pEditor, CUIRect View)
return 1;
}
}
if(pEditor->GetSelectedGroup()->m_GameGroup && !pEditor->m_Map.m_pFrontLayer)
{
// new frontup layer
View.HSplitBottom(10.0f, &View, &Button);
View.HSplitBottom(12.0f, &View, &Button);
static int s_NewSwitchLayerButton = 0;
if(pEditor->DoButton_Editor(&s_NewSwitchLayerButton, "Add Front Layer", 0, &Button, 0, "Creates a new Front layer"))
{
CLayer *l = new CLayerFront(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
pEditor->m_Map.MakeFrontLayer(l);
pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->AddLayer(l);
pEditor->m_SelectedLayer = pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->m_lLayers.size()-1;
pEditor->m_Brush.Clear();
return 1;
}
}
// new tile layer
View.HSplitBottom(10.0f, &View, &Button);
@ -243,8 +226,6 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View)
pEditor->m_Map.m_pTeleLayer = 0x0;
if(pEditor->GetSelectedLayer(0) == pEditor->m_Map.m_pSpeedupLayer)
pEditor->m_Map.m_pSpeedupLayer = 0x0;
if(pEditor->GetSelectedLayer(0) == pEditor->m_Map.m_pFrontLayer)
pEditor->m_Map.m_pFrontLayer = 0x0;
pEditor->m_Map.m_lGroups[pEditor->m_SelectedGroup]->DeleteLayer(pEditor->m_SelectedLayer);
return 1;
}
@ -269,7 +250,7 @@ int CEditor::PopupLayer(CEditor *pEditor, CUIRect View)
{0},
};
if(pEditor->m_Map.m_pGameLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pTeleLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pSpeedupLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pFrontLayer == pEditor->GetSelectedLayer(0)) // dont use Group and Detail from the selection if this is the game layer
if(pEditor->m_Map.m_pGameLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pTeleLayer == pEditor->GetSelectedLayer(0) || pEditor->m_Map.m_pSpeedupLayer == pEditor->GetSelectedLayer(0)) // dont use Group and Detail from the selection if this is the game layer
{
aProps[0].m_Type = PROPTYPE_NULL;
aProps[2].m_Type = PROPTYPE_NULL;

View file

@ -10,7 +10,6 @@ CLayers::CLayers()
m_pGameLayer = 0;
m_pTeleLayer = 0;
m_pSpeedupLayer = 0;
m_pFrontLayer = 0;
m_pMap = 0;
}
@ -52,8 +51,6 @@ void CLayers::Init(class IKernel *pKernel)
m_pTeleLayer = pTilemap;
if(pTilemap->m_Flags&4)
m_pSpeedupLayer = pTilemap;
if(pTilemap->m_Flags&8)
m_pFrontLayer = pTilemap;
}
}
}

View file

@ -14,7 +14,6 @@ class CLayers
CMapItemLayerTilemap *m_pGameLayer;
CMapItemLayerTilemap *m_pTeleLayer;
CMapItemLayerTilemap *m_pSpeedupLayer;
CMapItemLayerTilemap *m_pFrontLayer;
class IMap *m_pMap;
public:
@ -26,7 +25,6 @@ public:
CMapItemLayerTilemap *GameLayer() const { return m_pGameLayer; }
CMapItemLayerTilemap *TeleLayer() const { return m_pTeleLayer; }
CMapItemLayerTilemap *SpeedupLayer() const { return m_pSpeedupLayer; }
CMapItemLayerTilemap *FrontLayer() const { return m_pFrontLayer; }
CMapItemGroup *GetGroup(int Index) const;
CMapItemLayer *GetLayer(int Index) const;
};