Skip to content

Commit 70da8a9

Browse files
committedJun 20, 2015
Mapgen objects: Enable heatmap and humidmap for all biome api mapgens
1 parent d7190df commit 70da8a9

File tree

6 files changed

+47
-29
lines changed

6 files changed

+47
-29
lines changed
 

‎src/mapgen.cpp

+20-16
Original file line numberDiff line numberDiff line change
@@ -67,33 +67,37 @@ FlagDesc flagdesc_gennotify[] = {
6767

6868
Mapgen::Mapgen()
6969
{
70-
generating = false;
71-
id = -1;
72-
seed = 0;
73-
water_level = 0;
74-
flags = 0;
75-
76-
vm = NULL;
77-
ndef = NULL;
78-
heightmap = NULL;
79-
biomemap = NULL;
70+
generating = false;
71+
id = -1;
72+
seed = 0;
73+
water_level = 0;
74+
flags = 0;
75+
76+
vm = NULL;
77+
ndef = NULL;
78+
heightmap = NULL;
79+
biomemap = NULL;
80+
heatmap = NULL;
81+
humidmap = NULL;
8082
}
8183

8284

8385
Mapgen::Mapgen(int mapgenid, MapgenParams *params, EmergeManager *emerge) :
8486
gennotify(emerge->gen_notify_on, &emerge->gen_notify_on_deco_ids)
8587
{
86-
generating = false;
87-
id = mapgenid;
88-
seed = (int)params->seed;
89-
water_level = params->water_level;
90-
flags = params->flags;
91-
csize = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE);
88+
generating = false;
89+
id = mapgenid;
90+
seed = (int)params->seed;
91+
water_level = params->water_level;
92+
flags = params->flags;
93+
csize = v3s16(1, 1, 1) * (params->chunksize * MAP_BLOCKSIZE);
9294

9395
vm = NULL;
9496
ndef = NULL;
9597
heightmap = NULL;
9698
biomemap = NULL;
99+
heatmap = NULL;
100+
humidmap = NULL;
97101
}
98102

99103

‎src/mapgen.h

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class Mapgen {
152152
u32 blockseed;
153153
s16 *heightmap;
154154
u8 *biomemap;
155+
float *heatmap;
156+
float *humidmap;
155157
v3s16 csize;
156158

157159
GenerateNotifier gennotify;

‎src/mapgen_v5.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)
5858

5959
this->biomemap = new u8[csize.X * csize.Z];
6060
this->heightmap = new s16[csize.X * csize.Z];
61+
this->heatmap = NULL;
62+
this->humidmap = NULL;
6163

6264
MapgenV5Params *sp = (MapgenV5Params *)params->sparams;
6365
this->spflags = sp->spflags;
@@ -341,6 +343,9 @@ void MapgenV5::calculateNoise()
341343
noise_heat->result[i] += noise_heat_blend->result[i];
342344
noise_humidity->result[i] += noise_humidity_blend->result[i];
343345
}
346+
347+
heatmap = noise_heat->result;
348+
humidmap = noise_humidity->result;
344349
//printf("calculateNoise: %dus\n", t.stop());
345350
}
346351

‎src/mapgen_v5.h

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424

2525
#define LARGE_CAVE_DEPTH -256
2626

27-
/////////////////// Mapgen V5 flags
28-
//#define MGV5_ 0x01
29-
3027
class BiomeManager;
3128

3229
extern FlagDesc flagdesc_mapgen_v5[];

‎src/mapgen_v7.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge)
5959
this->ystride = csize.X;
6060
this->zstride = csize.X * (csize.Y + 2);
6161

62-
this->biomemap = new u8[csize.X * csize.Z];
63-
this->heightmap = new s16[csize.X * csize.Z];
62+
this->biomemap = new u8[csize.X * csize.Z];
63+
this->heightmap = new s16[csize.X * csize.Z];
64+
this->heatmap = NULL;
65+
this->humidmap = NULL;
6466
this->ridge_heightmap = new s16[csize.X * csize.Z];
6567

6668
MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
@@ -376,6 +378,9 @@ void MapgenV7::calculateNoise()
376378
noise_heat->result[i] += noise_heat_blend->result[i];
377379
noise_humidity->result[i] += noise_humidity_blend->result[i];
378380
}
381+
382+
heatmap = noise_heat->result;
383+
humidmap = noise_humidity->result;
379384
//printf("calculateNoise: %dus\n", t.stop());
380385
}
381386

‎src/script/lua_api/l_mapgen.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -510,21 +510,26 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L)
510510

511511
return 1;
512512
}
513-
case MGOBJ_HEATMAP: { // Mapgen V7 specific objects
514-
case MGOBJ_HUMIDMAP:
515-
if (strcmp(emerge->params.mg_name.c_str(), "v7"))
513+
case MGOBJ_HEATMAP: {
514+
if (!mg->heatmap)
516515
return 0;
517516

518-
MapgenV7 *mgv7 = (MapgenV7 *)mg;
517+
lua_newtable(L);
518+
for (size_t i = 0; i != maplen; i++) {
519+
lua_pushnumber(L, mg->heatmap[i]);
520+
lua_rawseti(L, -2, i + 1);
521+
}
522+
523+
return 1;
524+
}
519525

520-
float *arr = (mgobj == MGOBJ_HEATMAP) ?
521-
mgv7->noise_heat->result : mgv7->noise_humidity->result;
522-
if (!arr)
526+
case MGOBJ_HUMIDMAP: {
527+
if (!mg->humidmap)
523528
return 0;
524529

525530
lua_newtable(L);
526531
for (size_t i = 0; i != maplen; i++) {
527-
lua_pushnumber(L, arr[i]);
532+
lua_pushnumber(L, mg->humidmap[i]);
528533
lua_rawseti(L, -2, i + 1);
529534
}
530535

0 commit comments

Comments
 (0)
Please sign in to comment.