-
Notifications
You must be signed in to change notification settings - Fork 0
/
Services.h
79 lines (60 loc) · 2.19 KB
/
Services.h
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
//
// Created by Paul on 04.10.2017.
//
#ifndef PAXENGINE3_SERVICES_H
#define PAXENGINE3_SERVICES_H
#include <paxutil/resources/Resources.h>
#include <polypropylene/reflection/TypeMap.h>
#include <polypropylene/event/EventService.h>
#include <paxcore/io/InputSystem.h>
#include <polypropylene/memory/AllocationService.h>
#include <paxutil/io/Settings.h>
#include <paxcore/function/Updateable.h>
#include <polypropylene/serialisation/json/JsonFieldWriterRegister.h>
#include "Paths.h"
#include "FactoryService.h"
#include "WindowService.h"
namespace PAX {
class Engine;
class Services : private Updateable {
friend class Engine;
static Services* _instance;
TypeMap<void*> _registeredServices;
AllocationService allocationService;
EventService _eventService;
FactoryService _factoryService;
Resources _resources;
Settings _globalSettings;
WindowService _windowService;
Json::JsonFieldWriterRegister jsonFieldWriterRegister;
std::shared_ptr<InputSystem> _inputSystem = nullptr;
Paths _paths;
protected:
Services();
~Services() override;
void initialize();
void terminate();
public:
void registerService(const TypeId & type, void *service);
size_t unregisterService(const TypeId & type);
template<typename Service>
Service* get() {
const auto & service = _registeredServices.find(paxtypeid(Service));
if (service != _registeredServices.end())
return reinterpret_cast<Service*>(service->second);
return nullptr;
}
static Services& Instance();
static InputSystem& GetInput();
static Resources& GetResources();
static FactoryService& GetFactoryService();
static AllocationService& GetDefaultAllocationService();
static EventService& GetEventService();
static Paths& GetPaths();
static Settings& GetGlobalSettings();
static WindowService & GetWindowService();
static Json::JsonFieldWriterRegister & GetJsonWriterRegister();
void update(UpdateOptions & options) override;
};
}
#endif //PAXENGINE3_SERVICES_H