Skip to content

Commit

Permalink
Use game data for edges
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Dec 30, 2017
1 parent bbcfdbc commit 6301bb8
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 490 deletions.
8 changes: 8 additions & 0 deletions CGame_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "CSurface.h"
#include "callbacks.h"
#include "globals.h"
#include "lua/GameDataLoader.h"
#include <boost/assign/std/vector.hpp>
#include <boost/foreach.hpp>
#include <iostream>
Expand Down Expand Up @@ -81,6 +82,13 @@ bool CGame::Init()
surfSplash, 0, 0, surfSplash->w - 1, 0, 0, surfSplash->h - 1, surfSplash->w - 1, surfSplash->h - 1);
SDL_Flip(Surf_Display);

GameDataLoader gdLoader(global::worldDesc);
if(!gdLoader.Load())
{
std::cerr << "Failed to load game data!" << std::endl;
return false;
}

// continue loading pictures
using namespace boost::assign;
std::vector<std::string> paths;
Expand Down
23 changes: 8 additions & 15 deletions CIO/CFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ bool CFile::open_gou()

bobMAP* CFile::open_wld()
{
bobMAP* myMap = (bobMAP*)malloc(sizeof(bobMAP));
bobMAP* myMap = new bobMAP();

if(myMap == NULL)
return myMap;
Expand Down Expand Up @@ -573,11 +573,7 @@ bobMAP* CFile::open_wld()
CHECK_READ(libendian::le_read_us(&myMap->width, fp));
CHECK_READ(libendian::le_read_us(&myMap->height, fp));

if((myMap->vertex = (MapNode*)malloc(sizeof(MapNode) * myMap->width * myMap->height)) == NULL)
{
free(myMap);
return NULL;
}
myMap->vertex.resize(myMap->width * myMap->height);

// go to altitude information (we skip the 16 bytes long map data header that each block has)
fseek(fp, 16, SEEK_CUR);
Expand Down Expand Up @@ -1045,8 +1041,7 @@ bool CFile::read_bob02()
}

// array for start adresses of picture lines
if((starts = (Uint16*)malloc(bmpArray->h * sizeof(Uint16))) == NULL)
return false;
starts = new Uint16[bmpArray->h];

// read start adresses
for(int y = 0; y < bmpArray->h; y++)
Expand Down Expand Up @@ -1114,7 +1109,7 @@ bool CFile::read_bob02()
// increment bmpArray for the next picture
bmpArray++;

free(starts);
delete[] starts;

return true;
}
Expand Down Expand Up @@ -1216,8 +1211,7 @@ bool CFile::read_bob04(int player_color)
}

// array for start adresses of picture lines
if((starts = (Uint16*)malloc(bmpArray->h * sizeof(Uint16))) == NULL)
return false;
starts = new Uint16[bmpArray->h];

// read start adresses
for(int y = 0; y < bmpArray->h; y++)
Expand Down Expand Up @@ -1289,7 +1283,7 @@ bool CFile::read_bob04(int player_color)
// increment bmpArray for the next picture
bmpArray++;

free(starts);
delete[] starts;

return true;
}
Expand Down Expand Up @@ -1356,8 +1350,7 @@ bool CFile::read_bob07()
}

// array for start adresses of picture lines
if((starts = (Uint16*)malloc(shadowArray->h * sizeof(Uint16))) == NULL)
return false;
starts = new Uint16[shadowArray->h];

// read start adresses
for(int y = 0; y < shadowArray->h; y++)
Expand Down Expand Up @@ -1428,7 +1421,7 @@ bool CFile::read_bob07()
// increment shadowArray
shadowArray++;

free(starts);
delete[] starts;

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ENDIF()

add_executable(s25edit ${MAIN_SOURCES} ${CIO_SOURCES} ${icon_RC})

target_link_libraries(s25edit SGE rttrConfig s25Common endian nowide-static ${SDL_LIBRARY})
target_link_libraries(s25edit SGE rttrConfig s25Common gamedata endian nowide-static ${SDL_LIBRARY})

