Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/main_reto/src/OgreControl.cpp @ 141

Last change on this file since 141 was 141, checked in by rgrieder, 16 years ago

RunManager.cpp completely commented in Doxygen style.
One or two comments are yet inappropriate since a few changes to the code have to be made anyway. coming soon.

File size: 4.4 KB
Line 
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 *      Reto Grieder
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "OgreControl.h"
29
30#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
31// This function will locate the path to our application on OS X,
32// unlike windows you can not rely on the curent working directory
33// for locating your configuration files and resources.
34std::string macBundlePath()
35{
36        char path[1024];
37        CFBundleRef mainBundle = CFBundleGetMainBundle();
38        assert(mainBundle);
39
40        CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
41        assert(mainBundleURL);
42
43        CFStringRef cfStringRef =
44        CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
45        assert(cfStringRef);
46
47        CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
48
49        CFRelease(mainBundleURL);
50        CFRelease(cfStringRef);
51
52        return std::string(path);
53}
54#endif
55
56
57OgreControl::OgreControl()
58{
59        mRoot = 0;
60        // Provide a nice cross platform solution for locating the configuration
61        // files. On windows files are searched for in the current working
62  // directory, on OS X however you must provide the full path, the helper
63  // function macBundlePath does this for us.
64#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
65        mResourcePath = macBundlePath() + "/Contents/Resources/";
66#else
67        mResourcePath = "";
68#endif
69}
70
71
72// standard destructor
73OgreControl::~OgreControl()
74{
75        if (mRoot)
76                delete mRoot;
77}
78
79
80/**------------- SETTING UP OGRE --------------**/
81
82bool OgreControl::initialise(void)
83{
84        String pluginsPath;
85        // only use plugins.cfg if not static
86#ifndef OGRE_STATIC_LIB
87        pluginsPath = mResourcePath + "plugins.cfg";
88#endif
89
90        mRoot = new Root(pluginsPath, 
91                mResourcePath + "ogre.cfg", mResourcePath + "Ogre.log");
92
93        setupResources();
94
95        if (!configure())
96                return false;
97
98        return true;
99}
100
101
102// Method which will define the source of resources
103// (other than current folder)
104void OgreControl::setupResources(void)
105{
106        // Load resource paths from config file
107        ConfigFile cf;
108        cf.load(mResourcePath + "resources.cfg");
109
110        // Go through all sections & settings in the file
111        ConfigFile::SectionIterator seci = cf.getSectionIterator();
112
113        String secName, typeName, archName;
114        while (seci.hasMoreElements())
115        {
116                secName = seci.peekNextKey();
117                ConfigFile::SettingsMultiMap *settings = seci.getNext();
118                ConfigFile::SettingsMultiMap::iterator i;
119                for (i = settings->begin(); i != settings->end(); ++i)
120                {
121                        typeName = i->first;
122                        archName = i->second;
123#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
124                        // OS X does not set the working directory relative to the app,
125                        // In order to make things portable on OS X we need to provide
126                        // the loading with it's own bundle path location
127                        ResourceGroupManager::getSingleton().addResourceLocation(
128                                String(macBundlePath() + "/" + archName), typeName, secName);
129#else
130                        ResourceGroupManager::getSingleton().addResourceLocation(
131                                archName, typeName, secName);
132#endif
133                }
134        }
135}
136
137
138bool OgreControl::configure(void)
139{
140        // Show the configuration dialog and initialise the system
141        // You can skip this and use root.restoreConfig() to load configuration
142        // settings if you were sure there are valid ones saved in ogre.cfg
143        if(!mRoot->restoreConfig() && !mRoot->showConfigDialog())
144                return false;
145
146        // user clicked OK so initialise
147        // Here we choose to let the system create a default
148  // rendering window by passing 'true'
149        mWindow = mRoot->initialise(true);
150        mRoot->saveConfig();
151        return true;
152}
153
154
155Root* OgreControl::getRoot(void)
156{
157        return mRoot;
158}
159
160
161RenderWindow* OgreControl::getRenderWindow(void)
162{
163        return mWindow;
164}
165
166
167Ogre::String OgreControl::getResourcePath(void)
168{
169        return mResourcePath;
170}
Note: See TracBrowser for help on using the repository browser.