Monday, July 25, 2016

Basic Game Object Communication

Basic Game Object Communication
D3DXVECTOR3 vpos = FindPosition(warehouse, Convert_Truck_ID_To_Name(this->m_truck_id));

 

The line is contained the class called Truck,

It needs to retrieve where it's going to park in the warehouse.

In this case, The FindPosition requires a warehouse pointer/handle to

know where to start to look.

 

I've several options here.

1) Store a global pointer of the warehouse, so I can access it anywhere

2) Use a Singleton to do the similar stuff

3) Store a local pointer, so a warehouse is always passed into the truck object (Not quite modular in this case)

4) Make use of the state machine, and let the state machine store a vector/map of game objects pointers, so it starts to look up from there inside. And I just send a message to the Truck State Machine, the truck state machine fills up the warehouse information and Just put the FindPosition inside the state machine. And it will handle the rest

 

Should I use option 4? it seems to be the preferred way to go? Not sure, so want to ask your opinion?

 

 


No comments:

Post a Comment