#1522 closed defect (fixed)
[PATCH] RMS Deep Forest crashes with out of memory
Reported by: | FeXoR | Owned by: | O.Davoodi |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 11 |
Component: | UI & Simulation | Keywords: | patch, fix, rms, rmgen |
Cc: | Patch: |
Description
When generated on large or larger maps with only a few players the random map script fails with out of memory.
Here's a patch that fixes that by reducing the maximum tree density depending on map size and number of players.
Attachments (2)
Change History (7)
by , 12 years ago
Attachment: | deep_forest2012-7-4.zip added |
---|
follow-up: 2 comment:1 by , 12 years ago
Could you please add a comment explaining why the tree density is calculated in this way. It is quite a scary looking formula currently ;).
comment:2 by , 12 years ago
Replying to quantumstate:
Could you please add a comment explaining why the tree density is calculated in this way. It is quite a scary looking formula currently ;).
'maxTreeDensity' is a factor multiplied to other density factors (e.g. to grand the players space for their bases or to add a walkable circle between the players or to grand space for the center temple ruin) all between 0 and 1 that together determine the chance for each tile that a tree/bush (or less common deer) is placed there. If the multipliers calculation for example gives 0.2 for a specific tile there's a 20% chance for that tile to get a tree. Since maxTreeDensity
is not depending on the specific tile but on the map size and the number of players its somehow the maximum tree density that could ever occur on the map (if the tile is far enough away from players bases, the center and the free circle connecting the players start positions).
256x256 (= 65536) is the number of tiles of the biggest map where no out of memory error occurs (medium) when generated with 2 players and maxTreeDensity = 1
. This is scaled down with growing map size dependent on the tiles available on the map: mapSize*mapSize
. When the number of players are lower, however, the number of trees placed grows, too, because less start positions lower the chance for tiles to get a tree to grand the player the space to build his/her base. So I tried a bit and found out that 256*192 (instead of 256*256) works for all maps even if only one player is present. So this value has to be lowered by 256*64 if the number of players is 1 instead of 8 (the only one I tested on giant maps before). So for each player less than 8 this value has be lowered by about 2048 = 256*8. To reduce the tree density according to that the patch adds the bracket including this density reduction:
min(256 * (256 - (8 * (8 - numPlayers))) / mapSize / mapSize, 1)
min(..., 1)
forces the value to not raise the possibility of trees added (otherwise the bases would be full of trees on tiny/small maps).- 256 is the width of the maximum map size everything works fine (medium).
- 256*256 is the number on tiles on such a map.
- / mapSize / mapSize scales the factor down by the actual maps tiles (mapSize*mapSize). That way on every map bigger than 256*256 in average a similar amount of trees will be added (since each map tile has a chance to get a tree, in average the total number of trees will be: average chance*tiles)
- To take into account that less players means more trees placed each player less than 8 reduces the average number on the map by 256*8 (= 2048).
Not sure if that is very clear though x)
It makes perfect sense to me ^^
Perhaps it becomes more clear in another form:
256 * (256 - (8 * (8 - numPlayers))) / mapSize / mapSize
= 256*256 / (mapSize*mapSize) - 256*8 * (8-numPlayers) / (mapSize*mapSize)
With:
256*256
: Tiles of the biggest working mapmapSize*mapSize
: Tiles of the actual map. Everything is scaled down (divided by) with growing current map tiles.8-numPlayers
: Each player below the 8th.256*8
: Factor reduction per player below the 8th. Scaled with current map tiles, too. The players bases have roughly a radius of 25 tiles. That circle covers an area of 25² * PI ~= 2000 ~= 256*8 tiles. That area is covered with roughly 2000 trees more ifmaxTreeDensity = 1
and a player less is present. So each player less needs an average reduction of 2000 trees on medium maps (considering every tile would get a tree which is not true. But it's right for the scaling anyways). Because it's a probability it has to be scaled with the currentmapSize
as well.
I made a test (all with seed 0) and it shows the scaling works fine:
size width tiles entities with: average tree density 8 players 1 player 8 players 1 player tiny 128 16384 430 1827 ~0,026 ~0,112 small 192 36864 1365 5519 ~0,037 ~0,150 medium 256 65536 4862 8604 ~0,074 ~0,131 normal 320 102400 7010 9029 ~0,068 ~0,088 large 384 147456 8295 9439 ~0,056 ~0,064 very l. 448 200704 9213 9777 ~0,046 ~0,049 giant 512 262144 9916 9866 ~0,038 ~0,038
The maximum tree density is reached roughly at medium maps (256*256). Since the scaling ignores the map's shape (it's a circle, not a square) this is not very exact.
comment:5 by , 12 years ago
Keywords: | review removed |
---|---|
Milestone: | Backlog → Alpha 11 |
The rms deep_forest.js/json in a zip file