Skip to content

Commit

Permalink
Merge pull request #89381 from aaronfranke/disable-3d
Browse files Browse the repository at this point in the history
Disable all 3D nodes, physics, and resources when compiling without 3D
  • Loading branch information
akien-mga committed Mar 11, 2024
2 parents effb270 + 6aac3e4 commit f040a35
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 19 deletions.
11 changes: 10 additions & 1 deletion main/performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@
#include "servers/audio_server.h"
#include "servers/navigation_server_3d.h"
#include "servers/physics_server_2d.h"
#include "servers/physics_server_3d.h"
#include "servers/rendering_server.h"

#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#endif // _3D_DISABLED

Performance *Performance::singleton = nullptr;

void Performance::_bind_methods() {
Expand Down Expand Up @@ -71,9 +74,11 @@ void Performance::_bind_methods() {
BIND_ENUM_CONSTANT(PHYSICS_2D_ACTIVE_OBJECTS);
BIND_ENUM_CONSTANT(PHYSICS_2D_COLLISION_PAIRS);
BIND_ENUM_CONSTANT(PHYSICS_2D_ISLAND_COUNT);
#ifndef _3D_DISABLED
BIND_ENUM_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS);
BIND_ENUM_CONSTANT(PHYSICS_3D_COLLISION_PAIRS);
BIND_ENUM_CONSTANT(PHYSICS_3D_ISLAND_COUNT);
#endif // _3D_DISABLED
BIND_ENUM_CONSTANT(AUDIO_OUTPUT_LATENCY);
BIND_ENUM_CONSTANT(NAVIGATION_ACTIVE_MAPS);
BIND_ENUM_CONSTANT(NAVIGATION_REGION_COUNT);
Expand Down Expand Up @@ -119,9 +124,11 @@ String Performance::get_monitor_name(Monitor p_monitor) const {
"physics_2d/active_objects",
"physics_2d/collision_pairs",
"physics_2d/islands",
#ifndef _3D_DISABLED
"physics_3d/active_objects",
"physics_3d/collision_pairs",
"physics_3d/islands",
#endif // _3D_DISABLED
"audio/driver/output_latency",
"navigation/active_maps",
"navigation/regions",
Expand Down Expand Up @@ -248,9 +255,11 @@ Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
#ifndef _3D_DISABLED
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
#endif // _3D_DISABLED
MONITOR_TYPE_TIME,
MONITOR_TYPE_QUANTITY,
MONITOR_TYPE_QUANTITY,
Expand Down
5 changes: 3 additions & 2 deletions modules/navigation/3d/godot_navigation_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@

#include "godot_navigation_server_3d.h"

#include "core/os/mutex.h"
#include "scene/main/node.h"

#ifndef _3D_DISABLED
#include "nav_mesh_generator_3d.h"
#endif // _3D_DISABLED

#include "core/os/mutex.h"

using namespace NavigationUtilities;

/// Creates a struct for each function and a function that once called creates
Expand Down
9 changes: 6 additions & 3 deletions scene/animation/animation_mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@

#include "core/config/engine.h"
#include "core/config/project_settings.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/node_3d.h"
#include "scene/3d/skeleton_3d.h"
#include "scene/animation/animation_player.h"
#include "scene/resources/animation.h"
#include "scene/scene_string_names.h"
#include "servers/audio/audio_stream.h"

#ifndef _3D_DISABLED
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/node_3d.h"
#include "scene/3d/skeleton_3d.h"
#endif // _3D_DISABLED

#ifdef TOOLS_ENABLED
#include "editor/editor_node.h"
#include "editor/editor_undo_redo_manager.h"
Expand Down
6 changes: 3 additions & 3 deletions scene/main/shader_globals_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "shader_globals_override.h"

#include "scene/3d/node_3d.h"
#include "scene/main/node.h"
#include "scene/scene_string_names.h"

StringName *ShaderGlobalsOverride::_remap(const StringName &p_name) const {
Expand Down Expand Up @@ -247,12 +247,12 @@ void ShaderGlobalsOverride::_activate() {

void ShaderGlobalsOverride::_notification(int p_what) {
switch (p_what) {
case Node3D::NOTIFICATION_ENTER_TREE: {
case Node::NOTIFICATION_ENTER_TREE: {
add_to_group(SceneStringNames::get_singleton()->shader_overrides_group);
_activate();
} break;

case Node3D::NOTIFICATION_EXIT_TREE: {
case Node::NOTIFICATION_EXIT_TREE: {
if (active) {
//remove overrides
for (const KeyValue<StringName, Override> &E : overrides) {
Expand Down
4 changes: 0 additions & 4 deletions scene/resources/3d/world_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@
#include "servers/navigation_server_3d.h"

void World3D::_register_camera(Camera3D *p_camera) {
#ifndef _3D_DISABLED
cameras.insert(p_camera);
#endif
}

void World3D::_remove_camera(Camera3D *p_camera) {
#ifndef _3D_DISABLED
cameras.erase(p_camera);
#endif
}

RID World3D::get_space() const {
Expand Down
3 changes: 2 additions & 1 deletion scene/resources/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ env.scene_sources += scene_obj
env.Depends(scene_obj, thirdparty_obj)

SConscript("2d/SCsub")
SConscript("3d/SCsub")
if not env["disable_3d"]:
SConscript("3d/SCsub")
6 changes: 6 additions & 0 deletions scene/resources/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
#include "core/templates/pair.h"
#include "scene/resources/surface_tool.h"

#ifndef _3D_DISABLED
#include "scene/resources/3d/concave_polygon_shape_3d.h"
#include "scene/resources/3d/convex_polygon_shape_3d.h"
#endif // _3D_DISABLED

void MeshConvexDecompositionSettings::set_max_concavity(real_t p_max_concavity) {
max_concavity = CLAMP(p_max_concavity, 0.001, 1.0);
Expand Down Expand Up @@ -519,6 +521,7 @@ Vector<Face3> Mesh::get_surface_faces(int p_surface) const {
return Vector<Face3>();
}

#ifndef _3D_DISABLED
Ref<ConvexPolygonShape3D> Mesh::create_convex_shape(bool p_clean, bool p_simplify) const {
if (p_simplify) {
Ref<MeshConvexDecompositionSettings> settings = Ref<MeshConvexDecompositionSettings>();
Expand Down Expand Up @@ -578,6 +581,7 @@ Ref<ConcavePolygonShape3D> Mesh::create_trimesh_shape() const {
shape->set_faces(face_points);
return shape;
}
#endif // _3D_DISABLED

Ref<Mesh> Mesh::create_outline(float p_margin) const {
Array arrays;
Expand Down Expand Up @@ -896,6 +900,7 @@ void Mesh::clear_cache() const {
debug_lines.clear();
}

#ifndef _3D_DISABLED
Vector<Ref<Shape3D>> Mesh::convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const {
ERR_FAIL_NULL_V(convex_decomposition_function, Vector<Ref<Shape3D>>());

Expand Down Expand Up @@ -932,6 +937,7 @@ Vector<Ref<Shape3D>> Mesh::convex_decompose(const Ref<MeshConvexDecompositionSet

return ret;
}
#endif // _3D_DISABLED

int Mesh::get_builtin_bind_pose_count() const {
return 0;
Expand Down
4 changes: 4 additions & 0 deletions scene/resources/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include "core/io/resource.h"
#include "core/math/face3.h"
#include "core/math/triangle_mesh.h"
#ifndef _3D_DISABLED
#include "scene/resources/3d/shape_3d.h"
#endif // _3D_DISABLED
#include "scene/resources/material.h"
#include "servers/rendering_server.h"

Expand Down Expand Up @@ -194,9 +196,11 @@ class Mesh : public Resource {

static ConvexDecompositionFunc convex_decomposition_function;

#ifndef _3D_DISABLED
Vector<Ref<Shape3D>> convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const;
Ref<ConvexPolygonShape3D> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
Ref<ConcavePolygonShape3D> create_trimesh_shape() const;
#endif // _3D_DISABLED

virtual int get_builtin_bind_pose_count() const;
virtual Transform3D get_builtin_bind_pose(int p_index) const;
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/navigation_mesh_source_geometry_data_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H
#define NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H

#include "scene/3d/visual_instance_3d.h"
#include "scene/resources/mesh.h"

class NavigationMeshSourceGeometryData3D : public Resource {
GDCLASS(NavigationMeshSourceGeometryData3D, Resource);
Expand Down
2 changes: 2 additions & 0 deletions scene/resources/packed_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
#include "core/io/resource_loader.h"
#include "core/templates/local_vector.h"
#include "scene/2d/node_2d.h"
#ifndef _3D_DISABLED
#include "scene/3d/node_3d.h"
#endif // _3D_DISABLED
#include "scene/gui/control.h"
#include "scene/main/instance_placeholder.h"
#include "scene/main/missing_node.h"
Expand Down
19 changes: 17 additions & 2 deletions servers/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
Import("env")

env.servers_sources = []
env.add_source_files(env.servers_sources, "*.cpp")

env.add_source_files(env.servers_sources, "audio_server.cpp")
env.add_source_files(env.servers_sources, "camera_server.cpp")
env.add_source_files(env.servers_sources, "display_server.cpp")
env.add_source_files(env.servers_sources, "native_menu.cpp")
env.add_source_files(env.servers_sources, "navigation_server_2d.cpp")
env.add_source_files(env.servers_sources, "navigation_server_3d.cpp")
env.add_source_files(env.servers_sources, "physics_server_2d.cpp")
env.add_source_files(env.servers_sources, "physics_server_2d_wrap_mt.cpp")
env.add_source_files(env.servers_sources, "register_server_types.cpp")
env.add_source_files(env.servers_sources, "rendering_server.cpp")
env.add_source_files(env.servers_sources, "text_server.cpp")
env.add_source_files(env.servers_sources, "xr_server.cpp")

SConscript("xr/SCsub")
SConscript("camera/SCsub")
SConscript("physics_3d/SCsub")
if not env["disable_3d"]:
SConscript("physics_3d/SCsub")
env.add_source_files(env.servers_sources, "physics_server_3d.cpp")
env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp")
SConscript("physics_2d/SCsub")
SConscript("rendering/SCsub")
SConscript("audio/SCsub")
Expand Down
5 changes: 4 additions & 1 deletion servers/extensions/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ Import("env")

env_object = env.Clone()

env_object.add_source_files(env.servers_sources, "*.cpp")
env_object.add_source_files(env.servers_sources, "physics_server_2d_extension.cpp")

if not env["disable_3d"]:
env_object.add_source_files(env.servers_sources, "physics_server_3d_extension.cpp")
2 changes: 2 additions & 0 deletions servers/navigation_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
/**************************************************************************/

#include "navigation_server_3d.h"

#include "core/config/project_settings.h"
#include "scene/main/node.h"

NavigationServer3D *NavigationServer3D::singleton = nullptr;

Expand Down
4 changes: 4 additions & 0 deletions servers/physics_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef _3D_DISABLED

#include "physics_server_3d.h"

#include "core/config/project_settings.h"
Expand Down Expand Up @@ -1213,3 +1215,5 @@ PhysicsServer3DManager::PhysicsServer3DManager() {
PhysicsServer3DManager::~PhysicsServer3DManager() {
singleton = nullptr;
}

#endif // _3D_DISABLED
4 changes: 4 additions & 0 deletions servers/physics_server_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#ifndef PHYSICS_SERVER_3D_H
#define PHYSICS_SERVER_3D_H

#ifndef _3D_DISABLED

#include "core/io/resource.h"
#include "core/object/class_db.h"
#include "core/object/gdvirtual.gen.inc"
Expand Down Expand Up @@ -1055,4 +1057,6 @@ VARIANT_ENUM_CAST(PhysicsServer3D::G6DOFJointAxisFlag);
VARIANT_ENUM_CAST(PhysicsServer3D::AreaBodyStatus);
VARIANT_ENUM_CAST(PhysicsServer3D::ProcessInfo);

#endif // _3D_DISABLED

#endif // PHYSICS_SERVER_3D_H
1 change: 0 additions & 1 deletion servers/rendering/rendering_light_culler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "core/math/plane.h"
#include "core/math/projection.h"
#include "rendering_server_globals.h"
#include "scene/3d/camera_3d.h"

#ifdef RENDERING_LIGHT_CULLER_DEBUG_STRINGS
const char *RenderingLightCuller::Data::string_planes[] = {
Expand Down

0 comments on commit f040a35

Please sign in to comment.