« How Anal Is That? | Main | Quality of Engineering - Does It Really Matter? »

August 06, 2009

Comments

I guess we all have experienced something similar to your curtain example at one point or another. I often encountered similar problems with GUI stuff, like mouse cursor hiding or gamepad input routing.

Reference counting might help a bit but it often adds more problems than it solves, because it can go wrong quite easily. I've already seen code like "while(!visible()) visible_ref++;" ... no, really.

The solution I tend to choose nowadays is that there is only one piece of code that decides of the final result, but instead of pulling states itself from everywhere in the game, it has a stack of triggers, each trigger being owned by the relevant part of the game (cutscene, respawn, transition). And each trigger has three states: "on", "off" and "don't care". At every update, I search the stack in sequence, looking for the first "on" or "off" value. Each part of the game can only change its own trigger, and in the end it's only a matter of deciding the right order.

I don't know if my explanation is clear, but in fact it's a lot less code than it sounds, and it is very convenient to debug.

Duplication of data is actually desirable, now that we're moving to many-core architectures with disjoint local memories. Processes have no way to communicate, except by sending copies of data through fifos.

Alan Kay: "Actually I made up the term "object-oriented", and I can tell you I did not have C++ in mind."

I would make a "curtain" process that accepts multiple messages, like

1. lower curtain
2. raise curtain
3. lower curtain, and don't raise again until i say so

Your "transition" script would call message #2 and #3, because it knows it will visually glitch otherwise. The "respawn" script would call #1 and #2.

Implementation is not for the caller to know. Probably the "until I say so" part would involve something like a reference count?

The design focus should be on sussing out all the messages required to meet the expectations of callers.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.