Daniele Bartolini 10 år sedan
förälder
incheckning
a702c2421f
4 ändrade filer med 35 tillägg och 4 borttagningar
  1. 4 0
      src/config.h
  2. 22 4
      src/device/device.cpp
  3. 3 0
      src/device/device.h
  4. 6 0
      src/device/log.cpp

+ 4 - 0
src/config.h

@@ -97,6 +97,10 @@
 	#define CROWN_BUNDLEIGNORE ".bundleignore"
 #endif // CROWN_BUNDLEIGNORE
 
+#ifndef CROWN_LAST_LOG
+	#define CROWN_LAST_LOG "last.log"
+#endif // CROWN_LAST_LOG
+
 #ifndef CROWN_MAX_JOYPADS
 	#define CROWN_MAX_JOYPADS 4
 #endif // CROWN_MAX_JOYPADS

+ 22 - 4
src/device/device.cpp

@@ -10,6 +10,7 @@
 #include "console_server.h"
 #include "device.h"
 #include "disk_filesystem.h"
+#include "file.h"
 #include "filesystem.h"
 #include "input_device.h"
 #include "input_manager.h"
@@ -126,6 +127,7 @@ Device::Device(const DeviceOptions& opts)
 	: _allocator(default_allocator(), MAX_SUBSYSTEMS_HEAP)
 	, _device_options(opts)
 	, _bundle_filesystem(NULL)
+	, _last_log(NULL)
 	, _resource_loader(NULL)
 	, _resource_manager(NULL)
 	, _bgfx_allocator(NULL)
@@ -164,17 +166,17 @@ Device::Device(const DeviceOptions& opts)
 
 void Device::init()
 {
-	// Initialize
-	CE_LOGI("Initializing Crown Engine %s...", version());
-
 	profiler_globals::init();
 
 #if CROWN_PLATFORM_ANDROID
 	_bundle_filesystem = CE_NEW(_allocator, ApkFilesystem)(default_allocator(), const_cast<AAssetManager*>((AAssetManager*)_device_options.asset_manager()));
 #else
 	_bundle_filesystem = CE_NEW(_allocator, DiskFilesystem)(default_allocator(), _device_options.bundle_dir());
+	_last_log = _bundle_filesystem->open(CROWN_LAST_LOG, FileOpenMode::WRITE);
 #endif // CROWN_PLATFORM_ANDROID
 
+	CE_LOGI("Initializing Crown Engine %s...", version());
+
 	_resource_loader  = CE_NEW(_allocator, ResourceLoader)(*_bundle_filesystem);
 	_resource_manager = CE_NEW(_allocator, ResourceManager)(*_resource_loader);
 
@@ -246,7 +248,6 @@ void Device::shutdown()
 	CE_DELETE(_allocator, _shader_manager);
 	CE_DELETE(_allocator, _resource_manager);
 	CE_DELETE(_allocator, _resource_loader);
-	CE_DELETE(_allocator, _bundle_filesystem);
 
 	bgfx::shutdown();
 	window::destroy(_allocator, *_window);
@@ -254,6 +255,13 @@ void Device::shutdown()
 	CE_DELETE(_allocator, _bgfx_callback);
 	CE_DELETE(_allocator, _bgfx_allocator);
 
+	if (_last_log)
+	{
+		_bundle_filesystem->close(*_last_log);
+	}
+
+	CE_DELETE(_allocator, _bundle_filesystem);
+
 	profiler_globals::shutdown();
 
 	_allocator.clear();
@@ -422,6 +430,16 @@ void Device::reload(StringId64 type, StringId64 name)
 	}
 }
 
+void Device::log(const char* msg)
+{
+	if (_last_log)
+	{
+		_last_log->write(msg, strlen32(msg));
+		_last_log->write("\n", 1);
+		_last_log->flush();
+	}
+}
+
 ResourceManager* Device::resource_manager()
 {
 	return _resource_manager;

+ 3 - 0
src/device/device.h

@@ -36,6 +36,7 @@ class Device
 
 	const DeviceOptions& _device_options;
 	Filesystem* _bundle_filesystem;
+	File* _last_log;
 	ResourceLoader* _resource_loader;
 	ResourceManager* _resource_manager;
 	BgfxAllocator* _bgfx_allocator;
@@ -152,6 +153,8 @@ public:
 	/// Reloads the resource @a type @a name.
 	void reload(StringId64 type, StringId64 name);
 
+	void log(const char* msg);
+
 	/// Returns the resource manager.
 	ResourceManager* resource_manager();
 

+ 6 - 0
src/device/log.cpp

@@ -10,6 +10,7 @@
 #include "string_stream.h"
 #include "string_utils.h"
 #include "temp_allocator.h"
+#include "device.h"
 
 namespace crown
 {
@@ -75,6 +76,11 @@ namespace log_internal
 #endif
 		os::log("\n");
 
+		if (device())
+		{
+			device()->log(buf);
+		}
+
 		console_log(buf, sev);
 	}