Castle Battle  1.0
Public Member Functions | Private Attributes | List of all members
Application Class Reference

Application will set up Launcher screen, and start the loop through GameManager. More...

#include <Application.h>

Public Member Functions

 Application ()
 Names. More...
 
bool loop ()
 Main loop of the application. More...
 
void createWorldEnviroment ()
 Create physics and graphics scene. More...
 
bool init ()
 Start the launcher screen, and will wait the start button click event. More...
 
bool end ()
 Last stage of application. More...
 

Private Attributes

IrrlichtDevice * device
 Irrlicht device instance. More...
 
video::IVideoDriver * driver
 Irrlicht video instance. More...
 
scene::ISceneManager * smgr
 Irrlicht scene manager instance. More...
 
Physicsphysics
 Physics instance. More...
 
GameManagergameManager
 GameManager instance. More...
 
gui::IGUIEnvironment * gui
 Gui enviroment to build gui objects. More...
 
Terrainterrain
 Terrain of the world. More...
 
Launcherscreen
 GUI handler. More...
 

Detailed Description

Application will set up Launcher screen, and start the loop through GameManager.

In particular this class will init Irrlicht world and will add physics provided by Physics. Also it will show and handle the first launcher screen.

Constructor & Destructor Documentation

◆ Application()

Application::Application ( )

Names.

Default constructor. Given the video driver from command line, the constructor will start all instances, initialize logger, start launcher and create world

11  {
12  // ask user for driver
13  video::E_DRIVER_TYPE driverType = driverChoiceConsole();
14  if (driverType==video::EDT_COUNT)
15  exit (EXIT_FAILURE);
16 
17  this->device = createDevice(driverType, core::dimension2d<u32>(800,600), 16, false, false, false, 0);
18  this->device->getLogger()->setLogLevel(ELL_NONE);
19  #if (DEBUG_OUTPUT_MASK & 2)
20  // this->device->getLogger()->setLogLevel(ELL_DEBUG);
21  #endif
22  this->driver = this->device->getVideoDriver();
23  this->driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
24  this->smgr = this->device->getSceneManager();
25  this->smgr->setAmbientLight(video::SColor(0,255,255,204));
26  log(INFO,1,"Turn on lights");
27  this->gui = this->device->getGUIEnvironment();
28  this->createWorldEnviroment();
29 }
Definition: Logger.h:50
IrrlichtDevice * device
Irrlicht device instance.
Definition: Application.h:17
void createWorldEnviroment()
Create physics and graphics scene.
Definition: Application.cpp:30
#define log(tag, level, _Message)
Uncomment if you dont want to use the Makefile dynamic definition of MASK.
Definition: Logger.h:26
scene::ISceneManager * smgr
Irrlicht scene manager instance.
Definition: Application.h:23
gui::IGUIEnvironment * gui
Gui enviroment to build gui objects.
Definition: Application.h:32
video::IVideoDriver * driver
Irrlicht video instance.
Definition: Application.h:20

Member Function Documentation

◆ createWorldEnviroment()

void Application::createWorldEnviroment ( )

Create physics and graphics scene.

30  {
31  core::stringw pathTexture[2] = {"media/terrain/grass_green_old.jpg","media/terrain/grass_green_thin.jpg"};
32  this->terrain = new Terrain(smgr,driver,pathTexture,core::vector3df(250.f,0.0001f, 250.f));
33  Sky(smgr,driver,"media/terrain/sky.jpg",1000.0f);
34  log1("World created");
35  this->physics = new Physics(terrain->getTerrainBox());
36  log(INFO,1,"Law of physics successfully created");
37 }
Definition: Logger.h:50
#define log(tag, level, _Message)
Uncomment if you dont want to use the Makefile dynamic definition of MASK.
Definition: Logger.h:26
Physics * physics
Physics instance.
Definition: Application.h:26
scene::ISceneManager * smgr
Irrlicht scene manager instance.
Definition: Application.h:23
Terrain * terrain
Terrain of the world.
Definition: Application.h:35
video::IVideoDriver * driver
Irrlicht video instance.
Definition: Application.h:20
Physics class will handle all things related to collisions, creating Bullet physics objects and the p...
Definition: physics.h:12
#define log1(_Message)
Log message of 1 level verbosity.
Definition: Logger.h:28
Terrain of the world.
Definition: Terrain.h:5
Sky of the world.
Definition: Sky.h:7
core::aabbox3df getTerrainBox()
Get bounding box of the terrain.
Definition: Terrain.cpp:62

◆ end()

bool Application::end ( )

Last stage of application.

Show end screen

Free memory


From Irrlicht docs:. This method can free a lot of memory! Please note that after calling this, the pointer to the ITexture may no longer be valid, if it was not grabbed before by other parts of the engine for storing it longer. So it is a good idea to set all materials which are using this texture to 0 or another texture first.

Clear every scene node
Remove bullet memory

68  {
69  this->screen->endScreen(this->gameManager->getNames(), this->gameManager->getWinner());
70  driver->beginScene(true, true, video::SColor(255,200,200,200));
71  this->gui->drawAll();
72  driver->endScene();
73  // while(device->run() && driver){
74  // if (device->isWindowActive()){
75  // }
76  // break;
77  // }
86  this->driver->removeAllTextures();
88  this->smgr->clear();
90  delete this->physics;
91  int exit;
92  std::cout<<"Memory liberated"<<std::endl;
93  std::cout<<"Press something to close game"<<std::endl;
94  std::cin>>exit;
95  this->gui->clear();
96  return 0;
97 }
void endScreen(core::stringw *names, int winner)
Show winner screen.
Definition: launcher.cpp:45
Physics * physics
Physics instance.
Definition: Application.h:26
core::stringw * getNames()
Get player names.
Definition: gamemanager.cpp:67
scene::ISceneManager * smgr
Irrlicht scene manager instance.
Definition: Application.h:23
gui::IGUIEnvironment * gui
Gui enviroment to build gui objects.
Definition: Application.h:32
video::IVideoDriver * driver
Irrlicht video instance.
Definition: Application.h:20
Launcher * screen
GUI handler.
Definition: Application.h:38
int getWinner()
Get the winner.
Definition: gamemanager.cpp:64
GameManager * gameManager
GameManager instance.
Definition: Application.h:29

