Saturday, 2024-04-20, 3:42 PM


Main
Registration
Login
Welcome Guest | RSS  
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Hanky, Fireeye  
Clan NgO Forums » Discussions » Junk Yard » [vJass] Costum Motion (Improved Costum Interface)
[vJass] Costum Motion
HankyDate: Sunday, 2009-03-01, 4:43 AM | Message # 1
Lieutenant colonel
Group: Moderators
Messages: 116
Reputation: 9
Status: Offline
Well after some performance tests I thought about a way to improve the CostumInterface System. The only good way I found was to use simple textmacro. Well this is now more like a little template which can be only used for motions that use structs.

< Pros >
- good Performance (much better than the CostumInterface)
- very easy to use
- save some time and also you don't have to write those stuff yourself

< System Code >

Code
//! textmacro CostumMotion takes type,run,end,periodic
    static timer loopExe=CreateTimer()
    static integer size =0
    static $type$ array runStruct
    boolean active
    boolean paused
      
    static method loopRun takes nothing returns nothing
      local integer index=0
     
   loop
     exitwhen index==$type$.size
       
     if not $type$.runStruct[index].paused then
       if $type$.runStruct[index].active then
         call $type$.runStruct[index].$run$()
      set index=index+1
    else
      call $type$.runStruct[index].$end$()
      set $type$.size=$type$.size-1
      set $type$.runStruct[index]=$type$.runStruct[$type$.size]
    endif
     else
       set index=index+1
     endif
   endloop
        
      if $type$.size==0 then
        call PauseTimer($type$.loopExe)
      endif
    endmethod
      
    static method addMotion takes $type$ data returns integer
      if $type$.size==0 then
        call TimerStart($type$.loopExe,$periodic$,true,function $type$.loopRun)
      endif
      
      set $type$.runStruct[$type$.size]       =data
      set $type$.runStruct[$type$.size].active=true
      set $type$.runStruct[$type$.size].paused=false
      set $type$.size                         =$type$.size+1
        
      return $type$.size
    endmethod
//! endtextmacro

< How to use? >

Well it's pretty easy to use the system. First you need to create a struct with two methods. One of these methods is for the motion and the other method is for the destruction of the struct.

Code
struct exampleStuff
method motion takes nothing returns nothing
endmethod

method endmotion takes nothing returns nothing
endmehtod

//! runtextmacro CostumMotion("exampleStuff","motion","endmotion","0.03")
endstruct

The first parameter of the textmacro you have to enter the struct name. In the second parameter the name of the motion method should be added and the name of the end/desruction method should be entered in the third parameter. In the last parameter just enter the periodic time, in this example it would be "0.03".

Code
call exampleStuff.addMotion(struct)

With this function you can add a struct to the motion. Just enter in the parameter the struct.

Code
set whatever.active=true //this is default after you have added a function to the loop
set whatever.active=false //this end the loop and execute endmotion
set whatever.paused=true //this pause the execution of this struct but don't destory it
set whatever.paused=false //this enable again the periodic execution

These functions are still the same. I currently got no example map for this but I'll add this template to my spellpack, so you can look how you could use the template.



Made by Smoe reworked by GiR aka Darkt3mpl3r
 
Clan NgO Forums » Discussions » Junk Yard » [vJass] Costum Motion (Improved Costum Interface)
  • Page 1 of 1
  • 1
Search:

Clan NgO © 2024Powered by uCoz