Getticks: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
New page: '''getticks''' <gamevar> Writes the amount of milliseconds(1 second = 1000 millisecond) since the OS started to <gamevar>. This clock isn't synced with the game which means that it must n...
 
m This appears to be ticks since eduke32 started, not the OS.
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
'''getticks''' <gamevar>
'''getticks''' <gamevar>


Writes the amount of milliseconds(1 second = 1000 millisecond) since the OS started to <gamevar>. This clock isn't synced with the game which means that it must not be used for the gameplay if the mod is supposed to work in multiplayer. This command is useful for visual animating(especially in [[EVENT_DISPLAYMENU]]) and for performance profiling.
Writes the amount of milliseconds(1 second = 1000 millisecond) since the game started to <gamevar>. This clock isn't synced with the game which means that it must not be used for the gameplay if the mod is supposed to work in multiplayer. This command is useful for visual animating(especially in [[EVENT_DISPLAYMENU]]) and for performance profiling.


Example code(animation)
Example code(animation)
Line 13: Line 13:
onevent EVENT_DISPLAYMENU
onevent EVENT_DISPLAYMENU
   getticks curtick
   getticks curtick
  divvar curtick 1000
  divvar curtick 60
  addlogvar curtick
   ifvare prevtick -1 setvar tmp 0 else
   ifvare prevtick -1 setvar tmp 0 else
   {
   {

Latest revision as of 08:49, 18 July 2020

getticks <gamevar>

Writes the amount of milliseconds(1 second = 1000 millisecond) since the game started to <gamevar>. This clock isn't synced with the game which means that it must not be used for the gameplay if the mod is supposed to work in multiplayer. This command is useful for visual animating(especially in EVENT_DISPLAYMENU) and for performance profiling.

Example code(animation)

gamevar prevtick -1 0
gamevar curtick   0 0
gamevar tmp       0 0 // =curtick-prevtick

gamevar y         0 0

onevent EVENT_DISPLAYMENU
  getticks curtick
  ifvare prevtick -1 setvar tmp 0 else
  {
    setvarvar tmp curtick
    subvarvar tmp prevtick
  }

  mulvar tmp 8800
  addvarvar y tmp
  ifvarg y 13107200 setvar y 0 // 200*65536=13107200
  rotatesprite16 0 y 65536 0 0 0 0 26 0 0 xdim ydim

  setvarvar prevtick curtick
endevent

Example code(performance profiling)

gamevar i 0 0
gamevar j 0 0

// Loop from 0 to NUMWALLS-1
state process_normal
  setvar j 0
  whilevarn j 1000
  {
    setvar i 0
    whilevarvarn i NUMWALLS
    {
      addvar i 1
    }
    addvar j 1
  }
ends

// Loop from NUMWALLS-1 to 0
state process_backward
  setvar j 0
  whilevarn j 1000
  {
    setvarvar i NUMWALLS
    subvar i 1
    whilevarn i -1
    {
      subvar i 1
    }
    addvar j 1
  }
ends

onevent EVENT_ENTERLEVEL
  gamevar val1 0 0
  gamevar val2 0 0

  addlogvar NUMWALLS

  getticks val1
  state process_normal
  getticks val2
  subvarvar val2 val1
  addlogvar val2

  getticks val1
  state process_backward
  getticks val2
  subvarvar val2 val1
  addlogvar val2
endevent
/*
output
CONLOGVAR: L=1266 NUMWALLS  (read-only) (Global) =14793
CONLOGVAR: L=1272 val2  (Global) =1628 // normal
CONLOGVAR: L=1278 val2  (Global) =1285 // reverse

It shows how that processing in reverse order is faster.
*/