/*
This file is part of Minitrem.
Minitrem is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Minitrem is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Minitrem. If not, see .
*/
#include "common.hpp"
#include
#ifdef CONFIG_SHOW_RSS
#include
#include
#include
#endif
bool debug_draw_cmodels = false;
bool debug_draw_paths = false;
bool debug_draw_tile_coords = false;
bool debug_AI = false;
render::state_t *debug_render;
static ntime_t nclock_ref;
// always > 0
ntime_t nclock(void)
{
return std::chrono::high_resolution_clock::now().time_since_epoch() /
std::chrono::nanoseconds(1) - nclock_ref;
}
void freq_counter_t::tick(void)
{
if (!t0)
t0 = nclock();
ticks++;
}
float freq_counter_t::read(ntime_t ival)
{
ntime_t now;
now = nclock();
if (!t0)
return 0.0f;
if (now - t0 < ival)
return last_reading;
last_reading = ticks / (float)(now - t0) * 1.0e+9f;
t0 = now;
ticks = 0;
return last_reading;
}
freq_counter_t fc_render;
freq_counter_t fc_game;
freq_counter_t fc_traces, fc_trace_tiles, fc_trace_ents;
freq_counter_t fc_get_entities, fc_get_entities_ents;
#ifdef CONFIG_SHOW_RSS
size_t sys_get_rss(void)
{
std::ifstream file;
pid_t pid;
std::string line;
size_t res = 0;
pid = getpid();
file.open("/proc/" + std::to_string(pid) + "/status");
while (file >> line) {
if (line == "VmRSS:") {
file >> res;
break;
}
}
return res * 1024;
}
#endif
int main()
{
nclock_ref = nclock() - 1;
sf::RenderWindow window(sf::VideoMode(800, 600), "Minitrem");
render::state_t render(&window);
game::pseudostate_t game(&window);
debug_render = &render;
window.setVerticalSyncEnabled(true);
game::load_assets();
game.start();
while (1) {
static ntime_t before = 0;
ntime_t now = nclock();
double dt;
if (before)
dt = (now - before) * 1.0e-9;
else
dt = 0.1;
before = now;
game.tick(now, dt);
if (!window.isOpen())
break;
sys_get_rss();
render.begin_frame(now, dt);
render.render(game.get_world(), game.get_render_time());
game.render_interface_to(&render);
render.end_frame();
}
game.stop();
return 0;
}