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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
#include "stdafx.h"

#include "Headers/WarScene.h"
#include "Headers/WarSceneAIProcessor.h"

#include "GUI/Headers/GUIMessageBox.h"
#include "Managers/Headers/SceneManager.h"
#include "Core/Headers/PlatformContext.h"
#include "Core/Time/Headers/ApplicationTimer.h"
#include "Dynamics/Entities/Units/Headers/NPC.h"

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

namespace Divide {

namespace {
    bool g_navMeshStarted = false;
};

void WarScene::printMessage(U8 eventId, const stringImpl& unitName) {
    stringImpl eventName = "";
    switch (eventId) {
        case 0: {
            eventName = "Captured flag";
        } break;
        case 1: {
            eventName = "Recovered flag";
        } break;
    };

    U32 elapsedTimeMinutes = (Time::MicrosecondsToSeconds<U32>(_elapsedGameTime) / 60) % 60;
    U32 elapsedTimeSeconds = Time::MicrosecondsToSeconds<U32>(_elapsedGameTime) % 60;

    Console::d_printfn(Util::StringFormat("[GAME TIME: %d:%d][%s]: %s", elapsedTimeMinutes, elapsedTimeSeconds, eventName.c_str(), unitName.c_str()).c_str());
}

void WarScene::checkGameCompletion() {
    bool restartGame = false;
    bool timeReason = false;
    if (AI::WarSceneAIProcessor::getScore(0) == _scoreLimit ||
        AI::WarSceneAIProcessor::getScore(1) == _scoreLimit) {
        _elapsedGameTime = 0;
        if (_scoreLimit == 3) {
            _scoreLimit = 5;
            _timeLimitMinutes = 8;
            restartGame = true;
        } else if (_scoreLimit == 5) {
            _scoreLimit = 20;
            _timeLimitMinutes = 30;
            restartGame = true;
        }
        else if (_scoreLimit == 20) {
            if (_runCount == 1) {
                _scoreLimit = 3;
                _timeLimitMinutes = 5;
                _runCount = 2;
                restartGame = true;
            } else if (_runCount == 2) {
                _context.app().RequestShutdown();
            }
        }
    }

    U32 elapsedTimeMinutes = (Time::MicrosecondsToSeconds<U32>(_elapsedGameTime) / 60) % 60;
    if (elapsedTimeMinutes >= _timeLimitMinutes) {
        timeReason = true;
        if (_timeLimitMinutes == 5) {
            _timeLimitMinutes = 8;
            _scoreLimit = 5;
        } else if (_timeLimitMinutes == 8) {
            _timeLimitMinutes = 30;
            _scoreLimit = 20;
        } else if (_timeLimitMinutes == 30) {
            if (_runCount == 1) {
                _timeLimitMinutes = 5;
                _scoreLimit = 3;
                _runCount = 2;
            }
            else if (_runCount == 2) {
                _context.app().RequestShutdown();
            }
        }
        restartGame = true;
    }

    if (restartGame) {
        _elapsedGameTime = 0;
        Console::d_printfn(Util::StringFormat("\n\nRESTARTING GAME!. Reason: %s \n\n", (timeReason ? "TIME" : "SCORE")).c_str());
        AI::WarSceneAIProcessor::resetScore(0);
        AI::WarSceneAIProcessor::resetScore(1);
        if (timeReason) {
            _resetUnits = true;
            for (U8 i = 0; i < 2; ++i) {
                PhysicsComponent* flagPComp = _flag[i].lock()->get<PhysicsComponent>();
                flagPComp->popTransforms();
                _flag[i].lock()->setParent(_sceneGraph->getRoot());
                flagPComp->setPosition(vec3<F32>(25.0f, 0.1f, i == 0 ? -206.0f : 206.0f));
            }
            AI::WarSceneAIProcessor::reset();
            AI::WarSceneAIProcessor::registerFlags(_flag[0].lock(), _flag[1].lock());
        }
    }
}

void WarScene::registerPoint(U16 teamID, const stringImpl& unitName) {
    if (!_resetUnits) {
        _resetUnits = true;

        for (U8 i = 0; i < 2; ++i) {
            PhysicsComponent* flagPComp = _flag[i].lock()->get<PhysicsComponent>();
            WAIT_FOR_CONDITION(!flagPComp->popTransforms());
            _flag[i].lock()->setParent(_sceneGraph->getRoot());
            flagPComp->setPosition(vec3<F32>(25.0f, 0.1f, i == 0 ? -206.0f : 206.0f));
        }
        AI::WarSceneAIProcessor::reset();
        AI::WarSceneAIProcessor::incrementScore(teamID);
        AI::WarSceneAIProcessor::registerFlags(_flag[0].lock(), _flag[1].lock());

        U32 elapsedTimeMinutes = (Time::MicrosecondsToSeconds<U32>(_elapsedGameTime) / 60) % 60;
        U32 elapsedTimeSeconds = Time::MicrosecondsToSeconds<U32>(_elapsedGameTime) % 60;
        Console::d_printfn(Util::StringFormat("[GAME TIME: %d:%d][TEAM %s REGISTER POINT]: %s", elapsedTimeMinutes, elapsedTimeSeconds, (teamID == 0 ? "A" : "B"), unitName.c_str()).c_str());
        checkGameCompletion();
    }
}

bool WarScene::initializeAI(bool continueOnErrors) {
    //------------------------Artificial Intelligence------------------------//
    // Create 2 AI teams
    for (U8 i = 0; i < 2; ++i) {
        _faction[i] = MemoryManager_NEW AI::AITeam(i, *_aiManager);
    }
    // Make the teams fight each other
    _faction[0]->addEnemyTeam(_faction[1]->getTeamID());
    _faction[1]->addEnemyTeam(_faction[0]->getTeamID());

    bool state = addUnits();
    if (state || continueOnErrors) {
        Scene::initializeAI(continueOnErrors);
    }

    _sceneGraph->findNode("Soldier1").lock()->setActive(false);
    _sceneGraph->findNode("Soldier2").lock()->setActive(false);
    _sceneGraph->findNode("Soldier3").lock()->setActive(false);

    return state;
}

bool WarScene::removeUnits(bool removeNodesOnCall) {
    WAIT_FOR_CONDITION(!_aiManager->updating());
    for (U8 i = 0; i < 2; ++i) {
        for (SceneGraphNode_wptr npc : _armyNPCs[i]) {
            _aiManager->unregisterEntity(npc.lock()->get<UnitComponent>()->getUnit<NPC>()->getAIEntity());
            _sceneGraph->removeNode(npc, removeNodesOnCall);
        }
        _armyNPCs[i].clear();
    }

    return true;
}

bool WarScene::addUnits() {
    using namespace AI;

    // Go near the enemy flag.
    // The enemy flag will never be at the home base, because that is a scoring condition
    WarSceneAction approachEnemyFlag(ActionType::APPROACH_ENEMY_FLAG, "ApproachEnemyFlag");
    approachEnemyFlag.setPrecondition(GOAPFact(Fact::NEAR_ENEMY_FLAG), GOAPValue(false));
    approachEnemyFlag.setEffect(GOAPFact(Fact::NEAR_ENEMY_FLAG), GOAPValue(true));
    approachEnemyFlag.setEffect(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(false));

    WarSceneAction protectFlagInBase(ActionType::APPROACH_ENEMY_FLAG, "ProtectFlagInBase");
    protectFlagInBase.setPrecondition(GOAPFact(Fact::NEAR_ENEMY_FLAG), GOAPValue(false));
    protectFlagInBase.setPrecondition(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(true));
    protectFlagInBase.setEffect(GOAPFact(Fact::NEAR_ENEMY_FLAG), GOAPValue(true));

    // Grab the enemy flag only if we do not already have it and if we are near it
    // The enemy flag will never be at the home base, because that is a scoring condition
    WarSceneAction captureEnemyFlag(ActionType::CAPTURE_ENEMY_FLAG, "CaptureEnemyFlag");
    captureEnemyFlag.setPrecondition(GOAPFact(Fact::NEAR_ENEMY_FLAG), GOAPValue(true));
    captureEnemyFlag.setPrecondition(GOAPFact(Fact::HAS_ENEMY_FLAG), GOAPValue(false));
    captureEnemyFlag.setPrecondition(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(false));
    captureEnemyFlag.setEffect(GOAPFact(Fact::HAS_ENEMY_FLAG), GOAPValue(true));

    // Kill the enemy flag carrier to recover our own flag and return it to base
    WarSceneAction recoverFlag(ActionType::RECOVER_FLAG, "RecoverFlag");
    recoverFlag.setPrecondition(GOAPFact(Fact::ENEMY_HAS_FLAG), GOAPValue(true));
    recoverFlag.setPrecondition(GOAPFact(Fact::ENEMY_DEAD), GOAPValue(true));
    recoverFlag.setEffect(GOAPFact(Fact::ENEMY_HAS_FLAG), GOAPValue(false));

    // A general purpose "go home" action
    WarSceneAction returnToBase(ActionType::RETURN_TO_BASE, "ReturnToBase");
    returnToBase.setPrecondition(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(false));
    returnToBase.setEffect(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(true));

    // We can only score if we and both flags are in the same base location
    WarSceneAction scoreEnemyFlag(ActionType::SCORE_FLAG, "ScoreEnemyFlag");
    scoreEnemyFlag.setPrecondition(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(true));
    scoreEnemyFlag.setPrecondition(GOAPFact(Fact::HAS_ENEMY_FLAG), GOAPValue(true));
    scoreEnemyFlag.setPrecondition(GOAPFact(Fact::ENEMY_HAS_FLAG), GOAPValue(false));
    scoreEnemyFlag.setEffect(GOAPFact(Fact::HAS_ENEMY_FLAG), GOAPValue(false));

    // Do nothing, but do nothing at home
    WarSceneAction idleAction(ActionType::IDLE, "Idle");
    idleAction.setPrecondition(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(true));
    idleAction.setEffect(GOAPFact(Fact::IDLING), GOAPFact(true));

    // Kill stuff in lack of a better occupation
    WarSceneAction attackAction(ActionType::ATTACK_ENEMY, "Attack");
    attackAction.setPrecondition(GOAPFact(Fact::ENEMY_DEAD), GOAPValue(false));
    attackAction.setEffect(GOAPFact(Fact::ENEMY_DEAD), GOAPValue(true));

    GOAPGoal recoverOwnFlag("Recover flag", to_base(WarSceneOrder::WarOrder::RECOVER_FLAG));
    recoverOwnFlag.setVariable(GOAPFact(Fact::ENEMY_HAS_FLAG), GOAPValue(false));
    
    GOAPGoal captureFlag("Capture enemy flag", to_base(WarSceneOrder::WarOrder::CAPTURE_ENEMY_FLAG));
    captureFlag.setVariable(GOAPFact(Fact::HAS_ENEMY_FLAG), GOAPValue(true));
    captureFlag.setVariable(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(true));

    GOAPGoal scoreFlag("Score", to_base(WarSceneOrder::WarOrder::SCORE_ENEMY_FLAG));
    scoreFlag.setVariable(GOAPFact(Fact::HAS_ENEMY_FLAG), GOAPValue(false));

    GOAPGoal idle("Idle", to_base(WarSceneOrder::WarOrder::IDLE));
    idle.setVariable(GOAPFact(Fact::IDLING), GOAPValue(true));

    GOAPGoal killEnemy("Kill", to_base(WarSceneOrder::WarOrder::KILL_ENEMY));
    killEnemy.setVariable(GOAPFact(Fact::ENEMY_DEAD), AI::GOAPValue(true));

    GOAPGoal protectFlagCarrier("Protect Flag Carrier", to_base(WarSceneOrder::WarOrder::PROTECT_FLAG_CARRIER));
    protectFlagCarrier.setVariable(GOAPFact(Fact::NEAR_ENEMY_FLAG), GOAPValue(true));

    std::array<GOAPPackage,  to_base(WarSceneAIProcessor::AIType::COUNT)> goapPackages;
    for (GOAPPackage& goapPackage : goapPackages) {
        goapPackage._worldState.setVariable(GOAPFact(Fact::AT_HOME_BASE), GOAPValue(true));
        goapPackage._worldState.setVariable(GOAPFact(Fact::ENEMY_DEAD), GOAPValue(false));
        goapPackage._worldState.setVariable(GOAPFact(Fact::ENEMY_HAS_FLAG), GOAPValue(false));
        goapPackage._worldState.setVariable(GOAPFact(Fact::HAS_ENEMY_FLAG), GOAPValue(false));
        goapPackage._worldState.setVariable(GOAPFact(Fact::IDLING), GOAPValue(true));
        goapPackage._worldState.setVariable(GOAPFact(Fact::NEAR_ENEMY_FLAG), GOAPValue(false));

        goapPackage._actionSet.push_back(idleAction);
        goapPackage._actionSet.push_back(attackAction);
        goapPackage._actionSet.push_back(recoverFlag);
        goapPackage._actionSet.push_back(protectFlagInBase);
        goapPackage._goalList.push_back(idle);
        goapPackage._goalList.push_back(killEnemy);
        goapPackage._goalList.push_back(recoverOwnFlag);
    }

    GOAPPackage& lightPackage = goapPackages[to_base(WarSceneAIProcessor::AIType::LIGHT)];
    GOAPPackage& heavyPackage = goapPackages[to_base(WarSceneAIProcessor::AIType::HEAVY)];

    heavyPackage._actionSet.push_back(approachEnemyFlag);
    heavyPackage._actionSet.push_back(captureEnemyFlag);
    heavyPackage._actionSet.push_back(returnToBase);
    heavyPackage._actionSet.push_back(scoreEnemyFlag);
    lightPackage._actionSet.push_back(approachEnemyFlag);

    heavyPackage._goalList.push_back(captureFlag);
    heavyPackage._goalList.push_back(scoreFlag);
    heavyPackage._goalList.push_back(protectFlagCarrier);
    lightPackage._goalList.push_back(protectFlagCarrier);

    SceneGraphNode_ptr lightNode(_sceneGraph->findNode("Soldier1").lock());
    SceneGraphNode_ptr animalNode(_sceneGraph->findNode("Soldier2").lock());
    SceneGraphNode_ptr heavyNode(_sceneGraph->findNode("Soldier3").lock());

    std::shared_ptr<SceneNode> lightNodeMesh = lightNode->getNode();
    std::shared_ptr<SceneNode> animalNodeMesh = animalNode->getNode();
    std::shared_ptr<SceneNode> heavyNodeMesh = heavyNode->getNode();
    assert(lightNodeMesh && animalNodeMesh && heavyNodeMesh);

    AIEntity* aiSoldier = nullptr;
    std::shared_ptr<SceneNode> currentMesh;

    vec3<F32> currentScale;
    stringImpl currentName;

    static const U32 normalMask = to_base(SGNComponent::ComponentType::NAVIGATION) |
                                  to_base(SGNComponent::ComponentType::PHYSICS) |
                                  to_base(SGNComponent::ComponentType::BOUNDS) |
                                  to_base(SGNComponent::ComponentType::RENDERING) |
                                  to_base(SGNComponent::ComponentType::UNIT) |
                                  to_base(SGNComponent::ComponentType::NETWORKING);

    SceneGraphNode& root = _sceneGraph->getRoot();
    for (I32 k = 0; k < 2; ++k) {
        for (I32 i = 0; i < 15; ++i) {

            F32 speed = Metric::Base(-1.0f);
            F32 acc = Metric::Base(-1.0f);

            F32 zFactor = 0.0f;
            I32 damage = 5;
            AI::WarSceneAIProcessor::AIType type;
            if (IS_IN_RANGE_INCLUSIVE(i, 0, 4)) {
                currentMesh = lightNodeMesh;
                currentScale =
                    lightNode->get<PhysicsComponent>()->getScale();
                currentName = Util::StringFormat("Soldier_1_%d_%d", k, i);
                speed = Metric::Base(Random(6.5f, 9.5f));
                acc = Metric::Base(Random(4.5f, 8.0f));
                type = AI::WarSceneAIProcessor::AIType::LIGHT;
            } else if (IS_IN_RANGE_INCLUSIVE(i, 5, 9)) {
                currentMesh = animalNodeMesh;
                currentScale =
                    animalNode->get<PhysicsComponent>()->getScale();
                currentName = Util::StringFormat("Soldier_2_%d_%d", k, i % 5);
                speed = Metric::Base(Random(8.5f, 11.5f));
                acc = Metric::Base(Random(6.0f, 9.0f));
                zFactor = 1.0f;
                type = AI::WarSceneAIProcessor::AIType::ANIMAL;
                damage = 10;
            } else {
                currentMesh = heavyNodeMesh;
                currentScale =
                    heavyNode->get<PhysicsComponent>()->getScale();
                currentName = Util::StringFormat("Soldier_3_%d_%d", k, i % 10);
                speed = Metric::Base(Random(4.5f, 7.5f));
                acc = Metric::Base(Random(4.0f, 6.5f));
                zFactor = 2.0f;
                type = AI::WarSceneAIProcessor::AIType::HEAVY;
                damage = 15;
            }

            SceneGraphNode_ptr currentNode = root.addNode(currentMesh, normalMask, PhysicsGroup::GROUP_KINEMATIC, currentName);
            currentNode->setSelectable(true);

            PhysicsComponent* pComp =
                currentNode->get<PhysicsComponent>();
            pComp->setScale(currentScale);

            if (k == 0) {
                zFactor *= -25;
                zFactor -= 200;
                pComp->translateX(Metric::Base(-25.0f));
            } else {
                zFactor *= 25;
                zFactor += 200;
                pComp->rotateY(Angle::DEGREES<F32>(180.0f));
                pComp->translateX(Metric::Base(100.0f));
                pComp->translateX(Metric::Base(25.0f));
            }

            pComp->setPosition(vec3<F32>(Metric::Base(-125.0f + 25 * (i % 5)),
                                         Metric::Base(-0.01f),
                                         Metric::Base(zFactor)));

            aiSoldier = MemoryManager_NEW AI::AIEntity(pComp->getPosition(),
                                                       currentNode->getName());
            aiSoldier->addSensor(AI::SensorType::VISUAL_SENSOR);
            currentNode->get<RenderingComponent>()->toggleRenderOption(RenderingComponent::RenderOptions::RENDER_BOUNDS_AABB, k == 0);
            currentNode->get<RenderingComponent>()->toggleRenderOption(RenderingComponent::RenderOptions::RENDER_SKELETON, k != 0);

            AI::WarSceneAIProcessor* brain = MemoryManager_NEW AI::WarSceneAIProcessor(type, *_aiManager);

            // GOAP
            brain->registerGOAPPackage(goapPackages[to_U32(type)]);
            aiSoldier->setAIProcessor(brain);
            std::shared_ptr<NPC> soldier = std::make_shared<NPC>(aiSoldier);
            soldier->setAttribute(to_base(AI::UnitAttributes::HEALTH_POINTS), 100);
            soldier->setAttribute(to_base(AI::UnitAttributes::DAMAGE), damage);
            soldier->setAttribute(to_base(AI::UnitAttributes::ALIVE_FLAG), 1);
            soldier->setMovementSpeed(speed);
            soldier->setAcceleration(acc);
            currentNode->get<UnitComponent>()->setUnit(soldier);
            _armyNPCs[k].push_back(currentNode);
            _aiManager->registerEntity(k, aiSoldier);
            
        }
    }

    //----------------------- AI controlled units ---------------------//
    return !(_armyNPCs[0].empty() || _armyNPCs[1].empty());
}

AI::AIEntity* WarScene::findAI(SceneGraphNode_ptr node) {
    I64 targetGUID = node->getGUID();

    for (U8 i = 0; i < 2; ++i) {
        for (SceneGraphNode_cwptr npc : _armyNPCs[i]) {
            if (npc.lock()->getGUID() == targetGUID) {
                return npc.lock()->get<UnitComponent>()->getUnit<NPC>()->getAIEntity();
            }
        }
    }

    return nullptr;
}

bool WarScene::resetUnits() {
    _aiManager->pauseUpdate(true);
    bool state = false;
    if (removeUnits(true)) {
       state = addUnits();
    }
    _aiManager->pauseUpdate(false);
    return state;
}

bool WarScene::deinitializeAI(bool continueOnErrors) {
    _aiManager->pauseUpdate(true);
    if (removeUnits(true)) {
        for (U8 i = 0; i < 2; ++i) {
            MemoryManager::DELETE(_faction[i]);
        }
        return Scene::deinitializeAI(continueOnErrors);
    }

    return false;
}

void WarScene::startSimulation(I64 btnGUID) {
    if (g_navMeshStarted) {
        return;
    }

    g_navMeshStarted = true;

    _aiManager->pauseUpdate(true);
    _infoBox->setTitle("NavMesh state");
    _infoBox->setMessageType(GUIMessageBox::MessageType::MESSAGE_INFO);
    bool previousMesh = false;
    bool loadedFromFile = true;
    U64 currentTime = Time::ElapsedMicroseconds(true);
    U64 diffTime = currentTime - _lastNavMeshBuildTime;

    AI::AIEntity* aiEntity = _armyNPCs[0][0].lock()->get<UnitComponent>()->getUnit<NPC>()->getAIEntity();
    if (_lastNavMeshBuildTime == 0UL ||
        diffTime > Time::SecondsToMicroseconds(10)) {
        AI::Navigation::NavigationMesh* navMesh = 
            _aiManager->getNavMesh(aiEntity->getAgentRadiusCategory());
        if (navMesh) {
            previousMesh = true;
            _aiManager->destroyNavMesh(aiEntity->getAgentRadiusCategory());
        }
        navMesh = MemoryManager_NEW AI::Navigation::NavigationMesh(_context);
        navMesh->setFileName(getName());

        if (!navMesh->load(_sceneGraph->getRoot())) {
            loadedFromFile = false;
            AI::AIEntity::PresetAgentRadius radius = aiEntity->getAgentRadiusCategory();
            navMesh->build(
                _sceneGraph->getRoot(),
                [&radius, this](AI::Navigation::NavigationMesh* navMesh) {
                _aiManager->toggleNavMeshDebugDraw(true);
                _aiManager->addNavMesh(radius, navMesh);
                g_navMeshStarted = false;
            });
        } else {
            _aiManager->addNavMesh(aiEntity->getAgentRadiusCategory(), navMesh);
            if (Config::Build::IS_DEBUG_BUILD) {
                navMesh->debugDraw(true);
            }

            renderState().enableOption(SceneRenderState::RenderOptions::RENDER_DEBUG_TARGET_LINES);
        }

        if (previousMesh) {
            if (loadedFromFile) {
                _infoBox->setMessage(
                    "Re-loaded the navigation mesh from file!");
            }
            else {
                _infoBox->setMessage(
                    "Re-building the navigation mesh in a background thread!");
            }
        }
        else {
            if (loadedFromFile) {
                _infoBox->setMessage("Navigation mesh loaded from file!");
            }
            else {
                _infoBox->setMessage(
                    "Navigation mesh building in a background thread!");
            }
        }
        //_infoBox->show();
        _lastNavMeshBuildTime = currentTime;
        for (U8 i = 0; i < 2; ++i) {
            _faction[i]->clearOrders();
            _faction[i]->addOrder(std::make_shared<AI::WarSceneOrder>(
                AI::WarSceneOrder::WarOrder::CAPTURE_ENEMY_FLAG));
            _faction[i]->addOrder(std::make_shared<AI::WarSceneOrder>(
                AI::WarSceneOrder::WarOrder::SCORE_ENEMY_FLAG));
            _faction[i]->addOrder(std::make_shared<AI::WarSceneOrder>(
                AI::WarSceneOrder::WarOrder::IDLE));
            _faction[i]->addOrder(std::make_shared<AI::WarSceneOrder>(
                AI::WarSceneOrder::WarOrder::KILL_ENEMY));
            _faction[i]->addOrder(std::make_shared<AI::WarSceneOrder>(
                AI::WarSceneOrder::WarOrder::PROTECT_FLAG_CARRIER));
            _faction[i]->addOrder(std::make_shared<AI::WarSceneOrder>(
                AI::WarSceneOrder::WarOrder::RECOVER_FLAG));
        }
    } else {
        stringImpl info(
            "Can't reload the navigation mesh this soon.\n Please wait \\[ ");
        info.append(
            to_stringImpl(Time::MicrosecondsToSeconds<I32>(diffTime)).c_str());
        info.append(" ] seconds more!");

        _infoBox->setMessage(info);
        _infoBox->setMessageType(GUIMessageBox::MessageType::MESSAGE_WARNING);
        _infoBox->show();
    }

    _aiManager->pauseUpdate(false);
}

};  // namespace Divide

