From d9485f9c3ea013a3f16380abcf291e737a7a53d2 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 19 Dec 2023 00:21:39 +0100 Subject: [PATCH] Application initial cleanup. --- compile_linux.sh | 58 ++++++++++++++++++--------------- sfw/application/application.cpp | 25 +++++++------- sfw/application/application.h | 10 +++--- sfw/application/opengl.h | 2 +- sfw/application/scene.h | 4 +-- 5 files changed, 51 insertions(+), 48 deletions(-) diff --git a/compile_linux.sh b/compile_linux.sh index 36ea7b0..245a23b 100755 --- a/compile_linux.sh +++ b/compile_linux.sh @@ -9,31 +9,35 @@ #g++ -Wall -fexceptions -I/usr/include/SDL2 -D_REENTRANT -g -Isfw -c sfw/aabb.cpp -o sfw/aabb.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/aabb.cpp -o sfw/aabb.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/basis.cpp -o sfw/basis.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/color.cpp -o sfw/color.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/face3.cpp -o sfw/face3.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/logger.cpp -o sfw/logger.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/math_funcs.cpp -o sfw/math_funcs.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/memory.cpp -o sfw/memory.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pcg.cpp -o sfw/pcg.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/plane.cpp -o sfw/plane.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/projection.cpp -o sfw/projection.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/quaternion.cpp -o sfw/quaternion.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/random_pcg.cpp -o sfw/random_pcg.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/rect2.cpp -o sfw/rect2.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/rect2i.cpp -o sfw/rect2i.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/safe_refcount.cpp -o sfw/safe_refcount.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/transform_2d.cpp -o sfw/transform_2d.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/transform.cpp -o sfw/transform.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/ustring.cpp -o sfw/ustring.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector2.cpp -o sfw/vector2.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector2i.cpp -o sfw/vector2i.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector3.cpp -o sfw/vector3.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector3i.cpp -o sfw/vector3i.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector4.cpp -o sfw/vector4.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector4i.cpp -o sfw/vector4i.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/aabb.cpp -o sfw/aabb.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/basis.cpp -o sfw/basis.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/color.cpp -o sfw/color.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/face3.cpp -o sfw/face3.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/logger.cpp -o sfw/logger.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/math_funcs.cpp -o sfw/math_funcs.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/memory.cpp -o sfw/memory.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pcg.cpp -o sfw/pcg.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/plane.cpp -o sfw/plane.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/projection.cpp -o sfw/projection.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/quaternion.cpp -o sfw/quaternion.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/random_pcg.cpp -o sfw/random_pcg.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/rect2.cpp -o sfw/rect2.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/rect2i.cpp -o sfw/rect2i.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/safe_refcount.cpp -o sfw/safe_refcount.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/transform_2d.cpp -o sfw/transform_2d.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/transform.cpp -o sfw/transform.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/ustring.cpp -o sfw/ustring.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector2.cpp -o sfw/vector2.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector2i.cpp -o sfw/vector2i.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector3.cpp -o sfw/vector3.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector3i.cpp -o sfw/vector3i.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector4.cpp -o sfw/vector4.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/vector4i.cpp -o sfw/vector4i.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_vector.cpp -o sfw/pool_vector.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_allocator.cpp -o sfw/pool_allocator.o -g++ -Wall -D_REENTRANT -g -Isfw -c sfw/mutex.cpp -o sfw/mutex.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_vector.cpp -o sfw/pool_vector.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/pool_allocator.cpp -o sfw/pool_allocator.o +# g++ -Wall -D_REENTRANT -g -Isfw -c sfw/mutex.cpp -o sfw/mutex.o +g++ -Wall -D_REENTRANT -g -Isfw -c sfw/stime.cpp -o sfw/stime.o + +#g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/application.cpp -o sfw/application/application.o +#g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/scene.cpp -o sfw/application/scene.o diff --git a/sfw/application/application.cpp b/sfw/application/application.cpp index 70258af..b265d6e 100644 --- a/sfw/application/application.cpp +++ b/sfw/application/application.cpp @@ -1,13 +1,12 @@ #include "application.h" +#include "opengl.h" #include -void Application::event(const SDL_Event &ev) { - if (ev.type == SDL_QUIT) { - running = false; - } +#include "window.h" - scene->event(ev); +void Application::event() { + scene->event(); } void Application::update(float delta) { @@ -17,18 +16,20 @@ void Application::update(float delta) { void Application::render() { scene->render(); - SDL_GL_SwapWindow(window); + //SDL_GL_SwapWindow(window); } void Application::main_loop() { std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now(); //handle input + /* SDL_Event current_event; while (SDL_PollEvent(¤t_event)) { event(current_event); } + */ //update_world update(frame_delta); @@ -46,11 +47,11 @@ void Application::main_loop() { double remaining = tfps - t; if (remaining > 0) { - Uint32 fms = static_cast(remaining * 1000.0); + //uint32_t fms = static_cast(remaining * 1000.0); frame_delta = tfps; - SDL_Delay(fms); + //SDL_Delay(fms); } else { frame_delta = t; } @@ -66,6 +67,7 @@ Application::Application() { frame_delta = 0; + /* SDL_SetMainReady(); int error = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); @@ -104,13 +106,14 @@ Application::Application() { #endif // defined printf("%s\n", glGetString(GL_VERSION)); + */ } Application::~Application() { - SDL_DestroyWindow(window); + //SDL_DestroyWindow(window); - window = NULL; + // window = NULL; - SDL_Quit(); + //SDL_Quit(); } Application *Application::get_singleton() { diff --git a/sfw/application/application.h b/sfw/application/application.h index 4a06987..8c3cb8c 100644 --- a/sfw/application/application.h +++ b/sfw/application/application.h @@ -3,17 +3,16 @@ #include -#include - -#include "opengl.h" #include "scene.h" +class Window; + class Application { public: bool running; int target_fps; - virtual void event(const SDL_Event &ev); + virtual void event(); virtual void update(float delta); virtual void render(); @@ -24,8 +23,7 @@ public: Scene *scene; - SDL_Window *window; - SDL_GLContext context; + Window *window; static Application *get_singleton(); diff --git a/sfw/application/opengl.h b/sfw/application/opengl.h index efb1e6d..b391339 100644 --- a/sfw/application/opengl.h +++ b/sfw/application/opengl.h @@ -12,7 +12,7 @@ #endif #if defined(_WIN64) || defined(_WIN32) -#include +#include "3rd_glad.h" #endif // defined #endif // OPENGL_H diff --git a/sfw/application/scene.h b/sfw/application/scene.h index 2994c3d..45b5282 100644 --- a/sfw/application/scene.h +++ b/sfw/application/scene.h @@ -1,11 +1,9 @@ #ifndef SCENE_H #define SCENE_H -#include - class Scene { public: - virtual void event(const SDL_Event &ev) = 0; + virtual void event() = 0; virtual void update(float delta) = 0; virtual void render() = 0;