source: trunk/src/entity.h @ 2817

Last change on this file since 2817 was 2817, checked in by sam, 8 years ago

ticker: replace linked lists wih dynamic arrays for entity groups.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://www.wtfpl.net/ for more details.
9//
10
11//
12// The Entity class
13// ---------------
14// Entities are objects that can be ticked by the game loop and/or the render
15// loop. Entities are implemented as one or several linked lists. See the
16// Ticker class for the ticking logic and the linked list implementation.
17//
18
19#if !defined __LOL_ENTITY_H__
20#define __LOL_ENTITY_H__
21
22#include <stdint.h>
23
24namespace lol
25{
26
27struct InitState
28{
29    enum Value
30    {
31        Unknown,
32        Error,
33        NeedInitDraw,
34        NeedInitGame,
35        Ready,
36    }
37    m_value;
38
39    inline InitState(Value v) : m_value(v) {}
40    inline operator Value() { return m_value; }
41};
42
43class Entity
44{
45    friend class Ticker;
46    friend class TickerData;
47    friend class Dict;
48    friend class Emcee;
49
50public:
51    virtual char const *GetName();
52
53protected:
54    Entity();
55    virtual ~Entity();
56
57    inline int IsDestroying() { return m_destroy; }
58
59    virtual void InitGame();
60    virtual void InitDraw();
61
62    virtual void TickGame(float seconds);
63    virtual void TickDraw(float seconds);
64
65    enum
66    {
67        GAMEGROUP_BEFORE = 0,
68        GAMEGROUP_DEFAULT,
69        GAMEGROUP_AFTER,
70        GAMEGROUP_AFTER_0,
71        GAMEGROUP_AFTER_1,
72
73        // Must be the last element
74        GAMEGROUP_END
75    }
76    m_gamegroup;
77
78    enum
79    {
80        DRAWGROUP_BEFORE = GAMEGROUP_END,
81        DRAWGROUP_LIGHT,
82        DRAWGROUP_CAMERA,
83        DRAWGROUP_DEFAULT,
84        DRAWGROUP_AFTER,
85        DRAWGROUP_AFTER_0,
86        DRAWGROUP_AFTER_1,
87        DRAWGROUP_HUD,
88        DRAWGROUP_CAPTURE,
89        // Must be the last element
90        DRAWGROUP_END
91    }
92    m_drawgroup;
93
94    static int const GAMEGROUP_BEGIN = 0;
95    static int const DRAWGROUP_BEGIN = GAMEGROUP_END;
96    static int const ALLGROUP_END = DRAWGROUP_END;
97
98    /* The initialisation state */
99    InitState m_initstate;
100
101#if !LOL_BUILD_RELEASE
102    enum
103    {
104        STATE_IDLE = 0,
105        STATE_PRETICK_GAME,
106        STATE_POSTTICK_GAME,
107        STATE_PRETICK_DRAW,
108        STATE_POSTTICK_DRAW,
109    }
110    m_tickstate;
111#endif
112
113    // Emcee begin
114private:
115    void SetState(uint32_t newstate);
116    void SetStateWhenMatch(uint32_t newstate,
117                           Entity *other_entity, uint32_t other_state);
118    virtual uint32_t OnStateChanged(uint32_t newstate)
119    {
120        return LOLm_state = newstate;
121    }
122
123    uint32_t LOLm_state;
124    // Emcee end
125
126private:
127    int m_ref, m_autorelease, m_destroy;
128};
129
130} /* namespace lol */
131
132#endif // __LOL_ENTITY_H__
133
Note: See TracBrowser for help on using the repository browser.