-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (54 loc) · 1.57 KB
/
Copy pathmain.cpp
File metadata and controls
71 lines (54 loc) · 1.57 KB
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
#include <SFML/Graphics.hpp>
#include "ResourceLocator.h"
#include "GameStateManager.h"
#include "InWorldState.h"
#include <iostream>
int main(int argc, char* argv[])
{
sf::RenderWindow app(sf::VideoMode(1024, 768), "Binary Spirit");
//app.setVerticalSyncEnabled(true);
std::string initialLevel = "test";
std::string currentPath = argv[0];
currentPath = currentPath.substr(0, currentPath.find_last_of("\\")) + "\\";
ResourceLocator::provideDrawSurface(&app);
ResourceLocator::loadResources(currentPath);
if( argc > 1 )
{
std::string mapFileName;
for( int i = 1; i < argc; ++i )
{
mapFileName.append(argv[i]);
}
if( ResourceLocator::loadMapResource( "__argmap", currentPath + mapFileName ) )
initialLevel = "__argmap";
}
sf::Event e;
sf::Clock timer;
sf::Int64 since_last_frame_ms = 0;
sf::Int64 frame_start_ms = 0;
float delta_ms = 0;
InWorldState* state = new InWorldState();
state->init( initialLevel );
GameStateManager gsm(state);
while(app.isOpen())
{
since_last_frame_ms = timer.getElapsedTime().asMilliseconds() - frame_start_ms;
frame_start_ms = timer.getElapsedTime().asMilliseconds();
delta_ms = (float) since_last_frame_ms / 1000.f;
if(delta_ms > 0.005)
delta_ms = 0.005f;
while(app.pollEvent(e))
{
if(e.type == sf::Event::Closed)
{
app.close();
}
gsm.getCurrentState()->handleEvents(&e);
}
gsm.getCurrentState()->update(delta_ms);
app.clear( sf::Color::Black );
gsm.getCurrentState()->render();
app.display();
}
return 0;
}