SwissalpS / postool

minetest mod to show grid of current map-block (also HUD of position in space and time)
GNU Lesser General Public License v3.0
3 stars 4 forks source link

Biome data extension / Magic numbers #16

Closed Montandalar closed 2 years ago

Montandalar commented 2 years ago

This project extensively uses magic numbers, especially magic is the number 7. I wanted to write a biome data extension but I can't be bothered having to deal with refactoring it to make it number 8 and inserting my new hud flag at position nr. 7. I doubt if using some explanatory variables would hurt performance much.

huds.lua:   if 6 == #sFlags then sFlags[7] = false end
huds.lua:   local bWantsChunk = tDB.tb[7]
huds.lua:   lCount[5] = 0 lCount[6] = 0 lCount[7] = 0
huds.lua:   for i = 1, 7 do
huds.lua:   tDB.tb[7] = not tDB.tb[7]
huds.lua:   return tDB.tb[7]
Montandalar commented 2 years ago

Here is the code for my biomedata component:

postool.getBiomedata = function(oPlayer)
    local pos = oPlayer:get_pos()
    -- Biome data for node below feet, otherwise it may be innacurate due to 
    -- y range limits.
    pos.y = pos.y - 1

    local bd = minetest.get_biome_data(pos)
    return string.format("Biome = %s (%d) Heat=%.2f Humidity=%.2f", minetest.get_biome_name(bd.biome), bd.biome, bd.heat, bd.humidity)
end
SwissalpS commented 2 years ago

Thanks for your input. You can reference the indexes here Yes, it wouldn't hurt much to add textual indexes. However the nature of this mod is to be with as little overhead as possible, so I won't be adding it. It also was not designed to be extended. For an example of a dynamic HUD, see my TMI-CSM (Too Much Information)

I doubt we will add biome information on pandorabox. I have created an adaptation of your idea on a separate branch. You may want to change it here deleting lines 84 to 87 and uncomment the lines under those, to show temperature and humidity.

I removed those as they were making the line too long on small screens.

Feel free to PR to the biomeData branch :)

Montandalar commented 2 years ago

Thank you for writing the biome data extension up, it's more than I expected really :)

Rather than textual indices I was thinking about 'constants' written in SNAKE_CASE, but I'm sure there still a penalty, however small. Lua 5.4 supports constants, but Lua >5.1 gets no LuaJIT, and no love :(.

Thanks for mentioning your CSM as well, however the problem in this particular case is biome data is not available to clients in Minetest. I actually wonder what kind of performance gains might be possible with modchannels sending this kind of into to clients who then run the HUDs purely clientside, but that's all beyond scope.

SwissalpS commented 2 years ago

You are welcome, have fun :D

Modchannels aren't working at all for me. (I did read somewhere that it was possible to make them work)

It's likely that CSMs will get more methods, but that will probably have to wait until CSSM is figured out. That's when this mod will become obsolete and turned into a CSSM. But for that some other mods will have to be updated so that CSSMs can access the methods postool is using.