UnderwareDESIGN

PlayBASIC => Beginners => Topic started by: kevin on September 13, 2020, 12:01:03 AM

Title: PlayBASIC - Community Roadmap Discussion
Post by: kevin on September 13, 2020, 12:01:03 AM

(http://underwaredesign.com/PlayBasicSig.png)


PlayBASIC - Community Roadmap Discussion (13th Sep, 2020)


    This thread is for the community to help build a workable realistic list of additions the community would like to see come to PlayBASIC.




PlayBASIC BLOG Episoded #15 - Roadmap




 [plink]PlayBASIC BLOG Episode #15 -  Road Map - From Here To Nowhere  (13th Sep 2020) (https://www.underwaredesign.com/forums/index.php?topic=4524.msg30036#msg30036)[/plink]





Retail Upgrade History (Blogs)


    For older upgrade work in progress see,

   See  PlayBASIC V1.64P (http://www.underwaredesign.com/forums/index.php?topic=4089.0)

   See  PlayBASIC V1.64O (http://www.underwaredesign.com/forums/index.php?topic=3988.0)

    See  PlayBASIC V1.64N2 & V1.64N3 (http://www.underwaredesign.com/forums/index.php?topic=3833.0)

    See  PlayBASIC V1.64N (http://www.underwaredesign.com/forums/index.php?topic=3651.0)

    See  PlayBASIC V1.64M (http://www.underwaredesign.com/forums/index.php?topic=3440.0)

    See  PlayBASIC V1.64L Learning Edition History (http://www.underwaredesign.com/forums/index.php?topic=3405.0) (Building learning Edition Thread)





Thread Mission Statement:


      Thread Objectives:  Survey the PB community for potential feature additions (including implementations) that would benefit their PlayBASIC development.




User Feedback Links






Note:


      Feel free to list whatever you want, but all I ask is that at least attempt to think through how your ideas will be implemented / appear in PB.   Refraining from one line list of random ideas.    




Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: stevmjon on September 16, 2020, 09:49:55 PM
hey kev

long video. i don't know enough about new features to list them. i've only used basic. you seemed to have idea's about what you would like to implement.
i would say to focus on what you said about getting v1.65 stable to add pb2dll. this way people can write dll libraries to get their programs sped up in the areas they want to focus on.

is there any tasks we could help you with, since you are limited with time? like a repeatative task that takes time...

focus on what you enjoy doing, as you are the one programming pb. you need to like coding what you think is necessary to implement.
no point angry coding and mashing keys, needing a punching bag set up next to your computer desk, lol.

   stevmjon

Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on September 21, 2020, 10:10:12 AM

Hey Steve,

Quotelong video.

    sorry about about that, it was way longer tho.   :)   


Quotei don't know enough about new features to list them. i've only used basic. you seemed to have idea's about what you would like to implement.

   hmm... perhaps features was the wrong what to parse it..   

   language & command sets tweaks..  you know things that might just be small extensions to something that's been overlooked  is as good place to start as any.   

   I'm definitely no language guru..  way out of the loop today !


Quote
i would say to focus on what you said about getting v1.65 stable to add pb2dll. this way people can write dll libraries to get their programs sped up in the areas they want to focus on. 

Quoteis there any tasks we could help you with, since you are limited with time? like a repeatative task that takes time...

    Not that I can think of atm,  but there's bound to be something. 


Quotefocus on what you enjoy doing, as you are the one programming pb. you need to like coding what you think is necessary to implement.
no point angry coding and mashing keys, needing a punching bag set up next to your computer desk, lol.

   
   unfortunately most projects tend to be mostly coal mining with the odd golden moment in between.    that's why  my office has my drum pad next to the throne..  :) 


Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on September 23, 2020, 09:55:39 AM
   Since everybody is shy..   Here's a couple of Pixel/Colour functions that could be useful in certain types of programs.  


  (Function Names / behaviors are MOCKUP)



  SampleImage(ThisImage, ScaleX#,ScaleY#)

    The function would read a pixel from the supplied image by scaling the X/Y cords by scale values.   So 0.5 would be half way across or down the image.   So you don't need to know the size of the image your sampling.  


[pbcode]


      img=loadnewimage("SOME-IMAGE.bmp",2)
   
      drawimage img,0,0,false
      
      setcursory getimageheight(img)

      print hex$(SampleImagePoint(img,0   ,0))
      print hex$(SampleImagePoint(img,0.5   ,0))
      print hex$(SampleImagePoint(img,1   ,0))

      print hex$(SampleImagePoint(img,0   ,0.5))
      print hex$(SampleImagePoint(img,0.5   ,0.5))
      print hex$(SampleImagePoint(img,1   ,0.5))

      print hex$(SampleImagePoint(img,0   ,1))
      print hex$(SampleImagePoint(img,0.5   ,1))
      print hex$(SampleImagePoint(img,1   ,1))


      sync
      waitkey       
      

Function SampleImagePoint(ThisIMage,ScaleX#,Scaley#)
   oldimage=getsurface()
      rendertoimage ThisImage
      
      w=GetImageWidth(ThisImage)-1
      h=GetImageHeight(ThisImage)-1
      
      x=mod(Scalex#*W,W)
      y=mod(Scaley#*H,H)
   
      ThisRgb =Point(X,Y)
   rendertoimage oldimage
EndFunction ThisRGB

[/pbcode]



Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on November 12, 2020, 08:25:48 AM
 Was thinking about some type of array styled logic statement to choose which variable is read. 

[pbcode]
a=10
b=20
c=30
d=40

for lp=0 to 3
      print SelectVariable(lp,A,B,C,D)
next

[/pbcode]


  This would output,   10 - 20 - 30 - 40

  literals would also work, pulling data from arrays would be beyond it tho. 

 





Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on November 21, 2020, 08:26:14 PM

   FolderExist & FileExist need to support compile time evaluation.  

   For example if folder exist could eval at compile time,  then the code could check which version of a library to include.   Handy for when working on a library, which is then ignored when deployed.

   Here's an example of what I mean..  So in the case of the Math64 library the code could detect if it's being built on my system, or the DLL is stored locally within the folder and use that.



[pbcode]

      constant DLL_WORKPATH$="Some Long Path where the DLL is behind built\PB_Math64\Release\"

      #if folderexist(DLL_WORKPATH$)      
         constant DLL_PATH$ = DLL_WORKPATH$
      #else
         constant DLL_PATH$ = ""
      #endif
      
      
linkdll    DLL_PATH$+"PB_Math64.dll"


      //  Read / Write Strings to 64Bit variable Space

         PB64_LexCode(SourceCode$)  alias "_PB64_LexCode@4" as integer
         PB64_Compile(SourceCode$) alias "_PB64_Compile@4" as integer
         PB64_Execute(ProgramPTR) alias "_PB64_ExecutePRG@4"
         PB64_GetVariablePtr(ProgramPTR, VariableName$) alias "_PB64_GetVariablePtr@8" as integer
         PB64_GetVariableAsFLT(ProgramPTR,VariableName$) alias "_PB64_GetVariableAsFLT@8" as float
         PB64_SetVariablePTR(ProgramPTR,VariableName$,SrcPtr)      alias "_PB64_SetVariablePTR@12"
         PB64_SetVariableFLT(ProgramPTR,VariableName$,ThisValue#) alias "_PB64_SetVariableFLT@12"
         PB64_SetVariableINT(ProgramPTR,VariableName$,ThisValue)    alias "_PB64_SetVariableINT@12"

 etc etc

endlinkdll



[/pbcode]


      Beyond that you could have the compile abort if a DLL (or any FILE) can't be located at compile time.



[pbcode]

             #if Fileexist(DLL_PATH$+"PB_Math64.dll")=false

                        #Abort "Missing DLL"
             #endif


linkdll    DLL_PATH$+"PB_Math64.dll"



[/pbcode]
Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on January 31, 2021, 07:57:57 AM
    Quantity functions

     It'd be handy if the quantity functions hand optional mode params.   Allows the user return not just the upper limit of a medias indexes,  but the number of resources that are currently allocated within this structure.



 [pbcode]


      for lp =0 to 9
            Bank=Newbank(1000)
      next

      print GetBankQuant()
      print GetBankQuant(1)   ; return the used banks
      Sync
      waitkey
      


Function GetBankQuant(Mode=0)
   Size = getBankQuantity()
   if Mode=0
      exitfunction Size
   else
      local lp
      for lp=1 to Size
            Usedbanks += GetBankStatus(lp)         
      next
   
   endif   
   
ENdFunction UsedBanks

 [/pbcode]
Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on June 01, 2021, 10:02:33 AM
     There's this old issue with using the TYPE Name and Object together to return the HANDLE of the object (the resource index inside PB this data lives within) ,  but that same syntax is also used to retrieve POINTERS to structures within an array.  

    Meaning there's not really a way to get the pointer to Type Variable without a LIST attached to the Type.   Not list, not pointer, but it could return the pointer of the first cell in the structure when no list is present, which would be the normal type variable.


[pbcode]

   Type VM_RETRIEVED_FUNCTION_INFO
               Parm1
               parm2
   EndType

   Dim Test1 as VM_RETRIEVED_FUNCTION_INFO

   Dim Test2(0) as VM_RETRIEVED_FUNCTION_INFO

   p=getlistptr(Test1.VM_RETRIEVED_FUNCTION_INFO)            
   print p

   p=Test2(0).VM_RETRIEVED_FUNCTION_INFO            
   print p               
         
   sync
   waitkey


[/pbcode]


Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: stevmjon on June 06, 2021, 07:51:39 AM
can you make a video about what you are explaining. i sorta get it but am not sure what the actual issue is focused on.
not sure what KIST is also.

could you explain how variables, arrays(), and types are created and stored in memory (more a visual explanation so we can see what is happening).
i have always been interested at how memory works, and how the data is stored and access to this data.

i did have an idea about types. is there any reason you can't create a type and have it set up in memory, side by side, similar to an array?
instead of creating each type cell as you need to use it...

the difference between the array polygon(9,2) which creates the entire array in memory. you can treat it like the second element 0=x , 1=y , 2=z, and a type that mimics this.
the type, lets say [ type poly: x,y,z end type ]. and then dim polygon(9) as poly. so now we can use the type the same way as the polygon(9,2).
eg. array polygon(0,0) is equivalent to type polygon(0).x
eg. array polygon(0,1) is equivalent to type polygon(0).y
eg. array polygon(0,2) is equivalent to type polygon(0).z

since the type is just variables, and the type array size 0-9, then why can't the type be set up in memory like the standard array is... they are using the same data, and are the same size. and the type here knows that only numeric values are being used.

point me in the right direction, you know i am the type of person that can handle it... haha, get it? i made a funny.

  stevmjon
Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on June 06, 2021, 08:08:35 AM

Quotecan you make a video about what you are explaining.

  careful what you wish for :)

Quotei sorta get it but am not sure what the actual issue is focused on.
not sure what KIST is also.

  What's KIST ?
Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on June 07, 2021, 08:55:10 PM
  
Quotecould you explain how variables, arrays(), and types are created and stored in memory (more a visual explanation so we can see what is happening).
i have always been interested at how memory works, and how the data is stored and access to this data.
 


 Let's say we only have INTEGER Variables, then we can emulate the variable table as a block of memory.  Each variable is converted from it's source code name into an internal INDEX,  the index is basically a position within a Variable Table array.

so in PB code,  it'd like this.

  VARIABLE ONLY EXAMPLE

[pbcode]

   constant VariableINdex_A  = 1
   constant VariableINdex_B  = 2
   constant VariableINdex_C  = 3
   constant VariableINdex_D  = 4

   //etc etc for all variable names

   constant VariableINdex_HIGHESTVARIABLEINDEX  = 1000

   Dim VariableHeap( VariableINdex_HIGHESTVARIABLEINDEX )


   ;  Add a VARIABLE   A add D together with the result strored  in variable C
   ;  C = A + D
   VariableHeap(VariableINdex_C)    =  VariableHeap( VariableINdex_A )  +  VariableHeap(VariableINdex_D)  
 


[/pbcode]


 VARIABLES & 1D ARRAYS  (INTEGER ONLY)

[pbcode]


   //   ARRAYS are stored basically BANKS...
   //    
   //   ArrayNAMES are given a VARIABLEINDEX, so the name is converted to
   //   a position with the global variable heap.  To access we query the
   //   variable heap for the BANK, then look for the required INDEX (offset)
   //   with the BANK.


   constant VariableINdex_A           = 1
   constant VariableINdex_B        = 2
   constant VariableINdex_C        = 3
   constant VariableINdex_D           = 4
   constant VariableINdex_TABLE     = 5

 //  etc etc for all variable & Array names


   constant VariableINdex_HIGHESTVARIABLEINDEX  = 1000

   Dim VariableHeap( VariableINdex_HIGHESTVARIABLEINDEX )



      ;  A = 45
      VariableHeap(VariableINdex_A) = 45

      ;  D = 1000
      VariableHeap(VariableINdex_D) = 1000


   ;  Add VARIABLE   A and D together and strore result in C
    ;  C = A +   D
   VariableHeap(VariableINdex_C)    =  VariableHeap( VariableINdex_A )  +  VariableHeap(VariableINdex_D)  

   ;  PRINT "C="+str$(C)   
      print "C="+str$(VariableHeap(VariableINdex_C))




   ;  TAB DOWN THE DISPLAY
         Print "" : Print ""   

      ; ---------------------------------------------------
      ; ---------------------------------------------------
      ;  ARRAY MOCK UP
      ; ---------------------------------------------------
      ; ---------------------------------------------------

      
      ;  DIM TABLE(100)
      ARRAY_DIM_1D_INTEGER(VariableINdex_TABLE, 100)
      
      
      ;  TABLE(10) = 1234567
      ARRAY_WRITE_1D_INTEGER(VariableINdex_TABLE,  10,  1234567)

      ; Print TABLE(10)
      print  ARRAY_READ_1D_INTEGER(VariableINdex_TABLE,  10)
      
      
      Sync
      waitkey      



Function ARRAY_DIM_1D_INTEGER(ARRAY_NAME_INDEX, SIZE)

         if Size>0
            Handle= VariableHeap(ARRAY_NAME_INDEX)
            if Handle<>0
               //  This array needs to be deleted frist
               
               
            endif         


            //  Create Bank big enough to hold
            Handle = NewBank( Size    * 4 )  //  4 bytes to store one INTEGER

            VariableHeap(ARRAY_NAME_INDEX) = HANDLE
         endif
ENDFUNCTION


Function ARRAY_WRITE_1D_INTEGER(ARRAY_NAME_INDEX, INDEX, VALUE)
   
            Handle= VariableHeap(ARRAY_NAME_INDEX)
            // Check if the ARRAY was DIMMED / Does it exist ?
            if HANDLE<>0
               
               // Check if the index is at least positive ?
               if Index>=0
                  
                  //  Check if we're writing to within this BANK fo memory
                  if (Index*4)<GetbankSize(HANDLE)
                     POkebankInt HANDLE, INDEX * 4 , VALUE
                     
                  else
                        // THROW ERROR, illegal INDEX   - Too BIG
                  endif
                  
               else
                        // THROW ERROR, illegal INDEX   - Negative
               endif

            else
                  // THROW ERROR - ARRAY DOESN'T"T EXIST   
            endif

EndFunction


Function ARRAY_READ_1D_INTEGER(ARRAY_NAME_INDEX, INDEX)
   
            Handle= VariableHeap(ARRAY_NAME_INDEX)
            // Check if the ARRAY was DIMMED / Does it exist ?
            if HANDLE<>0
               
               // Check if the index is at least positive ?
               if Index>=0
                  
                  //  Check if we're writing to within this BANK fo memory
                  if (Index*4)<GetbankSize(HANDLE)
                     Value=PeekBankInt(HANDLE, INDEX * 4)
                     
                  else
                        // THROW ERROR, illegal INDEX   - Too BIG
                  endif
               else
                        // THROW ERROR, illegal INDEX   - Negative

               endif

            else
                  // THROW ERROR - ARRAY DOESN'T"T EXIST   
            endif

EndFunction VALUE


[/pbcode]



 VARIABLES & 1D ARRAYS  & TYPED ARRAYS (INTEGER ONLY)



[pbcode]

; PROJECT : 2021-06-08 - Variable - Array and Type Simulation
; AUTHOR  : Kev Picone - Http://PlayBASIC.com
; CREATED : 8/06/2021
; EDITED  : 9/06/2021
; ---------------------------------------------------------------------
explicit on

   //  TYPES are lists of the user defined VARIABLES stuck together
   //  so each FIELD of a TYPE compiles down to an OFFSET (INDEX)
   //  from the START this type in memory.  

  //  EXAMPLE
         Type MyCharacter
               Xpos
               Ypos
               Size
               Sprite
               Score
         EndType
        

   //  The MyCharacter TYPE Is parsed by the compiler and
   //  turned into basically a list of constants where each
   // field is X number of bytes from the first byte in the structure.
   //  Integer fields within the type 4 bytes in size, so those field
   //  would create the following constants.   
       
   constant TYPE_MyCharacter_XPOS        =0    
   constant TYPE_MyCharacter_YPOS        =4    
   constant TYPE_MyCharacter_SIZE        =8    
   constant TYPE_MyCharacter_SPRITE    =12    
   constant TYPE_MyCharacter_SCORE       =16    

   constant TYPE_MyCharacter_SIZEOF       =20   ;  20 bytes for this structure    


   //   ARRAYS are stored basically BANKS...
   //    
   //   ArrayNAMES are given a VARIABLEINDEX, so the name is coverted to
   //   a position with the global variable heap.  To access we query the
   //   variable heap for the BANK, then look for the required INDEX (offset)
   //   with the BANK.



   constant VariableINdex_A          = 1      //  A variable
   constant VariableINdex_B        = 2      //  B variable
   constant VariableINdex_C        = 3      //  C variable
   constant VariableINdex_D           = 4      //  D variable
   constant VariableINdex_TABLE     = 5      //  Dim Table(xxx)
   constant VariableINdex_BADGUYS    = 6      //  Dim BadGuys(xxx) as MyCharacter
   
   constant VariableINdex_HIGHESTVARIABLEINDEX  = 1000

   Dim VariableHeap( VariableINdex_HIGHESTVARIABLEINDEX )


      print "VARIABLES -------------------------"


      ;  A = 45
      VariableHeap(VariableINdex_A) = 45

      ;  D = 1000
      VariableHeap(VariableINdex_D) = 1000


   ;  Add VARIABLE   A and D together and store result in C
    ;  C = A +   D
   VariableHeap(VariableINdex_C)    =  VariableHeap( VariableINdex_A )  +  VariableHeap(VariableINdex_D)  

   ;  PRINT "C="+str$(C)   
      print "C="+str$(VariableHeap(VariableINdex_C))



      ; ---------------------------------------------------
      ; ---------------------------------------------------
      ;  ARRAY MOCK UP
      ; ---------------------------------------------------
      ; ---------------------------------------------------

      
      Print "" : Print ""   
      print "ARRAYS -------------------------"
      
      ;  DIM TABLE(100)
      ARRAY_DIM_1D_INTEGER(VariableINdex_TABLE, 100)
      
      
      ;  TABLE(10) = 1234567
      ARRAY_WRITE_1D_INTEGER(VariableINdex_TABLE,  10,  1234567)

      ; Print TABLE(10)
      print  ARRAY_READ_1D_INTEGER(VariableINdex_TABLE,  10)
      



      ; ---------------------------------------------------
      ; ---------------------------------------------------
      ;  ARRAY MOCK UP
      ; ---------------------------------------------------
      ; ---------------------------------------------------
      print ""
      print ""
      print "TYPED ARRAY -------------------------"
      
      ;  DIM BadGuys(20) as MyCharacter
      TYPEARRAY_DIM_1D(VariableINdex_BADGUYS, 20)
      
      ;  BadGuys(5) = New MyCharacter

      ; Alloc a new TYPE and Write the handle into this Type array      
      local ThisHANDLE = ALLOC_NEW_TYPE(TYPE_MyCharacter_SIZEOF)
      TYPEARRAY_WRITEHANDLE_1D(VariableINdex_BADGUYS, 5, ThisHANDLE)


      ; BadGuys(5). Xpos = 500
      ; BadGuys(5). Ypos = 600
      TYPEARRAY_WRITE_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,5, TYPE_MyCharacter_XPOS , 500)
      TYPEARRAY_WRITE_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,5, TYPE_MyCharacter_YPOS , 600)
         
         
      ; PRINT Badguys(5).xpos         
      ; PRINT Badguys(5).ypos         
         
      print  TYPEARRAY_READ_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,5, TYPE_MyCharacter_XPOS)
      print  TYPEARRAY_READ_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,5, TYPE_MyCharacter_YPOS)
      
      
      
      Sync
      waitkey      



// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ------------------------->> ARRAY FUNCTIONS <<-----------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------




Function ARRAY_DIM_1D_INTEGER(ARRAY_NAME_INDEX, SIZE)

         if Size>0
            local Handle= VariableHeap(ARRAY_NAME_INDEX)
            if Handle<>0
               //  This array needs to be deleted first
               #print "WARNING - LOSS OF DATA,  OLD ARRAY NOT DELETED"
            endif         


            //  Create Bank big enough to hold from 0 to SIZE INTEGERS
            Handle = NewBank( Size    * 4 )  //  4 bytes to store one INTEGER

            //  Store this handle for when we need to read/write to this
            // array
            VariableHeap(ARRAY_NAME_INDEX) = HANDLE
         endif
ENDFUNCTION


Function ARRAY_WRITE_1D_INTEGER(ARRAY_NAME_INDEX, INDEX, VALUE)
   
            local HANDLE= VariableHeap(ARRAY_NAME_INDEX)
            // Check if the ARRAY was DIMMED / Does it exist ?
            if HANDLE<>0
               
               // Check if the index is at least positive ?
               if Index>=0
                  
                  //  Check if we're writing to within this BANK fo memory
                  if (Index*4)<GetbankSize(HANDLE)
                     POkebankInt HANDLE, INDEX * 4 , VALUE
                     
                  else
                        // THROW ERROR, illegal INDEX   - Too BIG
                  endif
                  
               else
                        // THROW ERROR, illegal INDEX   - Negatve
               endif

            else
                  // THROW ERROR - ARRAY DOESN"T EXIST   
            endif

EndFunction


Function ARRAY_READ_1D_INTEGER(ARRAY_NAME_INDEX, INDEX)
   
            local HANDLE= VariableHeap(ARRAY_NAME_INDEX)
            
            // Check if the ARRAY was DIMMED / Does it exist ?
            if HANDLE<>0
               
               // Check if the index is at least positive ?
               if Index>=0
                  
                  //  Check if we're writing to within this BANK fo memory
                  if (Index*4)<GetbankSize(HANDLE)

                     Value=PeekBankInt(HANDLE, INDEX * 4)
                     
                  else
                        // THROW ERROR, illegal INDEX   - Too BIG
                        #print "illegal Array INDEX - Too BIG"
                  endif
               else
                        // THROW ERROR, illegal INDEX   - Negative
                        #print "illegal Array INDEX - Negative"
               endif

            else
                  // THROW ERROR - ARRAY DOESN"T EXIST   
                  #print "Array Doesn't Exist"
            endif

EndFunction VALUE




// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ------------------------->> TYPED ARRAY FUNCTIONS <<-----------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------

//  NOTE:   TO SAVE TIME --  I'll REUSED some of the PREVIOUS ARRAY
//          functions that read/write integers for our typed arrays


Function TYPEARRAY_DIM_1D(TYPEARRAY_NAME_INDEX, SIZE)


         if Size>0
            local Handle= VariableHeap(TYPEARRAY_NAME_INDEX)
            if Handle<>0
               //  This array needs to be deleted first
               #print "WARNING - DIM TYPED ARRAY.. LOSS OF DATA"
            endif   
   

            //  Create Bank big enough to hold TYPE HANDLES
            //  Since there are stored as INTEGERS (4 bytes each)
            // the amount of memory required is SIZE by 4
            Handle = NewBank( Size    * 4 )
            
            VariableHeap(TYPEARRAY_NAME_INDEX) = HANDLE
      endif

ENdFunction


         //  since a TYPED array is stored the same way as INTEGER
         // Here i'll cheat and just call the INTEGER read write
         //  The only difference anyway is that in a TYPE ARRAY
         //  we're READING and WRITE HANDLES and not DATA per say

Function TYPEARRAY_WRITEHANDLE_1D(TYPEARRAY_NAME_INDEX, INDEX, HANDLE)
         //  Check if there's a TYPE at this location ??
         local OLDHANDLE= ARRAY_READ_1D_INTEGER(TYPEARRAY_NAME_INDEX, INDEX)
         if OLDHANDLE
               //  DELETE OLD TYPE..
               //  
         endif

         //  Write the new handle   
         ARRAY_WRITE_1D_INTEGER(TYPEARRAY_NAME_INDEX, INDEX, HANDLE)

EndFunction

Function TYPEARRAY_READHANDLE_1D(TYPEARRAY_NAME_INDEX, INDEX)
         HANDLE= ARRAY_READ_1D_INTEGER(TYPEARRAY_NAME_INDEX, INDEX)
EndFunction HANDLE



Function ALLOC_NEW_TYPE(Size_OF_Type_In_Bytes)
         This_TYPE_HANDLE = NewBANK(Size_OF_Type_In_Bytes)   
EndFunction This_TYPE_HANDLE


      // ----------------------------------------------
      //  WRITE into an ARRAY of TYPES
      // ----------------------------------------------
      
Function TYPEARRAY_WRITE_1D_TYPE_FIELD_INTEGER(TYPEARRAY_NAME_INDEX, INDEX , FieldOffset,  Value)

         //  READ THE TYPE HANDLE from this array
         local ThisTypeHANDLE = TYPEARRAY_READHANDLE_1D(TYPEARRAY_NAME_INDEX, INDEX)


         //  Check if the handle is at least not zero
         if ThisTypeHANDLE
            // Check if this handle exists
            if GetBankStatus(ThisTypeHANDLE)
               
                  // Check if the field offset
                  if FieldOFFSET>=0
                     if  FieldOFFSET<getBankSize(ThisTypeHANDLE)
                        
                        // WRITE this data into the TYPE
                        POkeBankInt ThisTypeHANDLE , FieldOFFSET, VALUE

                     else
                        //  THROW ERROR - Offset too big
                        #print "Offset TOO BIG"
                     endif      
                  else
                        //  THROW ERROR - Offset is negative               
                        #print "Offset negative"
                  endif                  
               
            else
                  // THROW ERROR ..  THIS TYPE DOESN'T EXIST
                  #print "Type is undefined"
                  
            endif   
            
         endif
EndFunction




Function TYPEARRAY_READ_1D_TYPE_FIELD_INTEGER(TYPEARRAY_NAME_INDEX, INDEX , FieldOffset)

         //  READ THE TYPE HANDLE from this array
         local ThisTypeHANDLE = TYPEARRAY_READHANDLE_1D(TYPEARRAY_NAME_INDEX, INDEX)

         //  Check if the handle is at least not zero
         if ThisTypeHANDLE
            // Check if this handle exists
            if GetBankStatus(ThisTypeHANDLE)
               
                  // Check if the field offset
                  if FieldOFFSET>=0
                     if  FieldOFFSET<getBankSize(ThisTypeHANDLE)
                        
                        // WRITE this data into the TYPE
                        Value = PeekBankInt(ThisTypeHANDLE , FieldOFFSET)

                     else
                        //  THROW ERROR - Offset too big
                        #print "Offset TOO BIG"
                     endif      
                  else
                        //  THROW ERROR - Offset is negative               
                        #print "Offset negative"
                  endif                  
               
            else
                  // THROW ERROR ..  THIS TYPE DOESN'T EXIST
                  #print "Type is undefined"
            endif   
         else
            #print "Type is undefined"
   
         endif
EndFunction Value





[/pbcode]



    So to make an analogy

      ->  VARIABLE  are like the ground
      ->  ARRAYS are like tree trucks
      ->  TYPES are like the branches from the TREE

Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: stevmjon on June 08, 2021, 06:16:11 PM
KIST was on your post#7... it seems to not be there now. this has happened to me a few times now. i read a post, then when i look at it on another day, it has changed.
this happened on some code you posted elsewhere not too long ago. it was missing some code, then when i checked it again all the code was there. i wrote this in a reply. not sure if i am getting a 'crossed wire' so to speak.
Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on June 08, 2021, 08:52:37 PM
 I didn't know what  KIST was either, thought it was from the video...  then noticed the typo in the previous post..  It was meant to be LIST.




Title: Re: PlayBASIC - Community Roadmap Discussion
Post by: kevin on June 09, 2021, 04:56:48 AM
  PlayBASIC Live - Overview of how Variables Arrays and Types - Steve's Question (2021-06-09)

 




 Variable / Array & Typed Array simulation example:

[pbcode]
; PROJECT : 2021-06-08 - Variable - Array and Type Simulation
; AUTHOR  : Kev Picone - Http://PlayBASIC.com
; CREATED : 8/06/2021
; EDITED  : 9/06/2021
; ---------------------------------------------------------------------
explicit on

   //  TYPES are lists of the user defined VARIABLES stuck together
   //  so each FIELD of a TYPE compiles down to an OFFSET (INDEX)
   //  from the START this type in memory.  

  //  EXAMPLE
         Type MyCharacter
               Xpos
               Ypos
               Size
               Sprite
               Score
         EndType
        

   //  The MyCharacter TYPE Is parsed by the compiler and
   //  turned into basically a list of constants where each
   // field is X number of bytes from the first byte in the structure.
   //  Integer fields within the type 4 bytes in size, so those field
   //  would create the following constants.   
       
   constant TYPE_MyCharacter_XPOS        =0    
   constant TYPE_MyCharacter_YPOS        =4    
   constant TYPE_MyCharacter_SIZE        =8    
   constant TYPE_MyCharacter_SPRITE    =12    
   constant TYPE_MyCharacter_SCORE       =16    

   constant TYPE_MyCharacter_SIZEOF       =20   ;  20 bytes for this structure    


   //   ARRAYS are stored basically BANKS...
   //    
   //   ArrayNAMES are given a VARIABLEINDEX, so the name is coverted to
   //   a position with the global variable heap.  To access we query the
   //   variable heap for the BANK, then look for the required INDEX (offset)
   //   with the BANK.



   constant VariableINdex_A          = 1      //  A variable
   constant VariableINdex_B        = 2      //  B variable
   constant VariableINdex_C        = 3      //  C variable
   constant VariableINdex_D           = 4      //  D variable
   constant VariableINdex_TABLE     = 5      //  Dim Table(xxx)
   constant VariableINdex_BADGUYS    = 6      //  Dim BadGuys(xxx) as MyCharacter
   
   constant VariableINdex_HIGHESTVARIABLEINDEX  = 1000

   Dim VariableHeap( VariableINdex_HIGHESTVARIABLEINDEX )


      print "VARIABLES -------------------------"


      ;  A = 45
      VariableHeap(VariableINdex_A) = 45

      ;  D = 1000
      VariableHeap(VariableINdex_D) = 1000


   ;  Add VARIABLE   A and D together and store result in C
    ;  C = A +   D
   VariableHeap(VariableINdex_C)    =  VariableHeap( VariableINdex_A )  +  VariableHeap(VariableINdex_D)  

   ;  PRINT "C="+str$(C)   
      print "C="+str$(VariableHeap(VariableINdex_C))



      ; ---------------------------------------------------
      ; ---------------------------------------------------
      ;  ARRAY MOCK UP
      ; ---------------------------------------------------
      ; ---------------------------------------------------

      
      Print "" : Print ""   
      print "ARRAYS -------------------------"
      
      ;  DIM TABLE(100)
      ARRAY_DIM_1D_INTEGER(VariableINdex_TABLE, 100)
      
      
      ;  TABLE(10) = 1234567
      ARRAY_WRITE_1D_INTEGER(VariableINdex_TABLE,  10,  1234567)

      ; Print TABLE(10)
      print  ARRAY_READ_1D_INTEGER(VariableINdex_TABLE,  10)
      



      ; ---------------------------------------------------
      ; ---------------------------------------------------
      ;  ARRAY MOCK UP
      ; ---------------------------------------------------
      ; ---------------------------------------------------
      print ""
      print ""
      print "TYPED ARRAY -------------------------"
      
      ;  DIM BadGuys(20) as MyCharacter
      TYPEARRAY_DIM_1D(VariableINdex_BADGUYS, 20)
      
      ;  BadGuys(5) = New MyCharacter

      ; Alloc a new TYPE and Write the handle into this Type array      
      local ThisHANDLE = ALLOC_NEW_TYPE(TYPE_MyCharacter_SIZEOF)
      TYPEARRAY_WRITEHANDLE_1D(VariableINdex_BADGUYS, 5, ThisHANDLE)


      ; BadGuys(5). Xpos = 500
      ; BadGuys(5). Ypos = 600
      TYPEARRAY_WRITE_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,5, TYPE_MyCharacter_XPOS , 500)
      TYPEARRAY_WRITE_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,5, TYPE_MyCharacter_YPOS , 600)
         
         
      ; PRINT Badguys(5).xpos         
      ; PRINT Badguys(5).ypos         
         
      print  TYPEARRAY_READ_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,5, TYPE_MyCharacter_XPOS)
      print  TYPEARRAY_READ_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,5, TYPE_MyCharacter_YPOS)
      
      
      local lp

      for lp =0 to 10

         // Badguys(lp) = new MyCharacter
         ThisHANDLE = ALLOC_NEW_TYPE(TYPE_MyCharacter_SIZEOF)
         TYPEARRAY_WRITEHANDLE_1D(VariableINdex_BADGUYS, lp, ThisHANDLE)

         
         //  BadGuys(lp).xpos = rnd(800)
         //  BadGuys(lp).ypos = rnd(600)
         TYPEARRAY_WRITE_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,lp, TYPE_MyCharacter_XPOS , rnd(800))
         TYPEARRAY_WRITE_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,lp, TYPE_MyCharacter_YPOS , rnd(600))
         
      next
      
      local x,y
      for lp =0 to 10

         // X = badguys(lp).xpos
         // Y = badguys(lp).ypos

         x=TYPEARRAY_READ_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,lp, TYPE_MyCharacter_XPOS)
         y= TYPEARRAY_READ_1D_TYPE_FIELD_INTEGER(VariableINdex_BADGUYS,lp, TYPE_MyCharacter_YPOS)

         circlec x,y,30,true,rndrgb()
      next      
      
      
      Sync
      waitkey      



// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ------------------------->> ARRAY FUNCTIONS <<-----------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------




Function ARRAY_DIM_1D_INTEGER(ARRAY_NAME_INDEX, SIZE)

         if Size>0
            local Handle= VariableHeap(ARRAY_NAME_INDEX)
            if Handle<>0
               //  This array needs to be deleted first
               #print "WARNING - LOSS OF DATA,  OLD ARRAY NOT DELETED"
            endif         


            //  Create Bank big enough to hold from 0 to SIZE INTEGERS
            Handle = NewBank( Size    * 4 )  //  4 bytes to store one INTEGER

            //  Store this handle for when we need to read/write to this
            // array
            VariableHeap(ARRAY_NAME_INDEX) = HANDLE
         endif
ENDFUNCTION


Function ARRAY_WRITE_1D_INTEGER(ARRAY_NAME_INDEX, INDEX, VALUE)
   
            local HANDLE= VariableHeap(ARRAY_NAME_INDEX)
            // Check if the ARRAY was DIMMED / Does it exist ?
            if HANDLE<>0
               
               // Check if the index is at least positive ?
               if Index>=0
                  
                  //  Check if we're writing to within this BANK fo memory
                  if (Index*4)<GetbankSize(HANDLE)
                     POkebankInt HANDLE, INDEX * 4 , VALUE
                     
                  else
                        // THROW ERROR, illegal INDEX   - Too BIG
                  endif
                  
               else
                        // THROW ERROR, illegal INDEX   - Negatve
               endif

            else
                  // THROW ERROR - ARRAY DOESN"T EXIST   
            endif

