Skip to content

Commit 325df96

Browse files
committed
WIP: Editor and runner
1 parent e70146c commit 325df96

File tree

22 files changed

+588
-60
lines changed

22 files changed

+588
-60
lines changed

.github/workflows/test.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ jobs:
9898
# uses: pyvista/setup-headless-display-action@v2
9999

100100
- name: Test headless standalone
101-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5
101+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5
102102

103103
- name: Test headless standalone with asset root
104-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
104+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
105105

106106
- name: Test UI headless
107-
run: zig-out/bin/cetech1 --headless --test-ui --test-ui-junit ./result.xml
107+
run: zig-out/bin/cetech1_editor --headless --test-ui --test-ui-junit ./result.xml
108108

109109
- name: Publish Test Report
110110
uses: mikepenz/action-junit-report@v4
@@ -150,13 +150,13 @@ jobs:
150150
#run: kcov --include-pattern=/cetech1/src/,/cetech/public/ kcov-output zig-out/bin/cetech1_test
151151

152152
- name: Test headless standalone
153-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5
153+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5
154154

155155
- name: Test headless standalone with asset root
156-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
156+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
157157

158158
- name: Test UI headless
159-
run: zig-out/bin/cetech1 --headless --test-ui --test-ui-junit ./result.xml
159+
run: zig-out/bin/cetech1_editor --headless --test-ui --test-ui-junit ./result.xml
160160

161161
- name: Publish Test Report
162162
uses: mikepenz/action-junit-report@v4
@@ -206,15 +206,15 @@ jobs:
206206
# FIXME: Windows
207207
- name: Test headless standalone
208208
shell: bash
209-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5
209+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5
210210

211211
- name: Test headless standalone with asset root
212212
shell: bash
213-
run: zig-out/bin/cetech1 --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
213+
run: zig-out/bin/cetech1_editor --headless --max-kernel-tick 5 --asset-root fixtures/test_asset/
214214

215215
- name: Test UI headless
216216
shell: bash
217-
run: zig-out/bin/cetech1 --headless --test-ui --test-ui-junit ./result.xml
217+
run: zig-out/bin/cetech1_editor --headless --test-ui --test-ui-junit ./result.xml
218218

219219
- name: Publish Test Report
220220
uses: mikepenz/action-junit-report@v4

build.zig

