Browse Source

entity: add a flag system.

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
Sam Hocevar 5 years ago
parent
commit
1186c08ad7
39 changed files with 267 additions and 270 deletions
  1. +2
    -2
      doc/samples/physics/easycharactercontroller.cpp
  2. +2
    -2
      doc/samples/physics/easycharactercontroller.h
  3. +3
    -3
      doc/samples/physics/lolphysics.h
  4. +2
    -2
      src/application/application.cpp
  5. +25
    -58
      src/application/sdl-app.cpp
  6. +36
    -27
      src/application/sdl-app.h
  7. +1
    -1
      src/audio/sample.cpp
  8. +9
    -7
      src/debug/fps.cpp
  9. +9
    -7
      src/debug/fps.h
  10. +2
    -2
      src/debug/record.cpp
  11. +2
    -2
      src/debug/record.h
  12. +1
    -1
      src/debug/stats.cpp
  13. +9
    -7
      src/debug/stats.h
  14. +10
    -8
      src/emitter.cpp
  15. +9
    -7
      src/emitter.h
  16. +7
    -18
      src/engine/entity.cpp
  17. +47
    -29
      src/engine/entity.h
  18. +33
    -33
      src/engine/ticker.cpp
  19. +6
    -6
      src/engine/ticker.h
  20. +3
    -3
      src/engine/worldentity.cpp
  21. +2
    -2
      src/engine/worldentity.h
  22. +1
    -1
      src/font.cpp
  23. +2
    -2
      src/font.h
  24. +2
    -2
      src/gradient.cpp
  25. +2
    -2
      src/lol/audio/sample.h
  26. +2
    -2
      src/scene.cpp
  27. +2
    -2
      src/scene.h
  28. +10
    -8
      src/sprite.cpp
  29. +1
    -1
      src/text.cpp
  30. +2
    -2
      src/text.h
  31. +1
    -1
      src/textureimage.cpp
  32. +4
    -4
      src/textureimage.h
  33. +1
    -1
      src/tileset.cpp
  34. +1
    -1
      src/tileset.h
  35. +2
    -2
      src/ui/d3d9-input.cpp
  36. +9
    -7
      src/ui/d3d9-input.h
  37. +2
    -2
      src/ui/gui.h
  38. +2
    -2
      src/ui/sdl-input.cpp
  39. +1
    -1
      src/ui/sdl-input.h

+ 2
- 2
doc/samples/physics/easycharactercontroller.cpp View File

@@ -2,7 +2,7 @@
// Lol Engine — Bullet physics test
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -134,7 +134,7 @@ std::string EasyCharacterController::GetName()
//Physic Tick
void EasyCharacterController::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);

