First part of terrain scene node
[openstranded.git] / src / eal / engine.cc
blob6d17d02b8657152fb8bd16c93d11f44e08d778e9
1 /*
2 * Base class for graphics/sound
4 * Copyright (C) 2009 Mathias Gottschlag
6 * This file is part of OpenStranded
8 * OpenStranded is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * OpenStranded is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
22 #include "eal/engine.hh"
24 #include <irrlicht/irrlicht.h>
26 namespace eal
28 Engine*
29 Engine::get ()
31 static Engine engine;
32 return &engine;
35 Engine::Engine ()
37 irrlicht = 0;
38 lastfps = 0;
41 Engine::~Engine ()
43 if (irrlicht)
45 irrlicht->drop ();
49 bool
50 Engine::init ()
52 // Create window
53 irrlicht = irr::createDevice (irr::video::EDT_OPENGL,
54 irr::core::dimension2d<irr::s32>(1024, 768), 32);
56 irr::scene::ISceneManager* smgr = irrlicht->getSceneManager();
58 //irr::scene::ICameraSceneNode *camera = smgr->addCameraSceneNode ();
59 irr::scene::ICameraSceneNode *camera = smgr->addCameraSceneNodeFPS();
60 camera->setPosition(irr::core::vector3df(0, 30, 0));
61 camera->setTarget(irr::core::vector3df(0, 0, 0));
62 this->camera.create(camera);
63 return true;
66 GUI&
67 Engine::getGUI ()
69 return gui;
72 Camera&
73 Engine::getCamera ()
75 return camera;
78 Environment&
79 Engine::getEnvironment ()
81 return environment;
84 bool Engine::update ()
86 if (!irrlicht->run ())
87 return false;
89 irr::video::IVideoDriver *driver = irrlicht->getVideoDriver();
90 if (driver->getFPS () != lastfps)
92 lastfps = driver->getFPS ();
93 wchar_t caption[256];
94 swprintf (caption, 256, L"OpenStranded - FPS: %d", lastfps);
95 irrlicht->setWindowCaption (caption);
97 irr::scene::ISceneManager* smgr = irrlicht->getSceneManager();
98 // Render scene
99 driver->beginScene (true, true, irr::video::SColor (255, 100, 101, 140) );
100 smgr->drawAll ();
101 driver->endScene ();
102 return true;
105 irr::scene::ISceneManager*
106 Engine::getSceneManager()
108 if (!irrlicht) return 0;
109 return irrlicht->getSceneManager();