started work on a ECS

master
RedStealthDev 9 months ago
commit 4fff81f82d

18
.gitignore vendored

@ -0,0 +1,18 @@
# This file is for zig-specific build artifacts.
# If you have OS-specific or editor-specific files to ignore,
# such as *.swp or .DS_Store, put those in your global
# ~/.gitignore and put this in your ~/.gitconfig:
#
# [core]
# excludesfile = ~/.gitignore
#
# Cheers!
# -andrewrk
zig-cache/
zig-out/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/

@ -0,0 +1,38 @@
const std = @import("std");
const rl = @import("raylib-zig/build.zig");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var raylib = rl.getModule(b, "raylib-zig");
var raylib_math = rl.math.getModule(b, "raylib-zig");
//web exports are completely separate
if (target.getOsTag() == .emscripten) {
const exe_lib = rl.compileForEmscripten(b, "zig-raylib-game-test", "src/main.zig", target, optimize);
exe_lib.addModule("raylib", raylib);
exe_lib.addModule("raylib-math", raylib_math);
const raylib_artifact = rl.getRaylib(b, target, optimize);
// Note that raylib itself is not actually added to the exe_lib output file, so it also needs to be linked with emscripten.
exe_lib.linkLibrary(raylib_artifact);
const link_step = try rl.linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact });
b.getInstallStep().dependOn(&link_step.step);
const run_step = try rl.emscriptenRunStep(b);
run_step.step.dependOn(&link_step.step);
const run_option = b.step("run", "Run zig-raylib-game-test");
run_option.dependOn(&run_step.step);
return;
}
const exe = b.addExecutable(.{ .name = "zig-raylib-game-test", .root_source_file = .{ .path = "src/main.zig" }, .optimize = optimize, .target = target });
rl.link(b, exe, target, optimize);
exe.addModule("raylib", raylib);
exe.addModule("raylib-math", raylib_math);
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run", "Run zig-raylib-game-test");
run_step.dependOn(&run_cmd.step);
b.installArtifact(exe);
}

@ -0,0 +1,11 @@
.{
.name = "raylib-zig",
.version = "0.1.1",
.dependencies = .{
.raylib = .{
.url = "https://github.com/raysan5/raylib/archive/5.0.tar.gz",
.hash = "1220c28847ca8e8756734ae84355802b764c9d9cf4de057dbc6fc2b15c56e726f27b",
},
},
.paths = .{""},
}

@ -0,0 +1 @@
Subproject commit 7f73ddfa720b7fbda680b2846ba3d7f0ec9f8741

@ -0,0 +1,71 @@
const std = @import("std");
const Etyp = @import("EntitySystemTypes.zig");
//Variables Entity
const EntityIDs: std.TailQueue(u32) = init: {
var temp = std.TailQueue(u32);
var i = 0;
while(i < Etyp.MAXEntitys){
temp.append(i);
i += 1;
}
break :init temp;
};
var EntityAmount: u32 = 0;
const Signatures: [Etyp.MAXEntitys]Etyp.Signature = undefined;
//Entity System
pub fn CreateEntity() !Etyp.entity {
if(EntityAmount >= Etyp.MAXEntitys)
{
return error{};
}
EntityAmount += 1;
return EntityIDs.popFirst();
}
pub fn DestroyEntity(entity: Etyp.entity) void {
Signatures[entity] = null;
EntityIDs.append(entity);
EntityAmount -= 1;
}
pub fn SetSignature(entity: Etyp.entity, signature: Etyp.Signature) void {
Signatures[entity] = signature;
}
pub fn GetSignature(entity: Etyp.entity) Etyp.signature {
return Signatures[entity];
}
const ComponentArray = struct {
Components: [Etyp.MAXEntitys]type,
Entity2Array: [usize]EntityIDs,
Array2Entity: [EntityIDs]usize,
sizeM: usize,
pub fn AddComponent(self: ComponentArray, entity: Etyp.entity, comp: type) void{
var newidx: usize = self.sizeM;
self.Entity2Array[entity] = newidx;
self.Entity2Array[newidx] = entity;
self.Components[newidx] = comp;
self.sizeM += 1;
}
pub fn Removedata(self: ComponentArray, entity: Etyp.entity) void{
var remidx: usize = self.Entity2Array[entity];
var lastidx: usize = self.sizeM-1;
self.Components[remidx] = self.Components[lastidx];
var lastentity: Etyp.entity = self.Array2Entity[lastidx];
self.Entity2Array[lastentity] = remidx;
self.Array2Entity[remidx] = lastentity;
self.Entity2Array[entity] = null;
self.Array2Entity[lastentity] = null;
self.sizeM -= 1;
}
};

@ -0,0 +1,23 @@
const std = @import("std");
const rl = @import("raylib");
//Max Vars
pub const MAXEntitys: u32 = 1000;
pub const MAXComponents: u32 = 32;
//Id Types
pub const entity = usize;
pub const component = usize;
pub const Signature = std.bit_set.IntegerBitSet(MAXComponents);
//Components
pub const Transform = struct {
pos: rl.Vector2,
rot: f16,
scale: rl.Vector2,
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

@ -0,0 +1,30 @@
const rl = @import("raylib");
const std = @import("std");
const EnS = @import("EntitySystem.zig");
pub fn main() anyerror!void {
const screenWidth = 1280;
const screenHeight = 720;
rl.initWindow(screenWidth, screenHeight, "AHHHH");
defer rl.closeWindow();
//rl.setTargetFPS(60);
while (!rl.windowShouldClose()) {
try update();
try draw();
}
}
pub fn update() !void{
}
pub fn draw() !void{
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(rl.Color.black);
rl.drawFPS(10, 10);
}
Loading…
Cancel
Save