Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean(): Pass AmethystRuntime to Initialize function #23

Closed
ATXLtheAxolotl opened this issue Jan 4, 2024 · 2 comments
Closed

clean(): Pass AmethystRuntime to Initialize function #23

ATXLtheAxolotl opened this issue Jan 4, 2024 · 2 comments

Comments

@ATXLtheAxolotl
Copy link
Contributor

ATXLtheAxolotl commented Jan 4, 2024

About

Pass down an AmethystRuntime instance or some other "Manager" to the Initialize() function.

extern "C" __declspec(dllexport) void Initialize(AmethystRuntime* runtime) {
    runtime->inputManager;
    runtime->gameVersion;
};

Why?

Every time a change is made in Amethyst’s function parameters all mods break. While the community is small for now, hopefully it wont be in the future. If this is the case, it would be best to reduce future technical debt whenever we make a change to parameters so that mod developers don’t have to constantly make changes.

To go even further

Additionally, I personally think having so many
extern "C" __declspec(dllexport) at the beginning of functions is a bit ugly. Perhaps we could allow people to register it themselves.

For example we could make recreate something similar to the C# delegate pattern (not sure if that is something C++ will allow, I haven’t really looked into it) or just continue with the observer pattern we currently have.

extern "C" __declspec(dllexport) void Initialize(AmethystRuntime* runtime) {
    runtime->events->RegisterInputs += RegisterInputs;
};

void RegisterInputs(InputManager * inputManager) {
    inputManager->RegisterInput("f3", 0x72); 
}

Post Scriptum

Btw this was written on mobile so forgive any typos (and I didn’t proof read this)

@FrederoxDev
Copy link
Owner

FrederoxDev commented Jan 4, 2024

I agree with eventually trying to move a system that is more type-safe for mod function parameters, although I don't know exactly how I would want to do that.

I think the problem with the system proposed above is that now amethyst kind of has two stages before and after debugger, the RegisterInputs mod function is called before a debugger is able to be attached to the game.

Because we can't attach a debugger (because it's too slow), it could make developing using that approach hard to debug. We could also split this into two, but I'd rather have one consistent pattern then having two different ones

The extern "C" __declspec(dllexport) can be shortened down using a macro like #define ModFunction extern "C" __declspec(dllexport). Which results in being able to do the following syntax ModFunction void RegisterInputs()

@FrederoxDev
Copy link
Owner

I'm going to close this issue for now, I think this is something we are going to come back to in the future when amethyst starts to store more of the Minecraft state

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

No branches or pull requests

2 participants