Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leucome
Copy link

@leucome leucome commented Dec 30, 2019

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...

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.
@leucome
Copy link
Author

leucome commented Dec 30, 2019

I redone the originally proposed changes one by one each one of them on their own branch.
This one is the principal change with the addition of the biome API.

The other branch I can do a pull request are.
new-node (additional default game node)
ethereal-node (Like the name suggest, some ethereal node)
Fix-for-leaf (make sure that color 0 and 1 are never used)

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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?

Copy link
Owner

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
Copy link
Owner

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()
Copy link
Owner

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.

Copy link
Author

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.

@sofar
Copy link
Owner

sofar commented Jan 8, 2020

I'm very positive about the approach avoiding cache files, btw

@Lazerbeak12345
Copy link

Lazerbeak12345 commented Nov 29, 2022

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.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants