News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

PlayBASIC LIVE: Render (Event) Stacks (2017-05-28)

Started by kevin, May 28, 2017, 07:34:05 AM

Previous topic - Next topic

kevin

  PlayBASIC LIVE: Render (Event) Stacks  More Flexible Main Loop (2017-05-28)

Welcome...   This video looks at alternative ways we can set up the so called 'main loop' in our games in a more flexible fashion.  What we can do is separate our rendering / processing / logic code up into a series of events that need to performed to build each frame.   You can think of this as a 'to do'  or 'job' list. This allows us to change what jobs (and order) need to be performed,  as well allowing us to control this externally.  So your level editing tool/person can tweak things themselves without the programmer having to hard code every changing into your main loop(s)..





 Example:

PlayBASIC Code: [Select]
      setfps 20

Dim EventStack(255)
EventStack(10) = 100 ; CLS
EventStack(20) = 200 ; Draw Backdrop
EventStack(30) = 500 ; Draw Sprites
EventStack(40) = 1000 ; Call SYNC


do

For Lp=0 to 255

Select EventStack(lp)

case 100
Event_Cls()

case 200
Event_drawbackdrop()

case 201
Event_drawbackdrop2()

case 500
drawsprites()

case 1000
Event_SYNC()

endselect

next


IF FUNCTIONkEYS(1)
EventStack(25) = 201
ELSE
EventStack(25) = 0
ENDIF


loop






function Event_Cls()
cls rgb(200,0,0)
EndFunction

function Event_Sync()
sync
EndFunction


function Event_drawbackdrop()
shadebox 100,100,700,500,$11223344, $ff00ff, $00ff00,$00ff80
endfunction


function Event_drawbackdrop2()
circleC 0,0,100,true,$445566
endfunction




function drawsprites()

randomize 57

static scrollX
ScrollX=mod(ScrollX-1,800)

for lp =0 to 10
x=scrollX+rnd(800)
y=rnd(600)
col=rndrgb()
circlec x,y,32,true,col

next


endfunction






  Related To:

      - Execution Stack Example
      - Triggers Time Based Model
      - Abstraction Layer
      - Timer Based Life Spans
      - Action GUI