Shared data

Ethanon engine provides an easy way to share data across the gameplay script code and the platform-specific side (Java on Android and Objective-C on iOS). The Shared Data System is a map of strings that allows quick read/write access to string-based data that are safely and statically shared across these layers of code.

iOS, Windows and OS X (C++)

On platforms that are essentially based on native code, therefore use the C++ language, shared data is accessible trough the SharedDataManager object, statically declared in the ethanon/toolkit/Source/src/gs2d/src/Application.h header file:

// writing/creating custom data:
gs2d::Application::SharedData.Set(GS_L("com.mygame.playerName"), GS_L("Bob"));

// getting custom data values
gs2d::str_type::string playerName = gs2d::Application::SharedData.Get(GS_L("com.mygame.playerName"));

AngelScript

The following functions provide reading and writing functionalities to the script side:

bool SetSharedData(string key, string value)
bool IsSharedDataConstant(string key)
string GetSharedData(string key)
bool SharedDataExists(string key)
bool RemoveSharedData(string key)

Android

Shared data is accessible on the Java side through the following JNI interface:

package net.asantee.gs2d;

public class GS2DJNI {
	. . .
	// shared data method bindings
	public static native String getSharedData(String key);
	public static native void setSharedData(String key, String value);
	public static native void createConstSharedData(String key, String value);
}

Remarks

Shared data persists as long as the instance of the game application is running, and can be accessed at any time. The SharedDataManager behaves as a singleton for the entire application, which means that all interfaces that provide access to it share the exact same data source. Some data are marked as constant and cannot be written after created.