GameView

Published June 16, 2008
Advertisement
I haven't changed anything on the front-end yet, everything has been structural. In the GameView, I'm adding HookEntity and UnhookEntity functions, to pass the GameView an entity pointer. The entity itself is still maintained by the user, just like with the HUD.

There's a couple differences between the HUD's "statinfo" struct and the GameView's "entity" struct right now, although I'm probably going to modify the statinfo struct later anyways. One difference is that the HUD itself holds the statinfo struct, and the user only keeps the int pointer used to modify the value of the stat on-screen. The GameView only keeps a pointer to the entity struct, and the user keeps the entire thing. This lets the user modify more than just one field as well, which is nice.

The other difference is that the entity structure contains an iterator to the entity pointer's location in the GameView's std::list of entity*'s. This seems a bit odd, but it's not actually meant to be used by the user. When you HookEntity() an entity, the GameView stores the entity's list iterator position. You need this iterator to pass to UnhookEntity() so it can find and unhook the right structure. It also points the unhooked entity's iterator to NULL.

A note on HookEntity and UnhookEntity. In the HUD, I use std::vector, so when I DeleteStat, I pretty much break the integer indices I returned from AddStat that are in front of the stat deleted. In the GameView, I use std::list. When HookEntity is called, it first looks for an empty link in the list (where the entity* is NULL). If it can't find one, only then does it push_back on the list. This helps keep down the amount of wasted space in the list, while keeping the iterators in the existing entities valid. Thus, UnhookEntity unhooks an entity and replaces it in the list with a NULL pointer. It also, to keep things clean in the list, checks beforehand if the iterator is at end()-1, or the last item in the list. If it is, it just uses pop_back() to get rid of the link entirely.

I'm probably going to implement those two differences in GameView into the HUD too, because I don't see why not. And because DeleteStat's index-breaking habit is a bug. Comments please? :D
Previous Entry Movement
Next Entry Username Change
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement