genaray / Arch.Extended

Extensions for Arch with some useful features like Systems, Source Generator and Utils.
Apache License 2.0
160 stars 36 forks source link

Initialize component or system? #76

Closed Shadowblitz16 closed 1 month ago

Shadowblitz16 commented 1 month ago

How do I initialize something?

using System.Runtime.CompilerServices;
using Arch.System;
using VoxelTest.Games.VoxelGame.Components;

namespace VoxelTest.Games.VoxelGame.Systems;

public partial class ChunkSystem : BaseSystem<World, float>
{
    private static CubeMeshBuilder _meshBuilder = new();
    public ChunkSystem(World world) : base(world) { }

    [Query]
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void RenderChunk([Data] ref Grid<ushort> blocks, ref PositionI position)
    {

    }

    public static void Build(ref Grid<ushort> blocks, PositionI chunkPosition, PositionI blockPosition)
    {
        for (var z = 0; z < blocks.Size; z++)
        for (var y = 0; y < blocks.Size; y++) 
        for (var x = 0; x < blocks.Size; x++)
        {
            if (chunkPosition.Y + y > 0) blocks.Blocks[GetIndex(ref blocks, blockPosition)] = 1;
            else                         blocks.Blocks[GetIndex(ref blocks, blockPosition)] = 0;
        }
    }
Shadowblitz16 commented 1 month ago

Sorry I posted this in the wrong section