mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-08-03 09:46:41 -04:00
Update spawn algorithm for 1.21.2 + cmake + more
* added basic support for cmake (#127) * renamed Winter Drop version from MC_1_21_3 to MC_1_21_WD * updated world spawn location for 1.21.2 (cubiomes-viewer #340) * tweaked mc version to text conversion (#128) * removed properties field in structure config and added dimension field instead * moved biome tree selection back to biomenoise.c as it's slightly faster and avoids globals
This commit is contained in:
parent
6d1a190fe6
commit
89df24c3be
10
README.md
10
README.md
@ -61,15 +61,15 @@ int main()
|
|||||||
You can compile this code either by directly adding a target to the makefile via
|
You can compile this code either by directly adding a target to the makefile via
|
||||||
```
|
```
|
||||||
$ cd cubiomes
|
$ cd cubiomes
|
||||||
$ make libcubiomes
|
$ make
|
||||||
```
|
```
|
||||||
...or you can compile and link to a cubiomes archive using either of the following commands.
|
...or you can compile and link to a cubiomes archive using either of the following commands.
|
||||||
```
|
```
|
||||||
$ gcc find_biome_at.c libcubiomes.a -fwrapv -lm # static
|
$ gcc find_biome_at.c libcubiomes.a -fwrapv -lm # static
|
||||||
$ gcc find_biome_at.c -L. -lcubiomes -fwrapv -lm # dynamic
|
$ gcc find_biome_at.c -L. -lcubiomes -fwrapv -lm # dynamic
|
||||||
```
|
```
|
||||||
Both commands assume that your source code is saved as `find_biome_at.c` in the cubiomes working directory. If your makefile is configured to use pthreads, you may also need to add the `-lpthread` option to the compiler.
|
Both commands assume that your source code is saved as `find_biome_at.c` in the cubiomes working directory. If your makefile is configured to use pthreads, you may also need to add the `-lpthread` option for the compiler.
|
||||||
The option `-fwrapv` enforces two's complement for signed integer overflow, which this library relies on. It is not strictly necessary for this example as the library should already be compiled with this flag, but it is good practice to prevent undefined behaviour.
|
The option `-fwrapv` enforces two's complement for signed integer overflow, which is otherwise undefined behavior. It is not really necessary for this example, but it is a common pitfall when dealing with code that emulates the behavior of Java.
|
||||||
Running the program should output:
|
Running the program should output:
|
||||||
```
|
```
|
||||||
$ ./a.out
|
$ ./a.out
|
||||||
@ -78,9 +78,9 @@ Seed 262 has a Mushroom Fields biome at block position (0, 0).
|
|||||||
|
|
||||||
### Biome Generation in a Range
|
### Biome Generation in a Range
|
||||||
|
|
||||||
We can also generate biomes for an area or volume using `genBiomes()`. This will utilize whatever optimizations are available for the generator and can be much faster than generating each position individually. (The layered generators for versions up to 1.17 will benefit significantly more from this than the noise-based ones.)
|
We can also generate biomes for an area or volume using `genBiomes()`. This will utilize whatever optimizations are available for the generator, which can be much faster than generating each position individually. (The layered generators for versions up to 1.17 will benefit significantly more from this than the noise-based ones.)
|
||||||
|
|
||||||
Before we can generate the biomes for an area or volume, we need to define the bounds with a `Range` structure and allocate the necessary buffer using `allocCache()`. The `Range` is described by a scale, position, and size, where each cell inside the `Range` represents the `scale` of many blocks in the horizontal axes. The vertical direction is treated separately and always follows the biome coordinate scaling of 1:4, except for when `scale == 1`, in which case the vertical scaling is also 1:1.
|
Before we can generate the biomes for an area or volume, we need to define the bounds with a `Range` structure and allocate the necessary buffer using `allocCache()`. The `Range` is described by a scale, position, and size, where each cell inside the `Range` represents an amount of `scale` blocks in the horizontal axes. The vertical direction is treated separately and always follows the biome coordinate scaling of 1:4, except for when `scale == 1`, in which case the vertical scaling is also 1:1.
|
||||||
|
|
||||||
The only supported values for `scale` are 1, 4, 16, 64, and (for the Overworld) 256. For versions up to 1.17, the scale is matched to an appropriate biome layer and will influence the biomes that can generate.
|
The only supported values for `scale` are 1, 4, 16, 64, and (for the Overworld) 256. For versions up to 1.17, the scale is matched to an appropriate biome layer and will influence the biomes that can generate.
|
||||||
|
|
||||||
|
70
biomenoise.c
70
biomenoise.c
@ -1,5 +1,11 @@
|
|||||||
#include "biomenoise.h"
|
#include "biomenoise.h"
|
||||||
|
|
||||||
|
#include "tables/btree18.h"
|
||||||
|
#include "tables/btree192.h"
|
||||||
|
#include "tables/btree19.h"
|
||||||
|
#include "tables/btree20.h"
|
||||||
|
#include "tables/btree21wd.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -1359,9 +1365,7 @@ int getOldBetaBiome(float t, float h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if !DEBUG
|
static
|
||||||
static inline ATTR(hot, pure, always_inline)
|
|
||||||
#endif
|
|
||||||
uint64_t get_np_dist(const uint64_t np[6], const BiomeTree *bt, int idx)
|
uint64_t get_np_dist(const uint64_t np[6], const BiomeTree *bt, int idx)
|
||||||
{
|
{
|
||||||
uint64_t ds = 0, node = bt->nodes[idx];
|
uint64_t ds = 0, node = bt->nodes[idx];
|
||||||
@ -1380,9 +1384,7 @@ uint64_t get_np_dist(const uint64_t np[6], const BiomeTree *bt, int idx)
|
|||||||
return ds;
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !DEBUG
|
static
|
||||||
static inline ATTR(hot, pure)
|
|
||||||
#endif
|
|
||||||
int get_resulting_node(const uint64_t np[6], const BiomeTree *bt, int idx,
|
int get_resulting_node(const uint64_t np[6], const BiomeTree *bt, int idx,
|
||||||
int alt, uint64_t ds, int depth)
|
int alt, uint64_t ds, int depth)
|
||||||
{
|
{
|
||||||
@ -1428,28 +1430,56 @@ int get_resulting_node(const uint64_t np[6], const BiomeTree *bt, int idx,
|
|||||||
return leaf;
|
return leaf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ATTR(hot, flatten)
|
||||||
int climateToBiome(int mc, const uint64_t np[6], uint64_t *dat)
|
int climateToBiome(int mc, const uint64_t np[6], uint64_t *dat)
|
||||||
{
|
{
|
||||||
if (mc < MC_1_18 || mc > MC_NEWEST)
|
static const BiomeTree btree18 = {
|
||||||
return -1;
|
btree18_steps, &btree18_param[0][0], btree18_nodes, btree18_order,
|
||||||
|
sizeof(btree18_nodes) / sizeof(uint64_t)
|
||||||
const BiomeTree *bt = &g_btree[mc - MC_1_18];
|
};
|
||||||
int alt = 0;
|
static const BiomeTree btree192 = {
|
||||||
|
btree192_steps, &btree192_param[0][0], btree192_nodes, btree192_order,
|
||||||
|
sizeof(btree192_nodes) / sizeof(uint64_t)
|
||||||
|
};
|
||||||
|
static const BiomeTree btree19 = {
|
||||||
|
btree19_steps, &btree19_param[0][0], btree19_nodes, btree19_order,
|
||||||
|
sizeof(btree19_nodes) / sizeof(uint64_t)
|
||||||
|
};
|
||||||
|
static const BiomeTree btree20 = {
|
||||||
|
btree20_steps, &btree20_param[0][0], btree20_nodes, btree20_order,
|
||||||
|
sizeof(btree20_nodes) / sizeof(uint64_t)
|
||||||
|
};
|
||||||
|
static const BiomeTree btree21wd = {
|
||||||
|
btree21wd_steps, &btree21wd_param[0][0], btree21wd_nodes, btree21wd_order,
|
||||||
|
sizeof(btree21wd_nodes) / sizeof(uint64_t)
|
||||||
|
};
|
||||||
|
|
||||||
|
const BiomeTree *bt;
|
||||||
int idx;
|
int idx;
|
||||||
uint64_t ds = -1;
|
|
||||||
|
if (mc >= MC_1_21_WD)
|
||||||
|
bt = &btree21wd;
|
||||||
|
else if (mc >= MC_1_20_6)
|
||||||
|
bt = &btree20;
|
||||||
|
else if (mc >= MC_1_19_4)
|
||||||
|
bt = &btree19;
|
||||||
|
else if (mc >= MC_1_19_2)
|
||||||
|
bt = &btree192;
|
||||||
|
else
|
||||||
|
bt = &btree18;
|
||||||
|
|
||||||
if (dat)
|
if (dat)
|
||||||
{
|
{
|
||||||
alt = (int) *dat;
|
int alt = (int) *dat;
|
||||||
ds = get_np_dist(np, bt, alt);
|
uint64_t ds = get_np_dist(np, bt, alt);
|
||||||
}
|
idx = get_resulting_node(np, bt, 0, alt, ds, 0);
|
||||||
|
|
||||||
idx = get_resulting_node(np, bt, 0, alt, ds, 0);
|
|
||||||
if (dat)
|
|
||||||
{
|
|
||||||
*dat = (uint64_t) idx;
|
*dat = (uint64_t) idx;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
idx = get_resulting_node(np, bt, 0, 0, -1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return (bt->nodes[idx] >> 48) & 0xFF;
|
return (bt->nodes[idx] >> 48) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
biomenoise.h
13
biomenoise.h
@ -159,15 +159,6 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//==============================================================================
|
|
||||||
// Globals
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
// The global biome tree definitions.
|
|
||||||
// By default, these are defined in biometree.c and tables/btreeXX.h
|
|
||||||
extern BiomeTree g_btree[MC_NEWEST - MC_1_18 + 1];
|
|
||||||
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
// Noise
|
// Noise
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@ -267,8 +258,8 @@ double approxSurfaceBeta(const BiomeNoiseBeta *bnb, const SurfaceNoiseBeta *snb,
|
|||||||
int getOldBetaBiome(float t, float h);
|
int getOldBetaBiome(float t, float h);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the global biome tree definition (g_btree) to map a noise point
|
* Uses the global biome tree definitions (see tables/btreeXX.h)
|
||||||
* (i.e. climate) to the corresponding overworld biome.
|
* to map a noise point (i.e. climate) to the corresponding overworld biome.
|
||||||
*/
|
*/
|
||||||
int climateToBiome(int mc, const uint64_t np[6], uint64_t *dat);
|
int climateToBiome(int mc, const uint64_t np[6], uint64_t *dat);
|
||||||
|
|
||||||
|
2
biomes.c
2
biomes.c
@ -12,7 +12,7 @@ int biomeExists(int mc, int id)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (id == pale_garden)
|
if (id == pale_garden)
|
||||||
return mc >= MC_1_21_3;
|
return mc >= MC_1_21_WD;
|
||||||
|
|
||||||
if (id == cherry_grove)
|
if (id == cherry_grove)
|
||||||
return mc >= MC_1_20;
|
return mc >= MC_1_20;
|
||||||
|
11
biomes.h
11
biomes.h
@ -32,10 +32,11 @@ enum MCVersion
|
|||||||
MC_1_19_2,
|
MC_1_19_2,
|
||||||
MC_1_19_4, MC_1_19 = MC_1_19_4,
|
MC_1_19_4, MC_1_19 = MC_1_19_4,
|
||||||
MC_1_20_6, MC_1_20 = MC_1_20_6,
|
MC_1_20_6, MC_1_20 = MC_1_20_6,
|
||||||
MC_1_21_2,
|
MC_1_21_1,
|
||||||
MC_1_21_3, // (Winter Drop version TBA)
|
MC_1_21_2, // = 1.21.3
|
||||||
MC_1_21 = MC_1_21_2,
|
MC_1_21_WD, // Winter Drop, version TBA
|
||||||
MC_NEWEST = MC_1_21_3,
|
MC_1_21 = MC_1_21_WD,
|
||||||
|
MC_NEWEST = MC_1_21,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Dimension
|
enum Dimension
|
||||||
@ -170,7 +171,7 @@ enum BiomeID
|
|||||||
mangrove_swamp = 184,
|
mangrove_swamp = 184,
|
||||||
// 1.20
|
// 1.20
|
||||||
cherry_grove = 185,
|
cherry_grove = 185,
|
||||||
// 1.21.3
|
// 1.21 Winter Drop
|
||||||
pale_garden = 186,
|
pale_garden = 186,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
30
biometree.c
30
biometree.c
@ -1,30 +0,0 @@
|
|||||||
#include "biomenoise.h"
|
|
||||||
|
|
||||||
#include "tables/btree18.h"
|
|
||||||
#include "tables/btree192.h"
|
|
||||||
#include "tables/btree19.h"
|
|
||||||
#include "tables/btree20.h"
|
|
||||||
#include "tables/btree213.h"
|
|
||||||
|
|
||||||
BiomeTree g_btree[MC_NEWEST - MC_1_18 + 1] =
|
|
||||||
{
|
|
||||||
// MC_1_18_2
|
|
||||||
{ btree18_steps, &btree18_param[0][0], btree18_nodes, btree18_order,
|
|
||||||
sizeof(btree18_nodes) / sizeof(uint64_t) },
|
|
||||||
// MC_1_19_2
|
|
||||||
{ btree192_steps, &btree192_param[0][0], btree192_nodes, btree192_order,
|
|
||||||
sizeof(btree192_nodes) / sizeof(uint64_t) },
|
|
||||||
// MC_1_19_4
|
|
||||||
{ btree19_steps, &btree19_param[0][0], btree19_nodes, btree19_order,
|
|
||||||
sizeof(btree19_nodes) / sizeof(uint64_t) },
|
|
||||||
// MC_1_20_6
|
|
||||||
{ btree20_steps, &btree20_param[0][0], btree20_nodes, btree20_order,
|
|
||||||
sizeof(btree20_nodes) / sizeof(uint64_t) },
|
|
||||||
// MC_1_21_2
|
|
||||||
{ btree20_steps, &btree20_param[0][0], btree20_nodes, btree20_order,
|
|
||||||
sizeof(btree20_nodes) / sizeof(uint64_t) },
|
|
||||||
// MC_1_21_3
|
|
||||||
{ btree213_steps, &btree213_param[0][0], btree213_nodes, btree213_order,
|
|
||||||
sizeof(btree213_nodes) / sizeof(uint64_t) },
|
|
||||||
};
|
|
||||||
|
|
103
finders.c
103
finders.c
@ -12,7 +12,6 @@
|
|||||||
#define PI 3.14159265358979323846
|
#define PI 3.14159265358979323846
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
// Finding Structure Positions
|
// Finding Structure Positions
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@ -78,33 +77,33 @@ int getStructureConfig(int structureType, int mc, StructureConfig *sconf)
|
|||||||
s_village = { 10387312, 34, 26, Village, 0,0},
|
s_village = { 10387312, 34, 26, Village, 0,0},
|
||||||
s_ocean_ruin = { 14357621, 20, 12, Ocean_Ruin, 0,0},
|
s_ocean_ruin = { 14357621, 20, 12, Ocean_Ruin, 0,0},
|
||||||
s_shipwreck = {165745295, 24, 20, Shipwreck, 0,0},
|
s_shipwreck = {165745295, 24, 20, Shipwreck, 0,0},
|
||||||
s_monument = { 10387313, 32, 27, Monument, STRUCT_TRIANGULAR,0},
|
s_monument = { 10387313, 32, 27, Monument, 0,0},
|
||||||
s_mansion = { 10387319, 80, 60, Mansion, STRUCT_TRIANGULAR,0},
|
s_mansion = { 10387319, 80, 60, Mansion, 0,0},
|
||||||
s_ruined_portal = { 34222645, 40, 25, Ruined_Portal, 0,0},
|
s_ruined_portal = { 34222645, 40, 25, Ruined_Portal, 0,0},
|
||||||
s_ruined_portal_n = { 34222645, 40, 25, Ruined_Portal, STRUCT_NETHER,0},
|
s_ruined_portal_n = { 34222645, 40, 25, Ruined_Portal, DIM_NETHER,0},
|
||||||
s_ruined_portal_n_117 = { 34222645, 25, 15, Ruined_Portal_N, STRUCT_NETHER,0},
|
s_ruined_portal_n_117 = { 34222645, 25, 15, Ruined_Portal_N, DIM_NETHER,0},
|
||||||
s_ancient_city = { 20083232, 24, 16, Ancient_City, 0,0},
|
s_ancient_city = { 20083232, 24, 16, Ancient_City, 0,0},
|
||||||
s_trail_ruins = { 83469867, 34, 26, Trail_Ruins, 0,0},
|
s_trail_ruins = { 83469867, 34, 26, Trail_Ruins, 0,0},
|
||||||
s_trial_chambers = { 94251327, 34, 22, Trial_Chambers, 0,0},
|
s_trial_chambers = { 94251327, 34, 22, Trial_Chambers, 0,0},
|
||||||
s_treasure = { 10387320, 1, 1, Treasure, STRUCT_CHUNK,0},
|
s_treasure = { 10387320, 1, 1, Treasure, 0,0},
|
||||||
s_mineshaft = { 0, 1, 1, Mineshaft, STRUCT_CHUNK,0},
|
s_mineshaft = { 0, 1, 1, Mineshaft, 0,0},
|
||||||
s_desert_well_115 = { 30010, 1, 1, Desert_Well, STRUCT_CHUNK, 1.f/1000},
|
s_desert_well_115 = { 30010, 1, 1, Desert_Well, 0, 1.f/1000},
|
||||||
s_desert_well_117 = { 40013, 1, 1, Desert_Well, STRUCT_CHUNK, 1.f/1000},
|
s_desert_well_117 = { 40013, 1, 1, Desert_Well, 0, 1.f/1000},
|
||||||
s_desert_well = { 40002, 1, 1, Desert_Well, STRUCT_CHUNK, 1.f/1000},
|
s_desert_well = { 40002, 1, 1, Desert_Well, 0, 1.f/1000},
|
||||||
s_geode_117 = { 20000, 1, 1, Geode, STRUCT_CHUNK, 1.f/24},
|
s_geode_117 = { 20000, 1, 1, Geode, 0, 1.f/24},
|
||||||
s_geode = { 20002, 1, 1, Geode, STRUCT_CHUNK, 1.f/24},
|
s_geode = { 20002, 1, 1, Geode, 0, 1.f/24},
|
||||||
// nether and end structures
|
// nether and end structures
|
||||||
s_fortress_115 = { 0, 16, 8, Fortress, STRUCT_NETHER,0},
|
s_fortress_115 = { 0, 16, 8, Fortress, DIM_NETHER,0},
|
||||||
s_fortress = { 30084232, 27, 23, Fortress, STRUCT_NETHER,0},
|
s_fortress = { 30084232, 27, 23, Fortress, DIM_NETHER,0},
|
||||||
s_bastion = { 30084232, 27, 23, Bastion, STRUCT_NETHER,0},
|
s_bastion = { 30084232, 27, 23, Bastion, DIM_NETHER,0},
|
||||||
s_end_city = { 10387313, 20, 9, End_City, STRUCT_END|STRUCT_TRIANGULAR,0},
|
s_end_city = { 10387313, 20, 9, End_City, DIM_END,0},
|
||||||
// for the scattered return gateways
|
// for the scattered return gateways
|
||||||
s_end_gateway_115 = { 30000, 1, 1, End_Gateway, STRUCT_END|STRUCT_CHUNK, 700},
|
s_end_gateway_115 = { 30000, 1, 1, End_Gateway, DIM_END, 700},
|
||||||
s_end_gateway_116 = { 40013, 1, 1, End_Gateway, STRUCT_END|STRUCT_CHUNK, 700},
|
s_end_gateway_116 = { 40013, 1, 1, End_Gateway, DIM_END, 700},
|
||||||
s_end_gateway_117 = { 40013, 1, 1, End_Gateway, STRUCT_END|STRUCT_CHUNK, 1.f/700},
|
s_end_gateway_117 = { 40013, 1, 1, End_Gateway, DIM_END, 1.f/700},
|
||||||
s_end_gateway = { 40000, 1, 1, End_Gateway, STRUCT_END|STRUCT_CHUNK, 1.f/700},
|
s_end_gateway = { 40000, 1, 1, End_Gateway, DIM_END, 1.f/700},
|
||||||
s_end_island_116 = { 0, 1, 1, End_Island, STRUCT_END|STRUCT_CHUNK, 14},
|
s_end_island_116 = { 0, 1, 1, End_Island, DIM_END, 14},
|
||||||
s_end_island = { 0, 1, 1, End_Island, STRUCT_END|STRUCT_CHUNK, 1.f/14}
|
s_end_island = { 0, 1, 1, End_Island, DIM_END, 1.f/14}
|
||||||
;
|
;
|
||||||
|
|
||||||
switch (structureType)
|
switch (structureType)
|
||||||
@ -193,7 +192,7 @@ int getStructureConfig(int structureType, int mc, StructureConfig *sconf)
|
|||||||
return mc >= MC_1_20;
|
return mc >= MC_1_20;
|
||||||
case Trial_Chambers:
|
case Trial_Chambers:
|
||||||
*sconf = s_trial_chambers;
|
*sconf = s_trial_chambers;
|
||||||
return mc >= MC_1_21;
|
return mc >= MC_1_21_1;
|
||||||
default:
|
default:
|
||||||
memset(sconf, 0, sizeof(StructureConfig));
|
memset(sconf, 0, sizeof(StructureConfig));
|
||||||
return 0;
|
return 0;
|
||||||
@ -938,7 +937,7 @@ int nextStronghold(StrongholdIter *sh, const Generator *g)
|
|||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
uint64_t getSpawnDist(const Generator *g, int x, int z)
|
uint64_t calcFitness(const Generator *g, int x, int z)
|
||||||
{
|
{
|
||||||
int64_t np[6];
|
int64_t np[6];
|
||||||
uint32_t flags = SAMPLE_NO_DEPTH | SAMPLE_NO_BIOME;
|
uint32_t flags = SAMPLE_NO_DEPTH | SAMPLE_NO_BIOME;
|
||||||
@ -964,7 +963,20 @@ uint64_t getSpawnDist(const Generator *g, int x, int z)
|
|||||||
b = -np[5] + (uint64_t)spawn_np[6][0];
|
b = -np[5] + (uint64_t)spawn_np[6][0];
|
||||||
q = (int64_t)a > 0 ? a : (int64_t)b > 0 ? b : 0;
|
q = (int64_t)a > 0 ? a : (int64_t)b > 0 ? b : 0;
|
||||||
ds2 = ds + q*q;
|
ds2 = ds + q*q;
|
||||||
return ds1 <= ds2 ? ds1 : ds2;
|
ds = ds1 <= ds2 ? ds1 : ds2;
|
||||||
|
// apply dependence on distance from origin
|
||||||
|
a = (int64_t)x*x;
|
||||||
|
b = (int64_t)z*z;
|
||||||
|
if (g->mc < MC_1_21_2)
|
||||||
|
{
|
||||||
|
double s = (double)(a + b) / (2500 * 2500);
|
||||||
|
q = (uint64_t)(s*s * 1e8) + ds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
q = ds * (2048LL * 2048LL) + a + b;
|
||||||
|
}
|
||||||
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -978,11 +990,7 @@ void findFittest(const Generator *g, Pos *pos, uint64_t *fitness, double maxrad,
|
|||||||
{
|
{
|
||||||
int x = p.x + (int)(sin(ang) * rad);
|
int x = p.x + (int)(sin(ang) * rad);
|
||||||
int z = p.z + (int)(cos(ang) * rad);
|
int z = p.z + (int)(cos(ang) * rad);
|
||||||
// Calcuate portion of fitness dependent on distance from origin
|
uint64_t fit = calcFitness(g, x, z);
|
||||||
double d = ((double)x*x + (double)z*z) / (2500*2500);
|
|
||||||
uint64_t fit = (uint64_t)(d*d * 1e8);
|
|
||||||
// Calculate portion of fitness dependent on climate values
|
|
||||||
fit += getSpawnDist(g, x, z);
|
|
||||||
// Then update pos and fitness if combined total is lower/better
|
// Then update pos and fitness if combined total is lower/better
|
||||||
if (fit < *fitness)
|
if (fit < *fitness)
|
||||||
{
|
{
|
||||||
@ -998,7 +1006,7 @@ static
|
|||||||
Pos findFittestPos(const Generator *g)
|
Pos findFittestPos(const Generator *g)
|
||||||
{
|
{
|
||||||
Pos spawn = {0, 0};
|
Pos spawn = {0, 0};
|
||||||
uint64_t fitness = getSpawnDist(g, 0, 0);
|
uint64_t fitness = calcFitness(g, 0, 0);
|
||||||
findFittest(g, &spawn, &fitness, 2048.0, 512.0);
|
findFittest(g, &spawn, &fitness, 2048.0, 512.0);
|
||||||
findFittest(g, &spawn, &fitness, 512.0, 32.0);
|
findFittest(g, &spawn, &fitness, 512.0, 32.0);
|
||||||
// center of chunk
|
// center of chunk
|
||||||
@ -2875,10 +2883,11 @@ void getFixedEndGateways(int mc, uint64_t seed, Pos src[20])
|
|||||||
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int i;
|
||||||
uint64_t rng = 0;
|
uint64_t rng = 0;
|
||||||
setSeed(&rng, seed);
|
setSeed(&rng, seed);
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
uint8_t j = 19 - nextInt(&rng, 20-i);
|
uint8_t j = 19 - nextInt(&rng, 20-i);
|
||||||
uint8_t tmp = order[i];
|
uint8_t tmp = order[i];
|
||||||
@ -2886,7 +2895,7 @@ void getFixedEndGateways(int mc, uint64_t seed, Pos src[20])
|
|||||||
order[j] = tmp;
|
order[j] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++)
|
for (i = 0; i < 20; i++)
|
||||||
src[i] = fixed[ order[i] ];
|
src[i] = fixed[ order[i] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5436,7 +5445,7 @@ static const int g_biome_para_range_18[][13] = {
|
|||||||
{jagged_peaks , IMIN, 2000, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN, IMAX, -9333,-4001},
|
{jagged_peaks , IMIN, 2000, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN, IMAX, -9333,-4001},
|
||||||
{frozen_peaks , IMIN, 2000, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN, IMAX, 4000, 9333},
|
{frozen_peaks , IMIN, 2000, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN, IMAX, 4000, 9333},
|
||||||
{stony_peaks , 2000, 5500, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN, IMAX, -9333, 9333},
|
{stony_peaks , 2000, 5500, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN, IMAX, -9333, 9333},
|
||||||
};
|
{-1,0,0,0,0,0,0,0,0,0,0,0,0}};
|
||||||
|
|
||||||
static const int g_biome_para_range_19_diff[][13] = {
|
static const int g_biome_para_range_19_diff[][13] = {
|
||||||
{eroded_badlands , 5500, IMAX, IMIN,-1000, -1899, IMAX, IMIN, 500, IMIN, IMAX, -500, IMAX},
|
{eroded_badlands , 5500, IMAX, IMIN,-1000, -1899, IMAX, IMIN, 500, IMIN, IMAX, -500, IMAX},
|
||||||
@ -5445,7 +5454,7 @@ static const int g_biome_para_range_19_diff[][13] = {
|
|||||||
{jagged_peaks , IMIN, 2000, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN,10499, -9333,-4001},
|
{jagged_peaks , IMIN, 2000, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN,10499, -9333,-4001},
|
||||||
{deep_dark , IMIN, IMAX, IMIN, IMAX, IMIN, IMAX, IMIN, 1818, 10500, IMAX, IMIN, IMAX},
|
{deep_dark , IMIN, IMAX, IMIN, IMAX, IMIN, IMAX, IMIN, 1818, 10500, IMAX, IMIN, IMAX},
|
||||||
{mangrove_swamp , 2000, IMAX, IMIN, IMAX, -1100, IMAX, 5500, IMAX, IMIN, IMAX, IMIN, IMAX},
|
{mangrove_swamp , 2000, IMAX, IMIN, IMAX, -1100, IMAX, 5500, IMAX, IMIN, IMAX, IMIN, IMAX},
|
||||||
};
|
{-1,0,0,0,0,0,0,0,0,0,0,0,0}};
|
||||||
|
|
||||||
static const int g_biome_para_range_20_diff[][13] = {
|
static const int g_biome_para_range_20_diff[][13] = {
|
||||||
{swamp , -4500, 2000, IMIN, IMAX, -1100, IMAX, 5500, IMAX, IMIN, IMAX, IMIN, IMAX},
|
{swamp , -4500, 2000, IMIN, IMAX, -1100, IMAX, 5500, IMAX, IMIN, IMAX, IMIN, IMAX},
|
||||||
@ -5455,11 +5464,11 @@ static const int g_biome_para_range_20_diff[][13] = {
|
|||||||
{frozen_peaks , IMIN, 2000, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN,10500, 4000, 9333},
|
{frozen_peaks , IMIN, 2000, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN,10500, 4000, 9333},
|
||||||
{stony_peaks , 2000, 5500, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN,10500, -9333, 9333},
|
{stony_peaks , 2000, 5500, IMIN, IMAX, -1899, IMAX, IMIN,-3750, IMIN,10500, -9333, 9333},
|
||||||
{cherry_grove , -4500, 2000, IMIN,-1000, 300, IMAX, -7799, 500, IMIN, IMAX, 2666, IMAX},
|
{cherry_grove , -4500, 2000, IMIN,-1000, 300, IMAX, -7799, 500, IMIN, IMAX, 2666, IMAX},
|
||||||
};
|
{-1,0,0,0,0,0,0,0,0,0,0,0,0}};
|
||||||
|
|
||||||
static const int g_biome_para_range_213_diff[][13] = {
|
static const int g_biome_para_range_21wd_diff[][13] = {
|
||||||
{pale_garden , -1500, 2000, 3000, IMAX, 300, IMAX, -7799, 500, IMIN, IMAX, 2666, IMAX},
|
{pale_garden , -1500, 2000, 3000, IMAX, 300, IMAX, -7799, 500, IMIN, IMAX, 2666, IMAX},
|
||||||
};
|
{-1,0,0,0,0,0,0,0,0,0,0,0,0}};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -5498,20 +5507,18 @@ const int *getBiomeParaLimits(int mc, int id)
|
|||||||
{
|
{
|
||||||
if (mc <= MC_1_17)
|
if (mc <= MC_1_17)
|
||||||
return NULL;
|
return NULL;
|
||||||
int i, n;
|
int i;
|
||||||
if (mc > MC_1_21_2)
|
if (mc > MC_1_21_2)
|
||||||
{
|
{
|
||||||
n = sizeof(g_biome_para_range_213_diff) / sizeof(g_biome_para_range_213_diff[0]);
|
for (i = 0; g_biome_para_range_21wd_diff[i][0] != -1; i++)
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
{
|
||||||
if (g_biome_para_range_213_diff[i][0] == id)
|
if (g_biome_para_range_21wd_diff[i][0] == id)
|
||||||
return &g_biome_para_range_213_diff[i][1];
|
return &g_biome_para_range_21wd_diff[i][1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mc > MC_1_19)
|
if (mc > MC_1_19)
|
||||||
{
|
{
|
||||||
n = sizeof(g_biome_para_range_20_diff) / sizeof(g_biome_para_range_20_diff[0]);
|
for (i = 0; g_biome_para_range_20_diff[i][0] != -1; i++)
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
{
|
||||||
if (g_biome_para_range_20_diff[i][0] == id)
|
if (g_biome_para_range_20_diff[i][0] == id)
|
||||||
return &g_biome_para_range_20_diff[i][1];
|
return &g_biome_para_range_20_diff[i][1];
|
||||||
@ -5519,15 +5526,13 @@ const int *getBiomeParaLimits(int mc, int id)
|
|||||||
}
|
}
|
||||||
if (mc > MC_1_18)
|
if (mc > MC_1_18)
|
||||||
{
|
{
|
||||||
n = sizeof(g_biome_para_range_19_diff) / sizeof(g_biome_para_range_19_diff[0]);
|
for (i = 0; g_biome_para_range_19_diff[i][0] != -1; i++)
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
{
|
||||||
if (g_biome_para_range_19_diff[i][0] == id)
|
if (g_biome_para_range_19_diff[i][0] == id)
|
||||||
return &g_biome_para_range_19_diff[i][1];
|
return &g_biome_para_range_19_diff[i][1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n = sizeof(g_biome_para_range_18) / sizeof(g_biome_para_range_18[0]);
|
for (i = 0; g_biome_para_range_18[i][0] != -1; i++)
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
{
|
||||||
if (g_biome_para_range_18[i][0] == id)
|
if (g_biome_para_range_18[i][0] == id)
|
||||||
return &g_biome_para_range_18[i][1];
|
return &g_biome_para_range_18[i][1];
|
||||||
|
@ -43,13 +43,6 @@ enum StructureType
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
enum
|
|
||||||
{ // structure config property flags
|
|
||||||
STRUCT_TRIANGULAR = 0x01, // structure uses a triangular distribution
|
|
||||||
STRUCT_CHUNK = 0x02, // structure is checked for each chunk
|
|
||||||
STRUCT_NETHER = 0x10, // nether structure
|
|
||||||
STRUCT_END = 0x20, // end structure
|
|
||||||
};
|
|
||||||
// use getStructureConfig() for the version specific structure configuration
|
// use getStructureConfig() for the version specific structure configuration
|
||||||
STRUCT(StructureConfig)
|
STRUCT(StructureConfig)
|
||||||
{
|
{
|
||||||
@ -57,7 +50,7 @@ STRUCT(StructureConfig)
|
|||||||
int8_t regionSize;
|
int8_t regionSize;
|
||||||
int8_t chunkRange;
|
int8_t chunkRange;
|
||||||
uint8_t structType;
|
uint8_t structType;
|
||||||
uint8_t properties;
|
int8_t dim;
|
||||||
float rarity;
|
float rarity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
makefile
2
makefile
@ -30,7 +30,7 @@ release: CFLAGS += -fPIC
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
libcubiomes: noise.o biomes.o layers.o biometree.o biomenoise.o generator.o finders.o util.o quadbase.o
|
libcubiomes: noise.o biomes.o layers.o biomenoise.o generator.o finders.o util.o quadbase.o
|
||||||
$(AR) $(ARFLAGS) libcubiomes.a $^
|
$(AR) $(ARFLAGS) libcubiomes.a $^
|
||||||
|
|
||||||
finders.o: finders.c finders.h
|
finders.o: finders.c finders.h
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
enum { btree213_order = 6 };
|
enum { btree21wd_order = 6 };
|
||||||
|
|
||||||
static const uint32_t btree213_steps[] = { 1555, 259, 43, 7, 1, 0 };
|
static const uint32_t btree21wd_steps[] = { 1555, 259, 43, 7, 1, 0 };
|
||||||
|
|
||||||
static const int32_t btree213_param[][2] =
|
static const int32_t btree21wd_param[][2] =
|
||||||
{
|
{
|
||||||
{-12000,-10500},{-12000, -4550},{-12000, 10000},{-10500, -4550}, // 00-03
|
{-12000,-10500},{-12000, -4550},{-12000, 10000},{-10500, -4550}, // 00-03
|
||||||
{-10500, -1900},{-10500, 10000},{-10000, -9333},{-10000, -7799}, // 04-07
|
{-10500, -1900},{-10500, 10000},{-10000, -9333},{-10000, -7799}, // 04-07
|
||||||
@ -43,9 +43,9 @@ static const int32_t btree213_param[][2] =
|
|||||||
{ 10000, 10000},{ 10000, 11000},{ 11000, 11000},
|
{ 10000, 10000},{ 10000, 11000},{ 11000, 11000},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint64_t btree213_nodes[] =
|
static const uint64_t btree21wd_nodes[] =
|
||||||
{
|
{
|
||||||
// Binary encoded biome parameter search tree for 1.21.3 (24w40a).
|
// Binary encoded biome parameter search tree for 1.21 Winter Drop (24w40a).
|
||||||
//
|
//
|
||||||
// +-------------- If the top byte equals 0xFF, the node is a leaf and the
|
// +-------------- If the top byte equals 0xFF, the node is a leaf and the
|
||||||
// | second byte is the biome id, otherwise the two bytes
|
// | second byte is the biome id, otherwise the two bytes
|
13
tests.c
13
tests.c
@ -151,13 +151,14 @@ uint32_t testAreas(int mc, int dim, int scale)
|
|||||||
Range r = {scale, x, z, w, h, y, 1};
|
Range r = {scale, x, z, w, h, y, 1};
|
||||||
int *ids = allocCache(&g, r);
|
int *ids = allocCache(&g, r);
|
||||||
genBiomes(&g, ids, r);
|
genBiomes(&g, ids, r);
|
||||||
|
/*
|
||||||
float *surf = malloc(4 * w * h);
|
float *surf = malloc(4 * w * h);
|
||||||
initSurfaceNoise(&sn, dim, s);
|
initSurfaceNoise(&sn, dim, s);
|
||||||
mapApproxHeight(surf, 0, &g, &sn, x, z, w, h);
|
mapApproxHeight(surf, 0, &g, &sn, x, z, w, h);
|
||||||
for (int i = 0; i < w*h; i++)
|
for (int i = 0; i < w*h; i++)
|
||||||
ids[i] = (int) surf[i];
|
ids[i] = (int) surf[i];
|
||||||
free(surf);
|
free(surf);
|
||||||
|
*/
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
hash = 0;
|
hash = 0;
|
||||||
@ -332,7 +333,7 @@ void findBiomeParaBounds()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Generator g;
|
Generator g;
|
||||||
setupGenerator(&g, MC_1_21_3, 0);
|
setupGenerator(&g, MC_1_21, 0);
|
||||||
int64_t s;
|
int64_t s;
|
||||||
int r = 1000;
|
int r = 1000;
|
||||||
for (s = 0; s < 20000; s++)
|
for (s = 0; s < 20000; s++)
|
||||||
@ -353,10 +354,10 @@ void findBiomeParaBounds()
|
|||||||
|
|
||||||
for (i = 0; i < 256; i++)
|
for (i = 0; i < 256; i++)
|
||||||
{
|
{
|
||||||
if (!isOverworld(MC_1_21_3, i))
|
if (!isOverworld(MC_1_21, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
printf("{%-24s", biome2str(MC_1_21_3, i));
|
printf("{%-24s", biome2str(MC_1_21, i));
|
||||||
for (j = 0; j < 6; j++)
|
for (j = 0; j < 6; j++)
|
||||||
{
|
{
|
||||||
printf(", %6ld,%6ld", bbounds[i][j][0], bbounds[i][j][1]);
|
printf(", %6ld,%6ld", bbounds[i][j][0], bbounds[i][j][1]);
|
||||||
@ -528,12 +529,12 @@ int main()
|
|||||||
//endHeight(MC_1_15, 1, 370704, 96, 32, 32, 1);
|
//endHeight(MC_1_15, 1, 370704, 96, 32, 32, 1);
|
||||||
|
|
||||||
//testAreas(MC_1_21, 1, 1);
|
//testAreas(MC_1_21, 1, 1);
|
||||||
//testAreas(mc, 0, 4);
|
//testAreas(MC_1_21, 0, 4);
|
||||||
//testAreas(mc, 0, 16);
|
//testAreas(mc, 0, 16);
|
||||||
//testAreas(mc, 0, 256);
|
//testAreas(mc, 0, 256);
|
||||||
//testCanBiomesGenerate();
|
//testCanBiomesGenerate();
|
||||||
//testGeneration();
|
//testGeneration();
|
||||||
findBiomeParaBounds();
|
//findBiomeParaBounds();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
13
util.c
13
util.c
@ -73,18 +73,19 @@ const char* mc2str(int mc)
|
|||||||
case MC_1_19_2: return "1.19.2"; break;
|
case MC_1_19_2: return "1.19.2"; break;
|
||||||
case MC_1_19: return "1.19"; break;
|
case MC_1_19: return "1.19"; break;
|
||||||
case MC_1_20: return "1.20"; break;
|
case MC_1_20: return "1.20"; break;
|
||||||
|
case MC_1_21_1: return "1.21.1"; break;
|
||||||
case MC_1_21_2: return "1.21.2"; break;
|
case MC_1_21_2: return "1.21.2"; break;
|
||||||
case MC_1_21_3: return "1.21.3"; break;
|
case MC_1_21_WD: return "1.21 WD"; break;
|
||||||
//case MC_1_21: return "1.21"; break;
|
default: return "?";
|
||||||
default: return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int str2mc(const char *s)
|
int str2mc(const char *s)
|
||||||
{
|
{
|
||||||
if (!strcmp(s, "1.21")) return MC_1_21;
|
if (!strcmp(s, "1.21")) return MC_1_21;
|
||||||
if (!strcmp(s, "1.21.3")) return MC_1_21_3;
|
if (!strcmp(s, "1.21 WD")) return MC_1_21_WD;
|
||||||
if (!strcmp(s, "1.21.2")) return MC_1_21_2;
|
if (!strcmp(s, "1.21.2")) return MC_1_21_2;
|
||||||
|
if (!strcmp(s, "1.21.1")) return MC_1_21_1;
|
||||||
if (!strcmp(s, "1.20")) return MC_1_20;
|
if (!strcmp(s, "1.20")) return MC_1_20;
|
||||||
if (!strcmp(s, "1.20.6")) return MC_1_20_6;
|
if (!strcmp(s, "1.20.6")) return MC_1_20_6;
|
||||||
if (!strcmp(s, "1.19")) return MC_1_19;
|
if (!strcmp(s, "1.19")) return MC_1_19;
|
||||||
@ -131,7 +132,7 @@ int str2mc(const char *s)
|
|||||||
if (!strcmp(s, "1.0.0")) return MC_1_0_0;
|
if (!strcmp(s, "1.0.0")) return MC_1_0_0;
|
||||||
if (!strcmp(s, "Beta 1.8")) return MC_B1_8;
|
if (!strcmp(s, "Beta 1.8")) return MC_B1_8;
|
||||||
if (!strcmp(s, "Beta 1.7")) return MC_B1_7;
|
if (!strcmp(s, "Beta 1.7")) return MC_B1_7;
|
||||||
return -1;
|
return MC_UNDEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -267,7 +268,7 @@ const char *biome2str(int mc, int id)
|
|||||||
case mangrove_swamp: return "mangrove_swamp";
|
case mangrove_swamp: return "mangrove_swamp";
|
||||||
// 1.20
|
// 1.20
|
||||||
case cherry_grove: return "cherry_grove";
|
case cherry_grove: return "cherry_grove";
|
||||||
// 1.21.3 (Winter Drop)
|
// 1.21.4 (Winter Drop)
|
||||||
case pale_garden: return "pale_garden";
|
case pale_garden: return "pale_garden";
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user