mirror of
https://github.com/Relintai/world_generator.git
synced 2025-04-13 21:30:51 +02:00
Add instance() methods as an easy and scriptable way of duplicating planets, biomes etc. Also removed a few unused members.
This commit is contained in:
parent
e7acee7614
commit
a1b988e154
@ -280,6 +280,76 @@ void Biome::set_voxel_surfaces(const Vector<Variant> &voxel_surfaces) {
|
||||
|
||||
#endif
|
||||
|
||||
Ref<Biome> Biome::instance(const int seed) {
|
||||
if (has_method("_instance")) {
|
||||
return call("_instance", seed);
|
||||
}
|
||||
|
||||
return Ref<Biome>();
|
||||
}
|
||||
|
||||
Ref<Biome> Biome::_instance(const int seed, Ref<Biome> biome) {
|
||||
Ref<Biome> inst = biome;
|
||||
|
||||
if (!inst.is_valid())
|
||||
inst.instance();
|
||||
|
||||
inst->set_current_seed(seed);
|
||||
inst->set_level_range(_level_range);
|
||||
|
||||
inst->set_humidity_range(_humidity_range);
|
||||
inst->set_temperature_range(_temperature_range);
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
inst->set_environment(_environment);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _prop_datas.size(); ++i) {
|
||||
Ref<WorldGeneratorPropData> p = _prop_datas[i];
|
||||
|
||||
inst->add_prop_data(p);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _dungeons.size(); ++i) {
|
||||
Ref<Dungeon> d = _dungeons[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_dungeon(d->instance(seed));
|
||||
}
|
||||
|
||||
#ifdef ESS_PRESENT
|
||||
for (int i = 0; i < _entity_datas.size(); ++i) {
|
||||
Ref<EntityData> d = _entity_datas[i];
|
||||
|
||||
inst->add_entity_data(d);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
for (int i = 0; i < _environment_datas.size(); ++i) {
|
||||
Ref<EnvironmentData> d = _environment_datas[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_environment_data(d);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _voxel_surfaces.size(); ++i) {
|
||||
Ref<VoxelSurface> d = _voxel_surfaces[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_voxel_surface(d);
|
||||
}
|
||||
#endif
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
void Biome::setup() {
|
||||
if (has_method("_setup")) {
|
||||
call("_setup");
|
||||
@ -384,11 +454,15 @@ Biome::~Biome() {
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
_environment_datas.clear();
|
||||
_voxel_surfaces.clear();
|
||||
_liquid_voxel_surfaces.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Biome::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "inst", PROPERTY_HINT_RESOURCE_TYPE, "Biome"),
|
||||
"_instance",
|
||||
PropertyInfo(Variant::INT, "seed"),
|
||||
PropertyInfo(Variant::OBJECT, "instance", PROPERTY_HINT_RESOURCE_TYPE, "Biome")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_setup"));
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
@ -400,6 +474,9 @@ void Biome::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("instance", "seed"), &Biome::instance);
|
||||
ClassDB::bind_method(D_METHOD("_instance", "seed", "instance"), &Biome::_instance);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("setup"), &Biome::setup);
|
||||
ClassDB::bind_method(D_METHOD("setup_library", "library"), &Biome::setup_library);
|
||||
|
||||
|
@ -118,6 +118,9 @@ public:
|
||||
void set_voxel_surfaces(const Vector<Variant> &voxel_surfaces);
|
||||
#endif
|
||||
|
||||
Ref<Biome> instance(const int seed);
|
||||
virtual Ref<Biome> _instance(const int seed, Ref<Biome> biome);
|
||||
|
||||
void setup();
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
@ -161,7 +164,6 @@ private:
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
Vector<Ref<EnvironmentData> > _environment_datas;
|
||||
Vector<Ref<VoxelSurface> > _voxel_surfaces;
|
||||
Vector<Ref<VoxelSurface> > _liquid_voxel_surfaces;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
121
main/dungeon.cpp
121
main/dungeon.cpp
@ -462,6 +462,115 @@ void Dungeon::set_environment_datas(const Vector<Variant> &environment_datas) {
|
||||
}
|
||||
#endif
|
||||
|
||||
Ref<Dungeon> Dungeon::instance(const int seed) {
|
||||
if (has_method("_instance")) {
|
||||
return call("_instance", seed);
|
||||
}
|
||||
|
||||
return Ref<Dungeon>();
|
||||
}
|
||||
|
||||
Ref<Dungeon> Dungeon::_instance(const int seed, Ref<Dungeon> dungeon) {
|
||||
Ref<Dungeon> inst = dungeon;
|
||||
|
||||
if (!inst.is_valid())
|
||||
inst.instance();
|
||||
|
||||
inst->set_current_seed(seed);
|
||||
inst->set_level_range(_level_range);
|
||||
|
||||
inst->set_posx(_posx);
|
||||
inst->set_posy(_posy);
|
||||
inst->set_posz(_posz);
|
||||
|
||||
inst->set_sizex(_sizex);
|
||||
inst->set_sizey(_sizey);
|
||||
inst->set_sizez(_sizez);
|
||||
|
||||
inst->set_room_count(_room_count);
|
||||
|
||||
inst->set_min_sizex(_min_sizex);
|
||||
inst->set_min_sizey(_min_sizey);
|
||||
inst->set_min_sizez(_min_sizez);
|
||||
|
||||
inst->set_max_sizex(_max_sizex);
|
||||
inst->set_max_sizey(_max_sizey);
|
||||
inst->set_max_sizez(_max_sizez);
|
||||
|
||||
inst->set_min_room_count(_min_room_count);
|
||||
inst->set_max_room_count(_max_room_count);
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
inst->set_environment(_environment);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _dungeon_rooms.size(); ++i) {
|
||||
Ref<DungeonRoom> r = _dungeon_rooms[i];
|
||||
|
||||
if (!r.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_dungeon_room(r->instance(seed));
|
||||
}
|
||||
|
||||
for (int i = 0; i < _dungeon_start_rooms.size(); ++i) {
|
||||
Ref<DungeonRoom> r = _dungeon_start_rooms[i];
|
||||
|
||||
if (!r.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_dungeon_start_room(r->instance(seed));
|
||||
}
|
||||
|
||||
for (int i = 0; i < _dungeon_end_rooms.size(); ++i) {
|
||||
Ref<DungeonRoom> r = _dungeon_end_rooms[i];
|
||||
|
||||
if (!r.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_dungeon_end_room(r->instance(seed));
|
||||
}
|
||||
|
||||
for (int i = 0; i < _dungeon_corridors.size(); ++i) {
|
||||
Ref<DungeonRoom> r = _dungeon_corridors[i];
|
||||
|
||||
if (!r.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_dungeon_corridor(r->instance(seed));
|
||||
}
|
||||
|
||||
#ifdef ESS_PRESENT
|
||||
for (int i = 0; i < _entity_datas.size(); ++i) {
|
||||
Ref<EntityData> d = _entity_datas[i];
|
||||
|
||||
inst->add_entity_data(d);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
for (int i = 0; i < _environment_datas.size(); ++i) {
|
||||
Ref<EnvironmentData> d = _environment_datas[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_environment_data(d);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _voxel_surfaces.size(); ++i) {
|
||||
Ref<VoxelSurface> d = _voxel_surfaces[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_voxel_surface(d);
|
||||
}
|
||||
#endif
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
void Dungeon::setup() {
|
||||
if (has_method("_setup")) {
|
||||
call("_setup");
|
||||
@ -595,15 +704,16 @@ Dungeon::~Dungeon() {
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
_environment_datas.clear();
|
||||
#endif
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
_voxel_surfaces.clear();
|
||||
_liquid_voxel_surfaces.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dungeon::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "inst", PROPERTY_HINT_RESOURCE_TYPE, "Dungeon"),
|
||||
"_instance",
|
||||
PropertyInfo(Variant::INT, "seed"),
|
||||
PropertyInfo(Variant::OBJECT, "instance", PROPERTY_HINT_RESOURCE_TYPE, "Dungeon")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_setup"));
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
@ -615,6 +725,9 @@ void Dungeon::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("instance", "seed"), &Dungeon::instance);
|
||||
ClassDB::bind_method(D_METHOD("_instance", "seed", "instance"), &Dungeon::_instance);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("setup"), &Dungeon::setup);
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
|
@ -186,6 +186,9 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
Ref<Dungeon> instance(const int seed);
|
||||
virtual Ref<Dungeon> _instance(const int seed, Ref<Dungeon> dungeon);
|
||||
|
||||
void setup();
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
@ -252,7 +255,6 @@ private:
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
Vector<Ref<VoxelSurface> > _voxel_surfaces;
|
||||
Vector<Ref<VoxelSurface> > _liquid_voxel_surfaces;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -53,6 +53,19 @@ int DungeonCorridor::get_dungeon_room_count() const {
|
||||
return _dungeon_rooms.size();
|
||||
}
|
||||
|
||||
Ref<DungeonRoom> DungeonCorridor::_instance(const int seed, Ref<DungeonRoom> dungeon_room) {
|
||||
Ref<DungeonCorridor> inst = dungeon_room;
|
||||
|
||||
if (!inst.is_valid())
|
||||
inst.instance();
|
||||
|
||||
DungeonRoom::_instance(seed, inst);
|
||||
|
||||
inst->set_max_connections(_max_connections);
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
DungeonCorridor::DungeonCorridor() {
|
||||
_max_connections = 2;
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ public:
|
||||
|
||||
int get_dungeon_room_count() const;
|
||||
|
||||
Ref<DungeonRoom> _instance(const int seed, Ref<DungeonRoom> dungeon_room);
|
||||
|
||||
DungeonCorridor();
|
||||
~DungeonCorridor();
|
||||
|
||||
|
@ -320,6 +320,82 @@ void DungeonRoom::set_entity_datas(const Vector<Variant> &entity_datas) {
|
||||
|
||||
#endif
|
||||
|
||||
Ref<DungeonRoom> DungeonRoom::instance(const int seed) {
|
||||
if (has_method("_instance")) {
|
||||
return call("_instance", seed);
|
||||
}
|
||||
|
||||
return Ref<DungeonRoom>();
|
||||
}
|
||||
|
||||
Ref<DungeonRoom> DungeonRoom::_instance(const int seed, Ref<DungeonRoom> dungeon_room) {
|
||||
Ref<DungeonRoom> inst = dungeon_room;
|
||||
|
||||
if (!inst.is_valid())
|
||||
inst.instance();
|
||||
|
||||
inst->set_current_seed(seed);
|
||||
inst->set_level_range(_level_range);
|
||||
|
||||
inst->set_posx(_posx);
|
||||
inst->set_posy(_posy);
|
||||
inst->set_posz(_posz);
|
||||
|
||||
inst->set_sizex(_sizex);
|
||||
inst->set_sizey(_sizey);
|
||||
inst->set_sizez(_sizez);
|
||||
|
||||
inst->set_min_sizex(_min_sizex);
|
||||
inst->set_min_sizey(_min_sizey);
|
||||
inst->set_min_sizez(_min_sizez);
|
||||
|
||||
inst->set_max_sizex(_max_sizex);
|
||||
inst->set_max_sizey(_max_sizey);
|
||||
inst->set_max_sizez(_max_sizez);
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
inst->set_environment(_environment);
|
||||
//don't
|
||||
//inst->set_structure(_structure);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _prop_datas.size(); ++i) {
|
||||
Ref<WorldGeneratorPropData> p = _prop_datas[i];
|
||||
|
||||
inst->add_prop_data(p);
|
||||
}
|
||||
|
||||
#ifdef ESS_PRESENT
|
||||
for (int i = 0; i < _entity_datas.size(); ++i) {
|
||||
Ref<EntityData> d = _entity_datas[i];
|
||||
|
||||
inst->add_entity_data(d);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
for (int i = 0; i < _environment_datas.size(); ++i) {
|
||||
Ref<EnvironmentData> d = _environment_datas[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_environment_data(d);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _voxel_surfaces.size(); ++i) {
|
||||
Ref<VoxelSurface> d = _voxel_surfaces[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_voxel_surface(d);
|
||||
}
|
||||
#endif
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
void DungeonRoom::setup() {
|
||||
if (has_method("_setup")) {
|
||||
call("_setup");
|
||||
@ -424,11 +500,15 @@ DungeonRoom::~DungeonRoom() {
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
_environment_datas.clear();
|
||||
_voxel_surfaces.clear();
|
||||
_liquid_voxel_surfaces.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void DungeonRoom::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "inst", PROPERTY_HINT_RESOURCE_TYPE, "DungeonRoom"),
|
||||
"_instance",
|
||||
PropertyInfo(Variant::INT, "seed"),
|
||||
PropertyInfo(Variant::OBJECT, "instance", PROPERTY_HINT_RESOURCE_TYPE, "DungeonRoom")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_setup"));
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
@ -440,6 +520,9 @@ void DungeonRoom::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("instance", "seed"), &DungeonRoom::instance);
|
||||
ClassDB::bind_method(D_METHOD("_instance", "seed", "instance"), &DungeonRoom::_instance);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("setup"), &DungeonRoom::setup);
|
||||
ClassDB::bind_method(D_METHOD("setup_library", "library"), &DungeonRoom::setup_library);
|
||||
|
||||
|
@ -155,6 +155,9 @@ public:
|
||||
void set_entity_datas(const Vector<Variant> &entity_datas);
|
||||
#endif
|
||||
|
||||
Ref<DungeonRoom> instance(const int seed);
|
||||
virtual Ref<DungeonRoom> _instance(const int seed, Ref<DungeonRoom> dungeon_room);
|
||||
|
||||
void setup();
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
@ -209,7 +212,6 @@ private:
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
Vector<Ref<EnvironmentData> > _environment_datas;
|
||||
Vector<Ref<VoxelSurface> > _voxel_surfaces;
|
||||
Vector<Ref<VoxelSurface> > _liquid_voxel_surfaces;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -225,6 +225,72 @@ void Planet::set_voxel_surfaces(const Vector<Variant> &voxel_surfaces) {
|
||||
|
||||
#endif
|
||||
|
||||
Ref<Planet> Planet::instance(const int seed) {
|
||||
if (has_method("_instance")) {
|
||||
return call("_instance", seed);
|
||||
}
|
||||
|
||||
return Ref<Planet>();
|
||||
}
|
||||
|
||||
Ref<Planet> Planet::_instance(const int seed, Ref<Planet> planet) {
|
||||
Ref<Planet> inst = planet;
|
||||
|
||||
if (!inst.is_valid())
|
||||
inst.instance();
|
||||
|
||||
inst->set_id(_id);
|
||||
inst->set_current_seed(seed);
|
||||
inst->set_level_range(_level_range);
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
inst->set_environment(_environment);
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _biomes.size(); ++i) {
|
||||
Ref<Biome> b = _biomes[i];
|
||||
|
||||
if (!b.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_biome(b->instance(seed));
|
||||
}
|
||||
|
||||
for (int i = 0; i < _dungeons.size(); ++i) {
|
||||
Ref<Dungeon> d = _dungeons[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_dungeon(d->instance(seed));
|
||||
}
|
||||
|
||||
#ifdef FASTNOISE_PRESENT
|
||||
inst->set_humidity_noise_params(_humidity_noise_params->duplicate());
|
||||
inst->set_temperature_noise_params(_temperature_noise_params->duplicate());
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _environment_datas.size(); ++i) {
|
||||
Ref<EnvironmentData> d = _environment_datas[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_environment_data(d);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _voxel_surfaces.size(); ++i) {
|
||||
Ref<VoxelSurface> d = _voxel_surfaces[i];
|
||||
|
||||
if (!d.is_valid())
|
||||
continue;
|
||||
|
||||
inst->add_voxel_surface(d);
|
||||
}
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
void Planet::setup() {
|
||||
if (has_method("_setup")) {
|
||||
call("_setup");
|
||||
@ -319,11 +385,15 @@ Planet::~Planet() {
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
_environment_datas.clear();
|
||||
_voxel_surfaces.clear();
|
||||
_liquid_voxel_surfaces.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Planet::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "inst", PROPERTY_HINT_RESOURCE_TYPE, "Planet"),
|
||||
"_instance",
|
||||
PropertyInfo(Variant::INT, "seed"),
|
||||
PropertyInfo(Variant::OBJECT, "instance", PROPERTY_HINT_RESOURCE_TYPE, "Planet")));
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_setup"));
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
@ -334,6 +404,9 @@ void Planet::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::BOOL, "spawn_mobs")));
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("instance", "seed"), &Planet::instance);
|
||||
ClassDB::bind_method(D_METHOD("_instance", "seed", "instance"), &Planet::_instance);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("setup"), &Planet::setup);
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
|
@ -108,6 +108,9 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
Ref<Planet> instance(const int seed);
|
||||
virtual Ref<Planet> _instance(const int seed, Ref<Planet> planet);
|
||||
|
||||
void setup();
|
||||
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
@ -149,7 +152,6 @@ private:
|
||||
#ifdef VOXELMAN_PRESENT
|
||||
Vector<Ref<EnvironmentData> > _environment_datas;
|
||||
Vector<Ref<VoxelSurface> > _voxel_surfaces;
|
||||
Vector<Ref<VoxelSurface> > _liquid_voxel_surfaces;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user