#include <time_scheduler.hpp>
Public Member Functions | |
TimeScheduler () | |
virtual | ~TimeScheduler () |
void | update (float time) |
void | schedule_thread (HSQUIRRELVM vm, float time) |
Static Public Attributes | |
static TimeScheduler * | instance |
Private Types | |
typedef std::vector< ScheduleEntry > | ScheduleHeap |
Private Attributes | |
ScheduleHeap | schedule |
Classes | |
struct | ScheduleEntry |
(the typical result of a wait() command in a squirrel script)
Definition at line 28 of file time_scheduler.hpp.
typedef std::vector<ScheduleEntry> scripting::TimeScheduler::ScheduleHeap [private] |
Definition at line 53 of file time_scheduler.hpp.
scripting::TimeScheduler::TimeScheduler | ( | ) |
scripting::TimeScheduler::~TimeScheduler | ( | ) | [virtual] |
void scripting::TimeScheduler::update | ( | float | time | ) |
Definition at line 37 of file time_scheduler.cpp.
References scripting::global_vm, log_warning, and schedule.
00038 { 00039 while(!schedule.empty() && schedule.front().wakeup_time < time) { 00040 HSQOBJECT thread_ref = schedule.front().thread_ref; 00041 00042 sq_pushobject(global_vm, thread_ref); 00043 sq_getweakrefval(global_vm, -1); 00044 00045 HSQUIRRELVM scheduled_vm; 00046 if(sq_gettype(global_vm, -1) == OT_THREAD && 00047 SQ_SUCCEEDED(sq_getthread(global_vm, -1, &scheduled_vm))) { 00048 if(SQ_FAILED(sq_wakeupvm(scheduled_vm, SQFalse, SQFalse, SQTrue, SQFalse))) { 00049 std::ostringstream msg; 00050 msg << "Error waking VM: "; 00051 sq_getlasterror(scheduled_vm); 00052 if(sq_gettype(scheduled_vm, -1) != OT_STRING) { 00053 msg << "(no info)"; 00054 } else { 00055 const char* lasterr; 00056 sq_getstring(scheduled_vm, -1, &lasterr); 00057 msg << lasterr; 00058 } 00059 log_warning << msg.str() << std::endl; 00060 sq_pop(scheduled_vm, 1); 00061 } 00062 } 00063 00064 sq_release(global_vm, &thread_ref); 00065 sq_pop(global_vm, 2); 00066 00067 std::pop_heap(schedule.begin(), schedule.end()); 00068 schedule.pop_back(); 00069 } 00070 }
void scripting::TimeScheduler::schedule_thread | ( | HSQUIRRELVM | vm, | |
float | time | |||
) |
Definition at line 73 of file time_scheduler.cpp.
References scripting::global_vm, schedule, scripting::TimeScheduler::ScheduleEntry::thread_ref, scripting::vm_to_object(), and scripting::TimeScheduler::ScheduleEntry::wakeup_time.
Referenced by scripting::wait().
00074 { 00075 // create a weakref to the VM 00076 SQObject vm_obj = vm_to_object(scheduled_vm); 00077 sq_pushobject(global_vm, vm_obj); 00078 sq_weakref(global_vm, -1); 00079 00080 ScheduleEntry entry; 00081 if(SQ_FAILED(sq_getstackobj(global_vm, -1, & entry.thread_ref))) { 00082 sq_pop(global_vm, 2); 00083 throw SquirrelError(global_vm, "Couldn't get thread weakref from vm"); 00084 } 00085 entry.wakeup_time = time; 00086 00087 sq_addref(global_vm, & entry.thread_ref); 00088 sq_pop(global_vm, 2); 00089 00090 schedule.push_back(entry); 00091 std::push_heap(schedule.begin(), schedule.end()); 00092 }
TimeScheduler * scripting::TimeScheduler::instance [static] |
Definition at line 37 of file time_scheduler.hpp.
Referenced by ScreenManager::update_gamelogic(), and scripting::wait().