Application initial cleanup.

This commit is contained in:
Relintai 2023-12-19 00:21:39 +01:00
parent 666a5d7ed8
commit d9485f9c3e
5 changed files with 51 additions and 48 deletions

View File

@ -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

View File

@ -1,13 +1,12 @@
#include "application.h"
#include "opengl.h"
#include <chrono>
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(&current_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<Uint32>(remaining * 1000.0);
//uint32_t fms = static_cast<uint32_t>(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() {

View File

@ -3,17 +3,16 @@
#include <stdio.h>
#include <SDL.h>
#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();

View File

@ -12,7 +12,7 @@
#endif
#if defined(_WIN64) || defined(_WIN32)
#include <glad/glad.h>
#include "3rd_glad.h"
#endif // defined
#endif // OPENGL_H

View File

@ -1,11 +1,9 @@
#ifndef SCENE_H
#define SCENE_H
#include <SDL.h>
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;