|
|
|
3 registered members (Martin_HH, JeyKey II, 1 invisible),
5,519
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
mapping structs over skills
#246014
01/13/09 03:43
01/13/09 03:43
|
Joined: Dec 2008
Posts: 43
DavidM
OP
Newbie
|
OP
Newbie
Joined: Dec 2008
Posts: 43
|
I have this struct:
typedef struct { int x, y; float hello; } Foo ;
Foo* asFoo(ENTITY* e) {
Foo* r = (Foo*)(&e->skill[70]);
return r;
}
This is being used to map the block of memory occupied by skill[0..99] over the Foo structure. Oddly, this works sometimes and others it returns NULL!?!? Seems to be a weird casting issue with the skill array. Can anyone tell me why this happens?
|
|
|
Re: mapping structs over skills
[Re: DavidM]
#246026
01/13/09 09:18
01/13/09 09:18
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Pointers make my head hurt, but a quick look suggests to me that you are trying to map an array of VAR's (the entity skills) over the top of a structure of varied elements (two ints and a float). VARS, INTs and FLOATs are stored in four bytes of memory, BUT the format they are store in varies greatly. Your concept could 'possibly' work while all the values are zero, but after that, all bets are off.
Change your struct to be all VARs and it looks to be workable.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: mapping structs over skills
[Re: DavidM]
#246127
01/13/09 19:08
01/13/09 19:08
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
It will be a block of 400 bytes, but each 4-byte block is going to be expected to be in the VAR format when looked at from the skills angle, and will be expected to be INT or FLOAT format when looked at from the struct side. By 'type' format I mean which of the 4 bytes is the Most-Signifigant byte, which is the least, which is a multiplier and that sort of thing.
Its not a lite-c thing, its a true C thing. Try looking around some C or C++ tutorial sites and you may find how INTs and FLOATs are internally structured, but you'll need to ask the Devs about how the VAR is structured.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|
|
|
|