This lets us get rid of m_autorelease and m_destroy and we’ll be able to implement init_game/init_draw later, for stuff that must happen on the render thread.legacy
@@ -2,7 +2,7 @@ | |||||
// Lol Engine — Bullet physics test | // Lol Engine — Bullet physics test | ||||
// | // | ||||
// Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -134,7 +134,7 @@ std::string EasyCharacterController::GetName() | |||||
//Physic Tick | //Physic Tick | ||||
void EasyCharacterController::tick_game(float seconds) | void EasyCharacterController::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
//Send final velocity in Bullet | //Send final velocity in Bullet | ||||
{ | { | ||||
@@ -2,7 +2,7 @@ | |||||
// Lol Engine — Bullet physics test | // Lol Engine — Bullet physics test | ||||
// | // | ||||
// Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// © 2012—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -33,7 +33,7 @@ namespace phys | |||||
{ | { | ||||
class EasyCharacterController : public EasyPhysic, | class EasyCharacterController : public EasyPhysic, | ||||
public Entity | |||||
public entity | |||||
{ | { | ||||
friend class Simulation; | friend class Simulation; | ||||
@@ -2,7 +2,7 @@ | |||||
// Lol Engine — Bullet physics test | // Lol Engine — Bullet physics test | ||||
// | // | ||||
// Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// © 2012—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2012—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -65,7 +65,7 @@ struct RayCastResult | |||||
unsigned int m_flags; //??? | unsigned int m_flags; //??? | ||||
}; | }; | ||||
class Simulation : public Entity | |||||
class Simulation : public entity | |||||
{ | { | ||||
public: | public: | ||||
Simulation() : | Simulation() : | ||||
@@ -111,7 +111,7 @@ public: | |||||
virtual void tick_game(float seconds) | virtual void tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
//step the simulation | //step the simulation | ||||
if (m_dynamics_world) | if (m_dynamics_world) | ||||
@@ -73,7 +73,7 @@ protected: | |||||
#if __ANDROID__ | #if __ANDROID__ | ||||
//NOT HANDLED YET | //NOT HANDLED YET | ||||
#elif LOL_USE_SDL | #elif LOL_USE_SDL | ||||
SdlAppDisplay display; | |||||
sdl::app_display display; | |||||
#elif HAVE_GLES_2X | #elif HAVE_GLES_2X | ||||
/* FIXME: this macro is only deactivated if we include "lolgl.h" */ | /* FIXME: this macro is only deactivated if we include "lolgl.h" */ | ||||
//NOT HANDLED YET | //NOT HANDLED YET | ||||
@@ -137,7 +137,7 @@ class ApplicationData | |||||
#if __ANDROID__ | #if __ANDROID__ | ||||
AndroidApp app; | AndroidApp app; | ||||
#elif LOL_USE_SDL | #elif LOL_USE_SDL | ||||
SdlApp app; | |||||
sdl::app app; | |||||
#elif HAVE_GLES_2X | #elif HAVE_GLES_2X | ||||
/* FIXME: this macro is only deactivated if we include "lolgl.h" */ | /* FIXME: this macro is only deactivated if we include "lolgl.h" */ | ||||
EglApp app; | EglApp app; | ||||
@@ -31,24 +31,9 @@ namespace lol | |||||
{ | { | ||||
/* | /* | ||||
* SDL App display implementation class | |||||
* Public sdl::app_display class | |||||
*/ | */ | ||||
class SdlAppDisplayData | |||||
{ | |||||
friend class SdlAppDisplay; | |||||
private: | |||||
#if LOL_USE_SDL | |||||
SDL_Window *m_window; | |||||
SDL_GLContext m_glcontext; | |||||
#endif | |||||
}; | |||||
/* | |||||
* Public SdlApp class | |||||
*/ | |||||
SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) | |||||
: data(new SdlAppDisplayData()) | |||||
sdl::app_display::app_display(char const *title, ivec2 res) | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
ivec2 window_size = res; | ivec2 window_size = res; | ||||
@@ -70,72 +55,70 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) | |||||
int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | ||||
if (window_size == ivec2(0)) | if (window_size == ivec2(0)) | ||||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | ||||
data->m_window = SDL_CreateWindow(title, | |||||
m_window = SDL_CreateWindow(title, | |||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, | SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, | ||||
window_size.x, window_size.y, flags); | window_size.x, window_size.y, flags); | ||||
if (!data->m_window) | |||||
if (!m_window) | |||||
{ | { | ||||
msg::error("cannot create rendering window: %s\n", SDL_GetError()); | msg::error("cannot create rendering window: %s\n", SDL_GetError()); | ||||
SDL_Quit(); | SDL_Quit(); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
SDL_GetWindowSize(data->m_window, &res.x, &res.y); | |||||
SDL_GetWindowSize(m_window, &res.x, &res.y); | |||||
data->m_glcontext = SDL_GL_CreateContext(data->m_window); | |||||
m_glcontext = SDL_GL_CreateContext(m_window); | |||||
/* Initialise everything */ | /* Initialise everything */ | ||||
Video::Setup(res); //TODO ?? Should it be here ? | Video::Setup(res); //TODO ?? Should it be here ? | ||||
#endif | #endif | ||||
} | } | ||||
SdlAppDisplay::~SdlAppDisplay() | |||||
sdl::app_display::~app_display() | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
if (data->m_window) | |||||
if (m_window) | |||||
{ | { | ||||
SDL_GL_DeleteContext(data->m_glcontext); | |||||
SDL_DestroyWindow(data->m_window); | |||||
SDL_GL_DeleteContext(m_glcontext); | |||||
SDL_DestroyWindow(m_window); | |||||
} | } | ||||
#endif | #endif | ||||
delete data; | |||||
} | } | ||||
ivec2 SdlAppDisplay::resolution() const | |||||
ivec2 sdl::app_display::resolution() const | |||||
{ | { | ||||
ivec2 ret(0); | ivec2 ret(0); | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
SDL_GetWindowSize(data->m_window, &ret.x, &ret.y); | |||||
SDL_GetWindowSize(m_window, &ret.x, &ret.y); | |||||
#endif | #endif | ||||
return ret; | return ret; | ||||
} | } | ||||
void SdlAppDisplay::set_resolution(ivec2 resolution) | |||||
void sdl::app_display::set_resolution(ivec2 resolution) | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
SDL_SetWindowSize(data->m_window, resolution.x, resolution.y); | |||||
SDL_SetWindowSize(m_window, resolution.x, resolution.y); | |||||
#endif | #endif | ||||
} | } | ||||
void SdlAppDisplay::SetPosition(ivec2 position) | |||||
void sdl::app_display::SetPosition(ivec2 position) | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
SDL_SetWindowPosition(data->m_window, position.x, position.y); | |||||
SDL_SetWindowPosition(m_window, position.x, position.y); | |||||
#endif | #endif | ||||
} | } | ||||
void SdlAppDisplay::Enable() | |||||
void sdl::app_display::Enable() | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
//TODO: Should we do that: ? | //TODO: Should we do that: ? | ||||
SDL_GL_MakeCurrent(data->m_window, data->m_glcontext); | |||||
SDL_GL_MakeCurrent(m_window, m_glcontext); | |||||
#endif | #endif | ||||
} | } | ||||
void SdlAppDisplay::Disable() | |||||
void sdl::app_display::Disable() | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
SDL_GL_SwapWindow(data->m_window); | |||||
SDL_GL_SwapWindow(m_window); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -152,24 +135,9 @@ const char* SceneDisplay::GetPhysicalName(int index) | |||||
#endif | #endif | ||||
/* | /* | ||||
* SDL App implementation class | |||||
*/ | |||||
class SdlAppData | |||||
{ | |||||
friend class SdlApp; | |||||
private: | |||||
#if LOL_USE_SDL | |||||
SDL_Window *m_window; | |||||
SDL_GLContext m_glcontext; | |||||
#endif | |||||
}; | |||||
/* | |||||
* Public SdlApp class | |||||
* Public sdl::app class | |||||
*/ | */ | ||||
SdlApp::SdlApp(char const *title, ivec2 res, float fps) : | |||||
data(new SdlAppData()) | |||||
sdl::app::app(char const *title, ivec2 res, float fps) | |||||
{ | { | ||||
UNUSED(title); | UNUSED(title); | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
@@ -189,25 +157,24 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : | |||||
#endif | #endif | ||||
} | } | ||||
void SdlApp::ShowPointer(bool show) | |||||
void sdl::app::ShowPointer(bool show) | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
SDL_ShowCursor(show ? 1 : 0); | SDL_ShowCursor(show ? 1 : 0); | ||||
#endif | #endif | ||||
} | } | ||||
void SdlApp::Tick() | |||||
void sdl::app::Tick() | |||||
{ | { | ||||
/* Tick the renderer, show the frame and clamp to desired framerate. */ | /* Tick the renderer, show the frame and clamp to desired framerate. */ | ||||
Ticker::tick_draw(); | Ticker::tick_draw(); | ||||
} | } | ||||
SdlApp::~SdlApp() | |||||
sdl::app::~app() | |||||
{ | { | ||||
#if LOL_USE_SDL | #if LOL_USE_SDL | ||||
SDL_Quit(); | SDL_Quit(); | ||||
#endif | #endif | ||||
delete data; | |||||
} | } | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||||
// 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—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// 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 | #pragma once | ||||
@@ -17,19 +19,37 @@ | |||||
#include <lol/math/vector.h> | #include <lol/math/vector.h> | ||||
#if LOL_USE_SDL | |||||
# if HAVE_SDL2_SDL_H | |||||
# include <SDL2/SDL.h> | |||||
# elif HAVE_SDL_H | |||||
# include <SDL.h> | |||||
# endif | |||||
#endif | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
//----------------------------------------------------------------------------- | |||||
class SdlAppDisplayData; | |||||
namespace sdl | |||||
{ | |||||
class app | |||||
{ | |||||
public: | |||||
app(char const *title, ivec2 res, float fps); | |||||
virtual ~app(); | |||||
void ShowPointer(bool show); | |||||
void Tick(); | |||||
}; | |||||
class SdlAppDisplay | |||||
class app_display | |||||
{ | { | ||||
friend class ApplicationDisplay; | friend class ApplicationDisplay; | ||||
public: | public: | ||||
SdlAppDisplay(char const *title, ivec2 resolution); | |||||
virtual ~SdlAppDisplay(); | |||||
app_display(char const *title, ivec2 resolution); | |||||
virtual ~app_display(); | |||||
protected: | protected: | ||||
virtual void set_resolution(ivec2 resolution); | virtual void set_resolution(ivec2 resolution); | ||||
@@ -41,24 +61,13 @@ protected: | |||||
void Disable(); | void Disable(); | ||||
private: | private: | ||||
SdlAppDisplayData *data; | |||||
#if LOL_USE_SDL | |||||
SDL_Window *m_window; | |||||
SDL_GLContext m_glcontext; | |||||
#endif | |||||
}; | }; | ||||
//----------------------------------------------------------------------------- | |||||
class SdlAppData; | |||||
class SdlApp | |||||
{ | |||||
public: | |||||
SdlApp(char const *title, ivec2 res, float fps); | |||||
virtual ~SdlApp(); | |||||
void ShowPointer(bool show); | |||||
void Tick(); | |||||
private: | |||||
SdlAppData *data; | |||||
}; | |||||
} /* namespace sdl */ | |||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -95,7 +95,7 @@ sample::~sample() | |||||
void sample::tick_game(float seconds) | void sample::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
} | } | ||||
std::string sample::GetName() const | std::string sample::GetName() const | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// 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—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// 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 <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
@@ -52,7 +54,7 @@ DebugFps::DebugFps(int x, int y) | |||||
void DebugFps::tick_game(float seconds) | void DebugFps::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
char buf[1024]; | char buf[1024]; | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// 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—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// 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 | #pragma once | ||||
@@ -22,7 +24,7 @@ namespace lol | |||||
class DebugFpsData; | class DebugFpsData; | ||||
class DebugFps : public Entity | |||||
class DebugFps : public entity | |||||
{ | { | ||||
public: | public: | ||||
DebugFps(int x, int y); | DebugFps(int x, int y); | ||||
@@ -61,12 +61,12 @@ DebugRecord::DebugRecord(std::string const &path, float fps) | |||||
void DebugRecord::tick_game(float seconds) | void DebugRecord::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
} | } | ||||
void DebugRecord::tick_draw(float seconds, Scene &scene) | void DebugRecord::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
ivec2 size = Video::GetSize(); | ivec2 size = Video::GetSize(); | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -24,7 +24,7 @@ namespace lol | |||||
class DebugRecordData; | class DebugRecordData; | ||||
class DebugRecord : public Entity | |||||
class DebugRecord : public entity | |||||
{ | { | ||||
public: | public: | ||||
DebugRecord(std::string const &path, float fps); | DebugRecord(std::string const &path, float fps); | ||||
@@ -45,7 +45,7 @@ DebugStats::DebugStats(char const *path) | |||||
void DebugStats::tick_game(float seconds) | void DebugStats::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
fprintf(data->fp, "%i %f %f %f %f\n", | fprintf(data->fp, "%i %f %f %f %f\n", | ||||
Ticker::GetFrameNum(), | Ticker::GetFrameNum(), | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// 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—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// 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 | #pragma once | ||||
@@ -22,7 +24,7 @@ namespace lol | |||||
class DebugStatsData; | class DebugStatsData; | ||||
class DebugStats : public Entity | |||||
class DebugStats : public entity | |||||
{ | { | ||||
public: | public: | ||||
DebugStats(char const *path); | DebugStats(char const *path); | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// 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—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// 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 <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
@@ -61,12 +63,12 @@ void Emitter::tick_game(float seconds) | |||||
} | } | ||||
} | } | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
} | } | ||||
void Emitter::tick_draw(float seconds, Scene &scene) | void Emitter::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
for (int i = 0; i < data->nparticles; i++) | for (int i = 0; i < data->nparticles; i++) | ||||
scene.AddTile(data->tileset, data->particles[i], | scene.AddTile(data->tileset, data->particles[i], | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// 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—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// 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 | #pragma once | ||||
@@ -23,7 +25,7 @@ namespace lol | |||||
class EmitterData; | class EmitterData; | ||||
class Emitter : public Entity | |||||
class Emitter : public entity | |||||
{ | { | ||||
public: | public: | ||||
Emitter(TileSet *tileset, vec3 gravity); | Emitter(TileSet *tileset, vec3 gravity); | ||||
@@ -18,13 +18,10 @@ namespace lol | |||||
{ | { | ||||
/* | /* | ||||
* Public Entity class | |||||
* Public entity class | |||||
*/ | */ | ||||
Entity::Entity() : | |||||
m_initstate(InitState::Ready), | |||||
m_ref(0), | |||||
m_destroy(0) | |||||
entity::entity() | |||||
{ | { | ||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
m_tickstate = tickable::state::idle; | m_tickstate = tickable::state::idle; | ||||
@@ -36,28 +33,20 @@ Entity::Entity() : | |||||
Ticker::Register(this); | Ticker::Register(this); | ||||
} | } | ||||
Entity::~Entity() | |||||
entity::~entity() | |||||
{ | { | ||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
if (!m_destroy) | |||||
if (!has_flags(flags::destroying)) | |||||
msg::error("entity destructor called directly\n"); | msg::error("entity destructor called directly\n"); | ||||
#endif | #endif | ||||
} | } | ||||
std::string Entity::GetName() const | |||||
std::string entity::GetName() const | |||||
{ | { | ||||
return "<entity>"; | return "<entity>"; | ||||
} | } | ||||
void Entity::InitGame() | |||||
{ | |||||
} | |||||
void Entity::InitDraw() | |||||
{ | |||||
} | |||||
void Entity::tick_game(float seconds) | |||||
void entity::tick_game(float seconds) | |||||
{ | { | ||||
UNUSED(seconds); | UNUSED(seconds); | ||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
@@ -67,7 +56,7 @@ void Entity::tick_game(float seconds) | |||||
#endif | #endif | ||||
} | } | ||||
void Entity::tick_draw(float seconds, Scene &scene) | |||||
void entity::tick_draw(float seconds, Scene &scene) | |||||
{ | { | ||||
UNUSED(seconds, scene); | UNUSED(seconds, scene); | ||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
@@ -13,7 +13,7 @@ | |||||
#pragma once | #pragma once | ||||
// | // | ||||
// The Entity class | |||||
// The entity class | |||||
// ---------------- | // ---------------- | ||||
// Entities are objects that can be ticked by the game loop and/or the render | // Entities are objects that can be ticked by the game loop and/or the render | ||||
// loop. Entities are implemented as one or several linked lists. See the | // loop. Entities are implemented as one or several linked lists. See the | ||||
@@ -27,23 +27,7 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
struct InitState | |||||
{ | |||||
enum Value | |||||
{ | |||||
Unknown, | |||||
Error, | |||||
NeedInitDraw, | |||||
NeedInitGame, | |||||
Ready, | |||||
} | |||||
m_value; | |||||
inline InitState(Value v) : m_value(v) {} | |||||
inline operator Value() { return m_value; } | |||||
}; | |||||
class Entity | |||||
class entity | |||||
{ | { | ||||
friend class Scene; | friend class Scene; | ||||
friend class ticker; | friend class ticker; | ||||
@@ -52,22 +36,33 @@ class Entity | |||||
public: | public: | ||||
virtual std::string GetName() const; | virtual std::string GetName() const; | ||||
inline bool IsTicked() { return !!m_ref && !m_autorelease; } | |||||
protected: | |||||
Entity(); | |||||
virtual ~Entity(); | |||||
inline bool IsTicked() { return !!m_ref && !has_flags(flags::autorelease); } | |||||
inline int IsDestroying() { return m_destroy; } | |||||
enum class flags : uint16_t | |||||
{ | |||||
none = 0, | |||||
init_game = 1 << 0, | |||||
init_draw = 1 << 1, | |||||
fini_game = 1 << 2, | |||||
fini_draw = 1 << 4, | |||||
destroying = 1 << 5, | |||||
autorelease = 1 << 6, | |||||
}; | |||||
inline void add_flags(flags f); | |||||
inline void remove_flags(flags f); | |||||
inline bool has_flags(flags f); | |||||
protected: | |||||
entity(); | |||||
virtual ~entity(); | |||||
virtual void InitGame(); | |||||
virtual void InitDraw(); | |||||
virtual bool init_game() { return true; } | |||||
virtual bool init_draw() { return true; } | |||||
virtual void tick_game(float seconds); | virtual void tick_game(float seconds); | ||||
virtual void tick_draw(float seconds, class Scene &scene); | virtual void tick_draw(float seconds, class Scene &scene); | ||||
/* The initialisation state */ | |||||
InitState m_initstate; | |||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
tickable::state m_tickstate; | tickable::state m_tickstate; | ||||
#endif | #endif | ||||
@@ -76,10 +71,30 @@ protected: | |||||
tickable::group::draw m_drawgroup; | tickable::group::draw m_drawgroup; | ||||
private: | private: | ||||
int m_ref, m_autorelease, m_destroy; | |||||
flags m_flags = flags::none; | |||||
int m_ref = 0; | |||||
uint64_t m_scene_mask = 0; | uint64_t m_scene_mask = 0; | ||||
}; | }; | ||||
static inline entity::flags operator |(entity::flags a, entity::flags b) | |||||
{ | |||||
return (entity::flags)((uint16_t)a | (uint16_t)b); | |||||
} | |||||
static inline entity::flags operator &(entity::flags a, entity::flags b) | |||||
{ | |||||
return (entity::flags)((uint16_t)a & (uint16_t)b); | |||||
} | |||||
static inline entity::flags operator ^(entity::flags a, entity::flags b) | |||||
{ | |||||
return (entity::flags)((uint16_t)a ^ (uint16_t)b); | |||||
} | |||||
inline void entity::add_flags(entity::flags f) { m_flags = m_flags | f; } | |||||
inline void entity::remove_flags(entity::flags f) { m_flags = (m_flags | f) ^ f; } | |||||
inline bool entity::has_flags(entity::flags f) { return (m_flags & f) != flags::none; } | |||||
template<typename T> struct entity_dict | template<typename T> struct entity_dict | ||||
{ | { | ||||
T *get(std::string const &key) | T *get(std::string const &key) | ||||
@@ -106,5 +121,8 @@ template<typename T> struct entity_dict | |||||
std::map<T*, std::string> m_cache2; | std::map<T*, std::string> m_cache2; | ||||
}; | }; | ||||
// The old API | |||||
typedef entity Entity; | |||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -62,8 +62,8 @@ private: | |||||
std::unordered_set<std::shared_ptr<tickable>> m_tickables; | std::unordered_set<std::shared_ptr<tickable>> m_tickables; | ||||
/* Entity management */ | /* Entity management */ | ||||
array<Entity *> DEPRECATED_m_todolist, DEPRECATED_m_todolist_delayed, DEPRECATED_m_autolist; | |||||
array<Entity *> DEPRECATED_m_list[(int)tickable::group::all::end]; | |||||
array<entity *> DEPRECATED_m_todolist, DEPRECATED_m_todolist_delayed, DEPRECATED_m_autolist; | |||||
array<entity *> DEPRECATED_m_list[(int)tickable::group::all::end]; | |||||
array<int> DEPRECATED_m_scenes[(int)tickable::group::all::end]; | array<int> DEPRECATED_m_scenes[(int)tickable::group::all::end]; | ||||
int DEPRECATED_nentities; | int DEPRECATED_nentities; | ||||
@@ -114,7 +114,7 @@ void ticker::remove(std::shared_ptr<tickable> entity) | |||||
// Old API for entities | // Old API for entities | ||||
// | // | ||||
void Ticker::Register(Entity *entity) | |||||
void Ticker::Register(entity *entity) | |||||
{ | { | ||||
/* If we are called from its constructor, the object's vtable is not | /* If we are called from its constructor, the object's vtable is not | ||||
* ready yet, so we do not know which group this entity belongs to. Wait | * ready yet, so we do not know which group this entity belongs to. Wait | ||||
@@ -123,22 +123,22 @@ void Ticker::Register(Entity *entity) | |||||
/* Objects are autoreleased by default. Put them in a list. */ | /* Objects are autoreleased by default. Put them in a list. */ | ||||
data->DEPRECATED_m_autolist.push(entity); | data->DEPRECATED_m_autolist.push(entity); | ||||
entity->m_autorelease = 1; | |||||
entity->add_flags(entity::flags::autorelease); | |||||
entity->m_ref = 1; | entity->m_ref = 1; | ||||
data->DEPRECATED_nentities++; | data->DEPRECATED_nentities++; | ||||
} | } | ||||
void Ticker::Ref(Entity *entity) | |||||
void Ticker::Ref(entity *entity) | |||||
{ | { | ||||
ASSERT(entity, "dereferencing nullptr entity\n"); | ASSERT(entity, "dereferencing nullptr entity\n"); | ||||
ASSERT(!entity->m_destroy, | |||||
ASSERT(!entity->has_flags(entity::flags::destroying), | |||||
"referencing entity scheduled for destruction %s\n", | "referencing entity scheduled for destruction %s\n", | ||||
entity->GetName().c_str()); | entity->GetName().c_str()); | ||||
if (entity->m_autorelease) | |||||
if (entity->has_flags(entity::flags::autorelease)) | |||||
{ | { | ||||
/* Get the entity out of the m_autorelease list. This is usually | |||||
/* Get the entity out of the autorelease list. This is usually | |||||
* very fast since the last entry in autolist is the last | * very fast since the last entry in autolist is the last | ||||
* registered entity. */ | * registered entity. */ | ||||
for (int i = data->DEPRECATED_m_autolist.count(); i--; ) | for (int i = data->DEPRECATED_m_autolist.count(); i--; ) | ||||
@@ -149,19 +149,19 @@ void Ticker::Ref(Entity *entity) | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
entity->m_autorelease = 0; | |||||
entity->remove_flags(entity::flags::autorelease); | |||||
} | } | ||||
else | else | ||||
entity->m_ref++; | entity->m_ref++; | ||||
} | } | ||||
int Ticker::Unref(Entity *entity) | |||||
int Ticker::Unref(entity *entity) | |||||
{ | { | ||||
ASSERT(entity, "dereferencing null entity\n"); | ASSERT(entity, "dereferencing null entity\n"); | ||||
ASSERT(entity->m_ref > 0, "dereferencing unreferenced entity %s\n", | |||||
entity->GetName().c_str()); | |||||
ASSERT(!entity->m_autorelease, "dereferencing autoreleased entity %s\n", | |||||
entity->GetName().c_str()); | |||||
ASSERT(entity->m_ref > 0, | |||||
"dereferencing unreferenced entity %s\n", entity->GetName().c_str()); | |||||
ASSERT(!entity->has_flags(entity::flags::autorelease), | |||||
"dereferencing autoreleased entity %s\n", entity->GetName().c_str()); | |||||
return --entity->m_ref; | return --entity->m_ref; | ||||
} | } | ||||
@@ -241,9 +241,9 @@ void ticker_data::GameThreadTick() | |||||
for (int i = 0; i < data->DEPRECATED_m_list[g].count(); ++i) | for (int i = 0; i < data->DEPRECATED_m_list[g].count(); ++i) | ||||
{ | { | ||||
Entity *e = data->DEPRECATED_m_list[g][i]; | |||||
entity *e = data->DEPRECATED_m_list[g][i]; | |||||
msg::debug(" \\-- [%p] %s (m_ref %d, destroy %d)\n", | msg::debug(" \\-- [%p] %s (m_ref %d, destroy %d)\n", | ||||
e, e->GetName().c_str(), e->m_ref, e->m_destroy); | |||||
e, e->GetName().c_str(), e->m_ref, e->has_flags(entity::flags::destroying)); | |||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
@@ -292,7 +292,7 @@ void ticker_data::GameThreadTick() | |||||
for (int g = 0; g < (int)tickable::group::all::end && n < data->panic; ++g) | for (int g = 0; g < (int)tickable::group::all::end && n < data->panic; ++g) | ||||
for (int i = 0; i < data->DEPRECATED_m_list[g].count() && n < data->panic; ++i) | for (int i = 0; i < data->DEPRECATED_m_list[g].count() && n < data->panic; ++i) | ||||
{ | { | ||||
Entity * e = data->DEPRECATED_m_list[g][i]; | |||||
entity * e = data->DEPRECATED_m_list[g][i]; | |||||
if (e->m_ref) | if (e->m_ref) | ||||
{ | { | ||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
@@ -315,15 +315,15 @@ void ticker_data::GameThreadTick() | |||||
/* Garbage collect objects that can be destroyed. We can do this | /* Garbage collect objects that can be destroyed. We can do this | ||||
* before inserting awaiting objects, because only objects already | * before inserting awaiting objects, because only objects already | ||||
* in the tick lists can be marked for destruction. */ | * in the tick lists can be marked for destruction. */ | ||||
array<Entity*> destroy_list; | |||||
array<entity*> destroy_list; | |||||
bool do_reserve = true; | bool do_reserve = true; | ||||
for (int g = 0; g < (int)tickable::group::all::end; ++g) | for (int g = 0; g < (int)tickable::group::all::end; ++g) | ||||
{ | { | ||||
for (int i = data->DEPRECATED_m_list[g].count(); i--;) | for (int i = data->DEPRECATED_m_list[g].count(); i--;) | ||||
{ | { | ||||
Entity *e = data->DEPRECATED_m_list[g][i]; | |||||
entity *e = data->DEPRECATED_m_list[g][i]; | |||||
if (e->m_destroy && g < (int)tickable::group::game::end) | |||||
if (e->has_flags(entity::flags::destroying) && g < (int)tickable::group::game::end) | |||||
{ | { | ||||
/* Game tick list: | /* Game tick list: | ||||
* If entity is to be destroyed, remove it */ | * If entity is to be destroyed, remove it */ | ||||
@@ -335,7 +335,7 @@ void ticker_data::GameThreadTick() | |||||
} | } | ||||
destroy_list.push_unique(e); | destroy_list.push_unique(e); | ||||
} | } | ||||
else if (e->m_destroy) | |||||
else if (e->has_flags(entity::flags::destroying)) | |||||
{ | { | ||||
/* Draw tick list: | /* Draw tick list: | ||||
* If entity is to be destroyed, | * If entity is to be destroyed, | ||||
@@ -360,21 +360,21 @@ void ticker_data::GameThreadTick() | |||||
else | else | ||||
{ | { | ||||
if (e->m_ref <= 0 && g >= (int)tickable::group::draw::begin) | if (e->m_ref <= 0 && g >= (int)tickable::group::draw::begin) | ||||
e->m_destroy = 1; | |||||
e->add_flags(entity::flags::destroying); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
if (!!destroy_list.count()) | if (!!destroy_list.count()) | ||||
{ | { | ||||
data->DEPRECATED_nentities -= destroy_list.count(); | data->DEPRECATED_nentities -= destroy_list.count(); | ||||
for (Entity* e : destroy_list) | |||||
for (entity* e : destroy_list) | |||||
delete e; | delete e; | ||||
} | } | ||||
/* Insert waiting objects into the appropriate lists */ | /* Insert waiting objects into the appropriate lists */ | ||||
while (data->DEPRECATED_m_todolist.count()) | while (data->DEPRECATED_m_todolist.count()) | ||||
{ | { | ||||
Entity *e = data->DEPRECATED_m_todolist.last(); | |||||
entity *e = data->DEPRECATED_m_todolist.last(); | |||||
//If the entity has no mask, default it | //If the entity has no mask, default it | ||||
if (e->m_scene_mask == 0) | if (e->m_scene_mask == 0) | ||||
@@ -404,7 +404,7 @@ void ticker_data::GameThreadTick() | |||||
} | } | ||||
// Initialize the entity | // Initialize the entity | ||||
e->InitGame(); | |||||
e->init_game(); | |||||
} | } | ||||
data->DEPRECATED_m_todolist = data->DEPRECATED_m_todolist_delayed; | data->DEPRECATED_m_todolist = data->DEPRECATED_m_todolist_delayed; | ||||
@@ -415,8 +415,8 @@ void ticker_data::GameThreadTick() | |||||
{ | { | ||||
for (int i = 0; i < data->DEPRECATED_m_list[g].count() && !data->quit /* Stop as soon as required */; ++i) | for (int i = 0; i < data->DEPRECATED_m_list[g].count() && !data->quit /* Stop as soon as required */; ++i) | ||||
{ | { | ||||
Entity *e = data->DEPRECATED_m_list[g][i]; | |||||
if (!e->m_destroy) | |||||
entity *e = data->DEPRECATED_m_list[g][i]; | |||||
if (!e->has_flags(entity::flags::destroying)) | |||||
{ | { | ||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
if (e->m_tickstate != tickable::state::idle) | if (e->m_tickstate != tickable::state::idle) | ||||
@@ -468,9 +468,9 @@ void ticker_data::DrawThreadTick() | |||||
for (int i = 0; i < data->DEPRECATED_m_list[g].count() && !data->quit /* Stop as soon as required */; ++i) | for (int i = 0; i < data->DEPRECATED_m_list[g].count() && !data->quit /* Stop as soon as required */; ++i) | ||||
{ | { | ||||
Entity *e = data->DEPRECATED_m_list[g][i]; | |||||
entity *e = data->DEPRECATED_m_list[g][i]; | |||||
if (!e->m_destroy) | |||||
if (!e->has_flags(entity::flags::destroying)) | |||||
{ | { | ||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
if (e->m_tickstate != tickable::state::idle) | if (e->m_tickstate != tickable::state::idle) | ||||
@@ -506,13 +506,13 @@ void ticker_data::DiskThreadTick() | |||||
; | ; | ||||
} | } | ||||
void Ticker::SetState(Entity * /* entity */, uint32_t /* state */) | |||||
void Ticker::SetState(entity * /* entity */, uint32_t /* state */) | |||||
{ | { | ||||
} | } | ||||
void Ticker::SetStateWhenMatch(Entity * /* entity */, uint32_t /* state */, | |||||
Entity * /* other_entity */, uint32_t /* other_state */) | |||||
void Ticker::SetStateWhenMatch(entity * /* entity */, uint32_t /* state */, | |||||
entity * /* other_entity */, uint32_t /* other_state */) | |||||
{ | { | ||||
} | } | ||||
@@ -592,7 +592,7 @@ int Ticker::GetFrameNum() | |||||
void Ticker::Shutdown() | void Ticker::Shutdown() | ||||
{ | { | ||||
/* We're bailing out. Release all m_autorelease objects. */ | |||||
/* We're bailing out. Release all autorelease objects. */ | |||||
while (data->DEPRECATED_m_autolist.count()) | while (data->DEPRECATED_m_autolist.count()) | ||||
{ | { | ||||
data->DEPRECATED_m_autolist.last()->m_ref--; | data->DEPRECATED_m_autolist.last()->m_ref--; | ||||
@@ -37,9 +37,9 @@ public: | |||||
static void remove(std::shared_ptr<tickable> entity); | static void remove(std::shared_ptr<tickable> entity); | ||||
// The old API | // The old API | ||||
static void Register(class Entity *entity); | |||||
static void Ref(class Entity *entity); | |||||
static int Unref(class Entity *entity); | |||||
static void Register(class entity *entity); | |||||
static void Ref(class entity *entity); | |||||
static int Unref(class entity *entity); | |||||
static void StartBenchmark(); | static void StartBenchmark(); | ||||
static void StopBenchmark(); | static void StopBenchmark(); | ||||
@@ -47,9 +47,9 @@ public: | |||||
static void StopRecording(); | static void StopRecording(); | ||||
static int GetFrameNum(); | static int GetFrameNum(); | ||||
static void SetState(class Entity *entity, uint32_t state); | |||||
static void SetStateWhenMatch(class Entity *entity, uint32_t state, | |||||
class Entity *other_entity, uint32_t other_state); | |||||
static void SetState(class entity *entity, uint32_t state); | |||||
static void SetStateWhenMatch(class entity *entity, uint32_t state, | |||||
class entity *other_entity, uint32_t other_state); | |||||
static void Shutdown(); | static void Shutdown(); | ||||
static int Finished(); | static int Finished(); | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -41,12 +41,12 @@ std::string WorldEntity::GetName() const | |||||
void WorldEntity::tick_game(float seconds) | void WorldEntity::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
} | } | ||||
void WorldEntity::tick_draw(float seconds, Scene &scene) | void WorldEntity::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
} | } | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -24,7 +24,7 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
class WorldEntity : public Entity | |||||
class WorldEntity : public entity | |||||
{ | { | ||||
public: | public: | ||||
virtual std::string GetName() const; | virtual std::string GetName() const; | ||||
@@ -71,7 +71,7 @@ Font::~Font() | |||||
void Font::tick_draw(float seconds, Scene &scene) | void Font::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
if (data->tileset->GetTexture()) | if (data->tileset->GetTexture()) | ||||
{ | { | ||||
@@ -24,7 +24,7 @@ namespace lol | |||||
class FontData; | class FontData; | ||||
class Font : public Entity | |||||
class Font : public entity | |||||
{ | { | ||||
public: | public: | ||||
static Font *create(std::string const &path); | static Font *create(std::string const &path); | ||||
@@ -34,7 +34,7 @@ protected: | |||||
Font(std::string const &path); | Font(std::string const &path); | ||||
~Font(); | ~Font(); | ||||
/* Inherited from Entity */ | |||||
/* Inherited from entity */ | |||||
virtual std::string GetName() const; | virtual std::string GetName() const; | ||||
virtual void tick_draw(float seconds, Scene &scene); | virtual void tick_draw(float seconds, Scene &scene); | ||||
@@ -48,12 +48,12 @@ Gradient::Gradient(vec3 aa, vec3 bb) | |||||
void Gradient::tick_game(float seconds) | void Gradient::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
} | } | ||||
void Gradient::tick_draw(float seconds, Scene &scene) | void Gradient::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
float const vertex[] = { m_aabb.aa.x, m_aabb.aa.y, 0.0f, | float const vertex[] = { m_aabb.aa.x, m_aabb.aa.y, 0.0f, | ||||
m_aabb.bb.x, m_aabb.aa.y, 0.0f, | m_aabb.bb.x, m_aabb.aa.y, 0.0f, | ||||
@@ -27,7 +27,7 @@ namespace lol | |||||
class sample_data; | class sample_data; | ||||
class sample : public Entity | |||||
class sample : public entity | |||||
{ | { | ||||
public: | public: | ||||
static sample *create(std::string const &path); | static sample *create(std::string const &path); | ||||
@@ -37,7 +37,7 @@ protected: | |||||
sample(std::string const &path); | sample(std::string const &path); | ||||
virtual ~sample(); | virtual ~sample(); | ||||
/* Inherited from Entity */ | |||||
/* Inherited from entity */ | |||||
virtual std::string GetName() const; | virtual std::string GetName() const; | ||||
virtual void tick_game(float seconds); | virtual void tick_game(float seconds); | ||||
@@ -211,12 +211,12 @@ Scene& Scene::GetScene(int index) | |||||
return *g_scenes[index]; | return *g_scenes[index]; | ||||
} | } | ||||
void Scene::Link(Entity* entity) | |||||
void Scene::Link(entity* entity) | |||||
{ | { | ||||
entity->m_scene_mask |= m_mask_id; | entity->m_scene_mask |= m_mask_id; | ||||
} | } | ||||
bool Scene::IsRelevant(Entity* entity) | |||||
bool Scene::IsRelevant(entity* entity) | |||||
{ | { | ||||
return !!(entity->m_scene_mask & m_mask_id); | return !!(entity->m_scene_mask & m_mask_id); | ||||
} | } | ||||
@@ -121,8 +121,8 @@ public: | |||||
public: | public: | ||||
//TODO: don't like the name | //TODO: don't like the name | ||||
void Link(Entity* entity); | |||||
bool IsRelevant(Entity* entity); | |||||
void Link(entity* entity); | |||||
bool IsRelevant(entity* entity); | |||||
public: | public: | ||||
Camera* GetCamera(int cam_idx = -1); | Camera* GetCamera(int cam_idx = -1); | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// 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—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// 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 <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
@@ -39,12 +41,12 @@ Sprite::Sprite(TileSet *tileset, int id) | |||||
void Sprite::tick_game(float seconds) | void Sprite::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
} | } | ||||
void Sprite::tick_draw(float seconds, Scene &scene) | void Sprite::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
scene.AddTile(data->tileset, data->id, m_position, vec2(1.0f), 0.0f); | scene.AddTile(data->tileset, data->id, m_position, vec2(1.0f), 0.0f); | ||||
} | } | ||||
@@ -95,7 +95,7 @@ ivec2 Text::GetFontSize() | |||||
void Text::tick_draw(float seconds, Scene &scene) | void Text::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
if (auto length = data->m_text.length()) | if (auto length = data->m_text.length()) | ||||
{ | { | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -33,7 +33,7 @@ enum class TextAlign | |||||
Center, | Center, | ||||
}; | }; | ||||
class Text : public Entity | |||||
class Text : public entity | |||||
{ | { | ||||
public: | public: | ||||
Text(std::string const &text, char const *font); | Text(std::string const &text, char const *font); | ||||
@@ -91,7 +91,7 @@ void TextureImage::tick_draw(float seconds, Scene &scene) | |||||
{ | { | ||||
super::tick_draw(seconds, scene); | super::tick_draw(seconds, scene); | ||||
if (IsDestroying()) | |||||
if (has_flags(entity::flags::destroying)) | |||||
{ | { | ||||
if (m_data->m_image) | if (m_data->m_image) | ||||
{ | { | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -33,9 +33,9 @@ namespace lol | |||||
class TextureImageData; | class TextureImageData; | ||||
class TextureImage : public Entity | |||||
class TextureImage : public entity | |||||
{ | { | ||||
typedef Entity super; | |||||
typedef entity super; | |||||
protected: | protected: | ||||
virtual TextureImageData* GetNewData(); | virtual TextureImageData* GetNewData(); | ||||
@@ -53,7 +53,7 @@ protected: | |||||
virtual void tick_draw(float seconds, Scene &scene); | virtual void tick_draw(float seconds, Scene &scene); | ||||
public: | public: | ||||
/* Inherited from Entity */ | |||||
/* Inherited from entity */ | |||||
virtual std::string GetName() const; | virtual std::string GetName() const; | ||||
void UpdateTexture(image* img); | void UpdateTexture(image* img); | ||||
@@ -178,7 +178,7 @@ void TileSet::Init(std::string const &path, Image* image) | |||||
m_data->m_name = "<tileset> " + path; | m_data->m_name = "<tileset> " + path; | ||||
} | } | ||||
//Inherited from Entity ------------------------------------------------------- | |||||
//Inherited from entity ------------------------------------------------------- | |||||
std::string TileSet::GetName() const | std::string TileSet::GetName() const | ||||
{ | { | ||||
return m_data->m_name; | return m_data->m_name; | ||||
@@ -62,7 +62,7 @@ protected: | |||||
virtual void Init(std::string const &path, image* img); | virtual void Init(std::string const &path, image* img); | ||||
public: | public: | ||||
/* Inherited from Entity */ | |||||
/* Inherited from entity */ | |||||
virtual std::string GetName() const; | virtual std::string GetName() const; | ||||
/* New methods */ | /* New methods */ | ||||
@@ -87,7 +87,7 @@ D3d9Input::~D3d9Input() | |||||
void D3d9Input::tick_game(float seconds) | void D3d9Input::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
#if defined LOL_USE_XINPUT | #if defined LOL_USE_XINPUT | ||||
for (int i = 0; i < m_data->m_joysticks.count(); i++) | for (int i = 0; i < m_data->m_joysticks.count(); i++) | ||||
@@ -120,7 +120,7 @@ void D3d9Input::tick_game(float seconds) | |||||
void D3d9Input::tick_draw(float seconds, Scene &scene) | void D3d9Input::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
} | } | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// 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—2019 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// 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 | #pragma once | ||||
@@ -22,7 +24,7 @@ namespace lol | |||||
class D3d9InputData; | class D3d9InputData; | ||||
class D3d9Input : public Entity | |||||
class D3d9Input : public entity | |||||
{ | { | ||||
public: | public: | ||||
D3d9Input(); | D3d9Input(); | ||||
@@ -41,7 +41,7 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
class gui : public Entity | |||||
class gui : public entity | |||||
{ | { | ||||
public: | public: | ||||
gui(ImFontAtlas *shared_font_atlas); | gui(ImFontAtlas *shared_font_atlas); | ||||
@@ -54,7 +54,7 @@ public: | |||||
static void refresh_fonts(); | static void refresh_fonts(); | ||||
private: | private: | ||||
typedef Entity super; | |||||
typedef entity super; | |||||
protected: | protected: | ||||
virtual void tick_game(float seconds); | virtual void tick_game(float seconds); | ||||
@@ -110,7 +110,7 @@ SdlInput::~SdlInput() | |||||
void SdlInput::tick_game(float seconds) | void SdlInput::tick_game(float seconds) | ||||
{ | { | ||||
Entity::tick_game(seconds); | |||||
entity::tick_game(seconds); | |||||
if (!m_tick_in_draw_thread) | if (!m_tick_in_draw_thread) | ||||
tick(seconds); | tick(seconds); | ||||
@@ -118,7 +118,7 @@ void SdlInput::tick_game(float seconds) | |||||
void SdlInput::tick_draw(float seconds, Scene &scene) | void SdlInput::tick_draw(float seconds, Scene &scene) | ||||
{ | { | ||||
Entity::tick_draw(seconds, scene); | |||||
entity::tick_draw(seconds, scene); | |||||
if (m_tick_in_draw_thread) | if (m_tick_in_draw_thread) | ||||
tick(seconds); | tick(seconds); | ||||
@@ -32,7 +32,7 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
class SdlInput : public Entity | |||||
class SdlInput : public entity | |||||
{ | { | ||||
public: | public: | ||||
/** passing the screen resolution (note: not the windowed app resolution!) allows to make the mouse axis resolution-independent */ | /** passing the screen resolution (note: not the windowed app resolution!) allows to make the mouse axis resolution-independent */ | ||||