@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2019 Sam Hocevar <sam@hocevar.net> | ||||
// © 2009—2013 Sam Hocevar <sam@hocevar.net> | // © 2010—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// This library is free software. It comes without any warranty, to | // This library 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,11 +24,8 @@ namespace lol | |||||
// Override Gamegroups names for Physic-usage | // Override Gamegroups names for Physic-usage | ||||
// "_ENT_" means that this is a group for Entities that use EasyPhysic primitives. | // "_ENT_" means that this is a group for Entities that use EasyPhysic primitives. | ||||
// "_EZP_" means that this is a group for EasyPhysic primitives. | // "_EZP_" means that this is a group for EasyPhysic primitives. | ||||
#define GAMEGROUP_ENT_INPUT GAMEGROUP_INPUT | #define GAMEGROUP_EZP_CHAR_CTRLR tickable::group::game::other_2 | ||||
#define GAMEGROUP_ENT_PLATFORM GAMEGROUP_ENTITY | #define GAMEGROUP_SIMULATION tickable::group::game::other_3 | ||||
#define GAMEGROUP_ENT_MAIN GAMEGROUP_OTHER_1 | |||||
#define GAMEGROUP_EZP_CHAR_CTRLR GAMEGROUP_OTHER_2 | |||||
#define GAMEGROUP_SIMULATION GAMEGROUP_OTHER_3 | |||||
#define LOL2BT_UNIT 1.0f | #define LOL2BT_UNIT 1.0f | ||||
#define BT2LOL_UNIT 1.0f | #define BT2LOL_UNIT 1.0f | ||||
@@ -52,6 +52,9 @@ liblol_core_headers = \ | |||||
lol/audio/all.h \ | lol/audio/all.h \ | ||||
lol/audio/audio.h lol/audio/sample.h \ | lol/audio/audio.h lol/audio/sample.h \ | ||||
\ | \ | ||||
lol/engine/all.h \ | |||||
lol/engine/tickable.h \ | |||||
\ | |||||
lol/sys/all.h \ | lol/sys/all.h \ | ||||
lol/sys/init.h lol/sys/file.h lol/sys/getopt.h lol/sys/thread.h \ | lol/sys/init.h lol/sys/file.h lol/sys/getopt.h lol/sys/thread.h \ | ||||
lol/sys/threadtypes.h lol/sys/timer.h \ | lol/sys/threadtypes.h lol/sys/timer.h \ | ||||
@@ -130,7 +133,7 @@ liblol_core_sources = \ | |||||
image/filter/dilate.cpp image/filter/median.cpp image/filter/yuv.cpp \ | image/filter/dilate.cpp image/filter/median.cpp image/filter/yuv.cpp \ | ||||
image/movie.cpp \ | image/movie.cpp \ | ||||
\ | \ | ||||
engine/ticker.cpp engine/ticker.h \ | engine/tickable.cpp engine/ticker.cpp engine/ticker.h \ | ||||
engine/entity.cpp engine/entity.h \ | engine/entity.cpp engine/entity.h \ | ||||
engine/world.cpp engine/world.h \ | engine/world.cpp engine/world.h \ | ||||
engine/worldentity.cpp engine/worldentity.h \ | engine/worldentity.cpp engine/worldentity.h \ | ||||
@@ -27,8 +27,8 @@ namespace lol | |||||
Camera::Camera() | Camera::Camera() | ||||
{ | { | ||||
m_gamegroup = GAMEGROUP_CAMERA; | m_gamegroup = tickable::group::game::camera; | ||||
m_drawgroup = DRAWGROUP_CAMERA; | m_drawgroup = tickable::group::draw::camera; | ||||
//Arbitrary values when scene renderer is not ready. | //Arbitrary values when scene renderer is not ready. | ||||
ivec2 screen_size = (Scene::GetCount()) ? (Video::GetSize()) : (ivec2(800, 600)); | ivec2 screen_size = (Scene::GetCount()) ? (Video::GetSize()) : (ivec2(800, 600)); | ||||
@@ -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 | ||||
@@ -56,7 +56,7 @@ DebugRecord::DebugRecord(std::string const &path, float fps) | |||||
m_data->m_sequence = nullptr; | m_data->m_sequence = nullptr; | ||||
#endif | #endif | ||||
m_drawgroup = DRAWGROUP_CAPTURE; | m_drawgroup = tickable::group::draw::capture; | ||||
} | } | ||||
void DebugRecord::tick_game(float seconds) | void DebugRecord::tick_game(float seconds) | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | // Copyright © 2010—2019 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // the extent permitted by applicable law. You can redistribute it | ||||
// http://www.wtfpl.net/ for more details. | // 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> | ||||
@@ -38,7 +40,7 @@ DebugStats::DebugStats(char const *path) | |||||
{ | { | ||||
data->fp = fopen(path, "w+"); | data->fp = fopen(path, "w+"); | ||||
m_gamegroup = GAMEGROUP_STATS; | m_gamegroup = tickable::group::game::stats; | ||||
} | } | ||||
void DebugStats::tick_game(float seconds) | void DebugStats::tick_game(float seconds) | ||||
@@ -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 | ||||
@@ -29,8 +29,8 @@ Entity::Entity() : | |||||
#if !LOL_BUILD_RELEASE | #if !LOL_BUILD_RELEASE | ||||
m_tickstate = STATE_IDLE; | m_tickstate = STATE_IDLE; | ||||
#endif | #endif | ||||
m_gamegroup = GAMEGROUP_ENTITY; | m_gamegroup = tickable::group::game::entity; | ||||
m_drawgroup = DRAWGROUP_ENTITY; | m_drawgroup = tickable::group::draw::entity; | ||||
/* FIXME: is this a problem? because the object can | /* FIXME: is this a problem? because the object can | ||||
* be ticked before the constructor is finished! */ | * be ticked before the constructor is finished! */ | ||||
Ticker::Register(this); | Ticker::Register(this); | ||||
@@ -20,7 +20,9 @@ | |||||
// Ticker class for the ticking logic and the linked list implementation. | // Ticker class for the ticking logic and the linked list implementation. | ||||
// | // | ||||
#include <stdint.h> | #include <cstdint> | ||||
#include <lol/engine/tickable.h> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -44,7 +46,7 @@ struct InitState | |||||
class Entity | class Entity | ||||
{ | { | ||||
friend class Scene; | friend class Scene; | ||||
friend class Ticker; | friend class ticker; | ||||
friend class TickerData; | friend class TickerData; | ||||
friend class Emcee; | friend class Emcee; | ||||
@@ -64,58 +66,6 @@ protected: | |||||
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); | ||||
enum | |||||
{ | |||||
GAMEGROUP_BEGIN = 0, // must be the first element | |||||
GAMEGROUP_INPUT, // input should be polled before everything else | |||||
GAMEGROUP_IMGUI, // debug update needs to be called before the rest for init purposes | |||||
GAMEGROUP_APP, // main application update | |||||
GAMEGROUP_ENTITY, // default entity update | |||||
// ----------------- // split entity update: | |||||
GAMEGROUP_PLAYER, // player updates before AI to ensure player actions is prevalent | |||||
GAMEGROUP_AI, // AI update | |||||
GAMEGROUP_OTHER_0, // other misc updates here | |||||
GAMEGROUP_OTHER_1, // (same) | |||||
GAMEGROUP_OTHER_2, // (same) | |||||
GAMEGROUP_OTHER_3, // (same) | |||||
// ----------------- // primitives updates | |||||
GAMEGROUP_MESH, // update Mesh/Animation to ensure correct sync with PLY/AI | |||||
GAMEGROUP_FX, // update FX/other to ensure correct sync with WorldPos and Meshes | |||||
GAMEGROUP_LIGHT, // update after FX because it could some | |||||
GAMEGROUP_CAMERA, // update camera at the end of the frame, once everything is settled | |||||
GAMEGROUP_STATS, // stats update | |||||
GAMEGROUP_END // must be the last element | |||||
} | |||||
m_gamegroup; | |||||
enum | |||||
{ | |||||
DRAWGROUP_BEGIN = GAMEGROUP_END, | |||||
DRAWGROUP_CAMERA, // update camera first for rendering | |||||
DRAWGROUP_TEXTURE, // texture | |||||
DRAWGROUP_LIGHT, // | |||||
DRAWGROUP_WORLD, // other misc updates here | |||||
DRAWGROUP_ENTITY, // | |||||
DRAWGROUP_FX, // | |||||
DRAWGROUP_OTHER_0, // other misc updates here | |||||
DRAWGROUP_OTHER_1, // (same) | |||||
DRAWGROUP_OTHER_2, // (same) | |||||
DRAWGROUP_OTHER_3, // (same) | |||||
DRAWGROUP_APP, // main application Draw | |||||
DRAWGROUP_HUD, | |||||
DRAWGROUP_IMGUI, | |||||
DRAWGROUP_CAPTURE, | |||||
DRAWGROUP_END, // must be the next-to-last element | |||||
DRAWGROUP_NONE, // this group is for non draw-ticked | |||||
} | |||||
m_drawgroup; | |||||
static int const ALLGROUP_END = DRAWGROUP_END; | |||||
/* The initialisation state */ | /* The initialisation state */ | ||||
InitState m_initstate; | InitState m_initstate; | ||||
@@ -131,6 +81,9 @@ protected: | |||||
m_tickstate; | m_tickstate; | ||||
#endif | #endif | ||||
tickable::group::game m_gamegroup; | |||||
tickable::group::draw m_drawgroup; | |||||
// Emcee begin | // Emcee begin | ||||
private: | private: | ||||
void SetState(uint32_t newstate); | void SetState(uint32_t newstate); | ||||
@@ -0,0 +1,33 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// 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 <cstdlib> | |||||
#include <cstdint> | |||||
#include <functional> | |||||
namespace lol | |||||
{ | |||||
//auto p = tickable::create<tickable>(); | |||||
tickable::tickable() | |||||
{ | |||||
} | |||||
tickable::~tickable() | |||||
{ | |||||
} | |||||
} /* namespace lol */ | |||||
@@ -13,7 +13,7 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <stdint.h> | #include <cstdint> | ||||
#include <functional> | #include <functional> | ||||
namespace lol | namespace lol | ||||
@@ -25,7 +25,7 @@ namespace lol | |||||
static class TickerData | static class TickerData | ||||
{ | { | ||||
friend class Ticker; | friend class ticker; | ||||
public: | public: | ||||
TickerData() : | TickerData() : | ||||
@@ -57,8 +57,8 @@ public: | |||||
private: | private: | ||||
/* Entity management */ | /* Entity management */ | ||||
array<Entity *> m_todolist, m_todolist_delayed, m_autolist; | array<Entity *> m_todolist, m_todolist_delayed, m_autolist; | ||||
array<Entity *> m_list[Entity::ALLGROUP_END]; | array<Entity *> m_list[(int)tickable::group::all::end]; | ||||
array<int> m_scenes[Entity::ALLGROUP_END]; | array<int> m_scenes[(int)tickable::group::all::end]; | ||||
int nentities; | int nentities; | ||||
/* Fixed framerate management */ | /* Fixed framerate management */ | ||||
@@ -214,10 +214,10 @@ void TickerData::GameThreadTick() | |||||
#if 0 | #if 0 | ||||
msg::debug("-------------------------------------\n"); | msg::debug("-------------------------------------\n"); | ||||
for (int g = 0; g < Entity::ALLGROUP_END; ++g) | for (int g = 0; g < (int)tickable::group::all::end; ++g) | ||||
{ | { | ||||
msg::debug("%s Group %d\n", | msg::debug("%s Group %d\n", | ||||
(g < Entity::GAMEGROUP_END) ? "Game" : "Draw", g); | (g < (int)tickable::group::game::end) ? "Game" : "Draw", g); | ||||
for (int i = 0; i < data->m_list[g].count(); ++i) | for (int i = 0; i < data->m_list[g].count(); ++i) | ||||
{ | { | ||||
@@ -269,7 +269,7 @@ void TickerData::GameThreadTick() | |||||
int n = 0; | int n = 0; | ||||
data->panic = 2 * (data->panic + 1); | data->panic = 2 * (data->panic + 1); | ||||
for (int g = 0; g < Entity::ALLGROUP_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->m_list[g].count() && n < data->panic; ++i) | for (int i = 0; i < data->m_list[g].count() && n < data->panic; ++i) | ||||
{ | { | ||||
Entity * e = data->m_list[g][i]; | Entity * e = data->m_list[g][i]; | ||||
@@ -297,13 +297,13 @@ void TickerData::GameThreadTick() | |||||
* 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 < Entity::ALLGROUP_END; ++g) | for (int g = 0; g < (int)tickable::group::all::end; ++g) | ||||
{ | { | ||||
for (int i = data->m_list[g].count(); i--;) | for (int i = data->m_list[g].count(); i--;) | ||||
{ | { | ||||
Entity *e = data->m_list[g][i]; | Entity *e = data->m_list[g][i]; | ||||
if (e->m_destroy && g < Entity::GAMEGROUP_END) | if (e->m_destroy && 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 */ | ||||
@@ -328,7 +328,7 @@ void TickerData::GameThreadTick() | |||||
if (Scene::GetScene(j).IsRelevant(e)) | if (Scene::GetScene(j).IsRelevant(e)) | ||||
removal_count++; | removal_count++; | ||||
//Update scene index | //Update scene index | ||||
data->m_scenes[e->m_drawgroup][j] -= removal_count; | data->m_scenes[(int)e->m_drawgroup][j] -= removal_count; | ||||
} | } | ||||
if (do_reserve) | if (do_reserve) | ||||
{ | { | ||||
@@ -339,7 +339,7 @@ void TickerData::GameThreadTick() | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (e->m_ref <= 0 && g >= Entity::DRAWGROUP_BEGIN) | if (e->m_ref <= 0 && g >= (int)tickable::group::draw::begin) | ||||
e->m_destroy = 1; | e->m_destroy = 1; | ||||
} | } | ||||
} | } | ||||
@@ -363,11 +363,11 @@ void TickerData::GameThreadTick() | |||||
} | } | ||||
data->m_todolist.remove(-1); | data->m_todolist.remove(-1); | ||||
data->m_list[e->m_gamegroup].push(e); | data->m_list[(int)e->m_gamegroup].push(e); | ||||
if (e->m_drawgroup != Entity::DRAWGROUP_NONE) | if (e->m_drawgroup != tickable::group::draw::none) | ||||
{ | { | ||||
if (data->m_scenes[e->m_drawgroup].count() < Scene::GetCount()) | if (data->m_scenes[(int)e->m_drawgroup].count() < Scene::GetCount()) | ||||
data->m_scenes[e->m_drawgroup].resize(Scene::GetCount()); | data->m_scenes[(int)e->m_drawgroup].resize(Scene::GetCount()); | ||||
int added_count = 0; | int added_count = 0; | ||||
for (int i = 0; i < Scene::GetCount(); i++) | for (int i = 0; i < Scene::GetCount(); i++) | ||||
@@ -375,11 +375,11 @@ void TickerData::GameThreadTick() | |||||
//If entity is concerned by this scene, add it in the list | //If entity is concerned by this scene, add it in the list | ||||
if (Scene::GetScene(i).IsRelevant(e)) | if (Scene::GetScene(i).IsRelevant(e)) | ||||
{ | { | ||||
data->m_list[e->m_drawgroup].insert(e, data->m_scenes[e->m_drawgroup][i]); | data->m_list[(int)e->m_drawgroup].insert(e, data->m_scenes[(int)e->m_drawgroup][i]); | ||||
added_count++; | added_count++; | ||||
} | } | ||||
//Update scene index | //Update scene index | ||||
data->m_scenes[e->m_drawgroup][i] += added_count; | data->m_scenes[(int)e->m_drawgroup][i] += added_count; | ||||
} | } | ||||
} | } | ||||
@@ -391,7 +391,7 @@ void TickerData::GameThreadTick() | |||||
data->m_todolist_delayed.clear(); | data->m_todolist_delayed.clear(); | ||||
/* Tick objects for the game loop */ | /* Tick objects for the game loop */ | ||||
for (int g = Entity::GAMEGROUP_BEGIN; g < Entity::GAMEGROUP_END && !data->quit /* Stop as soon as required */; ++g) | for (int g = (int)tickable::group::game::begin; g < (int)tickable::group::game::end && !data->quit /* Stop as soon as required */; ++g) | ||||
{ | { | ||||
for (int i = 0; i < data->m_list[g].count() && !data->quit /* Stop as soon as required */; ++i) | for (int i = 0; i < data->m_list[g].count() && !data->quit /* Stop as soon as required */; ++i) | ||||
{ | { | ||||
@@ -435,11 +435,11 @@ void TickerData::DrawThreadTick() | |||||
scene.pre_render(data->deltatime); | scene.pre_render(data->deltatime); | ||||
/* Tick objects for the draw loop */ | /* Tick objects for the draw loop */ | ||||
for (int g = Entity::DRAWGROUP_BEGIN; g < Entity::DRAWGROUP_END && !data->quit /* Stop as soon as required */; ++g) | for (int g = (int)tickable::group::draw::begin; g < (int)tickable::group::draw::end && !data->quit /* Stop as soon as required */; ++g) | ||||
{ | { | ||||
switch (g) | switch (g) | ||||
{ | { | ||||
case Entity::DRAWGROUP_BEGIN: | case (int)tickable::group::draw::begin: | ||||
scene.Reset(); | scene.Reset(); | ||||
break; | break; | ||||
default: | default: | ||||
@@ -1,29 +1,31 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | // Copyright © 2010—2019 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // the extent permitted by applicable law. You can redistribute it | ||||
// http://www.wtfpl.net/ for more details. | // 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 | ||||
// | // | ||||
// The Ticker class | // The ticker class | ||||
// ---------------- | // ———————————————— | ||||
// The Ticker is a static class that registers entities and ticks them. | // The ticker is a static class that registers entities and ticks them. | ||||
// | // | ||||
#include <stdint.h> | #include <cstdint> | ||||
#include "engine/entity.h" | #include "engine/entity.h" | ||||
namespace lol | namespace lol | ||||
{ | { | ||||
class Ticker | class ticker | ||||
{ | { | ||||
public: | public: | ||||
static void Register(Entity *entity); | static void Register(Entity *entity); | ||||
@@ -46,8 +48,10 @@ public: | |||||
static int Finished(); | static int Finished(); | ||||
private: | private: | ||||
Ticker() {} | ticker() {} | ||||
}; | }; | ||||
typedef ticker Ticker; | |||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -60,7 +60,7 @@ Font::Font(std::string const &path) | |||||
data->tileset = TileSet::create(path, ivec2::zero, ivec2(16)); | data->tileset = TileSet::create(path, ivec2::zero, ivec2(16)); | ||||
data->size = data->tileset->GetTileSize(0); | data->size = data->tileset->GetTileSize(0); | ||||
m_drawgroup = DRAWGROUP_TEXTURE; | m_drawgroup = tickable::group::draw::texture; | ||||
} | } | ||||
Font::~Font() | Font::~Font() | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | // Copyright © 2010—2019 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // the extent permitted by applicable law. You can redistribute it | ||||
// http://www.wtfpl.net/ for more details. | // 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> | ||||
@@ -20,8 +22,8 @@ Light::Light() | |||||
: m_color(1.f), | : m_color(1.f), | ||||
m_type(LightType::Directional) | m_type(LightType::Directional) | ||||
{ | { | ||||
m_gamegroup = GAMEGROUP_LIGHT; | m_gamegroup = tickable::group::game::light; | ||||
m_drawgroup = DRAWGROUP_LIGHT; | m_drawgroup = tickable::group::draw::light; | ||||
SetPosition(vec3::zero); | SetPosition(vec3::zero); | ||||
} | } | ||||
@@ -106,6 +106,7 @@ | |||||
<ClCompile Include="easymesh\easymeshrender.cpp" /> | <ClCompile Include="easymesh\easymeshrender.cpp" /> | ||||
<ClCompile Include="easymesh\easymeshtransform.cpp" /> | <ClCompile Include="easymesh\easymeshtransform.cpp" /> | ||||
<ClCompile Include="engine\entity.cpp" /> | <ClCompile Include="engine\entity.cpp" /> | ||||
<ClCompile Include="engine\tickable.cpp" /> | |||||
<ClCompile Include="engine\ticker.cpp" /> | <ClCompile Include="engine\ticker.cpp" /> | ||||
<ClCompile Include="engine\world.cpp" /> | <ClCompile Include="engine\world.cpp" /> | ||||
<ClCompile Include="engine\worldentity.cpp" /> | <ClCompile Include="engine\worldentity.cpp" /> | ||||
@@ -228,6 +229,8 @@ | |||||
<ClInclude Include="lol\base\tuple.h" /> | <ClInclude Include="lol\base\tuple.h" /> | ||||
<ClInclude Include="lol\debug\all.h" /> | <ClInclude Include="lol\debug\all.h" /> | ||||
<ClInclude Include="lol\debug\lines.h" /> | <ClInclude Include="lol\debug\lines.h" /> | ||||
<ClInclude Include="lol\engine\all.h" /> | |||||
<ClInclude Include="lol\engine\tickable.h" /> | |||||
<ClInclude Include="lol\engine.h" /> | <ClInclude Include="lol\engine.h" /> | ||||
<ClInclude Include="lol\engine-internal.h" /> | <ClInclude Include="lol\engine-internal.h" /> | ||||
<ClInclude Include="lol\extras.h" /> | <ClInclude Include="lol\extras.h" /> | ||||
@@ -31,6 +31,9 @@ | |||||
<Filter Include="lol\algorithm"> | <Filter Include="lol\algorithm"> | ||||
<UniqueIdentifier>{39f6f872-186f-48af-8e87-bcceb06b1b21}</UniqueIdentifier> | <UniqueIdentifier>{39f6f872-186f-48af-8e87-bcceb06b1b21}</UniqueIdentifier> | ||||
</Filter> | </Filter> | ||||
<Filter Include="lol\engine"> | |||||
<UniqueIdentifier>{a20b47c1-a0f8-4a02-a7a8-6da2ccd8bb02}</UniqueIdentifier> | |||||
</Filter> | |||||
<Filter Include="lol\image"> | <Filter Include="lol\image"> | ||||
<UniqueIdentifier>{f25b3187-b24c-469a-b038-5a968eaa83f6}</UniqueIdentifier> | <UniqueIdentifier>{f25b3187-b24c-469a-b038-5a968eaa83f6}</UniqueIdentifier> | ||||
</Filter> | </Filter> | ||||
@@ -360,6 +363,9 @@ | |||||
<ClCompile Include="engine\entity.cpp"> | <ClCompile Include="engine\entity.cpp"> | ||||
<Filter>engine</Filter> | <Filter>engine</Filter> | ||||
</ClCompile> | </ClCompile> | ||||
<ClCompile Include="engine\tickable.cpp"> | |||||
<Filter>engine</Filter> | |||||
</ClCompile> | |||||
<ClCompile Include="engine\ticker.cpp"> | <ClCompile Include="engine\ticker.cpp"> | ||||
<Filter>engine</Filter> | <Filter>engine</Filter> | ||||
</ClCompile> | </ClCompile> | ||||
@@ -656,6 +662,12 @@ | |||||
<ClInclude Include="lol\debug\lines.h"> | <ClInclude Include="lol\debug\lines.h"> | ||||
<Filter>lol\debug</Filter> | <Filter>lol\debug</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="lol\engine\all.h"> | |||||
<Filter>lol\engine</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="lol\engine\tickable.h"> | |||||
<Filter>lol\engine</Filter> | |||||
</ClInclude> | |||||
<ClInclude Include="lol\image\image.h"> | <ClInclude Include="lol\image\image.h"> | ||||
<Filter>lol\image</Filter> | <Filter>lol\image</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
@@ -0,0 +1,16 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// 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 | |||||
#include <lol/engine/tickable.h> | |||||
@@ -0,0 +1,111 @@ | |||||
// | |||||
// Lol Engine | |||||
// | |||||
// 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 | |||||
// | |||||
// The tickable class | |||||
// —————————————————— | |||||
// Tickables are objects that can be ticked by the game loop and/or the render | |||||
// loop. | |||||
// | |||||
#include <cstdint> | |||||
namespace lol | |||||
{ | |||||
class game_tickable | |||||
{ | |||||
virtual void tick_game(float seconds) = 0; | |||||
}; | |||||
class draw_tickable | |||||
{ | |||||
virtual void tick_draw(float seconds, class Scene &scene) = 0; | |||||
}; | |||||
class tickable : public std::enable_shared_from_this<tickable> | |||||
{ | |||||
public: | |||||
tickable(); | |||||
virtual ~tickable(); | |||||
// Auto-registering factory | |||||
template<typename T> | |||||
static typename std::enable_if<std::is_base_of<tickable, T>::value, std::shared_ptr<T>>::type | |||||
create() | |||||
{ | |||||
auto p = std::make_shared<T>(); | |||||
return p; | |||||
} | |||||
// Tick groups | |||||
struct group | |||||
{ | |||||
enum class game | |||||
{ | |||||
begin = 0, // must be the first element | |||||
input, // input should be polled before everything else | |||||
gui, // debug update needs to be called before the rest for init purposes | |||||
app, // main application update | |||||
entity, // default entity update | |||||
// ----------------- // split entity update: | |||||
player, // player updates before AI to ensure player actions is prevalent | |||||
ai, // AI update | |||||
other_0, // other misc updates here | |||||
other_1, // (same) | |||||
other_2, // (same) | |||||
other_3, // (same) | |||||
// ----------------- // primitives updates | |||||
mesh, // update Mesh/Animation to ensure correct sync with PLY/AI | |||||
fx, // update FX/other to ensure correct sync with WorldPos and Meshes | |||||
light, // update after FX because it could some | |||||
camera, // update camera at the end of the frame, once everything is settled | |||||
stats, // stats update | |||||
end, // must be the last element | |||||
}; | |||||
enum class draw | |||||
{ | |||||
begin = (int)game::end, | |||||
camera, // update camera first for rendering | |||||
texture, // texture | |||||
light, // | |||||
world, // other misc updates here | |||||
entity, // | |||||
fx, // | |||||
other_0, // other misc updates here | |||||
other_1, // (same) | |||||
other_2, // (same) | |||||
other_3, // (same) | |||||
app, // main application Draw | |||||
hud, | |||||
gui, | |||||
capture, | |||||
end, // must be the next-to-last element | |||||
none, // this group is for non draw-ticked | |||||
}; | |||||
enum class all | |||||
{ | |||||
end = (int)draw::end, | |||||
}; | |||||
}; | |||||
}; | |||||
} /* namespace lol */ | |||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2016 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 | ||||
@@ -14,7 +14,7 @@ | |||||
// | // | ||||
// The main header | // The main header | ||||
// --------------- | // ——————————————— | ||||
// | // | ||||
#include <lol/base/all.h> | #include <lol/base/all.h> | ||||
@@ -25,4 +25,5 @@ | |||||
#include <lol/audio/all.h> | #include <lol/audio/all.h> | ||||
#include <lol/gpu/all.h> | #include <lol/gpu/all.h> | ||||
#include <lol/debug/all.h> | #include <lol/debug/all.h> | ||||
#include <lol/engine/all.h> | |||||
@@ -50,7 +50,7 @@ Text::Text(std::string const &text, char const *font) | |||||
data->m_scale = vec2(1.f); | data->m_scale = vec2(1.f); | ||||
data->m_spacing = 0.f; | data->m_spacing = 0.f; | ||||
m_drawgroup = DRAWGROUP_HUD; | m_drawgroup = tickable::group::draw::entity; | ||||
} | } | ||||
void Text::SetText(std::string const &text) | void Text::SetText(std::string const &text) | ||||
@@ -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 | ||||
@@ -12,8 +12,8 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <cstdlib> | |||||
#include <cstdio> | #include <cstdio> | ||||
#include <cstdlib> | |||||
#include <cstring> | #include <cstring> | ||||
#if defined _WIN32 | #if defined _WIN32 | ||||
@@ -84,7 +84,7 @@ void TextureImage::Init(std::string const &path, image* img) | |||||
m_data->m_texture_size = ivec2(PotUp(m_data->m_image_size.x), | m_data->m_texture_size = ivec2(PotUp(m_data->m_image_size.x), | ||||
PotUp(m_data->m_image_size.y)); | PotUp(m_data->m_image_size.y)); | ||||
m_drawgroup = DRAWGROUP_TEXTURE; | m_drawgroup = tickable::group::draw::texture; | ||||
} | } | ||||
void TextureImage::tick_draw(float seconds, Scene &scene) | void TextureImage::tick_draw(float seconds, Scene &scene) | ||||
@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2015 Benjamin Litzelmann | // Copyright © 2017—2019 Sam Hocevar <sam@hocevar.net> | ||||
// © 2017—2019 Sam Hocevar <sam@hocevar.net> | // © 2010—2015 Benjamin Litzelmann | ||||
// | // | ||||
// 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 | ||||
@@ -223,7 +223,7 @@ static uint32_t g_active_layer = ~((uint32_t)0); | |||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
Controller::Controller(std::string const &name) | Controller::Controller(std::string const &name) | ||||
{ | { | ||||
m_gamegroup = GAMEGROUP_INPUT; | m_gamegroup = tickable::group::game::input; | ||||
m_name = name; | m_name = name; | ||||
m_activate_nextframe = true; | m_activate_nextframe = true; | ||||
m_deactivate_nextframe = false; | m_deactivate_nextframe = false; | ||||
@@ -103,7 +103,7 @@ D3d9Input::D3d9Input() | |||||
} | } | ||||
#endif | #endif | ||||
m_gamegroup = GAMEGROUP_INPUT; | m_gamegroup = tickable::group::game::input; | ||||
} | } | ||||
D3d9Input::~D3d9Input() | D3d9Input::~D3d9Input() | ||||
@@ -45,8 +45,8 @@ gui::gui(ImFontAtlas *shared_font_atlas) | |||||
{ | { | ||||
ImGui::CreateContext(shared_font_atlas); | ImGui::CreateContext(shared_font_atlas); | ||||
m_gamegroup = GAMEGROUP_IMGUI; | m_gamegroup = tickable::group::game::gui; | ||||
m_drawgroup = DRAWGROUP_IMGUI; | m_drawgroup = tickable::group::draw::gui; | ||||
// Build shader code ------------------------------------------------------- | // Build shader code ------------------------------------------------------- | ||||
ShaderVar out_vertex = ShaderVar::GetShaderOut(ShaderProgram::Vertex); | ShaderVar out_vertex = ShaderVar::GetShaderOut(ShaderProgram::Vertex); | ||||
@@ -128,7 +128,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) | |||||
} | } | ||||
#endif | #endif | ||||
m_gamegroup = GAMEGROUP_INPUT; | m_gamegroup = tickable::group::game::input; | ||||
} | } | ||||
SdlInput::~SdlInput() | SdlInput::~SdlInput() | ||||