Cogs.Core
SwathPathMeshManager.h
1#pragma once
2
3#include "EntityDefinition.h"
4#include "Resources/Resources.h"
5#include "Services/TaskManager.h"
6#include "SwathPathChunks.h"
7
8#include "Foundation/ComponentModel/Component.h"
9
10#include <mutex>
11#include <atomic>
12#include <list>
13#include <map>
14#include <cstdint>
15#include <functional>
16
17namespace Cogs
18{
19 namespace Core
20 {
21 class Context;
22
23 namespace EchoSounder
24 {
25 class SwathPathChunks;
26
28 {
29 public:
30 typedef std::function<TaskFunction(MeshHandle&,uint32_t)> CreateBuildFunc;
31 typedef std::function<EntityPtr()> CreateEntity; // Runs in GUI thread, entities may be recycled.
32 typedef std::function<void(EntityPtr, uint32_t)> ActivateEntity; // Setup new or recycled entity for a fresh mesh.
33
35 {
36 SwathPathChunk chunk;
37 uint32_t index;
38 WeakEntityPtr entity;
39 bool dirty;
40 };
41
43 {
44 std::list<std::pair<EntityInfo, MeshHandle>> toBuild;
45 std::atomic<int> running = 0;
46 };
47
48 SwathPathMeshManager() { persistent.reset(new Persistent()); }
49
50 bool ready();
51
52 bool update(Context* context,
53 SwathPathChunks& chunks,
54 CreateBuildFunc& createBuildFunc,
55 CreateEntity & createEntity,
56 ActivateEntity & activateEntity);
57
58 void updateCurrent() { update_current = true; }
59 void clear() { handleClear = true; }
60
61
62 private:
63 std::map<uint32_t, EntityInfo> current;
64 bool handleClear = false;
65 uint32_t chunkGen = 0;
66 bool update_current = false;
67
68 std::map<uint32_t, EntityInfo> toDiscard;
69
70 std::shared_ptr<Persistent> persistent;
71 std::list<WeakEntityPtr> entityPool;
72
73 void discardEntity(WeakEntityPtr entity);
74
75 };
76 }
77 }
78}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
std::function< void()> TaskFunction
Type of task function used by the task manager.
Definition: TaskManager.h:38
std::shared_ptr< ComponentModel::Entity > EntityPtr
Smart pointer for Entity access.
Definition: EntityPtr.h:12
std::weak_ptr< ComponentModel::Entity > WeakEntityPtr
Weak Smart pointer for Entity access.
Definition: EntityPtr.h:18
Contains all Cogs related functionality.
Definition: FieldSetter.h:23