Page MenuHomeWildfire Games
Paste P143

Use a bit mask for tiledata
ActivePublic

Authored by lyv on Nov 15 2018, 2:11 PM.
Index: binaries/data/mods/public/maps/random/rmgen/RandomMap.js
===================================================================
--- binaries/data/mods/public/maps/random/rmgen/RandomMap.js (revision 21929)
+++ binaries/data/mods/public/maps/random/rmgen/RandomMap.js (working copy)
@@ -457,21 +457,18 @@
*/
RandomMap.prototype.exportTerrainTextures = function()
{
- let tileIndex = new Uint16Array(Math.square(this.size));
- let tilePriority = new Uint16Array(Math.square(this.size));
+ // Use one u16 array. 8 bits for each
+ let tileData = new Uint16Array(Math.square(this.size));
for (let x = 0; x < this.size; ++x)
for (let z = 0; z < this.size; ++z)
{
// TODO: For now just use the texture's index as priority, might want to do this another way
- tileIndex[z * this.size + x] = this.texture[x][z];
- tilePriority[z * this.size + x] = this.texture[x][z];
+ let val = (this.texture[x][z] << 8) | this.texture[x][z];
+ tileData[z * this.size + x] = val;
}
- return {
- "index": tileIndex,
- "priority": tilePriority
- };
+ return tileData;
};
RandomMap.prototype.ExportMap = function()
Index: source/graphics/MapReader.cpp
===================================================================
--- source/graphics/MapReader.cpp (revision 21929)
+++ source/graphics/MapReader.cpp (working copy)
@@ -1309,16 +1309,11 @@
// build tile data
m_Tiles.resize(SQR(size));
- JS::RootedValue tileData(cx);
- GET_TERRAIN_PROPERTY(m_MapData, tileData, &tileData)
-
// parse tile data object into flat arrays
- std::vector<u16> tileIndex;
- std::vector<u16> tilePriority;
- GET_TERRAIN_PROPERTY(tileData, index, tileIndex);
- GET_TERRAIN_PROPERTY(tileData, priority, tilePriority);
+ std::vector<u16> tileDatas;
+ GET_TERRAIN_PROPERTY(m_MapData, tileData, tileDatas);
- ENSURE(SQR(size) == tileIndex.size() && SQR(size) == tilePriority.size());
+ ENSURE(SQR(size) == tileDatas.size());
// reorder by patches and store
for (size_t x = 0; x < size; ++x)
@@ -1329,11 +1324,12 @@
{
size_t patchY = y / PATCH_SIZE;
size_t offY = y % PATCH_SIZE;
+ u16 tileDataValue = tileDatas[y*size + x];
STileDesc tile;
- tile.m_Tex1Index = tileIndex[y*size + x];
+ tile.m_Tex1Index = (tileDataValue >> 8) & 255;
tile.m_Tex2Index = 0xFFFF;
- tile.m_Priority = tilePriority[y*size + x];
+ tile.m_Priority = tileDataValue & 255;
m_Tiles[(patchY * m_PatchesPerSide + patchX) * SQR(PATCH_SIZE) + (offY * PATCH_SIZE + offX)] = tile;
}

Event Timeline

lyv created this paste.Nov 15 2018, 2:11 PM
lyv added a comment.Nov 15 2018, 2:14 PM

As seen here, ParseTerrain is ~20 ms faster. Total map gen time increased, which may or may not be due to a slighly older svn used for testing the unmodified system. exportTerrainTextures is also negligibly faster. Of course, the end result was same and there is no oos risk.

New system

Total map generation time: 42.029s.
Total entities: 7666, Terrain entities: 6287, Textures: 15.
TIMER| ParseTerrain: 39.8779 ms

Current system

Total map generation time: 40.376s.
Total entities: 7666, Terrain entities: 6287, Textures: 15.
TIMER| ParseTerrain: 59.5032 ms

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

New system

Total map generation time: 40.898s.
Total entities: 7551, Terrain entities: 6177, Textures: 15.
TIMER| ParseTerrain: 44.1158 ms

Current system

Total map generation time: 40.394s.
Total entities: 7551, Terrain entities: 6177, Textures: 15.
TIMER| ParseTerrain: 60.4342 ms

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Current system

Total map generation time: 35.909s.
Total entities: 7551, Terrain entities: 6177, Textures: 15.
exportTerrainTextures: 0.005 s
TIMER| ParseTerrain: 58.872 ms
TIMER| ParseEntities: 4.91293 s

New system

Total map generation time: 36.125s.
Total entities: 7551, Terrain entities: 6177, Textures: 15.
exportTerrainTextures: 0.003 s
TIMER| ParseTerrain: 39.207 ms
TIMER| ParseEntities: 5.00326 s

lyv added a comment.EditedNov 15 2018, 2:22 PM

I should note, that this would also use less memory. Which maybe a good thing or a bad thing. Now, there can only be max 256 textures and 256 priorities.

elexis added a subscriber: elexis.Nov 15 2018, 5:01 PM

Well saving 20ms once per loading screen is indeed negligible, but I appreciate the correct investigation.
Limiting from 65536 to 256 textures at most seems like an unnegligible restriction if we think about an ideal engine.
Better check the greatest problems to tackle first (#5011) - or testing whether serializing the entire terrain is making things more performant - or making rmgen not pass any entity in exportMap for rejoiners.

elexis changed the visibility from "All Users" to "Public (No Login Required)".Mar 20 2019, 4:18 PM