-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
109 lines (93 loc) · 3.21 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
#include "SFML/System.hpp"
#include "VelEng/Context.hpp"
#include "VelEng/SpriteComponent.hpp"
#include "VelEng/RigidBody.hpp"
#include "VelEng/PlatformerControllerComponent.hpp"
#include "VelEng/GameConfig.hpp"
#include "VelEng/Serialize/GameConfig.hpp"
#include "VelEng/log.hpp"
#include "fmt/core.h"
using namespace ven;
#include "data/icon32.c"
#include "data/splash.c"
int main(){
GameConfig config = parsef<GameConfig>("game.config");
for(auto& layer : config.layers){
if(layer[0] == 'L'){
auto ll = M_RS.pushLightingLayer(layer);
ll->setFogOpacity(0);
}else{
M_RS.pushLayer(layer);
}
}
M_RSD.pushLayer("debug");
for(auto& p : config.path){
M_AS::addPath(p);
}
#ifdef DEBUG
// because log to stderr makes gdb difficult to read
loguru::g_stderr_verbosity = -5;
#else
if(!config.stderr){
loguru::g_stderr_verbosity = -5;
}
#endif
if(config.infolog.size() > 0){
loguru::add_file(config.infolog.c_str(), loguru::Truncate, loguru::Verbosity_INFO);
}
if(config.errlog.size() > 0){
loguru::add_file(config.errlog.c_str(), loguru::Truncate, loguru::Verbosity_WARNING);
}
ComponentParser::registerComponent("sprite", parseSprite);
ComponentParser::registerComponent("body", parseRigidBody);
ComponentParser::registerComponent("platformer", parsePlatformerController);
M_AS::setDefaultFont("/home/miguel_mj/Programs/ASSETS/FONTS/Pixel Gosub.ttf");
if(config.splashscreen){
float ratio = (float)splash.height/splash.width;
float ww = 800;
window.create(sf::VideoMode(ww,ww*ratio), "", sf::Style::None);
sf::Image splashIm;
splashIm.create(splash.width, splash.height, splash.pixel_data);
sf::Texture t;
if(t.loadFromImage(splashIm)){
t.setSmooth(true);
sf::Sprite im(t);
auto s = t.getSize();
auto ws = window.getSize();
centerWindow();
im.scale((float)ws.x/s.x, (float)ws.y/s.y);
sf::Color col = sf::Color::White;
col.a=0;
sf::Clock c;
float elapsed = 0;
float total = 3.3;
do{
if(elapsed < total/5){
col.a = 255*(5*elapsed/total);
}else if(elapsed > total*4/5){
col.a = 255*((total - elapsed)/(total*1/5));
}
im.setColor(col);
window.clear();
window.draw(im);
window.display();
elapsed = c.getElapsedTime().asSeconds();
}while(elapsed < total);
// window.close();
}else{
LOG_F(WARNING,"No splash screen");
}
}
if(config.fullscreen){
ven::window.create(sf::VideoMode(), config.title, sf::Style::Fullscreen);
}else{
ven::window.create(sf::VideoMode(config.width,config.height), config.title);
}
ven::window.setIcon(icon.width, icon.height, icon.pixel_data);
ven::window.setFramerateLimit(60);
centerWindow();
auto s = M_AS::getScene(config.entry);
ven::setNextScene(s);
launch();
return 0;
}