if(MINGW)
target_link_libraries(s25edit -mconsole)
Expand Down
73 changes: 40 additions & 33 deletions CMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void CMap::constructMap(const std::string& filename, int width, int height, int
for(int j = -MAX_CHANGE_SECTION; j <= MAX_CHANGE_SECTION - 1; j++)
VertexCounter++;
}
Vertices = (struct cursorPoint*)malloc(VertexCounter * sizeof(struct cursorPoint));
Vertices.resize(VertexCounter);
calculateVertices();
setupVerticesActivity();
mode = EDITOR_MODE_HEIGHT_RAISE;
Expand All @@ -129,12 +129,10 @@ void CMap::constructMap(const std::string& filename, int width, int height, int
MaxRaiseHeight = 0x3C;
MinReduceHeight = 0x00;
saveCurrentVertices = false;
if((CurrPtr_savedVertices = (struct savedVertices*)malloc(sizeof(struct savedVertices))) != NULL)
{
CurrPtr_savedVertices->empty = true;
CurrPtr_savedVertices->prev = NULL;
CurrPtr_savedVertices->next = NULL;
}
CurrPtr_savedVertices = new SavedVertices;
CurrPtr_savedVertices->empty = true;
CurrPtr_savedVertices->prev = NULL;
CurrPtr_savedVertices->next = NULL;

// we count the players, cause the original editor writes number of players to header no matter if they are set or not
int CountPlayers = 0;
Expand Down Expand Up @@ -175,6 +173,26 @@ void CMap::constructMap(const std::string& filename, int width, int height, int

HorizontalMovementLocked = false;
VerticalMovementLocked = false;

DescIdx<LandscapeDesc> lt(0);
for(DescIdx<LandscapeDesc> i(0); i.value < global::worldDesc.landscapes.size(); i.value++)
{
if(global::worldDesc.get(i).s2Id == map->type)
{
lt = i;
break;
}
}
for(DescIdx<TerrainDesc> i(0); i.value < global::worldDesc.terrain.size(); i.value++)
{
const TerrainDesc& t = global::worldDesc.get(i);
if(t.landscape == lt)
{
if(map->s2IdToTerrain.size() <= t.s2Id)
map->s2IdToTerrain.resize(t.s2Id + 1);
map->s2IdToTerrain[t.s2Id] = i;
}
}
}
void CMap::destructMap()
{
Expand All @@ -192,9 +210,9 @@ void CMap::destructMap()
while(CurrPtr_savedVertices->prev != NULL)
{
CurrPtr_savedVertices = CurrPtr_savedVertices->prev;
free(CurrPtr_savedVertices->next);
delete CurrPtr_savedVertices->next;
}
free(CurrPtr_savedVertices);
delete CurrPtr_savedVertices;
}
// free the map surface
SDL_FreeSurface(Surf_Map);
Expand All @@ -203,16 +221,14 @@ void CMap::destructMap()
SDL_FreeSurface(Surf_RightMenubar);
Surf_RightMenubar = NULL;
// free vertex array
free(Vertices);
// free vertex memory
free(map->vertex);
Vertices.clear();
// free map structure memory
free(map);
delete map;
}

