Cogs.Core
ModelManager.h
1#pragma once
2
3#include <memory>
4#include <map>
5#include <queue>
6#include <thread>
7
8#include "ResourceManager.h"
9#include "DataFetcherManager.h"
10
11#include "Model.h"
12#include "Mesh.h"
13
14#include "IModelLoader.h"
15
16namespace Cogs
17{
18 class IGraphicsDevice;
19
20 namespace Core
21 {
25 class COGSCORE_DLL_API ModelManager : public ResourceManager<Model, ModelLoadInfo>
26 {
27 public:
29 ModelManager(Context * context);
30
33
44 ModelHandle loadModel(const StringView & resourceName, ResourceId resourceId, ModelLoadFlags flags);
45
46 void cancelModelLoad(ModelHandle handle);
47
49 void handleLoad(ModelLoadInfo * loadInfo) override;
50
51 void handleReload(ResourceHandleBase handle) override;
52
53 void processDeletion() override;
54
55 void handleDeletion(Model * model) override;
56
57 void destroyInternal(ResourceBase * resource) override;
58
59 protected:
60
61 void postProcessLoading() override final;
62
63 private:
64 std::thread::id main;
65
66 // Process a fetch data blob. Returns true if it was actually processed.
67 bool processFetchedItem(ILoadedModelLoader* loadedLoader, ModelLoadInfo* loadInfo, std::unique_ptr<FileContents> data);
68
69 std::unique_ptr<struct ModelManagerData> data;
70
71 struct FetchedItem {
72 std::unique_ptr<FileContents> data;
73 ModelLoadInfo* loadInfo = nullptr;
74 ILoadedModelLoader* loadedLoader = nullptr;
75 };
76
77 // Models that has been fetched, but has not yet had the loader run on it.
78 std::queue<FetchedItem> fetchedItems;
79
80 struct {
81 Cogs::Mutex lock;
82 std::map<size_t, DataFetcherManager::FetchId> map;
83 } fetchIds;
84
85
86 };
87 }
88}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Model manager responsible for loading, processing and lifetime for Model resources.
Definition: ModelManager.h:26
The generic resource manager provides a base implementation for specialized resource managers to buil...
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
ModelLoadFlags
Model loading flags. May be combined with resource loading flags.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Model resources define a template for a set of connected entities, with resources such as meshes,...
Definition: Model.h:56
Base class for engine resources.
Definition: ResourceBase.h:107
Resource handle base class handling reference counting of resources derived from ResourceBase.