Event Scheduling

by Stephen001
A library to provide global and local game events management and scheduling.
ID:1486865
 
BYOND Version:503
Operating System:Windows 7 Pro 64-bit
Web Browser:Chrome 32.0.1700.102
Applies to:Dream Seeker
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary: Here's a code snippet.

        New()
..()
src.state = new/Event/custom/ai/state(src, 10 * ++tick)


Where tick is equal to 0.

state calls its fire proc and does what it does and is set to reschedule itself. The problem is, usually, that one or both of them don't get to that point for some odd reason. This happens with any two combination of events.

Numbered Steps to Reproduce Problem: Call two events on the same or a multiple of 10 ticks. Set the events to reschedule (time is irrelevant) in their fire proc and watch the bug occur.

Expected Results: The events to continue to be rescheduled.

Actual Results: They pause, freeze, or otherwise don't execute.

Does the problem occur:
Every time? Or how often? Every time.
In other games? N/A
In other user accounts? N/A
On other computers? N/A

When does the problem NOT occur? Never.

Workarounds: None

Additional Details: It also happens using v.499.1202.

Just did another test and thought I'd report this.

When I changed the 10 in the OP's code snippet to 20, it worked as expected.

Edit: So I just ran this thinking it'd be a workaround.

src.state = new/Event/custom/ai/state(src, max(0, round(rand(0, 42), 3)))


The first time I ran it, the problem I thought only happened when you used 10 ticks happened (the not rescheduling thing).
Can you show me the fire() procedure of this event?
                fire() //update the drone's state.
world << "fired[drone.y]"
scheduler.reschedule(src, src.drone.movement_tick_lag)
return
if(src.drone.can_act())
if(src.drone.has_target())
src.current_state = "combat"
src.drone.action()
scheduler.reschedule(src, src.drone.tick_lag)

/*else if(src.drone.add_closest())
src.current_state = "combat"
src.drone.action()
ai_scheduler.reschedule(src, src.drone.tick_lag)*/


else //no combat calls.
if(src.drone.movement_type)
src.current_state = "movement"
src.drone.move()
scheduler.reschedule(src, src.drone.movement_tick_lag)


It returns at the beginning because I was testing whether it was was the npc was actually doing or a non-related issue.
Where is scheduler defined?

Can I also see where it is first scheduled?

scheduler.dm
var/EventScheduler/scheduler = new() //handles everything not outlined below.
var/EventScheduler/ai_scheduler = new() //handles ai.
var/EventScheduler/event_scheduler //handles minigame events.

world
New()
scheduler.start()
spawn(7) ai_scheduler.start()
..()

Del()
scheduler.stop()
spawn(7) ai_scheduler.stop()
..()



The spawns were placed to test if it was happening because they ran on the same tick.

Then it's first scheduled as seen here.


drone.dm
        New()
..()
src.state = new/Event/custom/ai/state(src, max(0, round(rand(0, 42), 4)))

Can you show me the New() procedure of that event? Seen as I assume it's actually scheduled inside that.
In response to Stephen001
Ah, my fault.


scheduler events.dm
                New(var/mob/combatant/reference, var/time)
src.drone = reference

scheduler.schedule(src, time)

Reviving a seemingly dead topic because this problem persists.

This test environment demonstrates the problem I had before. You'll notice that it (the scheduler) never fires all 10 events. Somehow, events are being left behind, skipped, etc.

Let me know if there's progress, if any at all, towards figuring out what the problem is. I rely on this implementation pretty heavily as it's a nice spawn() replacement.

Edit: Nevermind, made my own.