aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Game
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-21 13:37:27 +0800
committerchai <chaifix@163.com>2018-10-21 13:37:27 +0800
commit066e5987c515dfc34537d73ca9d2a81ddd1f9e1b (patch)
treeec45fe523daa4f9e8a30db0a045a0eb9cee84822 /src/libjin/Game
parent3292019e55dd02a96420e72bad88711fd36ef249 (diff)
*注释
Diffstat (limited to 'src/libjin/Game')
-rw-r--r--src/libjin/Game/je_entity.h51
-rw-r--r--src/libjin/Game/je_game.h33
-rw-r--r--src/libjin/Game/je_scene.h68
3 files changed, 148 insertions, 4 deletions
diff --git a/src/libjin/Game/je_entity.h b/src/libjin/Game/je_entity.h
new file mode 100644
index 0000000..29fe8be
--- /dev/null
+++ b/src/libjin/Game/je_entity.h
@@ -0,0 +1,51 @@
+#ifndef __JE_GAME_OBJECT_H
+#define __JE_GAME_OBJECT_H
+
+#include <map>
+#include <set>
+
+#include "../common/je_types.h"
+
+namespace JinEngine
+{
+ namespace Game
+ {
+
+ ///
+ /// Game object base class.
+ ///
+ class Entity
+ {
+ public:
+ virtual ~Entity();
+
+ void lifecycle();
+
+ protected:
+ virtual void onAlive();
+ virtual void onUpdate(float dt);
+ virtual void onDraw();
+ virtual void onDie();
+
+ uint32 layer; // layer where entity belongs
+ uint32 index; // render index in layer
+ uint64 tag; // tag of entity
+ bool mIsVisible;
+ bool mIsActive;
+
+ };
+
+ ///
+ /// Entity list. For quickly adding and removing entities.
+ ///
+ typedef std::list<Entity*> EntityList;
+
+ ///
+ /// Entity set. For searching and keeps entities unique and sorted.
+ ///
+ typedef std::set<Entity*> EntitySet;
+
+ } // namespace Game
+} // namespace JinEngine
+
+#endif \ No newline at end of file
diff --git a/src/libjin/Game/je_game.h b/src/libjin/Game/je_game.h
index 8fe4b51..6f7ad6d 100644
--- a/src/libjin/Game/je_game.h
+++ b/src/libjin/Game/je_game.h
@@ -12,6 +12,9 @@ namespace JinEngine
namespace Core
{
+ ///
+ /// Game class.
+ ///
class Game : public Subsystem<Game>
{
public:
@@ -21,6 +24,9 @@ namespace JinEngine
typedef void(*onUpdate)(int dt);
typedef void(*onDraw)();
+ ///
+ /// Game setting.
+ ///
struct Setting : SettingBase
{
onEvent eventHandler;
@@ -29,12 +35,31 @@ namespace JinEngine
onLoad loader;
};
+ ///
+ /// Main game loop.
+ ///
void run();
- inline void stop() { _running = false; };
- inline bool running() { return _running; };
+
+ ///
+ /// Stop game.
+ ///
+ inline void stop()
+ {
+ _running = false;
+ };
+
+ ///
+ /// Return if game is running.
+ ///
+ /// @return True if game is running, otherwise return false.
+ ///
+ inline bool running()
+ {
+ return _running;
+ };
private:
-
+
Game();
~Game() {};
@@ -55,4 +80,4 @@ namespace JinEngine
} // namespace Core
} // namespace JinEngine
-#endif // __JE_CORE_GAME_H
+#endif // __JE_CORE_GAME_H \ No newline at end of file
diff --git a/src/libjin/Game/je_scene.h b/src/libjin/Game/je_scene.h
new file mode 100644
index 0000000..388b047
--- /dev/null
+++ b/src/libjin/Game/je_scene.h
@@ -0,0 +1,68 @@
+#ifndef __JE_GAME_SCENE_H
+#define __JE_GAME_SCENE_H
+
+#include <map>
+#include <list>
+
+#include "je_entity.h"
+
+namespace JinEngine
+{
+ namespace Game
+ {
+
+ ///
+ /// Handle all entities.
+ ///
+ class Scene
+ {
+ public:
+ ///
+ ///
+ ///
+ void addEntity(Entity* entity);
+
+ ///
+ ///
+ ///
+ EntityList& getEntitiesByTag(uint64 tag);
+
+ ///
+ ///
+ ///
+ EntityList& getEntitiesByLayer(uint32 layer);
+
+ ///
+ ///
+ ///
+ void setEntitiesActiveByTag(uint64 tag);
+
+ ///
+ ///
+ ///
+ void setEntitiesActiveByLayer(uint32 layer);
+
+ ///
+ ///
+ ///
+ void removeEntitiesByLayer(uint32 layer);
+
+ ///
+ ///
+ ///
+ void removeEntitiesByTag(uint64 tag);
+
+ protected:
+ // all entities
+ EntitySet entities;
+ // all entities grouped by layer, render order
+ std::map<uint32, EntityList> layers;
+ // all entities grouped by tag
+ std::map<uint64, EntityList> tags;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file