• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lucky6969b

Please help "error C2504: 'Activity' : base class undefined"

8 posts in this topic

Object and Goods are abstract.

When I derive a class called TruckArrive from it, the titled error occurs.

Please help

#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;

#ifdef WIN32
#    define snprintf _snprintf
#endif

// Uncomment this to dump all the requests in stdout.
#define DUMP_REQS

// Returns a random number [0..1)
static float frand()
{
//    return ((float)(rand() & 0xffff)/(float)0xffff);
    return (float)rand()/(float)RAND_MAX;
}

inline bool inRange(const float* v1, const float* v2, const float r, const float h)
{
    const float dx = v2[0] - v1[0];
    const float dy = v2[1] - v1[1];
    const float dz = v2[2] - v1[2];
    return (dx*dx + dz*dz) < r*r && fabsf(dy) < h;
}


static int fixupCorridor(dtPolyRef* path, const int npath, const int maxPath,
                         const dtPolyRef* visited, const int nvisited)
{
    int furthestPath = -1;
    int furthestVisited = -1;
    
    // Find furthest common polygon.
    for (int i = npath-1; i >= 0; --i)
    {
        bool found = false;
        for (int j = nvisited-1; j >= 0; --j)
        {
            if (path[i] == visited[j])
            {
                furthestPath = i;
                furthestVisited = j;
                found = true;
            }
        }
        if (found)
            break;
    }

    // If no intersection found just return current path.
    if (furthestPath == -1 || furthestVisited == -1)
        return npath;
    
    // Concatenate paths.    

    // Adjust beginning of the buffer to include the visited.
    const int req = nvisited - furthestVisited;
    const int orig = rcMin(furthestPath+1, npath);
    int size = rcMax(0, npath-orig);
    if (req+size > maxPath)
        size = maxPath-req;
    if (size)
        memmove(path+req, path+orig, size*sizeof(dtPolyRef));
    
    // Store visited
    for (int i = 0; i < req; ++i)
        path[i] = visited[(nvisited-1)-i];                
    
    return req+size;
}


static bool getSteerTarget(dtNavMeshQuery* navQuery, const float* startPos, const float* endPos,
                           const float minTargetDist,
                           const dtPolyRef* path, const int pathSize,
                           float* steerPos, unsigned char& steerPosFlag, dtPolyRef& steerPosRef,
                           float* outPoints = 0, int* outPointCount = 0)                            
{
    // Find steer target.
    static const int MAX_STEER_POINTS = 3;
    float steerPath[MAX_STEER_POINTS*3];
    unsigned char steerPathFlags[MAX_STEER_POINTS];
    dtPolyRef steerPathPolys[MAX_STEER_POINTS];
    int nsteerPath = 0;
    navQuery->findStraightPath(startPos, endPos, path, pathSize,
                               steerPath, steerPathFlags, steerPathPolys, &nsteerPath, MAX_STEER_POINTS);
    if (!nsteerPath)
        return false;
        
    if (outPoints && outPointCount)
    {
        *outPointCount = nsteerPath;
        for (int i = 0; i < nsteerPath; ++i)
            dtVcopy(&outPoints[i*3], &steerPath[i*3]);
    }

    
    // Find vertex far enough to steer to.
    int ns = 0;
    while (ns < nsteerPath)
    {
        // Stop at Off-Mesh link or when point is further than slop away.
        if ((steerPathFlags[ns] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
            !inRange(&steerPath[ns*3], startPos, minTargetDist, 1000.0f))
            break;
        ns++;
    }
    // Failed to find good point to steer to.
    if (ns >= nsteerPath)
        return false;
    
    dtVcopy(steerPos, &steerPath[ns*3]);
    steerPos[1] = startPos[1];
    steerPosFlag = steerPathFlags[ns];
    steerPosRef = steerPathPolys[ns];
    
    return true;
}


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;

};

 

Thanks

Jack

 

0

Share this post


Link to post
Share on other sites

Well, you haven't included the code actually causing the error, but it seems you try to derive from the class Activity when the type is not visible and complete. Either you forgot to #include the header where Activity is defined or cyclical dependencies prevent the definition from being known at the point in question.

0

Share this post


Link to post
Share on other sites

#pragma once
 
#include "..\Objects\Objects.h"
#include "..\Activities\RunToObject.h"
#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);
 };
0

Share this post


Link to post
Share on other sites

Objects.h

#pragma once

