cangine
Loading...
Searching...
No Matches
cangine.hpp
Go to the documentation of this file.
1#pragma once
2
12#include <string>
13#include <type_traits>
14#include <initializer_list>
15
17
18#include "util/color.hpp"
19#include "util/position.hpp"
20
21#include "platform/window.hpp"
22
23#include "render/shader.hpp"
25
27#include "engine/exception.hpp"
28
29namespace cangine {
31 void init();
33 void terminate();
34
43 class CangineApp {
44 private:
45 bool isFirstFrame = true;
47 RenderSystem* _rs = nullptr;
48 ObjectManager* _om = nullptr;
49
54 void initShader(std::string name);
56 void initRenderSystem();
58 void initObjectManager();
60 void initAudioManager();
61
62 public:
66
77 int windowWidth = 800,
78 int windowHeight = 600,
79 std::string windowTitle = "cangine window",
80 bool fullscreen = false,
82 std::string defaultShaderName = "default"
83 );
85
87 virtual void onFirstFrame() {}
92 virtual void onFrame(double dt) {}
93
103 template <typename T, typename... Args>
104 T* instantiateObject(Args&&... args) {
105 static_assert(std::is_base_of<GameObject, T>::value,
106 "Instantiated object is not a GameObject");
107 return new T(std::forward<Args>(args)...);
108 }
109
111 void run();
112 };
113}
Singleton class that manages audio playback.
Definition audiomanager.hpp:20
Base application class that owns the window and main loop.
Definition cangine.hpp:43
virtual void onFrame(double dt)
Override to run per-frame game logic.
Definition cangine.hpp:92
RenderSystem * _rs
Owned render system.
Definition cangine.hpp:47
~CangineApp()
Definition cangine.cpp:85
Window * window
The application window.
Definition cangine.hpp:64
void initObjectManager()
Creates the object manager.
Definition cangine.cpp:44
void initShader(std::string name)
Loads and initializes the default shader.
Definition cangine.cpp:30
T * instantiateObject(Args &&... args)
Instantiates a game object of a derived type.
Definition cangine.hpp:104
void initAudioManager()
Creates the audio manager.
Definition cangine.cpp:48
ObjectManager * _om
Owned object manager.
Definition cangine.hpp:48
AudioManager * audioMan
Owned audio manager.
Definition cangine.hpp:65
void initRenderSystem()
Creates the render system.
Definition cangine.cpp:40
virtual void onFirstFrame()
Override to run setup logic on the first frame.
Definition cangine.hpp:87
void run()
Runs the main loop until the window is closed.
Definition cangine.cpp:52
Color windowFillColor
Color the window is cleared to each frame.
Definition cangine.hpp:63
bool isFirstFrame
Whether the next frame is the first one.
Definition cangine.hpp:45
Shader * shader
Default shader used for rendering.
Definition cangine.hpp:46
Singleton registry that owns and updates all game objects.
Definition object_manager.hpp:17
Singleton aggregating the engine's renderers.
Definition render_system.hpp:15
Wraps a compiled and linked OpenGL shader program.
Definition shader.hpp:61
Owns the application window, OpenGL context and the frame loop.
Definition window.hpp:34
const Color BLACK(0, 0, 0)
Black.
Definition audiomanager.cpp:4
void init()
Initializes engine-wide state (must be called before use).
Definition cangine.cpp:10
void terminate()
Tears down engine-wide state.
Definition cangine.cpp:23
RGBA color stored as normalized floating-point components.
Definition color.hpp:12