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
/*
   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_MANAGER_H_
#define _AI_MANAGER_G_

#include "AI/Headers/AIEntity.h"
#include "Scenes/Headers/SceneComponent.h"

namespace Divide {

class Scene;
class Task;
class TaskPool;

namespace GFX {
    class CommandBuffer;
}; //namespace GFX

namespace AI {

namespace Navigation {
    class NavigationMesh;
}; //namespace Navigation

class AIManager : public SceneComponent
{
  public:
    typedef hashMapImpl<U32, AITeam*> AITeamMap;
    typedef hashMapImpl<AIEntity::PresetAgentRadius,
                        Navigation::NavigationMesh*> NavMeshMap;

    explicit AIManager(Scene& parentScene, TaskPool& pool);
    ~AIManager();

    void initialize();
    /// Clear all AI related data (teams, entities, NavMeshes, etc);
    void destroy();
    /// Called at a fixed interval (preferably in a separate thread);
    void update(const U64 deltaTimeUS);
    /// Add an AI Entity to a specific team.
    /// Entities can be added to multiple teams. Caller is responsible for the
    /// lifetime of entity
    bool registerEntity(U32 teamID, AIEntity* entity);
    /// Remove an AI Entity from a specific teams. Entities can be added to multiple teams.
    /// Caller is responsible for the lifetime of entity
    void unregisterEntity(U32 teamID, AIEntity* entity);
    /// Remove an AI Entity from all teams. Entities can be added to multiple teams.
    /// Caller is responsible for the lifetime of entity
    void unregisterEntity(AIEntity* entity);
    inline AITeam* const getTeamByID(I32 AITeamID) {
        if (AITeamID != -1) {
            AITeamMap::const_iterator it = _aiTeams.find(AITeamID);
            if (it != std::end(_aiTeams)) {
                return it->second;
            }
        }
        return nullptr;
    }
    /// Add a NavMesh
    bool addNavMesh(AIEntity::PresetAgentRadius radius,
                    Navigation::NavigationMesh* const navMesh);
    Navigation::NavigationMesh* getNavMesh(
        AIEntity::PresetAgentRadius radius) const {
        NavMeshMap::const_iterator it = _navMeshes.find(radius);
        if (it != std::end(_navMeshes)) {
            return it->second;
        }
        return nullptr;
    }
    /// Remove a NavMesh
    void destroyNavMesh(AIEntity::PresetAgentRadius radius);

    inline void setSceneCallback(const DELEGATE_CBK<void>& callback) {
        WriteLock w_lock(_updateMutex);
        _sceneCallback = callback;
    }
    inline void pauseUpdate(bool state) { _pauseUpdate = state; }
    inline bool updatePaused() const { return _pauseUpdate; }
    inline bool updating() const { return _updating; }
    /// Handle any debug information rendering (nav meshes, AI paths, etc).
    /// Called by Scene::postRender after depth map preview call
    void debugDraw(GFX::CommandBuffer& bufferInOut, bool forceAll = true);
    inline bool isDebugDraw() const { return _navMeshDebugDraw; }
    /// Toggle debug draw for all NavMeshes
    void toggleNavMeshDebugDraw(bool state);
    inline bool navMeshDebugDraw() const { return _navMeshDebugDraw; }

    inline void stop() {
        _shouldStop = true;
    }

    inline bool running() const {
        return _running;
    }

  protected:
    friend class AITeam;
    /// Register an AI Team
    void registerTeam(AITeam* const team);
    /// Unregister an AI Team
    void unregisterTeam(AITeam* const team);

    bool shouldStop() const;

  private:
    bool processInput(const U64 deltaTimeUS);    ///< sensors
    bool processData(const U64 deltaTimeUS);     ///< think
    bool updateEntities(const U64 deltaTimeUS);  ///< react

  private:
    TaskPool& _parentPool;
    Task* _activeTask;
    U64 _deltaTimeUS, _currentTimeUS, _previousTimeUS;
    std::atomic<bool> _navMeshDebugDraw;
    std::atomic<bool> _pauseUpdate;
    std::atomic<bool> _updating;
    std::atomic<bool> _shouldStop;
    std::atomic<bool> _running;
    NavMeshMap _navMeshes;
    AITeamMap _aiTeams;
    mutable SharedLock _updateMutex;
    mutable SharedLock _navMeshMutex;
    DELEGATE_CBK<void> _sceneCallback;

};

};  // namespace AI
};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/AI/Headers/AIManager.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

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

[Ionut]
- Consistent naming between timing variables

933 Diff Diff IonutCava picture IonutCava Tue 15 Aug, 2017 00:02:05 +0000

[Ionut]
- CommandBuffer Part 2/3: code compiles and splash screen renders and application doesn’t crash (still has drawing issues)

878 Diff Diff IonutCava picture IonutCava Fri 17 Mar, 2017 17:16:21 +0000

[IonutCava]
- Change AIManager from a thread owning update system to the per-agent task system

842 Diff Diff IonutCava picture IonutCava Wed 01 Feb, 2017 17:25:15 +0000

[IonutCava]
- Start to implement scripting support via ChaiScript: http://chaiscript.com/
- Cleanup DELEGATE_CBK alias

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

[IonutCava]
- Update copyright notice

817 Diff Diff IonutCava picture IonutCava Sun 15 Jan, 2017 21:29:59 +0000

[IonutCava]
- Add a new Unit component to SGNs that holds NPC/Player/etc. objects
- Add support for multiple keyboard+mouse combos and joysticks and add mapping between these and players

777 Diff Diff IonutCava picture IonutCava Fri 07 Oct, 2016 16:14:48 +0000

[IonutCava]
- Continue to implement CommandBuffer / RenderPass / RenderSubPass system.
— Rendering artefacts are still present.

713 Diff Diff 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;

711 IonutCava picture IonutCava Mon 23 May, 2016 14:31:55 +0000

[IonutCava]
- More scene change fixes: pending tasks, GUI elements, etc
- Singleton removal: AIManager is a per-scene member instead of a global singleton now