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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
   Copyright (c) 2018 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"

struct dtCrowdAgent;

namespace Divide {

class SceneGraphNode;

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

namespace Attorney {
    class AIEntityAITeam;
};

/// Based on OgreCrowd.
class AIEntity : public GUIDWrapper {
    friend class Attorney::AIEntityAITeam;
   public:
    enum class PresetAgentRadius : U32 {
        AGENT_RADIUS_SMALL = 0,
        AGENT_RADIUS_MEDIUM = 1,
        AGENT_RADIUS_LARGE = 2,
        AGENT_RADIUS_EXTRA_LARGE = 3,
        COUNT
    };

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

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

    bool addSensor(SensorType type);
    bool setAIProcessor(AIProcessor* processor);

    void sendMessage(AIEntity& receiver, AIMsg msg, const AnyParam& msg_content);
    void receiveMessage(AIEntity& sender, AIMsg msg, const AnyParam& msg_content);
    void processMessage(AIEntity& sender, AIMsg msg, const AnyParam& 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.
    D64 getAgentHeight() const;
    /// The radius of the agent for this character.
    D64 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.
    D64 getMaxSpeed();
    /// The maximum acceleration this character has towards its maximum speed.
    /// This parameter is configured for the agent controlling this character.
    D64 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.
    D64 getSpeed() const { return getVelocity().length(); }
    /// Returns true if this character is moving.
    bool isMoving() const { return !_stopped || !IS_ZERO(getSpeed()); }

    stringImpl toString() const;

   protected:
    /**
      * Update current position of this character to the current position of its
    *agent.
    **/
    void updatePosition(const U64 deltaTimeUS);
    /**
  * 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:
    void setTeamPtr(AITeam* const teamPtr);
    bool processInput(const U64 deltaTimeUS);
    bool processData(const U64 deltaTimeUS);
    bool update(const U64 deltaTimeUS);

   private:
    stringImpl _name;
    AITeam* _teamPtr;
    AIProcessor* _processor;

    mutable SharedLock _updateMutex;
    mutable SharedLock _managerQueryMutex;

    typedef hashMapImpl<SensorType, Sensor*> 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 Attorney {
class AIEntityAITeam {
   private:
    static void setTeamPtr(AIEntity& entity, AITeam* const teamPtr) {
        entity.setTeamPtr(teamPtr);
    }
    static bool processInput(AIEntity& entity, const U64 deltaTimeUS) {
        return entity.processInput(deltaTimeUS);
    }
    static bool processData(AIEntity& entity, const U64 deltaTimeUS) {
        return entity.processData(deltaTimeUS);
    }
    static bool update(AIEntity& entity, const U64 deltaTimeUS) {
        return entity.update(deltaTimeUS);
    }
    friend class Divide::AI::AITeam;
};
};  // namespace Attorney
};  // namespace AI
};  // namespace Divide

#endif

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

Diff revisions: vs.
Revision Author Commited Message
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

993 Diff Diff IonutCava picture IonutCava Sun 10 Dec, 2017 20:07:57 +0000

[Ionut]
- Finished initial port of the old scene graph system to the new ECS based system.
- Finished converting 2 components to the new ECS system: Transform and RigidBody
- Fixed the “Deploy” build error with the CEGUI OpenGL renderer.
- Compilation now needs C++14 support (it’s sufficiently wide-spread now)

968 Diff Diff IonutCava picture IonutCava Tue 07 Nov, 2017 17:32:31 +0000

[Ionut]
- Consistent naming between timing variables

903 Diff Diff IonutCava picture IonutCava Sun 25 Jun, 2017 18:55:02 +0000

[IonutCava]
- Rework DebugInterface to be part of the PlatformContext and to allow adding of AntTweakBar elements via easy to use descriptors

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

740 Diff Diff IonutCava picture IonutCava Sat 25 Jun, 2016 17:09:50 +0000

[IonutCava]
- More scene changing related fixes
- GUIDWrapper is now a core feature instead of a utility

726 Diff Diff IonutCava picture IonutCava Fri 10 Jun, 2016 16:13:52 +0000

[IonutCava]
- More static analysis based corrections
- Added initial stub code for a command pool system for GenericDrawCommands

719 Diff Diff IonutCava picture IonutCava Fri 03 Jun, 2016 16:20:08 +0000

[IonutCava]
- More SceneManager – ScenePool splitting of responsibilities
- DefaultScene will be the first scene loaded by the application. If nothing is specified in XML, it will default to "DefaultScene"

713 IonutCava picture IonutCava Wed 25 May, 2016 15:43:38 +0000

[IonutCava]
- Removed all unique_ptr’s from the code with classic new/delete pairs. They were seriously not needed.
- Added the concept of SceneComponent to scene specific classes: aiManager, lightPool, sceneGraph, physicsInterface etc
— This allowed the removal of the global GET_ACTIVE_SCENEGRAPH call;