Changes terrain data returned by CMapGenerator to typed arrays, instead of an array of objects (this greatly reduces the size of the serialized data)
This was SVN commit r9664.
This commit is contained in:
parent
d89eafaf83
commit
5bc125a91f
@ -300,7 +300,7 @@ Map.prototype.getMapData = function()
|
||||
// Convert 2D heightmap array to flat array
|
||||
// Flat because it's easier to handle by the engine
|
||||
var mapSize = size+1;
|
||||
var height16 = new Array(mapSize*mapSize); // uint16
|
||||
var height16 = new Uint16Array(mapSize*mapSize); // uint16
|
||||
for (var x = 0; x < mapSize; x++)
|
||||
{
|
||||
for (var z = 0; z < mapSize; z++)
|
||||
@ -332,16 +332,18 @@ Map.prototype.getMapData = function()
|
||||
data["textureNames"] = textureNames;
|
||||
|
||||
// Convert 2D tile data to flat array
|
||||
var tiles = new Array(size*size);
|
||||
var tileIndex = new Uint16Array(size*size);
|
||||
var tilePriority = new Uint16Array(size*size);
|
||||
for (var x = 0; x < size; x++)
|
||||
{
|
||||
for (var z = 0; z < size; z++)
|
||||
{
|
||||
// TODO: For now just use the texture's index as priority, might want to do this another way
|
||||
tiles[z*size + x] = { "idx": this.texture[x][z], "priority": this.texture[x][z] };
|
||||
tileIndex[z*size + x] = this.texture[x][z];
|
||||
tilePriority[z*size + x] = this.texture[x][z];
|
||||
}
|
||||
}
|
||||
data["tileData"] = tiles;
|
||||
data["tileData"] = {"index": tileIndex, "priority": tilePriority};
|
||||
|
||||
return data;
|
||||
};
|
||||
|
@ -1140,22 +1140,22 @@ int CMapReader::ParseTerrain()
|
||||
|
||||
// parse terrain from map data
|
||||
// an error here should stop the loading process
|
||||
#define GET_TERRAIN_PROPERTY(prop, out)\
|
||||
if (!pSimulation2->GetScriptInterface().GetProperty(m_MapData.get(), #prop, out))\
|
||||
#define GET_TERRAIN_PROPERTY(val, prop, out)\
|
||||
if (!pSimulation2->GetScriptInterface().GetProperty(val, #prop, out))\
|
||||
{ LOGERROR(L"CMapReader::ParseTerrain() failed to get '%hs' property", #prop);\
|
||||
throw PSERROR_Game_World_MapLoadFailed("Error parsing terrain data.\nCheck application log for details"); }
|
||||
|
||||
u32 size;
|
||||
GET_TERRAIN_PROPERTY(size, size)
|
||||
GET_TERRAIN_PROPERTY(m_MapData.get(), size, size)
|
||||
|
||||
m_PatchesPerSide = size / PATCH_SIZE;
|
||||
|
||||
// flat heightmap of u16 data
|
||||
GET_TERRAIN_PROPERTY(height, m_Heightmap)
|
||||
GET_TERRAIN_PROPERTY(m_MapData.get(), height, m_Heightmap)
|
||||
|
||||
// load textures
|
||||
std::vector<std::string> textureNames;
|
||||
GET_TERRAIN_PROPERTY(textureNames, textureNames)
|
||||
GET_TERRAIN_PROPERTY(m_MapData.get(), textureNames, textureNames)
|
||||
num_terrain_tex = textureNames.size();
|
||||
|
||||
while (cur_terrain_tex < num_terrain_tex)
|
||||
@ -1170,11 +1170,16 @@ int CMapReader::ParseTerrain()
|
||||
// build tile data
|
||||
m_Tiles.resize(SQR(size));
|
||||
|
||||
// flat array of tile descriptors
|
||||
std::vector<CMapIO::STileDesc> tileData;
|
||||
GET_TERRAIN_PROPERTY(tileData, tileData)
|
||||
CScriptValRooted tileData;
|
||||
GET_TERRAIN_PROPERTY(m_MapData.get(), tileData, tileData)
|
||||
|
||||
ENSURE(SQR(size) == tileData.size());
|
||||
// parse tile data object into flat arrays
|
||||
std::vector<u16> tileIndex;
|
||||
std::vector<u16> tilePriority;
|
||||
GET_TERRAIN_PROPERTY(tileData.get(), index, tileIndex);
|
||||
GET_TERRAIN_PROPERTY(tileData.get(), priority, tilePriority);
|
||||
|
||||
ENSURE(SQR(size) == tileIndex.size() && SQR(size) == tilePriority.size());
|
||||
|
||||
// reorder by patches and store
|
||||
for (size_t x = 0; x < size; ++x)
|
||||
@ -1186,7 +1191,11 @@ int CMapReader::ParseTerrain()
|
||||
size_t patchY = y / PATCH_SIZE;
|
||||
size_t offY = y % PATCH_SIZE;
|
||||
|
||||
m_Tiles[(patchY * m_PatchesPerSide + patchX) * SQR(PATCH_SIZE) + (offY * PATCH_SIZE + offX)] = tileData[y*size + x];
|
||||
STileDesc tile;
|
||||
tile.m_Tex1Index = tileIndex[y*size + x];
|
||||
tile.m_Priority = tilePriority[y*size + x];
|
||||
|
||||
m_Tiles[(patchY * m_PatchesPerSide + patchX) * SQR(PATCH_SIZE) + (offY * PATCH_SIZE + offX)] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "ScriptInterface.h"
|
||||
|
||||
#include "graphics/Entity.h"
|
||||
#include "graphics/MapIO.h"
|
||||
#include "ps/utf16string.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/CStr.h"
|
||||
@ -167,21 +166,6 @@ template<> bool ScriptInterface::FromJSVal<Entity>(JSContext* cx, jsval v, Entit
|
||||
return true;
|
||||
}
|
||||
|
||||
template<> bool ScriptInterface::FromJSVal<CMapIO::STileDesc>(JSContext* cx, jsval v, CMapIO::STileDesc& out)
|
||||
{
|
||||
JSObject* obj;
|
||||
if (!JS_ValueToObject(cx, v, &obj) || obj == NULL)
|
||||
FAIL("Argument must be an object");
|
||||
|
||||
jsval texIdx, priority;
|
||||
if (!JS_GetProperty(cx, obj, "idx", &texIdx) || !FromJSVal(cx, texIdx, out.m_Tex1Index))
|
||||
FAIL("Failed to read CMapIO::STileDesc.m_Tex1Index property");
|
||||
if (!JS_GetProperty(cx, obj, "priority", &priority) || !FromJSVal(cx, priority, out.m_Priority))
|
||||
FAIL("Failed to read CMapIO::STileDesc.m_Priority property");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Primitive types:
|
||||
|
||||
@ -348,8 +332,3 @@ template<> bool ScriptInterface::FromJSVal<std::vector<Entity> >(JSContext* cx,
|
||||
{
|
||||
return FromJSVal_vector(cx, v, out);
|
||||
}
|
||||
|
||||
template<> bool ScriptInterface::FromJSVal<std::vector<CMapIO::STileDesc> >(JSContext* cx, jsval v, std::vector<CMapIO::STileDesc>& out)
|
||||
{
|
||||
return FromJSVal_vector(cx, v, out);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user