-
Notifications
You must be signed in to change notification settings - Fork 0
/
OgreFacade.cpp
132 lines (96 loc) · 3.85 KB
/
OgreFacade.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "OgreFacade.h"
#include <Compositor/OgreCompositorManager2.h>
#include <OgreConfigFile.h>
#include <OgreTextureManager.h>
namespace catapult {
OgreFacade::OgreFacade() :
root(new Ogre::Root("plugins.cfg")),
overlay(new Ogre::OverlaySystem()) // TODO Is this stuff leaking???
{
setupResources();
const size_t numThreads = 4; // I have this many cores. I am not looking to optimize in all platforms.
scene = root->createSceneManager(Ogre::ST_GENERIC, numThreads,
Ogre::INSTANCING_CULLING_THREADED,
"TheOgreSceneManager");
scene->addRenderQueueListener(overlay);
}
OgreFacade::~OgreFacade() {
Ogre::WindowEventUtilities::removeWindowEventListener(window, this);
windowClosed(window);
}
bool OgreFacade::configureWindow() {
bool restoredConfig = root->restoreConfig(); // Configuration saved on file.
if(restoredConfig || root->showConfigDialog())
{
// True means "make a default rendering window".
window = root->initialise(true, "Catapult");
}
Ogre::WindowEventUtilities::addWindowEventListener(window, this);
return (window != nullptr);
}
OgreBites::InputContext OgreFacade::prepareInputSystem(OIS::KeyListener* keys, OIS::MouseListener* mice) {
size_t windowHnd = 0;
window->getCustomAttribute("WINDOW", &windowHnd);
inputSystem.initialize(windowHnd);
OgreBites::InputContext inputContext;
inputContext.mMouse = inputSystem.mouse;
inputContext.mKeyboard = inputSystem.keyboard;
windowResized(window); // Initialize mouse clipping area.
inputSystem.mouse->setEventCallback(mice);
inputSystem.keyboard->setEventCallback(keys);
return inputContext;
}
void OgreFacade::finalizeResources() {
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
void OgreFacade::createViewports(Ogre::Camera* camera) {
Ogre::CompositorManager2* compositorManager = root->getCompositorManager2();
const Ogre::String workspaceName = "TheOnlyWorkspaceIUse";
if (!compositorManager->hasWorkspaceDefinition(workspaceName)) {
const Ogre::ColourValue skyColor(0.05f, 0.25f, 0.4f); // Won't use a fully-fledged skybox for this demo.
compositorManager->createBasicWorkspaceDef(workspaceName, skyColor, Ogre::IdString());
}
compositorManager->addWorkspace(scene, window, camera, workspaceName, true);
}
void OgreFacade::recaptureInputDevices() {
inputSystem.keyboard->capture();
inputSystem.mouse->capture();
}
void OgreFacade::windowResized(Ogre::RenderWindow* rw)
{
unsigned int width, height, depth;
int left, top;
rw->getMetrics(width, height, depth, left, top);
inputSystem.setMouseAreaSize(width, height);
}
void OgreFacade::windowClosed(Ogre::RenderWindow* rw)
{
//Only close for window that created OIS (the only one I have... not sure if Ogre can call with other windows).
if( rw == window )
inputSystem.shutdown();
}
void OgreFacade::setupResources(void)
{
const Ogre::String resourceConfigurationFile = "resources.cfg";
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load(resourceConfigurationFile);
// Go through all sections and settings in the file.
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
Ogre::String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
}
}