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
#include "Headers/AIManager.h"

#include "AI/ActionInterface/Headers/AITeam.h"
#include "AI/PathFinding/Headers/DivideRecast.h"

namespace Divide {

using namespace AI;

AIManager::AIManager() : _navMeshDebugDraw(false),
                         _pauseUpdate(true),
                         _updating(false),
                         _deltaTime(0ULL),
                         _currentTime(0ULL),
                         _previousTime(0ULL)
{
    Navigation::DivideRecast::createInstance();
}

AIManager::~AIManager() 
{
    Destroy();
}

///Clear up any remaining AIEntities
void AIManager::Destroy() {
    {
        WriteLock w_lock(_updateMutex);
		for (AITeamMap::value_type& entity : _aiTeams) {
            MemoryManager::DELETE( entity.second );
        }
        _aiTeams.clear();
    }
    {
        WriteLock w_lock(_navMeshMutex);
		for (NavMeshMap::value_type& it : _navMeshes) {
            MemoryManager::DELETE( it.second );
        }
        _navMeshes.clear();

        Navigation::DivideRecast::destroyInstance();
    }
}

void AIManager::update() {
    ///Lock the entities during update() adding or deleting entities is suspended until this returns
    ReadLock r_lock(_updateMutex);
    /// use internal delta time calculations
    _previousTime = _currentTime;
    _currentTime  = GETUSTIME();
    _deltaTime = _currentTime - _previousTime;
	if (_aiTeams.empty() || _pauseUpdate) {
		return; //nothing to do
	}
    _updating = true;
    if (_sceneCallback) {
        _sceneCallback();
    }
    r_lock.unlock();

    processInput(_deltaTime);  //sensors
    processData(_deltaTime);   //think
    updateEntities(_deltaTime);//react
    _updating = false;
    return;
}

void AIManager::signalInit() {
    ReadLock r_lock(_updateMutex);
	for (AITeamMap::value_type& team : _aiTeams) {
        team.second->init();
    }
}

void AIManager::processInput(const U64 deltaTime) {  //sensors
    ReadLock r_lock(_updateMutex);
	for (AITeamMap::value_type& team : _aiTeams) {
        team.second->processInput( deltaTime );
    }
}

void AIManager::processData(const U64 deltaTime) {   //think
    ReadLock r_lock(_updateMutex);
	for (AITeamMap::value_type& team : _aiTeams) {
        team.second->processData( deltaTime );
    }
}

void AIManager::updateEntities(const U64 deltaTime){//react
    ReadLock r_lock(_updateMutex);
	for (AITeamMap::value_type& team : _aiTeams) {
        team.second->update( deltaTime );
    }
}

bool AIManager::registerEntity(U32 teamId, AIEntity* entity) {
    WriteLock w_lock(_updateMutex);
    AITeamMap::const_iterator it = _aiTeams.find(teamId);
    DIVIDE_ASSERT(it != _aiTeams.end(), "AIManager error: attempt to register an AI Entity to a non-existent team!");
    it->second->addTeamMember(entity);
    return true;
}

void AIManager::unregisterEntity(AIEntity* entity) { 
	for (AITeamMap::value_type& team : _aiTeams) {
        unregisterEntity( team.second->getTeamID(), entity );
    }
}

void AIManager::unregisterEntity(U32 teamId, AIEntity* entity) {
    WriteLock w_lock(_updateMutex);
    AITeamMap::const_iterator it = _aiTeams.find(teamId);
    DIVIDE_ASSERT(it != _aiTeams.end(), "AIManager error: attempt to remove an AI Entity from a non-existent team!");
    it->second->removeTeamMember(entity);
}

bool AIManager::addNavMesh(AIEntity::PresetAgentRadius radius, Navigation::NavigationMesh* const navMesh) {
    WriteLock w_lock(_navMeshMutex);
    NavMeshMap::iterator it = _navMeshes.find(radius);
    DIVIDE_ASSERT(it == _navMeshes.end(), "AIManager error: NavMesh for specified dimensions already exists. Remove it first!");
    DIVIDE_ASSERT(navMesh != nullptr, "AIManager error: Invalid navmesh specified!");

    navMesh->debugDraw(_navMeshDebugDraw);
    hashAlg::emplace(_navMeshes, radius, navMesh);
    w_lock.unlock();

    WriteLock w_lock2(_updateMutex);
	for (AITeamMap::value_type& team : _aiTeams) {
        team.second->addCrowd( radius, navMesh );
    }

    return true;
}

void AIManager::destroyNavMesh(AIEntity::PresetAgentRadius radius) {
    WriteLock w_lock(_navMeshMutex);
    NavMeshMap::iterator it = _navMeshes.find(radius);
    DIVIDE_ASSERT(it != _navMeshes.end(), "AIManager error: Can't destroy NavMesh for specified radius (NavMesh not found)!");
    MemoryManager::DELETE( it->second );
    _navMeshes.erase(it);
    w_lock.unlock();
    
    WriteLock w_lock2(_updateMutex);
	for (AITeamMap::value_type& team : _aiTeams) {
        team.second->removeCrowd( radius );
    }
}

void AIManager::registerTeam(AITeam* const team) {
    WriteLock w_lock(_updateMutex);
    U32 teamID = team->getTeamID();
    DIVIDE_ASSERT(_aiTeams.find(teamID) == _aiTeams.end(), "AIManager error: attempt to double register an AI team!");

    hashAlg::insert(_aiTeams, hashAlg::makePair(teamID, team));
}

void AIManager::unregisterTeam(AITeam* const team) {
    WriteLock w_lock(_updateMutex);
    U32 teamID = team->getTeamID();
    AITeamMap::iterator it = _aiTeams.find(teamID);
    DIVIDE_ASSERT(it != _aiTeams.end(), "AIManager error: attempt to unregister an invalid AI team!");
    _aiTeams.erase(it);
}

void AIManager::toggleNavMeshDebugDraw(bool state) {
    WriteLock w_lock(_navMeshMutex);
	for (NavMeshMap::value_type& it : _navMeshes) {
        it.second->debugDraw( state );
    }

    _navMeshDebugDraw = state;
}

void AIManager::debugDraw(bool forceAll) {
    WriteLock w_lock(_navMeshMutex);
	for (NavMeshMap::value_type& it : _navMeshes) {
        it.second->update( _deltaTime );
        if ( forceAll || it.second->debugDraw() ) {
            it.second->render();
        }
    }
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Managers/AIManager.cpp

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)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

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)

320 Diff Diff IonutCava picture IonutCava Sun 31 Aug, 2014 21:45:33 +0000

[Ionut]
- More AI work (entity captures flag and returns it to base)

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

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

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