Skip to content

Commit a9a3aed

Browse files
committed
update engine
1 parent b2fd1a6 commit a9a3aed

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

externals/cage

Submodule cage updated 60 files

sources/simple/plagueRat.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
#include <atomic>
2+
13
#include <cage-core/assetsManager.h>
4+
#include <cage-core/concurrent.h>
25
#include <cage-core/entities.h>
36
#include <cage-core/hashString.h>
47
#include <cage-core/logger.h>
8+
#include <cage-core/tasks.h>
59
#include <cage-engine/highPerformanceGpuHint.h>
610
#include <cage-engine/scene.h>
711
#include <cage-engine/window.h>
@@ -12,6 +16,32 @@
1216
using namespace cage;
1317
constexpr uint32 AssetsName = HashString("cage-tests/plagueRat/rat.pack");
1418

19+
namespace
20+
{
21+
// simulate long-running task
22+
// if this task is scheduled in a thread that is waiting for its own subtasks, it will block it for long time
23+
// this could block graphics, which is very undesirable
24+
25+
std::atomic<int> tasksDone = 7;
26+
Holder<AsyncTask> task;
27+
28+
void taskRun(uint32)
29+
{
30+
CAGE_LOG(SeverityEnum::Info, "plague-rat", "wasteful task");
31+
threadSleep(1'000'000);
32+
tasksDone++;
33+
}
34+
35+
void engineUpdate()
36+
{
37+
if (tasksDone > 0)
38+
{
39+
tasksDone--;
40+
task = tasksRunAsync("waste", taskRun);
41+
}
42+
}
43+
}
44+
1545
int main(int argc, char *args[])
1646
{
1747
try
@@ -20,7 +50,7 @@ int main(int argc, char *args[])
2050
engineInitialize(EngineCreateConfig());
2151

2252
// events
23-
//const auto updateListener = controlThread().update.listen(&update);
53+
const auto updateListener = controlThread().update.listen(engineUpdate);
2454
const auto closeListener = engineWindow()->events.listen(inputFilter([](input::WindowClose) { engineStop(); }));
2555

2656
// window
@@ -55,7 +85,7 @@ int main(int argc, char *args[])
5585
{ // the rat
5686
Entity *e = ents->createAnonymous();
5787
e->value<TransformComponent>().position = Vec3(0, 0, 0);
58-
e->value<TransformComponent>().orientation = Quat({}, Degs(180), {});
88+
e->value<TransformComponent>().orientation = Quat({}, Degs(90), {});
5989
e->value<ModelComponent>().model = HashString("cage-tests/plagueRat/Rat.object");
6090
e->value<SkeletalAnimationComponent>().animation = HashString("cage-tests/plagueRat/Rat.glb?Rat_Walk");
6191
}

0 commit comments

Comments
 (0)