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
/*
   Copyright (c) 2017 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_TEAM_H_
#define _AI_TEAM_H_

#include "AI/Headers/AIEntity.h"

namespace Divide {

class TaskPool;

namespace AI {

class AIManager;

namespace Navigation {
    class DivideDtCrowd;
    class NavigationMesh;
};

class Order {
   public:
    Order(U32 id) : _id(id), _locked(false) {}
    inline U32 getID() const { return _id; }
    inline bool locked() const { return _locked; }
    virtual void lock() { _locked = true; }
    virtual void unlock() { _locked = false; }

   protected:
    U32 _id;
    bool _locked;
};

class AITeam : public GUIDWrapper {
   public:
    typedef Navigation::DivideDtCrowd* CrowdPtr;
    typedef hashMapImpl<AIEntity::PresetAgentRadius, CrowdPtr> AITeamCrowd;
    typedef hashMapImpl<AIEntity*, F32> MemberVariable;
    typedef hashMapImpl<I64, AIEntity*> TeamMap;
    typedef std::shared_ptr<Order> OrderPtr;
    typedef vectorImpl<OrderPtr> OrderList;
   public:
    AITeam(U32 id, AIManager& parentManager);
    ~AITeam();

    inline CrowdPtr const getCrowd(AIEntity::PresetAgentRadius radius) const {
        ReadLock r_lock(_crowdMutex);
        AITeamCrowd::const_iterator it = _aiTeamCrowd.find(radius);
        if (it != std::end(_aiTeamCrowd)) {
            return it->second;
        }
        return nullptr;
    }

    bool addTeamMember(AIEntity* entity);
    bool removeTeamMember(AIEntity* entity);
    bool addEnemyTeam(U32 enemyTeamID);
    bool removeEnemyTeam(U32 enemyTeamID);

    inline void setTeamID(U32 value) { _teamID = value; }
    inline U32  getTeamID() const { return _teamID; }
    inline I32  getEnemyTeamID(U32 index) const {
        if (_enemyTeams.size() <= index) {
            return -1;
        }
        return _enemyTeams[index];
    }

    inline const TeamMap& getTeamMembers() const { return _team; }
    inline MemberVariable& getMemberVariable() { return _memberVariable; }

    inline void clearOrders() {
        WriteLock w_lock(_orderMutex);
        _orders.clear();
    }

    inline void addOrder(const OrderPtr& order) {
        WriteLock w_lock(_orderMutex);
        if (findOrder(order->getID()) == std::end(_orders)) {
            _orders.push_back(order);
        }
    }

    inline void removeOrder(const Order& order) {
        WriteLock w_lock(_orderMutex);
        OrderList::iterator it = findOrder(order);
        if (it != std::end(_orders)) {
            _orders.erase(it);
        }
    }

    const OrderList& requestOrders() const { return _orders; }

   protected:
    friend class AIManager;
    /// Update the crowding system
    void resetCrowd();
    bool processInput(TaskPool& parentPool, const U64 deltaTime);
    bool processData(TaskPool& parentPool, const U64 deltaTime);
    bool update(TaskPool& parentPool, const U64 deltaTime);
    void addCrowd(AIEntity::PresetAgentRadius radius,
                  Navigation::NavigationMesh* crowd);
    void removeCrowd(AIEntity::PresetAgentRadius radius);

   protected:
    vectorImpl<AIEntity*> getEntityList() const;

    inline OrderList::iterator findOrder(const Order& order) {
        return findOrder(order.getID());
    }

    inline OrderList::iterator findOrder(U32 orderID) {
        return vectorAlg::find_if(
            std::begin(_orders), 
            std::end(_orders),
            [&orderID](const OrderPtr& order) -> bool {
                return orderID == order->getID();
            });
    }

    inline vectorImpl<U32>::iterator findEnemyTeamEntry(U32 enemyTeamID) {
        return vectorAlg::find_if(
            std::begin(_enemyTeams), std::end(_enemyTeams),
            [&enemyTeamID](U32 id) -> bool { return id == enemyTeamID; });
    }

   protected:
    mutable SharedLock _orderMutex;

   private:
    U32 _teamID;
    TeamMap _team;
    AI::AIManager& _parentManager;
    /// Container with data per team member. For example a map of distances
    MemberVariable _memberVariable;
    AITeamCrowd _aiTeamCrowd;
    mutable SharedLock _updateMutex;
    mutable SharedLock _crowdMutex;
    vectorImpl<U32> _enemyTeams;
    OrderList _orders;
};

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

#endif

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

Diff revisions: vs.
Revision Author Commited Message
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

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

[IonutCava]
- Update copyright notice

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

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

458 Diff Diff IonutCava picture IonutCava Tue 02 Jun, 2015 16:26:18 +0000

[Ionut]
- More Linux port work

434 Diff Diff IonutCava picture IonutCava Wed 13 May, 2015 22:26:29 +0000

[Ionut]
- Simplified SceneGraph/SceneGraphNode classes:
— RAII style. Dropped load/unload
— SGN deletion callbacks are tracked by ID
— Better node deletion System
- Better scoring system with manual override:
— Key 1 adds a point to team A
— Key 2 adds a point to team B
- Safer scene pointer management in SceneManager

423 Diff Diff IonutCava picture IonutCava Wed 06 May, 2015 15:45:24 +0000

[Ionut]
- WarScene AI work

421 Diff Diff IonutCava picture IonutCava Tue 05 May, 2015 16:19:01 +0000

[Ionut]
- More WarScene AI work

389 Diff Diff IonutCava picture IonutCava Thu 26 Mar, 2015 17:14:11 +0000

[Ionut]
- More rendering pipeline refactoring:
— Implemented temporary hack of binding a subrange of the nodebuffer to avoid using gl_BaseInstanceARB and just use gl_DrawIDARB for indexing data (works fine)
— Matrix data is only generated if we got valid rendering commands from a certain node
- Moved all *Attorney classes to an Attorney namespace
- Fixed a bug with caching uniform values in glShaderProgram
- Added some robustness checks to glUniformBuffer

366 IonutCava picture IonutCava Tue 10 Mar, 2015 16:56:30 +0000

[Ionut]
- More type safe enum replacement