JNR
laSystemIntegrator.cpp
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 
30 //
31 // FILE: laSystemIntegrator.cpp
32 //
33 // Copyright (C) 2007-2013 Atanas Laskov, <latanas@gmail.com>
34 //
35 #include "stdafx.h"
36 #include "Core.h"
37 
38 laSystemIntegrator* laSystemIntegrator::_pIntegrator = NULL;
39 
40 laSystemIntegrator::laSystemIntegrator(void)
41 {
42  _pSettings = NULL;
43  _pEnvironment = NULL;
44  _pGame = NULL;
45  _pRenderer = NULL;
46  _pInput = NULL;
47  _pSound = NULL;
48 
49  if(laSystemIntegrator::_pIntegrator!=NULL)
50  {
51  laSystemIntegrator::_pIntegrator->getEnvironment()->message(M_FALSE, "An attempt to create mulitple laSystemIntegrator instances was made");
52  return;
53  }
54 
55  _pIntegrator = this;
56 }
57 
58 laSystemIntegrator::~laSystemIntegrator(void)
59 {
60  //this->discard();
61 }
62 
63 void laSystemIntegrator::createSettings(laSettings *p)
64 {
65  if(_pSettings!=NULL)
66  throw laError("An attempt was made to create multiple laSettings objects");
67 
68  _pSettings = p;
69  _pSettings->Load("ron.cfg");
70 }
71 
72 void laSystemIntegrator::createEnvironment(laEnvironment *p)
73 {
74  if(_pEnvironment!=NULL)
75  throw laError("An attempt was made to create multiple laEnvironment objects");
76 
77  _pEnvironment = p;
78  _pEnvironment->create();
79 }
80 
81 void laSystemIntegrator::createGame(laGame *p)
82 {
83  if(_pGame!=NULL)
84  throw laError("An attempt was made to create multiple laGame objects");
85 
86  _pGame = p;
87  _pGame->onInit();
88 }
89 
90 void laSystemIntegrator::createRenderer(laRenderer *p)
91 {
92  if(_pRenderer!=NULL)
93  throw laError("An attempt was made to create multiple laRenderer objects");
94 
95  _pRenderer = p;
96  _pRenderer->create();
97 }
98 
99 void laSystemIntegrator::createInput(laInputManager *p)
100 {
101  if(_pInput!=NULL)
102  throw laError("An attempt was made to create multiple laInputManager objects");
103 
104  _pInput = p;
105  _pInput->create();
106 }
107 
108 void laSystemIntegrator::createSound(laSoundManager *p)
109 {
110  if(_pSound!=NULL)
111  throw laError("An attempt was made to create multiple laSoundManager objects");
112 
113  _pSound = p;
114  _pSound->create();
115 }
116 
117 void laSystemIntegrator::discard()
118 {
119  _pEnvironment->message(M_TRUE, "laSystemIntegrator: Discarding game object...");
120  if(_pGame) _pGame->onFini();
121 
122  _pEnvironment->message(M_TRUE, "laSystemIntegrator: Discarding renderer...");
123  if(_pRenderer) _pRenderer->discard();
124 
125  //if(_pInput) _pInput->discard();
126 
127  //if(_pSound) _pSound->discard();
128 
129  //if(_pSettings) _pSettings->discard();
130 
131  //if(_pEnvironment) _pEnvironment->discard();
132 
133  _pEnvironment->message(M_TRUE, "laSystemIntegrator: All subsystems discarded.");
134 }
Collection of laStage objects.
Definition: laGame.h:47
virtual void message(M_BOOL bSilent, const char *strText,...)=0
Display message box.
virtual void create()=0
Create OS environment.
Game Settings.
Definition: laSettings.h:38
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
Engine Sub-systems Integrator.
Error handling class.
Definition: laError.h:46
Engine abstract OS environment.
Definition: laEnvironment.h:50