Fix main loop setup.

This commit is contained in:
Relintai 2023-12-19 15:23:49 +01:00
parent b36a278f82
commit 3a6f715f35
6 changed files with 43 additions and 23 deletions

View File

@ -44,7 +44,7 @@ g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/scene.cpp -
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/window.cpp -o sfw/application/window.o g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c sfw/application/window.cpp -o sfw/application/window.o
#g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c game_scene.cpp -o game_scene.o g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c game_scene.cpp -o game_scene.o
g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c main.cpp -o main.o g++ -Wall -D_REENTRANT -g -Isfw -Isfw/application -c main.cpp -o main.o

View File

@ -2,6 +2,11 @@
#include "application.h" #include "application.h"
#include "3rd_glad.h"
//#include "camera.h"
//#include "sprite.h"
void GameScene::event() { void GameScene::event() {
/* /*
switch (ev.type) { switch (ev.type) {
@ -92,16 +97,14 @@ void GameScene::update(float delta) {
} }
void GameScene::render() { void GameScene::render() {
/* glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
camera->bind(); //camera->bind();
tile_map->render(); //tile_map->render();
sprite->render(); //sprite->render();
*/
} }
GameScene::GameScene() { GameScene::GameScene() {

View File

@ -3,30 +3,43 @@
#endif // __EMSCRIPTEN__ #endif // __EMSCRIPTEN__
#include "application.h" #include "application.h"
#include "window.h"
#include "game_application.h" #include "game_application.h"
Application *application = NULL; Application *application = NULL;
void handle_frame() { void handle_frame() {
application->main_loop(); application->main_loop();
} }
int main(int argc, char** argv) int main(int argc, char **argv) {
{ application = new GameApplication();
application = new GameApplication();
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
emscripten_set_main_loop(handle_frame, 0, 1); emscripten_set_main_loop(handle_frame, 0, 1);
#else #else
while (application->running) { //while (application->running) {
application->main_loop(); // application->main_loop();
} //}
delete application; AppWindow *w = AppWindow::get_singleton();
#endif // __EMSCRIPTEN__ while (application->running) {
if (w->frame_begin()) {
//w->resize();
//w->render_callback(loopArg);
w->frame_end();
w->frame_swap();
} else {
w->shutdown();
}
}
return 0; delete application;
#endif // __EMSCRIPTEN__
return 0;
} }

View File

@ -5,7 +5,7 @@
#include "scene.h" #include "scene.h"
class Window; class AppWindow;
class Application { class Application {
public: public:
@ -23,7 +23,7 @@ public:
Scene *scene; Scene *scene;
Window *window; AppWindow *window;
static Application *get_singleton(); static Application *get_singleton();

View File

@ -27,6 +27,7 @@
#include "stime.h" #include "stime.h"
#include "ustring.h" #include "ustring.h"
#include "vector4.h" #include "vector4.h"
#include "application.h"
/* /*
static volatile float framerate = 0; static volatile float framerate = 0;
@ -464,6 +465,8 @@ int AppWindow::frame_begin() {
//input_update(); //input_update();
Application::get_singleton()->render();
return 1; return 1;
} }

View File

@ -89,6 +89,8 @@ public:
void fps_lock(float fps); void fps_lock(float fps);
void fps_unlock(); void fps_unlock();
void shutdown();
Vector2 dpi(); Vector2 dpi();
enum CURSOR_SHAPES { enum CURSOR_SHAPES {
@ -119,7 +121,6 @@ protected:
static void drop_callback(GLFWwindow *window, int count, const char **paths); static void drop_callback(GLFWwindow *window, int count, const char **paths);
static void window_hints(unsigned flags); static void window_hints(unsigned flags);
GLFWmonitor *find_monitor(int wx, int wy); GLFWmonitor *find_monitor(int wx, int wy);
void shutdown();
void resize(); void resize();
static void loop_wrapper(void *loopArg); static void loop_wrapper(void *loopArg);
void glNewFrame(); void glNewFrame();