Jim Hunter wrote:
>
> The basic idea was
> that I added a structure (user_variables_t) to CBaseEntity
> and then used pev->iuser4 to hold a pointer to the
> structure.
[...]
> Then I
> created a user message to send the data during each call to
> UpdateClientData in client.cpp.  On the client, I caught the
> user data message and held the data until the next client
> update came in (since the user data message got sent just
> before the client update) and then associated the
> user_variables_t struct with the network update that came
> in.
[...]
> but have not released it yet since I
> wanted to make *absolutely* sure it was bug free first,
> considering the potential for total havoc with the use of
> dynamic memory allocation.

That looks like a pretty nifty idea to me. And I guess it works.
But since you asked, I'll add a comment, too. :)

I don't really think you will be getting into trouble with this
since HL runs only on Windows and Linux, both for i386 (and thus
iA32) architecture and little endian. So you will not be likely to
come across 64bit pointers. On the other hand, it is not
guaranteed that an int will be 32bit large. So your code is living
on some assumptions not necessarily true.

They will be true for most probable cases. I'm just saying that
your code is not _guaranteed_ to work. So if you want to spend the
time and cover all possible cases you would have to write wrappers
for accessing the struct which would take care of the case that an
int is only 16bits large. But I also think you'll hardly get into
any trouble if you spare yourself the work.

The same is true for endianess. I guess the engines transport
functions take care of that, so it shouldn't be a problem for you.
If you have a fixed structure you might gain some performance by
sending the structure members one by one with the respective
WRITE_ function. Sending byte by byte has the advantage that you
don't have to change the Send function when you change the
structure.

Since you said that you add a structure as a member I don't see
where the dynamic memory allocation comes in. Unless you allocate
the structure dynamically. But you could take care of that by
creating/deleting it in the constructor/destructor and be fine.
(BTW, the engine uses a similar ugly hack to expose a pointer to
an objects private members. *yuck*)

Just my 2 cents.

Florian.
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to