Daniele Bartolini 11 年之前
父节点
当前提交
084acaeb17
共有 4 个文件被更改,包括 24 次插入12 次删除
  1. 4 2
      engine/compilers/bundle_compiler.cpp
  2. 4 2
      engine/console_server.cpp
  3. 4 2
      engine/device.cpp
  4. 12 6
      engine/input/input.cpp

+ 4 - 2
engine/compilers/bundle_compiler.cpp

@@ -152,18 +152,20 @@ namespace bundle_compiler
 
 namespace bundle_compiler_globals
 {
+	char _buffer[sizeof(BundleCompiler)];
 	BundleCompiler* _compiler = NULL;
 
 	void init(const char* source_dir, const char* bundle_dir)
 	{
 #if CROWN_PLATFORM_LINUX || CROWN_PLATFORM_WINDOWS
-		_compiler = CE_NEW(default_allocator(), BundleCompiler)(source_dir, bundle_dir);
+		_compiler = new (_buffer) BundleCompiler(source_dir, bundle_dir);
 #endif
 	}
 
 	void shutdown()
 	{
-		CE_DELETE(default_allocator(), _compiler);
+		_compiler->~BundleCompiler();
+		_compiler = NULL;
 	}
 
 	BundleCompiler* compiler()

+ 4 - 2
engine/console_server.cpp

@@ -353,16 +353,18 @@ void ConsoleServer::processs_filesystem(TCPSocket client, const char* msg)
 
 namespace console_server_globals
 {
+	char _buffer[sizeof(ConsoleServer)];
 	ConsoleServer* _console = NULL;
 
 	void init()
 	{
-		_console = CE_NEW(default_allocator(), ConsoleServer);
+		_console = new (_buffer) ConsoleServer();
 	}
 
 	void shutdown()
 	{
-		CE_DELETE(default_allocator(), _console);
+		_console->~ConsoleServer();
+		_console = NULL;
 	}
 
 	ConsoleServer& console()

+ 4 - 2
engine/device.cpp

@@ -239,17 +239,19 @@ void Device::reload(const char* , const char* )
 
 namespace device_globals
 {
+	char _buffer[sizeof(Device)];
 	Device* _device = NULL;
 
 	void init(Filesystem& fs, StringId64 boot_package, StringId64 boot_script)
 	{
 		CE_ASSERT(_device == NULL, "Crown already initialized");
-		_device = CE_NEW(default_allocator(), Device)(fs, boot_package, boot_script);
+		_device = new (_buffer) Device(fs, boot_package, boot_script);
 	}
 
 	void shutdown()
 	{
-		CE_DELETE(default_allocator(), _device);
+		_device->~Device();
+		_device = NULL;
 	}
 } // namespace device_globals
 

+ 12 - 6
engine/input/input.cpp

@@ -34,22 +34,28 @@ namespace crown
 {
 namespace input_globals
 {
+	const size_t BUFFER_SIZE = sizeof(Keyboard) +
+								sizeof(Mouse) + sizeof(Touch);
+	char _buffer[BUFFER_SIZE];
 	Keyboard* _keyboard = NULL;
 	Mouse* _mouse = NULL;
 	Touch* _touch = NULL;
 
 	void init()
 	{
-		_keyboard = CE_NEW(default_allocator(), Keyboard);
-		_mouse = CE_NEW(default_allocator(), Mouse);
-		_touch = CE_NEW(default_allocator(), Touch);
+		_keyboard = new (_buffer) Keyboard();
+		_mouse = new (_buffer + sizeof(Keyboard)) Mouse();
+		_touch = new (_buffer + sizeof(Keyboard) + sizeof(Mouse)) Touch();
 	}
 
 	void shutdown()
 	{
-		CE_DELETE(default_allocator(), _keyboard);
-		CE_DELETE(default_allocator(), _mouse);
-		CE_DELETE(default_allocator(), _touch);
+		_keyboard->~Keyboard();
+		_keyboard = NULL;
+		_mouse->~Mouse();
+		_mouse = NULL;
+		_touch->~Touch();
+		_touch = NULL;
 	}
 
 	Keyboard& keyboard()