game interface

This commit is contained in:
peterino2 2025-09-24 23:31:46 -07:00
parent c008e5232d
commit ebe207170b
6 changed files with 96 additions and 13 deletions

View File

@ -426,3 +426,7 @@ pub fn SlackStruct(comptime T: type, comptime SlackSize: usize) type {
}
};
}
pub fn cast(comptime T: type, p: *anyopaque) T {
return @alignCast(@ptrCast(p));
}

View File

@ -4,6 +4,7 @@ windowOpen: bool = true,
spawnFuncs: std.ArrayListUnmanaged(SpawnEntry) = .{},
spawnPosition: core.Vectorf = .{},
spawnRotation: core.Rotation = .{},
spawnTarget: ?u32 = null,
pub const SpawnEntry = struct {
typeName: []const u8,
@ -28,16 +29,23 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
}
pub fn objectSpawnOptions(self: *@This()) void {
for (self.spawnFuncs.items) |entry| {
for (self.spawnFuncs.items, 0..) |entry, i| {
if (ig.smallButton(entry.typeName.ptr)) {
if (entry.spawnFunc(self.objectList)) |new| {
const entity = new.vtable.getEntity.?(new.ptr);
self.spawnTarget = @intCast(i);
if (!entry.opts.absoluteSpawnposition) {
self.prepareEntity(entity);
}
}
}
}
if (self.spawnTarget) |target| {
if (target >= self.spawnFuncs.items.len) {
self.spawnTarget = null;
}
}
}
fn spawnedObjectsList(self: *@This()) void {

View File

@ -1,5 +1,6 @@
pub const FpCamera = @import("gameplay/FpCamera.zig");
pub const pawns = @import("gameplay/pawns.zig");
pub const games = @import("gameplay/games.zig");
pub const inputDebugger = @import("debuggers/inputDebugger.zig");
pub const ObjectSpawner = @import("debuggers/objectSpawner.zig");
@ -9,3 +10,17 @@ pub const PhysicsObjectList = @import("debuggers/PhysicsObjectList.zig");
pub const ParticleDebugger = @import("debuggers/ParticleDebugger.zig");
pub const browser = @import("debuggers/fileBrowser.zig");
pub fn setup() !void {
_ = try core.createObject(games.GameList, .{});
}
pub const getGame = games.getGame;
pub const beginGame = games.beginGame;
pub const endGame = games.endGame;
pub const unloadGame = games.unloadGame;
const std = @import("std");
const backlog = @import("Backlog");
const core = backlog.core;

View File

@ -8,6 +8,7 @@ pub export fn startup(p_allocator: *anyopaque, p_a: ?*anyopaque) bool {
backlog.physics.setupFromModule();
// TODO backlog.setupFromModule
core.engine_logs("creating externgame");
start_module(core.startup_getArgs(p_a.?)) catch return false;
return true;
@ -26,6 +27,7 @@ var gAllocator: std.mem.Allocator = undefined;
pub fn start_module(args: core.ModuleLoaderArgs) !void {
if (args.firstLoad) {
_ = core.createObject(ExternGameObject, .{}) catch {};
core.engine_logs("creating externgame");
return;
}
@ -57,6 +59,38 @@ pub const ExternGameObject = struct {
// lib: bool = false,
//s: u32 = 0x42,
fireInput: ?*core.ActionBinding = null,
altFireInput: ?*core.ActionBinding = null,
pub fn beginPlay(p: *anyopaque) void {
const self = core.cast(*@This(), p);
self._beginPlay() catch {
core.engine_errs("unable to beginplay");
};
}
pub fn _beginPlay(self: *@This()) !void {
if (self.fireInput == null) {
self.fireInput = try core.ActionBinding.create(core.MakeName("fire"));
self.fireInput.?.addKey(.Mouse1, .keyDown);
_ = self.fireInput.?.data.addListener(self, onFire);
}
self.fireInput.?.activate();
if (self.altFireInput == null) {
self.altFireInput = try core.ActionBinding.create(core.MakeName("altFire"));
self.altFireInput.?.addKey(.Mouse3, .keyDown);
_ = self.altFireInput.?.data.addListener(self, onAltFire);
}
self.altFireInput.?.activate();
}
pub fn endPlay(p: *anyopaque) void {
const self = core.cast(*@This(), p);
self.fireInput.?.deactivate();
self.altFireInput.?.deactivate();
}
pub fn loadMap2(self: *@This()) !void {
if (self.tbMap) |tbMap| {
core.engine_log("killing the map", .{});
@ -84,16 +118,6 @@ pub const ExternGameObject = struct {
self.physicsObjectsWindow = try extras.PhysicsObjectList.create(self.allocator);
self.consoleWindow.setup();
const fireInput = try core.ActionBinding.create(core.MakeName("fire"));
fireInput.addKey(.Mouse1, .keyDown);
_ = fireInput.data.addListener(self, onFire);
fireInput.activate();
const altFireInput = try core.ActionBinding.create(core.MakeName("altFire"));
altFireInput.addKey(.Mouse3, .keyDown);
_ = altFireInput.data.addListener(self, onAltFire);
altFireInput.activate();
const settings: physics.ShapeSettings = .{ .box = try physics.BoxShapeSettings.create(.{ 1.0, 1.0, 1.0 }) };
defer settings.release();
try physics.addShape("ph_small_box", settings);
@ -118,6 +142,10 @@ pub const ExternGameObject = struct {
}
}
try extras.games.addGame("ExternGame", self, @This());
extras.beginGame("ExternGame");
return self;
}

View File

@ -231,6 +231,8 @@ pub fn prepare(self: *@This()) !void {
defer z.End();
try core.fs().addContentPath("sampleGame");
try extras.setup();
// try core.loadModule("externGame", true);
try backlog.loadDynamicModules();
@ -240,8 +242,6 @@ pub fn prepare(self: *@This()) !void {
// core.fs().watchPath("zig-out/modules");
// try core.fs().addFileChangedCallback(core.sharedLibName("externGame"), moduleChangedCallback, self);
// try self.tryLoadExtern("externGame");
// self.rendererDebugger = try extras.RendererDebug.create(self.allocator); //try core.createObject(extras.RendererDebug, .{});
const rendererDebug = try core.createObject(extras.RendererDebug, .{});
try rendererDebug.skyboxes.append(rendererDebug.allocator, core.MakeName("t_skybox"));
@ -261,7 +261,17 @@ pub fn prepare(self: *@This()) !void {
// self.videoplayerObject = try self.videoplayer.createVideoPlayerEntity();
rend.setSkyboxTexture("t_skybox");
beginPlay(@ptrCast(self));
}
fn beginPlay(p: ?*anyopaque) void {
const self = core.cast(*@This(), p.?);
self._beginPlay() catch {
core.engine_errs("unable to beginPlay sampleagme");
};
}
fn _beginPlay(self: *@This()) !void {
const exitInput = try core.ActionBinding.create(core.MakeName("exit"));
exitInput.addKey(.escape, .keyDown);
_ = exitInput.data.addListener(null, onExit);
@ -334,9 +344,15 @@ pub fn prepare(self: *@This()) !void {
_ = input.data.addListener(self, toggleMouseLook);
input.activate();
}
self.updateMouseLook();
}
fn game_endPlay(p: ?*anyopaque) void {
const self = core.cast(@This(), p);
_ = self;
}
fn onMouseLook(ctx: ?*anyopaque, axis: core.Vector2f) void {
const self: *@This() = @ptrCast(@alignCast(ctx));

View File

@ -0,0 +1,12 @@
exitInput: ?*core.ActionBinding = null,
const std = @import("std");
const backlog = @import("backlog");
const assets = backlog.assets;
const platform = backlog.platform;
const core = backlog.core;
const ig = backlog.imgui.api;
const rend = backlog.rend;
const script = core.script;
const tracy = core.tracy;
const ui = backlog.ui;