Add some memory cleanup code.

This commit is contained in:
Fries 2024-03-15 23:54:13 -07:00
parent eb21ac1dc7
commit 00fdd89b88
7 changed files with 18 additions and 1 deletions

View file

@ -17,6 +17,7 @@ class Controller {
virtual bool IsButtonPressed(Button button) { return 0; };
virtual float GetLeftJoystickXAxis() { return 0.0; };
virtual float GetLeftJoystickYAxis() { return 0.0; };
virtual ~Controller() {};
protected:
virtual int GetButtonMask(Button button) { return 0; }

View file

@ -34,6 +34,10 @@ bool Engine::ShouldWindowClose() {
return engine->ShouldWindowClose();
}
Engine::~Engine() {
delete engine;
}
void Engine::initScreen() {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glViewport(0, 0, 640, 480);

View file

@ -39,6 +39,8 @@ class Engine {
void initializeController();
void initializeEngine();
void initializeGameLoop();
void cleanupEngine();
virtual ~Engine();
struct Vector3 {
static Vector3 zero();
float x;

View file

@ -1,3 +1,4 @@
#include <GLFW/glfw3.h>
#ifdef __linux__
#include "linuxEngine.hh"
@ -45,4 +46,11 @@ void LinuxEngine::SwapBuffers() {
bool LinuxEngine::ShouldWindowClose() {
return glfwWindowShouldClose(this->window);
}
LinuxEngine::~LinuxEngine() {
delete controller;
glfwDestroyWindow(window);
glfwTerminate();
window = nullptr;
}
#endif

View file

@ -1,7 +1,6 @@
#ifndef LINUX_ENGINE_HH
#define LINUX_ENGINE_HH
#include "nativeEngine.hh"
#include <epoxy/gl.h>
#include <GLFW/glfw3.h>
class LinuxEngine : public NativeEngine {
@ -9,6 +8,7 @@ class LinuxEngine : public NativeEngine {
void initializeEngine() override;
void SwapBuffers() override;
bool ShouldWindowClose() override;
~LinuxEngine() override;
GLFWwindow* window = nullptr;
};
#endif

View file

@ -7,6 +7,7 @@ class NativeEngine {
virtual void initializeEngine(){};
virtual void SwapBuffers(){};
virtual bool ShouldWindowClose(){return false;};
virtual ~NativeEngine() {};
Controller* controller = nullptr;
};
#endif

View file

@ -34,4 +34,5 @@ int main(int argc, char *argv[]) {
Hello* engine = new Hello;
engine->initializeEngine();
engine->initializeGameLoop();
delete engine;
}