add game_debug.c
This commit is contained in:
parent
be1cb0ba9f
commit
7310056eea
163
build.zig
163
build.zig
@ -6,8 +6,9 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const tracy_enabled = b.option(bool, "tracy", "Enable tracy profiling") orelse (optimize == .Debug);
|
const tracy_enabled = b.option(bool, "tracy", "Enable tracy profiling") orelse (optimize == .Debug);
|
||||||
|
const imgui_enabled = b.option(bool, "imgui", "Enable ImGui integration") orelse (optimize == .Debug);
|
||||||
|
|
||||||
var targets = std.ArrayList(*std.Build.Step.Compile){};
|
var targets: std.ArrayList(*std.Build.Step.Compile) = .empty;
|
||||||
|
|
||||||
const mod = b.createModule(.{
|
const mod = b.createModule(.{
|
||||||
.target = target,
|
.target = target,
|
||||||
@ -16,20 +17,7 @@ pub fn build(b: *std.Build) !void {
|
|||||||
});
|
});
|
||||||
mod.addIncludePath(b.path("./src/"));
|
mod.addIncludePath(b.path("./src/"));
|
||||||
|
|
||||||
{
|
var cflags: std.ArrayList([]const u8) = .empty;
|
||||||
var src_dir = try std.fs.cwd().openDir("src", .{ .iterate = true });
|
|
||||||
defer src_dir.close();
|
|
||||||
|
|
||||||
var iter = src_dir.iterate();
|
|
||||||
while (try iter.next()) |entry| {
|
|
||||||
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".c")) {
|
|
||||||
mod.addCSourceFile(.{
|
|
||||||
.file = b.path(b.pathJoin(&.{ "src", entry.name })),
|
|
||||||
.flags = &.{}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const raylib_dep = b.dependency("raylib", .{
|
const raylib_dep = b.dependency("raylib", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
@ -45,62 +33,33 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const incbin_dep = b.dependency("incbin", .{});
|
const incbin_dep = b.dependency("incbin", .{});
|
||||||
mod.addIncludePath(incbin_dep.path("."));
|
mod.addIncludePath(incbin_dep.path("."));
|
||||||
|
|
||||||
{
|
if (imgui_enabled) {
|
||||||
const imgui_mod = b.createModule(.{
|
if (try buildImGui(b, .{
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.link_libcpp = true,
|
.raylib = raylib_dep.artifact("raylib")
|
||||||
});
|
})) |imgui| {
|
||||||
|
mod.linkLibrary(imgui);
|
||||||
|
try targets.append(b.allocator, imgui);
|
||||||
|
}
|
||||||
|
|
||||||
const imgui = b.dependency("imgui", .{});
|
try cflags.append(b.allocator, "-DIMGUI_ENABLED");
|
||||||
imgui_mod.addCSourceFiles(.{
|
|
||||||
.root = imgui.path("."),
|
|
||||||
.files = &.{
|
|
||||||
"imgui.cpp",
|
|
||||||
"imgui_demo.cpp",
|
|
||||||
"imgui_draw.cpp",
|
|
||||||
"imgui_tables.cpp",
|
|
||||||
"imgui_widgets.cpp",
|
|
||||||
},
|
|
||||||
.flags = &.{
|
|
||||||
"-fno-sanitize=undefined",
|
|
||||||
"-std=c++11",
|
|
||||||
"-Wno-deprecated-declarations",
|
|
||||||
"-DNO_FONT_AWESOME",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
imgui_mod.addIncludePath(imgui.path("."));
|
|
||||||
|
|
||||||
const imgui_lib = b.addLibrary(.{
|
|
||||||
.name = "imgui",
|
|
||||||
.root_module = imgui_mod
|
|
||||||
});
|
|
||||||
imgui_lib.installHeadersDirectory(imgui.path("."), "imgui", .{});
|
|
||||||
imgui_lib.installHeadersDirectory(imgui.path("."), ".", .{});
|
|
||||||
|
|
||||||
mod.linkLibrary(imgui_lib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const cimgui = b.dependency("cimgui", .{});
|
{
|
||||||
mod.addCSourceFile(.{
|
var src_dir = try std.fs.cwd().openDir("src", .{ .iterate = true });
|
||||||
.file = cimgui.path("cimgui.cpp"),
|
defer src_dir.close();
|
||||||
.flags = &.{
|
|
||||||
"-fno-exceptions",
|
|
||||||
"-fno-rtti",
|
|
||||||
"-std=c++11"
|
|
||||||
},
|
|
||||||
});
|
|
||||||
mod.addIncludePath(cimgui.path("."));
|
|
||||||
|
|
||||||
const rlimgui = b.dependency("rlimgui", .{
|
var iter = src_dir.iterate();
|
||||||
.target = target,
|
while (try iter.next()) |entry| {
|
||||||
.optimize = optimize,
|
if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".c")) {
|
||||||
});
|
mod.addCSourceFile(.{
|
||||||
mod.addCSourceFile(.{
|
.file = b.path(b.pathJoin(&.{ "src", entry.name })),
|
||||||
.file = rlimgui.path("rlImGui.cpp"),
|
.flags = cflags.items
|
||||||
.flags = &.{},
|
});
|
||||||
});
|
}
|
||||||
mod.addIncludePath(rlimgui.path("."));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = "gaem",
|
.name = "gaem",
|
||||||
@ -129,3 +88,77 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
_ = zcc.createStep(b, "cdb", try targets.toOwnedSlice(b.allocator));
|
_ = zcc.createStep(b, "cdb", try targets.toOwnedSlice(b.allocator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ImGuiOptions = struct {
|
||||||
|
target: std.Build.ResolvedTarget,
|
||||||
|
optimize: std.builtin.OptimizeMode,
|
||||||
|
raylib: *std.Build.Step.Compile
|
||||||
|
};
|
||||||
|
|
||||||
|
fn buildImGui(b: *std.Build, opts: ImGuiOptions) !?*std.Build.Step.Compile {
|
||||||
|
const imgui = b.lazyDependency("imgui", .{}) orelse return null;
|
||||||
|
const cimgui = b.lazyDependency("cimgui", .{}) orelse return null;
|
||||||
|
const rlimgui = b.lazyDependency("rlimgui", .{}) orelse return null;
|
||||||
|
|
||||||
|
const cpp_flags = .{
|
||||||
|
"-fno-exceptions",
|
||||||
|
"-fno-rtti",
|
||||||
|
"-std=c++11",
|
||||||
|
"-DNO_FONT_AWESOME"
|
||||||
|
};
|
||||||
|
|
||||||
|
const imgui_lib = b.addLibrary(.{
|
||||||
|
.name = "imgui",
|
||||||
|
.root_module = b.createModule(.{
|
||||||
|
.target = opts.target,
|
||||||
|
.optimize = opts.optimize,
|
||||||
|
.link_libcpp = true,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
imgui_lib.root_module.addCSourceFiles(.{
|
||||||
|
.root = imgui.path("."),
|
||||||
|
.files = &.{
|
||||||
|
"imgui.cpp",
|
||||||
|
"imgui_demo.cpp",
|
||||||
|
"imgui_draw.cpp",
|
||||||
|
"imgui_tables.cpp",
|
||||||
|
"imgui_widgets.cpp",
|
||||||
|
},
|
||||||
|
.flags = &cpp_flags
|
||||||
|
});
|
||||||
|
imgui_lib.root_module.addIncludePath(imgui.path("."));
|
||||||
|
|
||||||
|
// Needed for cimgui
|
||||||
|
imgui_lib.installHeadersDirectory(imgui.path("."), "imgui", .{});
|
||||||
|
// Needed for rlimgui
|
||||||
|
imgui_lib.installHeadersDirectory(imgui.path("."), ".", .{});
|
||||||
|
|
||||||
|
const lib = b.addLibrary(.{
|
||||||
|
.name = "imgui_raylib_cimgui",
|
||||||
|
.root_module = b.createModule(.{
|
||||||
|
.target = opts.target,
|
||||||
|
.optimize = opts.optimize,
|
||||||
|
.link_libcpp = true,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
lib.root_module.linkLibrary(imgui_lib);
|
||||||
|
|
||||||
|
lib.root_module.addCSourceFile(.{
|
||||||
|
.file = cimgui.path("cimgui.cpp"),
|
||||||
|
.flags = &cpp_flags
|
||||||
|
});
|
||||||
|
lib.root_module.addIncludePath(cimgui.path("."));
|
||||||
|
|
||||||
|
lib.root_module.addCSourceFile(.{
|
||||||
|
.file = rlimgui.path("rlImGui.cpp"),
|
||||||
|
.flags = &cpp_flags,
|
||||||
|
});
|
||||||
|
lib.root_module.addIncludePath(rlimgui.path("."));
|
||||||
|
lib.root_module.linkLibrary(opts.raylib);
|
||||||
|
|
||||||
|
lib.installHeader(rlimgui.path("rlImGui.h"), "rlImGui.h");
|
||||||
|
lib.installHeader(cimgui.path("cimgui.h"), "cimgui.h");
|
||||||
|
|
||||||
|
return lib;
|
||||||
|
}
|
||||||
|
|||||||
@ -20,14 +20,17 @@
|
|||||||
.imgui = .{
|
.imgui = .{
|
||||||
.url = "https://github.com/ocornut/imgui/archive/6d910d5487d11ca567b61c7824b0c78c569d62f0.tar.gz",
|
.url = "https://github.com/ocornut/imgui/archive/6d910d5487d11ca567b61c7824b0c78c569d62f0.tar.gz",
|
||||||
.hash = "N-V-__8AALp9cwA8tEuEno2YCZyivsMaobnF-Z7qZGY3qBOt",
|
.hash = "N-V-__8AALp9cwA8tEuEno2YCZyivsMaobnF-Z7qZGY3qBOt",
|
||||||
|
.lazy = true
|
||||||
},
|
},
|
||||||
.rlimgui = .{
|
.rlimgui = .{
|
||||||
.url = "https://github.com/raylib-extras/rlImGui/archive/dc7f97679a024eee8f5f009e77cc311748200415.tar.gz",
|
.url = "https://github.com/raylib-extras/rlImGui/archive/dc7f97679a024eee8f5f009e77cc311748200415.tar.gz",
|
||||||
.hash = "N-V-__8AAC-taQCKZ-3IjRuWJ-5Dc47QKHDPEmqlwXhvjBGq",
|
.hash = "N-V-__8AAC-taQCKZ-3IjRuWJ-5Dc47QKHDPEmqlwXhvjBGq",
|
||||||
|
.lazy = true
|
||||||
},
|
},
|
||||||
.cimgui = .{
|
.cimgui = .{
|
||||||
.url = "https://github.com/cimgui/cimgui/archive/bfd30140a9c5832b5e0dcf179d6e1e5c69373d5a.tar.gz",
|
.url = "https://github.com/cimgui/cimgui/archive/bfd30140a9c5832b5e0dcf179d6e1e5c69373d5a.tar.gz",
|
||||||
.hash = "N-V-__8AAOY-OACWjhmHu289AXFy9Fro3w_30mGFYL8FTq71",
|
.hash = "N-V-__8AAOY-OACWjhmHu289AXFy9Fro3w_30mGFYL8FTq71",
|
||||||
|
.lazy = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.minimum_zig_version = "0.15.2",
|
.minimum_zig_version = "0.15.2",
|
||||||
|
|||||||
58
src/game_debug.c
Normal file
58
src/game_debug.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#ifdef IMGUI_ENABLED
|
||||||
|
#define NO_FONT_AWESOME
|
||||||
|
#include <rlImGui.h>
|
||||||
|
|
||||||
|
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
||||||
|
#include <cimgui.h>
|
||||||
|
|
||||||
|
void game_debug_init()
|
||||||
|
{
|
||||||
|
rlImGuiBeginInitImGui();
|
||||||
|
|
||||||
|
ImGuiIO *io = igGetIO_ContextPtr(igGetCurrentContext());
|
||||||
|
io->IniFilename = NULL;
|
||||||
|
|
||||||
|
igStyleColorsDark(NULL);
|
||||||
|
|
||||||
|
rlImGuiEndInitImGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_debug_deinit()
|
||||||
|
{
|
||||||
|
rlImGuiShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_debug_show(struct Game *game)
|
||||||
|
{
|
||||||
|
rlImGuiBegin();
|
||||||
|
|
||||||
|
igSetNextWindowSize((ImVec2_c){ 400, 200 }, ImGuiCond_Once);
|
||||||
|
if (igBegin("Debug", NULL, ImGuiWindowFlags_None)) {
|
||||||
|
char label[64] = { 0 };
|
||||||
|
snprintf(label, sizeof(label), "FPS: %.1f (%.2fms)", 1.0f / game->input.dt, game->input.dt * 1000);
|
||||||
|
igTextEx(label, NULL, ImGuiTextFlags_None);
|
||||||
|
|
||||||
|
igTextEx("Hello, World", NULL, ImGuiTextFlags_None);
|
||||||
|
}
|
||||||
|
igEnd();
|
||||||
|
|
||||||
|
rlImGuiEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
void game_debug_init()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_debug_deinit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_debug_show(struct Game *game)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
10
src/main.c
10
src/main.c
@ -86,14 +86,12 @@ int main(void)
|
|||||||
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
rlImGuiSetup(true);
|
|
||||||
|
|
||||||
resources_init(&g_resources);
|
resources_init(&g_resources);
|
||||||
|
|
||||||
struct Game game = { 0 };
|
struct Game game = { 0 };
|
||||||
game_init(&game);
|
game_init(&game);
|
||||||
|
|
||||||
bool open = true;
|
game_debug_init();
|
||||||
|
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
@ -119,15 +117,13 @@ int main(void)
|
|||||||
game_tick(&game);
|
game_tick(&game);
|
||||||
end_window_scaling(&transform, BLACK);
|
end_window_scaling(&transform, BLACK);
|
||||||
|
|
||||||
rlImGuiBegin();
|
game_debug_show(&game);
|
||||||
if (open) igShowDemoWindow(&open);
|
|
||||||
rlImGuiEnd();
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
game_free(&game);
|
game_free(&game);
|
||||||
rlImGuiShutdown();
|
game_debug_deinit();
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
#include <rlImGui.h>
|
|
||||||
#include <rlgl.h>
|
#include <rlgl.h>
|
||||||
#include <TracyConfig.h>
|
#include <TracyConfig.h>
|
||||||
#include <tracy/TracyC.h>
|
#include <tracy/TracyC.h>
|
||||||
@ -15,9 +14,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
|
||||||
#include <cimgui.h>
|
|
||||||
|
|
||||||
#define INCBIN_STYLE INCBIN_STYLE_SNAKE
|
#define INCBIN_STYLE INCBIN_STYLE_SNAKE
|
||||||
#define INCBIN_PREFIX
|
#define INCBIN_PREFIX
|
||||||
#include <incbin.h>
|
#include <incbin.h>
|
||||||
@ -75,5 +71,9 @@ void game_init(struct Game *game);
|
|||||||
void game_free(struct Game *game);
|
void game_free(struct Game *game);
|
||||||
void game_tick(struct Game *game);
|
void game_tick(struct Game *game);
|
||||||
|
|
||||||
|
void game_debug_init();
|
||||||
|
void game_debug_deinit();
|
||||||
|
void game_debug_show(struct Game *game);
|
||||||
|
|
||||||
Color rgb(uint8_t r, uint8_t g, uint8_t b);
|
Color rgb(uint8_t r, uint8_t g, uint8_t b);
|
||||||
Color hex(const char *str);
|
Color hex(const char *str);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user