Esempio n. 1
0
int main(int argc, char **argv)
{
#ifdef ROCKET_PLATFORM_WIN32
        DoAllocConsole();
#endif

        int window_width = 1024;
        int window_height = 768;

	sf::RenderWindow MyWindow(sf::VideoMode(window_width, window_height), "libRocket with SFML");

	RocketSFMLRenderer Renderer;
	RocketSFMLSystemInterface SystemInterface;
	ShellFileInterface FileInterface("../Samples/assets/");

	if(!MyWindow.IsOpened())
		return 1;

	Renderer.SetWindow(&MyWindow);

	Rocket::Core::SetFileInterface(&FileInterface);
	Rocket::Core::SetRenderInterface(&Renderer);
	Rocket::Core::SetSystemInterface(&SystemInterface);

	if(!Rocket::Core::Initialise())
		return 1;

	Rocket::Core::FontDatabase::LoadFontFace("Delicious-Bold.otf");
	Rocket::Core::FontDatabase::LoadFontFace("Delicious-BoldItalic.otf");
	Rocket::Core::FontDatabase::LoadFontFace("Delicious-Italic.otf");
	Rocket::Core::FontDatabase::LoadFontFace("Delicious-Roman.otf");

	Rocket::Core::Context *Context = Rocket::Core::CreateContext("default",
		Rocket::Core::Vector2i(MyWindow.GetWidth(), MyWindow.GetHeight()));

	Rocket::Debugger::Initialise(Context);

	Rocket::Core::ElementDocument *Document = Context->LoadDocument("demo.rml");

	if(Document)
	{
		Document->Show();
		Document->RemoveReference();
	};

	while(MyWindow.IsOpened())
	{
		static sf::Event event;

		MyWindow.Clear();
		Context->Render();
		MyWindow.Display();

		while(MyWindow.GetEvent(event))
		{
			switch(event.Type)
			{
			case sf::Event::Resized:
				Renderer.Resize();
				break;
			case sf::Event::MouseMoved:
				Context->ProcessMouseMove(event.MouseMove.X, event.MouseMove.Y,
					SystemInterface.GetKeyModifiers(&MyWindow));
				break;
			case sf::Event::MouseButtonPressed:
				Context->ProcessMouseButtonDown(event.MouseButton.Button,
					SystemInterface.GetKeyModifiers(&MyWindow));
				break;
			case sf::Event::MouseButtonReleased:
				Context->ProcessMouseButtonUp(event.MouseButton.Button,
					SystemInterface.GetKeyModifiers(&MyWindow));
				break;
			case sf::Event::MouseWheelMoved:
				Context->ProcessMouseWheel(event.MouseWheel.Delta,
					SystemInterface.GetKeyModifiers(&MyWindow));
				break;
			case sf::Event::TextEntered:
				if (event.Text.Unicode > 32)
					Context->ProcessTextInput(event.Text.Unicode);
				break;
			case sf::Event::KeyPressed:
				Context->ProcessKeyDown(SystemInterface.TranslateKey(event.Key.Code),
					SystemInterface.GetKeyModifiers(&MyWindow));
				break;
			case sf::Event::KeyReleased:
				if(event.Key.Code == sf::Key::F8)
				{
					Rocket::Debugger::SetVisible(!Rocket::Debugger::IsVisible());
				};

				Context->ProcessKeyUp(SystemInterface.TranslateKey(event.Key.Code),
					SystemInterface.GetKeyModifiers(&MyWindow));
				break;
			case sf::Event::Closed:
				return 1;
				break;
			};
		};

		Context->Update();
	};

	return 0;
};
Esempio n. 2
0
int main(int, char**)
#endif
{
	#ifdef ROCKET_PLATFORM_MACOSX
	#define APP_PATH "../"
	#define ROCKET_PATH "../../bin/"
	#else
	#define APP_PATH "../Samples/pyinvaders/"
	#define ROCKET_PATH "."
	#endif

	#ifdef ROCKET_PLATFORM_WIN32
	DoAllocConsole();
	#endif

	// Generic OS initialisation, creates a window and attaches OpenGL.
	if (!Shell::Initialise("../Samples/pyinvaders/") ||
		!Shell::OpenWindow("Rocket Invaders from Mars (Python Powered)", true))
	{
		Shell::Shutdown();
		return -1;
	}

	// Rocket initialisation.
	ShellRenderInterfaceOpenGL opengl_renderer;
	Rocket::Core::SetRenderInterface(&opengl_renderer);

	ShellSystemInterface system_interface;
	Rocket::Core::SetSystemInterface(&system_interface);

	Rocket::Core::Initialise();
	// Initialise the Rocket Controls library.
	Rocket::Controls::Initialise();

	// Initialise the Python interface.
	PythonInterface::Initialise((Shell::GetExecutablePath() + (APP_PATH "python") + PATH_SEPARATOR + Shell::GetExecutablePath() + ROCKET_PATH).CString());

	// Create the main Rocket context and set it on the shell's input layer.
	context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
	if (context == NULL)
	{
		Rocket::Core::Shutdown();
		Shell::Shutdown();
		return -1;
	}

	Rocket::Debugger::Initialise(context);
	Input::SetContext(context);

	// Load the font faces required for Invaders.
	Shell::LoadFonts("../assets/");

	// Register Invader's custom decorator instancers.
	Rocket::Core::DecoratorInstancer* decorator_instancer = new DecoratorInstancerStarfield();
	Rocket::Core::Factory::RegisterDecoratorInstancer("starfield", decorator_instancer);
	decorator_instancer->RemoveReference();

	decorator_instancer = new DecoratorInstancerDefender();
	Rocket::Core::Factory::RegisterDecoratorInstancer("defender", decorator_instancer);
	decorator_instancer->RemoveReference();	

	// Construct the game singletons.
	HighScores::Initialise();

	// Fire off the startup script.
	PythonInterface::Import("autoexec");

	Shell::EventLoop(GameLoop);	

	// Shutdown the Rocket contexts.	
	context->RemoveReference();
	
	// Shutdown Python before we shut down Rocket.
	PythonInterface::Shutdown();

	// Shut down the game singletons.
	HighScores::Shutdown();

	// Shutdown Rocket.
	Rocket::Core::Shutdown();

	Shell::CloseWindow();
	Shell::Shutdown();

	return 0;
}
Esempio n. 3
0
int main(int ROCKET_UNUSED_PARAMETER(argc), char** ROCKET_UNUSED_PARAMETER(argv))
#endif
{
#ifdef ROCKET_PLATFORM_WIN32
	ROCKET_UNUSED(instance_handle);
	ROCKET_UNUSED(previous_instance_handle);
	ROCKET_UNUSED(command_line);
	ROCKET_UNUSED(command_show);
#else
	ROCKET_UNUSED(argc);
	ROCKET_UNUSED(argv);
#endif

#ifdef ROCKET_PLATFORM_LINUX
#define APP_PATH "../Samples/tutorial/datagrid_tree/"
#else
#define APP_PATH "../../Samples/tutorial/datagrid_tree/"
#endif

#ifdef ROCKET_PLATFORM_WIN32
        DoAllocConsole();
#endif

	int window_width = 1024;
	int window_height = 768;

	ShellRenderInterfaceOpenGL opengl_renderer;
	shell_renderer = &opengl_renderer;

	// Generic OS initialisation, creates a window and attaches OpenGL.
	if (!Shell::Initialise(APP_PATH) ||
		!Shell::OpenWindow("Datagrid Tree Tutorial", shell_renderer, window_width, window_height, true))
	{
		Shell::Shutdown();
		return -1;
	}

	// Rocket initialisation.
	Rocket::Core::SetRenderInterface(&opengl_renderer);
	opengl_renderer.SetViewport(window_width, window_height);

	ShellSystemInterface system_interface;
	Rocket::Core::SetSystemInterface(&system_interface);

	Rocket::Core::Initialise();
	Rocket::Controls::Initialise();

	// Create the main Rocket context and set it on the shell's input layer.
	context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window_width, window_height));
	if (context == NULL)
	{
		Rocket::Core::Shutdown();
		Shell::Shutdown();
		return -1;
	}

	Rocket::Debugger::Initialise(context);
	Input::SetContext(context);
	shell_renderer->SetContext(context);

	Shell::LoadFonts("../../assets/");

	// Load the defender decorator.
	Rocket::Core::DecoratorInstancer* decorator_instancer = Rocket::Core::Factory::RegisterDecoratorInstancer("defender", new DecoratorInstancerDefender());
	if (decorator_instancer != NULL)
		decorator_instancer->RemoveReference();

	// Add the ship formatter.
	HighScoresShipFormatter ship_formatter;

	// Construct the high scores.
	HighScores::Initialise();

	// Load and show the tutorial document.
	Rocket::Core::ElementDocument* document = context->LoadDocument("data/tutorial.rml");
	document->GetElementById("title")->SetInnerRML(document->GetTitle());
	if (document != NULL)
	{
		document->Show();
		document->RemoveReference();
	}

	Shell::EventLoop(GameLoop);

	// Shut down the high scores.
	HighScores::Shutdown();

	// Shutdown Rocket.
	context->RemoveReference();
	Rocket::Core::Shutdown();

	Shell::CloseWindow();
	Shell::Shutdown();

	return 0;
}
Esempio n. 4
0
int main(int, char**)
#endif
{
	#ifdef ROCKET_PLATFORM_MACOSX
	#define APP_PATH "../"
	#define ROCKET_PATH "../../bin/"
	#else
	#define APP_PATH "../Samples/luainvaders/"
	#define ROCKET_PATH "."
	#endif

	#ifdef ROCKET_PLATFORM_WIN32
	DoAllocConsole();
	#endif

	ShellRenderInterfaceOpenGL opengl_renderer;
	shell_renderer = &opengl_renderer;

	// Generic OS initialisation, creates a window and attaches OpenGL.
	if (!Shell::Initialise("../Samples/luainvaders/") ||
		!Shell::OpenWindow("Rocket Invaders from Mars (Lua Powered)", shell_renderer, 1024, 768, false))
	{
		Shell::Shutdown();
		return -1;
	}

	// Rocket initialisation.
	Rocket::Core::SetRenderInterface(&opengl_renderer);
	opengl_renderer.SetViewport(1024,768);

	ShellSystemInterface system_interface;
	Rocket::Core::SetSystemInterface(&system_interface);

	Rocket::Core::Initialise();
	// Initialise the Rocket Controls library.
	Rocket::Controls::Initialise();

	// Initialise the Lua interface
	Rocket::Core::Lua::Interpreter::Initialise();
	Rocket::Controls::Lua::RegisterTypes(Rocket::Core::Lua::Interpreter::GetLuaState());

	// Create the main Rocket context and set it on the shell's input layer.
	context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
	if (context == NULL)
	{
		Rocket::Core::Shutdown();
		Shell::Shutdown();
		return -1;
	}

	Rocket::Debugger::Initialise(context);
	Input::SetContext(context);
	shell_renderer->SetContext(context);

	// Load the font faces required for Invaders.
	Shell::LoadFonts("../assets/");

	// Register Invader's custom decorator instancers.
	Rocket::Core::DecoratorInstancer* decorator_instancer = new DecoratorInstancerStarfield();
	Rocket::Core::Factory::RegisterDecoratorInstancer("starfield", decorator_instancer);
	decorator_instancer->RemoveReference();

	decorator_instancer = new DecoratorInstancerDefender();
	Rocket::Core::Factory::RegisterDecoratorInstancer("defender", decorator_instancer);
	decorator_instancer->RemoveReference();	

	// Construct the game singletons.
	HighScores::Initialise();

	// Fire off the startup script.
    LuaInterface::Initialise(Rocket::Core::Lua::Interpreter::GetLuaState()); //the tables/functions defined in the samples
    Rocket::Core::Lua::Interpreter::LoadFile(Rocket::Core::String(APP_PATH).Append("lua/start.lua"));

	Shell::EventLoop(GameLoop);	

	// Shutdown the Rocket contexts.	
	context->RemoveReference();
	
	// Shutdown Lua  before we shut down Rocket.
	Rocket::Core::Lua::Interpreter::Shutdown();

	// Shut down the game singletons.
	HighScores::Shutdown();

	// Shutdown Rocket.
	Rocket::Core::Shutdown();

	Shell::CloseWindow();
	Shell::Shutdown();

	return 0;
}