diff --git a/doc/samples/btphystest.cpp b/doc/samples/btphystest.cpp index 7a2690ae..035d418b 100644 --- a/doc/samples/btphystest.cpp +++ b/doc/samples/btphystest.cpp @@ -758,12 +758,11 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("BtPhysTest", ivec2(1280, 960), 60.0f); + app app("BtPhysTest", ivec2(1280, 960), 60.0f); new BtPhysTest(argc > 1); - app.ShowPointer(false); - - app.Run(); + app.show_pointer(false); + app.run(); return EXIT_SUCCESS; } diff --git a/doc/tutorial/01_triangle.cpp b/doc/tutorial/01_triangle.cpp index fc20057f..25b990db 100644 --- a/doc/tutorial/01_triangle.cpp +++ b/doc/tutorial/01_triangle.cpp @@ -77,12 +77,11 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f); + app app("Tutorial 1: Triangle", ivec2(640, 480), 60.0f); new DebugFps(5, 5); new Triangle(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/02_cube.cpp b/doc/tutorial/02_cube.cpp index 936680a5..b1f5de51 100644 --- a/doc/tutorial/02_cube.cpp +++ b/doc/tutorial/02_cube.cpp @@ -181,13 +181,12 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 2: Cube", ivec2(640, 480), 60.0f); + app app("Tutorial 2: Cube", ivec2(640, 480), 60.0f); new DebugFps(5, 5); new Cube(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/03_noise.cpp b/doc/tutorial/03_noise.cpp index 4cc281d6..df8d50a9 100644 --- a/doc/tutorial/03_noise.cpp +++ b/doc/tutorial/03_noise.cpp @@ -85,11 +85,10 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f); + app app("Tutorial 3: Noise", ivec2(1280, 720), 60.0f); new NoiseDemo(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/04_texture.cpp b/doc/tutorial/04_texture.cpp index 142d1354..9a48dfd2 100644 --- a/doc/tutorial/04_texture.cpp +++ b/doc/tutorial/04_texture.cpp @@ -119,11 +119,10 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 4: Texture", ivec2(1280, 720), 60.0f); + app app("Tutorial 4: Texture", ivec2(1280, 720), 60.0f); new TextureDemo(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/05_easymesh.cpp b/doc/tutorial/05_easymesh.cpp index 9ff01900..25279b77 100644 --- a/doc/tutorial/05_easymesh.cpp +++ b/doc/tutorial/05_easymesh.cpp @@ -169,10 +169,9 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f); + app app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f); new EasyMeshTutorial(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/06_sprite.cpp b/doc/tutorial/06_sprite.cpp index 7e94458a..8649f78f 100644 --- a/doc/tutorial/06_sprite.cpp +++ b/doc/tutorial/06_sprite.cpp @@ -102,10 +102,9 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 6: Sprite", ivec2(640, 480), 60.0f); + app app("Tutorial 6: Sprite", ivec2(640, 480), 60.0f); new SpriteTutorial(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/07_input.cpp b/doc/tutorial/07_input.cpp index cf024e16..06d3199d 100644 --- a/doc/tutorial/07_input.cpp +++ b/doc/tutorial/07_input.cpp @@ -207,13 +207,12 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 7: Input", ivec2(640, 480), 60.0f); + app app("Tutorial 7: Input", ivec2(640, 480), 60.0f); new DebugFps(5, 5); new InputTutorial(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/08_fbo.cpp b/doc/tutorial/08_fbo.cpp index 6f476200..e4a05557 100644 --- a/doc/tutorial/08_fbo.cpp +++ b/doc/tutorial/08_fbo.cpp @@ -137,10 +137,9 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 08: Framebuffer Object", ivec2(512, 512), 60.0f); + app app("Tutorial 08: Framebuffer Object", ivec2(512, 512), 60.0f); new FBO(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/09_sound.cpp b/doc/tutorial/09_sound.cpp index c7f59292..d3c27279 100644 --- a/doc/tutorial/09_sound.cpp +++ b/doc/tutorial/09_sound.cpp @@ -107,10 +107,9 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 9: Sound", ivec2(640, 480), 60.0f); + app app("Tutorial 9: Sound", ivec2(640, 480), 60.0f); new sound_demo(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/11_fractal.cpp b/doc/tutorial/11_fractal.cpp index 5af2daad..87482a14 100644 --- a/doc/tutorial/11_fractal.cpp +++ b/doc/tutorial/11_fractal.cpp @@ -572,14 +572,13 @@ int main(int argc, char **argv) ivec2 window_size(640, 480); sys::init(argc, argv); - Application app("Tutorial 11: Fractal", window_size, 60.0f); + app app("Tutorial 11: Fractal", window_size, 60.0f); new DebugFps(5, 5); new Fractal(window_size); //new DebugRecord("fractalol.ogm", 60.0f); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/12_voronoi.cpp b/doc/tutorial/12_voronoi.cpp index 0ef9677c..28831f5f 100644 --- a/doc/tutorial/12_voronoi.cpp +++ b/doc/tutorial/12_voronoi.cpp @@ -402,11 +402,10 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 12: Jump Flooding Algorithm & Voronoi", ivec2(512, 512), 60.0f); + app app("Tutorial 12: Jump Flooding Algorithm & Voronoi", ivec2(512, 512), 60.0f); new Voronoi(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/13_shader_builder.cpp b/doc/tutorial/13_shader_builder.cpp index 05fa3c4a..a2fad78d 100644 --- a/doc/tutorial/13_shader_builder.cpp +++ b/doc/tutorial/13_shader_builder.cpp @@ -1,8 +1,8 @@ // // Lol Engine — Shader builder tutorial // -// Copyright © 2002—2015 Benjamin “Touky” Huet -// © 2012—2019 Sam Hocevar +// Copyright © 2012—2020 Sam Hocevar +// © 2002—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -121,11 +121,10 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 13: Shader Builder", ivec2(1280, 720), 60.0f); + app app("Tutorial 13: Shader Builder", ivec2(1280, 720), 60.0f); new ShaderBuilderDemo(); - app.Run(); + app.run(); return EXIT_SUCCESS; } - diff --git a/doc/tutorial/14_lua.cpp b/doc/tutorial/14_lua.cpp index 2ef8625f..db769a6a 100644 --- a/doc/tutorial/14_lua.cpp +++ b/doc/tutorial/14_lua.cpp @@ -223,11 +223,11 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 14: Lolua Demo", ivec2(800, 600), 60.0f); + app app("Tutorial 14: Lolua Demo", ivec2(800, 600), 60.0f); new LoluaDemo(); - app.Run(); + app.run(); return EXIT_SUCCESS; } diff --git a/doc/tutorial/15_gui.cpp b/doc/tutorial/15_gui.cpp index 9d11bd05..95fb9ac3 100644 --- a/doc/tutorial/15_gui.cpp +++ b/doc/tutorial/15_gui.cpp @@ -98,11 +98,11 @@ int main(int argc, char **argv) { sys::init(argc, argv); - Application app("Tutorial 15: ImGui", ivec2(800, 600), 60.0f); + app app("Tutorial 15: ImGui", ivec2(800, 600), 60.0f); new LolImGuiDemo(); - app.Run(); + app.run(); return EXIT_SUCCESS; } diff --git a/doc/tutorial/17_net.cpp b/doc/tutorial/17_net.cpp index a0c4a16e..e1da1ca7 100644 --- a/doc/tutorial/17_net.cpp +++ b/doc/tutorial/17_net.cpp @@ -55,9 +55,9 @@ int main(int argc, char **argv) { lol::sys::init(argc, argv); - lol::Application app("Tutorial 17: HTTP", lol::ivec2(800, 600), 60.0f); + lol::app app("Tutorial 17: HTTP", lol::ivec2(800, 600), 60.0f); new demo(); - app.Run(); + app.run(); return 0; } diff --git a/src/Makefile.am b/src/Makefile.am index 35ef92df..b525c776 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -79,7 +79,7 @@ liblol_core_sources = \ easymesh/shinydebuglighting.lolfx easymesh/shinydebugnormal.lolfx \ easymesh/shinydebugUV.lolfx easymesh/shiny_SK.lolfx \ \ - base/assert.cpp base/log.cpp \ + base/assert.cpp base/engine.cpp base/log.cpp \ \ math/geometry.cpp \ \ diff --git a/src/application/application.cpp b/src/application/application.cpp index 892c5d04..8741fb9d 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -34,168 +34,70 @@ namespace lol { -class null_display -{ - friend class ApplicationDisplayData; - friend class ApplicationDisplay; - -public: - null_display(char const *, ivec2) {} - virtual ~null_display() {} - -protected: - ivec2 resolution() const { return ivec2(0); } - void set_resolution(ivec2) {} - void SetPosition(ivec2) {} -}; - -class null_app -{ -public: - null_app(char const *, ivec2, float) - { - msg::error("no display library (SDL, EGL…) available"); - assert(false); - } - virtual ~null_app() {} - - void ShowPointer(bool) {} - void Tick() {} -}; - -class ApplicationDisplayData -{ - friend class ApplicationDisplay; - - ApplicationDisplayData(char const *name, ivec2 res) - : display(name, res) - { } - -protected: -#if __ANDROID__ - // TODO: implement this - null_display display; -#elif __NX__ - nx::app_display display; -#elif LOL_USE_SDL - sdl::app_display display; -#elif HAVE_GLES_2X - // FIXME: this macro is only deactivated if we include "lolgl.h" - //NOT HANDLED YET -#else - null_display display; +#if __EMSCRIPTEN__ +static app *g_app; +static void AppCallback() { g_app->Tick(); } #endif -}; - -ApplicationDisplay::ApplicationDisplay(char const *name, ivec2 res) -{ - data = new ApplicationDisplayData(name, res); -} - -ApplicationDisplay::~ApplicationDisplay() -{ - delete data; -} - -ivec2 ApplicationDisplay::resolution() const -{ - return data->display.resolution(); -} - -void ApplicationDisplay::set_resolution(ivec2 res) -{ - data->display.set_resolution(res); -} -void ApplicationDisplay::SetPosition(ivec2 position) -{ - data->display.SetPosition(position); -} - -void ApplicationDisplay::start_frame() -{ - data->display.start_frame(); -} - -void ApplicationDisplay::end_frame() -{ - data->display.end_frame(); -} +// +// Public app class +// -class ApplicationData +app::app(char const *name, ivec2 res, float framerate) { - friend class Application; + ticker::setup(framerate); - ApplicationData(char const *name, ivec2 res, float framerate) - : app(name, res, framerate) - { } + // FIXME: this should probably be a call to e.g. nx::app::init() which + // creates the proper shared pointers. #if __ANDROID__ - AndroidApp app; + // TODO: implement m_display + m_data = std::make_shared(name, res, framerate); #elif __NX__ - nx::app app; + m_display = std::make_shared(name, res); + m_data = std::make_shared(name, m_display->resolution(), framerate); #elif LOL_USE_SDL - sdl::app app; + m_display = std::make_shared(name, res); + m_data = std::make_shared(name, m_display->resolution(), framerate); #elif HAVE_GLES_2X // FIXME: this macro is only deactivated if we include "lolgl.h" - EglApp app; -#else - null_app app; + //NOT HANDLED YET + m_data = std::make_shared(name, res, framerate); #endif -}; - -#if __EMSCRIPTEN__ -static Application *g_app; - -static void AppCallback() -{ - g_app->Tick(); + Scene::add_display(m_display); } -#endif - -// -// Public Application class -// -Application::Application(char const *name, ivec2 res, float framerate) +app::~app() { - ticker::setup(framerate); - - auto app_display = new ApplicationDisplay(name, res); - Scene::add_display(app_display); - data = new ApplicationData(name, app_display->resolution(), framerate); + ticker::teardown(); } -bool Application::MustTick() +bool app::must_tick() { - return !Ticker::Finished(); + return !ticker::Finished(); } -void Application::Tick() +void app::tick() { - data->app.Tick(); + if (m_data) + m_data->tick(); } -void Application::Run() +void app::run() { #if __EMSCRIPTEN__ g_app = this; emscripten_set_main_loop(AppCallback, 0, 1); #else - while (MustTick()) - Tick(); + while (must_tick()) + tick(); #endif } -void Application::ShowPointer(bool show) +void app::show_pointer(bool show) { - data->app.ShowPointer(show); -} - -Application::~Application() -{ - ticker::teardown(); - delete data; + if (m_data) + m_data->show_pointer(show); } } // namespace lol diff --git a/src/application/application.h b/src/application/application.h index 5624fb20..8b04bef9 100644 --- a/src/application/application.h +++ b/src/application/application.h @@ -1,64 +1,70 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright © 2010—2020 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #pragma once +#include // std::shared_ptr + // -// The Application class -// --------------------- +// The app class +// ————————————— // namespace lol { -class ApplicationDisplayData; - -class ApplicationDisplay +class app { - friend class Scene; - public: - ApplicationDisplay(char const *name, ivec2 resolution); - virtual ~ApplicationDisplay(); - - virtual void start_frame(); - virtual void end_frame(); + app(char const *name, ivec2 resolution, float framerate); + ~app(); - // pos/size/... methods - virtual void set_resolution(ivec2 resolution); - virtual ivec2 resolution() const; + bool must_tick(); + void tick(); + void run(); - virtual void SetPosition(ivec2 position); + // UI interface + void show_pointer(bool show); -private: - ApplicationDisplayData *data; -}; + // Display interface + class display + { + public: + virtual ~display() {} + virtual void start_frame() {} + virtual void end_frame() {} -class ApplicationData; + // pos/size/... methods + virtual void set_resolution(ivec2 resolution) {} + virtual ivec2 resolution() const { return ivec2(0); } -class Application -{ -public: - Application(char const *name, ivec2 resolution, float framerate); - ~Application(); + virtual void set_position(ivec2 position) {} + }; - bool MustTick(); - void Tick(); - void Run(); + // Internal data + class data + { + public: + data() {} + virtual ~data() {} - void ShowPointer(bool show); + virtual void show_pointer(bool show) {} + virtual void tick() {} + }; private: - ApplicationData *data; + std::shared_ptr m_display; + std::shared_ptr m_data; }; } // namespace lol - diff --git a/src/application/egl-app.cpp b/src/application/egl-app.cpp index 7ac9059f..c07e7bb3 100644 --- a/src/application/egl-app.cpp +++ b/src/application/egl-app.cpp @@ -43,7 +43,7 @@ namespace lol class EglAppData { - friend class EglApp; + friend class app_data; private: #if defined LOL_USE_EGL && !defined __ANDROID__ @@ -61,11 +61,10 @@ private: }; /* - * Public EglApp class + * Public app_data class */ -EglApp::EglApp(char const *title, ivec2 res, float fps) : - data(new EglAppData()) +egl::app_data::app_data(char const *title, ivec2 res, float fps) { #if defined LOL_USE_EGL && !defined __ANDROID__ # if defined HAVE_BCM_HOST_H @@ -258,13 +257,13 @@ EglApp::EglApp(char const *title, ivec2 res, float fps) : (void)fps; } -void EglApp::ShowPointer(bool show) +void egl::app_data::show_pointer(bool show) { /* FIXME: unimplemented (do we have a mouse pointer anyway? */ (void)show; } -void EglApp::Tick() +void egl::app_data::tick() { /* Tick the renderer, show the frame and clamp to desired framerate. */ ticker::tick_draw(); @@ -273,7 +272,7 @@ void EglApp::Tick() #endif } -EglApp::~EglApp() +egl::app_data::~app_data() { #if defined LOL_USE_EGL && !defined __ANDROID__ eglDestroyContext(data->egl_dpy, data->egl_ctx); @@ -286,7 +285,6 @@ EglApp::~EglApp() XCloseDisplay(data->dpy); # endif #endif - delete data; } } /* namespace lol */ diff --git a/src/application/egl-app.h b/src/application/egl-app.h index 155faee8..d384f54a 100644 --- a/src/application/egl-app.h +++ b/src/application/egl-app.h @@ -19,23 +19,19 @@ #include -namespace lol -{ +#include "application/application.h" -class EglAppData; +namespace lol::egl +{ -class EglApp +class app_data : public app::data { public: - EglApp(char const *title, ivec2 res, float fps); - virtual ~EglApp(); + app_data(char const *title, ivec2 res, float fps); + virtual ~app_data(); - void ShowPointer(bool show); - void Tick(); - -private: - EglAppData *data; + void show_pointer(bool show); + void tick(); }; -} /* namespace lol */ - +} // namespace lol diff --git a/src/application/sdl-app.cpp b/src/application/sdl-app.cpp index c7491f16..edd923e3 100644 --- a/src/application/sdl-app.cpp +++ b/src/application/sdl-app.cpp @@ -54,23 +54,29 @@ sdl::app_display::app_display(char const *title, ivec2 res) for (int i = 0; i < SDL_GetNumVideoDisplays(); ++i) msg::debug("%d: %s\n", i, SDL_GetDisplayName(i)); - // This seems to fix a bug we used to have at context swap. Maybe remove one day. - SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); + int flags = SDL_WINDOW_RESIZABLE; + + if (engine::has_opengl()) + { + flags |= SDL_WINDOW_OPENGL; + + // This seems to fix a bug we used to have at context swap. Maybe remove one day. + SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); #if !defined __EMSCRIPTEN__ && !defined HAVE_GLES_2X - // Ask for GL 3.2 at least - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + // Ask for GL 3.2 at least + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); #if __APPLE__ - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); #endif #if LOL_BUILD_DEBUG - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); #endif #endif + } - int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; if (window_size == ivec2(0)) flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; msg::debug("initialising main window\n"); @@ -88,12 +94,15 @@ sdl::app_display::app_display(char const *title, ivec2 res) // Enable drag-and-drop SDL_EventState(SDL_DROPFILE, SDL_ENABLE); - m_glcontext = SDL_GL_CreateContext(m_window); - SDL_GL_MakeCurrent(m_window, m_glcontext); - msg::info("created GL context: %s\n", glGetString(GL_VERSION)); + if (engine::has_opengl()) + { + m_glcontext = SDL_GL_CreateContext(m_window); + SDL_GL_MakeCurrent(m_window, m_glcontext); + msg::info("created GL context: %s\n", glGetString(GL_VERSION)); - /* Initialise everything */ - Video::Setup(res); //TODO ?? Should it be here ? + // Initialise everything + Video::Setup(res); //TODO ?? Should it be here ? + } #endif } @@ -102,7 +111,9 @@ sdl::app_display::~app_display() #if LOL_USE_SDL if (m_window) { - SDL_GL_DeleteContext(m_glcontext); + if (engine::has_opengl()) + SDL_GL_DeleteContext(m_glcontext); + SDL_DestroyWindow(m_window); } #endif @@ -124,7 +135,7 @@ void sdl::app_display::set_resolution(ivec2 resolution) #endif } -void sdl::app_display::SetPosition(ivec2 position) +void sdl::app_display::set_position(ivec2 position) { #if LOL_USE_SDL SDL_SetWindowPosition(m_window, position.x, position.y); @@ -135,14 +146,16 @@ void sdl::app_display::start_frame() { #if LOL_USE_SDL //TODO: Should we do that: ? - SDL_GL_MakeCurrent(m_window, m_glcontext); + if (engine::has_opengl()) + SDL_GL_MakeCurrent(m_window, m_glcontext); #endif } void sdl::app_display::end_frame() { #if LOL_USE_SDL - SDL_GL_SwapWindow(m_window); + if (engine::has_opengl()) + SDL_GL_SwapWindow(m_window); #endif } @@ -150,7 +163,7 @@ void sdl::app_display::end_frame() // Public sdl::app class // -sdl::app::app(char const *title, ivec2 res, float fps) +sdl::app_data::app_data(char const *title, ivec2 res, float fps) { (void)title; #if LOL_USE_SDL @@ -170,25 +183,24 @@ sdl::app::app(char const *title, ivec2 res, float fps) #endif } -void sdl::app::ShowPointer(bool show) +sdl::app_data::~app_data() { #if LOL_USE_SDL - SDL_ShowCursor(show ? 1 : 0); + SDL_Quit(); #endif } -void sdl::app::Tick() -{ - /* Tick the renderer, show the frame and clamp to desired framerate. */ - Ticker::tick_draw(); -} - -sdl::app::~app() +void sdl::app_data::show_pointer(bool show) { #if LOL_USE_SDL - SDL_Quit(); + SDL_ShowCursor(show ? 1 : 0); #endif } -} /* namespace lol */ +void sdl::app_data::tick() +{ + // Tick the renderer, show the frame and clamp to desired framerate. + ticker::tick_draw(); +} +} // namespace lol diff --git a/src/application/sdl-app.h b/src/application/sdl-app.h index 2858832a..1534f3b0 100644 --- a/src/application/sdl-app.h +++ b/src/application/sdl-app.h @@ -19,6 +19,8 @@ #include +#include "application/application.h" + #if LOL_USE_SDL # if HAVE_SDL2_SDL_H # include @@ -30,32 +32,30 @@ namespace lol::sdl { -class app +class app_data : public lol::app::data { public: - app(char const *title, ivec2 res, float fps); - virtual ~app(); + app_data(char const *title, ivec2 res, float fps); + virtual ~app_data(); - void ShowPointer(bool show); - void Tick(); + virtual void show_pointer(bool show); + virtual void tick(); }; -class app_display +class app_display : public lol::app::display { - friend class lol::ApplicationDisplay; - public: app_display(char const *title, ivec2 resolution); virtual ~app_display(); protected: + void start_frame(); + void end_frame(); + virtual void set_resolution(ivec2 resolution); virtual ivec2 resolution() const; - void SetPosition(ivec2 position); - - void start_frame(); - void end_frame(); + void set_position(ivec2 position); private: #if LOL_USE_SDL diff --git a/src/base/engine.cpp b/src/base/engine.cpp new file mode 100644 index 00000000..aca92e7d --- /dev/null +++ b/src/base/engine.cpp @@ -0,0 +1,30 @@ +// +// Lol Engine +// +// Copyright © 2010—2020 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#include + +#include "lolgl.h" + +namespace lol::engine +{ + +bool has_opengl() +{ +#if defined LOL_USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLES_2X + return true; +#else + return false; +#endif +} + +} // namespace lol::engine + diff --git a/src/lol-core.vcxproj b/src/lol-core.vcxproj index f8b8d535..939339cc 100644 --- a/src/lol-core.vcxproj +++ b/src/lol-core.vcxproj @@ -108,6 +108,7 @@ + diff --git a/src/lol-core.vcxproj.filters b/src/lol-core.vcxproj.filters index e26ade50..152ffdd0 100644 --- a/src/lol-core.vcxproj.filters +++ b/src/lol-core.vcxproj.filters @@ -14,6 +14,9 @@ base + + base + base diff --git a/src/lol/engine-internal.h b/src/lol/engine-internal.h index e0073dbf..b9cf60b8 100644 --- a/src/lol/engine-internal.h +++ b/src/lol/engine-internal.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -17,26 +17,10 @@ // ---------------------------------------------- // -/* Include this as early as possible */ +// Include this as early as possible #if HAVE_CONFIG_H # include "config.h" #endif -/* If using Android, override main() with our version */ -#if __ANDROID__ -# define main lol_android_main -#endif - -/* If using SDL on Windows or OS X, let it override main() */ -#if LOL_USE_SDL && (_WIN32 || __APPLE__) -# include -#endif - -#include -#include - -#if defined _WIN32 -# undef near -# undef far -#endif +#include "engine.h" diff --git a/src/lol/engine.h b/src/lol/engine.h index ba65a8d8..6a8ce219 100644 --- a/src/lol/engine.h +++ b/src/lol/engine.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2016 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -17,7 +17,7 @@ // -------------------------------------- // -/* If using Android, override main() with our version */ +// If using Android, override main() with our version #if __ANDROID__ # define main lol_android_main #endif @@ -27,11 +27,18 @@ # define main lol_nx_main #endif -/* If using SDL on Windows or OS X, let it override main() */ +// If using SDL on Windows or OS X, let it override main() #if LOL_USE_SDL && (_WIN32 || __APPLE__) # include #endif +namespace lol::engine +{ + +bool has_opengl(); + +} + #include #include diff --git a/src/scene.cpp b/src/scene.cpp old mode 100755 new mode 100644 index 34d690f6..03844a98 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -44,7 +44,7 @@ namespace lol std::vector Scene::g_scenes; -static std::vector g_scene_displays; +static std::vector> g_scene_displays; static inline void gpu_marker(char const *message) { @@ -137,12 +137,12 @@ Scene::~Scene() Reset(); } -void Scene::add_display(ApplicationDisplay* display) +void Scene::add_display(std::shared_ptr display) { g_scene_displays.push_back(display); } -ApplicationDisplay *Scene::get_display(int index) +std::shared_ptr Scene::get_display(int index) { return g_scene_displays[index]; } diff --git a/src/scene.h b/src/scene.h index 813ebd4d..769d7010 100644 --- a/src/scene.h +++ b/src/scene.h @@ -79,8 +79,8 @@ private: public: static size_t GetCount(); - static void add_display(ApplicationDisplay* display); - static ApplicationDisplay* get_display(int index = 0); + static void add_display(std::shared_ptr display); + static std::shared_ptr get_display(int index = 0); static bool IsReady(int index = 0); static Scene& GetScene(int index = 0);