//Send final velocity in Bullet
{


+ 2
- 2
doc/samples/physics/easycharactercontroller.h View File

@@ -2,7 +2,7 @@
// Lol Engine — Bullet physics test
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -33,7 +33,7 @@ namespace phys
{

class EasyCharacterController : public EasyPhysic,
public Entity
public entity
{

friend class Simulation;


+ 3
- 3
doc/samples/physics/lolphysics.h View File

@@ -2,7 +2,7 @@
// Lol Engine — Bullet physics test
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -65,7 +65,7 @@ struct RayCastResult
unsigned int m_flags; //???
};

class Simulation : public Entity
class Simulation : public entity
{
public:
Simulation() :
@@ -111,7 +111,7 @@ public:

virtual void tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);

//step the simulation
if (m_dynamics_world)


+ 2
- 2
src/application/application.cpp View File

@@ -73,7 +73,7 @@ protected:
#if __ANDROID__
//NOT HANDLED YET
#elif LOL_USE_SDL
SdlAppDisplay display;
sdl::app_display display;
#elif HAVE_GLES_2X
/* FIXME: this macro is only deactivated if we include "lolgl.h" */
//NOT HANDLED YET
@@ -137,7 +137,7 @@ class ApplicationData
#if __ANDROID__
AndroidApp app;
#elif LOL_USE_SDL
SdlApp app;
sdl::app app;
#elif HAVE_GLES_2X
/* FIXME: this macro is only deactivated if we include "lolgl.h" */
EglApp app;


+ 25
- 58
src/application/sdl-app.cpp View File

@@ -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
ivec2 window_size = res;
@@ -70,72 +55,70 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res)
int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
if (window_size == ivec2(0))
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
data->m_window = SDL_CreateWindow(title,
m_window = SDL_CreateWindow(title,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
window_size.x, window_size.y, flags);
if (!data->m_window)
if (!m_window)
{
msg::error("cannot create rendering window: %s\n", SDL_GetError());
SDL_Quit();
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 */
Video::Setup(res); //TODO ?? Should it be here ?
#endif
}

SdlAppDisplay::~SdlAppDisplay()
sdl::app_display::~app_display()
{
#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

delete data;
}

ivec2 SdlAppDisplay::resolution() const
ivec2 sdl::app_display::resolution() const
{
ivec2 ret(0);
#if LOL_USE_SDL
SDL_GetWindowSize(data->m_window, &ret.x, &ret.y);
SDL_GetWindowSize(m_window, &ret.x, &ret.y);
#endif
return ret;
}

void SdlAppDisplay::set_resolution(ivec2 resolution)
void sdl::app_display::set_resolution(ivec2 resolution)
{
#if LOL_USE_SDL
SDL_SetWindowSize(data->m_window, resolution.x, resolution.y);
SDL_SetWindowSize(m_window, resolution.x, resolution.y);
#endif
}

void SdlAppDisplay::SetPosition(ivec2 position)
void sdl::app_display::SetPosition(ivec2 position)
{
#if LOL_USE_SDL
SDL_SetWindowPosition(data->m_window, position.x, position.y);
SDL_SetWindowPosition(m_window, position.x, position.y);
#endif
}

void SdlAppDisplay::Enable()
void sdl::app_display::Enable()
{
#if LOL_USE_SDL
//TODO: Should we do that: ?
SDL_GL_MakeCurrent(data->m_window, data->m_glcontext);
SDL_GL_MakeCurrent(m_window, m_glcontext);
#endif
}

void SdlAppDisplay::Disable()
void sdl::app_display::Disable()
{
#if LOL_USE_SDL
SDL_GL_SwapWindow(data->m_window);
SDL_GL_SwapWindow(m_window);
#endif
}

@@ -152,24 +135,9 @@ const char* SceneDisplay::GetPhysicalName(int index)
#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);
#if LOL_USE_SDL
@@ -189,25 +157,24 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) :
#endif
}

void SdlApp::ShowPointer(bool show)
void sdl::app::ShowPointer(bool show)
{
#if LOL_USE_SDL
SDL_ShowCursor(show ? 1 : 0);
#endif
}

void SdlApp::Tick()
void sdl::app::Tick()
{
/* Tick the renderer, show the frame and clamp to desired framerate. */
Ticker::tick_draw();
}

SdlApp::~SdlApp()
sdl::app::~app()
{
#if LOL_USE_SDL
SDL_Quit();
#endif
delete data;
}

} /* namespace lol */


+ 36
- 27
src/application/sdl-app.h View File

@@ -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
@@ -17,19 +19,37 @@

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

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

public:
SdlAppDisplay(char const *title, ivec2 resolution);
virtual ~SdlAppDisplay();
app_display(char const *title, ivec2 resolution);
virtual ~app_display();

protected:
virtual void set_resolution(ivec2 resolution);
@@ -41,24 +61,13 @@ protected:
void Disable();

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


+ 1
- 1
src/audio/sample.cpp View File

@@ -95,7 +95,7 @@ sample::~sample()

void sample::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);
}

std::string sample::GetName() const


+ 9
- 7
src/debug/fps.cpp View File

@@ -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>
@@ -52,7 +54,7 @@ DebugFps::DebugFps(int x, int y)

void DebugFps::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);

char buf[1024];



+ 9
- 7
src/debug/fps.h View File

@@ -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
@@ -22,7 +24,7 @@ namespace lol

class DebugFpsData;

class DebugFps : public Entity
class DebugFps : public entity
{
public:
DebugFps(int x, int y);


+ 2
- 2
src/debug/record.cpp View File

@@ -61,12 +61,12 @@ DebugRecord::DebugRecord(std::string const &path, float fps)

void DebugRecord::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);
}

