Pārlūkot izejas kodu

Pass allocator to InputManager

Daniele Bartolini 10 gadi atpakaļ
vecāks
revīzija
f51bb91437
3 mainītis faili ar 15 papildinājumiem un 12 dzēšanām
  1. 1 1
      src/device.cpp
  2. 11 10
      src/input/input_manager.cpp
  3. 3 1
      src/input/input_manager.h

+ 1 - 1
src/device.cpp

@@ -86,7 +86,7 @@ void Device::init()
 
 	read_config();
 
-	_input_manager = CE_NEW(_allocator, InputManager)();
+	_input_manager = CE_NEW(_allocator, InputManager)(default_allocator());
 
 	bgfx::init(bgfx::RendererType::Count
 		, BGFX_PCI_ID_NONE

+ 11 - 10
src/input/input_manager.cpp

@@ -157,26 +157,27 @@ static const char* s_pad_axis_names[] =
 };
 CE_STATIC_ASSERT(CE_COUNTOF(s_pad_axis_names) == JoypadAxis::COUNT);
 
-InputManager::InputManager()
-	: _keyboard(NULL)
+InputManager::InputManager(Allocator& a)
+	: _allocator(&a)
+	, _keyboard(NULL)
 	, _mouse(NULL)
 	, _touch(NULL)
 {
-	_keyboard = InputDevice::create(default_allocator()
+	_keyboard = InputDevice::create(*_allocator
 		, "Keyboard"
 		, KeyboardButton::COUNT
 		, 0
 		, s_keyboard_button_names
 		, NULL
 		);
-	_mouse = InputDevice::create(default_allocator()
+	_mouse = InputDevice::create(*_allocator
 		, "Mouse"
 		, MouseButton::COUNT
 		, MouseAxis::COUNT
 		, s_mouse_button_names
 		, s_mouse_axis_names
 		);
-	_touch = InputDevice::create(default_allocator()
+	_touch = InputDevice::create(*_allocator
 		, "Touch"
 		, TouchButton::COUNT
 		, 0
@@ -186,7 +187,7 @@ InputManager::InputManager()
 
 	for (uint8_t i = 0; i < CROWN_MAX_JOYPADS; ++i)
 	{
-		_joypad[i] = InputDevice::create(default_allocator()
+		_joypad[i] = InputDevice::create(*_allocator
 			, "Joypad"
 			, JoypadButton::COUNT
 			, JoypadAxis::COUNT
@@ -203,11 +204,11 @@ InputManager::InputManager()
 InputManager::~InputManager()
 {
 	for (uint8_t i = 0; i < CROWN_MAX_JOYPADS; ++i)
-		InputDevice::destroy(default_allocator(), _joypad[i]);
+		InputDevice::destroy(*_allocator, _joypad[i]);
 
-	InputDevice::destroy(default_allocator(), _touch);
-	InputDevice::destroy(default_allocator(), _mouse);
-	InputDevice::destroy(default_allocator(), _keyboard);
+	InputDevice::destroy(*_allocator, _touch);
+	InputDevice::destroy(*_allocator, _mouse);
+	InputDevice::destroy(*_allocator, _keyboard);
 }
 
 InputDevice* InputManager::keyboard()

+ 3 - 1
src/input/input_manager.h

@@ -8,6 +8,7 @@
 #include "config.h"
 #include "types.h"
 #include "input_types.h"
+#include "memory_types.h"
 
 namespace crown
 {
@@ -19,7 +20,7 @@ class InputManager
 {
 public:
 
-	InputManager();
+	InputManager(Allocator& a);
 	~InputManager();
 
 	/// Returns the default keyboard input device.
@@ -42,6 +43,7 @@ public:
 
 private:
 
+	Allocator* _allocator;
 	InputDevice* _keyboard;
 	InputDevice* _mouse;
 	InputDevice* _touch;