Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
165
Src/Wasabi/api/script/objects/timer.cpp
Normal file
165
Src/Wasabi/api/script/objects/timer.cpp
Normal file
|
@ -0,0 +1,165 @@
|
|||
#include <precomp.h>
|
||||
#include "timer.h"
|
||||
#include <api/script/scriptmgr.h>
|
||||
#include <api/script/objects/rootobject.h>
|
||||
//#include <api/wac/main.h>//CUT!!
|
||||
//#include <api/timer/genwnd.h> //CUT!!
|
||||
|
||||
STimer::STimer() {
|
||||
getScriptObject()->vcpu_setInterface(timerGuid, (void *)static_cast<STimer *>(this));
|
||||
getScriptObject()->vcpu_setClassName(L"Timer");
|
||||
getScriptObject()->vcpu_setController(timerController);
|
||||
delay = 1000;
|
||||
started = 0;
|
||||
}
|
||||
|
||||
STimer::~STimer() {
|
||||
}
|
||||
|
||||
void STimer::setDelay(int d) {
|
||||
delay = d;
|
||||
if (started)
|
||||
timerclient_setTimer(STIMER_ID, getDelay());
|
||||
}
|
||||
|
||||
int STimer::getDelay(void) {
|
||||
return delay;
|
||||
}
|
||||
|
||||
void STimer::start(void) {
|
||||
if (started) { stop(); }
|
||||
timerclient_setTimer(STIMER_ID, getDelay());
|
||||
started = 1;
|
||||
}
|
||||
|
||||
void STimer::stop(void) {
|
||||
if (!started) return;
|
||||
timerclient_killTimer(STIMER_ID);
|
||||
started = 0;
|
||||
}
|
||||
|
||||
void STimer::onTimer(void)
|
||||
{
|
||||
if (started)
|
||||
{
|
||||
script_onTimer(SCRIPT_CALL, getScriptObject());
|
||||
}
|
||||
}
|
||||
|
||||
void STimer::timerclient_timerCallback(int id)
|
||||
{
|
||||
if (id == STIMER_ID)
|
||||
onTimer();
|
||||
}
|
||||
|
||||
int STimer::isRunning() {
|
||||
return started;
|
||||
}
|
||||
|
||||
TimerScriptController _timerController;
|
||||
TimerScriptController *timerController=&_timerController;
|
||||
|
||||
// -- Functions table -------------------------------------
|
||||
function_descriptor_struct TimerScriptController::exportedFunction[] = {
|
||||
{L"setDelay", 1, (void*)STimer::script_setDelay },
|
||||
{L"getDelay", 0, (void*)STimer::script_getDelay },
|
||||
{L"start", 0, (void*)STimer::script_start },
|
||||
{L"stop", 0, (void*)STimer::script_stop },
|
||||
{L"onTimer", 0, (void*)STimer::script_onTimer },
|
||||
{L"isRunning",0, (void*)STimer::script_isRunning },
|
||||
{L"getSkipped",0, (void*)STimer::script_getSkipped },
|
||||
};
|
||||
// --------------------------------------------------------
|
||||
|
||||
const wchar_t *TimerScriptController::getClassName() {
|
||||
return L"Timer";
|
||||
}
|
||||
|
||||
const wchar_t *TimerScriptController::getAncestorClassName() {
|
||||
return L"Object";
|
||||
}
|
||||
|
||||
ScriptObjectController *TimerScriptController::getAncestorController() {
|
||||
return rootScriptObjectController;
|
||||
}
|
||||
|
||||
ScriptObject *TimerScriptController::instantiate() {
|
||||
STimer *s = new STimer;
|
||||
ASSERT(s != NULL);
|
||||
return s->getScriptObject();
|
||||
}
|
||||
|
||||
void TimerScriptController::destroy(ScriptObject *o) {
|
||||
STimer *s = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
|
||||
ASSERT(s != NULL);
|
||||
delete s;
|
||||
}
|
||||
|
||||
void *TimerScriptController::encapsulate(ScriptObject *o) {
|
||||
return NULL; // no encapsulation for timer yet
|
||||
}
|
||||
|
||||
void TimerScriptController::deencapsulate(void *o) {
|
||||
}
|
||||
|
||||
int TimerScriptController::getNumFunctions() {
|
||||
return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
|
||||
}
|
||||
|
||||
const function_descriptor_struct *TimerScriptController::getExportedFunctions() {
|
||||
return exportedFunction;
|
||||
}
|
||||
|
||||
GUID TimerScriptController::getClassGuid() {
|
||||
return timerGuid;
|
||||
}
|
||||
|
||||
scriptVar STimer::script_onTimer(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT;
|
||||
PROCESS_HOOKS0(o, timerController);
|
||||
SCRIPT_FUNCTION_CHECKABORTEVENT;
|
||||
SCRIPT_EXEC_EVENT0(o);
|
||||
}
|
||||
|
||||
scriptVar STimer::script_setDelay(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar d) {
|
||||
SCRIPT_FUNCTION_INIT;
|
||||
ASSERT(SOM::isNumeric(&d));
|
||||
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
|
||||
if (t) t->setDelay(SOM::makeInt(&d));
|
||||
RETURN_SCRIPT_VOID;
|
||||
}
|
||||
|
||||
scriptVar STimer::script_getDelay(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT;
|
||||
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
|
||||
if (t) return MAKE_SCRIPT_INT(t->getDelay());
|
||||
RETURN_SCRIPT_ZERO;
|
||||
}
|
||||
|
||||
scriptVar STimer::script_start(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT;
|
||||
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
|
||||
if (t) t->start();
|
||||
RETURN_SCRIPT_VOID;
|
||||
}
|
||||
|
||||
scriptVar STimer::script_stop(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT;
|
||||
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
|
||||
if (t) t->stop();
|
||||
RETURN_SCRIPT_VOID;
|
||||
}
|
||||
|
||||
scriptVar STimer::script_isRunning(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT;
|
||||
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
|
||||
if (t) return MAKE_SCRIPT_BOOLEAN(t->isRunning());
|
||||
RETURN_SCRIPT_ZERO;
|
||||
}
|
||||
|
||||
scriptVar STimer::script_getSkipped(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
|
||||
SCRIPT_FUNCTION_INIT;
|
||||
STimer *t = static_cast<STimer *>(o->vcpu_getInterface(timerGuid));
|
||||
if (t) return MAKE_SCRIPT_INT(t->timerclient_getSkipped());
|
||||
RETURN_SCRIPT_ZERO;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue