Compare commits
1 Commits
2aed98d688
...
d69d982398
Author | SHA1 | Date | |
---|---|---|---|
d69d982398 |
@ -9,7 +9,7 @@ namespace Gedeng {
|
||||
void Application::run() {
|
||||
// Setup Rendering
|
||||
// FIXME: Make these parameters variable, maybe move this to a different function
|
||||
RenderBackend::initialize_window(1920, 1080, String("Application"));
|
||||
RenderBackend::initialize_window(WINDOW_SIZE_X, WINDOW_SIZE_Y, WINDOW_NAME);
|
||||
Input::initialize(RenderBackend::get_window());
|
||||
|
||||
unsigned long previous_time_ms = Time::get_time_ms();
|
||||
@ -26,13 +26,11 @@ void Application::run() {
|
||||
|
||||
// Update fixed time step
|
||||
while (time_until_fixed_update_ms >= MS_PER_UPDATE) {
|
||||
// Fixed Update
|
||||
GG_CORE_INFO("Fixed Update");
|
||||
fixed_update(static_cast<double>(MS_PER_UPDATE) / 1000.0);
|
||||
time_until_fixed_update_ms -= MS_PER_UPDATE;
|
||||
}
|
||||
|
||||
// Variable update
|
||||
GG_CORE_INFO("Variable Update");
|
||||
dynamic_update(static_cast<double>(elapsed_time_ms) / 1000.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "String.h"
|
||||
|
||||
namespace Gedeng {
|
||||
|
||||
class Application {
|
||||
public:
|
||||
Application() = default;
|
||||
Application(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y, String window_name)
|
||||
: MS_PER_UPDATE(ms_per_update), WINDOW_SIZE_X(window_size_x), WINDOW_SIZE_Y(window_size_y),
|
||||
WINDOW_NAME(window_name) {
|
||||
}
|
||||
|
||||
// Virtual since this class will be inherited by user-created applications
|
||||
virtual ~Application() = default;
|
||||
|
||||
// Game Loop
|
||||
void run();
|
||||
|
||||
// Primarily for gameplay and physics
|
||||
// To be overridden by client applications
|
||||
virtual void fixed_update(double delta) = 0;
|
||||
|
||||
// Primarily for rendering
|
||||
// To be overridden by client applications
|
||||
virtual void dynamic_update(double delta) = 0;
|
||||
|
||||
// TODO: Write note for this: `undefined reference to vtable` can be caused by forgetting `= 0` for pure virtual
|
||||
// stuff
|
||||
|
||||
private:
|
||||
const unsigned long MS_PER_UPDATE = 20;
|
||||
// TODO: These will probably become a separate Settings struct
|
||||
const unsigned long MS_PER_UPDATE;
|
||||
const unsigned int WINDOW_SIZE_X;
|
||||
const unsigned int WINDOW_SIZE_Y;
|
||||
const String WINDOW_NAME;
|
||||
};
|
||||
|
||||
// To be defined in client applications
|
||||
|
@ -17,7 +17,8 @@ class Input {
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
}
|
||||
|
||||
// FIXME: Ignore warnings produced by these unused variables -- they're required for the callback to work
|
||||
// FIXME: Ignore warnings produced by these unused variables -- they're required for the callback to work:
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
|
||||
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
|
||||
|
@ -4,12 +4,23 @@
|
||||
|
||||
class TestApp : public Gedeng::Application {
|
||||
public:
|
||||
TestApp() = default;
|
||||
TestApp(unsigned long ms_per_update, unsigned int window_size_x, unsigned int window_size_y,
|
||||
Gedeng::String window_name)
|
||||
: Application(ms_per_update, window_size_x, window_size_y, window_name) {
|
||||
}
|
||||
|
||||
~TestApp() = default;
|
||||
|
||||
void fixed_update(double delta) override {
|
||||
GG_CLIENT_INFO("Fixed update");
|
||||
}
|
||||
|
||||
void dynamic_update(double delta) override {
|
||||
GG_CLIENT_INFO("Dynamic update");
|
||||
}
|
||||
};
|
||||
|
||||
Gedeng::Application *Gedeng::create_application() {
|
||||
GG_CLIENT_INFO("Creating Application");
|
||||
return new TestApp();
|
||||
return new TestApp(20, 900, 600, String("Test App"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user