Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
   Copyright (c) 2014 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy of this software
   and associated documentation files (the "Software"), to deal in the Software without restriction,
   including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */
#ifndef _AI_ENTITY_H_
#define _AI_ENTITY_H_

#include "AI/Sensors/Headers/AudioSensor.h"
#include "AI/Sensors/Headers/VisualSensor.h"

#include "Core/Headers/cdigginsAny.h"
#include "Utility/Headers/GUIDWrapper.h"
#include "Hardware/Platform/Headers/SharedMutex.h"

struct dtCrowdAgent;

namespace Divide {

class SceneGraphNode;
class NPC;
namespace AI {
class AITeam;
class AISceneImpl;
enum  AIMsg; //< scene dependent message list
class Order;
namespace Navigation {
    class DivideRecast;
    class DivideDtCrowd;
};

/// Based on OgreCrowd.
class AIEntity : public GUIDWrapper {
public:
    enum PresetAgentRadius {
        AGENT_RADIUS_SMALL = 0,
        AGENT_RADIUS_MEDIUM = 1,//< normal human
        AGENT_RADIUS_LARGE = 2,
        AGENT_RADIUS_EXTRA_LARGE = 3,
        AgentRadius_PLACEHOLDER = 4
    };

    AIEntity(const vec3<F32>& currentPosition, const stringImpl& name);
    ~AIEntity();

    void load(const vec3<F32>& position);
    void unload();

    bool addSensor(SensorType type);
    bool addAISceneImpl(AISceneImpl* AISceneImpl);
    void sendMessage(AIEntity* receiver,  AIMsg msg, const cdiggins::any& msg_content);
    void receiveMessage(AIEntity* sender, AIMsg msg, const cdiggins::any& msg_content);
    void processMessage(AIEntity* sender, AIMsg msg, const cdiggins::any& msg_content);
    Sensor* getSensor(SensorType type);

    inline AITeam* getTeam()   const { return _teamPtr; }
           I32     getTeamID() const;
    const stringImpl& getName() const {return _name;}

           void addUnitRef(NPC* const npc);
    inline NPC* getUnitRef()                {return _unitRef;}

    /// PathFinding
    /// Index ID identifying the agent of this character in the crowd
    inline I32 getAgentID() const { return _agentID; }
    /// The agent that steers this character within the crowd
    inline const dtCrowdAgent* getAgent() const { return _agent; }
    inline bool  isAgentLoaded() const { return _agentID >= 0; }
    /// Update the crowding system
    void resetCrowd();
    /// The height of the agent for this character.
    D32 getAgentHeight() const;
    /// The radius of the agent for this character.
    D32 getAgentRadius() const;
    /// The radius category of this character
    inline PresetAgentRadius getAgentRadiusCategory() const { return _agentRadiusCategory; }
    /**
      * Update the destination for this agent.
      * If updatePreviousPath is set to true the previous path will be reused instead
      * of calculating a completely new path, but this can only be used if the new
      * destination is close to the previous (eg. when chasing a moving entity).
    **/
    bool updateDestination(const vec3<F32>& destination, bool updatePreviousPath = false);
    /// The destination set for this agent.
    const vec3<F32>& getDestination() const;
    /// Returns true when this agent has reached its set destination.
    bool destinationReached();
    /// Place agent at new position.
    bool setPosition(const vec3<F32> position);
    /// The current position of the agent.
    /// Is only up to date once update() has been called in a frame.
    const vec3<F32>& getPosition() const;
    /// The maximum speed this character can attain.
    /// This parameter is configured for the agent controlling this character.
    D32 getMaxSpeed();
    /// The maximum acceleration this character has towards its maximum speed.
    /// This parameter is configured for the agent controlling this character.
    D32 getMaxAcceleration();
     /**
      * Request to set a manual velocity for this character, to control it
      * manually.
      * The set velocity will stay active, meaning that the character will
      * keep moving in the set direction, until you stop() it.
      * Manually controlling a character offers no absolute control as the
      * laws of acceleration and max speed still apply to an agent, as well
      * as the fact that it cannot steer off the navmesh or into other agents.
      * You will notice small corrections to steering when walking into objects
      * or the border of the navmesh (which is usually a wall or object).
    **/
    void setVelocity(const vec3<F32>& velocity);
    /// Manually control the character moving it forward.
    void moveForward();
    /// Manually control the character moving it backwards.
    void moveBackwards();
    /// Stop any movement this character is currently doing. 
    /// This means losing the requested velocity or target destination.
    void stop();
    /// The current velocity (speed and direction) this character is traveling at.
    vec3<F32> getVelocity() const;
    /// The current speed this character is traveling at.
    D32 getSpeed()  const { return getVelocity().length(); }
    /// Returns true if this character is moving.
    bool isMoving() const  {return !_stopped || !IS_ZERO(getSpeed()); }

protected:
    /**
      * Update current position of this character to the current position of its agent.
    **/
    void updatePosition(const U64 deltaTime);
        /**
      * Set destination member variable directly without updating the agent state.
      * Usually you should call updateDestination() externally, unless you are controlling
      * the agents directly and need to update the corresponding character class to reflect
      * the change in state (see OgreRecastApplication friendship).
    **/
    void setDestination(const vec3<F32>& destination);

protected:
    friend class AITeam;
    void setTeamPtr(AITeam* const teamPtr);
    void processInput(const U64 deltaTime);
    void processData(const U64 deltaTime);
    void update(const U64 deltaTime);
    void init();

private:
    stringImpl            _name;
    AITeam*               _teamPtr;
    AISceneImpl*          _AISceneImpl;

    mutable SharedLock    _updateMutex;
    mutable SharedLock    _managerQueryMutex;

    typedef hashMapImpl<SensorType, Sensor*, hashAlg::hash<I32> > SensorMap;
    SensorMap               _sensorList;
    NPC*                    _unitRef;
    /// PathFinding
    /// ID of mAgent within the crowd.
    I32 _agentID;
    /// Crowd in which the agent of this character is.
    Navigation::DivideDtCrowd* _detourCrowd;
    /// The agent controlling this character.
    const dtCrowdAgent* _agent;
    PresetAgentRadius   _agentRadiusCategory;

    /**
      * The current destination set for this agent.
      * Take care in properly setting this variable, as it is only updated properly when
      * using Character::updateDestination() to set an individual destination for this character.
      * After updating the destination of all agents this variable should be set externally using
      * setDestination().
    **/
    vec3<F32> _destination;
    vec3<F32> _currentPosition;  
    vec3<F32> _currentVelocity;
    F32       _distanceToTarget;
    F32       _previousDistanceToTarget;
    U64       _moveWaitTimer;
    /// True if this character is stopped.
    bool _stopped;
};

    };//namespace AI
}; //namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/AI/Headers/AIEntity.h

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

319 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 21:37:57 +0000

[Ionut]
- Performance tweaks based on profiling data

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

316 Diff Diff IonutCava picture IonutCava Mon 25 Aug, 2014 22:04:03 +0000

[Ionut]
- Cleaned up AI classes
- Added basic Order <-> Goal system

315 Diff Diff IonutCava picture IonutCava Mon 25 Aug, 2014 15:23:33 +0000

[Ionut]
- Update ReCast to the latest version available on GitHub
- Improved nav mesh target point selection
- Added basic “go to enemy flag” logic for the WarScene teams

314 Diff Diff IonutCava picture IonutCava Sun 24 Aug, 2014 19:54:33 +0000

[Ionut]
- More AI work
- Added some needed audio dlls

312 Diff Diff IonutCava picture IonutCava Fri 22 Aug, 2014 22:46:19 +0000

[Ionut]
- Replaced AESOP with CPPGOAP (https://github.com/cpowell/cppgoap)
- Added a better interface to GOAP classes and objects via the AISceneImpl
- Actions, goals and orders basic infrastructure

311 IonutCava picture IonutCava Mon 18 Aug, 2014 21:40:52 +0000

[Ionut]
- Added a basic AESOP implementation
- Moved all AI related classes under the “AI” namespace