Page 1 of 1
Posted: Thu Jul 25, 2002 7:26 pm
by BackupUser
Restored from previous forum. Originally posted by halo.
This solution was given to get around the PokeF bug. I don't understand the syntax, and fail to see how this equates poking a float to a memory buffer:
In the meantime you can use this:
Structure fptr
f.f[0]
EndStructure
*foo.fptr =
*foo\f[0] =
I am writing a dll to take plane equations, intersect them, and build a polygon from the data. Basically, it converts a bsp-type object to an .x. I am using a lot of 3D routines with no 3D engine.
Posted: Thu Jul 25, 2002 9:01 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Ok, i'll try to explain this a little. If you have knowledge of pointers and such it shouldn't be hard to understand, if not make some room in your brain and stuff this into it;)
Code: Select all
Structure fptr
float.f
EndStructure
;PokeF(address.l, value.f)
;is equal to:
;*ptr.fptr = address.l
;*ptr\float = value
;*ptr.fptr is a pointer to the structure fptr
So if you for instance have a buffer that you want to fill with different float numbers you could do this way:
Code: Select all
Structure fptr
float.f
EndStructure
nroffloats = 4
*buffer = AllocateMemory(0, nroffloats*4, 0)
*ptr.fptr = *buffer
*ptr\float = 50.32 : *ptr+4 ; must add the memory footprint of
; the float type i.e. 4 bytes.
*ptr\float = 0.12 : *ptr+4
*ptr\float = 12.1 : *ptr+4
*ptr\float = 5.5
; Now we have filled the memory buffer with floats
; Let's see if the numbers are correct
*ptr = *buffer
Debug "Pos 1 = "+StrF(PeekF(*ptr)) : *ptr+4
Debug "Pos 2 = "+StrF(PeekF(*ptr)) : *ptr+4
Debug "Pos 3 = "+StrF(PeekF(*ptr)) : *ptr+4
Debug "Pos 4 = "+StrF(PeekF(*ptr))
; Let's do this again with another method
*ptr = *buffer
Debug "Pos 1 = "+StrF(*ptr\float) : *ptr+4
Debug "Pos 2 = "+StrF(*ptr\float) : *ptr+4
Debug "Pos 3 = "+StrF(*ptr\float) : *ptr+4
Debug "Pos 4 = "+StrF(*ptr\float)
Hope you'll be able to learn something from my example.
Posted: Fri Jul 26, 2002 11:06 pm
by BackupUser
Restored from previous forum. Originally posted by tinman.
Just in case it wasn't immediately obvious (and halo can ignore this if he/she wants

- if you use the array syntax I gave, you really can treat it like an array and do not need to do maths on the pointer.
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.20)
Posted: Sat Jul 27, 2002 12:43 am
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Just in case it wasn't immediately obvious (and halo can ignore this if he/she wants

- if you use the array syntax I gave, you really can treat it like an array and do not need to do maths on the pointer.
Yes tinman, you're quite right, didn't think of it though -let's just hope that Fred doesn't put in some checking in the compiler that complain when you go outside the declared dimension!
Anyway this code below should be equal to my example above:
Code: Select all
Structure fptr
float.f[0]
EndStructure
nroffloats = 4
*buffer = AllocateMemory(0, nroffloats*4, 0)
*ptr.fptr = *buffer
*ptr\float[0] = 50.32
*ptr\float[1] = 0.12
*ptr\float[2] = 12.1
*ptr\float[3] = 5.5
; Now we have filled the memory buffer with floats
; Let's see if the numbers are correct
Debug "Pos 1 = "+StrF(*ptr\float[0])
Debug "Pos 2 = "+StrF(*ptr\float[1])
Debug "Pos 3 = "+StrF(*ptr\float[2])
Debug "Pos 4 = "+StrF(*ptr\float[3])
Edited by - Pupil on 29 July 2002 13:06:52
Posted: Sat Jul 27, 2002 12:19 pm
by BackupUser
Restored from previous forum. Originally posted by tinman.
Fred doesn't put in some checking in the compiler that complain when you go outside the declared dimension!
Agreed. Hopefully it should stay this way, as I think it was around since the early days of PB (array sizes of 0 was how Blitz used to implement structures, so that could be where Fred got the idea from
Anyway this code below should be equal to my example above:
Well, if you change those 0's at the end to 0,1,2 and 3 it will be
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.20)
Posted: Mon Jul 29, 2002 12:08 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
Well, if you change those 0's at the end to 0,1,2 and 3 it will be
Hehe, yes the old cut n' paste error

Anyway changed now..