This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9664 for ps


Ignore:
Timestamp:
06/26/11 04:56:54 (14 years ago)
Author:
ben
Message:

Changes terrain data returned by CMapGenerator to typed arrays, instead of an array of objects (this greatly reduces the size of the serialized data)

Location:
ps/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/maps/random/rmgen/map.js

    r9435 r9664  
    301301    //  Flat because it's easier to handle by the engine
    302302    var mapSize = size+1;
    303     var height16 = new Array(mapSize*mapSize);      // uint16
     303    var height16 = new Uint16Array(mapSize*mapSize);        // uint16
    304304    for (var x = 0; x < mapSize; x++)
    305305    {
     
    333333   
    334334    //  Convert 2D tile data to flat array
    335     var tiles = new Array(size*size);
     335    var tileIndex = new Uint16Array(size*size);
     336    var tilePriority = new Uint16Array(size*size);
    336337    for (var x = 0; x < size; x++)
    337338    {
     
    339340        {
    340341            // TODO: For now just use the texture's index as priority, might want to do this another way
    341             tiles[z*size + x] = { "idx": this.texture[x][z], "priority": this.texture[x][z] };
    342         }
    343     }
    344     data["tileData"] = tiles;
     342            tileIndex[z*size + x] = this.texture[x][z];
     343            tilePriority[z*size + x] = this.texture[x][z];
     344        }
     345    }
     346    data["tileData"] = {"index": tileIndex, "priority": tilePriority};
    345347   
    346348    return data;
  • ps/trunk/source/graphics/MapReader.cpp

    r9623 r9664  
    11411141    // parse terrain from map data
    11421142    //  an error here should stop the loading process
    1143 #define GET_TERRAIN_PROPERTY(prop, out)\
    1144     if (!pSimulation2->GetScriptInterface().GetProperty(m_MapData.get(), #prop, out))\
     1143#define GET_TERRAIN_PROPERTY(val, prop, out)\
     1144    if (!pSimulation2->GetScriptInterface().GetProperty(val, #prop, out))\
    11451145        {   LOGERROR(L"CMapReader::ParseTerrain() failed to get '%hs' property", #prop);\
    11461146            throw PSERROR_Game_World_MapLoadFailed("Error parsing terrain data.\nCheck application log for details"); }
    11471147
    11481148    u32 size;
    1149     GET_TERRAIN_PROPERTY(size, size)
     1149    GET_TERRAIN_PROPERTY(m_MapData.get(), size, size)
    11501150
    11511151    m_PatchesPerSide = size / PATCH_SIZE;
    11521152
    11531153    // flat heightmap of u16 data
    1154     GET_TERRAIN_PROPERTY(height, m_Heightmap)
     1154    GET_TERRAIN_PROPERTY(m_MapData.get(), height, m_Heightmap)
    11551155
    11561156    // load textures
    11571157    std::vector<std::string> textureNames;
    1158     GET_TERRAIN_PROPERTY(textureNames, textureNames)
     1158    GET_TERRAIN_PROPERTY(m_MapData.get(), textureNames, textureNames)
    11591159    num_terrain_tex = textureNames.size();
    11601160
     
    11711171    m_Tiles.resize(SQR(size));
    11721172
    1173     // flat array of tile descriptors
    1174     std::vector<CMapIO::STileDesc> tileData;
    1175     GET_TERRAIN_PROPERTY(tileData, tileData)
    1176 
    1177     ENSURE(SQR(size) == tileData.size());
     1173    CScriptValRooted tileData;
     1174    GET_TERRAIN_PROPERTY(m_MapData.get(), tileData, tileData)
     1175
     1176    // parse tile data object into flat arrays
     1177    std::vector<u16> tileIndex;
     1178    std::vector<u16> tilePriority;
     1179    GET_TERRAIN_PROPERTY(tileData.get(), index, tileIndex);
     1180    GET_TERRAIN_PROPERTY(tileData.get(), priority, tilePriority);
     1181
     1182    ENSURE(SQR(size) == tileIndex.size() && SQR(size) == tilePriority.size());
    11781183
    11791184    // reorder by patches and store
     
    11871192            size_t offY = y % PATCH_SIZE;
    11881193           
    1189             m_Tiles[(patchY * m_PatchesPerSide + patchX) * SQR(PATCH_SIZE) + (offY * PATCH_SIZE + offX)] = tileData[y*size + x];
     1194            STileDesc tile;
     1195            tile.m_Tex1Index = tileIndex[y*size + x];
     1196            tile.m_Priority = tilePriority[y*size + x];
     1197
     1198            m_Tiles[(patchY * m_PatchesPerSide + patchX) * SQR(PATCH_SIZE) + (offY * PATCH_SIZE + offX)] = tile;
    11901199        }
    11911200    }
  • ps/trunk/source/scriptinterface/ScriptConversions.cpp

    r9271 r9664  
    2121
    2222#include "graphics/Entity.h"
    23 #include "graphics/MapIO.h"
    2423#include "ps/utf16string.h"
    2524#include "ps/CLogger.h"
     
    165164        FAIL("Failed to read Entity.orientation property");
    166165
    167     return true;
    168 }
    169 
    170 template<> bool ScriptInterface::FromJSVal<CMapIO::STileDesc>(JSContext* cx, jsval v, CMapIO::STileDesc& out)
    171 {
    172     JSObject* obj;
    173     if (!JS_ValueToObject(cx, v, &obj) || obj == NULL)
    174         FAIL("Argument must be an object");
    175 
    176     jsval texIdx, priority;
    177     if (!JS_GetProperty(cx, obj, "idx", &texIdx) || !FromJSVal(cx, texIdx, out.m_Tex1Index))
    178         FAIL("Failed to read CMapIO::STileDesc.m_Tex1Index property");
    179     if (!JS_GetProperty(cx, obj, "priority", &priority) || !FromJSVal(cx, priority, out.m_Priority))
    180         FAIL("Failed to read CMapIO::STileDesc.m_Priority property");
    181    
    182166    return true;
    183167}
     
    349333    return FromJSVal_vector(cx, v, out);
    350334}
    351 
    352 template<> bool ScriptInterface::FromJSVal<std::vector<CMapIO::STileDesc> >(JSContext* cx, jsval v, std::vector<CMapIO::STileDesc>& out)
    353 {
    354     return FromJSVal_vector(cx, v, out);
    355 }
Note: See TracChangeset for help on using the changeset viewer.