EndFunction


Function ARRAY_READ_1D_INTEGER(ARRAY_NAME_INDEX, INDEX)
   
            local HANDLE= VariableHeap(ARRAY_NAME_INDEX)
            
            // Check if the ARRAY was DIMMED / Does it exist ?
            if HANDLE<>0
               
               // Check if the index is at least positive ?
               if Index>=0
                  
                  //  Check if we're writing to within this BANK fo memory
                  if (Index*4)<GetbankSize(HANDLE)

                     Value=PeekBankInt(HANDLE, INDEX * 4)
                     
                  else
                        // THROW ERROR, illegal INDEX   - Too BIG
                        #print "illegal Array INDEX - Too BIG"
                  endif
               else
                        // THROW ERROR, illegal INDEX   - Negative
                        #print "illegal Array INDEX - Negative"
               endif

            else
                  // THROW ERROR - ARRAY DOESN"T EXIST   
                  #print "Array Doesn't Exist"
            endif

EndFunction VALUE




// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ------------------------->> TYPED ARRAY FUNCTIONS <<-----------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------

//  NOTE:   TO SAVE TIME --  I'll REUSED some of the PREVIOUS ARRAY
//          functions that read/write integers for our typed arrays


Function TYPEARRAY_DIM_1D(TYPEARRAY_NAME_INDEX, SIZE)


         if Size>0
            local Handle= VariableHeap(TYPEARRAY_NAME_INDEX)
            if Handle<>0
               //  This array needs to be deleted first
               #print "WARNING - DIM TYPED ARRAY.. LOSS OF DATA"
            endif   
   

            //  Create Bank big enough to hold TYPE HANDLES
            //  Since there are stored as INTEGERS (4 bytes each)
            // the amount of memory required is SIZE by 4
            Handle = NewBank( Size    * 4 )
            
            VariableHeap(TYPEARRAY_NAME_INDEX) = HANDLE
      endif

