1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * |
---|
4 | * |
---|
5 | * License notice: |
---|
6 | * |
---|
7 | * This program is free software: you can redistribute it and/or modify |
---|
8 | * it under the terms of the GNU General Public License as published by |
---|
9 | * the Free Software Foundation, either version 3 of the License, or |
---|
10 | * (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | * |
---|
20 | * |
---|
21 | * Author: |
---|
22 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
23 | * Co-authors: |
---|
24 | * ... |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | #include <Ogre.h> |
---|
29 | #include <OIS/OIS.h> |
---|
30 | #include <CEGUI/CEGUI.h> |
---|
31 | #include <OgreCEGUIRenderer.h> |
---|
32 | |
---|
33 | #include "BaseObject.h" |
---|
34 | #include "Test.h" |
---|
35 | |
---|
36 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
37 | #include <CoreFoundation/CoreFoundation.h> |
---|
38 | |
---|
39 | // This function will locate the path to our application on OS X, |
---|
40 | // unlike windows you can not rely on the curent working directory |
---|
41 | // for locating your configuration files and resources. |
---|
42 | std::string macBundlePath() |
---|
43 | { |
---|
44 | char path[1024]; |
---|
45 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
---|
46 | assert(mainBundle); |
---|
47 | |
---|
48 | CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); |
---|
49 | assert(mainBundleURL); |
---|
50 | |
---|
51 | CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); |
---|
52 | assert(cfStringRef); |
---|
53 | |
---|
54 | CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); |
---|
55 | |
---|
56 | CFRelease(mainBundleURL); |
---|
57 | CFRelease(cfStringRef); |
---|
58 | |
---|
59 | return std::string(path); |
---|
60 | } |
---|
61 | #endif |
---|
62 | |
---|
63 | using namespace Ogre; |
---|
64 | |
---|
65 | class OrxExitListener : public FrameListener |
---|
66 | { |
---|
67 | public: |
---|
68 | OrxExitListener(OIS::Keyboard *keyboard) |
---|
69 | : mKeyboard(keyboard) |
---|
70 | { |
---|
71 | } |
---|
72 | |
---|
73 | bool frameStarted(const FrameEvent& evt) |
---|
74 | { |
---|
75 | mKeyboard->capture(); |
---|
76 | return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); |
---|
77 | } |
---|
78 | |
---|
79 | private: |
---|
80 | OIS::Keyboard *mKeyboard; |
---|
81 | }; |
---|
82 | |
---|
83 | class OrxApplication |
---|
84 | { |
---|
85 | public: |
---|
86 | void go() |
---|
87 | { |
---|
88 | /* createRoot(); |
---|
89 | defineResources(); |
---|
90 | setupRenderSystem(); |
---|
91 | createRenderWindow(); |
---|
92 | initializeResourceGroups(); |
---|
93 | setupScene(); |
---|
94 | setupInputSystem(); |
---|
95 | setupCEGUI(); |
---|
96 | createFrameListener(); |
---|
97 | startRenderLoop(); |
---|
98 | */ |
---|
99 | std::cout << "Test 1\n"; |
---|
100 | orxonox::BaseObject* test1; |
---|
101 | test1 = new orxonox::BaseObject(); |
---|
102 | test1 = new orxonox::BaseObject(); |
---|
103 | test1 = new orxonox::BaseObject(); |
---|
104 | |
---|
105 | std::cout << "Test 2\n"; |
---|
106 | orxonox::A1* test2; |
---|
107 | test2 = new orxonox::A1(); |
---|
108 | test2 = new orxonox::A1(); |
---|
109 | test2 = new orxonox::A1(); |
---|
110 | |
---|
111 | std::cout << "Test 3\n"; |
---|
112 | orxonox::BaseObject* test3; |
---|
113 | test3 = new orxonox::BaseObject(); |
---|
114 | test3 = new orxonox::BaseObject(); |
---|
115 | test3 = new orxonox::BaseObject(); |
---|
116 | |
---|
117 | std::cout << "Test 4\n"; |
---|
118 | orxonox::A3* test4; |
---|
119 | test4 = new orxonox::A3(); |
---|
120 | test4 = new orxonox::A3(); |
---|
121 | test4 = new orxonox::A3(); |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | ~OrxApplication() |
---|
126 | { |
---|
127 | mInputManager->destroyInputObject(mKeyboard); |
---|
128 | OIS::InputManager::destroyInputSystem(mInputManager); |
---|
129 | |
---|
130 | delete mRenderer; |
---|
131 | delete mSystem; |
---|
132 | |
---|
133 | delete mListener; |
---|
134 | delete mRoot; |
---|
135 | } |
---|
136 | |
---|
137 | private: |
---|
138 | Root *mRoot; |
---|
139 | OIS::Keyboard *mKeyboard; |
---|
140 | OIS::Mouse *mMouse; |
---|
141 | OIS::InputManager *mInputManager; |
---|
142 | CEGUI::OgreCEGUIRenderer *mRenderer; |
---|
143 | CEGUI::System *mSystem; |
---|
144 | OrxExitListener *mListener; |
---|
145 | |
---|
146 | void createRoot() |
---|
147 | { |
---|
148 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
149 | mRoot = new Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); |
---|
150 | #else |
---|
151 | mRoot = new Root(); |
---|
152 | #endif |
---|
153 | } |
---|
154 | |
---|
155 | void defineResources() |
---|
156 | { |
---|
157 | String secName, typeName, archName; |
---|
158 | ConfigFile cf; |
---|
159 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
160 | cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); |
---|
161 | #else |
---|
162 | cf.load("resources.cfg"); |
---|
163 | #endif |
---|
164 | |
---|
165 | ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
---|
166 | while (seci.hasMoreElements()) |
---|
167 | { |
---|
168 | secName = seci.peekNextKey(); |
---|
169 | ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
---|
170 | ConfigFile::SettingsMultiMap::iterator i; |
---|
171 | for (i = settings->begin(); i != settings->end(); ++i) |
---|
172 | { |
---|
173 | typeName = i->first; |
---|
174 | archName = i->second; |
---|
175 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
176 | ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); |
---|
177 | #else |
---|
178 | ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); |
---|
179 | #endif |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | void setupRenderSystem() |
---|
185 | { |
---|
186 | if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) |
---|
187 | throw Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); |
---|
188 | } |
---|
189 | |
---|
190 | void createRenderWindow() |
---|
191 | { |
---|
192 | mRoot->initialise(true, "Ogre Render Window"); |
---|
193 | } |
---|
194 | |
---|
195 | void initializeResourceGroups() |
---|
196 | { |
---|
197 | TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
198 | ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
199 | } |
---|
200 | |
---|
201 | void setupScene() |
---|
202 | { |
---|
203 | SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager"); |
---|
204 | Camera *cam = mgr->createCamera("Camera"); |
---|
205 | Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); |
---|
206 | } |
---|
207 | |
---|
208 | void setupInputSystem() |
---|
209 | { |
---|
210 | size_t windowHnd = 0; |
---|
211 | std::ostringstream windowHndStr; |
---|
212 | OIS::ParamList pl; |
---|
213 | RenderWindow *win = mRoot->getAutoCreatedWindow(); |
---|
214 | |
---|
215 | win->getCustomAttribute("WINDOW", &windowHnd); |
---|
216 | windowHndStr << windowHnd; |
---|
217 | pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); |
---|
218 | mInputManager = OIS::InputManager::createInputSystem(pl); |
---|
219 | |
---|
220 | try |
---|
221 | { |
---|
222 | mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); |
---|
223 | mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); |
---|
224 | } |
---|
225 | catch (const OIS::Exception &e) |
---|
226 | { |
---|
227 | throw new Exception(42, e.eText, "OrxApplication::setupInputSystem"); |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | void setupCEGUI() |
---|
232 | { |
---|
233 | SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); |
---|
234 | RenderWindow *win = mRoot->getAutoCreatedWindow(); |
---|
235 | |
---|
236 | // CEGUI setup |
---|
237 | mRenderer = new CEGUI::OgreCEGUIRenderer(win, Ogre::RENDER_QUEUE_OVERLAY, false, 3000, mgr); |
---|
238 | mSystem = new CEGUI::System(mRenderer); |
---|
239 | |
---|
240 | // Other CEGUI setup here. |
---|
241 | } |
---|
242 | |
---|
243 | void createFrameListener() |
---|
244 | { |
---|
245 | mListener = new OrxExitListener(mKeyboard); |
---|
246 | mRoot->addFrameListener(mListener); |
---|
247 | } |
---|
248 | |
---|
249 | void startRenderLoop() |
---|
250 | { |
---|
251 | mRoot->startRendering(); |
---|
252 | } |
---|
253 | }; |
---|
254 | |
---|
255 | #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
256 | #define WIN32_LEAN_AND_MEAN |
---|
257 | #include "windows.h" |
---|
258 | |
---|
259 | INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) |
---|
260 | #else |
---|
261 | int main(int argc, char **argv) |
---|
262 | #endif |
---|
263 | { |
---|
264 | try |
---|
265 | { |
---|
266 | OrxApplication orxonox; |
---|
267 | orxonox.go(); |
---|
268 | } |
---|
269 | catch(Exception& e) |
---|
270 | { |
---|
271 | #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
272 | MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
273 | #else |
---|
274 | fprintf(stderr, "An exception has occurred: %s\n", |
---|
275 | e.getFullDescription().c_str()); |
---|
276 | #endif |
---|
277 | } |
---|
278 | |
---|
279 | return 0; |
---|
280 | } |
---|
281 | |
---|