Lines changed: 107 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,18 @@ pub fn updateCectechStep(
119119
pub fn createKernelExe(
120120
b: *std.Build,
121121
comptime bin_name: []const u8,
122+
comptime run_name: []const u8,
123+
comptime run_description: []const u8,
122124
runner_main: std.Build.LazyPath,
123125
cetech1_kernel: *std.Build.Module,
124126
cetech1_kernel_lib: *std.Build.Step.Compile,
125127
versionn: std.SemanticVersion,
128+
static_modules: []const []const u8,
126129
target: std.Build.ResolvedTarget,
127130
optimize: std.builtin.OptimizeMode,
128-
) *std.Build.Step.Compile {
131+
ignored_modules: ?[]const []const u8,
132+
ignored_modules_prefix: ?[]const []const u8,
133+
) !*std.Build.Step.Compile {
129134
const exe = b.addExecutable(.{
130135
.name = bin_name,
131136
.version = versionn,
@@ -141,11 +146,74 @@ pub fn createKernelExe(
141146
exe.linkLibrary(cetech1_kernel_lib);
142147
b.installArtifact(exe);
143148
useSystemSDK(b, target, exe);
144-
createRunStep(b, exe, "run", "Run Forest run");
149+
createRunStep(b, exe, run_name, run_description);
150+
try linkStaticModules(b, exe, target, optimize, static_modules);
151+
152+
const options_step = b.addOptions();
153+
options_step.addOption(?[]const []const u8, "ignored_modules", ignored_modules);
154+
options_step.addOption(?[]const []const u8, "ignored_modules_prefix", ignored_modules_prefix);
155+
const options_module = options_step.createModule();
145156

157+
exe.root_module.addImport("kernel_options", options_module);
146158
return exe;
147159
}
148160

161+
pub fn createEditorExe(
162+
b: *std.Build,
163+
comptime base_bin_name: []const u8,
164+
root_source: std.Build.LazyPath,
165+
cetech1_kernel: *std.Build.Module,
166+
cetech1_kernel_lib: *std.Build.Step.Compile,
167+
versionn: std.SemanticVersion,
168+
static_modules: []const []const u8,
169+
target: std.Build.ResolvedTarget,
170+
optimize: std.builtin.OptimizeMode,
171+
) !*std.Build.Step.Compile {
172+
return try createKernelExe(
173+
b,
174+
base_bin_name ++ "_editor",
175+
"editor",
176+
"Run editor",
177+
root_source,
178+
cetech1_kernel,
179+
cetech1_kernel_lib,
180+
versionn,
181+
static_modules,
182+
target,
183+
optimize,
184+
&.{"runner"},
185+
&.{"runner_"},
186+
);
187+
}
188+
189+
pub fn createRunnerExe(
190+
b: *std.Build,
191+
comptime base_bin_name: []const u8,
192+
root_source: std.Build.LazyPath,
193+
cetech1_kernel: *std.Build.Module,
194+
cetech1_kernel_lib: *std.Build.Step.Compile,
195+
versionn: std.SemanticVersion,
196+
static_modules: []const []const u8,
197+
target: std.Build.ResolvedTarget,
198+
optimize: std.builtin.OptimizeMode,
199+
) !*std.Build.Step.Compile {
200+
return try createKernelExe(
201+
b,
202+
base_bin_name,
203+
"run",
204+
"Run Forest Run!",
205+
root_source,
206+
cetech1_kernel,
207+
cetech1_kernel_lib,
208+
versionn,
209+
static_modules,
210+
target,
211+
optimize,
212+
&.{"editor"},
213+
&.{"editor_"},
214+
);
215+
}
216+
149217
pub fn build(b: *std.Build) !void {
150218
try ensureZigVersion();
151219

@@ -159,6 +227,7 @@ pub fn build(b: *std.Build) !void {
159227
// Modules
160228
.enable_samples = b.option(bool, "with_samples", "build with sample modules.") orelse true,
161229
.enable_editor = b.option(bool, "with_editor", "build with editor modules.") orelse true,
230+
.enable_runner = b.option(bool, "with_runner", "build with editor modules.") orelse true,
162231

163232
.modules = b.option([]const []const u8, "with_module", "build with this modules."),
164233
.static_modules = b.option(bool, "static_modules", "build all modules in static mode.") orelse false,
@@ -317,6 +386,10 @@ pub fn build(b: *std.Build) !void {
317386

318387
// Modules
319388
const ModulesSet = std.StringArrayHashMapUnmanaged(void);
389+
390+
var internal_modules = std.ArrayListUnmanaged([]const u8){};
391+
defer internal_modules.deinit(b.allocator);
392+
320393
var module_set = ModulesSet{};
321394
defer module_set.deinit(b.allocator);
322395
for (all_modules) |module| {
@@ -333,6 +406,7 @@ pub fn build(b: *std.Build) !void {
333406

334407
if (options.enable_samples) try enabled_modules.appendSlice(b.allocator, &samples_modules);
335408
if (options.enable_editor) try enabled_modules.appendSlice(b.allocator, &editor_modules);
409+
if (options.enable_runner) try enabled_modules.appendSlice(b.allocator, &runner_modules);
336410
}
337411

338412
// Static modules.
@@ -403,7 +477,7 @@ pub fn build(b: *std.Build) !void {
403477
gen_ide.addArgs(&.{ "--ide", @tagName(options.ide) });
404478

405479
gen_ide.addArg("--bin-path");
406-
gen_ide.addDirectoryArg(b.path("zig-out/bin/cetech1"));
480+
gen_ide.addDirectoryArg(b.path("zig-out/bin/cetech1_editor"));
407481

408482
gen_ide.addArg("--project-path");
409483
gen_ide.addDirectoryArg(b.path(""));
@@ -446,6 +520,9 @@ pub fn build(b: *std.Build) !void {
446520
var buff: [256:0]u8 = undefined;
447521
for (dynamic_modules.keys()) |m| {
448522
const artifact_name = try std.fmt.bufPrintZ(&buff, "ct_{s}", .{m});
523+
524+
if (!module_set.contains(m)) continue;
525+
449526
const art = b.lazyDependency(m, .{
450527
.target = target,
451528
.optimize = optimize,
@@ -526,21 +603,36 @@ pub fn build(b: *std.Build) !void {
526603
});
527604

528605
//
529-
// CETech1 kernel standalone exe
606+
// CETech1 editor standalone exe
530607
//
531-
const exe = createKernelExe(
608+
const editor_exe = try createEditorExe(
532609
b,
533610
"cetech1",
534611
b.path("src/main.zig"),
535612
kernel_module,
536613
kernel_lib,
537614
cetech1_version,
615+
static_modules.keys(),
538616
target,
539617
optimize,
540618
);
541-
try linkStaticModules(b, exe, target, optimize, static_modules.keys());
542-
// Make exe depends on generated files.
543-
exe.step.dependOn(&generated_files.step);
619+
editor_exe.step.dependOn(&generated_files.step);
620+
621+
//
622+
// CETech1 runner standalone exe
623+
//
624+
const runner_exe = try createRunnerExe(
625+
b,
626+
"cetech1",
627+
b.path("src/main.zig"),
628+
kernel_module,
629+
kernel_lib,
630+
cetech1_version,
631+
static_modules.keys(),
632+
target,
633+
optimize,
634+
);
635+
runner_exe.step.dependOn(&generated_files.step);
544636

545637
//
546638
// CETech1 kernel standalone tests
@@ -557,17 +649,17 @@ pub fn build(b: *std.Build) !void {
557649
});
558650
useSystemSDK(b, target, tests);
559651
b.installArtifact(tests);
652+
try linkStaticModules(b, tests, target, optimize, static_modules.keys());
560653
tests.linkLibC();
561654
tests.linkLibrary(kernel_lib);
562655
tests.step.dependOn(&generated_files.step);
563-
try linkStaticModules(b, tests, target, optimize, static_modules.keys());
564656

565657
const run_unit_tests = b.addRunArtifact(tests);
566658
run_unit_tests.step.dependOn(b.getInstallStep());
567659
const test_step = b.step("test", "Run unit tests");
568660
test_step.dependOn(&run_unit_tests.step);
569661

570-
const run_tests_ui = b.addRunArtifact(exe);
662+
const run_tests_ui = b.addRunArtifact(editor_exe);
571663
run_tests_ui.addArgs(&.{ "--test-ui", "--headless" });
572664
run_tests_ui.step.dependOn(b.getInstallStep());
573665
const testui_step = b.step("test-ui", "Run UI headless test");
@@ -636,6 +728,10 @@ pub const editor_modules = [_][]const u8{
636728
"editor_renderer",
637729
};
638730

731+
pub const runner_modules = [_][]const u8{
732+
"runner",
733+
};
734+
639735
pub const core_modules = [_][]const u8{
640736
"gpu_bgfx",
641737
"graphvm",
@@ -668,4 +764,4 @@ pub const samples_modules = [_][]const u8{
668764
"editor_foo_viewport_tab",
669765
};
670766

671-
pub const all_modules = editor_modules ++ core_modules ++ samples_modules;
767+
pub const all_modules = editor_modules ++ runner_modules ++ core_modules ++ samples_modules;

build.zig.zon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
.editor_simulation = .{ .path = "modules/editor/simulation", .lazy = true },
4848
.editor_renderer = .{ .path = "modules/editor/renderer", .lazy = true },
4949

50+
// RUNNER
51+
.runner = .{ .path = "modules/runner/runner", .lazy = true },
52+
5053
// PHYSICS
5154
.physics = .{ .path = "modules/physics/physics", .lazy = true },
5255

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
zig-out/bin/cetech1_test && zig-out/bin/cetech1 --asset-root fixtures/test_asset/
1+
zig-out/bin/cetech1_test && zig-out/bin/cetech1_editor --asset-root fixtures/test_asset/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Desktop mode
2-
zig-out/bin/cetech1_test && zig-out/bin/cetech1 --asset-root fixtures/test_asset/
2+
zig-out/bin/cetech1_test && zig-out/bin/cetech1_editor --asset-root fixtures/test_asset/
33

44
# Standalone
5-
zig-out/bin/cetech1 --fullscreen --asset-root fixtures/test_asset/
5+
zig-out/bin/cetech1_editor --fullscreen --asset-root fixtures/test_asset/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
zig-out/bin/cetech1_test.exe && zig-out/bin/cetech1.exe --asset-root fixtures/test_asset/
1+
zig-out/bin/cetech1_test.exe && zig-out/bin/cetech1_editor.exe --asset-root fixtures/test_asset/

docs/topics/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ CETech1 has builtin support for tracy profiler and provide Tracy as submodule, b
152152
<tab title="MacOS">
153153
<code-block lang="bash">
154154
profiler/build/tracy-profiler -a localhost
155-
zig-out/bin/cetech1 # on separate terminal
155+
zig-out/bin/cetech1_editor # on separate terminal
156156
# Have fun
157157
</code-block>
158158
</tab>
159159
<tab title="Linux">
160160
<code-block lang="bash">
161161
# install tracy by your way
162162
profiler/build/tracy-profiler -a localhost
163-
zig-out/bin/cetech1 # on separate terminal
163+
zig-out/bin/cetech1_editor # on separate terminal
164164
# Have fun
165165
</code-block>
166166
</tab>

examples/editor_foo_viewport_tab/src/private.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ var foo_tab = editor.TabTypeI.implement(editor.TabTypeIArgs{
131131
gpu_backend,
132132
w,
133133
camera_ent,
134+
false,
134135
),
135136
.camera_ent = camera_ent,
136137
.world = w,

modules/editor/asset_preview/src/private.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ var foo_tab = editor.TabTypeI.implement(editor.TabTypeIArgs{
127127

128128
var tab_inst = _allocator.create(AssetPreviewTab) catch undefined;
129129
tab_inst.* = .{
130-
.viewport = try _render_viewport.createViewport(name, gpu_backend, w, camera_ent),
130+
.viewport = try _render_viewport.createViewport(name, gpu_backend, w, camera_ent, false),
131131
.world = w,
132132
.camera_ent = camera_ent,
133133
.render_pipeline = try _render_pipeline.createDefault(_allocator, gpu_backend, w),

modules/editor/entity_editor/src/private.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var foo_tab = editor.TabTypeI.implement(editor.TabTypeIArgs{
134134

135135
var tab_inst = _allocator.create(EntityEditorTab) catch undefined;
136136
tab_inst.* = .{
137-
.viewport = try _render_viewport.createViewport(name, gpu_backend, w, camera_ent),
137+
.viewport = try _render_viewport.createViewport(name, gpu_backend, w, camera_ent, false),
138138
.world = w,
139139
.camera_ent = camera_ent,
140140
.render_pipeline = try _render_pipeline.createDefault(_allocator, gpu_backend, w),

0 commit comments

Comments
 (0)