started adding bullets physics
[ltanks.git] / mainApp.cc
blob09c1bbaf19a34efefd48dacd90b82f777982e11d
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);
19 createRenderWindow(title,w,h,fs);
20 WindowEventUtilities::addWindowEventListener(win,this);
21 createResources();
23 game = new Game();
24 game->init(root,win);
26 return true;
29 void MainApp::destroy() {
30 if (game)
31 delete game;
32 game = NULL;
34 if (root)
35 delete root;
36 root = NULL;
39 void MainApp::run() {
40 unsigned long tLast = 0;
42 while (game->isRunning()) {
43 unsigned long tNow = root->getTimer()->getMilliseconds();
44 unsigned long tDelta = tNow - tLast;
45 tLast = tNow;
47 WindowEventUtilities::messagePump();
49 game->capture();
50 game->update(tDelta/1000.0f);
52 root->renderOneFrame();
56 bool MainApp::createRenderSystem() {
57 RenderSystemList *rSyses = root->getAvailableRenderers();
58 RenderSystemList::iterator it = rSyses->begin();
59 while (it != rSyses->end()) {
60 if ((rSys = *(it++))->getName() == "OpenGL Rendering Subsystem") {
61 root->setRenderSystem(rSys);
62 break;
66 if (root->getRenderSystem() == NULL) {
67 std::cerr << "Chyba: Nelze nastavit rendering subsystem\n";
68 return false;
71 return true;
74 void MainApp::createRenderWindow(const std::string &title, int w, int h, bool fs) {
75 NameValuePairList winAttrs;
76 winAttrs["title"] = title;
77 win = root->createRenderWindow("MainWin",w,h,fs,&winAttrs);
80 void MainApp::createResources() {
81 ResourceGroupManager *rgm = ResourceGroupManager::getSingletonPtr();
82 rgm->addResourceLocation("data","FileSystem","General");
83 rgm->addResourceLocation("data/fonts","FileSystem","General");
84 rgm->initialiseAllResourceGroups();
87 void MainApp::windowResized(RenderWindow *rw) {
88 unsigned int w,h,d;
89 int t,l;
90 rw->getMetrics(w,h,d,t,l);
91 game->setWinSize(w,h);
94 void MainApp::windowClosed(RenderWindow *rw) {
95 game->quit();