diff --git a/main/biome.cpp b/main/biome.cpp index 3361e10..3340780 100644 --- a/main/biome.cpp +++ b/main/biome.cpp @@ -281,22 +281,18 @@ void Biome::set_voxel_surfaces(const Vector &voxel_surfaces) { #endif Ref Biome::instance(const int seed) { - if (has_method("_instance")) { - return call("_instance", seed, Ref()); - } + Ref inst; - return Ref(); -} + inst = Ref(Object::cast_to(ClassDB::instance(get_class_name()))); + ERR_FAIL_COND_V(!inst.is_valid(), inst); -Ref Biome::_instance(const int seed, Ref biome) { - Ref inst = biome; - - if (!inst.is_valid()) - inst.instance(); - - if (inst->get_script().is_null() && !get_script().is_null()) + if (!get_script().is_null()) inst->set_script(get_script()); + return call("_instance", seed, inst); +} + +Ref Biome::_instance(const int seed, Ref inst) { inst->set_current_seed(seed); inst->set_level_range(_level_range); diff --git a/main/biome.h b/main/biome.h index 5355629..61a6c5a 100644 --- a/main/biome.h +++ b/main/biome.h @@ -119,7 +119,7 @@ public: #endif Ref instance(const int seed); - virtual Ref _instance(const int seed, Ref biome); + virtual Ref _instance(const int seed, Ref inst); void setup(); diff --git a/main/dungeon.cpp b/main/dungeon.cpp index db97e5b..80928ca 100644 --- a/main/dungeon.cpp +++ b/main/dungeon.cpp @@ -463,22 +463,18 @@ void Dungeon::set_environment_datas(const Vector &environment_datas) { #endif Ref Dungeon::instance(const int seed) { - if (has_method("_instance")) { - return call("_instance", seed, Ref()); - } + Ref inst; - return Ref(); -} + inst = Ref(Object::cast_to(ClassDB::instance(get_class_name()))); + ERR_FAIL_COND_V(!inst.is_valid(), inst); -Ref Dungeon::_instance(const int seed, Ref dungeon) { - Ref inst = dungeon; - - if (!inst.is_valid()) - inst.instance(); - - if (inst->get_script().is_null() && !get_script().is_null()) + if (!get_script().is_null()) inst->set_script(get_script()); + return call("_instance", seed, inst); +} + +Ref Dungeon::_instance(const int seed, Ref inst) { inst->set_current_seed(seed); inst->set_level_range(_level_range); diff --git a/main/dungeon.h b/main/dungeon.h index d384437..eda84c9 100644 --- a/main/dungeon.h +++ b/main/dungeon.h @@ -187,7 +187,7 @@ public: #endif Ref instance(const int seed); - virtual Ref _instance(const int seed, Ref dungeon); + virtual Ref _instance(const int seed, Ref inst); void setup(); diff --git a/main/dungeon_corridor.cpp b/main/dungeon_corridor.cpp index 78c846a..6b45320 100644 --- a/main/dungeon_corridor.cpp +++ b/main/dungeon_corridor.cpp @@ -53,17 +53,13 @@ int DungeonCorridor::get_dungeon_room_count() const { return _dungeon_rooms.size(); } -Ref DungeonCorridor::_instance(const int seed, Ref dungeon_room) { - Ref inst = dungeon_room; - - if (!inst.is_valid()) - inst.instance(); - +Ref DungeonCorridor::_instance(const int seed, Ref inst) { DungeonRoom::_instance(seed, inst); - inst->set_max_connections(_max_connections); + Ref cinst = inst; + cinst->set_max_connections(_max_connections); - return inst; + return cinst; } DungeonCorridor::DungeonCorridor() { diff --git a/main/dungeon_corridor.h b/main/dungeon_corridor.h index 50991ed..b5c109c 100644 --- a/main/dungeon_corridor.h +++ b/main/dungeon_corridor.h @@ -40,7 +40,7 @@ public: int get_dungeon_room_count() const; - Ref _instance(const int seed, Ref dungeon_room); + Ref _instance(const int seed, Ref inst); DungeonCorridor(); ~DungeonCorridor(); diff --git a/main/dungeon_room.cpp b/main/dungeon_room.cpp index 11bbd09..e8094a5 100644 --- a/main/dungeon_room.cpp +++ b/main/dungeon_room.cpp @@ -321,22 +321,18 @@ void DungeonRoom::set_entity_datas(const Vector &entity_datas) { #endif Ref DungeonRoom::instance(const int seed) { - if (has_method("_instance")) { - return call("_instance", seed, Ref()); - } + Ref inst; - return Ref(); -} + inst = Ref(Object::cast_to(ClassDB::instance(get_class_name()))); + ERR_FAIL_COND_V(!inst.is_valid(), inst); -Ref DungeonRoom::_instance(const int seed, Ref dungeon_room) { - Ref inst = dungeon_room; - - if (!inst.is_valid()) - inst.instance(); - - if (inst->get_script().is_null() && !get_script().is_null()) + if (!get_script().is_null()) inst->set_script(get_script()); + return call("_instance", seed, inst); +} + +Ref DungeonRoom::_instance(const int seed, Ref inst) { inst->set_current_seed(seed); inst->set_level_range(_level_range); diff --git a/main/dungeon_room.h b/main/dungeon_room.h index 8a96799..232f60e 100644 --- a/main/dungeon_room.h +++ b/main/dungeon_room.h @@ -156,7 +156,7 @@ public: #endif Ref instance(const int seed); - virtual Ref _instance(const int seed, Ref dungeon_room); + virtual Ref _instance(const int seed, Ref inst); void setup(); diff --git a/main/planet.cpp b/main/planet.cpp index b72edee..055aeca 100644 --- a/main/planet.cpp +++ b/main/planet.cpp @@ -226,22 +226,18 @@ void Planet::set_voxel_surfaces(const Vector &voxel_surfaces) { #endif Ref Planet::instance(const int seed) { - if (has_method("_instance")) { - return call("_instance", seed, Ref()); - } + Ref inst; - return Ref(); -} + inst = Ref(Object::cast_to(ClassDB::instance(get_class_name()))); + ERR_FAIL_COND_V(!inst.is_valid(), inst); -Ref Planet::_instance(const int seed, Ref planet) { - Ref inst = planet; - - if (!inst.is_valid()) - inst.instance(); - - if (inst->get_script().is_null() && !get_script().is_null()) + if (!get_script().is_null()) inst->set_script(get_script()); + return call("_instance", seed, inst); +} + +Ref Planet::_instance(const int seed, Ref inst) { inst->set_id(_id); inst->set_current_seed(seed); inst->set_level_range(_level_range); diff --git a/main/planet.h b/main/planet.h index 7c8012d..94611d1 100644 --- a/main/planet.h +++ b/main/planet.h @@ -109,7 +109,7 @@ public: #endif Ref instance(const int seed); - virtual Ref _instance(const int seed, Ref planet); + virtual Ref _instance(const int seed, Ref inst); void setup();