Skip to content

Instantly share code, notes, and snippets.

View mlarouche's full-sized avatar

Michaël Larouche mlarouche

View GitHub Profile
@mlarouche
mlarouche / SaveGameManagement.md
Last active March 29, 2023 21:15
So you want to handle save games ?

So you want to handle save games ?

Most games once reaced a certain size will need to persist data between game sessions. In our game dev jargon, we call this data a Save Game.

Your first reflex would be to think: oh this is easy, we only need to find the user's documents or data folder and use simple file read and write operations to handle the save data.

Assumming we are using the Zig programming language, our favorite here at Cold Bytes Games, and the library known-folders, a naive save game serialization code could look like this (this code has not been tested).

const known_folders = @import("known-folders");
@mlarouche
mlarouche / command_list.zig
Last active March 13, 2022 12:27
free function to Self wrapper
const std = @import("std");
const platform = @import("../platforms/platform.zig").platform;
const GpuResource = @import("gpu_resource.zig").GpuResource;
pub const CommandListKind = enum {
Graphics,
Compute,
Copy,
};
@mlarouche
mlarouche / zig_d3d12.zig
Last active September 14, 2020 21:28
Direct3D12 Sample in Zig
const std = @import("std");
const win32 = @import("win32.zig");
const d3d12 = @import("d3d12.zig");
const dxgi = @import("dxgi1_4.zig");
const d3dcompiler = @import("d3dcompiler.zig");
const windows = std.os.windows;
const L = std.unicode.utf8ToUtf16LeStringLiteral;
@mlarouche
mlarouche / build.json
Created August 15, 2020 22:58
Build platform optionally
{
"os": "windows",
"libraries": [
"c",
"d3d12",
"dxgi",
"d3dcompiler",
"dxguid"
],
"include_dirs": [],
@mlarouche
mlarouche / d3d11.zig
Created April 14, 2020 20:00
Direct3D sample usage in one of my projects
const DxContext = struct {
device: ?*dx.ID3D11Device = null,
deviceContext: ?*dx.ID3D11DeviceContext = null,
swapChain: ?*dx.IDXGISwapChain = null,
mainRenderTargetView: ?*dx.ID3D11RenderTargetView = null,
};
var dxContext: DxContext = undefined;
@mlarouche
mlarouche / debug_ir.log
Created March 6, 2020 20:53
zigimg test Debug IR crash Linux
This file has been truncated, but you can view the full file.
; ModuleID = 'test'
source_filename = "test"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"[]u8" = type { i8*, i64 }
%std.builtin.StackTrace = type { i64, %"[]usize" }
%"[]usize" = type { i64*, i64 }
%std.target.LinuxVersionRange = type { %std.builtin.Range, %std.builtin.Version }
@mlarouche
mlarouche / final_result.zig
Last active February 26, 2020 04:03
How to call a function via reflection?
fn findImageFormat(inStream: *ImageInStream, seekStream: *ImageSeekStream) !ImageFormat {
const allFuncs = comptime blk: {
// TODO: Use ArrayList when Zig support compile-time allocator
var result:[16]fn(inStream: *ImageInStream, seekStream: *ImageSeekStream) anyerror!ImageFormat = undefined;
var index:usize = 0;
inline for (std.meta.declarations(AllImageFormats)) |decl| {
switch(decl.data) {
.Type => |entryType| {
const entryTypeInfo = @typeInfo(entryType);
if (entryTypeInfo== .Struct) {
@mlarouche
mlarouche / com_call.zig
Last active February 24, 2020 04:46
Generic COM call
fn comFindReturnType(comptime vTableType: type, comptime name: []const u8) type {
for (@typeInfo(vTableType).Struct.fields) |field| {
if (std.mem.eql(u8, field.name, name)) {
const funcType = @typeInfo(@typeInfo(field.field_type).Optional.child);
return funcType.Fn.return_type.?;
}
}
return void;
}
@mlarouche
mlarouche / win32_helloworld.zig
Created February 22, 2020 18:34
win32 hello world
usingnamespace @import("std").os.windows;
extern "user32" fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) callconv(.Stdcall) c_int;
pub export fn WinMain(hInstance: ?HINSTANCE, hPrevInstance: ?HINSTANCE, lpCmdLine: ?LPWSTR, nShowCmd: INT) callconv(.Stdcall) INT {
_ = MessageBoxA(null, "Zig is pretty great!", "Wow much exposure", 4);
return 0;
}
@mlarouche
mlarouche / Result_PC
Created February 9, 2020 14:56
__divsi3 and __udivsi3 issues on Thumb1
fixed=2048
fixed2=640
result=3.51 / 819