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

Large-scale engine refactor #58

Merged
merged 272 commits into from
Apr 5, 2023
Merged

Large-scale engine refactor #58

merged 272 commits into from
Apr 5, 2023

Conversation

xezno
Copy link
Member

@xezno xezno commented Apr 5, 2023

Description

This pull request implements a lot of large-scale engine changes that are part of #53, but does not include any network-specific code.

  • Mocha now compiles down to a library (Mocha.Host.lib). A root is then created by either Mocha or MochaDedicatedServer
  • Bindings are no longer global and are now bound to a Root instance. This is currently accessed as Global.NativeEngine (or just NativeEngine in most cases)
  • Native globals are now stored inside a Global namespace
  • Re-wrote the base walk controller to use Jolt physics for collision and clipping
  • Added C# -> C++ callbacks (Allow passing managed callbacks to native code through interop #44)
  • Added integer console variables
  • HandleMap now has functions for Remove, RemoveAt, and Find

API Changes

Callbacks

Managed -> Native Callbacks
To register a callback that can be called from C++:

var callbackId = CallbackDispatcher.RegisterCallback( () => Log.Trace( "Hello" ) );
// Then pass callbackId to a native method that accepts a callback

Just use ClientRoot to fetch these for now - most of the places where we're accessing these are gonna need refactoring so that we can have many game/server instances.
I think ISubSystems should have a Root parent, which you can use to access these variables rather than using GetInstance() everywhere
We don't want bindings to be "global" like they are now. Ideally we want to make it so that C# can use bindings based on whichever context / realm / etc. it's in, and we want to be able to spin up multiple clients & servers if necessary. So in order to do that, we're going to do class-specific bindings rather than the monolithic namespaced bindings we have now. This should hopefully also make things a little bit easier to manage.

Note that the engine won't run properly at the minute because I haven't updated anything to use these new bindings - they're still a work-in-progress.

I also want to do a few things in order to make bindings more powerful, as well as make bindings automatically translate from C++ types to interop-compatible C types - that'll probably be what I tackle next.
Will be replaced again later on, this just makes it easier to do so
might re-write interopgen later
peter-r-g and others added 27 commits March 13, 2023 11:02
# Conflicts:
#	Source/Mocha.FrameworkBench/Mocha.FrameworkBench.cpp
#	Source/Mocha.Host/Framework/handlemap.h
This refactors only the Framework version of the HandleMap, which isn't being used anywhere in the engine yet.
- Use std::vector as backing collection instead of std::unordered_map
- Remove HandleMap::Find(), HandleMap::RemoveAt()
- Speed things up significantly by returning const refs to unique_ptr instead of copying shared_ptrs
- Add operator[], Front(), and Back()

This provides a significant speedup - from ~7M lookups/s to ~16M/s. This still isn't as fast as using Mocha::Array (~181M/s) so there's still a lot of work that could be done here.
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