Beispiel #1
0
void CreateTimer(ScriptValue &s, ScriptValue *args) {
	if (args[1].intVal < 1 || args[1].intVal > (1<<30)) {
		return;
	}
	ObjectValue *obj;
	int function = GetFunction(&args[0], &args[3], obj);
	if (function < 0) return;
	int index = FindTimerSpace();
	if (index == -1) {
		if (obj) obj->Release();
		return;
	}
	if (!(timers[index].slowTimer = (Timer*) malloc(sizeof(Timer)))) {
		if (obj) obj->Release();
		timers[index].type = KILLED_TIMER;
		return;
	}
	timers[index].obj = obj;
	timers[index].type = SLOW_TIMER;
	timers[index].function = function;
	timers[index].slowTimer->Init(SlowTimerProc, (void*)(size_t)index, args[1].intVal, RUN_ALWAYS, 0, SAVE_NONE);
	if (timers[index].slowTimer->timerMode != RUN_ALWAYS) {
		timers[index].Kill();
	}
	else {
		CreateIntValue(s, index+1);
		if (args[2].intVal == 0) {
			timers[index].slowTimer->lastRun = time64i();
			timers[index].slowTimer->ChangeDelay(timers[index].slowTimer->delay);
		}
	}
}
Beispiel #2
0
void CreateFastTimer(ScriptValue &s, ScriptValue *args) {
	if (args[1].intVal < 10 || args[1].intVal > 3600000) {
		return;
	}
	ObjectValue *obj;
	int function = GetFunction(&args[0], &args[3], obj);
	if (function < 0) return;

	int index = FindTimerSpace();
	if (index == -1) {
		if (obj) obj->Release();
		return;
	}
	timers[index].type = FAST_TIMER;
	timers[index].obj = obj;
	timers[index].function = function;
	timers[index].fastTimer.active = 0;
	timers[index].fastTimer.id = index+10;
	timers[index].fastTimer.delay = args[1].i32;
	if (!timers[index].Start(1)) {
		timers[index].Kill();
	}
	else {
		CreateIntValue(s, index+1);
		if (args[2].intVal)
			RunTimerFunction(timers[index].function, timers[index].obj, index+1);
	}
}
Beispiel #3
0
void ScriptTimer::Kill() {
	if (type != KILLED_TIMER) {
		Stop();
		if (type == SLOW_TIMER) free(slowTimer);
		type = KILLED_TIMER;
		if (obj) {
			obj->Release();
			obj = 0;
		}
	}
}