Skip to content

Separate thread module loading#270

Open
getcetc wants to merge 3 commits intocortex-command-community:developmentfrom
getcetc:separate-thread-module-loading
Open

Separate thread module loading#270
getcetc wants to merge 3 commits intocortex-command-community:developmentfrom
getcetc:separate-thread-module-loading

Conversation

@getcetc
Copy link
Contributor

@getcetc getcetc commented Feb 10, 2026

The module loading work is now done in a worker thread.

This speeds up loading progress printout, if enabled. The is done by the worker thread only pushing the printout strings, while the main thread consumes and draws them out.

By consuming SDL events on the main thread, this:

  • Makes the window not hang and go white after a few seconds during game launch. This popped an app-frozen error before.
  • Allows for premature exiting via Alt+F4 or pressing the close button on the window.

This also sets up for future module loading multithreading work.
Asserts from worker thread work OK, but caution is to be taken on further MT work. Some scaffolding has been built for it.

Also implemented is a spinlock watchdog thread, asserting with useful info.

Copy link
Contributor

@HeliumAnt HeliumAnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!
also linux/macos fixes needed

/// Inclusions of header files
#include "Entity.h"
#include "Singleton.h"
#include "shader.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forward declare class Shader instead. And #include "Shader.h" in cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

reader >> ClassName;
pClass = Entity::ClassInfo::GetClass(ClassName);
if (ClassName == "Shader") {
int a = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

???? (though if you really need this empty check to happen use (void); instead)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh this was to set a breakpoint on it 😅

while (1) {
mainThreadHeartbeat++;
PollSDLEventsCallback();
if (true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the if (true). you can just make a code block, that's still local scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very non-production PR from me, sorry! This and other things i intended not to have left in. Will fix up, thank you for great feedback!

} else if (spinlockDetected) {
spinlockDetected = false;
SpinlockAssert(toDoProgressPrintOut, loadingDone);
RTEAssert(false, to_string(mainThreadHeartbeat))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw we have RTEAbort for this usecase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learn more things 🙂
Will use!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants