Pārlūkot izejas kodu

Pass allocator to physics globals

Daniele Bartolini 10 gadi atpakaļ
vecāks
revīzija
15a6d4eae3
3 mainītis faili ar 16 papildinājumiem un 14 dzēšanām
  1. 2 2
      src/device.cpp
  2. 4 2
      src/world/physics.h
  3. 10 10
      src/world/physics_world_bullet.cpp

+ 2 - 2
src/device.cpp

@@ -205,7 +205,7 @@ void Device::init()
 	_lua_environment  = CE_NEW(_allocator, LuaEnvironment)();
 
 	audio_globals::init();
-	physics_globals::init();
+	physics_globals::init(_allocator);
 
 	_boot_package = create_resource_package(_boot_package_name);
 	_boot_package->load();
@@ -234,7 +234,7 @@ void Device::shutdown()
 	_boot_package->unload();
 	destroy_resource_package(*_boot_package);
 
-	physics_globals::shutdown();
+	physics_globals::shutdown(_allocator);
 	audio_globals::shutdown();
 
 	CE_DELETE(_allocator, _lua_environment);

+ 4 - 2
src/world/physics.h

@@ -5,6 +5,8 @@
 
 #pragma once
 
+#include "memory_types.h"
+
 namespace crown
 {
 /// Global physics-related functions
@@ -14,9 +16,9 @@ namespace physics_globals
 {
 	/// Initializes the physics system.
 	/// This is the place where to create and initialize per-application objects.
-	void init();
+	void init(Allocator& a);
 
 	/// It should reverse the actions performed by physics_globals::init().
-	void shutdown();
+	void shutdown(Allocator& a);
 } // namespace physics_globals
 } // namespace crown

+ 10 - 10
src/world/physics_world_bullet.cpp

@@ -54,20 +54,20 @@ namespace physics_globals
 	static btBroadphaseInterface* _bt_interface;
 	static btSequentialImpulseConstraintSolver* _bt_solver;
 
-	void init()
+	void init(Allocator& a)
 	{
-		_bt_configuration = CE_NEW(default_allocator(), btDefaultCollisionConfiguration);
-		_bt_dispatcher = CE_NEW(default_allocator(), btCollisionDispatcher)(_bt_configuration);
-		_bt_interface = CE_NEW(default_allocator(), btDbvtBroadphase);
-		_bt_solver = CE_NEW(default_allocator(), btSequentialImpulseConstraintSolver);
+		_bt_configuration = CE_NEW(a, btDefaultCollisionConfiguration);
+		_bt_dispatcher    = CE_NEW(a, btCollisionDispatcher)(_bt_configuration);
+		_bt_interface     = CE_NEW(a, btDbvtBroadphase);
+		_bt_solver        = CE_NEW(a, btSequentialImpulseConstraintSolver);
 	}
 
-	void shutdown()
+	void shutdown(Allocator& a)
 	{
-		CE_DELETE(default_allocator(), _bt_solver);
-		CE_DELETE(default_allocator(), _bt_interface);
-		CE_DELETE(default_allocator(), _bt_dispatcher);
-		CE_DELETE(default_allocator(), _bt_configuration);
+		CE_DELETE(a, _bt_solver);
+		CE_DELETE(a, _bt_interface);
+		CE_DELETE(a, _bt_dispatcher);
+		CE_DELETE(a, _bt_configuration);
 	}
 } // namespace physics_globals