MxEngine
Application.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include "Utilities/Time/Time.h"
32 #include "Core/Event/IEvent.h"
33 #include "Core/Runtime/RuntimeEditor.h"
34 #include "Core/Rendering/RenderAdaptor.h"
35 #include "Core/MxObject/MxObject.h"
36 #include "Utilities/FileSystem/File.h"
37 #include "Core/Components/Script.h"
38 
39 #include "Platform/Window/Window.h"
40 
41 namespace MxEngine
42 {
43  class LoggerImpl;
44 
46  {
47  struct ModuleManager
48  {
49  ModuleManager(Application* app);
50  ~ModuleManager();
51  } manager;
52  private:
53  static inline Application* Current = nullptr;
54  UniqueRef<Window> window;
55  RenderAdaptor renderAdaptor;
56  AppEventDispatcher dispatcher;
57  RuntimeEditor console;
58  TimeStep timeDelta = 0.0f;
59  int counterFPS = 0;
60  bool shouldClose = false;
61  bool isRunning = false;
62 
63  void InitializeRuntimeEditor(RuntimeEditor& console);
64  void InitializeRenderAdaptor(RenderAdaptor& adaptor);
65  void DrawObjects();
66  void InvokeUpdate();
67  bool VerifyApplicationState();
68  protected:
69 
70  Application();
71 
72  virtual void OnCreate();
73  virtual void OnUpdate();
74  virtual void OnDestroy();
75  public:
76  void ToggleRuntimeEditor(bool isVisible);
77  void CloseOnKeyPress(KeyCode key);
78 
79  AppEventDispatcher& GetEventDispatcher();
80  RenderAdaptor& GetRenderAdaptor();
81  LoggerImpl& GetLogger();
82  RuntimeEditor& GetRuntimeEditor();
83  Window& GetWindow();
84  float GetTimeDelta() const;
85  int GetCurrentFPS() const;
86  void Run();
87  bool IsRunning() const;
88  void CloseApplication();
89  void CreateContext();
90  virtual ~Application();
91 
92  static Application* Get();
93  static void Set(Application* application);
94  };
95 }
Definition: Application.h:45
Definition: RuntimeEditor.h:46
Definition: RenderAdaptor.h:35
Definition: Window.h:56
Definition: Application.cpp:49
Definition: Logger.h:43