photon游戏引擎代码例子2
2009-01-17 15:15
295 查看
该篇是介绍photon引擎中的Task类与其管理器类
代码如下:
接下来是其管理器类了
如下
代码如下:
//This file is part of g lib #ifndef G_GOAL_TASK_HPP #define G_GOAL_TASK_HPP #ifndef _G_LIB_ #error please defie _G_LIB_ #endif #include <string> #include <boost/shared_ptr.hpp> namespace g { namespace goal { // Title: Task // Enum: PriorityLevel // Enumeration defining priority of a Task. enum PriorityLevel { PRI_HIGHEST = 5, PRI_HIGH = 4, PRI_NORMAL = 3, PRI_LOW = 2, PRI_LOWEST = 1 }; // Class: Task // Abstract class for tasks // When writing a task, only update() needs to be overloaded. class Task { public: // Function: Task // Constructor, every task needs a name and priority. Task(const std::string& name, PriorityLevel priority=PRI_NORMAL); virtual ~Task(); public: // Function: update // Pure virtual, every child task must overload it's own update(), when a // task is active this is called every 'frame.' virtual void update(float timeDelta)=0; // Function: onStart // Virtual function, overload to define behavior when the task is started. virtual void onStart(); // Function: onKill // Virtual function, overload to define behavior when the task is killed. virtual void onKill(); // Function: onPause // Virtual function, overload to define behavior every time that the // task is paused. // // Note: // Children of onPause should call Task::onPause to let the task know it's // been paused. virtual void onPause(); // Function: onUnpause // Virtual function, overload to define behavior every time that the // task is unpaused. // // Note: // Children of onUnpause should call Task::onUnpause to let the task know // it's been paused. virtual void onUnpause(); // Function: kill // Sets state of task to dead, dead tasks remove themselves from the // <TaskManager>'s task pool. void kill(); public: // Function: getName // Get the name of the task. std::string getName() const; // Function: getPriority // Get the priority of the task. short getPriority() const; // Function: isAlive // Check if task is alive or not. bool isAlive() const; // Function: isPaused // Check if task is paused or not. bool isPaused() const; // data members private: std::string name_; // all tasks need a unique name PriorityLevel priority_; // priority determines ordering of tasks bool alive_; // if false, task will be pruned bool paused_; // if false task won't be executed }; // Type: TaskPtr // Pointer to a task, used since Task is abstract and will always be accessed // via a pointer. typedef boost::shared_ptr<Task> TaskPtr; } } #endif //G_GOAL_TASK_HPP
接下来是其管理器类了
如下
//This file is part of g lib #ifndef G_GAOL_TASKMANAGER_HPP #define G_GAOL_TASKMANAGER_HPP #ifndef _G_LIB_ #error please add g lib #endif #include <list> #include <algorithm> #include "gsingleton.hpp" #include "GTask.hpp" namespace g { namespace goal { // Class: TaskManager // TaskManager class, maintains a list of <Tasks> and manages their status, // handles adding, deleting, pausing, and unpausing tasks. // // To use TaskManager: // - (1) Add any tasks (should be derived from <Task>) // - (2) Call step() every frame when task should update. class TaskManager { //typedef std::list<TaskPtr>::iterator it public: ~TaskManager(); // Group: Running public: // Function: step // Steps the task manager, calling each active task once. void step(float timeDelta); // Group: Task Management public: // Function: addTask // Add a new <Task> to the TaskManager's list. void pushTask(TaskPtr task); // Function: killTask // Kill a task in the TaskManager task list. void killTask(const std::string& taskName); // Function: pauseTask // Pause a task in the TaskManager task list. void pauseTask(const std::string& taskName); // Function: unpauseTask // Unpause a task in the TaskManager task list. void unpauseTask(const std::string& taskName); // Function: killAllTasks void killAllTasks(); // data members private: TaskManager(); //singleton pattern. DEFINE_SINGLETON_CLASS(TaskManager); //stored list of tasks (stored in order of priority highest to lowest) std::list<TaskPtr> tasks_; //predicate for search class TaskNameEq : public std::binary_function<TaskPtr, std::string, bool> { public: bool operator()(const TaskPtr& lhs, const std::string& rhs) const; }; }; typedef g::design_pattern::Singleton<TaskManager> GTaskManager; } } #endif //G_GOAL_TASKMANAGER_HPP
相关文章推荐
- photon游戏引擎代码例子
- libgdx游戏引擎开发笔记(十二)SuperJumper游戏例子的讲解(篇六)---- .游戏主人公创建以及碰撞检测
- (转)分享一个cocos2d-x集成Photon的MMO(大型多人在线)游戏引擎
- 2D的RPG游戏人物角色移动代码(以egret游戏引擎、TypeScript语言为例)
- APE物理引擎教程(最少的代码,写最有趣的游戏)
- Unity3D + Photon 开发者沙龙(游戏引擎)
- libgdx游戏引擎开发笔记(七)SuperJumper游戏例子的讲解(篇一)---- 游戏框架的搭建
- libgdx游戏引擎开发笔记(十三)SuperJumper游戏例子的讲解(篇七)----各个物体的创建及其碰撞检测
- 265行代码实现第一人称游戏引擎
- 分享一个cocos2d-x集成Photon的MMO(大型多人在线)游戏引擎
- (虚幻3游戏引擎)Unreal3的Flash移植演讲代码示例!
- GFX游戏引擎衔接文件简述(二)Java代码部分
- 游戏引擎不仅是代码,更多的是完善的工具
- 整合Unity游戏引擎和 Visual Studio Code 代码编辑器 第二弹
- libgdx游戏引擎开发笔记(八)SuperJumper游戏例子的讲解(篇二)---- 游戏界面跳转
- LGame游戏引擎主要组件之一AVGame详解(结合具体的代码讲解)
- 265行代码实现第一人称游戏引擎
- libgdx游戏引擎开发笔记(十三)SuperJumper游戏例子的讲解(篇七)----各个物体的创建及其碰撞检测
- 使用游戏引擎photon打造一款特殊的远程控制软件
- 「游戏引擎Mojoc」(2)C代码风格