2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
// Scheduler.h
|
|
|
|
//
|
|
|
|
// Message scheduler
|
|
|
|
//
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_SCHEDULER
|
|
|
|
#define INCLUDED_SCHEDULER
|
2004-07-20 21:30:35 +02:00
|
|
|
|
|
|
|
#include <queue>
|
2005-05-18 07:32:09 +02:00
|
|
|
#include <list>
|
2005-12-18 08:33:16 +01:00
|
|
|
#include <set>
|
2005-05-18 07:32:09 +02:00
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
#include "EntityHandles.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/Singleton.h"
|
|
|
|
#include "ps/CStr.h"
|
2005-04-15 06:23:33 +02:00
|
|
|
#include "scripting/ScriptableObject.h"
|
|
|
|
|
|
|
|
class CJSProgressTimer;
|
2004-07-20 21:30:35 +02:00
|
|
|
|
|
|
|
// Message, destination and delivery time information.
|
|
|
|
struct SDispatchObject
|
|
|
|
{
|
2005-12-18 08:33:16 +01:00
|
|
|
int id;
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
int deliveryTime;
|
|
|
|
bool isRecurrent; int delay;
|
|
|
|
SDispatchObject( int _id, const int _deliveryTime )
|
2005-12-18 08:33:16 +01:00
|
|
|
: id(_id), deliveryTime( _deliveryTime ), isRecurrent( false ) {}
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
SDispatchObject( int _id, const int _deliveryTime, const int _recurrence )
|
2005-12-18 08:33:16 +01:00
|
|
|
: id(_id), deliveryTime( _deliveryTime ), isRecurrent( true ), delay( _recurrence ) {}
|
2004-07-20 21:30:35 +02:00
|
|
|
inline bool operator<( const SDispatchObject& compare ) const
|
|
|
|
{
|
2004-07-20 23:12:28 +02:00
|
|
|
return( deliveryTime > compare.deliveryTime );
|
2004-07-20 21:30:35 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SDispatchObjectScript : public SDispatchObject
|
|
|
|
{
|
2004-09-03 16:08:12 +02:00
|
|
|
CStrW script;
|
2004-07-20 21:30:35 +02:00
|
|
|
JSObject* operateOn;
|
2005-12-18 08:33:16 +01:00
|
|
|
inline SDispatchObjectScript( int _id, const CStrW& _script,
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
const int _deliveryTime, JSObject* _operateOn = NULL )
|
2005-12-18 08:33:16 +01:00
|
|
|
: SDispatchObject( _id, _deliveryTime ), script( _script ), operateOn( _operateOn ) {}
|
|
|
|
inline SDispatchObjectScript( int _id, const CStrW& _script,
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
const int _deliveryTime, JSObject* _operateOn, const int recurrence )
|
2005-12-18 08:33:16 +01:00
|
|
|
: SDispatchObject( _id, _deliveryTime, recurrence ), script( _script ), operateOn( _operateOn ) {}
|
2004-07-20 21:30:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SDispatchObjectFunction : public SDispatchObject
|
|
|
|
{
|
|
|
|
JSFunction* function;
|
|
|
|
JSObject* operateOn;
|
2005-12-18 08:33:16 +01:00
|
|
|
inline SDispatchObjectFunction( int _id, JSFunction* _function,
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
const int _deliveryTime, JSObject* _operateOn = NULL )
|
2005-12-18 08:33:16 +01:00
|
|
|
: SDispatchObject( _id, _deliveryTime ), function( _function ), operateOn( _operateOn ) {}
|
|
|
|
inline SDispatchObjectFunction( int _id, JSFunction* _function,
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
const int _deliveryTime, JSObject* _operateOn, const int recurrence )
|
2005-12-18 08:33:16 +01:00
|
|
|
: SDispatchObject( _id, _deliveryTime, recurrence ), function( _function ), operateOn( _operateOn ) {}
|
2004-07-20 21:30:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CScheduler : public Singleton<CScheduler>
|
|
|
|
{
|
|
|
|
std::priority_queue<SDispatchObjectScript> timeScript, frameScript;
|
|
|
|
std::priority_queue<SDispatchObjectFunction> timeFunction, frameFunction;
|
2005-04-15 06:23:33 +02:00
|
|
|
std::list<CJSProgressTimer*> progressTimers;
|
2005-12-18 08:33:16 +01:00
|
|
|
int m_nextTaskId;
|
2004-07-20 21:30:35 +02:00
|
|
|
bool m_abortInterval;
|
2005-12-18 08:41:02 +01:00
|
|
|
STL_HASH_SET<int> tasksToCancel;
|
2004-07-20 21:30:35 +02:00
|
|
|
|
2005-12-18 08:33:16 +01:00
|
|
|
CScheduler();
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
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 );
|
2007-05-02 14:07:08 +02:00
|
|
|
void PushProgressTimer( CJSProgressTimer* progressTimer );
|
|
|
|
void CancelTask( int id );
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
void Update(int elapsedSimulationTime);
|
2004-07-20 21:30:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define g_Scheduler CScheduler::GetSingleton()
|
|
|
|
|
2005-04-15 06:23:33 +02:00
|
|
|
class CJSProgressTimer : public CJSObject<CJSProgressTimer>
|
|
|
|
{
|
2005-05-18 07:32:09 +02:00
|
|
|
friend struct CScheduler;
|
2005-04-15 06:23:33 +02:00
|
|
|
double m_Max, m_Current, m_Increment;
|
|
|
|
JSFunction* m_Callback;
|
|
|
|
JSObject* m_OperateOn;
|
|
|
|
CJSProgressTimer( double Max, double Increment, JSFunction* Callback, JSObject* OperateOn );
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
static JSBool Construct( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
|
2005-04-15 06:23:33 +02:00
|
|
|
public:
|
|
|
|
static void ScriptingInit();
|
|
|
|
};
|
|
|
|
|
2005-08-15 01:34:37 +02:00
|
|
|
// made visible to main.cpp's Frame() so that it can abort after 100 frames
|
|
|
|
// if g_FixedFrameTiming == true (allows measuring performance).
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
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.
2008-05-11 20:48:32 +02:00
|
|
|
extern int frameCount;
|
2005-08-15 01:34:37 +02:00
|
|
|
|
2004-10-07 21:23:35 +02:00
|
|
|
extern const int ORDER_DELAY;
|
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
#endif
|