janwas
c0ed950657
this snowballed into a massive search+destroy of the hodgepodge of mostly equivalent types we had in use (int, uint, unsigned, unsigned int, i32, u32, ulong, uintN). it is more efficient to use 64-bit types in 64-bit mode, so the preferred default is size_t (for anything remotely resembling a size or index). tile coordinates are ssize_t to allow more efficient conversion to/from floating point. flags are int because we almost never need more than 15 distinct bits, bit test/set is not slower and int is fastest to type. finally, some data that is pretty much directly passed to OpenGL is now typed accordingly. after several hours, the code now requires fewer casts and less guesswork. other changes: - unit and player IDs now have an "invalid id" constant in the respective class to avoid casting and -1 - fix some endian/64-bit bugs in the map (un)packing. added a convenience function to write/read a size_t. - ia32: change CPUID interface to allow passing in ecx (required for cache topology detection, which I need at work). remove some unneeded functions from asm, replace with intrinsics where possible. This was SVN commit r5942.
102 lines
3.5 KiB
C++
102 lines
3.5 KiB
C++
// Scheduler.h
|
|
//
|
|
// Message scheduler
|
|
//
|
|
|
|
#ifndef INCLUDED_SCHEDULER
|
|
#define INCLUDED_SCHEDULER
|
|
|
|
#include <queue>
|
|
#include <list>
|
|
#include <set>
|
|
|
|
#include "EntityHandles.h"
|
|
#include "ps/Singleton.h"
|
|
#include "ps/CStr.h"
|
|
#include "scripting/ScriptableObject.h"
|
|
|
|
class CJSProgressTimer;
|
|
|
|
// Message, destination and delivery time information.
|
|
struct SDispatchObject
|
|
{
|
|
int id;
|
|
int deliveryTime;
|
|
bool isRecurrent; int delay;
|
|
SDispatchObject( int _id, const int _deliveryTime )
|
|
: id(_id), deliveryTime( _deliveryTime ), isRecurrent( false ) {}
|
|
SDispatchObject( int _id, const int _deliveryTime, const int _recurrence )
|
|
: id(_id), deliveryTime( _deliveryTime ), isRecurrent( true ), delay( _recurrence ) {}
|
|
inline bool operator<( const SDispatchObject& compare ) const
|
|
{
|
|
return( deliveryTime > compare.deliveryTime );
|
|
}
|
|
};
|
|
|
|
struct SDispatchObjectScript : public SDispatchObject
|
|
{
|
|
CStrW script;
|
|
JSObject* operateOn;
|
|
inline SDispatchObjectScript( int _id, const CStrW& _script,
|
|
const int _deliveryTime, JSObject* _operateOn = NULL )
|
|
: SDispatchObject( _id, _deliveryTime ), script( _script ), operateOn( _operateOn ) {}
|
|
inline SDispatchObjectScript( int _id, const CStrW& _script,
|
|
const int _deliveryTime, JSObject* _operateOn, const int recurrence )
|
|
: SDispatchObject( _id, _deliveryTime, recurrence ), script( _script ), operateOn( _operateOn ) {}
|
|
};
|
|
|
|
struct SDispatchObjectFunction : public SDispatchObject
|
|
{
|
|
JSFunction* function;
|
|
JSObject* operateOn;
|
|
inline SDispatchObjectFunction( int _id, JSFunction* _function,
|
|
const int _deliveryTime, JSObject* _operateOn = NULL )
|
|
: SDispatchObject( _id, _deliveryTime ), function( _function ), operateOn( _operateOn ) {}
|
|
inline SDispatchObjectFunction( int _id, JSFunction* _function,
|
|
const int _deliveryTime, JSObject* _operateOn, const int recurrence )
|
|
: SDispatchObject( _id, _deliveryTime, recurrence ), function( _function ), operateOn( _operateOn ) {}
|
|
};
|
|
|
|
struct CScheduler : public Singleton<CScheduler>
|
|
{
|
|
std::priority_queue<SDispatchObjectScript> timeScript, frameScript;
|
|
std::priority_queue<SDispatchObjectFunction> timeFunction, frameFunction;
|
|
std::list<CJSProgressTimer*> progressTimers;
|
|
int m_nextTaskId;
|
|
bool m_abortInterval;
|
|
STL_HASH_SET<int> tasksToCancel;
|
|
|
|
CScheduler();
|
|
int PushTime( int delay, const CStrW& fragment, JSObject* operateOn = NULL );
|
|
int PushFrame( int delay, const CStrW& fragment, JSObject* operateOn = NULL );
|
|
int PushInterval( int first, int interval, const CStrW& fragment, JSObject* operateOn = NULL, int id = 0 );
|
|
int PushTime( int delay, JSFunction* function, JSObject* operateOn = NULL );
|
|
int PushFrame( int delay, JSFunction* function, JSObject* operateOn = NULL );
|
|
int PushInterval( int first, int interval, JSFunction* function, JSObject* operateOn = NULL, int id = 0 );
|
|
void PushProgressTimer( CJSProgressTimer* progressTimer );
|
|
void CancelTask( int id );
|
|
void Update(int elapsedSimulationTime);
|
|
};
|
|
|
|
#define g_Scheduler CScheduler::GetSingleton()
|
|
|
|
class CJSProgressTimer : public CJSObject<CJSProgressTimer>
|
|
{
|
|
friend struct CScheduler;
|
|
double m_Max, m_Current, m_Increment;
|
|
JSFunction* m_Callback;
|
|
JSObject* m_OperateOn;
|
|
CJSProgressTimer( double Max, double Increment, JSFunction* Callback, JSObject* OperateOn );
|
|
static JSBool Construct( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
|
|
public:
|
|
static void ScriptingInit();
|
|
};
|
|
|
|
// made visible to main.cpp's Frame() so that it can abort after 100 frames
|
|
// if g_FixedFrameTiming == true (allows measuring performance).
|
|
extern int frameCount;
|
|
|
|
extern const int ORDER_DELAY;
|
|
|
|
#endif
|