You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The main section contains the init part, it will create our three systems, and execute them ten times.
The component IntComponent contains the Value field, which will be used for incrementation
The system CreateEntitySystem will create an entity with the IntComponent component. It will only be run once
The system WriteSystem will increment the newly created IntComponent by one.
The system ReadSystem will print the current value of IntComponent.
We make sure that ReadSystem update after WriteSystem which update after CreateEntitySystem.
usingrevecs;usingrevecs.Core;usingrevecs.Extensions.Generator.Commands;usingrevecs.Extensions.Generator.Components;usingrevecs.Systems;usingrevtask.Core;usingrevtask.OpportunistJobRunner;namespaceMyGame{staticpartialclassProgram{publicstaticvoidMain(string[]args){// Create the job runner, this will execute our systems.// Assign 50% of the core to itvarrunner=newOpportunistJobRunner(0.5f);// Create the ECS world and pass the runner to it// This will contains the entities and our components.varworld=newRevolutionWorld(runner);// Create a system group, it will contains our system and will schedule themvarsystemGroup=newSystemGroup(world);// Add our systems// The order here doesn't mattersystemGroup.Add(newCreateEntitySystem());systemGroup.Add(newWriteSystem());systemGroup.Add(newReadSystem());// Execute 10 timesfor(vari=0;i<10;i++){runner.CompleteBatch(systemGroup.Schedule(runner));}}partialstructIntComponent:ISparseComponent{publicintValue;}// This will create an entity with 'IntComponent' if it doesn't exist// This will only run oncepartialstructCreateEntitySystem:ISystem{privatepartialstructMyQuery:IQuery,With<IntComponent>{}privatepartialstructCommands:ICmdEntityAdmin,IntComponent.Cmd.IAdmin{}[RevolutionSystem]privatestaticvoidMethod(// Notice the Optional modifier, this mean that the system will still execute even if the query is empty[Query,Optional]MyQueryquery,[Cmd]Commandscmd){if(query.Any())return;varentity=cmd.CreateEntity();cmd.AddIntComponent(entity);}}// This system will increment the component from the entity we created in 'CreateEntitySystem'// This will be done every framepartialstructWriteSystem:ISystem{[RevolutionSystem][DependOn(typeof(CreateEntitySystem))]// This shall execute after CreateEntitySystemprivatestaticvoidMethod([Query]q<Write<IntComponent>>query){foreach(var(_,component)inquery){component.Value++;}}}// This system will read our component and print it to the consolepartialstructReadSystem:ISystem{[RevolutionSystem][DependOn(typeof(WriteSystem))]// This shall execute after WriteSystemprivatestaticvoidMethod([Query]q<Read<IntComponent>>query){foreach(var(_,component)inquery){Console.WriteLine(component.Value);}}}}}