GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - coplt/Coplt.Systems: Automatic system (the S in ECS) scheduling and dependency injection

BranchesTags
Open more actions menu

Latest commit

 

History

22 Commits
22 Commits

Folders and files

NameName
Last commit message
Last commit date
.idea/.idea.Coplt.Systems/.idea
.idea/.idea.Coplt.Systems/.idea
 
 
Coplt.Systems.Analyzers
Coplt.Systems.Analyzers
 
 
Coplt.Systems
Coplt.Systems
 
 
Tests
Tests
 
 
.gitignore
.gitignore
 
 
Coplt.Systems.sln
Coplt.Systems.sln
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
global.json
global.json
 
 

Repository files navigation

Coplt.Systems

Automatic system (the S in ECS) scheduling and dependency injection

Examples

[System]
public partial class SysGroup1 : ISystemGroup;
    
public struct Data
{
    public int inc;
}

[System]
public readonly partial struct Sys1<T>(ref float a, int b) // di on constructor parameters
{
    // di on partial properties
    public partial ref Data Data { get; }
    public partial ref readonly Data Data2 { get; }
    
    private readonly float some = a + b;
    
    public void Update(ref int a) // di on parameters
    {
        Data.inc++;
    }
}

// use

// Build systems
var sys = new Systems();
sys.SetResource(new Data()); // Resources will be automatically dependency injected
sys.Add<Sys1<int>>();
sys.Add<SysGroup1>();

// Call update every frame
sys.Update();

// Resources can be modified and retrieved at any time (thread-safe)
var inc = sys.GetResource<Data>().inc;
Console.WriteLine(inc);
Assert.That(inc, Is.EqualTo(1));

Setting groups and order via attributes

[System(Group = typeof(SysGroup1))]
public readonly partial struct Sys4
{
    private void Update(ref Data data) => data.inc *= 2;
}

[System(Group = typeof(SysGroup1), Before = [typeof(Sys4)])]
public readonly partial struct Sys5
{
    private void Update(ref Data data) => data.inc *= 3;
}

[System(After = [typeof(SysGroup1)])]
public readonly partial struct Sys6
{
    private void Update(ref Data data) => data.inc += 3;
}

var sys = new Systems();
sys.SetResource(new Data { inc = 6 });
sys.Add<SysGroup1>();
sys.Add<Sys4>();
sys.Add<Sys5>();
sys.Add<Sys6>();

sys.Update();

var inc = sys.GetResource<Data>().inc;
Console.WriteLine(inc);
Assert.That(inc, Is.EqualTo(39));

Custom resource providers

public class NullResourceProvider : ResourceProvider<NullAttribute>
{
    public override ResRef<T> GetRef<T>(NullAttribute data, ResReq req = default)
    {
        Console.WriteLine(data.Msg);
        return default;
    }
}

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
public sealed class NullAttribute(string Msg = "") : ResourceProviderAttribute<NullResourceProvider, NullAttribute>
{
    public string Msg { get; } = Msg;

    public override NullAttribute GetData() => this;
}

[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
public sealed class NullAttribute(string Msg = "") : ResourceProviderAttribute<NullResourceProvider>
{
    public string Msg { get; } = Msg;
}

[System]
public partial class NullResourceProviderSystem([Null] object? a) : ISystem
{
    [Null("Some")]
    public partial object? Some { get; set; }
    public partial object? Foo { get; set; }

    public void Update([Null] object? b) { }
}

var sys = new Systems();
sys.SetResourceProvider(new NullResourceProvider());
sys.Add<NullResourceProviderSystem>();
sys.Update();

// print: Some

About

Automatic system (the S in ECS) scheduling and dependency injection

www.nuget.org/packages/Coplt.Systems

Resources

Readme
MIT license
Activity
Custom properties

Stars

4 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.