| 06-28-2009, 02:33 PM | #1 |
I want to emulate a Wait usable like PolledWait() without its drawbacks (inaccurate, not nulling timer local variable, and totally avoid TriggerSleepAction, because of its drawbacks (not stopped when the game is paused, can't be used in a boolexpr) ). The result will be a bloat vJass code, but i don't care, i don't want the most efficiency possible, just be friendly user. Let's give an example : JASS:function Test takes nothing returns nothing local unit u = GetTriggerUnit() local integer i = 0 call Wait(0.) // F___1 // code after Wait1 set u = null loop // Loop___1 // code after Loop1 call Wait(1.) // F___2 // code after Wait2 exitwhen false call Wait(2.) // F___3 // code after Wait3 exitwhen true call Wait(3.) // F___4 // code after Wait4 if i == 1 then call Wait(4.) // F___5 // code after Wait5 elseif i == 2 then call Wait(5.) // F___6 // code after Wait6 loop exitwhen false call Wait(6.) // F___7 // code after Wait7 endloop // After___Loop2 // code after Loop2 else call Wait(7.) // F___8 // code after Wait8 endif // EndIf___1 // code after if/then else 1 endloop // After___Loop1 // code after Loop1 if i == 5 then endif call Wait(8.) // F___9 // code after Wait9 endfunction Should be replaced by : JASS:private struct s___data unit u integer i endstruct globals private s___data This___data private keyword Loop___1 private keyword Loop___2 private keyword AfterLoop___1 private keyword AfterLoop___2 private keyword EndIf___1 endglobals private function F___9 takes nothing returns boolean set This___data = KT_GetData() // code after Wait9 call This___data.destroy() set This___data.u = null return true endfunction private function F___8 takes nothing returns boolean set This___data = KT_GetData() // code after Wait8 call EndIf___1.evaluate() return true endfunction private function F___7 takes nothing returns boolean set This___data = KT_GetData() // code after Wait7 call Loop___2.evaluate() return true endfunction private function F___6 takes nothing returns boolean set This___data = KT_GetData() // code after Wait6 call Loop___2.evaluate() return true endfunction private function F___5 takes nothing returns boolean set This___data = KT_GetData() // code after Wait5 call EndIf___1.evaluate() return true endfunction private function F___4 takes nothing returns boolean set This___data = KT_GetData() // code after Wait4 if This___data.i == 1 then call KT_Add(function F___5,This___data,4.) elseif This___data.i == 2 then call KT_Add(function F___6,This___data,5.) else call KT_Add(function F___8,This___data,7.) endif return true endfunction private function F___3 takes nothing returns boolean set This___data = KT_GetData() // code after Wait3 if true then call AfterLoop___1.evaluate() else call KT_Add(function F___4,This___data,3.) endif return true endfunction private function F___2 takes nothing returns boolean set This___data = KT_GetData() // code after Wait2 if false then call AfterLoop___1.evaluate() else call KT_Add(function F___3,This___data,2.) endif return true endfunction private function F___1 takes nothing returns boolean set This___data = KT_GetData() // code after Wait1 set This___data.u = null call Loop___1.evaluate() return true endfunction private function EndIf___1 takes nothing returns nothing // code after if/then else 1 call Loop___1.evaluate() endfunction private function AfterLoop___2 takes nothing returns nothing // code after Loop2 call EndIf___1.evaluate() endfunction private function AfterLoop___1 takes nothing returns nothing // code after Loop1 if This___data.i == 5 then endif call KT_Add(function F___9,This___data,8.) endfunction private function Loop___2 takes nothing returns nothing if false then call AfterLoop___2.evaluate() else call KT_Add(function F___7,This___data,6.) endif endfunction private function Loop___1 takes nothing returns nothing // code after Loop1 call KT_Add(function F___2,This___data,1.) endfunction function CopyTest takes nothing returns nothing set This___data = s___data.create() set This___data.u = GetTriggerUnit() set This___data.i = 0 call KT_Add(function F___1,This___data,0.) endfunction function Test takes nothing returns nothing local unit u = GetTriggerUnit() local integer i = 0 call Wait(0.) // F___1 // code after Wait1 set u = null loop // Loop___1 // code after Loop1 call Wait(1.) // F___2 // code after Wait2 exitwhen false call Wait(2.) // F___3 // code after Wait3 exitwhen true call Wait(3.) // F___4 // code after Wait4 if i == 1 then call Wait(4.) // F___5 // code after Wait5 elseif i == 2 then call Wait(5.) // F___6 // code after Wait6 loop exitwhen false call Wait(6.) // F___7 // code after Wait7 endloop // After___Loop2 // code after Loop2 else call Wait(7.) // F___8 // code after Wait8 endif // EndIf___1 // code after if/then else 1 endloop // After___Loop1 // code after Loop1 if i == 5 then endif call Wait(8.) // F___9 // code after Wait9 endfunction So first is it possible without editing the vJass preprocessor itself ? Because i don't want touch it, and neither recode all vJass features ... I perfectly know : - The code must be in a scope or a library, but it's not a problem for me. - local array are not supported yet, i think i will use hashtables. - events responses Get... won't work after a Wait, i will declare them in the struct later. - i've to declare an empty Wait function that takes a real r and returns nothing, and place it on the top of the script, just after the globals declaration, and i need to place the library KT to be the first. - I could reduce the numbers of evaluates, if i handle better the position of the functions. |
| 06-28-2009, 04:46 PM | #2 |
If you want to do it correctly, it is tougher than compiling structs, that's for sure. If you just want to pull out a hack then I guess you could even do something as dumb as compiling your waits to Mad[lion]'s timing system: http://www.wc3c.net/showthread.php?t=101988 |
| 06-28-2009, 04:55 PM | #3 |
Textmacros ... It doesn't help me. I just want to know if i can make a vJass version of the code and let JassHelper do the jass compilation or if i need to edit your preprocessor. |
| 06-28-2009, 04:58 PM | #4 |
Please read that again, you could compile your wait call into those textmacros. |
| 06-28-2009, 05:00 PM | #5 | |
Quote:
|
| 06-28-2009, 06:26 PM | #6 | ||
Quote:
See, if you compile the code into textmacros that doesn't mean the user has to deal with textmacros. |
| 06-28-2009, 07:37 PM | #7 |
I'm lost ![]() Could you give an example plz ? Or maybe i'm not enough clear, and you don't understand what i want. |
| 06-29-2009, 01:05 PM | #8 |
well, you make your compiler compile call wait(x) into //!runtextmacro wait(x) |
| 06-29-2009, 08:55 PM | #9 |
This is relatively simple in principal. You turn all local variables into struct variables, and turn the function into a state machine. When the function is called you allocate a struct, then pass that to the actual worker function. The worker function looks at the struct, sees that it is in state 0, and starts from the beginning. The hard part is that for a real wait you also need to rewrite the CALLING function, and ITS calling function and so on. Otherwise they will just finish without waiting, even though your method is now on a timer. That is going to be painful, especially if you want to deal with cases where the function is called indirectly, eg. with TriggerEvaluate or ExecuteFunc. I really don't think you're going to be able to deal with the recursive waiting case. |
| 07-03-2009, 07:23 PM | #10 | ||
Quote:
Quote:
I don't really see the problem, but i haven't try recursive waits yet, thought. |
| 07-08-2009, 04:01 AM | #11 |
Let me give an example of what I mean, in partial pseudo code. JASS:function Waiter takes nothing returns nothing print "2" wait for 3 seconds print "3" endfunction function Caller takes nothing returns nothing print "1" call Waiter() print "4" endfunction A correct wait will cause the output to be 1, 2, 3, 4. A partially correct wait will cause the output to be 1, 2, 4, 3. |
| 07-08-2009, 03:19 PM | #12 |
Then i simply need to handle functions like i handle if/then/else blocks. |
| 02-09-2011, 09:17 PM | #13 |
Ok i'm able to edit the function compile_map(path) of the wehack.lua in order to launch a personal .exe which can modify a text file (war3map.j). However it seems that the file "war3map.j" in the JNGP folder is here only as a log, editing it before jasshelper process does nothing. Actually i sadly haven't enough skills to find the solution myself. Is there a simple dirty solution like inject the modified war3map.j in the map before the jasshelper process ? And how can i do it if it's possible ? (wehack.injectfile or something ?) |
| 02-10-2011, 08:11 PM | #14 | |
Nevermind it was so easy, after reading the jasshelper documentation. Sorry for that i was watching about grimoire instead >< Quote:
|
