Fix compile for older versions of the engine than 3.x.

This commit is contained in:
Relintai 2021-08-29 18:55:51 +02:00
parent d9d157bf37
commit 2afd6eff45
6 changed files with 39 additions and 12 deletions

6
SCsub
View File

@ -4,6 +4,8 @@ Import('env')
module_env = env.Clone()
import version
if os.path.isdir('../mesh_data_resource'):
module_env.Append(CPPDEFINES=['MESH_DATA_RESOURCE_PRESENT'])
@ -37,7 +39,6 @@ sources = [
"props/prop_data_scene.cpp",
"props/prop_data_light.cpp",
"props/prop_data_prop.cpp",
"props/prop_data_portal.cpp",
"props/prop_data_tiled_wall.cpp",
"clutter/ground_clutter.cpp",
@ -65,6 +66,9 @@ sources = [
"material_cache/prop_material_cache.cpp"
]
if version.minor >= 4:
sources.append("props/prop_data_portal.cpp")
if has_texture_packer:
sources.append("material_cache/prop_material_cache_pcm.cpp")

View File

@ -82,6 +82,7 @@ void PropEditorPlugin::convert_scene(Node *root, const String &path) {
}
void PropEditorPlugin::find_room_points(Variant param) {
#if VERSION_MINOR >= 4
SceneTree *st = SceneTree::get_singleton();
if (st) {
@ -91,6 +92,7 @@ void PropEditorPlugin::find_room_points(Variant param) {
PropUtils::get_singleton()->generate_room_points_node(scene);
}
}
#endif
}
void PropEditorPlugin::_quick_convert_button_pressed() {
@ -110,7 +112,9 @@ PropEditorPlugin::PropEditorPlugin(EditorNode *p_node) {
#if VERSION_MAJOR < 4
editor->add_tool_menu_item("Convert active scene to PropData", this, "convert_active_scene_to_prop_data");
editor->add_tool_menu_item("Convert selected scene(s) to PropData", this, "convert_selected_scene_to_prop_data");
#if VERSION_MINOR >= 4
editor->add_tool_menu_item("(Prop) Find room points.", this, "find_room_points");
#endif
#else
#endif

View File

@ -36,11 +36,14 @@ SOFTWARE.
#include "props/prop_data.h"
#include "props/prop_data_entry.h"
#include "props/prop_data_light.h"
#include "props/prop_data_portal.h"
#include "props/prop_data_prop.h"
#include "props/prop_data_scene.h"
#include "props/prop_data_tiled_wall.h"
#if VERSION_MINOR >= 4
#include "props/prop_data_portal.h"
#endif
#include "clutter/ground_clutter.h"
#include "clutter/ground_clutter_foliage.h"
@ -85,9 +88,12 @@ void register_props_types() {
ClassDB::register_class<PropDataScene>();
ClassDB::register_class<PropDataLight>();
ClassDB::register_class<PropDataProp>();
ClassDB::register_class<PropDataPortal>();
ClassDB::register_class<PropDataTiledWall>();
#if VERSION_MINOR >= 4
ClassDB::register_class<PropDataPortal>();
#endif
ClassDB::register_class<GroundClutter>();
ClassDB::register_class<GroundClutterFoliage>();
@ -129,8 +135,10 @@ void register_props_types() {
Ref<PropDataScene> scene_processor = Ref<PropDataScene>(memnew(PropDataScene));
PropUtils::add_processor(scene_processor);
#if VERSION_MINOR >= 4
Ref<PropDataPortal> portal_processor = Ref<PropDataPortal>(memnew(PropDataPortal));
PropUtils::add_processor(portal_processor);
#endif
Ref<PropDataTiledWall> tiled_wall_processor = Ref<PropDataTiledWall>(memnew(PropDataTiledWall));
PropUtils::add_processor(tiled_wall_processor);

View File

@ -25,15 +25,16 @@ SOFTWARE.
#include "../props/prop_data.h"
#include "../props/prop_data_entry.h"
#include "scene/3d/room.h"
#include "core/version.h"
#if VERSION_MINOR >= 4
#include "core/math/quick_hull.h"
#include "scene/3d/portal.h"
#include "scene/3d/room.h"
#include "scene/3d/room_manager.h"
#endif
#include "core/math/quick_hull.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/portal.h"
#if MESH_DATA_RESOURCE_PRESENT
#include "../../mesh_data_resource/nodes/mesh_data_instance.h"
@ -46,7 +47,7 @@ SOFTWARE.
#endif
PropUtils *PropUtils::_instance;
Vector<Ref<PropDataEntry>> PropUtils::_processors;
Vector<Ref<PropDataEntry> > PropUtils::_processors;
PropUtils *PropUtils::get_singleton() {
return _instance;
@ -106,6 +107,7 @@ void PropUtils::_convert_tree(Ref<PropData> prop_data, Node *node, const Transfo
}
}
} else {
#if VERSION_MINOR >= 4
//only handle the first encountered room per prop
if (!prop_data->get_is_room()) {
Room *r = Object::cast_to<Room>(sp);
@ -118,6 +120,7 @@ void PropUtils::_convert_tree(Ref<PropData> prop_data, Node *node, const Transfo
prop_data->set_room_bounds(points);
}
}
#endif
for (int i = 0; i < node->get_child_count(); ++i) {
Node *child = node->get_child(i);
@ -134,6 +137,7 @@ void PropUtils::_convert_tree(Ref<PropData> prop_data, Node *node, const Transfo
}
}
#if VERSION_MINOR >= 4
bool PropUtils::generate_room_points_node(Node *node) {
ERR_FAIL_COND_V(!ObjectDB::instance_validate(node), false);
@ -157,7 +161,7 @@ bool PropUtils::generate_room_points_node(Node *node) {
void PropUtils::generate_room_points(Room *room) {
ERR_FAIL_COND(!ObjectDB::instance_validate(room));
Vector<PoolVector<Vector3>> mesh_arrays;
Vector<PoolVector<Vector3> > mesh_arrays;
get_mesh_arrays(room, &mesh_arrays);
@ -302,7 +306,7 @@ bool PropUtils::is_plane_unique(const PoolVector<Plane> &planes, const Plane &p)
return true;
}
void PropUtils::get_mesh_arrays(Node *node, Vector<PoolVector<Vector3>> *arrs) {
void PropUtils::get_mesh_arrays(Node *node, Vector<PoolVector<Vector3> > *arrs) {
ERR_FAIL_COND(!ObjectDB::instance_validate(node));
for (int i = 0; i < node->get_child_count(); ++i) {
@ -456,6 +460,8 @@ void PropUtils::get_mesh_arrays(Node *node, Vector<PoolVector<Vector3>> *arrs) {
}
}
#endif
int PropUtils::add_processor(const Ref<PropDataEntry> &processor) {
ERR_FAIL_COND_V(!processor.is_valid(), 0);

View File

@ -41,7 +41,10 @@ SOFTWARE.
class PropData;
class PropDataEntry;
#if VERSION_MINOR >= 4
class Room;
#endif
class PropUtils : public Object {
GDCLASS(PropUtils, Object);
@ -52,11 +55,12 @@ public:
Ref<PropData> convert_tree(Node *root);
void _convert_tree(Ref<PropData> prop_data, Node *node, const Transform &transform);
#if VERSION_MINOR >= 4
bool generate_room_points_node(Node *node);
void generate_room_points(Room *room);
void get_mesh_arrays(Node *node, Vector<PoolVector<Vector3>> *arrs);
bool is_plane_unique(const PoolVector<Plane> &planes, const Plane &p);
#endif
static int add_processor(const Ref<PropDataEntry> &processor);
static Ref<PropDataEntry> get_processor(const int index);

View File

@ -2,7 +2,6 @@
#include "core/version.h"
#include "core/version.h"
#include "scene/resources/texture.h"
#if VERSION_MAJOR < 4
@ -290,8 +289,10 @@ TiledWall::TiledWall() {
_physics_body_rid = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC);
#if VERSION_MINOR >= 4
//temporary
set_portal_mode(PORTAL_MODE_GLOBAL);
#endif
_mesher.instance();
}