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
/*
   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_SCENE_IMPLEMENTATION_H_
#define _AI_SCENE_IMPLEMENTATION_H_

#include "GOAPInterface.h"
#include "AI/Headers/AIEntity.h"
#include "Core/Headers/cdigginsAny.h"

namespace Divide {
    class Texture;
    namespace AI {

enum AIMsg;
/// Provides a scene-level AI implementation
class AISceneImpl : private NonCopyable {
public:
    AISceneImpl() : _entity(nullptr),
                    _activeGoal(nullptr),
                    _currentStep(-1)
    {
    }

    virtual ~AISceneImpl() 
    {
        _goals.clear();
    }

    virtual void addEntityRef(AIEntity* entity) {
        if (entity) {
            _entity = entity;
        }
    }

    inline GOAPWorldState& worldState() { return _worldState; }
	inline const GOAPWorldState& worldStateConst() const { return _worldState; }

    /// Register a specific action.
    /// This only holds a reference to the action itself and does not create a local copy!
    virtual void registerAction(GOAPAction* const action) {
        _actionSet.push_back(action);
    }
    /// Register a specific action.
    /// This only holds a reference to the action itself and does not create a local copy!
    virtual void registerGoal(const GOAPGoal& goal) {
        _goals.push_back(goal);
    }

    virtual GOAPGoal* findGoal(const stringImpl& goalName) {
        vectorImpl<GOAPGoal >::iterator it;
        it = std::find_if(_goals.begin(), _goals.end(), 
                          [&goalName]( const GOAPGoal& goal )->bool {
                            return goal.getName().compare(goalName.c_str()) == 0; 
                          });

        if (it != _goals.end()) {
            return &(*it);
        }
    
        return nullptr;
    }

    inline const vectorImpl<GOAPGoal >& goalListConst() const { return _goals; }

protected:
    friend class AIEntity;
    inline vectorImpl<GOAPGoal >& goalList() { return _goals; }
    inline GOAPActionSet&  actionSetPtr() { return _actionSet; }

    inline void resetActiveGoals() {
        _activeGoals.clear();
        for (GOAPGoal& goal : goalList()) {
            goal.relevancy(0.0f);
            activateGoal(stringAlg::toBase(goal.getName()));
        }
    }
    /// Although we want the goal to be activated, 
    /// it might not be the most relevant in the current scene state
    inline bool activateGoal(const stringImpl& name) {
        GOAPGoal* goal = findGoal(name);
        if (goal != nullptr) {
            _activeGoals.push_back(goal);
        }
        return (goal != nullptr);
    }

    /// Get the most relevant goal and set it as active
    GOAPGoal* findRelevantGoal() {

        if (_activeGoals.empty()) {
            return nullptr;
        }

        std::sort(_activeGoals.begin(), _activeGoals.end(), 
                  [](GOAPGoal const* a, GOAPGoal const* b) {
                    return a->relevancy() < b->relevancy();
                  });

        _activeGoal = _activeGoals.back();
        _currentStep = -1;
        return _activeGoal;
    }

    bool popActiveGoal(GOAPGoal* goal) {
        if (goal == nullptr) {
            return false;
        }
        if (_activeGoals.empty()) {
            return false;
        }
        vectorImpl<GOAPGoal* >::iterator it;
        it = vectorAlg::find_if(_activeGoals.begin(), _activeGoals.end(),
                                [goal](GOAPGoal const* actGoal) { 
                                    return actGoal->getName().compare(goal->getName()) == 0; 
                                });

        if (it == _activeGoals.end()) {
            return false;
        }

        _activeGoals.erase(it);
        return true;
    }

    inline bool replanGoal() {
        if (_activeGoal != nullptr) {
            if (_activeGoal->plan(_worldState, _actionSet) ) {
                popActiveGoal(_activeGoal);
                advanceGoal();
                return true;
            }  else {
                invalidateCurrentPlan();
            }
        }
        return false;
    }

    inline bool advanceGoal() {
        if (_activeGoal == nullptr) {
            return false;
        }
        const GOAPPlan& plan = _activeGoal->getCurrentPlan();
        if (!plan.empty()) {
            _currentStep++;
            if (!performAction(getActiveAction())) {
                invalidateCurrentPlan();
                return false;
            }
            return true;
        }
        return false;
    }

	inline bool printPlan() {
		if (_activeGoal == nullptr) {
			return false;
		}
		const GOAPPlan& plan = _activeGoal->getCurrentPlan();
		for (const GOAPAction* action : plan) {
			if (!printActionStats(action)){
				return false;
			}
		}
		return true;
	}

    inline void invalidateCurrentPlan() { 
        _activeGoal = nullptr;   
        _currentStep = -1;
    }

    inline const GOAPAction* getActiveAction() const { 
        if (_activeGoal == nullptr) {
            return nullptr;
        }
        const GOAPPlan& plan = _activeGoal->getCurrentPlan();
        if (static_cast<U32>(_currentStep) >= plan.size()) {
            return nullptr;
        }
        return plan[_currentStep]; 
    }

    inline GOAPGoal* const getActiveGoal() { return _activeGoal; }

    virtual bool performActionStep(GOAPAction::operationsIterator step) = 0;
    virtual bool performAction(const GOAPAction* planStep) = 0;
	virtual bool printActionStats(const GOAPAction* planStep) const { return true;  }
    virtual void processData(const U64 deltaTime) = 0;
    virtual void processInput(const U64 deltaTime) = 0;
    virtual void update(const U64 deltaTime, NPC* unitRef = nullptr) = 0;
    virtual void processMessage(AIEntity* sender, AIMsg msg, const cdiggins::any& msg_content) = 0;
    virtual void init() = 0;

protected:
    AIEntity*  _entity;

private:
    I32 _currentStep;
    GOAPGoal* _activeGoal;
    GOAPActionSet   _actionSet;
    GOAPWorldState  _worldState;

    vectorImpl<GOAPGoal >  _goals;
    vectorImpl<GOAPGoal* > _activeGoals;
};

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

#endif

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

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)

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)

317 Diff Diff IonutCava picture IonutCava Tue 26 Aug, 2014 22:08:06 +0000

[Ionut]
- More AI Work

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

313 Diff Diff IonutCava picture IonutCava Sat 23 Aug, 2014 23:46:25 +0000

[Ionut]
- Added a messageBox gui element. Simple title/message hide/show System
- Added a working memory system to the WarSceneAISceneImpl class and a few memory facts for testing
- Reworked AI sensor system

312 IonutCava picture IonutCava Fri 22 Aug, 2014 22:46:19 +0000

[Ionut]
- Replaced AESOP with CPPGOAP (https://github.com/cpowell/cppgoap)
- Added a better interface to GOAP classes and objects via the AISceneImpl
- Actions, goals and orders basic infrastructure