Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: b7505a121aa4e8e33e9551a9c4e25f9fa39cc5c8 (plain)
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
/*
   client/application.cc
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

// project headers
#include "client/client.h"
#include "client/application.h"
#include "core/core.h"

// SDL headers
#include <SDL/SDL.h>

// C++ headers
#include <cmath>

namespace client
{

extern "C" void func_con_toggle(std::stringstream &args)
{
	console.toggle();
}

void Application::quit(int status)
{
	SDL_Quit();
	core::ApplicationInterface::quit(status);
}

void Application::init()
{
	// initialize core
	core::ApplicationInterface::init();

	con_print << "Initializing client..." << std::endl;

	// Initialize the video subsystem
	video.init();
	if (!video.initialized) {
		quit(1);
	}

	// initialize input
	input.init();

	// register our engine functions
	core::func_register("con_toggle", func_con_toggle);
}

void Application::run()
{
	Uint32 chrono = SDL_GetTicks();

	while (true) {
		Uint32 current = SDL_GetTicks();

		// overflow protection ~49 days
		if (current < chrono) {
			chrono = current;
		}

		// update the core chronometer
		float seconds = ((float)(current - chrono)) / 1000.0f;
		frame(seconds);
		
		// update the video chronometers and draw
		video.frame(seconds);
		if (seconds > 0)
			current_fps = floorf(1/seconds);
		else
			current_fps = 9999;

		// process input
		input.frame();

		// update the main loop chronometer
		chrono = current;
	}

}

void Application::shutdown()
{
	con_debug << "Shutting down client..." << std::endl;
	console.flush();

	input.shutdown();
	console.flush();

	video.shutdown();
	console.flush();

	core::ApplicationInterface::shutdown();
	console.flush();

	quit(0);
}

}