Skip to content

Commit

Permalink
Lua get_biome_data: calc heat and humidity only once
Browse files Browse the repository at this point in the history
  • Loading branch information
kno10 committed Jan 25, 2025
1 parent 282c81f commit ba9d582
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/script/lua_api/l_mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,24 +552,33 @@ int ModApiMapgen::l_get_biome_data(lua_State *L)
if (!biomegen)
return 0;

const Biome *biome = biomegen->calcBiomeAtPoint(pos);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;

lua_newtable(L);

lua_pushinteger(L, biome->index);
lua_setfield(L, -2, "biome");

if (biomegen->getType() == BIOMEGEN_ORIGINAL) {
float heat = ((BiomeGenOriginal*) biomegen)->calcHeatAtPoint(pos);
float humidity = ((BiomeGenOriginal*) biomegen)->calcHumidityAtPoint(pos);
const Biome *biome = ((BiomeGenOriginal*) biomegen)->calcBiomeFromNoise(heat, humidity, pos);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;

lua_newtable(L);

lua_pushinteger(L, biome->index);
lua_setfield(L, -2, "biome");

lua_pushnumber(L, heat);
lua_setfield(L, -2, "heat");

lua_pushnumber(L, humidity);
lua_setfield(L, -2, "humidity");

} else {
const Biome *biome = biomegen->calcBiomeAtPoint(pos);
if (!biome || biome->index == OBJDEF_INVALID_INDEX)
return 0;

lua_newtable(L);

lua_pushinteger(L, biome->index);
lua_setfield(L, -2, "biome");
}

return 1;
Expand Down

0 comments on commit ba9d582

Please sign in to comment.