Example #1
0
int kore(int argc, char** argv) {
	Kore::log(Kore::Info, "Starting Kore");

	int width;
	int height;
	bool fullscreen = false;
	std::string name;
	
	{
		Kore::log(Kore::Info, "Reading project.kha");
		Kore::FileReader file("project.kha");
		int filesize = file.size();
		char* string = new char[filesize + 1];
		char* data = (char*)file.readAll();
		for (int i = 0; i < filesize; ++i) string[i] = data[i];
		string[filesize] = 0;
		Json::Data json(string);
		Json::Value& game = json["game"];
		name = game["name"].string();
		width = game["width"].number();
		height = game["height"].number();
		if (game.has("fullscreen")) fullscreen = game["fullscreen"].boolean();
		delete string;
	}

	Kore::Application* app = new Kore::Application(argc, argv, width, height, fullscreen, name.c_str());
	Kore::Mixer::init();
	Kore::Audio::init();
	Kore::Graphics::setRenderState(Kore::DepthTest, false);
	app->foregroundCallback = foreground;
	app->resumeCallback = resume;
	app->pauseCallback = pause;
	app->backgroundCallback = background;
	app->shutdownCallback = shutdown;
	app->setCallback(update);
	
	Kore::log(Kore::Info, "Initializing Haxe libraries");
	hxcpp_set_top_of_stack();

	const char* err = hxRunLibrary();
	if (err) {
		fprintf(stderr, "Error %s\n", err);
		return 1;
	}

	Kore::Keyboard::the()->KeyDown = keyDown;
	Kore::Keyboard::the()->KeyUp = keyUp;
	Kore::Mouse::the()->Press = mouseDown;
	Kore::Mouse::the()->Release = mouseUp;
	Kore::Mouse::the()->Move = mouseMove;
	Kore::Gamepad::get(0)->Axis = gamepadAxis;
	Kore::Gamepad::get(0)->Button = gamepadButton;
	Kore::Surface::the()->TouchStart = touchStart;
	Kore::Surface::the()->TouchEnd = touchEnd;
	Kore::Surface::the()->Move = touchMove;
	Kore::Sensor::the(Kore::SensorAccelerometer)->Changed = accelerometerChanged;
	Kore::Sensor::the(Kore::SensorGyroscope)->Changed = gyroscopeChanged;

	Kore::log(Kore::Info, "Starting application");
#ifdef SYS_IOS
	::kha::Sys_obj::screenRotation = ::kha::ScreenRotation_obj::Rotation270;
#endif
	app->start();
	Kore::log(Kore::Info, "Application stopped");

	return 0;
}
Example #2
0
int kore(int argc, char** argv) {
	Kore::log(Kore::Info, "Starting Kore");

	int width = 256;
	int height = 256;
	bool fullscreen = false;
	int antialiasing = 1;
	char name[256];
	name[0] = 0;
	
	{
		Kore::log(Kore::Info, "Reading project.kha");
		Kore::FileReader file("project.kha");
		int filesize = file.size();
		char* string = new char[filesize + 1];
		char* data = (char*)file.readAll();
		for (int i = 0; i < filesize; ++i) string[i] = data[i];
		string[filesize] = 0;

		jsmn_parser parser;
		jsmn_init(&parser);
		int size = jsmn_parse(&parser, string, filesize, nullptr, 0);
		jsmntok_t* tokens = new jsmntok_t[size];
		jsmn_init(&parser);
		size = jsmn_parse(&parser, string, filesize, tokens, size);

		for (int i = 0; i < size; ++i) {
			if (tokens[i].type == JSMN_STRING && strncmp("game", &string[tokens[i].start], tokens[i].end - tokens[i].start) == 0) {
				++i;
				int gamesize = tokens[i].size * 2;
				++i;
				int gamestart = i;
				for (; i < gamestart + gamesize; ++i) {
					if (tokens[i].type == JSMN_STRING && strncmp("name", &string[tokens[i].start], tokens[i].end - tokens[i].start) == 0) {
						++i;
						int ni = 0;
						for (int i2 = tokens[i].start; i2 < tokens[i].end; ++i2) {
							name[ni] = string[i2];
							++ni;
						}
						name[ni] = 0;
					}
					else if (tokens[i].type == JSMN_STRING && strncmp("width", &string[tokens[i].start], tokens[i].end - tokens[i].start) == 0) {
						++i;
						char number[25];
						int ni = 0;
						for (int i2 = tokens[i].start; i2 < tokens[i].end; ++i2) {
							number[ni] = string[i2];
							++ni;
						}
						number[ni] = 0;
						width = atoi(number);
					}
					else if (tokens[i].type == JSMN_STRING && strncmp("height", &string[tokens[i].start], tokens[i].end - tokens[i].start) == 0) {
						++i;
						char number[25];
						int ni = 0;
						for (int i2 = tokens[i].start; i2 < tokens[i].end; ++i2) {
							number[ni] = string[i2];
							++ni;
						}
						number[ni] = 0;
						height = atoi(number);
					}
					else if (tokens[i].type == JSMN_STRING && strncmp("antiAliasingSamples", &string[tokens[i].start], tokens[i].end - tokens[i].start) == 0) {
						++i;
						char number[25];
						int ni = 0;
						for (int i2 = tokens[i].start; i2 < tokens[i].end; ++i2) {
							number[ni] = string[i2];
							++ni;
						}
						number[ni] = 0;
						antialiasing = atoi(number);
					}
					else if (tokens[i].type == JSMN_STRING && strncmp("fullscreen", &string[tokens[i].start], tokens[i].end - tokens[i].start) == 0) {
						++i;
						fullscreen = strncmp("true", &string[tokens[i].start], tokens[i].end - tokens[i].start) == 0;
					}
				}

				break;
			}
		}
		
		delete[] tokens;
		delete string;
	}

	Kore::Application* app = new Kore::Application(argc, argv, width, height, fullscreen, name);
	//Kore::Mixer::init();
	mutex.Create();
	Kore::Audio::audioCallback = mix;
	Kore::Audio::init();
#ifndef VR_RIFT
	Kore::Graphics::setRenderState(Kore::DepthTest, false);
#endif
	app->orientationCallback = orientation;
	app->foregroundCallback = foreground;
	app->resumeCallback = resume;
	app->pauseCallback = pause;
	app->backgroundCallback = background;
	app->shutdownCallback = shutdown;
	app->setCallback(update);
	
	Kore::log(Kore::Info, "Initializing Haxe libraries");
	hxcpp_set_top_of_stack();

	const char* err = hxRunLibrary();
	if (err) {
		fprintf(stderr, "Error %s\n", err);
		return 1;
	}

	Kore::Keyboard::the()->KeyDown = keyDown;
	Kore::Keyboard::the()->KeyUp = keyUp;
	Kore::Mouse::the()->Press = mouseDown;
	Kore::Mouse::the()->Release = mouseUp;
	Kore::Mouse::the()->Move = mouseMove;
	Kore::Gamepad::get(0)->Axis = gamepadAxis;
	Kore::Gamepad::get(0)->Button = gamepadButton;
	Kore::Surface::the()->TouchStart = touchStart;
	Kore::Surface::the()->TouchEnd = touchEnd;
	Kore::Surface::the()->Move = touchMove;
	Kore::Sensor::the(Kore::SensorAccelerometer)->Changed = accelerometerChanged;
	Kore::Sensor::the(Kore::SensorGyroscope)->Changed = gyroscopeChanged;


#ifdef VR_GEAR_VR
	// Enter VR mode
	Kore::VrInterface::Initialize();
#endif

	Kore::log(Kore::Info, "Starting application");
	app->start();
	Kore::log(Kore::Info, "Application stopped");

	return 0;
}