ENdFunction


         //  since a TYPED array is stored the same way as INTEGER
         // Here i'll cheat and just call the INTEGER read write
         //  The only difference anyway is that in a TYPE ARRAY
         //  we're READING and WRITE HANDLES and not DATA per say

Function TYPEARRAY_WRITEHANDLE_1D(TYPEARRAY_NAME_INDEX, INDEX, HANDLE)
         //  Check if there's a TYPE at this location ??
         local OLDHANDLE= ARRAY_READ_1D_INTEGER(TYPEARRAY_NAME_INDEX, INDEX)
         if OLDHANDLE
               //  DELETE OLD TYPE..
               //  
         endif

         //  Write the new handle   
         ARRAY_WRITE_1D_INTEGER(TYPEARRAY_NAME_INDEX, INDEX, HANDLE)

EndFunction

Function TYPEARRAY_READHANDLE_1D(TYPEARRAY_NAME_INDEX, INDEX)
         HANDLE= ARRAY_READ_1D_INTEGER(TYPEARRAY_NAME_INDEX, INDEX)
EndFunction HANDLE



Function ALLOC_NEW_TYPE(Size_OF_Type_In_Bytes)
         This_TYPE_HANDLE = NewBANK(Size_OF_Type_In_Bytes)   
EndFunction This_TYPE_HANDLE


      // ----------------------------------------------
      //  WRITE into an ARRAY of TYPES
      // ----------------------------------------------
      
