Plasma Engine  2.0
Loading...
Searching...
No Matches
AssetProcessor.h
1#pragma once
2
3#include <EditorFramework/EditorFrameworkDLL.h>
4#include <EditorFramework/IPC/EditorProcessCommunicationChannel.h>
5#include <Foundation/Configuration/Singleton.h>
6#include <Foundation/Logging/Log.h>
7#include <Foundation/Logging/LogEntry.h>
8#include <Foundation/Threading/AtomicInteger.h>
9#include <Foundation/Threading/TaskSystem.h>
10#include <Foundation/Threading/Thread.h>
11#include <Foundation/Types/UniquePtr.h>
12#include <ToolsFoundation/FileSystem/DataDirPath.h>
13#include <atomic>
14
16class plTask;
17struct plAssetInfo;
18
21{
22public:
23 virtual void HandleLogMessage(const plLoggingEventData& le) override;
24 void AddLogWriter(plLoggingEvent::Handler handler);
25 void RemoveLogWriter(plLoggingEvent::Handler handler);
26
27 plLoggingEvent m_LoggingEvent;
28};
29
31{
32 enum class Type
33 {
34 ProcessTaskStateChanged
35 };
36
37 Type m_Type;
38};
39
40
42{
43public:
45 : plThread("plProcessThread")
46 {
47 }
48
49
50 virtual plUInt32 Run() override;
51};
52
54{
55public:
56 enum class State
57 {
58 LookingForWork,
59 WaitingForConnection,
60 Ready,
61 Processing,
62 ReportResult
63 };
64
65public:
68
69 plUInt32 m_uiProcessorID;
70
71 bool Tick(bool bStartNewWork); // returns false, if all processing is done, otherwise call Tick again.
72
73 bool IsConnected();
74
75 bool HasProcessCrashed();
76
77 plResult StartProcess();
78
79 void ShutdownProcess();
80
81private:
82 void EventHandlerIPC(const plProcessCommunicationChannel::Event& e);
83
84 bool GetNextAssetToProcess(plAssetInfo* pInfo, plUuid& out_guid, plDataDirPath& out_path);
85 bool GetNextAssetToProcess(plUuid& out_guid, plDataDirPath& out_path);
86 void OnProcessCrashed(plStringView message);
87
88
89 State m_State = State::LookingForWork;
90 plUuid m_AssetGuid;
91 plUInt64 m_uiAssetHash = 0;
92 plUInt64 m_uiThumbHash = 0;
93 plDataDirPath m_AssetPath;
95 bool m_bProcessShouldBeRunning = false;
96 plTransformStatus m_Status;
97 plDynamicArray<plLogEntry> m_LogEntries;
98 plDynamicArray<plString> m_TransitiveHull;
99};
100
103class PL_EDITORFRAMEWORK_DLL plAssetProcessor
104{
105 PL_DECLARE_SINGLETON(plAssetProcessor);
106
107public:
108 enum class ProcessTaskState : plUInt8
109 {
110 Stopped,
111 Running,
112 Stopping,
113 };
114
117
118 void StartProcessTask();
119 void StopProcessTask(bool bForce);
120 ProcessTaskState GetProcessTaskState() const
121 {
122 return m_ProcessTaskState;
123 }
124
125 void AddLogWriter(plLoggingEvent::Handler handler);
126 void RemoveLogWriter(plLoggingEvent::Handler handler);
127
128public:
129 // Can be called from worker threads!
131
132private:
133 friend class plProcessTask;
134 friend class plProcessThread;
135 friend class plAssetCurator;
136
137 void Run();
138
139private:
140 plAssetProcessorLog m_CuratorLog;
141
142 // Process thread and its state
144 std::atomic<bool> m_bForceStop = false;
145
146 // Locks writes to m_ProcessTaskState to make sure the state machine does not go from running to stopped before having fired stopping.
147 mutable plMutex m_ProcessorMutex;
148 std::atomic<ProcessTaskState> m_ProcessTaskState = ProcessTaskState::Stopped;
149
150 // Data owned by the process thread.
151 plDynamicArray<plProcessTask> m_ProcessTasks;
152};
Definition AssetCurator.h:139
Background asset processing is handled by this class. Creates EditorProcessor processes.
Definition AssetProcessor.h:104
ProcessTaskState
Definition AssetProcessor.h:109
Log for all background processing results.
Definition AssetProcessor.h:21
virtual void HandleLogMessage(const plLoggingEventData &le) override
Override this function to handle logging events.
Definition AssetProcessor.cpp:46
A reference to a file or folder inside a data directory.
Definition DataDirPath.h:18
Definition DynamicArray.h:81
Definition EditorProcessCommunicationChannel.h:13
plDelegate< void(const plLoggingEventData &)> Handler
Definition Event.h:45
Base class for all logging classes.
Definition Log.h:77
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Definition AssetProcessor.h:54
Definition AssetProcessor.h:42
virtual plUInt32 Run() override
The run function can be used to implement a long running task in a thread in a platform independent w...
Definition AssetProcessor.cpp:528
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Base class for custom tasks.
Definition Task.h:10
This class is the base class for platform independent long running threads.
Definition Thread.h:40
plThread(plStringView sName="plThread", plUInt32 uiStackSize=128 *1024)
Initializes the runnable class.
Definition Thread.cpp:15
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
Definition AssetCurator.h:122
Definition AssetCurator.h:62
Definition AssetProcessor.h:31
A generic delegate class which supports static functions and member functions.
Definition Delegate.h:76
The data that is sent through plLogInterface.
Definition Log.h:50
Definition ProcessCommunicationChannel.h:33
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition Declarations.h:114