How to "kind of" make shared an object? :) | | |
I have this classes tree
GameManager 1 object
Game Multiple objects
Map 1 object
Player Multiple objects
Squads Multiple objects
Units Multiple objects
Now each Squad or Units have to know about data on it's Map
Say I have Game1 and Game 2
Game2 have different map than Game1
any unit1_1 of branch Game1 need to know about Map1
any unit1_2 of branch Game2 need to know about Map2
How to accomplish that?
Should I pass to Unit1_1 the Game1 instance?
I whould like the Map1 shared to all Game1 children objects somehow..the
same with Map2 and Game2
Right now I keep passing the map arround each time I need it way down to a
unit that move or do stuffs
--
Cheers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------ | | | | re: How to "kind of" make shared an object? :)
What I want to know is if it is possible to make some kind of xml tree
walking, so I can go up and access any ancestor of a node... i my case nore
is a reference to a class instance
--
Cheers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
"Crirus" <Crirus@datagroup.ro> wrote in message
news:e599T7n2DHA.2948@TK2MSFTNGP09.phx.gbl...[color=blue]
> I have this classes tree
>
> GameManager 1 object
> Game Multiple objects
> Map 1 object
> Player Multiple objects
> Squads Multiple objects
> Units Multiple objects
>
> Now each Squad or Units have to know about data on it's Map
>
> Say I have Game1 and Game 2
> Game2 have different map than Game1
> any unit1_1 of branch Game1 need to know about Map1
> any unit1_2 of branch Game2 need to know about Map2
>
> How to accomplish that?
>
> Should I pass to Unit1_1 the Game1 instance?
>
> I whould like the Map1 shared to all Game1 children objects somehow..the
> same with Map2 and Game2
>
> Right now I keep passing the map arround each time I need it way down to a
> unit that move or do stuffs
>
> --
> Cheers,
> Crirus
>
> ------------------------------
> If work were a good thing, the boss would take it all from you
>
> ------------------------------
>
>[/color] | | | | re: How to "kind of" make shared an object? :)
On Wed, 14 Jan 2004 11:14:32 +0200, Crirus wrote:
[color=blue]
>
> GameManager 1 object
> Game Multiple objects
> Map 1 object
> Player Multiple objects
> Squads Multiple objects
> Units Multiple objects
>[/color]
I don't know fully what you are designing, but to my mind, Player should
not be on the same level as Game but rather a sub level of game:
GameManager
Game
Map
Player
Squads
Units
Player, to me is an element of a Map. It seems like it would be a child of
map. A GameManager contains Games which contain maps which contain players
which have squads of units.
If this is the case, then a single unit can traverse up through it parents
to get the map info.
Just my thoughts.
--
Chris
To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address. | | | | re: How to "kind of" make shared an object? :)
the players are indeed childs of game.. was a TAB missing there
Map is a separate class only with data of the terrain
Players join to game not to map in my design
How to traverse up such a graph?
--
Cheers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1f2f71hr5wcw9.119uhrmtrgxjm$.dlg@40tude.net.. .[color=blue]
> On Wed, 14 Jan 2004 11:14:32 +0200, Crirus wrote:
>[color=green]
> >
> > GameManager 1 object
> > Game Multiple objects
> > Map 1 object
> > Player Multiple objects
> > Squads Multiple objects
> > Units Multiple objects
> >[/color]
>
> I don't know fully what you are designing, but to my mind, Player should
> not be on the same level as Game but rather a sub level of game:
>
> GameManager
> Game
> Map
> Player
> Squads
> Units
>
> Player, to me is an element of a Map. It seems like it would be a child[/color]
of[color=blue]
> map. A GameManager contains Games which contain maps which contain[/color]
players[color=blue]
> which have squads of units.
>
> If this is the case, then a single unit can traverse up through it parents
> to get the map info.
>
> Just my thoughts.
>
> --
> Chris
>
> To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
> address.[/color] | | | | re: How to "kind of" make shared an object? :)
On Thu, 15 Jan 2004 09:47:30 +0200, Crirus wrote:
[color=blue]
> the players are indeed childs of game.. was a TAB missing there
> Map is a separate class only with data of the terrain
> Players join to game not to map in my design
>
>
>
> How to traverse up such a graph?[/color]
My only thought on that would be that each object would have a "parent"
property or perhaps a "ContainedBy" proprty that contains a reference to
the object that contains them. As each object is created, its parent
object could be set. I don't know how a heirarchy like this might affect
performance.
So a Unit could get the map data by using something like
Squad = Unit.Parent 'Get the squad the unit is in
Player = Squad.Parent 'Get the Player that owns the squad
Map = Player.Parent 'Get the map object for the player
Game = Map.Parent 'Get the game object for that map
There may be better ways, though
--
Chris
To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address. | | | | re: How to "kind of" make shared an object? :)
Yes, that can be a solution, or even better to make a parent or grand parent
reference only in the classes that need it....
But I was wander if there could be a way to get this automatically without
my concern, but I guess a child class have no ideea about a parent that hold
it's reference
--
Cheers,
Crirus
------------------------------
If work were a good thing, the boss would take it all from you
------------------------------
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:ncxmytlgf1xl$.8qyk88qlsec8$.dlg@40tude.net...[color=blue]
> On Thu, 15 Jan 2004 09:47:30 +0200, Crirus wrote:
>[color=green]
> > the players are indeed childs of game.. was a TAB missing there
> > Map is a separate class only with data of the terrain
> > Players join to game not to map in my design
> >
> >
> >
> > How to traverse up such a graph?[/color]
>
> My only thought on that would be that each object would have a "parent"
> property or perhaps a "ContainedBy" proprty that contains a reference to
> the object that contains them. As each object is created, its parent
> object could be set. I don't know how a heirarchy like this might affect
> performance.
>
> So a Unit could get the map data by using something like
>
> Squad = Unit.Parent 'Get the squad the unit is in
> Player = Squad.Parent 'Get the Player that owns the squad
> Map = Player.Parent 'Get the map object for the player
> Game = Map.Parent 'Get the game object for that map
>
> There may be better ways, though
>
> --
> Chris
>
> To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
> address.[/color] |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,353 network members.
|