Function TYPEARRAY_WRITE_1D_TYPE_FIELD_INTEGER(TYPEARRAY_NAME_INDEX, INDEX , FieldOffset,  Value)

         //  READ THE TYPE HANDLE from this array
         local ThisTypeHANDLE = TYPEARRAY_READHANDLE_1D(TYPEARRAY_NAME_INDEX, INDEX)


         //  Check if the handle is at least not zero
         if ThisTypeHANDLE
            
            // Check if this handle exists
            if GetBankStatus(ThisTypeHANDLE)
               
                  // Check if the field offset
                  if FieldOFFSET>=0
                     if  FieldOFFSET<getBankSize(ThisTypeHANDLE)
                        
                        // WRITE this data into the TYPE
                        POkeBankInt ThisTypeHANDLE , FieldOFFSET, VALUE

                     else
                        //  THROW ERROR - Offset too big
                        #print "Offset TOO BIG"
                     endif      
                  else
                        //  THROW ERROR - Offset is negative               
                        #print "Offset negative"
                  endif                  
               
            else
                  // THROW ERROR ..  THIS TYPE DOESN'T EXIST
                  #print "Type is undefined"
                  
            endif   
            
         endif
EndFunction




Function TYPEARRAY_READ_1D_TYPE_FIELD_INTEGER(TYPEARRAY_NAME_INDEX, INDEX , FieldOffset)

         //  READ THE TYPE HANDLE from this array
         local ThisTypeHANDLE = TYPEARRAY_READHANDLE_1D(TYPEARRAY_NAME_INDEX, INDEX)

         //  Check if the handle is at least not zero
         if ThisTypeHANDLE
            // Check if this handle exists
            if GetBankStatus(ThisTypeHANDLE)
               
                  // Check if the field offset
                  if FieldOFFSET>=0
                     if  FieldOFFSET<getBankSize(ThisTypeHANDLE)
                        
                        // WRITE this data into the TYPE
                        Value = PeekBankInt(ThisTypeHANDLE , FieldOFFSET)

                     else
                        //  THROW ERROR - Offset too big
                        #print "Offset TOO BIG"
                     endif      
                  else
                        //  THROW ERROR - Offset is negative               
                        #print "Offset negative"
                  endif                  
               
            else
                  // THROW ERROR ..  THIS TYPE DOESN'T EXIST
                  #print "Type is undefined"
            endif   
         else
            #print "Type is undefined"
   
         endif