Commits for Divide-Framework/trunk/Source Code/Scenes/WarScene/WarSceneAI.cpp

Diff revisions: vs.
Revision Author Commited Message
949 Diff Diff IonutCava picture IonutCava Thu 19 Oct, 2017 21:48:37 +0000

[Ionut]
- More command buffer refactoring

929 Diff Diff IonutCava picture IonutCava Sat 12 Aug, 2017 17:34:44 +0000

[Ionut]
- More work on finishing up new PushConstant / Command buffer rendering system:
— Everything compiles and runs but with graphical and performance issues

909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

890 Diff Diff IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

838 Diff Diff IonutCava picture IonutCava Mon 30 Jan, 2017 17:28:35 +0000

[IonutCava]
- Added a NetworkingComponent to SGNs
- Started cleaning up Client / Server architecture

818 Diff Diff IonutCava picture IonutCava Mon 16 Jan, 2017 17:23:20 +0000

[IonutCava]
- Units get their bound node setup by the SGN UnitComponent and not during creation
- Profile guided optimizations

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

815 IonutCava picture IonutCava Thu 12 Jan, 2017 23:33:01 +0000

[IonutCava]
- Fixed viewport alignment issue
- Added per-player RenderTargets (added index support to GFXRTPool)
- Initial implementation of per-player cameras
— Removed defaultCamera
— Scenes now use a baseCamera as a template for new player cameras