Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / Game Design & Programming / Circular References Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
FreelanceGames

October 24, 2004, 03:05 PM

Is there anything wrong with circular references? For example, in my case I have the following relationship:

Unit->Hull->Engine Mounting Point->Engine

However, the reverse if also true:

Engine->Engine Mounting Point->Hull->Unit

Now when I render the engine, I am using a separate class in order to separate the behavior from the view. So in this case the following is being implemented:

Engine Renderer->Engine


However, in order to render the engine I also need to know the position of the Engine Mounting Point and the angle of the Unit. So I have two choices:

First when I create the Engine Renderer, I can use the circular reference outlined above and just let the Engine Renderer know about the Engine; when I create the Engine Renderer.

Second choice would be to let the Engine Renderer know about the Unit, Engine Mounting Point, and the Unit.

Engine Renderer->Engine & Engine Mounting Point & Unit

I think I prefer the second choice because it lowers coupling within the model? Anyone else have an opinion? Welcome base Flipcode…

Sean Doherty, BCS
www.FreelanceGames.com

 
onebeer

October 24, 2004, 09:24 PM

I hate to say it, but you might want to rethink your render process. Normally, the Engine doesn't have to know where it is to be rendered. The Engine Mount has a pointer to the Engine and will setup the transform before the Engine is rendered. If you tie the Engine to the Engine Mount, you will never be able to use the Engine tied to any other object.

 
FreelanceGames

October 26, 2004, 09:01 PM

Ya, I am not linking the engine to the mounting point. Here is what I am doing at present:

Unit->Hull->Mounting Point->Engine
Unit--has a->Hull--has one or more->mounting point--has an->engine.

Now, the actual engine is being rendered by the another class that is part of the view called the engine renderer. Spliting the rendering into another class allows me to maintain the sperations of concerns between the view and the model. That said, the engine renderer needs to knows about the Unit, Mounting Point, and Engine at the time of creation. Now when I render the engine I simply look up the various values for the classes and calculate the translation matrix. This design allows for a segration between the view and the model. Basically, you can swap out the view for a different one.

 
This thread contains 3 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.