Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Zig build package and bindings forhttps://github.com/SanderMertens/flecs

License

NotificationsYou must be signed in to change notification settings

zig-gamedev/zflecs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig build package and bindings forflecs ECS v4.1.1

Getting started

Examplebuild.zig:

pubfnbuild(b:*std.Build)void {constexe=b.addExecutable(.{... });constzflecs=b.dependency("zflecs", .{});exe.root_module.addImport("zflecs",zflecs.module("root"));exe.linkLibrary(zflecs.artifact("flecs"));}

Now in your code you may import and usezflecs:

conststd=@import("std");constecs=@import("zflecs");constPosition=struct {x:f32,y:f32 };constVelocity=struct {x:f32,y:f32 };constEats=struct {};constApples=struct {};fnmove_system(positions: []Position,velocities: []constVelocity)void {for (positions,velocities)|*p,v| {p.x+=v.x;p.y+=v.y;    }}//Optionally, systems can receive the components iterator (usually not necessary)fnmove_system_with_it(it:*ecs.iter_t,positions: []Position,velocities: []constVelocity)void {consttype_str=ecs.table_str(it.world,it.table).?;std.debug.print("Move entities with [{s}]\n", .{type_str});deferecs.os.free(type_str);for (positions,velocities)|*p,v| {p.x+=v.x;p.y+=v.y;    }}pubfnmain()!void {constworld=ecs.init();defer_=ecs.fini(world);ecs.COMPONENT(world,Position);ecs.COMPONENT(world,Velocity);ecs.TAG(world,Eats);ecs.TAG(world,Apples);_=ecs.ADD_SYSTEM(world,"move system",ecs.OnUpdate,move_system);_=ecs.ADD_SYSTEM(world,"move system with iterator",ecs.OnUpdate,move_system_with_it);constbob=ecs.new_entity(world,"Bob");_=ecs.set(world,bob,Position, .{ .x=0, .y=0 });_=ecs.set(world,bob,Velocity, .{ .x=1, .y=2 });ecs.add_pair(world,bob,ecs.id(Eats),ecs.id(Apples));_=ecs.progress(world,0);_=ecs.progress(world,0);constp=ecs.get(world,bob,Position).?;std.debug.print("Bob's position is ({d}, {d})\n", .{p.x,p.y });}

zig build run should result in:

Move entities with [main.Position, main.Velocity, (Identifier,Name), (main.Eats,main.Apples)]Move entities with [main.Position, main.Velocity, (Identifier,Name), (main.Eats,main.Apples)]Bob's position is (4, 8)

About

Zig build package and bindings forhttps://github.com/SanderMertens/flecs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp