Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by madpower2000. 07/22/26 14:01
ZorroGPT
by TipmyPip. 07/21/26 17:54
New Zorro version 3.11
by jcl. 07/21/26 13:42
Lapsa's very own thread
by Lapsa. 07/18/26 13:40
Purchase A8 full licence version
by ukgamer. 07/17/26 05:52
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 9,798 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Ephraim, Student_64151
19223 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
mapping structs over skills array #246142
01/13/09 20:25
01/13/09 20:25
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
(reposted from Lite-C forum as this seems more appropriate)

I have this struct:
Code:
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 function 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 array [Re: DavidM] #246213
01/14/09 08:09
01/14/09 08:09
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Foo* r = (Foo*)(&e->skill[70]);

I don't think this will return the memory area from skill0 on..
Static Enttiies have less skills, I think around 20.
This might cause th eproblem.

Re: mapping structs over skills array [Re: FBL] #246292
01/14/09 14:25
01/14/09 14:25
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
Thanks Firo.

When you say static entities you mean ones declared as globals in my code, or ones placed by WED inside the wmp file?

The ENTITY I was passing to my function was a map entity so that makes sense.

Re: mapping structs over skills array [Re: DavidM] #246306
01/14/09 15:40
01/14/09 15:40
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Static entities are entities with no action assigned.

Re: mapping structs over skills array [Re: Pappenheimer] #246326
01/14/09 17:12
01/14/09 17:12
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Code:
typedef struct {...} Bar;
const int BAR_SLOT 70;
LIST barList; // any dynamic list implementation will do here, i've once contributed one, just adapt the functions' names below

Bar* AsBar(ENTITY* e) {
    if (!in(barList, e)) {
        e->skill[BAR_SLOT] = (int)malloc(sizeof(Bar));
        push(barList, e);
    }
    return (Bar*)(e->skill[BAR_SLOT]);
}

...

void cleanup(void) {
    for (i = 0; i < size(barList); i ++) {
        free((void*)pop(barList));
    }
}


haven't tested it but should work. greetings!

Re: mapping structs over skills array [Re: Joey] #246345
01/14/09 18:46
01/14/09 18:46
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
Thanks for the replies!

If I understand correctly the engine determines skills array size based on whether "events" field is empty or not.

So, if I have an entity and I clear the "events" handler in a function, does the engine resize the ENTITY*?

Or is the entity size determination made at the end of the action() assigned to it? (ie. once sized the skills array does not change)

Re: mapping structs over skills array [Re: DavidM] #246429
01/15/09 07:43
01/15/09 07:43
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
The indicator is the 'dynamic' flag. But I don't think the engine will size down any dynamic entities which were flagged to static during runtime.
I don't know for sure, though.

Re: mapping structs over skills array [Re: FBL] #246551
01/15/09 15:59
01/15/09 15:59
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
Thanks to all who helped me with this.


Moderated by  old_bill, Tobias 

Gamestudio download | 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