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

Prefabs #16

Open
MasonRemaley opened this issue Jan 30, 2025 · 0 comments
Open

Prefabs #16

MasonRemaley opened this issue Jan 30, 2025 · 0 comments

Comments

@MasonRemaley
Copy link
Contributor

MasonRemaley commented Jan 30, 2025

There should be a way to load sets of entities from disk. Here's a way this could be done.

Sub Command buffers

cmds.addSubCmdBuf(self: *CmdBuf, sub: *CmdBuf)

Adds a sub command buffer by pointer to this command buffer. When reached its executed.

See vk for prior art, and whether this went well or poorly there.

(Maybe loosen restrictions on component value pointers on the cb while we're at it, if we allow this no reason to force those to be comptime.)

Support relative binding

Entity.reserveCmd & Entity.relativeCmd

The former reserves an entity on execute instead of on command issue. In the meantime it returns a relative reference (could be of a different type or not.) The latter gets the relative reference number without binding it.

This let's you run the same command buffer multiple times if it's fully relative.

We may also want track while creating whether a cb is relative or not, so we can assert that subcommand buffers are, or assert they are when we intend to reuse them.

Generate prefabs with code

You can now fill a command buffer with the instructions to generate a set of entities. It'll be very efficient to execute since most of the work is done and it's all passed by pointer. It's also self contained, it doesn't matter where the original data came from because it's all stored on the command buffer.

Parse sub command buffers

Now the user can set up parsing to read sub command buffers from disk. You will need to provide a list of components and what their names are for this to work, but this is probably desirable anyway--not everything should be supported necessarily.

You can also bake these to a binary format by just asserting the buffer is self contained and then saving its bytes to disk, if we have a way to map or preserve comp IDs.

We potentially could sort by alignment here if desired. Remember that we can bucket sort. Consider that we could even just store separate buffers per alignment in cmdbuf if we wanted, or segment a single one this way.

Patching components

Components will sometimes want to reference other components. When serialized they should probably reference eachother by name rather than number, or the files will be hard to work with. OTOH maybe you just make an editor in dear imgui or such for this sorta thing. Either way you're gonna have to have serialization code that replaces entity references with something else since de-serializing non exhaustive enums is probably kind of annoying? Or we could solve that problem.

Then when it's time to instantiate, we need another command, something like patch_entity that takes a byte offset into the most recently added component, reads the relative entity value there, and replaces it with an absolute one. Or we could have it call a function that does this but either way something along these lines. Make it easy to generate these commands automatically for most types.

Templating

We could also have patch commands for templating prefabs, but that's a bit too far in the future for me to envision exactly how it'd work right now.

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

1 participant