added missing files
[ltanks.git] / mainApp.cc
blob29db1fb75eff284995882a9942edbd46b97a6563
1 #include "mainApp.h"
3 MainApp::MainApp() {
6 MainApp::~MainApp() {
7 destroy();
10 bool MainApp::init(const std::string &title, int w, int h, bool fs) {
11 root = new Root("plugins.cfg","");
13 LogManager::getSingleton().setLogDetail(LL_BOREME);
15 if (!createRenderSystem())
16 return false;
18 root->initialise(false);
20 createRenderWindow(title,w,h,fs);
22 WindowEventUtilities::addWindowEventListener(win,this);
24 createResources();
26 game = new Game();
27 game->init(root,win);
29 return true;
32 void MainApp::destroy() {
33 if (game)
34 delete game;
35 game = NULL;
37 if (root)
38 delete root;
39 root = NULL;
42 void MainApp::run() {
43 unsigned long tLast = 0;
45 while (game->isRunning()) {
46 unsigned long tNow = root->getTimer()->getMilliseconds();
47 unsigned long tDelta = tNow - tLast;
48 tLast = tNow;
50 WindowEventUtilities::messagePump();
52 game->capture();
53 game->update(tDelta);
55 root->renderOneFrame();
59 bool MainApp::createRenderSystem() {
60 RenderSystemList *rSyses = root->getAvailableRenderers();
61 RenderSystemList::iterator it = rSyses->begin();
62 while (it != rSyses->end()) {
63 if ((rSys = *(it++))->getName() == "OpenGL Rendering Subsystem") {
64 root->setRenderSystem(rSys);
65 break;
69 if (root->getRenderSystem() == NULL) {
70 std::cerr << "Chyba: Nelze nastavit rendering subsystem\n";
71 return false;
74 return true;
77 void MainApp::createRenderWindow(const std::string &title, int w, int h, bool fs) {
78 NameValuePairList winAttrs;
79 winAttrs["title"] = title;
80 win = root->createRenderWindow("MainWin",w,h,fs,&winAttrs);
83 void MainApp::createResources() {
84 ResourceGroupManager *rgm = ResourceGroupManager::getSingletonPtr();
85 rgm->addResourceLocation("data","FileSystem","General");
86 rgm->addResourceLocation("data/fonts","FileSystem","General");
87 rgm->initialiseAllResourceGroups();
91 void MainApp::windowResized(RenderWindow *rw) {
92 unsigned int w,h,d;
93 int t,l;
94 rw->getMetrics(w,h,d,t,l);
95 game->setWinSize(w,h);
98 void MainApp::windowClosed(RenderWindow *rw) {
99 game->quit();