-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory cache + Biome API #6
base: master
Are you sure you want to change the base?
Conversation
Keep few map in memory for the mapgen to work with. Once discarded the Biome API is used instead. Map generation is even faster this way and it do not require the use of a files on the drive.
I redone the originally proposed changes one by one each one of them on their own branch. The other branch I can do a pull request are. wide-folliage .... This one is specifically meant to be used with wide texture. So I may think about an other way to distribute it with the a texture pack or something. Still i personally think that wider grass look better than default mine-test. |
local map = minetest.decompress(z) | ||
|
||
local map = gt[p] | ||
local mv = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 0
value here is never used. Just use local mv
here. Luacheck will spot this and warn about it otherwise.
local node = minetest.get_node(pos) | ||
node.param2 = cmpy(string.byte(map, l + 1), pos.y) | ||
if map == nil then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not map then
collectgarbage() | ||
tablesize = 0 | ||
end | ||
tablesize = tablesize + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use #gt
to refer to the table size here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine, though, to track size manually.
local wp = minetest.get_worldpath() .. "/luscious" | ||
minetest.mkdir(wp) | ||
gt = {} | ||
tablesize = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should both be local
since they are only used inside this file.
local p = minetest.hash_node_position(v) | ||
if tablesize > 75 then | ||
gt = {} | ||
collectgarbage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely not so bad, but, I think you can avoid calling collectgarbage()
here entirely. I also think that this method of wiping all cache is relatively inefficient, as you're constantly redoing the caches.
A not-so-complex approach is to keep hashing on p
, but not embed only the data in there, but also a timestamp
and delete only old things from the cache.
so gt[p].timestamp
and gt[p].value
.
Then you can walk the array, and erase older values than some limit or threshold.
Perhaps you could even embed a cache hit
counter in the record and use that to eliminate things that get none or little cache hits, and always keep items with lots of cache hits.
When you do that, you want to make sure you don't remove just 1 item and have to re-prune when 1 item is added, just let the cache grow e.g. to 128, and then prune down to 64.
I would avoid calling collectgarbage()
if you can at all times and let the lua VM take care of this, if you can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this part can be improved.
The current code downside is that when the cache is discarded there is a chance to see the biome API called to finish the generation. So about 1 or 2 map every 75 is likely to fall back on the biome API instead.
These biome API calls could be reduce to nearly zero by pruning half the oldest cache instead. Also removing the collectgarbage() would be nice.
I'm very positive about the approach avoiding cache files, btw |
OP is very inactive. These changes should be able to be made without their input (by forking their fork - keeping credit where it's due by retaining their commit.). |
The maps are kept in memory for the mapgen to work with. Once the map are discarded it use the biome api instead.
The initial map generation noticeably faster with memory and no drive IO.
The slower biome api is only used on older world with missing colors or when we do manual change later like adding block planting tree ect...