-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (69 loc) · 2.32 KB
/
Copy pathmain.cpp
File metadata and controls
80 lines (69 loc) · 2.32 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
72
73
74
75
76
77
78
79
80
#include <Managers.hpp>
#include <Physics.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window/WindowStyle.hpp>
#include <iostream>
#include <lua.hpp>
int main(const int argc, const char *argv[]) {
if (argc < 2) {
std::cout << "No Lua files given." << std::endl;
return 1;
}
// Set up Lua
lua_State *L = luaL_newstate();
luaL_openlibs(L);
if (luaL_dofile(L, argv[1]) != LUA_OK) {
std::cout << lua_tostring(L, -1) << std::endl;
return 1;
}
// Read from Lua
Physics::Universe universe;
Physics::Configuration configuration;
if (!configuration.FromLua(L) || !universe.FromLua(L)) {
return 1;
}
lua_close(L);
// Setup window and graphics settings
Physics::ViewManager viewManager(configuration.width, configuration.height);
sf::ContextSettings settings;
settings.antialiasingLevel = configuration.AALevel;
sf::RenderWindow window(sf::VideoMode(configuration.width, configuration.height),
"Planets",
sf::Style::Default,
settings);
window.setFramerateLimit(configuration.fpsLimit);
// Clock used for elapsed time
sf::Clock clock;
// Update loop
while (window.isOpen()) {
window.setView(viewManager.GetView());
// Event handling
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::MouseWheelMoved) {
viewManager.MouseScrolled(event.mouseWheel.delta);
}
if (event.type == sf::Event::Resized) {
viewManager.WindowResized(event.size.width, event.size.height);
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
window.close();
}
}
float elapsedTime = clock.getElapsedTime().asSeconds();
clock.restart();
// Update routines
viewManager.Update(elapsedTime);
if (!sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {
universe.Update(elapsedTime);
}
// Draw routines
window.clear();
universe.Draw(window);
window.display();
}
return 0;
}