EndFunction Value




[/pbcode]


  Example #2
[pbcode]


      type MyArray
            Array(20)
      EndType

      type MyGameObject
            Status
            XPos,Ypos
            Child as MyArray
            Child2(20)
      EndType


      Dim a as MyGameObject
      A= new MyGameObject
      
      A.Child.Array(20) = 100
      
      ptr = a.Child.MyArray
      pokeint ptr + (21*4),  5555
      
      
      sync
      waitkey
            
      

[/pbcode]



  Example #3
[pbcode]



      type Vector3
         X#,y#,z#
   EndType
   



      DIm Vertex(1000) as vector3  ArrayOfStructures

      For lp =0 to 999
               vertex(lp).x = 1221
               vertex(lp).y = 1221
               vertex(lp).z = 1221
      next

      //
      VertexBank = NewBank(  SizeOf(Vector3) * 1000)   )

      dim me as vector3 pointer
      For lp =0 to 999
         me = getBankPtr(Vertexbank) + ( lp * Sizeof(vector3))
         
         me.x = 1221
         me.y = 1221
         me.z = 1221
         
      next



      dim me as vector3 pointer
      Me = GetBankPtr(Vertexbank)
      For lp =0 to 999
         me(lp).x = 1221
         me(lp).y = 1221
         me(lp).z = 1221
      next
      
      
      dim me as vector3 pointer
      Me = GetBankPtr(Vertexbank)
      For lp =0 to 999
         me.x = 1221
         me.y = 1221
         me.z = 1221
         me = int(me) + Sizeof(Vector3)
      next
      

 [/pbcode]



 
Related Articles:


      - How Memory Works - Variable - Array - Type Array Visualizer Demo (https://www.underwaredesign.com/forums/index.php?topic=4583.0)