More cleanups and simplifications.

This commit is contained in:
Relintai 2024-01-03 14:01:29 +01:00
parent 89d8b7dcca
commit ee823eab5d
4 changed files with 9 additions and 61 deletions

View File

@ -9,8 +9,7 @@ class GameApplication : public Application {
SFW_OBJECT(GameApplication, Application); SFW_OBJECT(GameApplication, Application);
public: public:
GameApplication() : GameApplication() {
Application() {
scene = new GameScene(); scene = new GameScene();
} }

View File

@ -4,23 +4,15 @@
#include "game_application.h" #include "game_application.h"
Application *application = NULL;
void handle_frame() {
application->core_loop();
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
application = memnew(GameApplication()); Application *application = memnew(GameApplication());
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
emscripten_set_main_loop(handle_frame, 0, 1); emscripten_set_main_loop(&Application::core_loop_static, 0, 1);
#else #else
while (application->running) { while (application->running) {
application->core_loop(); application->core_loop();
} }
#endif // __EMSCRIPTEN__ #endif // __EMSCRIPTEN__
memdelete(application); memdelete(application);

View File

@ -20,8 +20,6 @@ void Application::update(float delta) {
void Application::render() { void Application::render() {
scene->render(); scene->render();
//SDL_GL_SwapWindow(window);
} }
void Application::core_loop() { void Application::core_loop() {
@ -83,6 +81,7 @@ Application::Application() {
frame_delta = 0; frame_delta = 0;
// TODO Move these to a central place in core!
StringName::setup(); StringName::setup();
MemoryPool::setup(); MemoryPool::setup();
CoreStringNames::create(); CoreStringNames::create();
@ -95,51 +94,11 @@ Application::Application() {
} }
_init_window(); _init_window();
/*
SDL_SetMainReady();
int error = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
if (error) {
SDL_Log("SDL_Init fail: %s\n", SDL_GetError());
running = false;
return;
}
#if defined(_WIN64) || defined(_WIN32)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#endif
window = SDL_CreateWindow("SDL + OpenGL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (!window) {
SDL_Log("SDL_CreateWindow Failed! %s\n", SDL_GetError());
running = false;
return;
}
context = SDL_GL_CreateContext(window);
#if defined(_WIN64) || defined(_WIN32)
gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress);
#endif // defined
printf("%s\n", glGetString(GL_VERSION));
*/
} }
Application::~Application() { Application::~Application() {
_instance = NULL; _instance = NULL;
// TODO Move these to a central place in core!
StringName::cleanup(); StringName::cleanup();
MemoryPool::cleanup(); MemoryPool::cleanup();
CoreStringNames::free(); CoreStringNames::free();
@ -147,12 +106,6 @@ Application::~Application() {
// TODO add a helper static method // TODO add a helper static method
memdelete(AppWindow::get_singleton()); memdelete(AppWindow::get_singleton());
memdelete(Input::get_singleton()); memdelete(Input::get_singleton());
//SDL_DestroyWindow(window);
// window = NULL;
//SDL_Quit();
} }
Application *Application::get_singleton() { Application *Application::get_singleton() {

View File

@ -30,6 +30,10 @@ public:
void core_loop(); void core_loop();
void main_loop(); void main_loop();
_FORCE_INLINE_ void core_loop_static() {
Application::get_singleton()->core_loop();
}
Application(); Application();
virtual ~Application(); virtual ~Application();