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

View File

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

View File

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

View File

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

View File

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

View File

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