Forced pause in loops. I think i figured out a way.
So, I've been working on more source for personal use.
I've seen many addons that somehow utilize a pause. I searched quite a bit to no avail. In particular, those addons that arrange bags seem to have a timed delay in activity during execution. My thinking was.. if I can use the user defined wait() function to act as the fire for iteration, I can use and increment a table to define my iteration start pts each time wait() fires. (note that wait(), itself, does not increment the table values, the incrementing takes place in the deepest nested loop, as you can see in my code below.) So, in essence, this is a triple nested loop that is broken (hard return) on the inner most level each time. (only after incrementing the table values from which the loops obtain their start point and then invoking the wait() function) . This allows for less code than using if/then in place of the loops. This can also be re-worked in a number of ways, and is versatile to many concepts. I'm no pro, so I was hoping for feedback. Whatsup? (also stickied for those of u who prefer it: http://www.wowace.com/paste/4089/) Code:
Thanks for checking it out, I'd love any comments/advice. |
waiting is no option in a wow-addon. the game is haltet until your addon is finished with its action even if its a wait-loop :)
|
Quote:
|
This is not a wait, it's known as a timeout. It's putting aside separate code to be run later. To show some light on the subject, here's the difference.
Wait Code:
-- Some code Timeout Code:
-- Some code Note: Wait() and Timeout() do not exist and are used in pseudo-code to explain the difference in concept. |
Thanks for the clarification, SDPhantom. However, I'm not attempting to shed light on this wait function's misnomer, as I did not write it. It's right out of the wiki.
This post was to illustrate it's use to hard itterate nested loops on a delay. look closer. Notice the tables used as iterator start points for the nested loops. In use, one would obviously call to GetContainerNumSlot for the termination index, rather than leaving it at 14. The tables are updated anytime the wait is called, and the nested loops are exited. Then when wait fires its function, it calls for our original nested loops sequence to resume, using the tabled data as the start points for the iterators. |
oops I did not scroll down the code because I'd expected functions to be declared before the use and thought you're looking for help how such functions should look ... sorry :)
|
Quote:
:) |
Hello
I am not sure, but I think you are looking for a timer library. Check our timer library (RDX addon) in this file: VFL\Timers\Schedulers.lua (RDX code is full opensource and you can use it, copy it) Our API: Code:
--- Adaptive-schedule a recurring process. Code:
--- Unschedule by ID from the adaptive scheduler Code:
--- Schedule func to be executed dt seconds from now. Code:
--- Unschedule a function scheduled by ZMSchedule. Code:
--- Schedule something to happen on the next frame. Code:
--- Create a "periodic latch" around a function. The periodic latch guarantees that a function |
Quote:
Thanks sigg! Neat stuff. I used RDX for a bit, created some pretty nasty environments for my gaming, but a wow patch completely raped RDX for me and after a few days I was forced to make some changes to my dependencies in game. I loved the concept, for sure. I'm not sure the terminology of things, but the code I have above works very well. After invoking similar notions in many ways, I've determined that coders must've been using this sort of thing for many years. It's not that it's really all that complicated, it just hadn't occurred to me to do it until now. Thanks for the reply, and also.. if there is a term for what I'm doing in my code, I'd love to know it. Wb |
While the goal of your code is noble and the general idea is sound, it has some serious performance issues for code that runs every frame in an OnUpdate, which I would suggest you resolve if for no other reason than to learn why they are bad.
In no particular order: 1) Using tremove to read 3 values from a 3 value table that serves no other purpose is extremely inefficient, each call to tremove has to look up then invoke a function, the function has to move all of entries in the table, and then return the one you wanted. Stick to local a, b, c = tbl[1], tbl[2], tbl[3]. 2) Removing each entry, checking if it's ready to fire, and re-building and putting it back if not, is also very wasteful, both in terms of cycles and garbage. You're much better off looking at each entry, then either remove-and-use, or modify-in place 3) It may be much faster to keep a "currentTime" value (incremented by the 2nd argument to OnUpdate) and express fire time in terms of that, so you dont have to modify the records AT ALL. 4) You may want to consider keeping the array sorted so that the soonest tasks are at the end, then you can scan it from the end each OnUpdate, stop when you find a task that's not ready, and removal will never have to move other entries, only nil out the last one. Alternatively use a heap data structure or linked list. |
All times are GMT -6. The time now is 08:32 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI