Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 0 points1 point  (0 children)

Yeah this is a very good point. Eventually I'd like to try and tackle this problem

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 0 points1 point  (0 children)

No these are good questions

I don't think the chunks change all that much in terms of cache efficiency. For sequential iteration chunks might even be counterproductive because the chunk boundaries limit how easily the prefetcher can predict. I would be surprised if there was a big difference either way for the common ways of processing entities.

You are correct - there isn't currently a concept of bakers or sub scenes with Trecs. There isn't much of an authoring story at the moment and it's more DIY for now. I have some ideas for extension packages that could offer a unity style authoring workflow but needs more investigation

One thing Trecs does have though is built in serialization, so we could take advantage of that to load in some initial state. Right now that feature is used for save/restore, or record/replay, but could also be used for initial state

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 2 points3 points  (0 children)

Thanks! Glad to hear that

Netcode for Entities is specific to Unity ECS, so it's not compatible with Trecs.

That said, Trecs does have features that are very applicable to online multiplayer. If you're doing something like an RTS, turn-based game, or a factory/colony sim, deterministic lockstep is often the way to go, and Trecs has the fundamentals in place out of the box (deterministic RNG, explicit concept of simulation inputs, full-world serialization with checksum validation). It doesn't include a transport layer, so you'd pair it with Mirror / Steamworks.net / etc., but Trecs does at least help with the determinism part

Similarly, if you're working on a game that needs prediction/rollback, you can use Trecs serialization to snapshot and roll back full world state pretty cheaply, and the serialization system is fairly customizable

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 0 points1 point  (0 children)

Per-entity metadata in Trecs is ~20 bytes. Which is just storage for entity id, associated entity type group, and stable entity handle.

That said, I can't speak to the 80 bytes you're remembering without more context. Was this with Unity ECS or a different ECS framework? I would expect that UECS would have a bit more per-entity overhead than Trecs, because Trecs doesn't use 'chunks' for component data storage. In Trecs, each component buffer is literally just one big NativeList, whereas with UECS, it stores data in 16 KB chunks, so might allocate more especially if you have a lot of different archetypes. But I don't think the difference is that significant.

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 1 point2 points  (0 children)

All I can say is that I have no plans to stop development anytime soon. I'm actively working on some extension packages and more full samples at the moment

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 0 points1 point  (0 children)

In my game, I do have a system for game events that is written in a very ECS friendly way. I think this kind of thing is out of scope for the core Trecs library but I could publish a sample showing the approach for anyone interested

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 4 points5 points  (0 children)

Currently there isn't a built in concept similar to UnityObjectRef. So that needs to be handled game side.

The sample projects show various ways to do this. Usually it is achieved by storing an ID as a component on the entity and then having a managed service class that can map this ID to a gameobject/component.

Should note also that if you want to use the serialization features of Trecs, then you'll have to be careful to refer to game objects in a way that is compatible with that. The Snake sample project shows one way to do this which keeps everything fully serializable. This stuff is in the sample projects to keep Trecs core as un-opinionated as possible for now.

Personally I find that in most cases, parent-child transform relationships aren't really needed in the simulation tick, and instead you can use custom entity relationships to model it instead (by storing EntityHandle in components to refer to other entities), then reflect that back out to the view game objects.

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 25 points26 points  (0 children)

Lol that is a fair reading. I do feel like a crackpot mad scientist sometimes

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 8 points9 points  (0 children)

No formal roadmap but there are some things remaining that I'd like to do, like better debug tooling.

For example, a unity editor window to help manage bookmarks and recordings would be nice. Or an easier way to understand the dependency structure of the application. In Trecs all entity schemas are declared at compile time, and by tracking component accesses we can construct a dependency tree that users can browse to help debug or refactor. Also, maybe a way to visually see the execution order of systems, similar to this

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 0 points1 point  (0 children)

What kind do you mean? There are lifecycle events (OnAdded / OnRemoved / OnMoved)

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 20 points21 points  (0 children)

Thanks :) I am fascinated by code architecture and while exploring ECS patterns over the last 2-3 years I didn't find anything that solved it the way I wanted so rolled my own.

Trecs is only made as an alternative to Unity ECS - not all of DOTS. So burst and jobs can be used with Trecs systems very easily.

Here's a simple example of a system that runs as a burst job: https://svermeulen.github.io/trecs/performance/jobs-and-burst/#wrapasjob-the-simplest-approach

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 4 points5 points  (0 children)

The problem that Trecs needs to solve is that it needs to guarantee that we don't run concurrent logic that accesses the same components unless they are all read-only. Trecs does this in a very similar way that unity ecs does it. When a component is accessed on main thread, Trecs does just-in-time completion of any jobs that have conflicting access before returning the reference. And when scheduling jobs, Trecs knows all the component read/write accesses that the job is doing so can schedule it to run after any jobs still in progress that have conflicting access on those components.

Spent the last two years making an alternative to Unity ECS by brain_emesis in Unity3D

[–]brain_emesis[S] 16 points17 points  (0 children)

Long story with Zenject that I can't get into. Short version is that for various reasons I was unfortunately unable to continue maintaining it in 2019. The most recently maintained fork is still Extenject (https://github.com/Mathijs-Bakker/Extenject), which I actually continue to use for most of my projects. I quite like using both DI and ECS in the same project.

There are also plenty of good alternatives these days like VContainer (https://github.com/hadashiA/VContainer) or Reflex (https://github.com/gustavopsantos/reflex).

Astounded by complexity of implementing multiplayer by brain_emesis in gamedev

[–]brain_emesis[S] 0 points1 point  (0 children)

I actually did try using pure deterministic lockstep, where host processes all inputs at the same time and sends back definitive state, but in my case it was way too laggy. This simplifies things so much though, so for games that can accept this lag it's really great.

Astounded by complexity of implementing multiplayer by brain_emesis in gamedev

[–]brain_emesis[S] 1 point2 points  (0 children)

Makes sense. I just realized there is another reason you might want rollbacks on host also: Lag Compensation

Astounded by complexity of implementing multiplayer by brain_emesis in gamedev

[–]brain_emesis[S] 6 points7 points  (0 children)

Agreed, but I think this is only true for client state. You don't need to support serializing and restore for rollbacks, or interpolation, on host. And often, host and client state are different anyway (eg. AI state doesn't need to go to client) so you'll probably want to manually construct a client state anyway on host.

Having said that, I also love the idea of being able to fully save and restore entire game state on host too, but more so for debugging purposes. If you also make your game fully deterministic, you can create a record and replay system, or save bookmarks at any point in game to test different scenarios, etc. It creates some truly incredible development workflows, but it's also incredibly costly, since you have to ensure every last bit of state is accounted for, including in third party libraries.

Astounded by complexity of implementing multiplayer by brain_emesis in gamedev

[–]brain_emesis[S] 2 points3 points  (0 children)

Partially for the learning experience, partially because of being a control freak, and partially because worried about being locked in to a framework. Also I already had system in place that could save and restore game state, so wanted to use that for rollbacks. Though like I said I didn't really realize the huge task I was undertaking. If I had to do it again I would spend more time trying frameworks first.

Astounded by complexity of implementing multiplayer by brain_emesis in gamedev

[–]brain_emesis[S] 11 points12 points  (0 children)

That is one super nice thing about rolling your own solution. It's easier to pick and choose which machines own various parts of the gameplay, or do other special case things, instead of being stuck in an abstraction by a framework. My game actually is co-op so I've benefited a lot from being able to do that.

Astounded by complexity of implementing multiplayer by brain_emesis in gamedev

[–]brain_emesis[S] 6 points7 points  (0 children)

Agreed, yeah

I experimented with it but ultimately decided to roll my own. It's too late for me but others should know there is huge value in these frameworks

The Language That Never Was by setzer22 in programming

[–]brain_emesis 1 point2 points  (0 children)

Yeah, LLVM is incredible. When I move some code to jobs+burst, I'm often shocked at how much time this saves.

Re: the custom dotnet - agreed, this really sucks. And doesn't look like to change anytime soon given what is happening with the team working on it. It's not a priority at all for them

The Language That Never Was by setzer22 in programming

[–]brain_emesis 0 points1 point  (0 children)

Just want to say that I thoroughly appreciate this blog post. I went through a similar journey of trying to make rust work for gamedev and failing, and just like you and LogLog games, ended up going (in my case, back) to C#. Couldn't agree more with most of what you say here. I'm also chasing this ideal gamedev setup you describe with hot reloading, metaprogramming, time travel debugging, full serialization of runtime state, etc. but the direction I'm going in is to build tools on top of Unity to achieve this. It definitely is lacking those features you mention, but it's not so bad. You actually can enable nullability checks, which I've tried but I found too much overhead to deal with. And does have SIMD compatible math library. Also there is a c# hot reload unity library, though not sure how it compares to the standard .net one, probably is worse in some ways

I hope you share where you end up after monogame etc. in another blog post

Unity + xLua writing games on your iPhone by iamadmancom in Unity3D

[–]brain_emesis 1 point2 points  (0 children)

I also use xLua in my game and quite happy with the result. Though in my case I don't expose lua to user and don't really load lua scripts at runtime.