1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef COB_ENGINE_H
#define COB_ENGINE_H
/*
* The cob engine is responsible for "scheduling" and running threads that are
* running in infinite loops.
* It also manages reading and caching of the actual .cob files
*/
#include "CobThread.h"
#include "System/creg/creg_cond.h"
#include "System/creg/STL_Queue.h"
#include <vector>
#include <map>
class CCobThread;
class CCobInstance;
class CCobFile;
class CCobThreadPtr_less : public std::binary_function<CCobThread*, CCobThread*, bool> {
public:
bool operator() (const CCobThread* const& a, const CCobThread* const& b) const {
return a->GetWakeTime() > b->GetWakeTime();
}
};
class CCobEngine
{
CR_DECLARE_STRUCT(CCobEngine)
protected:
std::vector<CCobThread*> running;
/**
* Threads are added here if they are in Running.
* And moved to real running after running is empty.
*/
std::vector<CCobThread*> wantToRun;
std::priority_queue<CCobThread*, std::vector<CCobThread*>, CCobThreadPtr_less> sleeping;
CCobThread* curThread;
int currentTime;
void TickThread(CCobThread* thread);
public:
CCobEngine();
~CCobEngine();
void AddThread(CCobThread* thread);
void Tick(int deltaTime);
void ShowScriptError(const std::string& msg);
int GetCurrentTime() { return currentTime; }
};
class CCobFileHandler
{
protected:
std::map<std::string, CCobFile*> cobFiles;
public:
~CCobFileHandler();
CCobFile* GetCobFile(const std::string& name);
CCobFile* ReloadCobFile(const std::string& name);
const CCobFile* GetScriptAddr(const std::string& name) const;
};
extern CCobEngine* cobEngine;
extern CCobFileHandler* cobFileHandler;
#endif // COB_ENGINE_H
|