bobMAP* CMap::generateMap(int width, int height, int type, int texture, int border, int border_texture)
{
bobMAP* myMap = (bobMAP*)malloc(sizeof(bobMAP));
bobMAP* myMap = new bobMAP();
if(!myMap)
return NULL;

Expand All @@ -230,11 +246,7 @@ bobMAP* CMap::generateMap(int width, int height, int type, int texture, int bord
myMap->HQy[i] = 0xFFFF;
}

if((myMap->vertex = (MapNode*)malloc(sizeof(MapNode) * myMap->width * myMap->height)) == NULL)
{
free(myMap);
return NULL;
}
myMap->vertex.resize(myMap->width * myMap->height);

for(int j = 0; j < myMap->height; j++)
{
Expand Down Expand Up @@ -275,9 +287,7 @@ bobMAP* CMap::generateMap(int width, int height, int type, int texture, int bord
void CMap::rotateMap()
{
// we allocate memory for the new triangle field but with x equals the height and y equals the width
MapNode* new_vertex = NULL;
if((new_vertex = (MapNode*)malloc(map->height * map->width * sizeof(MapNode))) == NULL)
return;
std::vector<MapNode> new_vertex(map->vertex.size());

// free concatenated list for "undo" and "do"
if(CurrPtr_savedVertices != NULL)
Expand All @@ -291,7 +301,7 @@ void CMap::rotateMap()
while(CurrPtr_savedVertices->prev != NULL)
{
CurrPtr_savedVertices = CurrPtr_savedVertices->prev;
free(CurrPtr_savedVertices->next);
delete CurrPtr_savedVertices->next;
}
CurrPtr_savedVertices->next = NULL;
}
Expand All @@ -306,8 +316,7 @@ void CMap::rotateMap()
}

// release old map and point to new
free(map->vertex);
map->vertex = new_vertex;
std::swap(map->vertex, new_vertex);

// permute width and height
Uint16 tmp_height = map->height;
Expand Down Expand Up @@ -1151,7 +1160,7 @@ void CMap::render()
if(modify)
modifyVertex();

if(map->vertex != NULL)
if(!map->vertex.empty())
CSurface::DrawTriangleField(Surf_Map, displayRect, map);

// draw pictures to cursor position
Expand Down Expand Up @@ -1538,13 +1547,11 @@ void CMap::modifyVertex()
}
if(CurrPtr_savedVertices->next == NULL)
{
if((CurrPtr_savedVertices->next = (struct savedVertices*)malloc(sizeof(struct savedVertices))) != NULL)
{
CurrPtr_savedVertices->next->empty = true;
CurrPtr_savedVertices->next->prev = CurrPtr_savedVertices;
CurrPtr_savedVertices->next->next = NULL;
CurrPtr_savedVertices = CurrPtr_savedVertices->next;
}
CurrPtr_savedVertices->next = new SavedVertices;
CurrPtr_savedVertices->next->empty = true;
CurrPtr_savedVertices->next->prev = CurrPtr_savedVertices;
CurrPtr_savedVertices->next->next = NULL;
CurrPtr_savedVertices = CurrPtr_savedVertices->next;
} else
CurrPtr_savedVertices = CurrPtr_savedVertices->next;
}
Expand Down
8 changes: 4 additions & 4 deletions CMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CMap
bool modify;
// necessary for "undo"- and "do"-function
bool saveCurrentVertices;
struct savedVertices
struct SavedVertices
{
bool empty;
int VertexX, VertexY;
Expand All @@ -41,8 +41,8 @@ class CMap
// this ranges up to 10 vertices
//+ 2 because modifications on a vertex will touch building and shading around
MapNode PointsArroundVertex[((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1) * ((MAX_CHANGE_SECTION + 10 + 2) * 2 + 1)];
struct savedVertices* prev;
struct savedVertices* next;
struct SavedVertices* prev;
struct SavedVertices* next;
} * CurrPtr_savedVertices;
// get the number of the triangle nearest to cursor and save it to VertexX and VertexY
void saveVertex(Uint16 MouseX, Uint16 MouseY, Uint8 MouseState);
Expand All @@ -67,7 +67,7 @@ class CMap
// counts how many vertices we have around the cursor (and including the cursor)
int VertexCounter;
// array to store all vertices (editor mode) --> after constructing class CMap this will have 'VertexCounter' elements
struct cursorPoint* Vertices;
std::vector<cursorPoint> Vertices;
// these are the new (internal) values for player positions (otherwise we had to walk through the objectXXXX-Blocks step by step)
Uint16 PlayerHQx[MAXPLAYERS];
Uint16 PlayerHQy[MAXPLAYERS];
Expand Down
Loading

0 comments on commit 6301bb8

Please sign in to comment.