Ooops
March 05, 2021, 07:54:23 AM

Author Topic: [bb] Project PLASMA FPS 2004: Action.bb by Techlord [ 1+ years ago ]  (Read 546 times)

Offline BlitzBot

Title : Project PLASMA FPS 2004: Action.bb
Author : Techlord
Posted : 1+ years ago

Description : A simple dynamic function selector that works similar to a Function Pointer by storing function indices and parameters. Use the actionCall Function to pass the action as an argument. The actionCall function will select the function by index and call the function passing the parameters stored in the action object.

Can be useful many things as a function index and parameters can be change at runtime to select other functions.


Code :
Code: BlitzBasic
  1. ;============================
  2. ;ACTION
  3. ;============================
  4. Const ACTION_MAX=1024
  5. Dim actionId.action(ACTION_MAX)
  6.  
  7. Type action
  8.         Field id%
  9.         Field typeid%
  10.         Field funct%
  11.         Field i%[4]
  12.         Field f#[4]
  13.         Field s$[4]
  14. End Type
  15.  
  16. Function actionStop()
  17.         For this.action=Each action
  18.                 actionDelete(this)
  19.         Next
  20. End Function
  21.  
  22. Function actionNew.action()
  23.         this.action=New action
  24.         thisid%=id%
  25.         this    ypeid%=0
  26.         thisfunct%=0
  27.         Return this
  28. End Function
  29.  
  30. Function actionDelete(this.action)
  31.         Delete this
  32. End Function
  33.  
  34. Function actionCopy.action(this.action)
  35.         copy.action=New action
  36.         copyid%=thisid%
  37.         copy    ypeid%=this     ypeid%
  38.         copyfunct%=thisfunct%
  39.         For loop=1 To 4:copyi%[loop]=thisi%[loop]:Next
  40.         For loop=1 To 4:copyf#[loop]=thisf#[loop]:Next
  41.         For loop=1 To 4:copys$[loop]=thiss$[loop]:Next
  42.         Return copy
  43. End Function
  44.  
  45. Function actionMimic(mimic.action,this.action)
  46.         mimicid%=thisid%
  47.         mimic   ypeid%=this     ypeid%
  48.         mimicfunct%=thisfunct%
  49.         For loop=1 To 4:mimici%[loop]=thisi%[loop]:Next
  50.         For loop=1 To 4:mimicf#[loop]=thisf#[loop]:Next
  51.         For loop=1 To 4:mimics$[loop]=thiss$[loop]:Next
  52. End Function
  53.  
  54. Function actionCreate.action(id%,typeid%,funct%,i1%,i2%,i3%,i4%,f1#,f2#,f3#,f4#,s1$,s2$,s3$,s4$)
  55.         this.action=actionNew()
  56.         thisid%=id%
  57.         this    ypeid%=typeid%
  58.         thisfunct%=funct%
  59.         thisi%[1]=i1%
  60.         thisi%[2]=i2%
  61.         thisi%[3]=i3%
  62.         thisi%[4]=i4%
  63.         thisf#[1]=f1#
  64.         thisf#[2]=f2#
  65.         thisf#[3]=f3#
  66.         thisf#[4]=f4#
  67.         thiss$[1]=s1$
  68.         thiss$[2]=s2$
  69.         thiss$[3]=s3$
  70.         thiss$[4]=s4$
  71.         Return this
  72. End Function
  73.  
  74. Function actionCall(this.action)
  75.         Select thisfunct%
  76.                 Case 1 ;funct1(thisi%[1],thisi%[2])
  77.                 Case 2 ;funct2(thisi%[1],thisi%[2])
  78.                 ;
  79.                 ;
  80.                 ;
  81.         End Select
  82. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal