Sswift's event system question

Blitz3D Forums/Blitz3D Programming/Sswift's event system question

Dustin(Posted 2005) [#1]
I'm using Sswift's nifty little event system: http://www.blitzbasic.com/codearcs/codearcs.php?code=632

Question... how do you kill an active event before it expires?

Example:
Create an event-
Newevent.event(5,MilliSecs(),MilliSecs()+5000)

To kill it the only way I see, at the moment, is to cycle through all of the events, find it then kill it:
For ThisEvent.event = Each event
If ThisEvent\event_type = 5 Then Delete ThisEvent
Next

Is there a more efficient way?


sswift(Posted 2005) [#2]
Heh, I don't even use that myself (too much work to bother with event systems unless I'm forced to with Blitzplus, and then only for windows events) so I don't remember exaclty what I was doing with that system, but I think I can offer a suggestion.

Looping through all the events really wouldn't be any kind of performance hit worth worrying about. I would just do that. I loop through large types with lots of objects in many of my systems. It's just not going to suck that much CPU time to worry about. Less than a millisecond probably.

But if you really want to delete an event faster, you'll have to store the pointer to the event type somewhere. And since the system can delete an event at any time if it's a timed event, then you need to worry about what happens if you try to access that event manually after it has been deleted by the system.

Thankfully, Blitz helps you out here. I think. I'm pretty sure that if you have a pointer to a type in another type, that if the type is deleted, the pointer in the type referencing it will be automatically set to null.

I think this might even work if the type is in a variable.

So if you go KillMe.Event = New Event, and then you go Blah.Event= KillMe then if you go Delete KillMe, then Blah should be set to Null.

It should be easy for you to test this. But in any case, if that does not work, I am almost 100% positive it will work if Blah.Event is a field in a type.

But that's kind of kludgy, don't you think? I think the better solution is to just make a killevent function that goes through and looks for events of a specific type like you show above and kills them all.


Dustin(Posted 2005) [#3]
Cool! I'll take you're word for it. And quite honestly I'll never have more than 5 or 6 events active at any moment. It was more for future planning. I just thought that there was a more efficient system out there. I'm pleasently surprised to see that I was wrong!

Thanks!


Dustin(Posted 2005) [#4]
Hmm, still struggling here a little bit. I understand that if you create a pointer that references an object in a type and then kill that pointer you are in effect killing that object in the type.

But how do reference the pointer to the type? I've tried referencing it with a standard variable and I've tried creating a new type who's sole purpose is to point to the other type. But all attempts seem to end with a "Variable must be a Type" error.

Okay, so what am I mucking up here?


sswift(Posted 2005) [#5]
Type Event
Field Nothing
End Type

Type Monster
Field Something.Event
End Type

ThisMonster.Monster = New Monster
ThisEvent.Event = New Event
ThisMonster\Something = ThisEvent

Delete ThisEvent

IF ThisMonster\Something = Null Then Print "Hooray!"


Dustin(Posted 2005) [#6]
You make it look so easy. Big thanks!