Ah I see, but the problem here is not to find the gentity_t base adress
(it's already stored in memory in sv.gentities by SV_LocateGameData()), but
to find the adress of the health field, and the problem is that because
there are a lot of fields between r and health, and of many different
types, it's just impossible to make a locating function without knowing the
exact structure of gentity. Because in fact my biggest problem at first was
that I couldn't find a way to get the declaration of the gentity_t type
without having includes error.

Anyway, I would love to be able to access the health field without having
to rely on the gentity_t type, so if you have an idea how to get the health
field without using a gentity_t anywhere, it would be great, because it
would then avoid the weird includes I did to make the code work properly.

Cordially,
Stephen Larroque

Le 10 mars 2012 23:31, Ben Noordhuis <i...@bnoordhuis.nl> a écrit :

> On Sat, Mar 10, 2012 at 19:07, Stephen LARROQUE <lrq3...@gmail.com> wrote:
> > Hello Ben,
> >
> > Thank you very much for your code, I wish I could write so much
> complicated
> > defines by myself ;)
> >
> > Unfortunately your code does not work right away, first because as_gent
> > takes entityShared_t as argument instead of sharedEntity_t, and secondly
> > your function only returns the r member, which is in fact an
> entityShared_t,
> > but this is not what I'm looking for.
>
> Yes, sorry. There's a typo in the example, it should have read:
>
>  return container_of(shared_ent, gentity_t, r);
>
> IOW, take the field offset of `r` and subtract it from the
> `shared_ent` pointer to get the address of the enclosing `gentity_t`
> struct.
> _______________________________________________
> ioquake3 mailing list
> ioquake3@lists.ioquake.org
> http://lists.ioquake.org/listinfo.cgi/ioquake3-ioquake.org
> By sending this message I agree to love ioquake3 and libsdl.
>
_______________________________________________
ioquake3 mailing list
ioquake3@lists.ioquake.org
http://lists.ioquake.org/listinfo.cgi/ioquake3-ioquake.org
By sending this message I agree to love ioquake3 and libsdl.

Reply via email to