#include "..\SkinnedMesh\skinnedMesh.h"
 
#include "..\Activities\Activity.h"
#include "..\Activities\RunToObject.h"
#include "..\Activities\Idle.h"
#include "..\Activities\TruckArrive.h"

#include "MotiveBase.h"

//#include "..\myDX9Widget.h"

class myDX9Widget;
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;



};

class CWarehouse : public Objects
{
public:
    CWarehouse() { }
    CWarehouse(const CWarehouse& warehouse) { this->mesh = warehouse.mesh; }
    CWarehouse(SkinnedMesh *_mesh, myDX9Widget *_Owner) : Objects(_mesh, _Owner) { }

    
};


class CCB : public Objects
{
public:
    CCB()  { }
    CCB(const CCB& ccb) { this->mesh = ccb.mesh; }
    CCB(SkinnedMesh *_mesh, myDX9Widget* _Owner) : Objects(_mesh, _Owner) {  }

    

private:
    MotiveBase Motives;

};


class Goods : public Objects
{
public:
    Goods() { }
    Goods(const Goods& goods) { this->mesh = goods.mesh; }
    Goods(SkinnedMesh *_mesh, myDX9Widget* _Owner);
    void OnUpdate(float dt);

    virtual Activity *DefaultActivity(Objects*, Goods*) = 0;
    
    
    // The priority of the job the worker needs to clear up first
    virtual float PriorityInterest(Objects*) = 0;
    
};

class Pallet : public Goods
{
    Pallet() { }
    Pallet(const Pallet& pallet) { this->mesh = pallet.mesh; }
    Pallet(SkinnedMesh *_mesh, myDX9Widget *_Owner) : Goods(_mesh, _Owner) { }

public:

    

    Activity* DefaultActivity(Objects *object, Goods* goods)
    {
    }

    // The priority of the job the worker needs to clear up first
    float PriorityInterest(Objects *object)
    {
        return 1.0f;
    }


};

class Carton : public Goods
{
    Carton() { }
    Carton(const Carton& carton) { this->mesh = carton.mesh; }
    Carton(SkinnedMesh *_mesh, myDX9Widget* _Owner) : Goods(_mesh, _Owner) { }
public:

    

    Activity* DefaultActivity(Objects *object, Goods* goods)
    {
    }

    // The priority of the job the worker needs to clear up first
    float PriorityInterest(Objects *object)
    {
        return 1.0f;
    }

};

class COperator : public Objects
{
public:
    COperator() { }
    COperator(const COperator& op) { this->mesh = op.mesh; }
    COperator(SkinnedMesh *_mesh, myDX9Widget* _Owner) : Objects(_mesh, _Owner) {  }

    

};

class Lorry : public Objects
{
public:
    Lorry() { }
    Lorry(const Lorry& lorry) { this->mesh = lorry.mesh; }
    Lorry(SkinnedMesh *_mesh, myDX9Widget* _Owner) : Objects(_mesh, _Owner) {  SetVisible(false); }
    ~Lorry() {
        if (activity != NULL) {
            delete activity;
            activity = NULL;
        }

        if (m_pAnimCtrl != NULL)
        {
            m_pAnimCtrl->Release();
            m_pAnimCtrl = NULL;
        }
    }

    void Update(const D3DXMATRIX& mat, float dt);
    

    Activity* DefaultActivity(Objects *object, Goods* goods);
    

    // The priority of the job the worker needs to clear up first
    float PriorityInterest(Objects *object);
    
};
0

Share this post


Link to post
Share on other sites

It is hard to understand your current code as there is an awful lot of it. You probably have a circular header dependency. Check out [url="http://www.gamedev.net/page/resources/_/technical/general-programming/organizing-code-files-in-c-and-c-r1798"]this article[/url] for an overview of how to structure your code.

 

I'd also advise you to consider splitting your code into more headers, and placing more of the implementation in source files.

Edited by rip-off
0

Share this post


Link to post
Share on other sites

I believe your onUpdate in TruckArrive needs to be Virtual:

 

virtual bool OnUpdate(float seconds);

0

Share this post


Link to post
Share on other sites

I believe your onUpdate in TruckArrive needs to be Virtual:
 
virtual bool OnUpdate(float seconds);


No, that is not the problem. If a function is virtual in a base class, none of the implementations in subclasses need to mark themselves virtual. In C++11 it would be a good idea to use the 'override' keyword though.
lucky6969b's problem is just simple inclusion chaos. He needs a better plan on which class needs access to what, he needs to stick to the "one header, one class"-rule, he needs to use more implementation files instead of just writing almost everything in the header, he needs to make better use of forward declarations.
1

