mirror of
https://github.com/Relintai/sfw.git
synced 2025-02-19 23:14:19 +01:00
Simplify main().
This commit is contained in:
parent
85bad3cfda
commit
9ec2133dae
@ -6,8 +6,11 @@
|
|||||||
#include "game_scene.h"
|
#include "game_scene.h"
|
||||||
|
|
||||||
class GameApplication : public Application {
|
class GameApplication : public Application {
|
||||||
|
SFW_OBJECT(GameApplication, Application);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameApplication() : Application() {
|
GameApplication() :
|
||||||
|
Application() {
|
||||||
scene = new GameScene();
|
scene = new GameScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,5 +19,4 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // GAME_APPLICATION_H
|
#endif // GAME_APPLICATION_H
|
||||||
|
39
main.cpp
39
main.cpp
@ -2,59 +2,28 @@
|
|||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#endif // __EMSCRIPTEN__
|
#endif // __EMSCRIPTEN__
|
||||||
|
|
||||||
#include "render_core/application.h"
|
|
||||||
#include "render_core/window.h"
|
|
||||||
|
|
||||||
#include "game_application.h"
|
#include "game_application.h"
|
||||||
#include "render_core/window.h"
|
|
||||||
|
|
||||||
#include "core/pool_vector.h"
|
|
||||||
#include "core/string_name.h"
|
|
||||||
#include "object/core_string_names.h"
|
|
||||||
|
|
||||||
Application *application = NULL;
|
Application *application = NULL;
|
||||||
|
|
||||||
void handle_frame() {
|
void handle_frame() {
|
||||||
application->main_loop();
|
application->core_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
//TODO centralize these
|
application = memnew(GameApplication());
|
||||||
StringName::setup();
|
|
||||||
MemoryPool::setup();
|
|
||||||
CoreStringNames::create();
|
|
||||||
|
|
||||||
AppWindow *w = memnew(AppWindow());
|
|
||||||
w->create(100, 0);
|
|
||||||
|
|
||||||
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) {
|
|
||||||
// application->main_loop();
|
|
||||||
//}
|
|
||||||
|
|
||||||
while (application->running) {
|
while (application->running) {
|
||||||
if (w->frame_begin()) {
|
application->core_loop();
|
||||||
//w->resize();
|
|
||||||
//w->render_callback(loopArg);
|
|
||||||
w->frame_end();
|
|
||||||
w->frame_swap();
|
|
||||||
} else {
|
|
||||||
w->shutdown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete application;
|
memdelete(application);
|
||||||
|
|
||||||
#endif // __EMSCRIPTEN__
|
#endif // __EMSCRIPTEN__
|
||||||
|
|
||||||
StringName::cleanup();
|
|
||||||
MemoryPool::cleanup();
|
|
||||||
CoreStringNames::free();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
#include "render_core/input/input.h"
|
#include "render_core/input/input.h"
|
||||||
#include "render_core/window.h"
|
#include "render_core/window.h"
|
||||||
|
|
||||||
|
#include "core/pool_vector.h"
|
||||||
|
#include "core/string_name.h"
|
||||||
|
#include "object/core_string_names.h"
|
||||||
|
|
||||||
void Application::input_event(const Ref<InputEvent> &event) {
|
void Application::input_event(const Ref<InputEvent> &event) {
|
||||||
scene->input_event(event);
|
scene->input_event(event);
|
||||||
}
|
}
|
||||||
@ -20,6 +24,19 @@ void Application::render() {
|
|||||||
//SDL_GL_SwapWindow(window);
|
//SDL_GL_SwapWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::core_loop() {
|
||||||
|
AppWindow *w = AppWindow::get_singleton();
|
||||||
|
|
||||||
|
if (w->frame_begin()) { // calls Application::main_loop()
|
||||||
|
//w->resize();
|
||||||
|
//w->render_callback(loopArg);
|
||||||
|
w->frame_end();
|
||||||
|
w->frame_swap();
|
||||||
|
} else {
|
||||||
|
w->shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Application::main_loop() {
|
void Application::main_loop() {
|
||||||
uint64_t start = STime::time_us();
|
uint64_t start = STime::time_us();
|
||||||
|
|
||||||
@ -52,6 +69,10 @@ void Application::main_loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::_init_window() {
|
||||||
|
AppWindow::get_singleton()->create(100, 0);
|
||||||
|
}
|
||||||
|
|
||||||
Application::Application() {
|
Application::Application() {
|
||||||
_instance = this;
|
_instance = this;
|
||||||
|
|
||||||
@ -62,10 +83,18 @@ Application::Application() {
|
|||||||
|
|
||||||
frame_delta = 0;
|
frame_delta = 0;
|
||||||
|
|
||||||
|
StringName::setup();
|
||||||
|
MemoryPool::setup();
|
||||||
|
CoreStringNames::create();
|
||||||
|
|
||||||
|
memnew(AppWindow());
|
||||||
|
|
||||||
if (!Input::get_singleton()) {
|
if (!Input::get_singleton()) {
|
||||||
memnew(Input());
|
memnew(Input());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_init_window();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SDL_SetMainReady();
|
SDL_SetMainReady();
|
||||||
|
|
||||||
@ -108,6 +137,12 @@ Application::Application() {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
Application::~Application() {
|
Application::~Application() {
|
||||||
|
_instance = NULL;
|
||||||
|
|
||||||
|
StringName::cleanup();
|
||||||
|
MemoryPool::cleanup();
|
||||||
|
CoreStringNames::free();
|
||||||
|
|
||||||
//SDL_DestroyWindow(window);
|
//SDL_DestroyWindow(window);
|
||||||
|
|
||||||
// window = NULL;
|
// window = NULL;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
class AppWindow;
|
class AppWindow;
|
||||||
class InputEvent;
|
class InputEvent;
|
||||||
|
|
||||||
class Application : Object {
|
class Application : public Object {
|
||||||
SFW_OBJECT(Application, Object);
|
SFW_OBJECT(Application, Object);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -27,6 +27,7 @@ public:
|
|||||||
return _idle_frames;
|
return _idle_frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void core_loop();
|
||||||
void main_loop();
|
void main_loop();
|
||||||
|
|
||||||
Application();
|
Application();
|
||||||
@ -41,6 +42,8 @@ public:
|
|||||||
real_t frame_delta;
|
real_t frame_delta;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void _init_window();
|
||||||
|
|
||||||
static Application *_instance;
|
static Application *_instance;
|
||||||
|
|
||||||
uint64_t _idle_frames;
|
uint64_t _idle_frames;
|
||||||
|
Loading…
Reference in New Issue
Block a user