Browse Source

Fixing cleanup bugs

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
b2824f70ad

+ 3 - 3
CMakeLists.txt

@@ -56,10 +56,8 @@ else()
 	set(_ANKI_ENABLE_COUNTERS 0)
 	set(_ANKI_ENABLE_COUNTERS 0)
 endif()
 endif()
 
 
-# Address space
 set(ANKI_CPU_ADDR_SPACE "0" CACHE STRING "The CPU architecture (0 or 32 or 64). If zero go native")
 set(ANKI_CPU_ADDR_SPACE "0" CACHE STRING "The CPU architecture (0 or 32 or 64). If zero go native")
 
 
-# SIMD
 option(ANKI_ENABLE_SIMD "Enable or not SIMD optimizations" ON)
 option(ANKI_ENABLE_SIMD "Enable or not SIMD optimizations" ON)
 
 
 if(ANKI_ENABLE_SIMD)
 if(ANKI_ENABLE_SIMD)
@@ -70,7 +68,6 @@ endif()
 
 
 # Take a wild guess on the windowing system
 # Take a wild guess on the windowing system
 if(LINUX)
 if(LINUX)
-	#set(_WIN_BACKEND "GLXX11")
 	set(_WIN_BACKEND "SDL")
 	set(_WIN_BACKEND "SDL")
 elseif(WINDOWS)
 elseif(WINDOWS)
 	set(_WIN_BACKEND "SDL")
 	set(_WIN_BACKEND "SDL")
@@ -99,6 +96,9 @@ set(CXX_FLAGS "")
 set(COMPILER_FLAGS "")
 set(COMPILER_FLAGS "")
 set(LINKER_FLAGS "")
 set(LINKER_FLAGS "")
 
 
+# When building AnKi define this special flag
+set(COMPILER_FLAGS "${COMPILER_FLAGS} -DANKI_BUILD ")
+
 # address space
 # address space
 if(NOT ANKI_CPU_ADDR_SPACE STREQUAL "0")
 if(NOT ANKI_CPU_ADDR_SPACE STREQUAL "0")
 	set(LINKER_FLAGS "${LINKER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")
 	set(LINKER_FLAGS "${LINKER_FLAGS} -m${ANKI_CPU_ADDR_SPACE} ")

+ 1 - 1
include/anki/gr/GrManager.h

@@ -78,9 +78,9 @@ public:
 	/// @}
 	/// @}
 
 
 private:
 private:
+	GrAllocator<U8> m_alloc; ///< Keep it first to get deleted last
 	UniquePtr<GrManagerImpl> m_impl;
 	UniquePtr<GrManagerImpl> m_impl;
 	String m_cacheDir;
 	String m_cacheDir;
-	GrAllocator<U8> m_alloc; ///< Keep it last to deleted last
 };
 };
 
 
 template<typename T, typename... Args>
 template<typename T, typename... Args>

+ 5 - 1
include/anki/gr/gl/RenderingThread.h

@@ -69,7 +69,8 @@ public:
 private:
 private:
 	GrManager* m_manager = nullptr;
 	GrManager* m_manager = nullptr;
 
 
-	Array<CommandBufferPtr, 128> m_queue; ///< Command queue
+	static const U QUEUE_SIZE = 512;
+	DArray<CommandBufferPtr> m_queue; ///< Command queue
 	U64 m_tail; ///< Tail of queue
 	U64 m_tail; ///< Tail of queue
 	U64 m_head; ///< Head of queue. Points to the end
 	U64 m_head; ///< Head of queue. Points to the end
 	U8 m_renderingThreadSignal; ///< Signal to the thread
 	U8 m_renderingThreadSignal; ///< Signal to the thread
@@ -98,6 +99,9 @@ private:
 	CommandBufferPtr m_syncCommands;
 	CommandBufferPtr m_syncCommands;
 	Barrier m_syncBarrier{2};
 	Barrier m_syncBarrier{2};
 
 
+	/// Command buffer with an empty command.
+	CommandBufferPtr m_emptyCmdb;
+
 	/// The function that the thread runs
 	/// The function that the thread runs
 	static ANKI_USE_RESULT Error threadCallback(Thread::Info&);
 	static ANKI_USE_RESULT Error threadCallback(Thread::Info&);
 	void threadLoop();
 	void threadLoop();

+ 1 - 4
include/anki/physics/Common.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_PHYSICS_COMMON_H
-#define ANKI_PHYSICS_COMMON_H
+#pragma once
 
 
 #include "anki/util/StdTypes.h"
 #include "anki/util/StdTypes.h"
 #include "anki/util/Enum.h"
 #include "anki/util/Enum.h"
@@ -78,5 +77,3 @@ ANKI_USE_RESULT inline Mat4 toNewton(const Mat4& m)
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif
-

+ 5 - 7
include/anki/physics/PhysicsBody.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_PHYSICS_PHYSICS_BODY_H
-#define ANKI_PHYSICS_PHYSICS_BODY_H
+#pragma once
 
 
 #include "anki/physics/PhysicsObject.h"
 #include "anki/physics/PhysicsObject.h"
 
 
@@ -86,18 +85,17 @@ private:
 
 
 	/// Newton callback.
 	/// Newton callback.
 	static void onTransformCallback(
 	static void onTransformCallback(
-		const NewtonBody* const body, 
-		const dFloat* const matrix, 
+		const NewtonBody* const body,
+		const dFloat* const matrix,
 		int threadIndex);
 		int threadIndex);
 
 
 	/// Newton callback
 	/// Newton callback
 	static void applyGravityForce(
 	static void applyGravityForce(
-		const NewtonBody* body, 
-		dFloat timestep, 
+		const NewtonBody* body,
+		dFloat timestep,
 		int threadIndex);
 		int threadIndex);
 };
 };
 /// @}
 /// @}
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 4 - 6
include/anki/physics/PhysicsObject.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_PHYSICS_PHYSICS_OBJECT_H
-#define ANKI_PHYSICS_PHYSICS_OBJECT_H
+#pragma once
 
 
 #include "anki/physics/Common.h"
 #include "anki/physics/Common.h"
 
 
@@ -28,9 +27,9 @@ public:
 	};
 	};
 
 
 	PhysicsObject(Type type, PhysicsWorld* world)
 	PhysicsObject(Type type, PhysicsWorld* world)
-	:	m_world(world),
-		m_type(type),
-		m_refcount(0)
+		: m_world(world)
+		, m_type(type)
+		, m_refcount(0)
 	{
 	{
 		ANKI_ASSERT(m_world);
 		ANKI_ASSERT(m_world);
 	}
 	}
@@ -69,4 +68,3 @@ private:
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 15 - 15
include/anki/physics/PhysicsPlayerController.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_PHYSICS_PLAYER_CONTROLLER_H
-#define ANKI_PHYSICS_PLAYER_CONTROLLER_H
+#pragma once
 
 
 #include "anki/physics/PhysicsObject.h"
 #include "anki/physics/PhysicsObject.h"
 
 
