Bläddra i källkod

Fix Android build

Daniele Bartolini 10 år sedan
förälder
incheckning
f20eed14f9
7 ändrade filer med 57 tillägg och 35 borttagningar
  1. 1 1
      src/crown.cpp
  2. 1 1
      src/crown.h
  3. 10 2
      src/device.cpp
  4. 3 3
      src/device.h
  5. 15 0
      src/device_options.h
  6. 24 27
      src/main/main_android.cpp
  7. 3 1
      src/renderers/shader.cpp

+ 1 - 1
src/crown.cpp

@@ -56,7 +56,7 @@ static void help(const char* msg = NULL)
 	);
 }
 
-bool init(const DeviceOptions& opts)
+bool init(DeviceOptions& opts)
 {
 	profiler_globals::init();
 	audio_globals::init();

+ 1 - 1
src/crown.h

@@ -12,7 +12,7 @@
 namespace crown
 {
 	/// Initializes the engine.
-	bool init(const DeviceOptions& opts);
+	bool init(DeviceOptions& opts);
 
 	/// Updates all the subsystems.
 	void update();

+ 10 - 2
src/device.cpp

@@ -22,12 +22,16 @@
 #include "path.h"
 #include "disk_filesystem.h"
 
+#if CROWN_PLATFORM_ANDROID
+	#include "apk_filesystem.h"
+#endif // CROWN_PLATFORM_ANDROID
+
 #define MAX_SUBSYSTEMS_HEAP 8 * 1024 * 1024
 
 namespace crown
 {
 
-Device::Device(const DeviceOptions& opts)
+Device::Device(DeviceOptions& opts)
 	: _allocator(default_allocator(), MAX_SUBSYSTEMS_HEAP)
 	, _width(0)
 	, _height(0)
@@ -56,7 +60,11 @@ void Device::init()
 	// Initialize
 	CE_LOGI("Initializing Crown Engine %s...", version());
 
+#if CROWN_PLATFORM_ANDROID
+	_bundle_filesystem = CE_NEW(_allocator, ApkFilesystem)(_device_options.asset_manager());
+#else
 	_bundle_filesystem = CE_NEW(_allocator, DiskFilesystem)(_device_options.bundle_dir());
+#endif // CROWN_PLATFORM_ANDROID
 
 	read_config();
 
@@ -278,7 +286,7 @@ namespace device_globals
 	char _buffer[sizeof(Device)];
 	Device* _device = NULL;
 
-	void init(const DeviceOptions& opts)
+	void init(DeviceOptions& opts)
 	{
 		CE_ASSERT(_device == NULL, "Crown already initialized");
 		_device = new (_buffer) Device(opts);

+ 3 - 3
src/device.h

@@ -27,7 +27,7 @@ namespace crown
 /// @ingroup Device
 struct Device
 {
-	Device(const DeviceOptions& opts);
+	Device(DeviceOptions& opts);
 
 	void init();
 
@@ -125,7 +125,7 @@ private:
 	float _last_delta_time;
 	double _time_since_start;
 
-	const DeviceOptions& _device_options;
+	DeviceOptions& _device_options;
 	Filesystem* _bundle_filesystem;
 	StringId64 _boot_package_id;
 	StringId64 _boot_script_id;
@@ -146,7 +146,7 @@ private:
 
 namespace device_globals
 {
-	void init(const DeviceOptions& opts);
+	void init(DeviceOptions& opts);
 	void shutdown();
 } // namespace device_globals
 

+ 15 - 0
src/device_options.h

@@ -6,6 +6,11 @@
 #pragma once
 
 #include "types.h"
+#include "config.h"
+
+#if CROWN_PLATFORM_ANDROID
+	#include <android/asset_manager.h>
+#endif // CROWN_PLATFORM_ANDROID
 
 namespace crown
 {
@@ -28,6 +33,10 @@ struct DeviceOptions
 	uint16_t window_width() const { return _window_width; }
 	uint16_t window_height() const { return _window_height; }
 
+#if CROWN_PLATFORM_ANDROID
+	AAssetManager* asset_manager();
+#endif // CROWN_PLATFORM_ANDROID
+
 private:
 
 	const char* _source_dir;
@@ -43,6 +52,12 @@ private:
 	uint16_t _window_y;
 	uint16_t _window_width;
 	uint16_t _window_height;
+
+public:
+
+#if CROWN_PLATFORM_ANDROID
+	AAssetManager* _asset_manager;
+#endif
 };
 
 } // namespace crown

+ 24 - 27
src/main/main_android.cpp

@@ -8,12 +8,13 @@
 #if CROWN_PLATFORM_ANDROID
 
 #include "os_event_queue.h"
-#include "os_window_android.h"
 #include "thread.h"
 #include "main.h"
-#include "apk_filesystem.h"
+#include "device_options.h"
 #include "console_server.h"
 #include "crown.h"
+#include "memory.h"
+#include <stdlib.h>
 #include <jni.h>
 #include <android/sensor.h>
 #include <android_native_app_glue.h>
@@ -46,14 +47,13 @@ static bool s_exit = false;
 
 struct MainThreadArgs
 {
-	Filesystem* fs;
-	ConfigSettings* cs;
+	DeviceOptions* opts;
 };
 
 int32_t func(void* data)
 {
-	MainThreadArgs* args = (MainThreadArgs*) data;
-	crown::init(*args->fs, *args->cs);
+	MainThreadArgs* args = (MainThreadArgs*)data;
+	crown::init(*args->opts);
 	crown::update();
 	crown::shutdown();
 	s_exit = true;
@@ -62,10 +62,9 @@ int32_t func(void* data)
 
 struct AndroidDevice
 {
-	void run(struct android_app* app, Filesystem& fs, ConfigSettings& cs)
+	void run(struct android_app* app, DeviceOptions& opts)
 	{
-		_margs.fs = &fs;
-		_margs.cs = &cs;
+		_margs.opts = &opts;
 
 		app->userData = this;
 		app->onAppCmd = crown::AndroidDevice::on_app_cmd;
@@ -136,12 +135,12 @@ struct AndroidDevice
 		if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION)
 		{
 			const int32_t action = AMotionEvent_getAction(event);
-			const int32_t pointerIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
-			const int32_t pointerCount = AMotionEvent_getPointerCount(event);
+			const int32_t pointer_index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+			const int32_t pointer_count = AMotionEvent_getPointerCount(event);
 
-			const int32_t pointerId = AMotionEvent_getPointerId(event, pointerIndex);
-			const float x = AMotionEvent_getX(event, pointerIndex);
-			const float y = AMotionEvent_getY(event, pointerIndex);
+			const int32_t pointer_id = AMotionEvent_getPointerId(event, pointer_index);
+			const float x = AMotionEvent_getX(event, pointer_index);
+			const float y = AMotionEvent_getY(event, pointer_index);
 
 			const int32_t actionMasked = (action & AMOTION_EVENT_ACTION_MASK);
 
@@ -150,24 +149,24 @@ struct AndroidDevice
 				case AMOTION_EVENT_ACTION_DOWN:
 				case AMOTION_EVENT_ACTION_POINTER_DOWN:
 				{
-					_queue.push_touch_event((int16_t)x, (int16_t)y, (uint8_t)pointerId, true);
+					_queue.push_touch_event((int16_t)x, (int16_t)y, (uint8_t)pointer_id, true);
 					break;
 				}
 				case AMOTION_EVENT_ACTION_UP:
 				case AMOTION_EVENT_ACTION_POINTER_UP:
 				{
-					_queue.push_touch_event((int16_t)x, (int16_t)y, (uint8_t)pointerId, false);
+					_queue.push_touch_event((int16_t)x, (int16_t)y, (uint8_t)pointer_id, false);
 					break;
 				}
 				case AMOTION_EVENT_ACTION_OUTSIDE:
 				case AMOTION_EVENT_ACTION_CANCEL:
 				{
-					_queue.push_touch_event((int16_t)x, (int16_t)y, (uint8_t)pointerId, false);
+					_queue.push_touch_event((int16_t)x, (int16_t)y, (uint8_t)pointer_id, false);
 					break;
 				}
 				case AMOTION_EVENT_ACTION_MOVE:
 				{
-					for (int index = 0; index < pointerCount; index++)
+					for (int index = 0; index < pointer_count; index++)
 					{
 						const float xx = AMotionEvent_getX(event, index);
 						const float yy = AMotionEvent_getY(event, index);
@@ -187,7 +186,8 @@ struct AndroidDevice
 
 			if (keycode == AKEYCODE_BACK)
 			{
-				_queue.push_keyboard_event(0, KeyboardButton::ESCAPE, keyaction == AKEY_EVENT_ACTION_DOWN ? true : false);
+				_queue.push_keyboard_event(KeyboardButton::ESCAPE
+					, keyaction == AKEY_EVENT_ACTION_DOWN ? true : false);
 			}
 
 			return 1;
@@ -231,15 +231,12 @@ void android_main(struct android_app* app)
 
 	memory_globals::init();
 
-	{
-		ConfigSettings cs;
-		ApkFilesystem dst_fs(app->activity->assetManager);
-		parse_config_file(dst_fs, cs);
-		console_server_globals::init(cs.console_port, false);
-		crown::s_advc.run(app, dst_fs, cs);
-		console_server_globals::shutdown();
-	}
+	DeviceOptions opts(0, NULL);
+	opts._asset_manager = app->activity->assetManager;
 
+	console_server_globals::init(opts.console_port(), false);
+	crown::s_advc.run(app, opts);
+	console_server_globals::shutdown();
 	memory_globals::shutdown();
 }
 

+ 3 - 1
src/renderers/shader.cpp

@@ -26,7 +26,9 @@
 #	define SHADERC_PATH SHADERC_NAME""SHADERC_BITS
 #elif CROWN_PLATFORM_WINDOWS
 #	define SHADERC_PATH SHADERC_NAME""SHADERC_BITS".exe"
-#endif // CROWN_PLATFORM_WINDOWS
+#else
+# 	define SHADERC_PATH ""
+#endif // CROWN_PLATFORM_LINUX
 
 namespace crown
 {