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

#include "core.h"
#include "AI/Headers/AIEntity.h"
#include "AI/PathFinding/NavMeshes/Headers/NavMesh.h"

namespace Divide {

namespace AI {
DEFINE_SINGLETON(AIManager)
public:
    typedef hashMapImpl<U32, AITeam*> AITeamMap;
    typedef hashMapImpl<AIEntity::PresetAgentRadius, Navigation::NavigationMesh*, hashAlg::hash<I32> > NavMeshMap;

    /// Clear all AI related data (teams, entities, NavMeshes, etc);
    void Destroy();
    /// Called at a fixed interval (preferably in a separate thread);
    void update();
    /// 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 != _aiTeams.end()) {
                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 != _navMeshes.end()) {
            return it->second;
        }
        return nullptr;
    }
    ///Remove a NavMesh
    void destroyNavMesh(AIEntity::PresetAgentRadius radius);

    inline void setSceneCallback(const DELEGATE_CBK<>& 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(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; }

   
protected:
    AIManager();
    ~AIManager();

protected:
    friend class Scene;
    void signalInit();

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

private:
    void processInput(const U64 deltaTime);  ///< sensors
    void processData(const U64 deltaTime);   ///< think
    void updateEntities(const U64 deltaTime);///< react

private:
    U64 _deltaTime,_currentTime, _previousTime;
    std::atomic<bool> _navMeshDebugDraw;
    std::atomic<bool> _pauseUpdate;
    std::atomic<bool> _updating;
    NavMeshMap      _navMeshes;
    AITeamMap       _aiTeams;
    mutable SharedLock _updateMutex;
    mutable SharedLock _navMeshMutex;
	DELEGATE_CBK<>     _sceneCallback;

END_SINGLETON

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

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

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

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

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

311 Diff Diff 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

310 Diff Diff IonutCava picture IonutCava Sun 17 Aug, 2014 23:31:04 +0000

[Ionut]
- Some cleanups in AI related classes

304 Diff Diff IonutCava picture IonutCava Sun 10 Aug, 2014 21:10:54 +0000

[Ionut]
- Redesigned the WorldEditor (dummy functions added for every button/option)
- Improved debug rendering performance by using static IMPrimitives for axis gizmo rendering
- Simplified skeleton rendering

255 k1ngp1n picture k1ngp1n Thu 10 Apr, 2014 16:13:23 +0000

[Ionut] [[BR]]
- Added AESOP library http://code.google.com/p/aesop-open-planner/ [[BR]]
- Performance optimizations: [[BR]]
— Update animations only for visible nodes (must handle special cases when nodes are just outside the frustum) [[BR]]
— Compile shaders only for the current stage when the material is requested (as opposed to compiling shaders for all the rendering stages when first accessing the material)[[BR]]
- Renamed Coordination to AITeam [[BR]]