void DebugRecord::tick_draw(float seconds, Scene &scene)
{
Entity::tick_draw(seconds, scene);
entity::tick_draw(seconds, scene);

ivec2 size = Video::GetSize();



+ 2
- 2
src/debug/record.h View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -24,7 +24,7 @@ namespace lol

class DebugRecordData;

class DebugRecord : public Entity
class DebugRecord : public entity
{
public:
DebugRecord(std::string const &path, float fps);


+ 1
- 1
src/debug/stats.cpp View File

@@ -45,7 +45,7 @@ DebugStats::DebugStats(char const *path)

void DebugStats::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);

fprintf(data->fp, "%i %f %f %f %f\n",
Ticker::GetFrameNum(),


+ 9
- 7
src/debug/stats.h View File

@@ -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
@@ -22,7 +24,7 @@ namespace lol

class DebugStatsData;

class DebugStats : public Entity
class DebugStats : public entity
{
public:
DebugStats(char const *path);


+ 10
- 8
src/emitter.cpp View File

@@ -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>
@@ -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)
{
Entity::tick_draw(seconds, scene);
entity::tick_draw(seconds, scene);

for (int i = 0; i < data->nparticles; i++)
scene.AddTile(data->tileset, data->particles[i],


+ 9
- 7
src/emitter.h View File

@@ -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
@@ -23,7 +25,7 @@ namespace lol

class EmitterData;

class Emitter : public Entity
class Emitter : public entity
{
public:
Emitter(TileSet *tileset, vec3 gravity);


+ 7
- 18
src/engine/entity.cpp View File

@@ -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
m_tickstate = tickable::state::idle;
@@ -36,28 +33,20 @@ Entity::Entity() :
Ticker::Register(this);
}

Entity::~Entity()
entity::~entity()
{
#if !LOL_BUILD_RELEASE
if (!m_destroy)
if (!has_flags(flags::destroying))
msg::error("entity destructor called directly\n");
#endif
}

std::string Entity::GetName() const
std::string entity::GetName() const
{
return "<entity>";
}

void Entity::InitGame()
{
}

void Entity::InitDraw()
{
}

void Entity::tick_game(float seconds)
void entity::tick_game(float seconds)
{
UNUSED(seconds);
#if !LOL_BUILD_RELEASE
@@ -67,7 +56,7 @@ void Entity::tick_game(float seconds)
#endif
}

void Entity::tick_draw(float seconds, Scene &scene)
void entity::tick_draw(float seconds, Scene &scene)
{
UNUSED(seconds, scene);
#if !LOL_BUILD_RELEASE


+ 47
- 29
src/engine/entity.h View File

@@ -13,7 +13,7 @@
#pragma once

//
// The Entity class
// The entity class
// ----------------
// 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
@@ -27,23 +27,7 @@
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 ticker;
@@ -52,22 +36,33 @@ class Entity
public:
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_draw(float seconds, class Scene &scene);

/* The initialisation state */
InitState m_initstate;

#if !LOL_BUILD_RELEASE
tickable::state m_tickstate;
#endif
@@ -76,10 +71,30 @@ protected:
tickable::group::draw m_drawgroup;

private:
int m_ref, m_autorelease, m_destroy;
flags m_flags = flags::none;
int m_ref = 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
{
T *get(std::string const &key)
@@ -106,5 +121,8 @@ template<typename T> struct entity_dict
std::map<T*, std::string> m_cache2;
};

// The old API
typedef entity Entity;

} /* namespace lol */


+ 33
- 33
src/engine/ticker.cpp View File

@@ -62,8 +62,8 @@ private:
std::unordered_set<std::shared_ptr<tickable>> m_tickables;

/* 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];
int DEPRECATED_nentities;

@@ -114,7 +114,7 @@ void ticker::remove(std::shared_ptr<tickable> entity)
// 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
* 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. */
data->DEPRECATED_m_autolist.push(entity);
entity->m_autorelease = 1;
entity->add_flags(entity::flags::autorelease);
entity->m_ref = 1;

data->DEPRECATED_nentities++;
}

void Ticker::Ref(Entity *entity)
void Ticker::Ref(entity *entity)
{
ASSERT(entity, "dereferencing nullptr entity\n");
ASSERT(!entity->m_destroy,
ASSERT(!entity->has_flags(entity::flags::destroying),
"referencing entity scheduled for destruction %s\n",
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
* registered entity. */
for (int i = data->DEPRECATED_m_autolist.count(); i--; )
@@ -149,19 +149,19 @@ void Ticker::Ref(Entity *entity)
break;
}
}
entity->m_autorelease = 0;
entity->remove_flags(entity::flags::autorelease);
}
else
entity->m_ref++;
}

int Ticker::Unref(Entity *entity)
int Ticker::Unref(entity *entity)
{
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;
}
@@ -241,9 +241,9 @@ void ticker_data::GameThreadTick()

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",
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
@@ -292,7 +292,7 @@ void ticker_data::GameThreadTick()
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)
{
Entity * e = data->DEPRECATED_m_list[g][i];
entity * e = data->DEPRECATED_m_list[g][i];
if (e->m_ref)
{
#if !LOL_BUILD_RELEASE
@@ -315,15 +315,15 @@ void ticker_data::GameThreadTick()
/* Garbage collect objects that can be destroyed. We can do this
* before inserting awaiting objects, because only objects already
* in the tick lists can be marked for destruction. */
array<Entity*> destroy_list;
array<entity*> destroy_list;
bool do_reserve = true;
for (int g = 0; g < (int)tickable::group::all::end; ++g)
{
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:
* If entity is to be destroyed, remove it */
@@ -335,7 +335,7 @@ void ticker_data::GameThreadTick()
}
destroy_list.push_unique(e);
}
else if (e->m_destroy)
else if (e->has_flags(entity::flags::destroying))
{
/* Draw tick list:
* If entity is to be destroyed,
@@ -360,21 +360,21 @@ void ticker_data::GameThreadTick()
else
{
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())
{
data->DEPRECATED_nentities -= destroy_list.count();
for (Entity* e : destroy_list)
for (entity* e : destroy_list)
delete e;
}

/* Insert waiting objects into the appropriate lists */
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 (e->m_scene_mask == 0)
@@ -404,7 +404,7 @@ void ticker_data::GameThreadTick()
}

// Initialize the entity
e->InitGame();
e->init_game();
}

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)
{
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 (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)
{
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 (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()
{
/* We're bailing out. Release all m_autorelease objects. */
/* We're bailing out. Release all autorelease objects. */
while (data->DEPRECATED_m_autolist.count())
{
data->DEPRECATED_m_autolist.last()->m_ref--;


+ 6
- 6
src/engine/ticker.h View File

@@ -37,9 +37,9 @@ public:
static void remove(std::shared_ptr<tickable> entity);

// 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 StopBenchmark();
@@ -47,9 +47,9 @@ public:
static void StopRecording();
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 int Finished();


+ 3
- 3
src/engine/worldentity.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// 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)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);
}

void WorldEntity::tick_draw(float seconds, Scene &scene)
{
Entity::tick_draw(seconds, scene);
entity::tick_draw(seconds, scene);
}

} /* namespace lol */


+ 2
- 2
src/engine/worldentity.h View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -24,7 +24,7 @@
namespace lol
{

class WorldEntity : public Entity
class WorldEntity : public entity
{
public:
virtual std::string GetName() const;


+ 1
- 1
src/font.cpp View File

@@ -71,7 +71,7 @@ Font::~Font()

void Font::tick_draw(float seconds, Scene &scene)
{
Entity::tick_draw(seconds, scene);
entity::tick_draw(seconds, scene);

if (data->tileset->GetTexture())
{


+ 2
- 2
src/font.h View File

@@ -24,7 +24,7 @@ namespace lol

class FontData;

class Font : public Entity
class Font : public entity
{
public:
static Font *create(std::string const &path);
@@ -34,7 +34,7 @@ protected:
Font(std::string const &path);
~Font();

/* Inherited from Entity */
/* Inherited from entity */
virtual std::string GetName() const;
virtual void tick_draw(float seconds, Scene &scene);



+ 2
- 2
src/gradient.cpp View File

@@ -48,12 +48,12 @@ Gradient::Gradient(vec3 aa, vec3 bb)

void Gradient::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);
}

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,
m_aabb.bb.x, m_aabb.aa.y, 0.0f,


+ 2
- 2
src/lol/audio/sample.h View File

@@ -27,7 +27,7 @@ namespace lol

class sample_data;

class sample : public Entity
class sample : public entity
{
public:
static sample *create(std::string const &path);
@@ -37,7 +37,7 @@ protected:
sample(std::string const &path);
virtual ~sample();

/* Inherited from Entity */
/* Inherited from entity */
virtual std::string GetName() const;
virtual void tick_game(float seconds);



+ 2
- 2
src/scene.cpp View File

@@ -211,12 +211,12 @@ Scene& Scene::GetScene(int index)
return *g_scenes[index];
}

void Scene::Link(Entity* entity)
void Scene::Link(entity* entity)
{
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);
}


+ 2
- 2
src/scene.h View File

@@ -121,8 +121,8 @@ public:

public:
//TODO: don't like the name
void Link(Entity* entity);
bool IsRelevant(Entity* entity);
void Link(entity* entity);
bool IsRelevant(entity* entity);

public:
Camera* GetCamera(int cam_idx = -1);


+ 10
- 8
src/sprite.cpp View File

@@ -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>
@@ -39,12 +41,12 @@ Sprite::Sprite(TileSet *tileset, int id)

void Sprite::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);
}

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);
}


+ 1
- 1
src/text.cpp View File

@@ -95,7 +95,7 @@ ivec2 Text::GetFontSize()

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())
{


+ 2
- 2
src/text.h View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -33,7 +33,7 @@ enum class TextAlign
Center,
};

