Exemplo n.º 1
0
void MLevel::changeCurrentScene(unsigned int id)
{
	if(id == m_currentSceneId)
		return;

	MEngine * engine = MEngine::getInstance();

	if(id < getScenesNumber())
	{
		MScene * scene = getCurrentScene();

		// onEndScene
		MGame * game = engine->getGame();
		if(game)
			game->onEndScene();

		// change scene
		setCurrentSceneId(id);
		scene = getCurrentScene();

		// onBeginScene
		if(game)
			game->onBeginScene();
	}	
}
Exemplo n.º 2
0
void MaratisPlayer::graphicLoop(void)
{
	MWindow * window = MWindow::getInstance();
	MEngine * engine = MEngine::getInstance();
	MRenderingContext * render = engine->getRenderingContext();

	// game
	MGame * game = engine->getGame();
	if(game)
	{
		if(game->isRunning())
		{
			render->disableScissorTest();
			render->setViewport(0, 0, window->getWidth(), window->getHeight());
			game->draw();
		}
		else
		{
			render->clear(M_BUFFER_COLOR);
		}
	}
	else
	{
		render->clear(M_BUFFER_COLOR);
	}
}
Exemplo n.º 3
0
void MaratisPlayer::logicLoop(void)
{
	MEngine * engine = MEngine::getInstance();

	// game
	MGame * game = engine->getGame();
	if(game)
	{
		if(game->isRunning()){
			game->update();
		}
	}
}
Exemplo n.º 4
0
void update(void)
{
	MEngine * engine = MEngine::getInstance();
	MGame * game = engine->getGame();

	if(game)
	{
		if(game->isRunning())
		{
			game->update();
		}
	}
}
Exemplo n.º 5
0
// window events
void windowEvents(MWinEvent * windowEvents)
{
	MEngine * engine = MEngine::getInstance();

	// game
	MGame * game = engine->getGame();
	if(game)
	{
		if(game->isRunning()){
			gameWinEvents(windowEvents);
		}
	}

	if(windowEvents->type == MWIN_EVENT_KEY_DOWN && windowEvents->data[0] == MKEY_ESCAPE){
		MWindow::getInstance()->setActive(false);
	}

	if(windowEvents->type == MWIN_EVENT_WINDOW_CLOSE){
		MWindow::getInstance()->setActive(false);
	}
}
Exemplo n.º 6
0
void draw(void)
{
	MWindow * window = MWindow::getInstance();
	MEngine * engine = MEngine::getInstance();
	MRenderingContext * render = engine->getRenderingContext();
	MGame * game = engine->getGame();

	// set basic viewport
	render->disableScissorTest();
	render->setViewport(0, 0, window->getWidth(), window->getHeight());

	if(game)
	{
		if(game->isRunning())
		{
			game->draw();
		}
	}

	window->swapBuffer();
}
Exemplo n.º 7
0
// main
int main(int argc, char **argv)
{
	setlocale(LC_NUMERIC, "C");


	// get engine (first time call onstructor)
	MEngine * engine = MEngine::getInstance();

	// get window (first time call onstructor)
	MWindow * window = MWindow::getInstance();

	// create window
	window->create("Maratis", 1024,768, 32, false);

	// set current directory
	char rep[256];
	getRepertory(rep, argv[0]);
	window->setCurrentDirectory(rep);

	// get Maratis (first time call onstructor)
	Maratis * maratis = Maratis::getInstance();
	MRenderingContext * render = engine->getRenderingContext();

	// init gui
	MGui * gui = MGui::getInstance();
	gui->setRenderingContext(render);
	gui->addFont(new MGuiTextureFont("font/default.tga"));

	// init MaratisUI
	window->setPointerEvent(MaratisUI::windowEvents);

	// logo
	{
		MImage image;
		if(! M_loadImage("gui/Title.png", &image))
			return 0;

		render->createTexture(&logoTextureId);
		render->bindTexture(logoTextureId);
		render->sendTextureImage(&image, false, false, false);

		// clear window
		draw();

		MGuiText text("LOADING", MVector2(480, 280), 16, MVector4(1, 1, 1, 1));
		text.draw();

		window->swapBuffer();
	}

	// load project
	if(argc > 1)
    {
		maratis->loadProject(argv[1]);
	}

	// time
	unsigned int frequency = 60;
	unsigned long previousFrame = 0;
	unsigned long startTick = window->getSystemTick();

	int f = 0;
	int t = 0;
	
	
	// on events
	while(window->isActive())
	{
		// on events
		if(window->onEvents())
		{
			// compute target tick
			unsigned long currentTick = window->getSystemTick();

			unsigned long tick = currentTick - startTick;
			unsigned long frame = (unsigned long)(tick * (frequency * 0.001f));

			// update elapsed time
			unsigned int i;
			unsigned int steps = (unsigned int)(frame - previousFrame);

			if(window->getFocus())
			{
				// don't wait too much
				if(steps >= (frequency/2))
				{
					update();
					draw();
					previousFrame += steps;
					continue;
				}
				
				// update
				for(i=0; i<steps; i++)
				{
					update();
					previousFrame++;
					t++;
					if(t == frequency)
					{
						MGame * game = engine->getGame();
						if(game)
						{
							if(! game->isRunning())
								MFilesUpdate::update();
						}
						else
						{
							MFilesUpdate::update();
						}

						//printf("fps:%d\n", f);
						t = 0;
						f = 0;
					}
				}

				// draw
				//if(steps > 0)
				{
					draw();
					f++;
				}
			}
			else
			{
				previousFrame = frame;
				window->swapBuffer();
			}
		}
	}

	gui->clear();
	maratis->clear();
	return 0;
}