-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
136 lines (117 loc) · 4.64 KB
/
main.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
132
133
134
135
136
#include <OgreWindowEventUtilities.h>
#include <QtWidgets/QApplication>
#include <QtCore/qexception.h>
#include "object.hpp"
#include "mainwindow.hpp"
#include "scene.hpp"
#include "ogrewidget.hpp"
#include "collisiondetector.hpp"
#include <list>
int main(int argc, char* argv[])
{
try
{
QApplication app(argc, argv);
Ogre::Root* root =new Ogre::Root;
if(root->restoreConfig() || root->showConfigDialog())
root->initialise(false, "Bump"); //koniecznie tuż pod konstruktorem root!
else
throw "Ogre initialisation error.";
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("Resources", "FileSystem");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);//Ponoć niektóre API to omijają, więc warto dodać
MainWindow view;
view.show();
Ogre::Timer frameTimer;
Ogre::Timer deltaTimer;
unsigned long frameCount=0;
boost::property_tree::basic_ptree<std::string, std::string> pt;
boost::property_tree::ini_parser::read_ini("scenes.ini", pt);
std::list<std::pair<std::string, Scene*>> Scenes;
for(auto sceneProperties : pt)
{
Scene* s=new Scene(sceneProperties.second);
s->SetInactive();
QObject::connect(s, &Scene::ObjectsCollisionInSceneChanged, &view, &MainWindow::SwitchCollisionInScene);
Scenes.push_back(std::make_pair(sceneProperties.first,s));
view.AddScene(sceneProperties.first);
}
Scenes.begin()->second->SetActive();
QObject::connect(&view, &MainWindow::sceneChanged, [=](const std::string& sceneTitle)
{
for (auto scenePair : Scenes)
if(scenePair.second->IsActive())
scenePair.second->SetInactive();
else if(scenePair.first==sceneTitle)
scenePair.second->SetActive();
}
);
CollisionDetector collisionDetector;
QObject::connect(&collisionDetector, &CollisionDetector::ObjectsCollisionInAlgorithmChanged, &view, &MainWindow::SwitchCollisionInAlgorithm);
for(auto name : {"None","Bounding box", "Triangle", "Bounding box + triangle"})
view.AddAlgorithm(name);
QObject::connect(&view, &MainWindow::algorithmChanged, [&](const std::string& algorithmTitle)
{
//default
collisionDetector.ActiveAlgorithm=CollisionDetector::None;
if(algorithmTitle=="Bounding box")
collisionDetector.ActiveAlgorithm=CollisionDetector::BoundingBox;
if(algorithmTitle=="Triangle")
collisionDetector.ActiveAlgorithm=CollisionDetector::Triangle;
if(algorithmTitle=="Bounding box + triangle")
collisionDetector.ActiveAlgorithm=CollisionDetector::Complex;
}
);
while(true)
{
// Pump window messages for nice behaviour
Ogre::WindowEventUtilities::messagePump();
if(view.isHidden())
{
return false;
}
app.processEvents();
for(auto scenePair : Scenes)
{
Scene* scene=scenePair.second;
if(scene->IsActive())
{
scene->CheckSceneCollision();
collisionDetector.CheckCollision(scene->ObjectA, scene->ObjectB);
if(deltaTimer.getMilliseconds()>1000/30)
{
scene->Tick(deltaTimer.getMilliseconds()*30/1000);
deltaTimer.reset();
}
break;
}
}
// Render a frame
if(!root->renderOneFrame()) break;
frameCount++;
if(frameTimer.getMilliseconds()>1000)
{
view.setFPS(1000*frameCount/frameTimer.getMilliseconds());
frameCount=0;
frameTimer.reset();
}
}
}
catch( Ogre::Exception& oe )
{
std::cerr << "An exception has occured: " <<oe.getFullDescription().c_str() << std::endl;
}
catch( QException& qe)
{
std::cerr<<"Exception: "<<qe.what()<<std::endl;
}
catch( std::exception& e)
{
std::cerr<<"Exception: "<<e.what()<<std::endl;
}
catch(char const* c)
{
std::cerr<<"Exception: "<<c<<std::endl;
}
return 0;
}