CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    Circular references suspected. Any help please.

    Objects.h
    Code:
    #pragma once
    
    #include "..\SkinnedMesh\skinnedMesh.h"
     
    
    #include "..\Activities\RunToObject.h"
    #include "..\Activities\Idle.h"
    #include "..\Activities\TruckArrive.h"
    
    #include "MotiveBase.h"
    
    //#include "..\myDX9Widget.h"
    
    class myDX9Widget;
    class Activity;
    class TruckArrive;
     
    
    class Objects
    {
    	friend class InverseKinematics;
    public:
    	Objects() : m_pAnimCtrl(0), energy(0) { }
    
    	Objects(SkinnedMesh* _mesh, myDX9Widget *_Owner); 
    	virtual ~Objects(void) { 
    		OutputDebugStringA("Cleanup code for Objects\n");
    /*		if (StateMachine != NULL)
    		{
    			delete StateMachine; 
    			StateMachine = NULL;
    		}*/
    
    		if (m_pAnimCtrl != NULL)
    		{
    			m_pAnimCtrl->Release(); 
    			m_pAnimCtrl = NULL;
    		}
    
    		if (activity != NULL)
    		{
    			delete activity;
    			activity = NULL;
    
    		}
    	
    		
    	}
    
    	virtual void Init()
    	{
    		 this->GetAnimations(animations);
    
    		 if (animations.size() > 0)
    				this->SetAnimation(animations[m_activeAnimation]);
    
    		 
    	}
    
    	void SetPos(const D3DXVECTOR3& _pos) { m_vPos = _pos; }
    	void SetRot(const D3DXVECTOR3& _rot) { m_vRot = _rot; }
    	void SetScale(const D3DXVECTOR3& _scale) { m_vScale = _scale; }
    	void SetScaleCenter(const D3DXVECTOR3& _scale) { m_vScaleCenter = _scale; }
    	void SetRotQuat(const D3DXQUATERNION& _quat) { m_quatRot = _quat; }
    	void SetRotCenter(const D3DXVECTOR3& _rot) { m_vRotCenter = _rot; }
    
    	void AddToPos(D3DXVECTOR3 &vPos)		{ m_vPos += vPos;     }
    	void AddToScale(D3DXVECTOR3 &vScale)	{ m_vScale += vScale; }
    	void AddToRot(D3DXVECTOR3 &vRot)		{ m_vRot += vRot;	  }	
    
    	D3DXVECTOR3 GetPos()					{ return m_vPos;   }
    	D3DXVECTOR3 GetScale()					{ return m_vScale; }
    	D3DXVECTOR3 GetRot()					{ return m_vRot;   }
    
    	
    
    public:
    	bool IsVisible() { return mVisible; }
    	void SetVisible(bool bVisible) { mVisible = bVisible; }
    
    
    
    public:
    	D3DXMATRIX GetWorldMatrix()
    	{
    		D3DXMATRIX matWorld;
    		if(m_vRot.x != 0.0f || m_vRot.y != 0.0f || m_vRot.z != 0.0f)
    		{
    			D3DXQuaternionRotationYawPitchRoll(&m_quatRot, m_vRot.x, m_vRot.y, m_vRot.z);
    			D3DXMatrixTransformation(&matWorld, &m_vScaleCenter, NULL, &m_vScale,
    				&m_vRotCenter, &m_quatRot, &m_vPos);
    		}
    		else
    			D3DXMatrixTransformation(&matWorld, &m_vScaleCenter, NULL, &m_vScale, 
    			NULL, NULL, &m_vPos);
    
    		return matWorld;
    	}
    
    	SkinnedMesh *GetMesh()
    	{
    		return mesh;
    	}
    
    protected:
    	virtual void OnUpdate(float dt) { return; }
    
    public:
    	virtual void Update(const D3DXMATRIX& mat, float dt);
    	void Draw();
    
    private: 
    	void UpdateMatrices(D3DXFRAME_DERIVED* f, D3DXMATRIX* m);
    	
    	
    	void SetAnimation(std::string name);
    	void GetAnimations(std::vector<std::string> &animations);
    
    protected:
    	SkinnedMesh *mesh;
    	D3DXVECTOR3 m_vPos;
    	D3DXVECTOR3 m_vRot;
    	D3DXVECTOR3 m_vScale;
    	D3DXVECTOR3 m_vScaleCenter;
    	D3DXVECTOR3 m_vRotCenter;
    	D3DXQUATERNION m_quatRot;
    	D3DCAPS9 m_d3dcaps;
    
    	LPD3DXANIMATIONCONTROLLER m_pAnimCtrl;
    
    	int m_activeAnimation;
    
        std::vector<std::string> animations;
    	 
    public:		
    	Activity *activity;
    	float energy;
    
    	//*todo DXWidget doesn't have reference to m_vRenderObjects
    	myDX9Widget *Owner;
    
    private:
    	bool mVisible;
    
    
    
    };
    Activity.h
    Code:
    #pragma once
    
    #include <string>
    #include "..\NavMeshLoader.h"
    #include "..\Pathfinding\Detour\Include\DetourCommon.h"
    #include "..\Pathfinding\Recast\Include\Recast.h"
    #include "DetourNavMeshQuery.h" 
    #include "..\Objects\Objects.h"
    
    
    class Idle;
    class Objects;
    class Goods;
    
    
    class Activity
    {
    public:
    	Objects *Actor;
    	Goods *Target;
    	Activity() : Actor(0), Target(0) { }
    	Activity( Objects* actor, Goods* target ) : Actor(actor), Target(target)
    	{
    		NavMesh::GetNavMeshLoader().loadAll("Data\\all_tiles_navmesh.bin"); 
    		mStep = 0;
    	}
    
    	~Activity()
    	{
    		dtFreeNavMeshQuery(m_navQuery); 
    		m_navQuery = NULL;
    	}
    
    	void InitNavMesh(const dtNavMesh *navMesh);
    	 
    private:
    	void SetNavMesh(const dtNavMesh* navMesh) { m_navMesh = navMesh; }
    
    protected:
    	void findPath(); 
    
    
    	void ReCalc();
    	 
    
    public:
    	virtual bool OnUpdate(float seconds) = 0;
    
    	void Update(float seconds);
    	
    
    	Activity *FindBestActivity(Objects *actor);
    	
    	std::string ToString();
    
    private:
    	// *todo separate these into a module
    	dtNavMeshQuery* m_navQuery;
    
    	const dtNavMesh *m_navMesh;
    
    	dtQueryFilter m_filter;
    
    	dtStatus m_pathFindStatus;
    	 
    	
    
    	enum ToolMode
    	{
    		TOOLMODE_PATHFIND_FOLLOW,
    		TOOLMODE_PATHFIND_STRAIGHT,
    		TOOLMODE_PATHFIND_SLICED,
    		TOOLMODE_RAYCAST,
    		TOOLMODE_DISTANCE_TO_WALL,
    		TOOLMODE_FIND_POLYS_IN_CIRCLE,
    		TOOLMODE_FIND_POLYS_IN_SHAPE,
    		TOOLMODE_FIND_LOCAL_NEIGHBOURHOOD,
    	};
    	
    	ToolMode m_toolMode;
    
    	int m_straightPathOptions;
    	
    	static const int MAX_POLYS = 256;
    	static const int MAX_SMOOTH = 2048;
    	
    	dtPolyRef m_startRef;
    	dtPolyRef m_endRef;
    	dtPolyRef m_polys[MAX_POLYS];
    	dtPolyRef m_parent[MAX_POLYS];
    	int m_npolys;
    	float m_straightPath[MAX_POLYS*3];
    	unsigned char m_straightPathFlags[MAX_POLYS];
    	dtPolyRef m_straightPathPolys[MAX_POLYS];
    	int m_nstraightPath;
    	float m_polyPickExt[3];
    	float m_smoothPath[MAX_SMOOTH*3];
    	int m_nsmoothPath;
    	float m_queryPoly[4*3];
    
    	static const int MAX_RAND_POINTS = 64;
    	float m_randPoints[MAX_RAND_POINTS*3];
    	int m_nrandPoints;
    	bool m_randPointsInCircle;
    	
    	float m_spos[3];
    	float m_epos[3];
    	float m_hitPos[3];
    	float m_hitNormal[3];
    	bool m_hitResult;
    	float m_distanceToWall;
    	float m_neighbourhoodRadius;
    	float m_randomRadius;
    	bool m_sposSet;
    	bool m_eposSet;
    
    	int m_pathIterNum;
    	dtPolyRef m_pathIterPolys[MAX_POLYS]; 
    	int m_pathIterPolyCount;
    	float m_prevIterPos[3], m_iterPos[3], m_steerPos[3], m_targetPos[3];
    	
    	static const int MAX_STEER_POINTS = 10;
    	float m_steerPoints[MAX_STEER_POINTS*3];
    	int m_steerPointCount;
    
    private:
    
    	class NavMesh
    	{
    	public:
    		static NavMeshLoader& GetNavMeshLoader()
    		{
    			static NavMeshLoader m_NavMeshLoader;
    			return m_NavMeshLoader;
    		}
    
    
    
    	};
    public:
    	void SetSrcPos(const D3DXVECTOR3& src);
    	 
    	void SetDestPos(const D3DXVECTOR3& dest);
    	 
    	float* GetPath(int index);
    	 
    private:
    	float m_SrcPos[3];
    	float m_DestPos[3];
    
    protected:
    	// iterating the path
    	int mStep;
    
    };
    TruckArrive.h
    Code:
    #pragma once 
     
     
    #include "Activity.h"
    
    class Objects;
    class Activity;
    class RunToObject;
    class Goods;
    
    
    #define MAX_BACK_MOVE 5
    
    class TruckArrive : public Activity
    {
    private:
    
    	static int mBackMove;
    
    	RunToObject runToObject;
    
    public:
    	TruckArrive();
    
    	TruckArrive(Objects *obj, Goods* goods);
    
    	bool OnUpdate(float seconds);
     };
    Idle.h
    Code:
    #pragma once
    
    
    #include "Activity.h"
     
    #define MAX_IDLE_TIME 8 // ehhh. slack for 8 seconds
    #define ACTIVITY_IDLE_ENERGY 1.0
    
    class Objects;
    class Activity;
    class Goods;
    
    class Idle : public Activity
    {
    private:
    	float mTimeInIdle;
    
    public:
    	Idle() : mTimeInIdle(0)	{ }
    	Idle(Objects *actor, Goods *target) : Activity(actor, target), mTimeInIdle(0) { }
    
    	bool OnUpdate(float seconds);
    	
    
    };
    I got these error messages:
    Error 1 error C2504: 'Activity' : base class undefined e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\Activities\TruckArrive.h 15 1 PerfectSim
    Error 2 error C2504: 'Activity' : base class undefined e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\Activities\Idle.h 14 1 PerfectSim
    Error 3 error C2614: 'Idle' : illegal member initialization: 'Activity' is not a base or member e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\Activities\Idle.h 20 1 PerfectSim
    Error 4 error C2504: 'Activity' : base class undefined e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\Activities\TruckArrive.h 15 1 PerfectSim
    Error 5 error C2504: 'Activity' : base class undefined e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\Activities\Idle.h 14 1 PerfectSim
    Error 6 error C2614: 'Idle' : illegal member initialization: 'Activity' is not a base or member e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\Activities\Idle.h 20 1 PerfectSim


    Thanks in advance
    Jack

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Circular references suspected. Any help please.

    In general, why are you not creating .CPP files, so that a lot of these member function implementations can be removed from the header file and into the .CPP file?

    I would first look at Activity and start creating an Activity.cpp file. Then a lot of those class functions would be moved to the CPP file instead of the header file, thus removing those #include lines that do nothing except slow down your compilation.

    For example:
    Code:
    #include "..\NavMeshLoader.h"
    Why do you need to include this file in Activity.h? Look carefully as to why you need to include it, and then change the code to not need to include it (in this case, forward declare whatever class you need, make sure your header just uses references or pointers to this class, and in the CPP file, implement the full function).

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Circular references suspected. Any help please.

    Code:
    #include "..\NavMeshLoader.h"
    //...
    class Activity
    {
    //...
        class NavMesh
        {
    	public:
    		static NavMeshLoader& GetNavMeshLoader()
    		{
    			static NavMeshLoader m_NavMeshLoader;
    			return m_NavMeshLoader;
    		}
        };
        //...
    };
    Code like the above need not be implemented in the header file.
    Code:
    class NavMeshLoader;
    //...
    class Activity
    {
    //...
        class NavMesh
        {
       	public:
    		static NavMeshLoader& GetNavMeshLoader();
        };
        //...
    };
    That's all you need in the header file. Then NavMeshLoader gets forward declared instead of the full-blown header being included.

    In the Activity.cpp file, you have the full implementation:
    Code:
    #include "..\NavMeshLoader.h"
    //...
    NavMeshLoader& Activity::NavMesh::GetNavMeshLoader()
    {
        static NavMeshLoader m_NavMeshLoader;
        return m_NavMeshLoader;
    };
    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 15th, 2013 at 06:01 AM.

  4. #4
    Join Date
    Dec 2010
    Posts
    907

    Re: Circular references suspected. Any help please.

    Dear Paul,
    Now what I leave to this file is a dry header file, no implementation stuff, except the inner class.
    But the problem seems to persist.
    Code:
    #pragma once
    
    #include <string>
    #include "..\NavMeshLoader.h"
    #include "..\Pathfinding\Detour\Include\DetourCommon.h"
    #include "..\Pathfinding\Recast\Include\Recast.h"
    #include "DetourNavMeshQuery.h" 
    #include "..\Objects\Objects.h"
    
    
    class Idle;
    class Objects;
    class Goods;
    
    
    class Activity
    {
    public:
    	Objects *Actor;
    	Goods *Target;
    	Activity();
    	Activity( Objects* actor, Goods* target );  
    	~Activity();
    	 
    	void InitNavMesh(const dtNavMesh *navMesh);
    	 
    private:
    	void SetNavMesh(const dtNavMesh* navMesh);
    
    protected:
    	void findPath(); 
    
    
    	void ReCalc();
    	 
    
    public:
    	virtual bool OnUpdate(float seconds) = 0;
    
    	void Update(float seconds);
    	
    
    	Activity *FindBestActivity(Objects *actor);
    	
    	std::string ToString();
    
    private:
    	// *todo separate these into a module
    	dtNavMeshQuery* m_navQuery;
    
    	const dtNavMesh *m_navMesh;
    
    	dtQueryFilter m_filter;
    
    	dtStatus m_pathFindStatus;
    	 
    	
    
    	enum ToolMode
    	{
    		TOOLMODE_PATHFIND_FOLLOW,
    		TOOLMODE_PATHFIND_STRAIGHT,
    		TOOLMODE_PATHFIND_SLICED,
    		TOOLMODE_RAYCAST,
    		TOOLMODE_DISTANCE_TO_WALL,
    		TOOLMODE_FIND_POLYS_IN_CIRCLE,
    		TOOLMODE_FIND_POLYS_IN_SHAPE,
    		TOOLMODE_FIND_LOCAL_NEIGHBOURHOOD,
    	};
    	
    	ToolMode m_toolMode;
    
    	int m_straightPathOptions;
    	
    	static const int MAX_POLYS = 256;
    	static const int MAX_SMOOTH = 2048;
    	
    	dtPolyRef m_startRef;
    	dtPolyRef m_endRef;
    	dtPolyRef m_polys[MAX_POLYS];
    	dtPolyRef m_parent[MAX_POLYS];
    	int m_npolys;
    	float m_straightPath[MAX_POLYS*3];
    	unsigned char m_straightPathFlags[MAX_POLYS];
    	dtPolyRef m_straightPathPolys[MAX_POLYS];
    	int m_nstraightPath;
    	float m_polyPickExt[3];
    	float m_smoothPath[MAX_SMOOTH*3];
    	int m_nsmoothPath;
    	float m_queryPoly[4*3];
    
    	static const int MAX_RAND_POINTS = 64;
    	float m_randPoints[MAX_RAND_POINTS*3];
    	int m_nrandPoints;
    	bool m_randPointsInCircle;
    	
    	float m_spos[3];
    	float m_epos[3];
    	float m_hitPos[3];
    	float m_hitNormal[3];
    	bool m_hitResult;
    	float m_distanceToWall;
    	float m_neighbourhoodRadius;
    	float m_randomRadius;
    	bool m_sposSet;
    	bool m_eposSet;
    
    	int m_pathIterNum;
    	dtPolyRef m_pathIterPolys[MAX_POLYS]; 
    	int m_pathIterPolyCount;
    	float m_prevIterPos[3], m_iterPos[3], m_steerPos[3], m_targetPos[3];
    	
    	static const int MAX_STEER_POINTS = 10;
    	float m_steerPoints[MAX_STEER_POINTS*3];
    	int m_steerPointCount;
    
    private:
    
    	class NavMesh
    	{
    	public:
    		static NavMeshLoader& GetNavMeshLoader()
    		{
    			static NavMeshLoader m_NavMeshLoader;
    			return m_NavMeshLoader;
    		}
    
    
    
    	};
    public:
    	void SetSrcPos(const D3DXVECTOR3& src);
    	 
    	void SetDestPos(const D3DXVECTOR3& dest);
    	 
    	float* GetPath(int index);
    	 
    private:
    	float m_SrcPos[3];
    	float m_DestPos[3];
    
    protected:
    	// iterating the path
    	int mStep;
    
    };

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Circular references suspected. Any help please.

    Quote Originally Posted by lucky6969b View Post
    Dear Paul,
    Now what I leave to this file is a dry header file,
    You did not remove those #include files from the header. The less #include files you have in the header, the less chance of there being circular dependencies.

    Also, my previous posts shows that you do not need that inner class's function implementation in the header file. That is the whole point -- get rid of all the implementations that require you to #include a full blown header file within Activity.h. If your Activity.h just uses references or pointers to those classes, then all that's needed is to forward declare the classes instead of #including the entire header file.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 15th, 2013 at 06:22 AM.

  6. #6
    Join Date
    Dec 2010
    Posts
    907

    Re: Circular references suspected. Any help please.

    I received 300+ errors after removing the #include
    I did throw a forward declaration at it.
    Code:
    Error	1	error C2079: 'Activity::m_filter' uses undefined class 'dtQueryFilter'	e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\activities\Activity.h	53	1	PerfectSim
    Error	2	error C2146: syntax error : missing ';' before identifier 'm_pathFindStatus'	e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\activities\Activity.h	55	1	PerfectSim
    Error	3	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\activities\Activity.h	55	1	PerfectSim
    Error	4	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\activities\Activity.h	55	1	PerfectSim
    Error	5	error C2146: syntax error : missing ';' before identifier 'm_startRef'	e:\jacky\documents\visual studio 2010\projects\perfectsim\perfectsim\perfectsim\activities\Activity.h	78	1	PerfectSim
    Last edited by lucky6969b; June 15th, 2013 at 06:37 AM.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Circular references suspected. Any help please.

    Quote Originally Posted by lucky6969b View Post
    I received 300+ errors after removing the #include
    I did throw a forward declaration at it.
    Did you understand my previous posts?
    Code:
    Error	1	error C2079: 'Activity::m_filter' uses undefined class 'dtQueryFilter'
    Is your usage of "dtQuereyFilter" a pointer or reference? Then it requires that the definition be known, meaning you need to include the header that defines dtQueryFilter.

    Any other types where you are just referring to a reference or pointer to do not require the header to be included, only forward declared. And even that, you make sure that if you use the pointer or reference in the implementation, then you move the implementation to a .CPP file, just like the inner class's implementation I showed earlier.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 15th, 2013 at 08:07 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured