1. Christian Fischer
  2. wiesel

Commits

Christian Fischer  committed 21b9209

removed android dependencies from the core library

  • Participants
  • Parent commits 89d3a1e
  • Branches default

Comments (0)

Files changed (31)

File libraries/android-native/wiesel-android/Android.mk

View file
+# wiesel-android
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+# define source folders of this library
+MY_LOCAL_FOLDERS := \
+				$(LOCAL_PATH)/src								\
+				$(LOCAL_PATH)/../../../src/android				\
+
+MY_SUBFOLDERS := \
+				$(foreach dir,$(MY_LOCAL_FOLDERS),$(shell /usr/bin/find $(dir) -type d -print))
+
+MY_FILES := \
+				$(subst $(LOCAL_PATH), ,$(foreach dir,$(MY_SUBFOLDERS),$(wildcard $(dir)/*.cpp)))
+
+# configure the module
+LOCAL_MODULE               := wiesel-android
+LOCAL_MODULE_FILENAME      := libwieselandroid
+LOCAL_CFLAGS               := -Werror
+LOCAL_LDLIBS               := 
+LOCAL_STATIC_LIBRARIES     := wiesel-base wiesel-core
+LOCAL_SRC_FILES            := $(MY_FILES)
+LOCAL_C_INCLUDES           := $(MY_LOCAL_FOLDERS)
+LOCAL_EXPORT_C_INCLUDES    := $(MY_LOCAL_FOLDERS)
+LOCAL_EXPORT_LDLIBS        := 
+
+# Build the static library
+include $(BUILD_STATIC_LIBRARY)
+
+# import all required modules
+$(call import-module,wiesel-base)
+$(call import-module,wiesel-core)
+
+# External third-party modules
+$(call import-module,third-party/libpng)

File samples/HelloWiesel/android/jni/Android.mk

View file
 
 
 # configure the application's build
-LOCAL_MODULE               := main
-LOCAL_SRC_FILES            := $(MY_FILES)
-LOCAL_LDLIBS               :=
-LOCAL_STATIC_LIBRARIES     := wiesel-common wiesel-core
+LOCAL_MODULE                  := main
+LOCAL_SRC_FILES               := $(MY_FILES)
+LOCAL_LDLIBS                  :=
+LOCAL_STATIC_LIBRARIES        := wiesel-common wiesel-core
+LOCAL_WHOLE_STATIC_LIBRARIES  := wiesel-android
 
 # build the shared library
 include $(BUILD_SHARED_LIBRARY)
 
 # import all required modules
+$(call import-module,wiesel-android)
 $(call import-module,wiesel-base)
 $(call import-module,wiesel-core)
 $(call import-module,wiesel-common)

File samples/HelloWiesel/android/jni/Application.mk

View file
 #APP_ABI := armeabi armeabi-v7a x86
 APP_CPPFLAGS += -frtti
 APP_STL := gnustl_static
+APP_DEBUG := true

File samples/HelloWiesel/android/jni/module_registry.cpp

View file
 
 #include "wiesel/resources/graphics/image_loader_libpng.loadable_module"
+#include "wiesel/generic_platform.loadable_module"
 
+#include "wiesel/android/util/log_writer_android.loadable_module"
+#include "wiesel/android/video/android_video_loader.loadable_module"
+#include "wiesel/android/android_platform.loadable_module"

File src/android/wiesel/android/android_main.cpp

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifdef __ANDROID__
+
+#include <wiesel/engine.h>
+
+#include "android_platform.h"
+
+#include <android_native_app_glue.h>
+
+
+using namespace wiesel;
+using namespace wiesel::android;
+
+
+extern "C" void android_main(struct android_app* state) {
+	// Make sure glue isn't stripped.
+	app_dummy();
+
+	// initialize the engine
+	Engine::getInstance()->initialize(0, NULL);
+
+	// find the android platform
+	const std::vector<Platform*> *platforms = Engine::getInstance()->getPlatforms();
+	for(std::vector<Platform*>::const_iterator it=platforms->begin(); it!=platforms->end(); it++) {
+		AndroidPlatform *platform = dynamic_cast<AndroidPlatform*>(*it);
+		if (platform) {
+			platform->initAndroidApp(state);
+		}
+	}
+
+	// start the application
+	Engine::getInstance()->run();
+	Engine::getInstance()->shutdown();
+
+	return;
+}
+
+
+#endif // __ANDROID__

File src/android/wiesel/android/android_platform.cpp

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifdef __ANDROID__
+
+#include "android_platform.h"
+#include "io/android_asset_fs.h"
+#include "video/android_video_device.h"
+
+#include "wiesel/io/datasource.h"
+#include "wiesel/io/file.h"
+#include "wiesel/ui/touchhandler.h"
+#include "wiesel/util/log.h"
+#include "wiesel/video/video_device.h"
+#include "wiesel/engine.h"
+
+#include <algorithm>
+#include <assert.h>
+#include <inttypes.h>
+#include <android_native_app_glue.h>
+
+
+using namespace wiesel;
+using namespace wiesel::android;
+using namespace std;
+
+
+AndroidPlatform::AndroidPlatform() {
+	this->app					= NULL;
+	this->asset_fs				= NULL;
+	this->window_initialized	= false;
+
+	return;
+}
+
+AndroidPlatform::~AndroidPlatform() {
+	if (asset_fs) {
+		delete asset_fs;
+		asset_fs = NULL;
+	}
+
+	return;
+}
+
+
+
+
+
+
+/**
+ * Process the next input event.
+ */
+int32_t wiesel::android::platform_handle_input(struct android_app* app, AInputEvent* event) {
+	AndroidPlatform* platform = static_cast<AndroidPlatform*>(app->userData);
+	if (platform) {
+		return platform->onInputEvent(app, event);
+	}
+
+	return 0;
+}
+
+/**
+ * Process the next main command.
+ */
+void wiesel::android::platform_handle_cmd(struct android_app* app, int32_t cmd) {
+	AndroidPlatform* platform = static_cast<AndroidPlatform*>(app->userData);
+	if (platform) {
+		platform->onCommand(app, cmd);
+	}
+
+	return;
+}
+
+
+
+
+
+
+
+
+void AndroidPlatform::initAndroidApp(struct android_app *app) {
+	this->app		= app;
+	this->asset_fs	= new AndroidAssetFileSystem(app->activity->assetManager);
+
+	app->userData     = this;
+	app->onAppCmd     = platform_handle_cmd;
+	app->onInputEvent = platform_handle_input;
+
+	// wait until window was created
+	do {
+		onRun();
+	}
+	while(!window_initialized);
+
+	return;
+}
+
+
+void AndroidPlatform::addReceiver(IAndroidMessageReceiver* recv) {
+	receivers.push_back(recv);
+	return;
+}
+
+void AndroidPlatform::removeReceiver(const IAndroidMessageReceiver* recv) {
+	std::vector<IAndroidMessageReceiver*>::iterator it;
+
+	while((it = std::find(receivers.begin(), receivers.end(), recv)) != receivers.end()) {
+		receivers.erase(it);
+	}
+
+	return;
+}
+
+
+bool AndroidPlatform::onInit() {
+	return true;
+}
+
+
+void AndroidPlatform::onCommand(android_app* app, int32_t cmd) {
+	/*
+	string cmd_name = "<unknown>";
+	switch(cmd) {
+		case APP_CMD_INPUT_CHANGED:				cmd_name = "APP_CMD_INPUT_CHANGED";				break;
+		case APP_CMD_INIT_WINDOW:				cmd_name = "APP_CMD_INIT_WINDOW";				break;
+		case APP_CMD_TERM_WINDOW:				cmd_name = "APP_CMD_TERM_WINDOW";				break;
+		case APP_CMD_WINDOW_RESIZED:			cmd_name = "APP_CMD_WINDOW_RESIZED";			break;
+		case APP_CMD_WINDOW_REDRAW_NEEDED:		cmd_name = "APP_CMD_WINDOW_REDRAW_NEEDED";		break;
+		case APP_CMD_CONTENT_RECT_CHANGED:		cmd_name = "APP_CMD_CONTENT_RECT_CHANGED";		break;
+		case APP_CMD_GAINED_FOCUS:				cmd_name = "APP_CMD_GAINED_FOCUS";				break;
+		case APP_CMD_LOST_FOCUS:				cmd_name = "APP_CMD_LOST_FOCUS";				break;
+		case APP_CMD_CONFIG_CHANGED:			cmd_name = "APP_CMD_CONFIG_CHANGED";			break;
+		case APP_CMD_LOW_MEMORY:				cmd_name = "APP_CMD_LOW_MEMORY";				break;
+		case APP_CMD_START:						cmd_name = "APP_CMD_START";						break;
+		case APP_CMD_RESUME:					cmd_name = "APP_CMD_RESUME";					break;
+		case APP_CMD_SAVE_STATE:				cmd_name = "APP_CMD_SAVE_STATE";				break;
+		case APP_CMD_PAUSE:						cmd_name = "APP_CMD_PAUSE";						break;
+		case APP_CMD_STOP:						cmd_name = "APP_CMD_STOP";						break;
+		case APP_CMD_DESTROY:					cmd_name = "APP_CMD_DESTROY";					break;
+	}
+
+	Log::info << endl << cmd_name << endl;
+	*/
+	
+
+	// check, if the app object is valid
+	assert(app == this->app);
+	if (app != this->app) {
+		return;
+	}
+
+	switch (cmd) {
+		case APP_CMD_SAVE_STATE: {
+			// The system has asked us to save our current state.  Do so.
+			break;
+		}
+
+		case APP_CMD_INIT_WINDOW: {
+			// The window is being shown, get it ready.
+			window_initialized = true;
+			break;
+		}
+
+		case APP_CMD_CONFIG_CHANGED: {
+			break;
+		}
+
+		case APP_CMD_WINDOW_RESIZED: {
+			break;
+		}
+
+		case APP_CMD_TERM_WINDOW: {
+			window_initialized = false;
+			break;
+		}
+
+		case APP_CMD_GAINED_FOCUS: {
+			break;
+		}
+
+		case APP_CMD_LOST_FOCUS: {
+			break;
+		}
+
+		case APP_CMD_PAUSE:
+		case APP_CMD_STOP: {
+			break;
+		}
+
+		case APP_CMD_START:
+		case APP_CMD_RESUME: {
+			break;
+		}
+
+		case APP_CMD_DESTROY: {
+			break;
+		}
+	}
+
+	// send this event to all registered message receivers
+	for(std::vector<IAndroidMessageReceiver*>::iterator it=receivers.begin(); it!=receivers.end(); it++) {
+		(*it)->onAndroidCommand(cmd);
+	}
+
+	return;
+}
+
+
+int32_t AndroidPlatform::onInputEvent(struct android_app* app, AInputEvent* event) {
+	int32_t ret = 0;
+
+	// check, if the app object is valid
+	assert(app == this->app);
+	if (app != this->app) {
+		return 0;
+	}
+
+	// send this event to all registered message receivers
+	for(std::vector<IAndroidMessageReceiver*>::iterator it=receivers.begin(); it!=receivers.end(); it++) {
+		int32_t r = (*it)->onAndroidInputEvent(event);
+		if (r) {
+			ret = r;
+		}
+	}
+
+	return ret;
+}
+
+
+/*
+bool AndroidPlatform::initWindow() {
+	if (app->window != NULL) {
+		// when there's still an existing screen, try to re-attach to it's EGL context
+		if (video_device != NULL) {
+			bool success = false;
+
+			if (video_device->reattachContext()) {
+				success = true;
+			}
+
+			if (!success) {
+				closeWindow();
+				assert(screen == NULL);
+			}
+		}
+
+		if (video_device == NULL) {
+			video_device = new AndroidVideoDevice(this, app);
+			video_device->retain();
+
+			if (video_device->init() == false) {
+				closeWindow();
+			}
+		}
+	}
+
+	return video_device != NULL;
+}
+
+
+void AndroidPlatform::closeWindow() {
+	if (video_device) {
+		video_device->releaseContext();
+		video_device->release();
+		video_device = NULL;
+	}
+
+	return;
+}
+*/
+
+
+void AndroidPlatform::onShutdown() {
+	// close the java activity
+	ANativeActivity_finish(app->activity);
+	return;
+}
+
+
+void AndroidPlatform::onRunFirst() {
+	return;
+}
+
+
+bool AndroidPlatform::onRun() {
+	// Read all pending events.
+	int ident;
+	int events;
+	struct android_poll_source* source;
+
+	// loop until all events are read, then continue
+	while ((ident=ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0) {
+		// Process this event.
+		if (source != NULL) {
+			source->process(app, source);
+		}
+
+		// Check if we are exiting.
+		if (app->destroyRequested != 0) {
+			Engine::getInstance()->requestExit();
+			return true;
+		}
+	}
+
+	/*
+	if (video_device) {
+		switch(video_device->getState()) {
+			case Engine_Background:
+			case Engine_Suspended: {
+				// no need to waste CPU time while in suspend state...
+				sleep(1);
+				break;
+			}
+
+			default: {
+				break;
+			}
+		}
+	}
+	*/
+
+	return false;
+}
+
+
+FileSystem *AndroidPlatform::getRootFileSystem() {
+	return NULL;
+}
+
+
+FileSystem *AndroidPlatform::getAssetFileSystem() {
+	return asset_fs;
+}
+
+
+
+IAndroidMessageReceiver::IAndroidMessageReceiver() {
+	return;
+}
+
+IAndroidMessageReceiver::~IAndroidMessageReceiver() {
+	return;
+}
+
+
+#endif // __ANDROID__

File src/android/wiesel/android/android_platform.h

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifndef __WIESEL_ANDROID_PLATFORM_H__
+#define __WIESEL_ANDROID_PLATFORM_H__
+
+#include <wiesel/wiesel-android.def>
+
+#ifdef __ANDROID__
+
+#include <wiesel/io/filesystem.h>
+#include <wiesel/platform.h>
+#include <android_native_app_glue.h>
+
+
+namespace wiesel {
+namespace android {
+
+	class AndroidAssetFileSystem;
+	class AndroidVideoDevice;
+	class IAndroidMessageReceiver;
+
+
+
+	int32_t platform_handle_input(struct android_app* app, AInputEvent* event);
+	void platform_handle_cmd(struct android_app* app, int32_t cmd);
+
+
+	/**
+	 * @brief The android engine implementation.
+	 */
+	class WIESEL_ANDROID_EXPORT AndroidPlatform : public Platform
+	{
+	friend int32_t platform_handle_input(struct android_app* app, AInputEvent* event);
+	friend void platform_handle_cmd(struct android_app* app, int32_t cmd);
+
+	public:
+		AndroidPlatform();
+		virtual ~AndroidPlatform();
+
+	// android stuff
+	public:
+		/// initialize the platform with the native android app object
+		void initAndroidApp(struct android_app* app);
+
+		/// get the android app object
+		inline struct android_app *getAndroidApp() {
+			return app;
+		}
+
+	// message receiver
+	public:
+		void addReceiver(IAndroidMessageReceiver *receiver);
+		void removeReceiver(const IAndroidMessageReceiver *receiver);
+
+	// to be called by callback functions
+	private:
+		void onCommand(struct android_app* app, int32_t cmd);
+		int32_t onInputEvent(struct android_app* app, AInputEvent* event);
+
+/*
+	protected:
+		bool initWindow();
+		void closeWindow();
+*/
+
+	// overridables
+	protected:
+		virtual bool onInit();
+		virtual void onShutdown();
+
+		virtual void onRunFirst();
+		virtual bool onRun();
+
+	public:
+		virtual FileSystem *getRootFileSystem();
+		virtual FileSystem *getAssetFileSystem();
+
+	protected:
+		struct android_app*			app;
+		AndroidAssetFileSystem*		asset_fs;
+		bool						window_initialized;
+
+		std::vector<IAndroidMessageReceiver*>	receivers;
+	};
+
+
+
+	/**
+	 * @brief An interface receiving events from the android platform.
+	 */
+	class IAndroidMessageReceiver : public virtual SharedObject
+	{
+	public:
+		IAndroidMessageReceiver();
+		virtual ~IAndroidMessageReceiver();
+
+	public:
+		virtual void onAndroidCommand(int32_t cmd) = 0;
+		virtual int32_t onAndroidInputEvent(AInputEvent *event) = 0;
+	};
+}
+}
+
+#endif /* __ANDROID__ */
+#endif /* __WIESEL_ANDROID_PLATFORM_H__ */

File src/android/wiesel/android/android_platform.loadable_module

View file
+
+#include <wiesel/module_registry.h>
+#include "android_platform.h"
+
+// add the module to the module registry
+namespace wiesel {
+	namespace android {
+		REGISTER_MODULE_SINGLETON(
+				Platform,
+				AndroidPlatform,
+				&generic_create<AndroidPlatform>,
+				"android",
+				0x01000000u,
+				IModuleLoader::PriorityNormal
+		)
+	}
+}

File src/android/wiesel/android/io/android_asset_fs.cpp

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef __ANDROID__
+
+#include "android_asset_fs.h"
+#include "wiesel/io/databuffer.h"
+#include "wiesel/util/log.h"
+#include <dirent.h>
+
+
+using namespace wiesel;
+using namespace wiesel::android;
+using namespace std;
+
+
+AndroidAssetFileSystem::AndroidAssetFileSystem(AAssetManager *assetManager) {
+	this->assetManager = assetManager;
+	root = new AndroidAssetFileSystemDirectory(this, NULL, "");
+	root->retain();
+	return;
+}
+
+AndroidAssetFileSystem::~AndroidAssetFileSystem() {
+	root->release();
+	return;
+}
+
+
+Directory *AndroidAssetFileSystem::getRootDirectory() {
+	return root;
+}
+
+
+
+
+
+
+
+
+AndroidAssetFileSystemDirectory::AndroidAssetFileSystemDirectory(AndroidAssetFileSystem *fs, Directory *parent, const string &name)
+:	Directory(fs, parent), name(name)
+{
+	return;
+}
+
+AndroidAssetFileSystemDirectory::~AndroidAssetFileSystemDirectory() {
+	return;
+}
+
+
+string AndroidAssetFileSystemDirectory::getName() const {
+	return name;
+}
+
+
+Directory *AndroidAssetFileSystemDirectory::getSubDirectory(const string &name) {
+	// get the full path
+	string path = (getFullPath() + "/" + name);
+
+	// strip leading slash
+	if (path.size() >= 1 && path[0] == '/') {
+		path.erase(path.begin());
+	}
+
+	// check, if this directory really exists
+	AAssetDir *dir = AAssetManager_openDir(getAssetManager(), path.c_str());
+	if (dir != NULL) {
+		AndroidAssetFileSystem *fs = dynamic_cast<AndroidAssetFileSystem*>(getFileSystem());
+		AndroidAssetFileSystemDirectory *subdir = new AndroidAssetFileSystemDirectory(fs, this, name);
+		AAssetDir_close(dir);
+
+		return subdir;
+	}
+
+	return NULL;
+}
+
+
+DirectoryList AndroidAssetFileSystemDirectory::getSubDirectories() {
+	DirectoryList directories;
+
+	// it's not possible to get a directory listing from the asset filesystem,
+	// so, this function will always return a empty list.
+
+	return directories;
+}
+
+
+FileList AndroidAssetFileSystemDirectory::getFiles() {
+	FileList files;
+	AAssetDir *dir;
+	const char *filename;
+
+	// strip leading slash
+	string path = getFullPath();
+	if (path.size() >= 1 && path[0] == '/') {
+		path.erase(path.begin());
+	}
+
+	if ((dir = AAssetManager_openDir(getAssetManager(), path.c_str())) != NULL) {
+		while ((filename = AAssetDir_getNextFileName(dir)) != NULL) {
+			files.push_back(new AndroidAssetFileSystemFile(this, filename));
+		}
+
+		AAssetDir_close(dir);
+	}
+
+	return files;
+}
+
+
+
+
+
+
+
+AndroidAssetFileSystemFile::AndroidAssetFileSystemFile(AndroidAssetFileSystemDirectory *parent, const string &name)
+: File(parent), name(name)
+{
+	return;
+}
+
+AndroidAssetFileSystemFile::~AndroidAssetFileSystemFile() {
+	return;
+}
+
+
+string AndroidAssetFileSystemFile::getName() const {
+	return name;
+}
+
+
+DataBuffer *AndroidAssetFileSystemFile::getContent() {
+	string path = getFullPath();
+
+	// strip leading slash
+	if (path[0] == '/') {
+		path.erase(path.begin());
+	}
+
+	// open the asset object
+	AAsset *asset = AAssetManager_open(getAssetManager(), path.c_str(), AASSET_MODE_BUFFER);
+
+	// get the asset's data
+	if (asset) {
+		const void *data   = AAsset_getBuffer(asset);
+		off_t       size   = AAsset_getLength(asset);
+		DataBuffer *buffer = NULL;
+
+		if (data && size) {
+			buffer = ExclusiveDataBuffer::createCopyOf(reinterpret_cast<DataBuffer::data_t>(data), size);
+		}
+
+		// close the buffer
+		AAsset_close(asset);
+
+		return buffer;
+	}
+
+	return NULL;
+}
+
+#endif // __ANDROID__

File src/android/wiesel/android/io/android_asset_fs.h

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifndef __WIESEL_ANDROID_ASSET_FS_H__
+#define __WIESEL_ANDROID_ASSET_FS_H__
+
+#include <wiesel/wiesel-core.def>
+
+#include "wiesel/io/filesystem.h"
+
+#include <android/asset_manager.h>
+
+
+namespace wiesel {
+namespace android {
+
+	class AndroidAssetFileSystemDirectory;
+
+
+
+	class WIESEL_CORE_EXPORT AndroidAssetFileSystem : public FileSystem
+	{
+	private:
+		AndroidAssetFileSystem() {};
+
+	public:
+		AndroidAssetFileSystem(AAssetManager* assetManager);
+		virtual ~AndroidAssetFileSystem();
+
+		virtual Directory *getRootDirectory();
+
+		inline AAssetManager *getAssetManager() {
+			return assetManager;
+		}
+
+	private:
+		AndroidAssetFileSystemDirectory*	root;
+		AAssetManager*						assetManager;
+	};
+
+
+
+	class WIESEL_CORE_EXPORT AndroidAssetFileSystemDirectory : public Directory
+	{
+	public:
+		AndroidAssetFileSystemDirectory(AndroidAssetFileSystem *fs, Directory *parent, const std::string &name);
+		~AndroidAssetFileSystemDirectory();
+
+		virtual std::string getName() const;
+		virtual Directory *getSubDirectory(const std::string &name);
+		virtual DirectoryList getSubDirectories();
+		virtual FileList getFiles();
+
+		inline AAssetManager *getAssetManager() {
+			return ((AndroidAssetFileSystem*)getFileSystem())->getAssetManager();
+		}
+
+	private:
+		std::string		name;
+	};
+
+
+
+	class WIESEL_CORE_EXPORT AndroidAssetFileSystemFile : public File
+	{
+	public:
+		AndroidAssetFileSystemFile(AndroidAssetFileSystemDirectory *parent, const std::string &name);
+		~AndroidAssetFileSystemFile();
+
+		virtual std::string getName() const;
+
+		virtual DataBuffer *getContent();
+
+		inline AAssetManager *getAssetManager() {
+			return ((AndroidAssetFileSystem*)getParent()->getFileSystem())->getAssetManager();
+		}
+
+	private:
+		std::string		name;
+	};
+
+} /* namespace android */
+} /* namespace wiesel */
+#endif /* __WIESEL_ANDROID_ASSET_FS_H__ */

File src/android/wiesel/android/util/log_writer_android.cpp

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifdef __ANDROID__
+
+#include "log_writer_android.h"
+#include <android/log.h>
+
+
+using namespace wiesel;
+using namespace wiesel::android;
+
+
+LogWriterAndroid::LogWriterAndroid() {
+	return;
+}
+
+LogWriterAndroid::~LogWriterAndroid() {
+	return;
+}
+
+// implementing the platform specific logging
+bool LogWriterAndroid::write(LogLevel level, const std::string &tag, const std::string &message) {
+	android_LogPriority priority = ANDROID_LOG_INFO;
+
+	switch(level) {
+		case LogLevel_Debug:	priority = ANDROID_LOG_DEBUG;	break;
+		case LogLevel_Info:		priority = ANDROID_LOG_INFO;	break;
+		case LogLevel_Warning:	priority = ANDROID_LOG_WARN;	break;
+		case LogLevel_Error:	priority = ANDROID_LOG_ERROR;	break;
+	}
+
+	return __android_log_print(priority, tag.c_str(), message.c_str());
+}
+
+#endif // __ANDROID__

File src/android/wiesel/android/util/log_writer_android.h

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifndef __WIESEL_ANDROID_LOG_WRITER_H__
+#define __WIESEL_ANDROID_LOG_WRITER_H__
+
+#include <wiesel/wiesel-android.def>
+#include <wiesel/util/log_writer.h>
+#include <wiesel/util/log.h>
+
+
+
+namespace wiesel {
+namespace android {
+
+	/**
+	 * @brief A log writer module to write log messages into stdout stream
+	 */
+	class WIESEL_ANDROID_EXPORT LogWriterAndroid : public ILogWriter
+	{
+	public:
+		LogWriterAndroid();
+		virtual ~LogWriterAndroid();
+
+	public:
+		virtual bool write(LogLevel level, const std::string &tag, const std::string &message);
+	};
+
+} /* namespace android */
+} /* namespace wiesel */
+#endif /* __WIESEL_UTIL_LOG_WRITER_STDOUT_H__ */

File src/android/wiesel/android/util/log_writer_android.loadable_module

View file
+
+#include <wiesel/module_registry.h>
+#include "log_writer_android.h"
+
+// add the module to the module registry
+namespace wiesel {
+	namespace android {
+		REGISTER_MODULE_SINGLETON(
+				ILogWriter,
+				LogWriterAndroid,
+				&generic_create<LogWriterAndroid>,
+				"android",
+				0x01000000u,
+				IModuleLoader::PriorityNormal
+		)
+	}
+}

File src/android/wiesel/android/video/android_video_device.cpp

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifdef __ANDROID__
+
+#include "android_video_device.h"
+#include <wiesel/gl/gl.h>
+#include <wiesel/ui/touchhandler.h>
+#include <wiesel/util/log.h>
+#include <assert.h>
+
+
+using namespace wiesel;
+using namespace wiesel::android;
+using namespace wiesel::video;
+
+
+
+AndroidVideoDevice::AndroidVideoDevice(AndroidPlatform *platform, Screen *screen) : VideoDevice(screen) {
+	this->platform		= platform;
+	this->display		= EGL_NO_DISPLAY;
+	this->surface		= EGL_NO_SURFACE;
+	this->context		= EGL_NO_CONTEXT;
+	this->config		= NULL;
+	return;
+}
+
+
+AndroidVideoDevice::~AndroidVideoDevice() {
+	// check if the screen was released correctly
+	assert(display == EGL_NO_DISPLAY);
+	assert(surface == EGL_NO_SURFACE);
+	assert(context == EGL_NO_CONTEXT);
+	assert(config  == NULL);
+	return;
+}
+
+
+bool AndroidVideoDevice::init() {
+	// check if the screen is not already initialized
+	assert(display == EGL_NO_DISPLAY);
+	assert(surface == EGL_NO_SURFACE);
+	assert(context == EGL_NO_CONTEXT);
+	assert(config  == NULL);
+
+	if (
+			platform
+		&&	platform->getAndroidApp()
+		&&	platform->getAndroidApp()->window
+	) {
+		if (!initContext()) {
+			return false;
+		}
+	}
+	else {
+		setState(Video_Uninitialized);
+	}
+
+	return true;
+}
+
+bool AndroidVideoDevice::initContext() {
+	// initialize OpenGL ES and EGL
+
+	// get the android app object
+	assert(platform);
+	struct android_app *app = platform->getAndroidApp();
+	assert(app);
+
+	logmsg(LogLevel_Info, "TEST", "init context, window=%p", app->window);
+
+	EGLDisplay default_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+	if (this->display != EGL_NO_DISPLAY && this->display != default_display) {
+		releaseContext();
+	}
+
+	if (display == EGL_NO_DISPLAY) {
+		display =  default_display;
+		eglInitialize(display, 0, 0);
+	}
+
+	if (config == NULL) {
+		/*
+		 * Here specify the attributes of the desired configuration.
+		 * Below, we select an EGLConfig with at least 8 bits per color
+		 * component compatible with on-screen windows
+		 */
+		const EGLint config_attribs[] = {
+				EGL_SURFACE_TYPE,		EGL_WINDOW_BIT,
+				EGL_RENDERABLE_TYPE,	EGL_OPENGL_ES2_BIT,
+				EGL_BLUE_SIZE,			8,
+				EGL_GREEN_SIZE,			8,
+				EGL_RED_SIZE,			8,
+				EGL_DEPTH_SIZE,			16,
+				EGL_NONE
+		};
+
+		EGLint numConfigs;
+
+		/* Here, the application chooses the configuration it desires. In this
+		 * sample, we have a very simplified selection process, where we pick
+		 * the first EGLConfig that matches our criteria
+		 */
+		eglChooseConfig(display, config_attribs, &config, 1, &numConfigs);
+
+		/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
+		 * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
+		 * As soon as we picked a EGLConfig, we can safely reconfigure the
+		 * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID.
+		 */
+		eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
+	}
+
+	if (surface == EGL_NO_SURFACE) {
+		ANativeWindow_setBuffersGeometry(app->window, 0, 0, format);
+		
+		surface = eglCreateWindowSurface(display, config, app->window, NULL);
+	}
+
+	if (context == EGL_NO_CONTEXT) {
+		const EGLint context_attribs[] = {
+				EGL_CONTEXT_CLIENT_VERSION,		2,
+				EGL_NONE
+		};
+
+		context = eglCreateContext(display, config, NULL, context_attribs);
+		CHECK_GL_ERROR;
+	}
+
+	if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
+		logmsg(LogLevel_Error, WIESEL_GL_LOG_TAG, "eglMakeCurrent failed!");
+		return false;
+	}
+
+	// Initialize GL state.
+	glDisable(GL_CULL_FACE);
+	glDisable(GL_DEPTH_TEST);
+
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+	// initialize the window's size
+	resize();
+
+	// video device is ready
+	setState(Video_Active);
+
+	// log OpenGL information
+	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Version:    %s", ((const char*)glGetString(GL_VERSION)));
+	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Vendor:     %s", ((const char*)glGetString(GL_VENDOR)));
+	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Renderer:   %s", ((const char*)glGetString(GL_RENDERER)));
+	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Shader:     %s", ((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)));
+	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Extensions: %s", ((const char*)glGetString(GL_EXTENSIONS)));
+
+	CHECK_GL_ERROR;
+
+	return true;
+}
+
+
+bool AndroidVideoDevice::resize() {
+	EGLint w, h;
+
+	// get the display size
+	eglQuerySurface(display, surface, EGL_WIDTH,  &w);
+	eglQuerySurface(display, surface, EGL_HEIGHT, &h);
+	CHECK_GL_ERROR;
+
+	// setup viewport
+	glViewport(0, 0, w, h);
+
+	// update screen size and projection
+	updateScreenSize(w, h);
+
+	return true;
+}
+
+
+bool AndroidVideoDevice::releaseContext() {
+	if (display != EGL_NO_DISPLAY) {
+		eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+
+		if (context != EGL_NO_CONTEXT) {
+			eglDestroyContext(display, context);
+		}
+
+		if (surface != EGL_NO_SURFACE) {
+			eglDestroySurface(display, surface);
+		}
+
+		eglTerminate(display);
+	}
+
+	display = EGL_NO_DISPLAY;
+	context = EGL_NO_CONTEXT;
+	surface = EGL_NO_SURFACE;
+	config  = NULL;
+
+	CHECK_GL_ERROR;
+
+	return true;
+}
+
+
+bool AndroidVideoDevice::detachContext() {
+	// detach the gl context
+	if (display != EGL_NO_DISPLAY) {
+		eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+	}
+
+	// release surface
+	if (surface != EGL_NO_SURFACE) {
+		eglDestroySurface(display, surface);
+		surface = EGL_NO_SURFACE;
+	}
+	
+	return true;
+}
+
+
+bool AndroidVideoDevice::reattachContext() {
+	return initContext();
+}
+
+
+void AndroidVideoDevice::onAndroidCommand(int32_t cmd) {
+	switch(cmd) {
+		case APP_CMD_CONFIG_CHANGED: {
+			resize();
+			break;
+		}
+
+		case APP_CMD_WINDOW_RESIZED: {
+			resize();
+			break;
+		}
+
+		case APP_CMD_INIT_WINDOW: {
+			bool success = initContext();
+			assert(success);
+			break;
+		}
+
+		case APP_CMD_TERM_WINDOW: {
+			// The window is being hidden or closed, clean it up.
+			detachContext();
+			break;
+		}
+
+		case APP_CMD_GAINED_FOCUS: {
+			if (getScreen()) {
+				getScreen()->getTouchHandler()->releaseAllTouches();
+			}
+
+			setState(wiesel::video::Video_Active);
+
+			break;
+		}
+
+		case APP_CMD_LOST_FOCUS: {
+			if (getScreen()) {
+				getScreen()->getTouchHandler()->releaseAllTouches();
+			}
+
+			if (getState() == wiesel::video::Video_Active) {
+				setState(wiesel::video::Video_Background);
+			}
+
+			break;
+		}
+
+		case APP_CMD_PAUSE:
+		case APP_CMD_STOP: {
+			setState(wiesel::video::Video_Suspended);
+			break;
+		}
+
+		case APP_CMD_START:
+		case APP_CMD_RESUME: {
+			setState(wiesel::video::Video_Active);
+			break;
+		}
+
+		case APP_CMD_DESTROY: {
+			break;
+		}
+	}
+
+	return;
+}
+
+
+int32_t AndroidVideoDevice::onAndroidInputEvent(AInputEvent *event) {
+	wiesel::video::Screen *screen = getScreen();
+
+	if (
+			AInputEvent_getType(event)   == AINPUT_EVENT_TYPE_MOTION
+		&&	AInputEvent_getSource(event) == AINPUT_SOURCE_TOUCHSCREEN
+	) {
+		int action = AMotionEvent_getAction(event);
+
+		switch(action & AMOTION_EVENT_ACTION_MASK) {
+			case AMOTION_EVENT_ACTION_DOWN:
+			case AMOTION_EVENT_ACTION_POINTER_DOWN: {
+				int index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+				int id    = AMotionEvent_getPointerId(event, index);
+				int x     = AMotionEvent_getX(event, index);
+				int y     = AMotionEvent_getY(event, index);
+
+				if (screen) {
+					screen->getTouchHandler()->startTouch(id, x, y);
+				}
+
+				break;
+			}
+
+			case AMOTION_EVENT_ACTION_MOVE: {
+				for(int index=AMotionEvent_getPointerCount(event); --index>=0;) {
+					int id    = AMotionEvent_getPointerId(event, index);
+					int x     = AMotionEvent_getX(event, index);
+					int y     = AMotionEvent_getY(event, index);
+
+					if (screen) {
+						screen->getTouchHandler()->updateTouchLocation(id, x, y);
+					}
+				}
+
+				break;
+			}
+
+			case AMOTION_EVENT_ACTION_UP:
+			case AMOTION_EVENT_ACTION_CANCEL:
+			case AMOTION_EVENT_ACTION_POINTER_UP: {
+				int index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+				int id    = AMotionEvent_getPointerId(event, index);
+
+				if (screen) {
+					screen->getTouchHandler()->releaseTouch(id);
+				}
+
+				break;
+			}
+		}
+
+		return 1;
+	}
+
+	return 0;
+}
+
+
+void AndroidVideoDevice::preRender() {
+	if (display == EGL_NO_DISPLAY) {
+		return;
+	}
+
+	// Just fill the screen with a color.
+	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
+	CHECK_GL_ERROR;
+
+	return;
+}
+
+
+void AndroidVideoDevice::postRender() {
+	eglSwapBuffers(display, surface);
+	CHECK_GL_ERROR;
+	return;
+}
+
+#endif // __ANDROID__

File src/android/wiesel/android/video/android_video_device.h

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifndef __WIESEL_ANDROID_VIDEO_DEVICE_H__
+#define __WIESEL_ANDROID_VIDEO_DEVICE_H__
+
+#include <wiesel/wiesel-android.def>
+
+#ifdef __ANDROID__
+
+#include <wiesel/video/screen.h>
+#include <wiesel/video/video_device.h>
+#include <wiesel/android/android_platform.h>
+
+#include <wiesel/geometry.h>
+
+#include <EGL/egl.h>
+#include <GLES2/gl2.h>
+
+#include <android_native_app_glue.h>
+
+
+namespace wiesel {
+namespace android {
+
+	/**
+	 * @brief The android VideoDevice implementation.
+	 */
+	class WIESEL_ANDROID_EXPORT AndroidVideoDevice :
+			public wiesel::video::VideoDevice,
+			public wiesel::android::IAndroidMessageReceiver
+	{
+	public:
+		AndroidVideoDevice(AndroidPlatform *platform, wiesel::video::Screen *screen);
+		virtual ~AndroidVideoDevice();
+
+	public:
+		bool init();
+
+	private:
+		bool initContext();
+		bool resize();
+		bool detachContext();
+		bool reattachContext();
+		bool releaseContext();
+
+		virtual void onAndroidCommand(int32_t cmd);
+		virtual int32_t onAndroidInputEvent(AInputEvent *event);
+
+		virtual void preRender();
+		virtual void postRender();
+
+	private:
+		AndroidPlatform*	platform;
+		dimension			configured_size;
+
+		EGLint     format;
+		EGLConfig  config;
+		EGLDisplay display;
+		EGLSurface surface;
+		EGLContext context;
+	};
+
+}
+}
+
+#endif // __ANDROID__
+
+#endif /* __WIESEL_ANDROID_VIDEO_DEVICE_H__ */

File src/android/wiesel/android/video/android_video_loader.cpp

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#include "android_video_loader.h"
+#include "android_video_device.h"
+
+#include <wiesel/video/video_loader.h>
+#include <wiesel/engine.h>
+
+
+using namespace wiesel;
+using namespace wiesel::android;
+using namespace wiesel::video;
+
+
+
+AndroidVideoLoader::AndroidVideoLoader() {
+	return;
+}
+
+
+AndroidVideoLoader::~AndroidVideoLoader() {
+	return;
+}
+
+
+bool AndroidVideoLoader::loadVideoDevice(Screen *screen, const dimension &resolution, unsigned int flags) {
+	// try to find the sdl platform
+	AndroidPlatform *platform = NULL;
+	const std::vector<Platform*> *platforms = Engine::getInstance()->getPlatforms();
+	for(std::vector<Platform*>::const_iterator it=platforms->begin(); it!=platforms->end(); it++) {
+		AndroidPlatform *android_platform = dynamic_cast<AndroidPlatform*>(*it);
+		if (android_platform) {
+			platform = android_platform;
+		}
+	}
+
+	// sdl platform is required
+	assert(platform);
+	if (platform == NULL) {
+		return false;
+	}
+
+	// create the new video device
+	AndroidVideoDevice *device = new AndroidVideoDevice(platform, screen);
+
+	// inizialize the window
+	if (device->init() == false) {
+		return false;
+	}
+
+	// try to install the device into the screen
+	if (install(screen, device) == false) {
+		return false;
+	}
+
+	return true;
+}
+

File src/android/wiesel/android/video/android_video_loader.h

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifndef __WIESEL_ANDROID_VIDEO_SDLVIDEOLOADER_H__
+#define __WIESEL_ANDROID_VIDEO_SDLVIDEOLOADER_H__
+
+#include <wiesel/wiesel-android.def>
+
+#include <wiesel/video/screen.h>
+#include <wiesel/video/video_loader.h>
+
+
+namespace wiesel {
+namespace android {
+
+	/**
+	 * @brief The Android video device implementation.
+	 */
+	class WIESEL_ANDROID_EXPORT AndroidVideoLoader :
+			public wiesel::video::IVideoLoader
+	{
+	public:
+		AndroidVideoLoader();
+		virtual ~AndroidVideoLoader();
+
+	public:
+		virtual bool loadVideoDevice(video::Screen *screen, const dimension &resolution, unsigned int flags);
+	};
+
+}
+}
+
+#endif // __WIESEL_ANDROID_VIDEO_SDLVIDEOLOADER_H__

File src/android/wiesel/android/video/android_video_loader.loadable_module

View file
+
+#include <wiesel/module_registry.h>
+#include "android_video_loader.h"
+
+// add the module to the module registry
+namespace wiesel {
+	namespace android {
+		REGISTER_MODULE_SINGLETON(
+				wiesel::video::IVideoLoader,
+				AndroidVideoLoader,
+				&generic_create<AndroidVideoLoader>,
+				"android",
+				0x01000000u,
+				IModuleLoader::PriorityNormal
+		)
+	}
+}

File src/android/wiesel/wiesel-android.def

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifndef __WIESEL_ANDROID_DEF_H__
+#define __WIESEL_ANDROID_DEF_H__
+
+/**
+ * some defines and flags specially for the wiesel-android library
+ */
+
+#if defined(_WIN32)
+	#if defined(wiesel_android_EXPORTS)
+		#define WIESEL_ANDROID_EXPORT		__declspec(dllexport)
+	#else
+		#define WIESEL_ANDROID_EXPORT		__declspec(dllimport)
+	#endif
+#else
+		#define WIESEL_ANDROID_EXPORT
+#endif
+
+
+#endif // __WIESEL_ANDROID_DEF_H__

File src/common/wiesel/generic_platform.cpp

View file
 #include "wiesel/io/directory_filesystem.h"
 #include "wiesel/util/log.h"
 
-#include <sys/unistd.h>
+#include <unistd.h>
 #include <sys/param.h>
 #include <sstream>
 
 GenericPlatform::GenericPlatform() {
 	// create file systems
 	root_fs = new GenericFileSystem();
+	asset_fs = NULL;
 
 	// get the current working directory
 	char working_dir_name[MAXPATHLEN];
 		}
 	}
 
-	stringstream ss;
-	ss << working_dir_name;
-	ss << "/resources/common";
+	if (working_dir_name) {
+		stringstream ss;
+		ss << working_dir_name;
+		ss << "/resources/common";
 
-	Directory *asset_root = root_fs->findDirectory(ss.str());
-	assert(asset_root);
-
-	if (asset_root) {
-		asset_fs = new DirectoryFileSystem(asset_root);
-	}
-	else {
-		// try another root file-system as a fallback
-		asset_fs = new GenericFileSystem();
+		Directory *asset_root = root_fs->findDirectory(ss.str());
+		if (asset_root) {
+			asset_fs = new DirectoryFileSystem(asset_root);
+		}
 	}
 
 	return;

File src/core/wiesel/engine.cpp

View file
 		}
 	}
 
-	// try to find a valid application object
-	if (this->application == NULL) {
-		std::vector<ModuleLoader<Application>*> loaders = ModuleRegistry::getInstance()->findModules<Application>();
-		for(std::vector<ModuleLoader<Application>*>::iterator it=loaders.begin(); it!=loaders.end(); it++) {
-			Application *app = (*it)->create();
-			if (app) {
-				this->application = app;
-				this->application->retain();
-				this->application->onInit();
-			}
-		}
-
-		assert(application);
-		if (application == NULL) {
-			return false;
-		}
-	}
-
 	return true;
 }
 
 
 
 bool Engine::shutdown() {
-	// release the application object
-	if (application) {
-		application->onShutdown();
-		application->release();
-		application = NULL;
-	}
-
 	// release all platforms
 	for(std::vector<Platform*>::reverse_iterator it=platforms.rbegin(); it!=platforms.rend(); it++) {
 		Platform *platform = *it;
 
 
 void Engine::run() {
+	// try to find valid application objects
+	std::vector<ModuleLoader<Application>*> loaders = ModuleRegistry::getInstance()->findModules<Application>();
+	for(std::vector<ModuleLoader<Application>*>::iterator it=loaders.begin(); it!=loaders.end(); it++) {
+		Application *app = (*it)->create();
+
+		// run the main loop with each selected application
+		if (app) {
+			run(app);
+		}
+	}
+
+	return;
+}
+
+
+void Engine::run(Application *app) {
 	// check, if a platform object is available
 	assert(platforms.empty() == false);
 	if (platforms.empty()) {
 	}
 
 	// we need a valid application object to run
-	assert(application);
-	if (application == NULL) {
+	assert(app);
+	if (app == NULL) {
 		return;
 	}
 
+	// no other application should be active
+	assert(application == NULL);
+	if (application) {
+		return;
+	}
+
+	// initialize the application object
+	this->application = app;
+	this->application->retain();
+	this->application->onInit();
+
 	// reset the exit_requested flag before starting the main loop
 	exit_requested = false;
 
 	}
 
 	// timers
-	clock_t last_t = clock();
-	clock_t now_t;
+	clock_t now_t = clock();
+	clock_t last_t;
 
 	bool done = false;
 	do {
 	}
 	while(!done);
 
+	// release the application object
+	application->onShutdown();
+	application->release();
+	application = NULL;
+
 	return;
 }
 

File src/core/wiesel/engine.h