Share this post


Link to post
Share on other sites

Hi,

I have segregate everything into files.

Objects.h

#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;



};






 
 
 

 

Here the what the Activity.h file looks like

#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;

#ifdef WIN32
#    define snprintf _snprintf
#endif

// Uncomment this to dump all the requests in stdout.
#define DUMP_REQS

// Returns a random number [0..1)
static float frand()
{
//    return ((float)(rand() & 0xffff)/(float)0xffff);
    return (float)rand()/(float)RAND_MAX;
}

inline bool inRange(const float* v1, const float* v2, const float r, const float h)
{
    const float dx = v2[0] - v1[0];
    const float dy = v2[1] - v1[1];
    const float dz = v2[2] - v1[2];
    return (dx*dx + dz*dz) < r*r && fabsf(dy) < h;
}


static int fixupCorridor(dtPolyRef* path, const int npath, const int maxPath,
                         const dtPolyRef* visited, const int nvisited)
{
    int furthestPath = -1;
    int furthestVisited = -1;
    
    // Find furthest common polygon.
    for (int i = npath-1; i >= 0; --i)
    {
        bool found = false;
        for (int j = nvisited-1; j >= 0; --j)
        {
            if (path[i] == visited[j])
            {
                furthestPath = i;
                furthestVisited = j;
                found = true;
            }
        }
        if (found)
            break;
    }

    // If no intersection found just return current path.
    if (furthestPath == -1 || furthestVisited == -1)
        return npath;
    
    // Concatenate paths.    

    // Adjust beginning of the buffer to include the visited.
    const int req = nvisited - furthestVisited;
    const int orig = rcMin(furthestPath+1, npath);
    int size = rcMax(0, npath-orig);
    if (req+size > maxPath)
        size = maxPath-req;
    if (size)
        memmove(path+req, path+orig, size*sizeof(dtPolyRef));
    
    // Store visited
    for (int i = 0; i < req; ++i)
        path[i] = visited[(nvisited-1)-i];                
    
    return req+size;
}


static bool getSteerTarget(dtNavMeshQuery* navQuery, const float* startPos, const float* endPos,
                           const float minTargetDist,
                           const dtPolyRef* path, const int pathSize,
                           float* steerPos, unsigned char& steerPosFlag, dtPolyRef& steerPosRef,
                           float* outPoints = 0, int* outPointCount = 0)                            
{
    // Find steer target.
    static const int MAX_STEER_POINTS = 3;
    float steerPath[MAX_STEER_POINTS*3];
    unsigned char steerPathFlags[MAX_STEER_POINTS];
    dtPolyRef steerPathPolys[MAX_STEER_POINTS];
    int nsteerPath = 0;
    navQuery->findStraightPath(startPos, endPos, path, pathSize,
                               steerPath, steerPathFlags, steerPathPolys, &nsteerPath, MAX_STEER_POINTS);
    if (!nsteerPath)
        return false;
        
    if (outPoints && outPointCount)
    {
        *outPointCount = nsteerPath;
        for (int i = 0; i < nsteerPath; ++i)
            dtVcopy(&outPoints[i*3], &steerPath[i*3]);
    }

    
    // Find vertex far enough to steer to.
    int ns = 0;
    while (ns < nsteerPath)
    {
        // Stop at Off-Mesh link or when point is further than slop away.
        if ((steerPathFlags[ns] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
            !inRange(&steerPath[ns*3], startPos, minTargetDist, 1000.0f))
            break;
        ns++;
    }
    // Failed to find good point to steer to.
    if (ns >= nsteerPath)
        return false;
    
    dtVcopy(steerPos, &steerPath[ns*3]);
    steerPos[1] = startPos[1];
    steerPosFlag = steerPathFlags[ns];
    steerPosRef = steerPathPolys[ns];
    
    return true;
}


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;

};

What the Idle.h and TruckArrive.h look

Idle.h

#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);
    

};

TruckArrive.h

#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);
 };

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    19    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    25    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    19    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    25    1    PerfectSim
 
 

Edited by lucky6969b
0

Share this post


Link to post
Share on other sites

Objects.h includes Idle.h which includes Activity.h which includes Objects.h. This kind of circular dependency is an excellent indication that you need to refactor.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0