Peoplemon  0.1.0
Peoplemon 3 game source documentation
main.cpp
Go to the documentation of this file.
1 #include <BLIB/Engine.hpp>
2 #include <BLIB/Logging.hpp>
3 #include <BLIB/Resources.hpp>
4 #include <BLIB/Util/Waiter.hpp>
5 
8 #include <Core/Files/ItemDB.hpp>
9 #include <Core/Files/MoveDB.hpp>
11 #include <Core/Input/Control.hpp>
12 #include <Core/Items/Item.hpp>
13 #include <Core/Peoplemon/Move.hpp>
15 
16 #include <Core/Properties.hpp>
17 #include <Core/Resources.hpp>
18 #include <Core/Systems/Systems.hpp>
19 #include <Game/States/MainGame.hpp>
20 #include <Game/States/MainMenu.hpp>
21 
22 #include <BLIB/ECS.hpp>
23 #include <iostream>
24 
25 struct WindowSizePersister : public bl::event::Listener<bl::engine::event::WindowResized> {
26  virtual void observe(const bl::engine::event::WindowResized&) override {
28  }
29 };
30 
31 int main(int argc, char** argv) {
32 #ifdef PEOPLEMON_DEBUG
33  bl::logging::Config::rollLogs("logs", "verbose", 3);
34  bl::logging::Config::configureOutput(std::cout, bl::logging::Config::Info);
35  bl::logging::Config::addFileOutput("logs/verbose.log", bl::logging::Config::Trace);
36 #else
37  bl::logging::Config::rollLogs("logs", "error", 3);
38  bl::logging::Config::configureOutput(std::cout, bl::logging::Config::Warn);
39  bl::logging::Config::addFileOutput("logs/error.log", bl::logging::Config::Warn);
40  (void)argc;
41  (void)argv;
42 #endif
43 
44  BL_LOG_INFO << "Initializing resource systems";
45 #ifdef PEOPLEMON_DEBUG
47 #else
49 #endif
50 
51  BL_LOG_INFO << "Loading application properties";
52  if (!core::Properties::load(false)) {
53  BL_LOG_ERROR << "Failed to load application properties";
54  return 1;
55  }
56  WindowSizePersister sizePersist;
57  bl::event::Dispatcher::subscribe(&sizePersist);
58  bl::cam::OverlayCamera::setOverlayCoordinateSpace(
59  static_cast<float>(core::Properties::WindowWidth()),
60  static_cast<float>(core::Properties::WindowHeight()));
61 
62  BL_LOG_INFO << "Loading game metadata";
63  BL_LOG_INFO << "Loading items";
64  core::file::ItemDB itemdb;
65  if (!itemdb.load()) {
66  BL_LOG_ERROR << "Failed to load item database";
67  return 1;
68  }
70  BL_LOG_INFO << "Loading moves";
71  core::file::MoveDB movedb;
72  if (!movedb.load()) {
73  BL_LOG_ERROR << "Failed to load move database";
74  return 1;
75  }
77  BL_LOG_INFO << "Loading Peoplemon";
79  if (!ppldb.load()) {
80  BL_LOG_ERROR << "Failed to load peoplemon database";
81  return 1;
82  }
84  BL_LOG_INFO << "Game metadata loaded";
85 
86  {
87  BL_LOG_INFO << "Creating engine instance";
88  const bl::engine::Settings engineSettings =
89  bl::engine::Settings()
90  .withWindowParameters(
91  bl::engine::Settings::WindowParameters()
92  .withVideoMode(sf::VideoMode(
94  .withStyle(sf::Style::Close | sf::Style::Titlebar | sf::Style::Resize)
95  .withTitle("Peoplemon")
97  .withLetterBoxOnResize(true)
98  .withInitialViewSize(core::Properties::WindowSize())
99  .fromConfig())
100  .fromConfig();
101  bl::engine::Engine engine(engineSettings);
102  core::input::configureInputSystem(engine.inputSystem());
103  BL_LOG_INFO << "Created engine";
104 
105  BL_LOG_INFO << "Initializing game systems";
106 #ifdef PEOPLEMON_DEBUG
107  engine.systems().registerSystem<core::debug::DebugBanner>(bl::engine::FrameStage::Update0,
108  bl::engine::StateMask::All);
109 #endif
110  core::system::Systems systems(engine);
111  BL_LOG_INFO << "Core game systems initialized";
112 
113  BL_LOG_INFO << "Configuring menu sounds";
114  bl::menu::Menu::setDefaultMoveSound(core::Properties::MenuMoveSound());
115  bl::menu::Menu::setDefaultSelectSound(core::Properties::MenuMoveSound());
116  bl::menu::Menu::setDefaultMoveFailSound(core::Properties::MenuMoveFailSound());
117 
118  bl::engine::State::Ptr state = game::state::MainMenu::create(systems);
119 #ifdef PEOPLEMON_DEBUG
120  core::debug::DebugOverrides::subscribe();
121 
122  if (argc == 2) {
123  const std::string path = argv[1];
124  BL_LOG_INFO << "Loading save: " << path;
126  BL_LOG_CRITICAL << "Failed to load save";
127  return 1;
128  }
129  state = game::state::MainGame::create(systems);
130  }
131 #endif
132 
133  BL_LOG_INFO << "Running engine main loop";
134  if (!engine.run(state)) {
135  BL_LOG_ERROR << "Engine exited with error";
136  bl::util::Waiter::unblockAll();
137  return 1;
138  }
139 
140  BL_LOG_INFO << "Unblocking waiting threads";
141  bl::util::Waiter::unblockAll();
142  }
143 
144  BL_LOG_INFO << "Freeing resources";
145  bl::resource::GarbageCollector::shutdownAndClear();
146 
147  BL_LOG_INFO << "Exiting normally";
148  return 0;
149 }
void installProdLoaders()
Sets up the BLIB resource managers in prod mode and mounts the resource bundles.
Definition: Resources.cpp:29
void installDevLoaders()
Sets up the BLIB resource managers in dev mode.
Definition: Resources.cpp:16
void configureInputSystem(bl::input::InputSystem &system)
Configures the input system for the set of peoplemon inputs.
Definition: Control.cpp:7
static bool loadFromFile(const std::string &sourceFile)
Loads the game from the given save file.
Definition: GameSave.cpp:78
Loads and stores metadata surrounding items in the game.
Definition: ItemDB.hpp:24
bool load()
Loads the item metadata from the data file.
Definition: ItemDB.cpp:11
Stores the metadata of all peoplemon moves.
Definition: MoveDB.hpp:22
bool load()
Loads the moves from the data file.
Definition: MoveDB.cpp:12
Data structure that holds the underlaying data for all the peoplemon.
Definition: PeoplemonDB.hpp:26
bool load()
Loads the database data from the save file.
Definition: PeoplemonDB.cpp:12
static void setDataSource(file::ItemDB &source)
Set the data source for the item methods.
Definition: Item.cpp:41
static void setDataSource(file::MoveDB &source)
Set the data source for each method.
Definition: Move.cpp:46
static void setDataSource(file::PeoplemonDB &data)
Sets the data source for all peoplemon. Must remain in scope.
Definition: Peoplemon.cpp:94
static void save()
Saves the config to the data file.
Definition: Properties.cpp:242
static int WindowWidth()
Definition: Properties.cpp:250
static bl::audio::AudioSystem::Handle MenuMoveFailSound()
Definition: Properties.cpp:707
static bl::audio::AudioSystem::Handle MenuMoveSound()
Definition: Properties.cpp:702
static sf::Vector2f WindowSize()
Definition: Properties.cpp:262
static int WindowHeight()
Definition: Properties.cpp:256
static bool load(bool inEditor)
Loads from the config file and sets defaults. Must be called before using any properties.
Definition: Properties.cpp:119
static const std::string & WindowIconFile()
Definition: Properties.cpp:244
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates the main game state. The game state must be initialized before invoking the main game state.
Definition: MainGame.cpp:35
static bl::engine::State::Ptr create(core::system::Systems &systems)
Creates a new MainMenu state.
Definition: MainMenu.cpp:18
virtual void observe(const bl::engine::event::WindowResized &) override
Definition: main.cpp:26
int main()
Definition: main.cpp:8