Last active
December 15, 2015 21:49
-
-
Save tkymx/063e3c7bbbed651d78fb to your computer and use it in GitHub Desktop.
CTask CTaskManager
タスクの概念を実装するために用いる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Task.h" | |
CTask::CTask(void) | |
{ | |
} | |
CTask::~CTask(void) | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<string> | |
#include<vector> | |
using namespace std; | |
/* | |
CTask | |
○概要 | |
タスク情報が記録されている | |
異本的には、タスクマネージャーに登録しておき | |
初期化 | |
更新 | |
開放 | |
タスクマネージャーによって生成されるイベント | |
などによって呼び出される | |
○使用法 | |
使用時には、このクラスを継承し | |
作成したタスクマネージャーに登録する。 | |
なおイベントは生成時に呼ばれる(マネージャー実行) | |
*/ | |
class CTask | |
{ | |
public: | |
CTask(void); | |
virtual ~CTask(void); | |
public: | |
virtual int OnInit()=0; | |
virtual void OnUpdate()=0; | |
virtual void OnRelase()=0; | |
virtual void OnEvent(string message)=0; | |
}; | |
//ポインタ改名 | |
typedef CTask* LPTask; | |
//タスクの集まり | |
typedef vector<LPTask> VECLPTASK; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "TaskManager.h" | |
CTaskManager::CTaskManager(void) | |
{ | |
m_ctasks.clear(); | |
} | |
CTaskManager::~CTaskManager(void) | |
{ | |
m_ctasks.clear(); | |
} | |
int CTaskManager::Init() | |
{ | |
//後でエラー処理を書く | |
try | |
{ | |
//メイン初期化 | |
OnInit(); | |
//タスクのループ | |
for(VECLPTASK::iterator it = m_ctasks.begin(); it != m_ctasks.end(); it++ ) | |
{ | |
(*it)->OnInit(); | |
} | |
} | |
catch( string e ) | |
{ | |
return false; | |
} | |
return true; | |
} | |
void CTaskManager::Update() | |
{ | |
//メイン更新 | |
OnUpdate(); | |
//タスクのループ | |
for(VECLPTASK::iterator it = m_ctasks.begin(); it != m_ctasks.end(); it++ ) | |
{ | |
(*it)->OnUpdate(); | |
} | |
} | |
void CTaskManager::Release() | |
{ | |
//メイン開放 | |
OnRelase(); | |
//タスクのループ | |
for(VECLPTASK::iterator it = m_ctasks.begin(); it != m_ctasks.end(); it++ ) | |
{ | |
(*it)->OnRelase(); | |
} | |
} | |
void CTaskManager::ExecuteEvent(string message) | |
{ | |
//タスクのループ | |
for(VECLPTASK::iterator it = m_ctasks.begin(); it != m_ctasks.end(); it++ ) | |
{ | |
(*it)->OnEvent(message); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include<string> | |
#include<vector> | |
#include"Task.h" | |
using namespace std; | |
/* | |
CTaskManager | |
○概要 | |
タスクマネージャーでは、追加されたタスクの実行を行う | |
生成後にタスクを追加し、初期化、更新、開放などのタイミングで | |
下のタスクも同様に実行される。 | |
○使用法 | |
使用時は継承を行うことで使用できる | |
その際に大事になってくることはイベントの生成である | |
イベントの生成は基本的には更新時にデータセンターへのアクセスによって | |
動機付けを行って生成関数を実行する。この関数は外部からも実行できるが | |
内部での循環にとどめておきたい | |
*/ | |
class CTaskManager | |
{ | |
private: | |
VECLPTASK m_ctasks; //子Taskたち | |
public: | |
CTaskManager(void); | |
virtual ~CTaskManager(void); | |
public: | |
int Init(); | |
void Update(); | |
void Release(); | |
void ExecuteEvent(string message); | |
private: | |
virtual int OnInit()=0; | |
virtual void OnUpdate()=0; | |
virtual void OnRelase()=0; | |
}; | |
typedef CTaskManager* LPTaskManager; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment