hx3d  1
2D/3D Simple Game Framework
core.cpp
1 /*
2  Centralized framework management.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
30 #include "hx3d/core/core.hpp"
31 #include "hx3d/window/events.hpp"
32 
33 #include "hx3d/net/net.hpp"
34 #include "hx3d/audio/audio.hpp"
35 
36 #include "hx3d/utils/assets.hpp"
37 
38 #include <cstdlib>
39 
40 namespace hx3d {
41 
42 #if __ANDROID__
44 #elif __unix
45  Core::SystemType Core::CurrentSystem = Core::SystemType::Linux;
46 #elif _WIN32_
47  Core::SystemType Core::CurrentSystem = Core::SystemType::Windows;
48 #elif __APPLE__
49  #include "TargetConditionals.h"
50  #if TARGET_IPHONE_SIMULATOR
51  Core::SystemType Core::CurrentSystem = Core::SystemType::iOS;
52  #elif TARGET_OS_IPHONE
53  Core::SystemType Core::CurrentSystem = Core::SystemType::iOS;
54  #elif TARGET_OS_MAC
55  Core::SystemType Core::CurrentSystem = Core::SystemType::MacOS;
56  #endif
57 #else
58  Core::SystemType Core::CurrentSystem = Core::SystemType::Unknown;
59 #endif
60 
61 Core* Core::_instance(nullptr);
62 
63 Core::Core() {
64  _assets = new AssetManager();
65  _net = new net::Net();
66  _audio = new audio::AudioDevice();
67 }
68 
69 Core::~Core() {
70  if (_assets)
71  delete _assets;
72  if (_net)
73  delete _net;
74  if (_audio)
75  delete _audio;
76 }
77 
79  return get()->_application;
80 }
81 
83  return get()->_game;
84 }
85 
87  return get()->_assets;
88 }
89 
91  return get()->_events;
92 }
93 
95  return get()->_net;
96 }
97 
99  return get()->_audio;
100 }
101 
103 
105  _instance = new Core();
106  _instance->_application = app;
107  _instance->_events = events;
108 }
109 
111  _instance->_game = game;
112 }
113 
115  if (_instance)
116  delete _instance;
117 }
118 
119 Core* Core::get() {
120  if (!_instance) {
121  Log.Error("Attempt to use the Core without initializing it.");
122  exit(1);
123  }
124 
125  return _instance;
126 }
127 
128 } /* hx3d */
Audio device management.
Definition: audio.hpp:40
static window::Game * CurrentGame()
Get the game instance.
Definition: core.cpp:82
static void setGame(window::Game *game)
Set the game.
Definition: core.cpp:110
Game main class: multiple screens management.
Definition: game.hpp:42
iPhone/iPad system
Network management.
Definition: net.hpp:34
static void shutdown()
Shutdown the core system.
Definition: core.cpp:114
Manage real-time inputs.
Application management.
Definition: application.hpp:42
static net::Net * Network()
Get the net instance.
Definition: core.cpp:94
static window::Application * App()
Get the application instance.
Definition: core.cpp:78
static AssetManager * Assets()
Get the asset manager.
Definition: core.cpp:86
hx3d framework namespace
Definition: audio.hpp:26
void Error(const std::string fmt,...)
Write an error message.
Definition: log.cpp:72
static hx3d::LogImpl Log
Current log implementation.
Definition: log.hpp:91
static SystemType CurrentSystem
Current system type.
Definition: core.hpp:135
SystemType
System types.
Definition: core.hpp:57
Centralized framework management.
Definition: core.hpp:50
static void initialize(window::Application *app, window::EventManager *events)
Initialize the core system.
Definition: core.cpp:104
static window::EventManager * Events()
Get the event manager.
Definition: core.cpp:90
Asset management.
Definition: assets.hpp:36
static audio::AudioDevice * Audio()
Get the audio device instance.
Definition: core.cpp:98