#include "Wumbo-Program.h"
#include "Wumbo-Scene.h"
#if PLATFORM_IOS
#include "Wumbo-iOSRoot.h"
#endif
namespace Wumbo
{
	Program::Program()
	{
		scene = NULL;
		newScene = NULL;
		renderer = NULL;
		inputManager = NULL;
		assignedFrameRate = 30;
#if PLATFORM_PC
		sfmlwindow = NULL;
#endif
	}
	void Program::begin()
	{
		printf("Program::begin() -- This method must be overridden by a child class.\n");
	}
	void Program::end()
	{
		printf("Program::end() -- This method must be overridden by a child class.\n");
	}
	void Program::update()
	{
		if (newScene != NULL)
		{
			printf("FUCK");
			if (scene != NULL)
				scene->end();
			delete scene;
			newScene->begin();
			//newScene->update();
			scene = newScene;
		}
		else
			printf("DAMNIT");
		newScene = NULL;
		scene->update();
	}
	void Program::render()
	{
		scene->render();
	}
	Scene *Program::getScene()
	{
		return scene;
	}
	void Program::setScene(Scene *scn)
	{
		newScene = scn;
	}
	Renderer *Program::getRenderer()
	{
		return renderer;
	}
	void Program::setRenderer(Renderer *rend)
	{
		renderer = rend;
	}
	InputManager *Program::getInputManager()
	{
		return inputManager;
	}
	void Program::setInputManager(InputManager *inputman)
	{
		inputManager = inputman;
	}

	void Program::setAssignedFrameRate(int num)
	{
		assignedFrameRate = num;
#if PLATFORM_PC
		sfmlwindow->setFramerateLimit(num);
#elif PLATFORM_IOS
		((GLKViewController*)glkcontroller).preferredFramesPerSecond = num;
#endif
	}
	int Program::getAssignedFrameRate()
	{
		return assignedFrameRate;
	}

#if PLATFORM_PC
	void Program::setSFMLWindow(sf::RenderWindow *window)
	{
		sfmlwindow = window;
	}

	sf::RenderWindow *Program::getSFMLWindow()
	{
		return sfmlwindow;
	}
#elif PLATFORM_IOS
	void Program::setGLKViewController(id controller)
	{
		glkcontroller = controller;
	}
	id Program::getGLKViewController()
	{
		return glkcontroller;
	}
	void Program::setAppDelegate(id delegate)
	{
		appdelegate = delegate;
	}
	id Program::getAppDelegate()
	{
		return appdelegate;
	}
	void Program::addSupportedOrientation(UIDeviceOrientation orient)
	{
		[((ViewController*) glkcontroller) addSupportedOrientation:orient];
	}
	void Program::removeSupportedOrientation(UIDeviceOrientation orient)
	{
		[((ViewController*) glkcontroller) removeSupportedOrientation:orient];
	}
#endif
};