Just™ Game Engine
engine.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020-2022 Konstanty Misiak
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#pragma once
8#include "jng/core/base.hpp"
10
11#include <chrono>
12
13namespace jng {
14
15 class Event;
16 class WindowCloseEvent;
17 class WindowResizeEvent;
18 class Window;
19
23 class Engine :
24 public NonCopyable
25 {
26 public:
27 enum class RendererType { None, Renderer2D, Renderer3D };
28
30 {
31 const char* windowTitle;
32 unsigned int windowWidth;
33 unsigned int windowHeight;
35 const char* assetsDirectory = "assets";
36 };
37
38 explicit Engine(const Properties& properties);
39 virtual ~Engine();
40
41 void run();
42 void close() { m_isRunning = false; }
43
44 static Engine& get() { return *s_instance; }
45 const Properties& getProperties() const { return m_properties; }
46 Window& getWindow() { return *m_window; }
47 protected:
48 LayerStack& getLayerStack() { return m_layerStack; }
49 private:
50 void onEvent(Event& event);
51 bool onWindowClose(WindowCloseEvent& event);
52 bool onWindowResize(WindowResizeEvent& event);
53
54 static Engine* s_instance;
55 Properties m_properties;
56 Scope<Window> m_window;
57 RendererType m_rendererType;
58 LayerStack m_layerStack;
59 bool m_isRunning = true;
60 std::chrono::time_point<std::chrono::steady_clock> m_lastFrameTime;
61 };
62
63} // namespace jng
Main engine class from which all client applications derive.
Definition: engine.hpp:25
Engine(const Properties &properties)
Definition: engine.cpp:24
static Engine & get()
Definition: engine.hpp:44
const Properties & getProperties() const
Definition: engine.hpp:45
Window & getWindow()
Definition: engine.hpp:46
void run()
Definition: engine.cpp:69
void close()
Definition: engine.hpp:42
LayerStack & getLayerStack()
Definition: engine.hpp:48
RendererType
Definition: engine.hpp:27
virtual ~Engine()
Definition: engine.cpp:51
Definition: event.hpp:24
Definition: layer_stack.hpp:14
Definition: base.hpp:14
Definition: window_events.hpp:15
Definition: window.hpp:20
Definition: window_events.hpp:24
Definition: base.hpp:11
std::unique_ptr< T > Scope
Definition: base.hpp:24
Definition: engine.hpp:30
unsigned int windowWidth
Definition: engine.hpp:32
RendererType rendererType
Definition: engine.hpp:34
unsigned int windowHeight
Definition: engine.hpp:33
const char * windowTitle
Definition: engine.hpp:31
const char * assetsDirectory
Definition: engine.hpp:35