-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
79 lines (63 loc) · 2.44 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
#include <stdio.h>
#include <string>
#include "graphics.h"
#include "worldmanager.h"
#include "frametimer.h"
#include <math.h>
#include <Imagine/Graphics.h>
#include "userui.h"
using namespace std;
int main()
{
int width,height;
//Window size
width=height=800;
//Create managers: GraphicManager, WorldManager UserUIManager
//And link them
GraphicManager graphicManager(width,height);
WorldManager worldManager;
UserUI userUI(worldManager.getShapeManager(),&graphicManager,&worldManager);
worldManager.setDebugDrawer(&graphicManager);
Imagine::openWindow(width,height);
//-----------Edit your input file name here--------------
//--------------------------------------------------------
//--------------------------------------------------------
//worldManager.readFile("data_angrybirds.txt");
worldManager.readFile("data_tutorial.txt");
//worldManager.readFile("data10block.txt");
//--------------------------------------------------------
//--------------------------------------------------------
//--------------------------------------------------------
//worldManager tell us what is a correct frame time
//And we creat a FrameTimer to tell us when to run one step simulation
double frameTime=worldManager.getRecommendFrameTime();
FrameTimer timer(frameTime);
timer.start();
int frameCount=0;
while(1){
if(timer.isTimeToGo()){
//Graphic ask World for the shapeList, and he draw all the shapes
graphicManager.myDisplay(worldManager.getShapeList());
//graphicManager.savePrintScreen();
//World run one step of simulation
worldManager.OneStep();
//UserUI can draw buttons on screen, because he knows GraphicManager
userUI.drawButtons();
//UserUI treat user's action like "drag object" and "creat polygon"
userUI.treatEvents();
//tell FrameTimer that we have finished one frame
//he will note this down
//and we will wait him to say: "is time to run another frame!"
timer.finishOneFrame();
cout<<"frameCount "<<frameCount++<<endl;
//----DEBUG----
//if(frameCount==134){
// cout<<"stop"<<endl;
//}
//~DEBUG
cout<<"fps "<<1000./timer.timeBetweenTwoCalls()<<endl;
}
}
Imagine::endGraphics();
return 0;
}