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 bool IsButtonPressed(Button button) { return 0; };
virtual float GetLeftJoystickXAxis() { return 0.0; }; virtual float GetLeftJoystickXAxis() { return 0.0; };
virtual float GetLeftJoystickYAxis() { return 0.0; }; virtual float GetLeftJoystickYAxis() { return 0.0; };
virtual ~Controller() {};
protected: protected:
virtual int GetButtonMask(Button button) { return 0; } virtual int GetButtonMask(Button button) { return 0; }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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