PDA

View Full Version : Pointers...



matthew
16-03-2007, 16:04
Can I use Pointers in thinBASIC?

I'm currently Rewriting NeHe Lesson09 and Pointers would come in useful. :)

RobertoBianchi
16-03-2007, 17:01
Matthew,

the reply is yes but depends on the use, here is an example of pointers use from Bug Zapper.tbasicc script:


' PEEK$
sItem = "PEEK$"
sDummy = "Blue"
IF Peek$(STRPTR(sDummy), len(sdummy)) = "Blue" then
DisplayResult(sGroup, sItem, sPassed)
ELSE
DisplayResult(sGroup, sItem, sFailed)
END IF

' POKE$
sItem = "POKE$"
sDummy = "Green"
Poke$(STRPTR(sDummy), "White")
IF sDummy = "White" then
DisplayResult(sGroup, sItem, sPassed)
ELSE
DisplayResult(sGroup, sItem, sFailed)
END IF


but pointers render code unsafe, up to you the choice.

Roberto

ErosOlmi
16-03-2007, 17:07
You can get a pointer to any thinBasic variable using VARPTR.
In case of dynamic strings VARPTR will point to a 32bit DWORD that point to the real string data.
If you need a pointer to a dynamic string data use STRPTR.

Attention: thinBasic has no direct way to reference pointed data.

An example:

type Star
r as integer
g as integer
b as integer
dist as single
angle as single
end type

dim MaxStars as long value 1000
dim Stars(MaxStars) as Star

dim ptrToStar as long

'---ptrToStar will point to the first star
ptrToStar = varptr(Stars(1))
msgbox 0, "Pointer to first star: " & ptrToStar

'---ptrToStar will point to the last star
ptrToStar = varptr(Stars(MaxStars))
msgbox 0, "Pointer to last star: " & ptrToStar

Petr Schreiber
16-03-2007, 17:27
Hi mathew,

if you want pointers "just" because some possible performance issues,
maybe you could consider display list for rendering particles instead of immediate mode ( tbgl_BeginPoly / tbgl_EndPoly )


Bye,
Petr

matthew
16-03-2007, 19:40
Thank's for all the Help. :)

But I've found a way of writing Lesson09 without having to use Pointers. :P

I should have finished Rewriting this Lesson by Tonight.