@@ -14,8 +13,9 @@ namespace anki {
 /// @{
 /// @{
 
 
 /// Initializer for PhysicsPlayerController.
 /// Initializer for PhysicsPlayerController.
-struct PhysicsPlayerControllerInitializer
+class PhysicsPlayerControllerInitializer
 {
 {
+public:
 	F32 m_mass = 83.0;
 	F32 m_mass = 83.0;
 	F32 m_innerRadius = 0.30;
 	F32 m_innerRadius = 0.30;
 	F32 m_outerRadius = 0.50;
 	F32 m_outerRadius = 0.50;
@@ -31,13 +31,15 @@ public:
 	using Initializer = PhysicsPlayerControllerInitializer;
 	using Initializer = PhysicsPlayerControllerInitializer;
 
 
 	PhysicsPlayerController(PhysicsWorld* world)
 	PhysicsPlayerController(PhysicsWorld* world)
-	:	PhysicsObject(Type::PLAYER_CONTROLLER, world)
+		: PhysicsObject(Type::PLAYER_CONTROLLER, world)
 	{}
 	{}
 
 
+	~PhysicsPlayerController();
+
 	ANKI_USE_RESULT Error create(const Initializer& init);
 	ANKI_USE_RESULT Error create(const Initializer& init);
 
 
 	// Update the state machine
 	// Update the state machine
-	void setVelocity(F32 forwardSpeed, F32 strafeSpeed, F32 jumpSpeed, 
+	void setVelocity(F32 forwardSpeed, F32 strafeSpeed, F32 jumpSpeed,
 		const Vec4& forwardDir)
 		const Vec4& forwardDir)
 	{
 	{
 		m_forwardSpeed = forwardSpeed;
 		m_forwardSpeed = forwardSpeed;
@@ -65,8 +67,8 @@ public:
 
 
 	/// Called by Newton thread to update the controller.
 	/// Called by Newton thread to update the controller.
 	static void postUpdateKernelCallback(
 	static void postUpdateKernelCallback(
-		NewtonWorld* const world, 
-		void* const context, 
+		NewtonWorld* const world,
+		void* const context,
 		int threadIndex);
 		int threadIndex);
 	/// @}
 	/// @}
 
 
@@ -83,10 +85,10 @@ private:
 	F32 m_sphereCastOrigin;
 	F32 m_sphereCastOrigin;
 	F32 m_restrainingDistance;
 	F32 m_restrainingDistance;
 	Bool8 m_isJumping;
 	Bool8 m_isJumping;
+	NewtonBody* m_body;
 	NewtonCollision* m_castingShape;
 	NewtonCollision* m_castingShape;
 	NewtonCollision* m_supportShape;
 	NewtonCollision* m_supportShape;
 	NewtonCollision* m_upperBodyShape;
 	NewtonCollision* m_upperBodyShape;
-	NewtonBody* m_body;
 
 
 	// State
 	// State
 	F32 m_forwardSpeed = 0.0;
 	F32 m_forwardSpeed = 0.0;
@@ -115,22 +117,22 @@ private:
 
 
 	Vec4 calculateDesiredOmega(const Vec4& headingAngle, F32 dt) const;
 	Vec4 calculateDesiredOmega(const Vec4& headingAngle, F32 dt) const;
 
 
-	Vec4 calculateDesiredVelocity(F32 forwardSpeed, F32 strafeSpeed, 
+	Vec4 calculateDesiredVelocity(F32 forwardSpeed, F32 strafeSpeed,
 		F32 verticalSpeed, const Vec4& gravity, F32 dt) const;
 		F32 verticalSpeed, const Vec4& gravity, F32 dt) const;
 
 
 	void calculateVelocity(F32 dt);
 	void calculateVelocity(F32 dt);
 
 
-	F32 calculateContactKinematics(const Vec4& veloc, 
+	F32 calculateContactKinematics(const Vec4& veloc,
 		const NewtonWorldConvexCastReturnInfo* contactInfo) const;
 		const NewtonWorldConvexCastReturnInfo* contactInfo) const;
 
 
-	void updateGroundPlane(Mat4& matrix, const Mat4& castMatrix, 
+	void updateGroundPlane(Mat4& matrix, const Mat4& castMatrix,
 		const Vec4& dst, int threadIndex);
 		const Vec4& dst, int threadIndex);
 
 
 	void postUpdate(F32 dt, int threadIndex);
 	void postUpdate(F32 dt, int threadIndex);
 
 
 	static void onTransformCallback(
 	static void onTransformCallback(
-		const NewtonBody* const body, 
-		const dFloat* const matrix, 
+		const NewtonBody* const body,
+		const dFloat* const matrix,
 		int threadIndex);
 		int threadIndex);
 
 
 	void onTransform(Mat4 matrix);
 	void onTransform(Mat4 matrix);
@@ -139,5 +141,3 @@ private:
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif
-

+ 2 - 3
include/anki/physics/PhysicsWorld.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_PHYSICS_PHYSICS_WORLD_H
-#define ANKI_PHYSICS_PHYSICS_WORLD_H
+#pragma once
 
 
 #include "anki/physics/Common.h"
 #include "anki/physics/Common.h"
 #include "anki/util/List.h"
 #include "anki/util/List.h"
@@ -42,6 +41,7 @@ public:
 		return m_world;
 		return m_world;
 	}
 	}
 
 
+	/// Used for static collision.
 	NewtonCollision* getNewtonScene() const
 	NewtonCollision* getNewtonScene() const
 	{
 	{
 		return m_sceneCollision;
 		return m_sceneCollision;
@@ -149,4 +149,3 @@ inline PhysicsPtr<T> PhysicsWorld::newInstance(TArgs&&... args)
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 2 - 3
include/anki/resource/ResourceManager.h

@@ -123,6 +123,8 @@ public:
 
 
 	ANKI_USE_RESULT Error create(Initializer& init);
 	ANKI_USE_RESULT Error create(Initializer& init);
 
 
+	/// @privatesection
+	/// @{
 	U32 getMaxTextureSize() const
 	U32 getMaxTextureSize() const
 	{
 	{
 		return m_maxTextureSize;
 		return m_maxTextureSize;
@@ -133,8 +135,6 @@ public:
 		return m_textureAnisotropy;
 		return m_textureAnisotropy;
 	}
 	}
 
 
-	/// @privatesection
-	/// @{
 	ResourceAllocator<U8>& getAllocator()
 	ResourceAllocator<U8>& getAllocator()
 	{
 	{
 		return m_alloc;
 		return m_alloc;
@@ -210,7 +210,6 @@ private:
 	ResourceAllocator<U8> m_alloc;
 	ResourceAllocator<U8> m_alloc;
 	TempResourceAllocator<U8> m_tmpAlloc;
 	TempResourceAllocator<U8> m_tmpAlloc;
 	String m_cacheDir;
 	String m_cacheDir;
-	String m_dataDir;
 	U32 m_maxTextureSize;
 	U32 m_maxTextureSize;
 	U32 m_textureAnisotropy;
 	U32 m_textureAnisotropy;
 	String m_shadersPrependedSource;
 	String m_shadersPrependedSource;

+ 8 - 14
include/anki/scene/BodyComponent.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_SCENE_BODY_COMPONENT_H
-#define ANKI_SCENE_BODY_COMPONENT_H
+#pragma once
 
 
 #include "anki/scene/Common.h"
 #include "anki/scene/Common.h"
 #include "anki/scene/SceneComponent.h"
 #include "anki/scene/SceneComponent.h"
@@ -19,14 +18,9 @@ namespace anki {
 class BodyComponent: public SceneComponent
 class BodyComponent: public SceneComponent
 {
 {
 public:
 public:
-	static Bool classof(const SceneComponent& c)
-	{
-		return c.getType() == Type::BODY;
-	}
-
 	BodyComponent(SceneNode* node, PhysicsBodyPtr body)
 	BodyComponent(SceneNode* node, PhysicsBodyPtr body)
-	:	SceneComponent(Type::BODY, node), 
-		m_body(body)
+		: SceneComponent(Type::BODY, node)
+		, m_body(body)
 	{}
 	{}
 
 
 	~BodyComponent();
 	~BodyComponent();
@@ -46,14 +40,16 @@ public:
 		return m_body;
 		return m_body;
 	}
 	}
 
 
-	/// @name SceneComponent overrides
-	/// @{
 	ANKI_USE_RESULT Error update(SceneNode&, F32, F32, Bool& updated) override
 	ANKI_USE_RESULT Error update(SceneNode&, F32, F32, Bool& updated) override
 	{
 	{
 		m_trf = m_body->getTransform(updated);
 		m_trf = m_body->getTransform(updated);
 		return ErrorCode::NONE;
 		return ErrorCode::NONE;
 	}
 	}
-	/// @}
+
+	static Bool classof(const SceneComponent& c)
+	{
+		return c.getType() == Type::BODY;
+	}
 
 
 private:
 private:
 	PhysicsBodyPtr m_body;
 	PhysicsBodyPtr m_body;
@@ -63,5 +59,3 @@ private:
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif
-

+ 2 - 4
include/anki/scene/BodyNode.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_SCENE_BODY_NODE_H
-#define ANKI_SCENE_BODY_NODE_H
+#pragma once
 
 
 #include "anki/scene/SceneNode.h"
 #include "anki/scene/SceneNode.h"
 #include "anki/resource/CollisionResource.h"
 #include "anki/resource/CollisionResource.h"
@@ -19,7 +18,7 @@ class BodyNode: public SceneNode
 {
 {
 public:
 public:
 	BodyNode(SceneGraph* scene)
 	BodyNode(SceneGraph* scene)
-	:	SceneNode(scene)
+		: SceneNode(scene)
 	{}
 	{}
 
 
 	~BodyNode();
 	~BodyNode();
@@ -35,4 +34,3 @@ private:
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 2 - 4
include/anki/scene/Camera.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_SCENE_CAMERA_H
-#define ANKI_SCENE_CAMERA_H
+#pragma once
 
 
 #include "anki/scene/SceneNode.h"
 #include "anki/scene/SceneNode.h"
 #include "anki/scene/SpatialComponent.h"
 #include "anki/scene/SpatialComponent.h"
@@ -46,7 +45,7 @@ public:
 
 
 private:
 private:
 	Type m_type;
 	Type m_type;
-	
+
 	/// Called when moved.
 	/// Called when moved.
 	void onMoveComponentUpdate(MoveComponent& move);
 	void onMoveComponentUpdate(MoveComponent& move);
 
 
@@ -93,4 +92,3 @@ private:
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 1 - 3
include/anki/scene/Common.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_SCENE_COMMON_H
-#define ANKI_SCENE_COMMON_H
+#pragma once
 
 
 #include "anki/util/Allocator.h"
 #include "anki/util/Allocator.h"
 #include "anki/util/String.h"
 #include "anki/util/String.h"
@@ -36,4 +35,3 @@ using SceneDictionary =
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 1 - 3
include/anki/scene/Forward.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_SCENE_FORWARD_H
-#define ANKI_SCENE_FORWARD_H
+#pragma once
 
 
 namespace anki {
 namespace anki {
 
 
@@ -30,4 +29,3 @@ class Sector;
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 1 - 3
include/anki/scene/FrustumComponent.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_SCENE_FRUSTUM_COMPONENT_H
-#define ANKI_SCENE_FRUSTUM_COMPONENT_H
+#pragma once
 
 
 #include "anki/collision/Frustum.h"
 #include "anki/collision/Frustum.h"
 #include "anki/scene/SpatialComponent.h"
 #include "anki/scene/SpatialComponent.h"
@@ -184,4 +183,3 @@ private:
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 12 - 16
include/anki/scene/PlayerControllerComponent.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_SCENE_PLAYER_CONTROLLER_COMPONENT_H
-#define ANKI_SCENE_PLAYER_CONTROLLER_COMPONENT_H
+#pragma once
 
 
 #include "anki/scene/SceneComponent.h"
 #include "anki/scene/SceneComponent.h"
 #include "anki/physics/PhysicsPlayerController.h"
 #include "anki/physics/PhysicsPlayerController.h"
@@ -18,17 +17,14 @@ namespace anki {
 class PlayerControllerComponent: public SceneComponent
 class PlayerControllerComponent: public SceneComponent
 {
 {
 public:
 public:
-	static Bool classof(const SceneComponent& c)
-	{
-		return c.getType() == Type::PLAYER_CONTROLLER;
-	}
-
-	PlayerControllerComponent(SceneNode* node, 
+	PlayerControllerComponent(SceneNode* node,
 		PhysicsPlayerControllerPtr player)
 		PhysicsPlayerControllerPtr player)
-	:	SceneComponent(Type::PLAYER_CONTROLLER, node),
-		m_player(player)
+		: SceneComponent(Type::PLAYER_CONTROLLER, node)
+		, m_player(player)
 	{}
 	{}
 
 
+	~PlayerControllerComponent() = default;
+
 	const Transform& getTransform() const
 	const Transform& getTransform() const
 	{
 	{
 		return m_trf;
 		return m_trf;
@@ -39,20 +35,22 @@ public:
 		m_player->moveToPosition(trf.getOrigin());
 		m_player->moveToPosition(trf.getOrigin());
 	}
 	}
 
 
-	void setVelocity(F32 forwardSpeed, F32 strafeSpeed, F32 jumpSpeed, 
+	void setVelocity(F32 forwardSpeed, F32 strafeSpeed, F32 jumpSpeed,
 		const Vec4& forwardDir)
 		const Vec4& forwardDir)
 	{
 	{
 		m_player->setVelocity(forwardSpeed, strafeSpeed, jumpSpeed, forwardDir);
 		m_player->setVelocity(forwardSpeed, strafeSpeed, jumpSpeed, forwardDir);
 	}
 	}
 
 
-	/// @name SceneComponent overrides
-	/// @{
 	ANKI_USE_RESULT Error update(SceneNode&, F32, F32, Bool& updated) override
 	ANKI_USE_RESULT Error update(SceneNode&, F32, F32, Bool& updated) override
 	{
 	{
 		m_trf = m_player->getTransform(updated);
 		m_trf = m_player->getTransform(updated);
 		return ErrorCode::NONE;
 		return ErrorCode::NONE;
 	}
 	}
-	/// @}
+
+	static Bool classof(const SceneComponent& c)
+	{
+		return c.getType() == Type::PLAYER_CONTROLLER;
+	}
 
 
 private:
 private:
 	PhysicsPlayerControllerPtr m_player;
 	PhysicsPlayerControllerPtr m_player;
@@ -62,5 +60,3 @@ private:
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif
-

+ 1 - 4
include/anki/scene/PlayerNode.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_SCENE_PLAYER_NODE_H
-#define ANKI_SCENE_PLAYER_NODE_H
+#pragma once
 
 
 #include "anki/scene/SceneNode.h"
 #include "anki/scene/SceneNode.h"
 #include "anki/Math.h"
 #include "anki/Math.h"
@@ -34,5 +33,3 @@ private:
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif
-

+ 3 - 0
include/anki/scene/SceneComponent.h

@@ -43,6 +43,9 @@ public:
 		, m_type(type)
 		, m_type(type)
 	{}
 	{}
 
 
+	virtual ~SceneComponent()
+	{}
+
 	Type getType() const
 	Type getType() const
 	{
 	{
 		return m_type;
 		return m_type;

+ 3 - 3
include/anki/util/Allocator.h

@@ -3,8 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#ifndef ANKI_UTIL_ALLOCATOR_H
-#define ANKI_UTIL_ALLOCATOR_H
+#pragma once
 
 
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
 #include "anki/util/Memory.h"
 #include "anki/util/Memory.h"
@@ -144,6 +143,7 @@ public:
 	///             be PtrSize
 	///             be PtrSize
 	pointer allocate(size_type n, const void* hint = nullptr)
 	pointer allocate(size_type n, const void* hint = nullptr)
 	{
 	{
+		ANKI_ASSERT(m_pool);
 		(void)hint;
 		(void)hint;
 
 
 		size_type size = n * sizeof(value_type);
 		size_type size = n * sizeof(value_type);
@@ -166,6 +166,7 @@ public:
 	/// Deallocate memory
 	/// Deallocate memory
 	void deallocate(void* p, size_type n)
 	void deallocate(void* p, size_type n)
 	{
 	{
+		ANKI_ASSERT(m_pool);
 		(void)n;
 		(void)n;
 		m_pool->free(p);
 		m_pool->free(p);
 	}
 	}
@@ -410,4 +411,3 @@ using ChainAllocator = GenericPoolAllocator<T, ChainMemoryPool>;
 
 
 } // end namespace anki
 } // end namespace anki
 
 
-#endif

+ 3 - 0
src/core/App.cpp

@@ -105,6 +105,9 @@ void App::cleanup()
 		m_heapAlloc.deleteInstance(m_window);
 		m_heapAlloc.deleteInstance(m_window);
 		m_window = nullptr;
 		m_window = nullptr;
 	}
 	}
+
+	m_settingsDir.destroy(m_heapAlloc);
+	m_cacheDir.destroy(m_heapAlloc);
 }
 }
 
 
 //==============================================================================
 //==============================================================================

+ 24 - 12
src/gr/gl/RenderingThread.cpp

@@ -50,6 +50,16 @@ public:
 	}
 	}
 };
 };
 
 
+/// Empty command
+class EmptyCommand final: public GlCommand
+{
+public:
+	ANKI_USE_RESULT Error operator()(GlState&)
+	{
+		return ErrorCode::NONE;
+	}
+};
+
 //==============================================================================
 //==============================================================================
 // RenderingThread                                                             =
 // RenderingThread                                                             =
 //==============================================================================
 //==============================================================================
@@ -68,7 +78,9 @@ RenderingThread::RenderingThread(GrManager* manager)
 
 
 //==============================================================================
 //==============================================================================
 RenderingThread::~RenderingThread()
 RenderingThread::~RenderingThread()
-{}
+{
+	m_queue.destroy(m_manager->getAllocator());
+}
 
 
 //==============================================================================
 //==============================================================================
 void RenderingThread::flushCommandBuffer(CommandBufferPtr commands)
 void RenderingThread::flushCommandBuffer(CommandBufferPtr commands)
@@ -82,9 +94,9 @@ void RenderingThread::flushCommandBuffer(CommandBufferPtr commands)
 		// Set commands
 		// Set commands
 		U64 diff = m_tail - m_head;
 		U64 diff = m_tail - m_head;
 
 
-		if(diff < m_queue.size())
+		if(diff < m_queue.getSize())
 		{
 		{
-			U64 idx = m_tail % m_queue.size();
+			U64 idx = m_tail % m_queue.getSize();
 
 
 			m_queue[idx] = commands;
 			m_queue[idx] = commands;
 			++m_tail;
 			++m_tail;
@@ -125,6 +137,7 @@ void RenderingThread::start(
 {
 {
 	ANKI_ASSERT(m_tail == 0 && m_head == 0);
 	ANKI_ASSERT(m_tail == 0 && m_head == 0);
 	m_state.m_registerMessages = registerMessages;
 	m_state.m_registerMessages = registerMessages;
+	m_queue.create(m_manager->getAllocator(), QUEUE_SIZE);
 
 
 	// Context
 	// Context
 	ANKI_ASSERT(ctx != nullptr && makeCurrentCb != nullptr);
 	ANKI_ASSERT(ctx != nullptr && makeCurrentCb != nullptr);
@@ -147,6 +160,9 @@ void RenderingThread::start(
 	// Create sync command buffer
 	// Create sync command buffer
 	m_syncCommands = m_manager->newInstance<CommandBuffer>();
 	m_syncCommands = m_manager->newInstance<CommandBuffer>();
 	m_syncCommands->getImplementation().pushBackNewCommand<SyncCommand>(this);
 	m_syncCommands->getImplementation().pushBackNewCommand<SyncCommand>(this);
+
+	m_emptyCmdb = m_manager->newInstance<CommandBuffer>();
+	m_emptyCmdb->getImplementation().pushBackNewCommand<EmptyCommand>();
 #else
 #else
 	prepare();
 	prepare();
 
 
@@ -158,14 +174,10 @@ void RenderingThread::start(
 void RenderingThread::stop()
 void RenderingThread::stop()
 {
 {
 #if !ANKI_DISABLE_GL_RENDERING_THREAD
 #if !ANKI_DISABLE_GL_RENDERING_THREAD
-	{
-		LockGuard<Mutex> lock(m_mtx);
-		m_renderingThreadSignal = 1;
+	syncClientServer();
+	m_renderingThreadSignal = 1;
+	flushCommandBuffer(m_emptyCmdb);
 
 
-		// Set some dummy values in order to unlock the cond var
-		m_tail = m_queue.size() + 1;
-		m_head = m_tail + 1;
-	}
 	Error err = m_thread.join();
 	Error err = m_thread.join();
 	(void)err;
 	(void)err;
 #else
 #else
@@ -202,7 +214,7 @@ void RenderingThread::prepare()
 void RenderingThread::finish()
 void RenderingThread::finish()
 {
 {
 	// Iterate the queue and release the refcounts
 	// Iterate the queue and release the refcounts
-	for(U i = 0; i < m_queue.size(); i++)
+	for(U i = 0; i < m_queue.getSize(); i++)
 	{
 	{
 		if(m_queue[i].isCreated())
 		if(m_queue[i].isCreated())
 		{
 		{
@@ -255,7 +267,7 @@ void RenderingThread::threadLoop()
 				break;
 				break;
 			}
 			}
 
 
-			U64 idx = m_head % m_queue.size();
+			U64 idx = m_head % m_queue.getSize();
 			// Pop a command
 			// Pop a command
 			cmd = m_queue[idx];
 			cmd = m_queue[idx];
 			m_queue[idx] = CommandBufferPtr(); // Insert empty cmd buffer
 			m_queue[idx] = CommandBufferPtr(); // Insert empty cmd buffer

+ 1 - 1
src/physics/PhysicsBody.cpp

@@ -11,7 +11,7 @@ namespace anki {
 
 
 //==============================================================================
 //==============================================================================
 PhysicsBody::PhysicsBody(PhysicsWorld* world)
 PhysicsBody::PhysicsBody(PhysicsWorld* world)
-:	PhysicsObject(Type::BODY, world)
+	: PhysicsObject(Type::BODY, world)
 {}
 {}
 
 
 //==============================================================================
 //==============================================================================

+ 117 - 108
src/physics/PhysicsPlayerController.cpp

@@ -16,7 +16,7 @@ namespace anki {
 struct CustomControllerConvexRayFilter
 struct CustomControllerConvexRayFilter
 {
 {
 	const NewtonBody* m_me = nullptr;
 	const NewtonBody* m_me = nullptr;
-	Vec4 m_hitContact = Vec4(0.0); 
+	Vec4 m_hitContact = Vec4(0.0);
 	Vec4 m_hitNormal = Vec4(0.0);
 	Vec4 m_hitNormal = Vec4(0.0);
 	const NewtonBody* m_hitBody = nullptr;
 	const NewtonBody* m_hitBody = nullptr;
 	const NewtonCollision* m_shapeHit = nullptr;
 	const NewtonCollision* m_shapeHit = nullptr;
@@ -24,40 +24,40 @@ struct CustomControllerConvexRayFilter
 	F32 m_intersectParam = 1.2;
 	F32 m_intersectParam = 1.2;
 
 
 	static F32 filterCallback(
 	static F32 filterCallback(
-		const NewtonBody* const body, 
-		const NewtonCollision* const shapeHit, 
-		const dFloat* const hitContact, 
-		const dFloat* const hitNormal, 
+		const NewtonBody* const body,
+		const NewtonCollision* const shapeHit,
+		const dFloat* const hitContact,
+		const dFloat* const hitNormal,
 		dLong collisionId,
 		dLong collisionId,
-		void* const userData, 
+		void* const userData,
 		dFloat intersectParam)
 		dFloat intersectParam)
 	{
 	{
-		CustomControllerConvexRayFilter* filter = 
+		CustomControllerConvexRayFilter* filter =
 			static_cast<CustomControllerConvexRayFilter*>(userData);
 			static_cast<CustomControllerConvexRayFilter*>(userData);
 
 
 		ANKI_ASSERT(body != filter->m_me);
 		ANKI_ASSERT(body != filter->m_me);
 
 
-		if(intersectParam < filter->m_intersectParam) 
+		if(intersectParam < filter->m_intersectParam)
 		{
 		{
-			filter->m_hitBody = body;	
+			filter->m_hitBody = body;
 			filter->m_shapeHit = shapeHit;
 			filter->m_shapeHit = shapeHit;
 			filter->m_collisionId = collisionId;
 			filter->m_collisionId = collisionId;
 			filter->m_intersectParam = intersectParam;
 			filter->m_intersectParam = intersectParam;
 			filter->m_hitContact = Vec4(
 			filter->m_hitContact = Vec4(
 				hitContact[0], hitContact[1], hitContact[2], 0.0);
 				hitContact[0], hitContact[1], hitContact[2], 0.0);
 			filter->m_hitNormal = Vec4(
 			filter->m_hitNormal = Vec4(
-				hitNormal[0], hitNormal[1], hitNormal[2], 0.0); 
+				hitNormal[0], hitNormal[1], hitNormal[2], 0.0);
 		}
 		}
 
 
 		return intersectParam;
 		return intersectParam;
 	}
 	}
 
 
 	static unsigned prefilterCallback(
 	static unsigned prefilterCallback(
-		const NewtonBody* const body, 
-		const NewtonCollision* const myCollision, 
+		const NewtonBody* const body,
+		const NewtonCollision* const myCollision,
 		void* const userData)
 		void* const userData)
 	{
 	{
-		CustomControllerConvexRayFilter* filter = 
+		CustomControllerConvexRayFilter* filter =
 			static_cast<CustomControllerConvexRayFilter*>(userData);
 			static_cast<CustomControllerConvexRayFilter*>(userData);
 
 
 		return (body != filter->m_me) ? 1 : 0;
 		return (body != filter->m_me) ? 1 : 0;
@@ -70,17 +70,17 @@ struct CustomControllerConvexCastPreFilter
 	const NewtonBody* m_me = nullptr;
 	const NewtonBody* m_me = nullptr;
 
 
 	CustomControllerConvexCastPreFilter(NewtonBody* body)
 	CustomControllerConvexCastPreFilter(NewtonBody* body)
-	:	m_me(body)
+		: m_me(body)
 	{
 	{
 		ANKI_ASSERT(m_me != nullptr);
 		ANKI_ASSERT(m_me != nullptr);
 	}
 	}
 
 
 	static unsigned prefilterCallback(
 	static unsigned prefilterCallback(
-		const NewtonBody* const body, 
-		const NewtonCollision* const myCollision, 
+		const NewtonBody* const body,
+		const NewtonCollision* const myCollision,
 		void* const userData)
 		void* const userData)
 	{
 	{
-		CustomControllerConvexCastPreFilter* filter = 
+		CustomControllerConvexCastPreFilter* filter =
 			static_cast<CustomControllerConvexCastPreFilter*>(userData);
 			static_cast<CustomControllerConvexCastPreFilter*>(userData);
 
 
 		return (body != filter->m_me) ? 1 : 0;
 		return (body != filter->m_me) ? 1 : 0;
@@ -99,7 +99,7 @@ static Vec4 calcAverageOmega(Quat q0, const Quat& q1, F32 invdt)
 	Vec4 omegaDir(dq.x(), dq.y(), dq.z(), 0.0);
 	Vec4 omegaDir(dq.x(), dq.y(), dq.z(), 0.0);
 
 
 	F32 dirMag2 = omegaDir.getLengthSquared();
 	F32 dirMag2 = omegaDir.getLengthSquared();
-	if(dirMag2 < 1.0e-5 * 1.0e-5) 
+	if(dirMag2 < 1.0e-5 * 1.0e-5)
 	{
 	{
 		return Vec4(0.0);
 		return Vec4(0.0);
 	}
 	}
@@ -118,7 +118,7 @@ static Quat integrateOmega(const Quat& rot, const Vec4& omega, F32 dt)
 	Quat rotation(rot);
 	Quat rotation(rot);
 	F32 omegaMag2 = omega.dot(omega);
 	F32 omegaMag2 = omega.dot(omega);
 	F32 errAngle2 = toRad(0.0125) * toRad(0.0125);
 	F32 errAngle2 = toRad(0.0125) * toRad(0.0125);
-	if(omegaMag2 > errAngle2) 
+	if(omegaMag2 > errAngle2)
 	{
 	{
 		F32 invOmegaMag = 1.0 / sqrt(omegaMag2);
 		F32 invOmegaMag = 1.0 / sqrt(omegaMag2);
 		Vec4 omegaAxis(omega * invOmegaMag);
 		Vec4 omegaAxis(omega * invOmegaMag);
@@ -135,6 +135,15 @@ static Quat integrateOmega(const Quat& rot, const Vec4& omega, F32 dt)
 // PhysicsPlayerController                                                     =
 // PhysicsPlayerController                                                     =
 //==============================================================================
 //==============================================================================
 
 
+//==============================================================================
+PhysicsPlayerController::~PhysicsPlayerController()
+{
+	NewtonDestroyCollision(m_upperBodyShape);
+	NewtonDestroyCollision(m_supportShape);
+	NewtonDestroyCollision(m_castingShape);
+	NewtonDestroyBody(m_body);
+}
+
 //==============================================================================
 //==============================================================================
 Error PhysicsPlayerController::create(const Initializer& init)
 Error PhysicsPlayerController::create(const Initializer& init)
 {
 {
@@ -167,8 +176,8 @@ Error PhysicsPlayerController::create(const Initializer& init)
 	ANKI_ASSERT(shapeHeight > 0.0);
 	ANKI_ASSERT(shapeHeight > 0.0);
 	Vec4 p0(m_innerRadius, 0.0, 0.0, 0.0);
 	Vec4 p0(m_innerRadius, 0.0, 0.0, 0.0);
 	Vec4 p1(m_innerRadius, shapeHeight, 0.0, 0.0);
 	Vec4 p1(m_innerRadius, shapeHeight, 0.0, 0.0);
-	
-	for(U i = 0; i < steps; ++i) 
+
+	for(U i = 0; i < steps; ++i)
 	{
 	{
 		Mat3 rotm3(Axisang(toRad(320.0) / steps * i, m_upDir.xyz()));
 		Mat3 rotm3(Axisang(toRad(320.0) / steps * i, m_upDir.xyz()));
 		Mat4 rotation(rotm3);
 		Mat4 rotation(rotm3);
@@ -177,7 +186,7 @@ Error PhysicsPlayerController::create(const Initializer& init)
 	}
 	}
 
 
 	NewtonCollision* supportShape = NewtonCreateConvexHull(
 	NewtonCollision* supportShape = NewtonCreateConvexHull(
-		world, steps * 2, &convexPoints[0][0][0], sizeof(Vec4), 
+		world, steps * 2, &convexPoints[0][0][0], sizeof(Vec4),
 		0.0, 0, nullptr);
 		0.0, 0, nullptr);
 	if(supportShape == nullptr)
 	if(supportShape == nullptr)
 	{
 	{
@@ -191,7 +200,7 @@ Error PhysicsPlayerController::create(const Initializer& init)
 	F32 capsuleHeight = m_height - m_stepHeight;
 	F32 capsuleHeight = m_height - m_stepHeight;
 	ANKI_ASSERT(capsuleHeight > 0.0);
 	ANKI_ASSERT(capsuleHeight > 0.0);
 	m_sphereCastOrigin = capsuleHeight * 0.5 + m_stepHeight;
 	m_sphereCastOrigin = capsuleHeight * 0.5 + m_stepHeight;
-	
+
 	Vec4 transl(m_upDir * m_sphereCastOrigin);
 	Vec4 transl(m_upDir * m_sphereCastOrigin);
 	transl.w() = 1.0;
 	transl.w() = 1.0;
 	outerShapeMatrix.setTranslationPart(transl);
 	outerShapeMatrix.setTranslationPart(transl);
@@ -205,7 +214,7 @@ Error PhysicsPlayerController::create(const Initializer& init)
 		return ErrorCode::FUNCTION_FAILED;
 		return ErrorCode::FUNCTION_FAILED;
 	}
 	}
 
 
-	NewtonCollisionSetScale(bodyCapsule, capsuleHeight, m_outerRadius * 4.0, 
+	NewtonCollisionSetScale(bodyCapsule, capsuleHeight, m_outerRadius * 4.0,
 		m_outerRadius * 4.0);
 		m_outerRadius * 4.0);
 
 
 	// Compound collision player controller
 	// Compound collision player controller
@@ -216,7 +225,7 @@ Error PhysicsPlayerController::create(const Initializer& init)
 		return ErrorCode::FUNCTION_FAILED;
 		return ErrorCode::FUNCTION_FAILED;
 	}
 	}
 
 
-	NewtonCompoundCollisionBeginAddRemove(playerShape);	
+	NewtonCompoundCollisionBeginAddRemove(playerShape);
 	NewtonCompoundCollisionAddSubCollision(playerShape, supportShape);
 	NewtonCompoundCollisionAddSubCollision(playerShape, supportShape);
 	NewtonCompoundCollisionAddSubCollision(playerShape, bodyCapsule);
 	NewtonCompoundCollisionAddSubCollision(playerShape, bodyCapsule);
 	NewtonCompoundCollisionEndAddRemove(playerShape);
 	NewtonCompoundCollisionEndAddRemove(playerShape);
@@ -224,7 +233,7 @@ Error PhysicsPlayerController::create(const Initializer& init)
 	// Create the kinematic body
 	// Create the kinematic body
 	Mat4 locationMatrix(Mat4::getIdentity());
 	Mat4 locationMatrix(Mat4::getIdentity());
 	locationMatrix.setTranslationPart(init.m_position.xyz1());
 	locationMatrix.setTranslationPart(init.m_position.xyz1());
-	m_body = NewtonCreateKinematicBody(world, playerShape, 
+	m_body = NewtonCreateKinematicBody(world, playerShape,
 		&toNewton(locationMatrix)[0]);
 		&toNewton(locationMatrix)[0]);
 	if(m_body == nullptr)
 	if(m_body == nullptr)
 	{
 	{
@@ -237,7 +246,7 @@ Error PhysicsPlayerController::create(const Initializer& init)
 	NewtonBodySetMaterialGroupID(
 	NewtonBodySetMaterialGroupID(
 		m_body, NewtonMaterialGetDefaultGroupID(m_world->_getNewtonWorld()));
 		m_body, NewtonMaterialGetDefaultGroupID(m_world->_getNewtonWorld()));
 
 
-	// Players must have weight, otherwise they are infinitely strong when 
+	// Players must have weight, otherwise they are infinitely strong when
 	// they collide
 	// they collide
 	NewtonCollision* shape = NewtonBodyGetCollision(m_body);
 	NewtonCollision* shape = NewtonBodyGetCollision(m_body);
 	if(shape == nullptr)
 	if(shape == nullptr)
@@ -255,14 +264,14 @@ Error PhysicsPlayerController::create(const Initializer& init)
 
 
 	Vec4 q0(castRadius, 0.0, 0.0, 0.0);
 	Vec4 q0(castRadius, 0.0, 0.0, 0.0);
 	Vec4 q1(castRadius, castHeight, 0.0, 0.0);
 	Vec4 q1(castRadius, castHeight, 0.0, 0.0);
-	for(U i = 0; i < steps; ++i) 
+	for(U i = 0; i < steps; ++i)
 	{
 	{
 		Mat3 rotm3(Axisang(toRad(320.0) / steps * i, m_upDir.xyz()));
 		Mat3 rotm3(Axisang(toRad(320.0) / steps * i, m_upDir.xyz()));
 		Mat4 rotation(rotm3);
 		Mat4 rotation(rotm3);
 		convexPoints[0][i] = localAxis * (rotation * q0);
 		convexPoints[0][i] = localAxis * (rotation * q0);
 		convexPoints[1][i] = localAxis * (rotation * q1);
 		convexPoints[1][i] = localAxis * (rotation * q1);
 	}
 	}
-	m_castingShape = NewtonCreateConvexHull(world, steps * 2, 
+	m_castingShape = NewtonCreateConvexHull(world, steps * 2,
 		&convexPoints[0][0][0], sizeof(Vec4), 0.0, 0, nullptr);
 		&convexPoints[0][0][0], sizeof(Vec4), 0.0, 0, nullptr);
 	if(m_castingShape == nullptr)
 	if(m_castingShape == nullptr)
 	{
 	{
@@ -298,7 +307,7 @@ Vec4 PhysicsPlayerController::calculateDesiredOmega(
 
 
 //==============================================================================
 //==============================================================================
 Vec4 PhysicsPlayerController::calculateDesiredVelocity(
 Vec4 PhysicsPlayerController::calculateDesiredVelocity(
-	F32 forwardSpeed, F32 strafeSpeed, 
+	F32 forwardSpeed, F32 strafeSpeed,
 	F32 verticalSpeed, const Vec4& gravity, F32 dt) const
 	F32 verticalSpeed, const Vec4& gravity, F32 dt) const
 {
 {
 	Mat4 matrix;
 	Mat4 matrix;
@@ -312,25 +321,25 @@ Vec4 PhysicsPlayerController::calculateDesiredVelocity(
 
 
 	Vec4 veloc(0.0);
 	Vec4 veloc(0.0);
 	Vec4 groundPlaneDir = m_groundPlane.xyz0();
 	Vec4 groundPlaneDir = m_groundPlane.xyz0();
-	if((verticalSpeed <= 0.0) && groundPlaneDir.getLengthSquared() > 0.0) 
+	if((verticalSpeed <= 0.0) && groundPlaneDir.getLengthSquared() > 0.0)
 	{
 	{
 		// Plane is supported by a ground plane, apply the player input velocity
 		// Plane is supported by a ground plane, apply the player input velocity
-		if(groundPlaneDir.dot(updir) >= m_maxSlope) 
+		if(groundPlaneDir.dot(updir) >= m_maxSlope)
 		{
 		{
 			// Player is in a legal slope, he is in full control of his movement
 			// Player is in a legal slope, he is in full control of his movement
 			Vec4 bodyVeloc(0.0);
 			Vec4 bodyVeloc(0.0);
 			NewtonBodyGetVelocity(m_body, &bodyVeloc[0]);
 			NewtonBodyGetVelocity(m_body, &bodyVeloc[0]);
-			veloc = updir * bodyVeloc.dot(updir) 
-				+ gravity * dt 
-				+ frontDir * forwardSpeed 
-				+ rightDir * strafeSpeed 
+			veloc = updir * bodyVeloc.dot(updir)
+				+ gravity * dt
+				+ frontDir * forwardSpeed
+				+ rightDir * strafeSpeed
 				+ updir * verticalSpeed;
 				+ updir * verticalSpeed;
 
 
 			veloc += m_groundVelocity - updir * updir.dot(m_groundVelocity);
 			veloc += m_groundVelocity - updir * updir.dot(m_groundVelocity);
 
 
-			F32 speedLimitMag2 = forwardSpeed * forwardSpeed 
-				+ strafeSpeed * strafeSpeed 
-				+ verticalSpeed * verticalSpeed 
+			F32 speedLimitMag2 = forwardSpeed * forwardSpeed
+				+ strafeSpeed * strafeSpeed
+				+ verticalSpeed * verticalSpeed
 				+ m_groundVelocity.dot(m_groundVelocity) + 0.1;
 				+ m_groundVelocity.dot(m_groundVelocity) + 0.1;
 
 
 			F32 speedMag2 = veloc.getLengthSquared();
 			F32 speedMag2 = veloc.getLengthSquared();
@@ -340,26 +349,26 @@ Vec4 PhysicsPlayerController::calculateDesiredVelocity(
 			}
 			}
 
 
 			F32 normalVeloc = groundPlaneDir.dot(veloc - m_groundVelocity);
 			F32 normalVeloc = groundPlaneDir.dot(veloc - m_groundVelocity);
-			if(normalVeloc < 0.0) 
+			if(normalVeloc < 0.0)
 			{
 			{
 				veloc -= groundPlaneDir * normalVeloc;
 				veloc -= groundPlaneDir * normalVeloc;
 			}
 			}
-		} 
-		else 
+		}
+		else
 		{
 		{
-			// Player is in an illegal ramp, he slides down hill an loses 
-			// control of his movement 
+			// Player is in an illegal ramp, he slides down hill an loses
+			// control of his movement
 			NewtonBodyGetVelocity(m_body, &veloc[0]);
 			NewtonBodyGetVelocity(m_body, &veloc[0]);
 			veloc += updir * verticalSpeed;
 			veloc += updir * verticalSpeed;
 			veloc += gravity * dt;
 			veloc += gravity * dt;
 			F32 normalVeloc = groundPlaneDir.dot(veloc - m_groundVelocity);
 			F32 normalVeloc = groundPlaneDir.dot(veloc - m_groundVelocity);
-			if(normalVeloc < 0.0) 
+			if(normalVeloc < 0.0)
 			{
 			{
 				veloc -= groundPlaneDir * normalVeloc;
 				veloc -= groundPlaneDir * normalVeloc;
 			}
 			}
 		}
 		}
-	} 
-	else 
+	}
+	else
 	{
 	{
 		// Player is on free fall, only apply the gravity
 		// Player is on free fall, only apply the gravity
 		NewtonBodyGetVelocity(m_body, &veloc[0]);
 		NewtonBodyGetVelocity(m_body, &veloc[0]);
@@ -375,7 +384,7 @@ void PhysicsPlayerController::calculateVelocity(F32 dt)
 {
 {
 	Vec4 omega(calculateDesiredOmega(m_forwardDir, dt));
 	Vec4 omega(calculateDesiredOmega(m_forwardDir, dt));
 	Vec4 veloc(calculateDesiredVelocity(
 	Vec4 veloc(calculateDesiredVelocity(
-		m_forwardSpeed, m_strafeSpeed, m_jumpSpeed, m_gravity, dt));			
+		m_forwardSpeed, m_strafeSpeed, m_jumpSpeed, m_gravity, dt));
 
 
 	NewtonBodySetOmega(m_body, &omega[0]);
 	NewtonBodySetOmega(m_body, &omega[0]);
 	NewtonBodySetVelocity(m_body, &veloc[0]);
 	NewtonBodySetVelocity(m_body, &veloc[0]);
@@ -387,26 +396,26 @@ void PhysicsPlayerController::calculateVelocity(F32 dt)
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-F32 PhysicsPlayerController::calculateContactKinematics(const Vec4& veloc, 
+F32 PhysicsPlayerController::calculateContactKinematics(const Vec4& veloc,
 	const NewtonWorldConvexCastReturnInfo* contactInfo) const
 	const NewtonWorldConvexCastReturnInfo* contactInfo) const
 {
 {
 	Vec4 contactVeloc(0.0);
 	Vec4 contactVeloc(0.0);
-	if(contactInfo->m_hitBody) 
+	if(contactInfo->m_hitBody)
 	{
 	{
-		NewtonBodyGetPointVelocity(contactInfo->m_hitBody, 
+		NewtonBodyGetPointVelocity(contactInfo->m_hitBody,
 			contactInfo->m_point, &contactVeloc[0]);
 			contactInfo->m_point, &contactVeloc[0]);
 	}
 	}
 
 
 	const F32 restitution = 0.0;
 	const F32 restitution = 0.0;
-	Vec4 normal(contactInfo->m_normal[0], contactInfo->m_normal[1], 
+	Vec4 normal(contactInfo->m_normal[0], contactInfo->m_normal[1],
 		contactInfo->m_normal[2], 0.0);
 		contactInfo->m_normal[2], 0.0);
-	F32 reboundVelocMag = -((veloc - contactVeloc).dot(normal)) 
+	F32 reboundVelocMag = -((veloc - contactVeloc).dot(normal))
 		* (1.0 + restitution);
 		* (1.0 + restitution);
 	return max(reboundVelocMag, 0.0f);
 	return max(reboundVelocMag, 0.0f);
 }
 }
 
 
 //==============================================================================
 //==============================================================================
-void PhysicsPlayerController::updateGroundPlane(Mat4& matrix, 
+void PhysicsPlayerController::updateGroundPlane(Mat4& matrix,
 	const Mat4& castMatrix, const Vec4& dst, int threadIndex)
 	const Mat4& castMatrix, const Vec4& dst, int threadIndex)
 {
 {
 	NewtonWorld* world = m_world->_getNewtonWorld();
 	NewtonWorld* world = m_world->_getNewtonWorld();
@@ -414,19 +423,19 @@ void PhysicsPlayerController::updateGroundPlane(Mat4& matrix,
 	CustomControllerConvexRayFilter filter;
 	CustomControllerConvexRayFilter filter;
 	filter.m_me = m_body;
 	filter.m_me = m_body;
 
 
-	NewtonWorldConvexRayCast(world, 
-		m_castingShape, 
-		&toNewton(castMatrix)[0], 
-		reinterpret_cast<const F32*>(&dst), 
-		CustomControllerConvexRayFilter::filterCallback, 
-		&filter, 
-		CustomControllerConvexRayFilter::prefilterCallback, 
+	NewtonWorldConvexRayCast(world,
+		m_castingShape,
+		&toNewton(castMatrix)[0],
+		reinterpret_cast<const F32*>(&dst),
+		CustomControllerConvexRayFilter::filterCallback,
+		&filter,
+		CustomControllerConvexRayFilter::prefilterCallback,
 		threadIndex);
 		threadIndex);
 
 
 	m_groundPlane = Vec4(0.0);
 	m_groundPlane = Vec4(0.0);
 	m_groundVelocity = Vec4(0.0);
 	m_groundVelocity = Vec4(0.0);
 
 
-	if(filter.m_hitBody) 
+	if(filter.m_hitBody)
 	{
 	{
 		m_isJumping = false;
 		m_isJumping = false;
 
 
@@ -457,7 +466,7 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 
 
 	calculateVelocity(dt);
 	calculateVelocity(dt);
 
 
-	// Get the body motion state 
+	// Get the body motion state
 	NewtonBodyGetMatrix(m_body, &matrix[0]);
 	NewtonBodyGetMatrix(m_body, &matrix[0]);
 	matrix = toAnki(matrix);
 	matrix = toAnki(matrix);
 	NewtonBodyGetVelocity(m_body, &veloc[0]);
 	NewtonBodyGetVelocity(m_body, &veloc[0]);
@@ -470,7 +479,7 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 	matrix.setRotationPart(Mat3(bodyRotation));
 	matrix.setRotationPart(Mat3(bodyRotation));
 
 
 	// Integrate linear velocity
 	// Integrate linear velocity
-	F32 normalizedTimeLeft = 1.0; 
+	F32 normalizedTimeLeft = 1.0;
 	F32 step = dt * veloc.getLength();
 	F32 step = dt * veloc.getLength();
 	F32 descreteTimeStep = dt * (1.0 / DESCRETE_MOTION_STEPS);
 	F32 descreteTimeStep = dt * (1.0 / DESCRETE_MOTION_STEPS);
 	U prevContactCount = 0;
 	U prevContactCount = 0;
@@ -483,7 +492,7 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 	NewtonCollisionGetScale(
 	NewtonCollisionGetScale(
 		m_upperBodyShape, &scale.x(), &scale.y(), &scale.z());
 		m_upperBodyShape, &scale.x(), &scale.y(), &scale.z());
 	F32 radio = (m_outerRadius + m_restrainingDistance) * 4.0;
 	F32 radio = (m_outerRadius + m_restrainingDistance) * 4.0;
-	NewtonCollisionSetScale(m_upperBodyShape, 
+	NewtonCollisionSetScale(m_upperBodyShape,
 		m_height - m_stepHeight, radio, radio);
 		m_height - m_stepHeight, radio, radio);
 
 
 	NewtonWorldConvexCastReturnInfo upConstraint;
 	NewtonWorldConvexCastReturnInfo upConstraint;
@@ -493,11 +502,11 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 	upConstraint.m_normal[2] = m_upDir.z();
 	upConstraint.m_normal[2] = m_upDir.z();
 	upConstraint.m_normal[3] = m_upDir.w();
 	upConstraint.m_normal[3] = m_upDir.w();
 
 
-	for(U j = 0; 
-		(j < MAX_INTERGRATION_STEPS) && (normalizedTimeLeft > 1.0e-5f); 
-		++j) 
+	for(U j = 0;
+		(j < MAX_INTERGRATION_STEPS) && (normalizedTimeLeft > 1.0e-5f);
+		++j)
 	{
 	{
-		if((veloc.getLengthSquared()) < 1.0e-6) 
+		if((veloc.getLengthSquared()) < 1.0e-6)
 		{
 		{
 			break;
 			break;
 		}
 		}
@@ -507,15 +516,15 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 
 
 		Vec4 destPosit(matrix.getTranslationPart().xyz0() + veloc * dt);
 		Vec4 destPosit(matrix.getTranslationPart().xyz0() + veloc * dt);
 		U contactCount = NewtonWorldConvexCast(
 		U contactCount = NewtonWorldConvexCast(
-			world, 
-			&matrix.getTransposed()[0], 
-			&destPosit[0], 
-			m_upperBodyShape, 
-			&timetoImpact, 
-			&castFilterData, 
-			CustomControllerConvexCastPreFilter::prefilterCallback, 
-			&info[0], 
-			info.getSize(), 
+			world,
+			&matrix.getTransposed()[0],
+			&destPosit[0],
+			m_upperBodyShape,
+			&timetoImpact,
+			&castFilterData,
+			CustomControllerConvexCastPreFilter::prefilterCallback,
+			&info[0],
+			info.getSize(),
 			threadIndex);
 			threadIndex);
 
 
 		if(contactCount > 0)
 		if(contactCount > 0)
@@ -523,7 +532,7 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 			matrix.setTranslationPart(
 			matrix.setTranslationPart(
 				matrix.getTranslationPart() + veloc * (timetoImpact * dt));
 				matrix.getTranslationPart() + veloc * (timetoImpact * dt));
 
 
-			if(timetoImpact > 0.0) 
+			if(timetoImpact > 0.0)
 			{
 			{
 				Vec4 tmp = matrix.getTranslationPart() -
 				Vec4 tmp = matrix.getTranslationPart() -
 					veloc * (CONTACT_SKIN_THICKNESS / veloc.getLength());
 					veloc * (CONTACT_SKIN_THICKNESS / veloc.getLength());
@@ -536,14 +545,14 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 			Array<F32, MAX_CONTACTS * 2> bounceSpeed;
 			Array<F32, MAX_CONTACTS * 2> bounceSpeed;
 			Array<Vec4, MAX_CONTACTS * 2> bounceNormal;
 			Array<Vec4, MAX_CONTACTS * 2> bounceNormal;
 
 
-			for(U i = 1; i < contactCount; ++i) 
+			for(U i = 1; i < contactCount; ++i)
 			{
 			{
 				Vec4 n0(info[i - 1].m_normal);
 				Vec4 n0(info[i - 1].m_normal);
 
 
-				for(U j = 0; j < i; ++j) 
+				for(U j = 0; j < i; ++j)
 				{
 				{
 					Vec4 n1(info[j].m_normal);
 					Vec4 n1(info[j].m_normal);
-					if((n0.dot(n1)) > 0.9999) 
+					if((n0.dot(n1)) > 0.9999)
 					{
 					{
 						info[i] = info[contactCount - 1];
 						info[i] = info[contactCount - 1];
 						--i;
 						--i;
@@ -554,7 +563,7 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 			}
 			}
 
 
 			U count = 0;
 			U count = 0;
-			if(!m_isJumping) 
+			if(!m_isJumping)
 			{
 			{
 				Vec4 matTls = matrix.getTranslationPart();
 				Vec4 matTls = matrix.getTranslationPart();
 				upConstraint.m_point[0] = matTls.x();
 				upConstraint.m_point[0] = matTls.x();
@@ -564,48 +573,48 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 
 
 				speed[count] = 0.0;
 				speed[count] = 0.0;
 				bounceNormal[count] = Vec4(upConstraint.m_normal);
 				bounceNormal[count] = Vec4(upConstraint.m_normal);
-				bounceSpeed[count] = 
+				bounceSpeed[count] =
 					calculateContactKinematics(veloc, &upConstraint);
 					calculateContactKinematics(veloc, &upConstraint);
 				++count;
 				++count;
 			}
 			}
 
 
-			for(U i = 0; i < contactCount; ++i) 
+			for(U i = 0; i < contactCount; ++i)
 			{
 			{
 				speed[count] = 0.0;
 				speed[count] = 0.0;
 				bounceNormal[count] = Vec4(info[i].m_normal);
 				bounceNormal[count] = Vec4(info[i].m_normal);
-				bounceSpeed[count] = 
+				bounceSpeed[count] =
 					calculateContactKinematics(veloc, &info[i]);
 					calculateContactKinematics(veloc, &info[i]);
 				++count;
 				++count;
 			}
 			}
 
 
-			for(U i = 0; i < prevContactCount; ++i) 
+			for(U i = 0; i < prevContactCount; ++i)
 			{
 			{
 				speed[count] = 0.0;
 				speed[count] = 0.0;
 				bounceNormal[count] = Vec4(prevInfo[i].m_normal);
 				bounceNormal[count] = Vec4(prevInfo[i].m_normal);
-				bounceSpeed[count] = 
+				bounceSpeed[count] =
 					calculateContactKinematics(veloc, &prevInfo[i]);
 					calculateContactKinematics(veloc, &prevInfo[i]);
 				++count;
 				++count;
 			}
 			}
 
 
 			F32 residual = 10.0;
 			F32 residual = 10.0;
 			Vec4 auxBounceVeloc (0.0);
 			Vec4 auxBounceVeloc (0.0);
-			for(U i = 0; 
-				(i < MAX_SOLVER_ITERATIONS) && (residual > 1.0e-3); 
-				++i) 
+			for(U i = 0;
+				(i < MAX_SOLVER_ITERATIONS) && (residual > 1.0e-3);
+				++i)
 			{
 			{
 				residual = 0.0;
 				residual = 0.0;
-				for(U k = 0; k < count; ++k) 
+				for(U k = 0; k < count; ++k)
 				{
 				{
 					Vec4 normal(bounceNormal[k]);
 					Vec4 normal(bounceNormal[k]);
 					F32 v = bounceSpeed[k] - normal.dot(auxBounceVeloc);
 					F32 v = bounceSpeed[k] - normal.dot(auxBounceVeloc);
 					F32 x = speed[k] + v;
 					F32 x = speed[k] + v;
-					if(x < 0.0) 
+					if(x < 0.0)
 					{
 					{
 						v = 0.0;
 						v = 0.0;
 						x = 0.0;
 						x = 0.0;
 					}
 					}
 
 
-					if(abs(v) > residual) 
+					if(abs(v) > residual)
 					{
 					{
 						residual = abs(v);
 						residual = abs(v);
 					}
 					}
@@ -616,7 +625,7 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 			}
 			}
 
 
 			Vec4 velocStep (0.0);
 			Vec4 velocStep (0.0);
-			for(U i = 0; i < count; ++i) 
+			for(U i = 0; i < count; ++i)
 			{
 			{
 				Vec4 normal(bounceNormal[i]);
 				Vec4 normal(bounceNormal[i]);
 				velocStep += normal * speed[i];
 				velocStep += normal * speed[i];
@@ -625,7 +634,7 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 			veloc += velocStep;
 			veloc += velocStep;
 
 
 			F32 velocMag2 = velocStep.getLengthSquared();
 			F32 velocMag2 = velocStep.getLengthSquared();
-			if(velocMag2 < 1.0e-6) 
+			if(velocMag2 < 1.0e-6)
 			{
 			{
 				F32 advanceTime = min(
 				F32 advanceTime = min(
 					descreteTimeStep, normalizedTimeLeft * dt);
 					descreteTimeStep, normalizedTimeLeft * dt);
@@ -637,11 +646,11 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 			}
 			}
 
 
 			prevContactCount = contactCount;
 			prevContactCount = contactCount;
-			memcpy(&prevInfo[0], &info[0], 
+			memcpy(&prevInfo[0], &info[0],
 				prevContactCount * sizeof(NewtonWorldConvexCastReturnInfo));
 				prevContactCount * sizeof(NewtonWorldConvexCastReturnInfo));
 
 
-		} 
-		else 
+		}
+		else
 		{
 		{
 			matrix.setTranslationPart(destPosit.xyz1());
 			matrix.setTranslationPart(destPosit.xyz1());
 			break;
 			break;
@@ -655,15 +664,15 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 	Vec4 tmp = supportMatrix.getTranslationPart() + updir * m_sphereCastOrigin;
 	Vec4 tmp = supportMatrix.getTranslationPart() + updir * m_sphereCastOrigin;
 	supportMatrix.setTranslationPart(tmp.xyz1());
 	supportMatrix.setTranslationPart(tmp.xyz1());
 
 
-	if(m_isJumping) 
+	if(m_isJumping)
 	{
 	{
 		Vec4 dst = matrix.getTranslationPart().xyz0();
 		Vec4 dst = matrix.getTranslationPart().xyz0();
 		updateGroundPlane(matrix, supportMatrix, dst, threadIndex);
 		updateGroundPlane(matrix, supportMatrix, dst, threadIndex);
-	} 
-	else 
+	}
+	else
 	{
 	{
 		step = abs(updir.dot(veloc * dt));
 		step = abs(updir.dot(veloc * dt));
-		F32 castDist = 
+		F32 castDist =
 			(m_groundPlane.getLengthSquared() > 0.0) ? m_stepHeight : step;
 			(m_groundPlane.getLengthSquared() > 0.0) ? m_stepHeight : step;
 		Vec4 tmp = matrix.getTranslationPart() - updir * (castDist * 2.0);
 		Vec4 tmp = matrix.getTranslationPart() - updir * (castDist * 2.0);
 		Vec4 dst = tmp.xyz0();
 		Vec4 dst = tmp.xyz0();
@@ -678,11 +687,11 @@ void PhysicsPlayerController::postUpdate(F32 dt, int threadIndex)
 
 
 //==============================================================================
 //==============================================================================
 void PhysicsPlayerController::postUpdateKernelCallback(
 void PhysicsPlayerController::postUpdateKernelCallback(
-	NewtonWorld* const world, 
-	void* const context, 
+	NewtonWorld* const world,
+	void* const context,
 	int threadIndex)
 	int threadIndex)
 {
 {
-	PhysicsPlayerController* x = 
+	PhysicsPlayerController* x =
 		static_cast<PhysicsPlayerController*>(context);
 		static_cast<PhysicsPlayerController*>(context);
 	x->postUpdate(x->m_world->getDeltaTime(), threadIndex);
 	x->postUpdate(x->m_world->getDeltaTime(), threadIndex);
 }
 }
@@ -699,8 +708,8 @@ void PhysicsPlayerController::moveToPosition(const Vec4& position)
 
 
 //==============================================================================
 //==============================================================================
 void PhysicsPlayerController::onTransformCallback(
 void PhysicsPlayerController::onTransformCallback(
-	const NewtonBody* const body, 
-	const dFloat* const matrix, 
+	const NewtonBody* const body,
+	const dFloat* const matrix,
 	int /*threadIndex*/)
 	int /*threadIndex*/)
 {
 {
 	ANKI_ASSERT(body);
 	ANKI_ASSERT(body);

+ 2 - 1
src/physics/PhysicsWorld.cpp

@@ -31,6 +31,8 @@ PhysicsWorld::PhysicsWorld()
 //==============================================================================
 //==============================================================================
 PhysicsWorld::~PhysicsWorld()
 PhysicsWorld::~PhysicsWorld()
 {
 {
+	cleanupMarkedForDeletion();
+
 	if(m_sceneBody)
 	if(m_sceneBody)
 	{
 	{
 		NewtonDestroyBody(m_sceneBody);
 		NewtonDestroyBody(m_sceneBody);
@@ -133,7 +135,6 @@ void PhysicsWorld::cleanupMarkedForDeletion()
 		// Remove from player controllers
 		// Remove from player controllers
 		if(obj->getType() == PhysicsObject::Type::PLAYER_CONTROLLER)
 		if(obj->getType() == PhysicsObject::Type::PLAYER_CONTROLLER)
 		{
 		{
-
 			auto it2 = m_playerControllers.getBegin();
 			auto it2 = m_playerControllers.getBegin();
 			for(; it2 != m_playerControllers.getEnd(); ++it2)
 			for(; it2 != m_playerControllers.getEnd(); ++it2)
 			{
 			{

+ 6 - 1
src/renderer/Is.cpp

@@ -135,7 +135,12 @@ Is::Is(Renderer* r)
 
 
 //==============================================================================
 //==============================================================================
 Is::~Is()
 Is::~Is()
-{}
+{
+	if(m_barrier)
+	{
+		getAllocator().deleteInstance(&m_barrier.get());
+	}
+}
 
 
 //==============================================================================
 //==============================================================================
 Error Is::init(const ConfigSet& config)
 Error Is::init(const ConfigSet& config)

+ 1 - 0
src/resource/ResourceManager.cpp

@@ -27,6 +27,7 @@ ResourceManager::ResourceManager()
 ResourceManager::~ResourceManager()
 ResourceManager::~ResourceManager()
 {
 {
 	m_cacheDir.destroy(m_alloc);
 	m_cacheDir.destroy(m_alloc);
+	m_shadersPrependedSource.destroy(m_alloc);
 	m_alloc.deleteInstance(m_asyncLoader);
 	m_alloc.deleteInstance(m_asyncLoader);
 }
 }
 
 

+ 10 - 10
src/scene/Camera.cpp

@@ -16,7 +16,7 @@ class CameraMoveFeedbackComponent: public SceneComponent
 {
 {
 public:
 public:
 	CameraMoveFeedbackComponent(Camera* node)
 	CameraMoveFeedbackComponent(Camera* node)
-	:	SceneComponent(SceneComponent::Type::NONE, node)
+		: SceneComponent(SceneComponent::Type::NONE, node)
 	{}
 	{}
 
 
 	ANKI_USE_RESULT Error update(
 	ANKI_USE_RESULT Error update(
@@ -44,7 +44,7 @@ class CameraFrustumFeedbackComponent: public SceneComponent
 {
 {
 public:
 public:
 	CameraFrustumFeedbackComponent(Camera* node)
 	CameraFrustumFeedbackComponent(Camera* node)
-	:	SceneComponent(SceneComponent::Type::NONE, node)
+		: SceneComponent(SceneComponent::Type::NONE, node)
 	{}
 	{}
 
 
 	ANKI_USE_RESULT Error update(
 	ANKI_USE_RESULT Error update(
@@ -68,13 +68,13 @@ public:
 //==============================================================================
 //==============================================================================
 
 
 //==============================================================================
 //==============================================================================
-Camera::Camera(SceneGraph* scene, Type type) 
-:	SceneNode(scene),
-	m_type(type)
+Camera::Camera(SceneGraph* scene, Type type)
+	: SceneNode(scene)
+	, m_type(type)
 {}
 {}
 
 
 //==============================================================================
 //==============================================================================
-Error Camera::create(const CString& name, Frustum* frustum) 
+Error Camera::create(const CString& name, Frustum* frustum)
 {
 {
 	ANKI_CHECK(SceneNode::create(name));
 	ANKI_CHECK(SceneNode::create(name));
 
 
@@ -93,7 +93,7 @@ Error Camera::create(const CString& name, Frustum* frustum)
 	addComponent(comp, true);
 	addComponent(comp, true);
 
 
 	// Feedback component #2
 	// Feedback component #2
-	comp = 
+	comp =
 		getSceneAllocator().newInstance<CameraFrustumFeedbackComponent>(this);
 		getSceneAllocator().newInstance<CameraFrustumFeedbackComponent>(this);
 	addComponent(comp, true);
 	addComponent(comp, true);
 
 
@@ -114,7 +114,7 @@ void Camera::lookAtPoint(const Vec3& point)
 	MoveComponent& move = getComponent<MoveComponent>();
 	MoveComponent& move = getComponent<MoveComponent>();
 
 
 	Vec4 j = Vec4(0.0, 1.0, 0.0, 0.0);
 	Vec4 j = Vec4(0.0, 1.0, 0.0, 0.0);
-	Vec4 vdir = 
+	Vec4 vdir =
 		(point.xyz0() - move.getLocalTransform().getOrigin()).getNormalized();
 		(point.xyz0() - move.getLocalTransform().getOrigin()).getNormalized();
 	Vec4 vup = j - vdir * j.dot(vdir);
 	Vec4 vup = j - vdir * j.dot(vdir);
 	Vec4 vside = vdir.cross(vup);
 	Vec4 vside = vdir.cross(vup);
@@ -152,7 +152,7 @@ void Camera::onMoveComponentUpdate(MoveComponent& move)
 
 
 //==============================================================================
 //==============================================================================
 PerspectiveCamera::PerspectiveCamera(SceneGraph* scene)
 PerspectiveCamera::PerspectiveCamera(SceneGraph* scene)
-:	Camera(scene, Type::PERSPECTIVE)
+	: Camera(scene, Type::PERSPECTIVE)
 {}
 {}
 
 
 //==============================================================================
 //==============================================================================
@@ -172,7 +172,7 @@ void PerspectiveCamera::setAll(F32 fovX, F32 fovY, F32 near, F32 far)
 
 
 //==============================================================================
 //==============================================================================
 OrthographicCamera::OrthographicCamera(SceneGraph* scene)
 OrthographicCamera::OrthographicCamera(SceneGraph* scene)
-:	Camera(scene, Type::ORTHOGRAPHIC)
+	: Camera(scene, Type::ORTHOGRAPHIC)
 {}
 {}
 
 
 //==============================================================================
 //==============================================================================

+ 1 - 2
src/scene/Light.cpp

@@ -177,8 +177,7 @@ Error Light::loadLensFlare(const CString& filename)
 		return err;
 		return err;
 	}
 	}
 
 
-	addComponent(flareComp);
-	flareComp->setAutomaticCleanup(true);
+	addComponent(flareComp, true);
 
 
 	return ErrorCode::NONE;
 	return ErrorCode::NONE;
 }
 }

+ 5 - 0
src/scene/ModelNode.cpp

@@ -62,6 +62,11 @@ ModelPatchNode::ModelPatchNode(SceneGraph* scene)
 //==============================================================================
 //==============================================================================
 ModelPatchNode::~ModelPatchNode()
 ModelPatchNode::~ModelPatchNode()
 {
 {
+	for(SpatialComponent* sp : m_spatials)
+	{
+		getSceneAllocator().deleteInstance(sp);
+	}
+
 	m_spatials.destroy(getSceneAllocator());
 	m_spatials.destroy(getSceneAllocator());
 }
 }
 
 

+ 9 - 9
src/scene/PlayerNode.cpp

@@ -22,22 +22,22 @@ class PlayerNodeFeedbackComponent final: public SceneComponent
 {
 {
 public:
 public:
 	PlayerNodeFeedbackComponent(SceneNode* node)
 	PlayerNodeFeedbackComponent(SceneNode* node)
-	:	SceneComponent(SceneComponent::Type::NONE, node)
+		: SceneComponent(SceneComponent::Type::NONE, node)
 	{}
 	{}
 
 
 	Error update(SceneNode& node, F32, F32, Bool& updated) override
 	Error update(SceneNode& node, F32, F32, Bool& updated) override
 	{
 	{
 		updated = false;
 		updated = false;
 
 
-		PlayerControllerComponent& playerc = 
+		PlayerControllerComponent& playerc =
 			node.getComponent<PlayerControllerComponent>();
 			node.getComponent<PlayerControllerComponent>();
 		const Input& in = node.getSceneGraph().getInput();
 		const Input& in = node.getSceneGraph().getInput();
 		const F32 ang = toRad(7.0);
 		const F32 ang = toRad(7.0);
 
 
 		F32 y = in.getMousePosition().y();
 		F32 y = in.getMousePosition().y();
 		F32 x = in.getMousePosition().x();
 		F32 x = in.getMousePosition().x();
-		if(playerc.getTimestamp() == node.getGlobalTimestamp() 
-			|| y != 0.0 
+		if(playerc.getTimestamp() == node.getGlobalTimestamp()
+			|| y != 0.0
 			|| x != 0.0)
 			|| x != 0.0)
 		{
 		{
 			MoveComponent& move = node.getComponent<MoveComponent>();
 			MoveComponent& move = node.getComponent<MoveComponent>();
@@ -81,13 +81,13 @@ public:
 	{
 	{
 		updated = false;
 		updated = false;
 
 
-		PlayerControllerComponent& playerc = 
+		PlayerControllerComponent& playerc =
 			node.getComponent<PlayerControllerComponent>();
 			node.getComponent<PlayerControllerComponent>();
 		MoveComponent& move = node.getComponent<MoveComponent>();
 		MoveComponent& move = node.getComponent<MoveComponent>();
 		const Input& in = node.getSceneGraph().getInput();
 		const Input& in = node.getSceneGraph().getInput();
 
 
 		const F32 speed = 3.5;
 		const F32 speed = 3.5;
-		
+
 		Vec4 moveVec(0.0);
 		Vec4 moveVec(0.0);
 		if(in.getKey(KeyCode::W))
 		if(in.getKey(KeyCode::W))
 		{
 		{
@@ -114,9 +114,9 @@ public:
 		dir.normalize();
 		dir.normalize();
 
 
 		playerc.setVelocity(
 		playerc.setVelocity(
-			moveVec.z() * speed, 
+			moveVec.z() * speed,
 			moveVec.x() * speed,
 			moveVec.x() * speed,
-			0.0, 
+			0.0,
 			dir);
 			dir);
 
 
 		return ErrorCode::NONE;
 		return ErrorCode::NONE;
@@ -129,7 +129,7 @@ public:
 
 
 //==============================================================================
 //==============================================================================
 PlayerNode::PlayerNode(SceneGraph* scene)
 PlayerNode::PlayerNode(SceneGraph* scene)
-:	SceneNode(scene)
+	: SceneNode(scene)
 {}
 {}
 
 
 //==============================================================================
 //==============================================================================

+ 17 - 5
src/scene/SceneGraph.cpp

@@ -95,6 +95,15 @@ SceneGraph::SceneGraph()
 //==============================================================================
 //==============================================================================
 SceneGraph::~SceneGraph()
 SceneGraph::~SceneGraph()
 {
 {
+	Error err = iterateSceneNodes([&](SceneNode& s) -> Error
+	{
+		s.setMarkedForDeletion();
+		return ErrorCode::NONE;
+	});
+	(void)err;
+
+	deleteNodesMarkedForDeletion();
+
 	if(m_sectors)
 	if(m_sectors)
 	{
 	{
 		m_alloc.deleteInstance(m_sectors);
 		m_alloc.deleteInstance(m_sectors);
@@ -172,7 +181,7 @@ void SceneGraph::unregisterNode(SceneNode* node)
 {
 {
 	// Remove from vector
 	// Remove from vector
 	auto it = m_nodes.begin();
 	auto it = m_nodes.begin();
-	for(; it != m_nodes.end(); it++)
+	for(; it != m_nodes.end(); ++it)
 	{
 	{
 		if((*it) == node)
 		if((*it) == node)
 		{
 		{
@@ -230,13 +239,16 @@ void SceneGraph::deleteNodesMarkedForDeletion()
 		Bool found = false;
 		Bool found = false;
 		auto it = m_nodes.begin();
 		auto it = m_nodes.begin();
 		auto end = m_nodes.end();
 		auto end = m_nodes.end();
-		for(; it != end; it++)
+		for(; it != end; ++it)
 		{
 		{
-			if((*it)->getMarkedForDeletion())
+			SceneNode* node = *it;
+
+			if(node->getMarkedForDeletion())
 			{
 			{
 				// Delete node
 				// Delete node
-				unregisterNode(*it);
-				m_alloc.deleteInstance(*it);
+				unregisterNode(node);
+				m_alloc.deleteInstance(node);
+				m_objectsMarkedForDeletionCount.fetchSub(1);
 				found = true;
 				found = true;
 				break;
 				break;
 			}
 			}

+ 8 - 8
src/scene/SceneNode.cpp

@@ -10,16 +10,9 @@ namespace anki {
 
 
 //==============================================================================
 //==============================================================================
 SceneNode::SceneNode(SceneGraph* scene)
 SceneNode::SceneNode(SceneGraph* scene)
-:	m_scene(scene)
+	: m_scene(scene)
 {}
 {}
 
 
-//==============================================================================
-Error SceneNode::create(const CString& name)
-{
-	m_name.create(getSceneAllocator(), name);
-	return ErrorCode::NONE;
-}
-
 //==============================================================================
 //==============================================================================
 SceneNode::~SceneNode()
 SceneNode::~SceneNode()
 {
 {
@@ -41,6 +34,13 @@ SceneNode::~SceneNode()
 	m_components.destroy(alloc);
 	m_components.destroy(alloc);
 }
 }
 
 
+//==============================================================================
+Error SceneNode::create(const CString& name)
+{
+	m_name.create(getSceneAllocator(), name);
+	return ErrorCode::NONE;
+}
+
 //==============================================================================
 //==============================================================================
 void SceneNode::setMarkedForDeletion()
 void SceneNode::setMarkedForDeletion()
 {
 {

+ 6 - 6
src/scene/StaticGeometryNode.cpp

@@ -43,6 +43,10 @@ StaticGeometryPatchNode::StaticGeometryPatchNode(SceneGraph* scene)
 	: SceneNode(scene)
 	: SceneNode(scene)
 {}
 {}
 
 
+//==============================================================================
+StaticGeometryPatchNode::~StaticGeometryPatchNode()
+{}
+
 //==============================================================================
 //==============================================================================
 Error StaticGeometryPatchNode::create(
 Error StaticGeometryPatchNode::create(
 	const CString& name, const ModelPatch* modelPatch)
 	const CString& name, const ModelPatch* modelPatch)
@@ -59,7 +63,7 @@ Error StaticGeometryPatchNode::create(
 			getSceneAllocator().newInstance<SpatialComponent>(
 			getSceneAllocator().newInstance<SpatialComponent>(
 			this, &m_modelPatch->getBoundingShapeSub(i));
 			this, &m_modelPatch->getBoundingShapeSub(i));
 
 
-		addComponent(spatial);
+		addComponent(spatial, true);
 
 
 		spatial->setSpatialOrigin(
 		spatial->setSpatialOrigin(
 			m_modelPatch->getBoundingShapeSub(i).getCenter());
 			m_modelPatch->getBoundingShapeSub(i).getCenter());
@@ -69,15 +73,11 @@ Error StaticGeometryPatchNode::create(
 	// Create render component
 	// Create render component
 	RenderComponent* rcomp =
 	RenderComponent* rcomp =
 		getSceneAllocator().newInstance<StaticGeometryRenderComponent>(this);
 		getSceneAllocator().newInstance<StaticGeometryRenderComponent>(this);
-	addComponent(rcomp);
+	addComponent(rcomp, true);
 
 
 	return ErrorCode::NONE;
 	return ErrorCode::NONE;
 }
 }
 
 
-//==============================================================================
-StaticGeometryPatchNode::~StaticGeometryPatchNode()
-{}
-
 //==============================================================================
 //==============================================================================
 Error StaticGeometryPatchNode::buildRendering(RenderingBuildData& data)
 Error StaticGeometryPatchNode::buildRendering(RenderingBuildData& data)
 {
 {

+ 1 - 0
testapp/Main.cpp

@@ -545,6 +545,7 @@ int main(int argc, char* argv[])
 	}
 	}
 	else
 	else
 	{
 	{
+		delete app;
 		ANKI_LOGI("Bye!!");
 		ANKI_LOGI("Bye!!");
 	}
 	}