News:

Function Finder  Find all the functions within source code files

Main Menu

Abstraction Layer

Started by kevin, February 28, 2011, 12:05:36 AM

Previous topic - Next topic

kevin

PlayBASIC Code: [Select]
` *=---------------------------------------------------------------------=*
`
` > Abstraction Layers Example V0.01 <<
`
` By Kevin Picone
`
` Built with PlayBASIC V1.64M
`
` (c) copyright 2011, By Kevin Picone, All rights reserved.
` *=---------------------------------------------------------------------=*
`
` This is an experiment with building a generic abstraction layer. The
` concept being to use the same base layer code to prop up user code layers,
` which can then be plugged in without needing to modify the underlying
` layer each time a (higher level) change is made.
`
` This works by using type inheritance and the dynamic function calling.
` Where each object/character class has three main functions, a creation
` and update and destroy function.
`
` By registering your character class, you can then generically create
` any register character by name. The created resource is added to the
` internal character/object list, then the library calls your libraries
` creation function. The same occurs during Process_Objects() function,
` where the function runs through and calls each characters update function
` or if it's to be released, then it'll call your delete function for you.
`
` While this is only an experiment, it could certainly be expanded into
` some more robust by the creative PlayBASIC programmers out there.
` Have fun !
`
` *=---------------------------------------------------------------------=*





Big C.

a short question...

Quote
Type tCircle As tGameObject
   radius
EndType

// Register this character class name with the manager layer
RegisterClassName("Circle",tCircle+0)

This peace of code makes me confusing...  ???

You decleare a Type-Var tCircle and then you call a function which parameters expected a String and a Int var. As int var you fit in "tCircle+0" but if I use this peace of code

Quote// Register this character class name with the manager layer
   RegisterClassName("Circle",tCircle+0)
   
   Print tCircle
   sync
   waitkey

then I get the error "Parameter Types are incorrect".

Otherwise this
Quote// Register this character class name with the manager layer
   RegisterClassName("Circle",tCircle+0)
   
   Print tCircle+0
   sync
   waitkey

gives me the result of 5.

In the Types-Tut I read that if I want to use a type var then I have to dim this first. How does this works correctly? Has tCircle nothing to do with the Name of the Type?

kevin

#2
   You can't print tcircle  since print  will only accept an Integer, Float or a String data types as a parameter.  tCircle is none of those, it needs to be recast into something Print understands.   Same with trying to pass it into a function (user defined or otherwise).   The parameter matching won't allow it and there's no auto-casting here to convert it from an identifier into an integer or float.

  However,  the type index can be obtained directly from the identifier, either through assignment or by using arithmetic on it, hence the tcircle+0.

  ie.  
  SomeInt = tCircle
  print SomeInt
  or

  print tCircle+0
 

PlayBASIC Code: [Select]
   // Parent
Type ParentType
Status
EndType

// child
Type Child1 as ParentType
a,b,c
EndType

Type Child2 as ParentType
x,y,zx,sd,ss,wwe,ee
EndType

Max=5

// declare the house for the family of types
Dim Kids(Max) as ParentType

// Randomly fill the array with children
For lp=0 to Max

; pick a type and spawn it. So it's alternative between child 1 and child 2
Kids(lp) = New (Child1+Rnd(1))

; Work out what type this is
s$=str$(lp)
select TypeOf(Kids(lp))
case Child1
s$+="=Child#1"
case Child2
s$+="=Child#2"
endselect
print s$
Next

Sync
waitkey





Quote
In the Types-Tut I read that if I want to use a type var then I have to dim this first. How does this works correctly? Has tCircle nothing to do with the Name of the Type?

 The type name is simply an index of the type structure.    The allocator (the NEW operator) can allocate the type structure (the memory) using either the implicit name (of the type) or the index as shown above and  here in  Type Collections for example.    The latter is so type can be selected at runtime, rather than at compile time.

 So assuming the following code was the first type declarations in the program,  Stuff would have a type index of #1 and Dude would be #2.

PlayBASIC Code: [Select]
   Type Stuff
EndType

Type Dude
EndType