Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (vicknick, AndrewAMD), 1,292 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: handle function -> HBYTE-type -> how to?? [Re: Myrkling] #382844
09/13/11 11:17
09/13/11 11:17
Joined: Sep 2003
Posts: 303
Germany
Clemens Offline OP
Senior Member
Clemens  Offline OP
Senior Member

Joined: Sep 2003
Posts: 303
Germany
Great, this works! Thanks guys...
(even if I wonder about the working solutions a little bit)

Re: handle function -> HBYTE-type -> how to?? [Re: Clemens] #382846
09/13/11 11:28
09/13/11 11:28
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
fyi
Quote:
But it surprises me, that it doesn't matter if I use ((TEXT*)Object).pos_x = PositionX; or ((PANEL*)Object).pos_x = PositionX; in my code above. Both works independet from which type is passed... (?)


After the typecasting the compiler knows the type, which is in the first example "TEXT*". It doesn't really matter which object "Object" really is. The compiler thinks it's type is "TEXT*". The "." is reinterpreteted as "->". The "->" leads to a resolving of the pointer (so access the memory area behind the pointer). The "pos_x" tells the compiler the offset to the value of the pointer "Object". The type of "pos_x" tells the compiler how many bytes he has to erase / overwrite with PositionX.

If now PANEL* and TEXT* "pos_x/y" parameters have the same offset, and the parameters have the same type, the code will work identically for the compiler.

That's by the way, the way handle works. Handle() just reads out the index in the C_LINK structure in the engine object. As you see in ANY engine object, the C_LINK structure is the FIRST parameter (offset 0).
So actually handle does nothing but:

ENTITY* obj = ...;
int handle_of = ((int)*((void*)obj)));

This code just interpretes the first 4 bytes of the ENTITY object as integer. As you can see in the struct the first 4 bytes of any engine-object (STRING,PANEL etc.) is filled with the C_LINK struct. The first 4 Bytes of the C_LINK struct is filled with the index of an object.

That's why: handle is extremly fast (ptr_for_handle is not that fast as it has to iterate over a linked list, with a complexity of O(N), which is never that fast - though as you know, the index of an object also contains the type, which makes things a little bit slower).

Re: handle function -> HBYTE-type -> how to?? [Re: TechMuc] #382879
09/13/11 15:57
09/13/11 15:57
Joined: Sep 2003
Posts: 303
Germany
Clemens Offline OP
Senior Member
Clemens  Offline OP
Senior Member

Joined: Sep 2003
Posts: 303
Germany
Hey, that's a detailed and well developed description - thank you

Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1