blob: cd810eaa3d2ba6fca31fc3e1b760de454144d352 (
plain) (
blame)
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
|
#include "GameManager.hpp"
using namespace OpenVic;
GameManager::GameManager(
InstanceManager::gamestate_updated_func_t new_gamestate_updated_callback,
SimulationClock::state_changed_function_t new_clock_state_changed_callback
) : gamestate_updated_callback {
new_gamestate_updated_callback ? std::move(new_gamestate_updated_callback) : []() {}
}, clock_state_changed_callback {
new_clock_state_changed_callback ? std::move(new_clock_state_changed_callback) : []() {}
}, definitions_loaded { false } {}
bool GameManager::load_definitions(
Dataloader::path_vector_t const& roots, Dataloader::localisation_callback_t localisation_callback
) {
if (definitions_loaded) {
Logger::error("Cannot load definitions - already loaded!");
return false;
}
bool ret = true;
if (!dataloader.set_roots(roots)) {
Logger::error("Failed to set dataloader roots!");
ret = false;
}
if (!dataloader.load_defines(definition_manager)) {
Logger::error("Failed to load defines!");
ret = false;
}
if (!dataloader.load_localisation_files(localisation_callback)) {
Logger::error("Failed to load localisation!");
ret = false;
}
definitions_loaded = true;
return ret;
}
bool GameManager::setup_instance(Bookmark const* bookmark) {
if (instance_manager) {
Logger::info("Resetting existing game instance.");
} else {
Logger::info("Setting up first game instance.");
}
instance_manager.emplace(definition_manager, gamestate_updated_callback, clock_state_changed_callback);
bool ret = instance_manager->setup();
ret &= instance_manager->load_bookmark(bookmark);
return ret;
}
bool GameManager::start_game_session() {
if (!instance_manager || !instance_manager->is_game_instance_setup()) {
Logger::error("Cannot start game session - instance manager not set up!");
return false;
}
if (instance_manager->is_game_session_started()) {
Logger::error("Cannot start game session - session already started!");
return false;
}
if (!instance_manager->is_bookmark_loaded()) {
Logger::warning("Starting game session with no bookmark loaded!");
}
return instance_manager->start_game_session();
}
|