◆ init()

bool Application::init ( )

Start the launcher screen, and will wait the start button click event.

38  {
39  this->screen = new Launcher(this->gui, this->device);
40  assert(screen != 0);
41  while(device->run() && driver){
42  if (device->isWindowActive()){
43  driver->beginScene(true, true, video::SColor(255,200,200,200));
44  this->gui->drawAll();
45  assert(screen->listener != 0);
47  break;
49  }
50  driver->endScene();
51  }
52  }
53  if(!driver) return false;
54  // this->names = new core::stringw[2];
55  core::stringw* names = new core::stringw[2];
56  names[0] = (screen->players[0]->getText());
57  names[1] = (screen->players[1]->getText());
58  screen->clear();
60  #if (DEBUG_OUTPUT_MASK & 2)
61  this->smgr->addCameraSceneNodeFPS(0,100.f,0.04f)->setPosition(terrain->getCenter());
62  #endif
63 
64  this->device->getCursorControl()->setVisible(false);
65  log1("Gameplay initialized.");
66  return true;
67 }
IrrlichtDevice * device
Irrlicht device instance.
Definition: Application.h:17
Physics * physics
Physics instance.
Definition: Application.h:26
scene::ISceneManager * smgr
Irrlicht scene manager instance.
Definition: Application.h:23
Terrain * terrain
Terrain of the world.
Definition: Application.h:35
gui::IGUIEnvironment * gui
Gui enviroment to build gui objects.
Definition: Application.h:32
Definition: launcher.h:10
video::IVideoDriver * driver
Irrlicht video instance.
Definition: Application.h:20
#define log1(_Message)
Log message of 1 level verbosity.
Definition: Logger.h:28
void clear()
Clear all gui objects.
Definition: launcher.cpp:54
LauncherEventReceiver * listener
GUI event listener.
Definition: launcher.h:40
core::vector3df getCenter()
Get center of the terrain.
Definition: Terrain.cpp:34
Launcher * screen
GUI handler.
Definition: Application.h:38
GameManager is the main manager of the gameplay.
Definition: gamemanager.h:11
bool stateElement[3]
Number of elements to listen events.
Definition: launcher.h:17
Launcher start screen.
Definition: launcher.h:25
GameManager * gameManager
GameManager instance.
Definition: Application.h:29
gui::IGUIEditBox * players[2]
Player names.
Definition: launcher.h:35

◆ loop()

bool Application::loop ( )

Main loop of the application.

Returns
true if someone win with a printed message on command line, false if something went wrong
98  {
99  u32 TimeStamp = device->getTimer()->getTime(), DeltaTime = 0;
100  u32 lastFPS = 0;
101  bool flagWin = false;
102  while(device->run() && device) {
103 
104  // if(device->isWindowActive()){
105  u32 fps = driver->getFPS();
106  DeltaTime = device->getTimer()->getTime() - TimeStamp;
107  physics->UpdatePhysics(DeltaTime,fps);
108  driver->beginScene(true, true, video::SColor(255,200,200,200));
109 
110  smgr->drawAll();
111  if(gameManager->loop()){
112  flagWin = true;
113  break;
114  }
115  driver->endScene();
116 
117  TimeStamp = device->getTimer()->getTime();
118 
119  if(lastFPS != fps)
120  {
121  core::stringw str =L"Castle Battle [";
122  str += driver->getName();
123  str += "] FPS:";
124  str += fps;
125  device->setWindowCaption(str.c_str());
126  lastFPS = fps;
127  }
128  }
129  if(flagWin) {
130  std::cout<<"Thanks for playing. Goodbye!"<<std::endl;
131  this->end();
132  }
133  return 1;
134 
135 }
IrrlichtDevice * device
Irrlicht device instance.
Definition: Application.h:17
Physics * physics
Physics instance.
Definition: Application.h:26
scene::ISceneManager * smgr
Irrlicht scene manager instance.
Definition: Application.h:23
video::IVideoDriver * driver
Irrlicht video instance.
Definition: Application.h:20
bool loop()
Main Gameplay loop.
Definition: gamemanager.cpp:70
void UpdatePhysics(u32 delta, u32 fps)
World step simulation.
Definition: physics.cpp:50
bool end()
Last stage of application.
Definition: Application.cpp:68
GameManager * gameManager
GameManager instance.
Definition: Application.h:29

Member Data Documentation

◆ device

IrrlichtDevice* Application::device
private

Irrlicht device instance.

◆ driver

video::IVideoDriver* Application::driver
private

Irrlicht video instance.

◆ gameManager

GameManager* Application::gameManager
private

GameManager instance.

◆ gui

gui::IGUIEnvironment* Application::gui
private

Gui enviroment to build gui objects.

◆ physics

Physics* Application::physics
private

Physics instance.

◆ screen

Launcher* Application::screen
private

GUI handler.

◆ smgr

scene::ISceneManager* Application::smgr
private

Irrlicht scene manager instance.

◆ terrain

Terrain* Application::terrain
private

Terrain of the world.


The documentation for this class was generated from the following files: