summaryrefslogtreecommitdiff
path: root/scene/resources/world_3d.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-05-14 23:09:03 +0200
committerGitHub <noreply@github.com>2020-05-14 23:09:03 +0200
commit00949f0c5fcc6a4f8382a4a97d5591fd9ec380f8 (patch)
tree2b1c31f45add24085b64425ce440f577424c16a1 /scene/resources/world_3d.cpp
parent5046f666a1181675b39f156c38346525dc1c444e (diff)
parent0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (diff)
Merge pull request #38738 from akien-mga/cause-we-never-go-out-of-style
Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks
Diffstat (limited to 'scene/resources/world_3d.cpp')
-rw-r--r--scene/resources/world_3d.cpp63
1 files changed, 18 insertions, 45 deletions
diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp
index dee00dd82a..8100f150ef 100644
--- a/scene/resources/world_3d.cpp
+++ b/scene/resources/world_3d.cpp
@@ -37,18 +37,15 @@
#include "scene/scene_string_names.h"
struct SpatialIndexer {
-
Octree<VisibilityNotifier3D> octree;
struct NotifierData {
-
AABB aabb;
OctreeElementID id;
};
Map<VisibilityNotifier3D *, NotifierData> notifiers;
struct CameraData {
-
Map<VisibilityNotifier3D *, uint64_t> notifiers;
};
@@ -65,7 +62,6 @@ struct SpatialIndexer {
uint64_t last_frame;
void _notifier_add(VisibilityNotifier3D *p_notifier, const AABB &p_rect) {
-
ERR_FAIL_COND(notifiers.has(p_notifier));
notifiers[p_notifier].aabb = p_rect;
notifiers[p_notifier].id = octree.create(p_notifier, p_rect);
@@ -73,11 +69,11 @@ struct SpatialIndexer {
}
void _notifier_update(VisibilityNotifier3D *p_notifier, const AABB &p_rect) {
-
Map<VisibilityNotifier3D *, NotifierData>::Element *E = notifiers.find(p_notifier);
ERR_FAIL_COND(!E);
- if (E->get().aabb == p_rect)
+ if (E->get().aabb == p_rect) {
return;
+ }
E->get().aabb = p_rect;
octree.move(E->get().id, E->get().aabb);
@@ -85,7 +81,6 @@ struct SpatialIndexer {
}
void _notifier_remove(VisibilityNotifier3D *p_notifier) {
-
Map<VisibilityNotifier3D *, NotifierData>::Element *E = notifiers.find(p_notifier);
ERR_FAIL_COND(!E);
@@ -94,7 +89,6 @@ struct SpatialIndexer {
List<Camera3D *> removed;
for (Map<Camera3D *, CameraData>::Element *F = cameras.front(); F; F = F->next()) {
-
Map<VisibilityNotifier3D *, uint64_t>::Element *G = F->get().notifiers.find(p_notifier);
if (G) {
@@ -104,7 +98,6 @@ struct SpatialIndexer {
}
while (!removed.empty()) {
-
p_notifier->_exit_camera(removed.front()->get());
removed.pop_front();
}
@@ -113,7 +106,6 @@ struct SpatialIndexer {
}
void _add_camera(Camera3D *p_camera) {
-
ERR_FAIL_COND(cameras.has(p_camera));
CameraData vd;
cameras[p_camera] = vd;
@@ -121,7 +113,6 @@ struct SpatialIndexer {
}
void _update_camera(Camera3D *p_camera) {
-
Map<Camera3D *, CameraData>::Element *E = cameras.find(p_camera);
ERR_FAIL_COND(!E);
changed = true;
@@ -131,7 +122,6 @@ struct SpatialIndexer {
ERR_FAIL_COND(!cameras.has(p_camera));
List<VisibilityNotifier3D *> removed;
for (Map<VisibilityNotifier3D *, uint64_t>::Element *E = cameras[p_camera].notifiers.front(); E; E = E->next()) {
-
removed.push_back(E->key());
}
@@ -144,16 +134,16 @@ struct SpatialIndexer {
}
void _update(uint64_t p_frame) {
-
- if (p_frame == last_frame)
+ if (p_frame == last_frame) {
return;
+ }
last_frame = p_frame;
- if (!changed)
+ if (!changed) {
return;
+ }
for (Map<Camera3D *, CameraData>::Element *E = cameras.front(); E; E = E->next()) {
-
pass++;
Camera3D *c = E->key();
@@ -168,12 +158,10 @@ struct SpatialIndexer {
List<VisibilityNotifier3D *> removed;
for (int i = 0; i < culled; i++) {
-
//notifiers in frustum
Map<VisibilityNotifier3D *, uint64_t>::Element *H = E->get().notifiers.find(ptr[i]);
if (!H) {
-
E->get().notifiers.insert(ptr[i], pass);
added.push_back(ptr[i]);
} else {
@@ -182,9 +170,9 @@ struct SpatialIndexer {
}
for (Map<VisibilityNotifier3D *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) {
-
- if (F->get() != pass)
+ if (F->get() != pass) {
removed.push_back(F->key());
+ }
}
while (!added.empty()) {
@@ -202,7 +190,6 @@ struct SpatialIndexer {
}
SpatialIndexer() {
-
pass = 0;
last_frame = 0;
changed = false;
@@ -211,60 +198,52 @@ struct SpatialIndexer {
};
void World3D::_register_camera(Camera3D *p_camera) {
-
#ifndef _3D_DISABLED
indexer->_add_camera(p_camera);
#endif
}
void World3D::_update_camera(Camera3D *p_camera) {
-
#ifndef _3D_DISABLED
indexer->_update_camera(p_camera);
#endif
}
-void World3D::_remove_camera(Camera3D *p_camera) {
+void World3D::_remove_camera(Camera3D *p_camera) {
#ifndef _3D_DISABLED
indexer->_remove_camera(p_camera);
#endif
}
void World3D::_register_notifier(VisibilityNotifier3D *p_notifier, const AABB &p_rect) {
-
#ifndef _3D_DISABLED
indexer->_notifier_add(p_notifier, p_rect);
#endif
}
void World3D::_update_notifier(VisibilityNotifier3D *p_notifier, const AABB &p_rect) {
-
#ifndef _3D_DISABLED
indexer->_notifier_update(p_notifier, p_rect);
#endif
}
void World3D::_remove_notifier(VisibilityNotifier3D *p_notifier) {
-
#ifndef _3D_DISABLED
indexer->_notifier_remove(p_notifier);
#endif
}
void World3D::_update(uint64_t p_frame) {
-
#ifndef _3D_DISABLED
indexer->_update(p_frame);
#endif
}
RID World3D::get_space() const {
-
return space;
}
RID World3D::get_scenario() const {
-
return scenario;
}
@@ -274,16 +253,16 @@ void World3D::set_environment(const Ref<Environment> &p_environment) {
}
environment = p_environment;
- if (environment.is_valid())
+ if (environment.is_valid()) {
RS::get_singleton()->scenario_set_environment(scenario, environment->get_rid());
- else
+ } else {
RS::get_singleton()->scenario_set_environment(scenario, RID());
+ }
emit_changed();
}
Ref<Environment> World3D::get_environment() const {
-
return environment;
}
@@ -293,47 +272,43 @@ void World3D::set_fallback_environment(const Ref<Environment> &p_environment) {
}
fallback_environment = p_environment;
- if (fallback_environment.is_valid())
+ if (fallback_environment.is_valid()) {
RS::get_singleton()->scenario_set_fallback_environment(scenario, p_environment->get_rid());
- else
+ } else {
RS::get_singleton()->scenario_set_fallback_environment(scenario, RID());
+ }
emit_changed();
}
Ref<Environment> World3D::get_fallback_environment() const {
-
return fallback_environment;
}
void World3D::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) {
-
camera_effects = p_camera_effects;
- if (camera_effects.is_valid())
+ if (camera_effects.is_valid()) {
RS::get_singleton()->scenario_set_camera_effects(scenario, camera_effects->get_rid());
- else
+ } else {
RS::get_singleton()->scenario_set_camera_effects(scenario, RID());
+ }
}
Ref<CameraEffects> World3D::get_camera_effects() const {
-
return camera_effects;
}
PhysicsDirectSpaceState3D *World3D::get_direct_space_state() {
-
return PhysicsServer3D::get_singleton()->space_get_direct_state(space);
}
void World3D::get_camera_list(List<Camera3D *> *r_cameras) {
-
for (Map<Camera3D *, SpatialIndexer::CameraData>::Element *E = indexer->cameras.front(); E; E = E->next()) {
r_cameras->push_back(E->key());
}
}
void World3D::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space);
ClassDB::bind_method(D_METHOD("get_scenario"), &World3D::get_scenario);
ClassDB::bind_method(D_METHOD("set_environment", "env"), &World3D::set_environment);
@@ -352,7 +327,6 @@ void World3D::_bind_methods() {
}
World3D::World3D() {
-
space = PhysicsServer3D::get_singleton()->space_create();
scenario = RenderingServer::get_singleton()->scenario_create();
@@ -372,7 +346,6 @@ World3D::World3D() {
}
World3D::~World3D() {
-
PhysicsServer3D::get_singleton()->free(space);
RenderingServer::get_singleton()->free(scenario);