class Text : public Entity
class Text : public entity
{
public:
Text(std::string const &text, char const *font);


+ 1
- 1
src/textureimage.cpp View File

@@ -91,7 +91,7 @@ void TextureImage::tick_draw(float seconds, Scene &scene)
{
super::tick_draw(seconds, scene);

if (IsDestroying())
if (has_flags(entity::flags::destroying))
{
if (m_data->m_image)
{


+ 4
- 4
src/textureimage.h View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -33,9 +33,9 @@ namespace lol

class TextureImageData;

class TextureImage : public Entity
class TextureImage : public entity
{
typedef Entity super;
typedef entity super;
protected:
virtual TextureImageData* GetNewData();

@@ -53,7 +53,7 @@ protected:
virtual void tick_draw(float seconds, Scene &scene);

public:
/* Inherited from Entity */
/* Inherited from entity */
virtual std::string GetName() const;

void UpdateTexture(image* img);


+ 1
- 1
src/tileset.cpp View File

@@ -178,7 +178,7 @@ void TileSet::Init(std::string const &path, Image* image)
m_data->m_name = "<tileset> " + path;
}

//Inherited from Entity -------------------------------------------------------
//Inherited from entity -------------------------------------------------------
std::string TileSet::GetName() const
{
return m_data->m_name;


+ 1
- 1
src/tileset.h View File

@@ -62,7 +62,7 @@ protected:
virtual void Init(std::string const &path, image* img);

public:
/* Inherited from Entity */
/* Inherited from entity */
virtual std::string GetName() const;

/* New methods */


+ 2
- 2
src/ui/d3d9-input.cpp View File

@@ -87,7 +87,7 @@ D3d9Input::~D3d9Input()

void D3d9Input::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);

#if defined LOL_USE_XINPUT
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)
{
Entity::tick_draw(seconds, scene);
entity::tick_draw(seconds, scene);
}

} /* namespace lol */


+ 9
- 7
src/ui/d3d9-input.h View File

@@ -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
@@ -22,7 +24,7 @@ namespace lol

class D3d9InputData;

class D3d9Input : public Entity
class D3d9Input : public entity
{
public:
D3d9Input();


+ 2
- 2
src/ui/gui.h View File

@@ -41,7 +41,7 @@
namespace lol
{

class gui : public Entity
class gui : public entity
{
public:
gui(ImFontAtlas *shared_font_atlas);
@@ -54,7 +54,7 @@ public:
static void refresh_fonts();

private:
typedef Entity super;
typedef entity super;

protected:
virtual void tick_game(float seconds);


+ 2
- 2
src/ui/sdl-input.cpp View File

@@ -110,7 +110,7 @@ SdlInput::~SdlInput()

void SdlInput::tick_game(float seconds)
{
Entity::tick_game(seconds);
entity::tick_game(seconds);

if (!m_tick_in_draw_thread)
tick(seconds);
@@ -118,7 +118,7 @@ void SdlInput::tick_game(float seconds)

void SdlInput::tick_draw(float seconds, Scene &scene)
{
Entity::tick_draw(seconds, scene);
entity::tick_draw(seconds, scene);

if (m_tick_in_draw_thread)
tick(seconds);


+ 1
- 1
src/ui/sdl-input.h View File

@@ -32,7 +32,7 @@
namespace lol
{

class SdlInput : public Entity
class SdlInput : public entity
{
public:
/** passing the screen resolution (note: not the windowed app resolution!) allows to make the mouse axis resolution-independent */


Loading…
Cancel
Save