- Timestamp:
- 06/26/11 04:56:54 (14 years ago)
- Location:
- ps/trunk
- Files:
-
- 3 edited
-
binaries/data/mods/public/maps/random/rmgen/map.js (modified) (3 diffs)
-
source/graphics/MapReader.cpp (modified) (3 diffs)
-
source/scriptinterface/ScriptConversions.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/maps/random/rmgen/map.js
r9435 r9664 301 301 // Flat because it's easier to handle by the engine 302 302 var mapSize = size+1; 303 var height16 = new Array(mapSize*mapSize); // uint16303 var height16 = new Uint16Array(mapSize*mapSize); // uint16 304 304 for (var x = 0; x < mapSize; x++) 305 305 { … … 333 333 334 334 // 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); 336 337 for (var x = 0; x < size; x++) 337 338 { … … 339 340 { 340 341 // 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}; 345 347 346 348 return data; -
ps/trunk/source/graphics/MapReader.cpp
r9623 r9664 1141 1141 // parse terrain from map data 1142 1142 // 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))\ 1145 1145 { LOGERROR(L"CMapReader::ParseTerrain() failed to get '%hs' property", #prop);\ 1146 1146 throw PSERROR_Game_World_MapLoadFailed("Error parsing terrain data.\nCheck application log for details"); } 1147 1147 1148 1148 u32 size; 1149 GET_TERRAIN_PROPERTY( size, size)1149 GET_TERRAIN_PROPERTY(m_MapData.get(), size, size) 1150 1150 1151 1151 m_PatchesPerSide = size / PATCH_SIZE; 1152 1152 1153 1153 // flat heightmap of u16 data 1154 GET_TERRAIN_PROPERTY( height, m_Heightmap)1154 GET_TERRAIN_PROPERTY(m_MapData.get(), height, m_Heightmap) 1155 1155 1156 1156 // load textures 1157 1157 std::vector<std::string> textureNames; 1158 GET_TERRAIN_PROPERTY( textureNames, textureNames)1158 GET_TERRAIN_PROPERTY(m_MapData.get(), textureNames, textureNames) 1159 1159 num_terrain_tex = textureNames.size(); 1160 1160 … … 1171 1171 m_Tiles.resize(SQR(size)); 1172 1172 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()); 1178 1183 1179 1184 // reorder by patches and store … … 1187 1192 size_t offY = y % PATCH_SIZE; 1188 1193 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; 1190 1199 } 1191 1200 } -
ps/trunk/source/scriptinterface/ScriptConversions.cpp
r9271 r9664 21 21 22 22 #include "graphics/Entity.h" 23 #include "graphics/MapIO.h"24 23 #include "ps/utf16string.h" 25 24 #include "ps/CLogger.h" … … 165 164 FAIL("Failed to read Entity.orientation property"); 166 165 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 182 166 return true; 183 167 } … … 349 333 return FromJSVal_vector(cx, v, out); 350 334 } 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.
