Skip to content

Introducing cleo modules - #101

Merged
x87 merged 14 commits into
cleolibrary:masterfrom
MiranDMC:Introducing_Cleo_Modules
Sep 30, 2023
Merged

x87 merged 14 commits into
cleolibrary:masterfrom
MiranDMC:Introducing_Cleo_Modules

Conversation

@MiranDMC

Copy link
Copy Markdown
Contributor

No description provided.

@MiranDMC MiranDMC closed this Sep 18, 2023
@MiranDMC MiranDMC reopened this Sep 18, 2023
Comment thread source/CModuleSystem.cpp Resolved
Comment thread source/cleo.cpp Resolved
Comment thread source/CScriptEngine.cpp Resolved
Comment thread source/CCustomOpcodeSystem.cpp Resolved
Comment thread source/CCustomOpcodeSystem.cpp Resolved
Comment thread source/CCustomOpcodeSystem.cpp Resolved
Comment thread source/CModuleSystem.cpp Resolved
Comment thread CHANGELOG.md Resolved
Comment thread source/CScriptEngine.cpp Resolved
Comment thread source/CScriptEngine.cpp Resolved
Figured out using plugin_sdk classes in project.
Comment thread source/CModuleSystem.cpp Resolved
@x87

x87 commented Sep 24, 2023 •

Copy link
Copy Markdown
Contributor

Another interesting idea would be to make hot reload for active modules. If you recompile the module you can "reload" it without restarting the game. This way you can continue testing the code.

Reload can be done either by watching file changes on disk (this is how CLEO Redux does it), or by having a global hotkey to reload modules at any time. Note that such hotkey may potentially conflict with existing scripts.

Thoughts?

@MiranDMC

MiranDMC commented Sep 24, 2023 •

Copy link
Copy Markdown
Contributor Author

I created "reload" function but how to make it working?
You need to update program base in all running scripts. Possible. You need to update all call stack records where addresses are modules. Still doable. What with scripts that current IP is currently inside the module?

@x87

x87 commented Sep 24, 2023 •

Copy link
Copy Markdown
Contributor

Alright, I was thinking about a simple case where the script just sits idle in the main scope. If the script is currently running in the module scope, doing hot reload could be problematic.

@x87

x87 commented Sep 24, 2023

Copy link
Copy Markdown
Contributor

We can have a usage counter for modules. Increment by 1 in cleo_call, decrement by 1 on cleo_return or script terminate. Then reload only modules which counter is 0

@MiranDMC

Copy link
Copy Markdown
Contributor Author

We can have a usage counter for modules. Increment by 1 in cleo_call, decrement by 1 on cleo_return or script terminate. Then reload only modules which counter is 0

Implemented. How you want to trigger this?

Comment thread source/CModuleSystem.cpp
{
// query files once a second
for(size_t i = 0; i < 100 && updateActive; i++)
std::this_thread::sleep_for(std::chrono::milliseconds(10));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why don't we sleep for 1000 ms once instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It won't check for updateActive active then, which will result in 1s delay for each module destructor call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess it's fine? 1s to switch between compiler & game window. CLEO Redux uses 1s sleep

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

also it could be a better idea to use some well tested library. https://github.com/SpartanJ/efsw https://github.com/ThomasMonkman/filewatch

I had look at the library you linked earlier, but having global watcher sounded problematic in terms of threads synchronization etc.
Module would need it's thread to load the file anyway. Std:: is "well tested" library too. Threads and file system features provided by newer cpp versions are cross platform too.

@x87
x87 merged commit 98a4911 into cleolibrary:master Sep 30, 2023
@x87

x87 commented Sep 30, 2023

Copy link
Copy Markdown
Contributor

Thanks a lot for your help!

@x87 x87 mentioned this pull request Jul 27, 2026
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