quote:Original post by Wildfire
I think you''re taking encapsulation a bit far. As long as you are writing the class, you don''t have to hide data from yourself? It''s like writing a private iterface for accessing your private data... Unless you can''t remember that talk() shouldn''t alter any foot values, I don''t see any reason why you should be accidently doing it?
I understand I was taking it a little bit to far, but as I said I am being picky.
quote:
And, like I mentioned in my above post, if you make the static variable part of the function, it''s accessible for that one member function only.
Well I will give you a quick example of my class so you can understand more what I am talking about:
class Agent {public: Agent(); virtual ~Agent(); float getX(); float getY(); int getHeading(); void setXY(int iX, int iY); void setHeading(int iHeading); void moveXY(int iX, int iY); void setID(int iID); bool getControllable(); void setControllable(bool bControl); void update(); LOS *getLOS(); AStar *getAStar(); AgentCoverMap *getCoverMap(); void setDataMap(DataMap *CDataMap); void go(); enum MovementSpeed getMovementSpeed(); void setMovementSpeed(enum MovementSpeed eSpeed); int getState(); char *getStateName();private: void updateState(); void updateMovement(); void findNearestCover(); bool m_bHControl; AgentCoverMap m_CCover; float m_fX; float m_fY; int m_iHeading; //int m_iHealth; LOS m_CLOS; AStar *m_CAStar; DataMap *m_CDataMap; int m_iID; int m_iState; enum MovementSpeed m_eMotionSpeed; Weapon m_CSelectedWeapon;};void Agent::updateMovement(){ static AList::iterator CNode; static AList::iterator CDebugNode; AList::iterator CPreviousNode; static bool bFirstMove; static bool bAtDestination=true; static long lNextMoveTick; static bool bNextMove=true; static bool bFinalMove; static int iMoveX, iMoveY; static float fMovingX, fMovingY; static float fSpeedX,fSpeedY; long lTimeLimit; bool bEnd; int iErrorLoop=0; //update pathfinding if ((!m_CAStar->pathFound()) && (!m_CAStar->faultOccured())) //check if astar needs to be calculated { lTimeLimit = (long)GetTickCount() + 50; //run until AStar runs out of time do { m_CAStar->update(); //check for fault or path found if (m_CAStar->faultOccured() || m_CAStar->pathFound()) break; }while (lTimeLimit > (long)GetTickCount()); bFirstMove = true; if (m_CAStar->pathFound()) { bAtDestination=false; lNextMoveTick = GetTickCount(); bNextMove = true; bFinalMove = false; //setup first node CNode = m_CAStar->getPath()->begin(); } } if (m_CAStar->pathFound()) { //move along path if ((!bAtDestination) && (lNextMoveTick { if (bNextMove) { //get next node bEnd = false; do { //check if no nodes exist on list if (m_CAStar->getPath()->size() == 0) { bAtDestination=true; return; } //grab new and previous node and remove previous from list CPreviousNode = CNode; ++CNode; m_CAStar->getPath()->remove(*CPreviousNode); //check if agent is about to move to last node if (CNode == m_CAStar->getPath()->end()) bEnd = true; iMoveX = CNode->iX; iMoveY = CNode->iY; //check how many errors have occured iErrorLoop++; if (iErrorLoop>1000) { //report error and quit MessageBox(NULL,"Error: Agent stuck in movement update loop","",MB_OK); bAtDestination=true; return; } if (bEnd) break; } while (!(iMoveXgetWidth() && iMoveYgetHeight() && iMoveY>=0 && iMoveX>=0)); fMovingX = m_fX - (float)iMoveX; fMovingY = m_fY - (float)iMoveY; fSpeedX = fMovingX/m_eMotionSpeed; fSpeedY = fMovingY/m_eMotionSpeed; m_CAStar->getPath()->remove(*CPreviousNode); //check if final node if (bEnd) { bFinalMove=true; bAtDestination=true; } bNextMove=false; } //move along route if (!bAtDestination) { m_fX -= fSpeedX; m_fY -= fSpeedY; } //check if at next move if ((m_fX == float(iMoveX)) && (m_fY == float(iMoveY))) { bNextMove = true; if (bFinalMove) { bAtDestination=true; m_fX = iMoveX; m_fY = iMoveY; } } //check if within map bounds if (m_fX < 0) m_fX = 0; if (m_fY < 0) m_fY = 0; lNextMoveTick = GetTickCount() + 70; } }}
So as you can see there are a lot of static variables (I probably have used them to a bit of excess). It''s just that when I do an update - it always causes my first agent to move when my second agent is supposed to move, due to the statics being updated by the second.
So is there any other way than using member level variables to store specific to that instance?
Extracting Patch....
Initializing Windows XP Update Path 2543663B....
Core Dumped, Now Installing Linux.....
----
Mike
Team AI: Http://members.iinet.net.au/~slyons/teamai