odinfmt: Switch to Stroustrup braces, run fmt on project

This commit is contained in:
Riyyi
2026-11-15 13:15:37 +01:00
parent 235ff0a41d
commit 916a40611c
10 changed files with 73 additions and 47 deletions
+21 -10
View File
@@ -14,17 +14,20 @@ import "../vendor/brokkr"
when ODIN_OS == .Windows { when ODIN_OS == .Windows {
LIB_EXT :: ".dll" LIB_EXT :: ".dll"
OS_NAME :: "windows" OS_NAME :: "windows"
} else when ODIN_OS == .Darwin { }
else when ODIN_OS == .Darwin {
LIB_EXT :: ".dylib" LIB_EXT :: ".dylib"
OS_NAME :: "macos" OS_NAME :: "macos"
} else { }
else {
LIB_EXT :: ".so" LIB_EXT :: ".so"
OS_NAME :: "linux" OS_NAME :: "linux"
} }
when ODIN_ARCH == .amd64 { when ODIN_ARCH == .amd64 {
ARCH_NAME :: "x86_64" ARCH_NAME :: "x86_64"
} else when ODIN_ARCH == .arm64 { }
else when ODIN_ARCH == .arm64 {
ARCH_NAME :: "aarch64" ARCH_NAME :: "aarch64"
} }
@@ -192,7 +195,8 @@ hot_reload :: proc(debug: bool, extra_args: []string) {
if !ok { if !ok {
die("hot reload: failed to terminate running %s", process) die("hot reload: failed to terminate running %s", process)
} }
} else { }
else {
_, ok, _ := exec([]string{"pkill", "-TERM", "-x", process}) _, ok, _ := exec([]string{"pkill", "-TERM", "-x", process})
if !ok { if !ok {
die( die(
@@ -219,7 +223,8 @@ wgpu_init :: proc(version_override := "") {
when ODIN_OS == .Windows { when ODIN_OS == .Windows {
target_name := target_name :=
"wgpu-" + OS_NAME + "-" + ARCH_NAME + "-msvc" + "-release" "wgpu-" + OS_NAME + "-" + ARCH_NAME + "-msvc" + "-release"
} else { }
else {
target_name := "wgpu-" + OS_NAME + "-" + ARCH_NAME + "-release" target_name := "wgpu-" + OS_NAME + "-" + ARCH_NAME + "-release"
} }
@@ -315,7 +320,8 @@ wgpu_init :: proc(version_override := "") {
); dl_err != nil { ); dl_err != nil {
die("wgpu setup: failed to download wgpu-native release") die("wgpu setup: failed to download wgpu-native release")
} }
} else { }
else {
if dl_err := brokkr.execute_command( if dl_err := brokkr.execute_command(
[]string{"curl", "-fL", "--retry", "3", "-o", zip_path, url}, []string{"curl", "-fL", "--retry", "3", "-o", zip_path, url},
); dl_err != nil { ); dl_err != nil {
@@ -339,7 +345,8 @@ wgpu_init :: proc(version_override := "") {
); ex_err != nil { ); ex_err != nil {
die("wgpu setup: failed to extract wgpu-native release") die("wgpu setup: failed to extract wgpu-native release")
} }
} else { }
else {
// Matches scripts/wgpu-init.sh. // Matches scripts/wgpu-init.sh.
if ex_err := brokkr.execute_command( if ex_err := brokkr.execute_command(
[]string{"unzip", "-o", "-q", zip_path, "-d", target}, []string{"unzip", "-o", "-q", zip_path, "-d", target},
@@ -384,7 +391,8 @@ bindings_version_from_file :: proc(
chmod_recursively :: proc(path: string) { chmod_recursively :: proc(path: string) {
when ODIN_OS == .Windows { when ODIN_OS == .Windows {
return return
} else { }
else {
info, err := os.stat(path, context.temp_allocator) info, err := os.stat(path, context.temp_allocator)
if err != nil { if err != nil {
die( die(
@@ -520,7 +528,9 @@ pre_commit :: proc() {
// Pop additional changes // Pop additional changes
cleanup :: proc() { cleanup :: proc() {
err := brokkr.execute_command([]string{"git", "stash", "pop", "--quiet"}) err := brokkr.execute_command(
[]string{"git", "stash", "pop", "--quiet"},
)
if err != nil do os.exit(1) if err != nil do os.exit(1)
} }
@@ -588,7 +598,8 @@ engine_is_running :: proc() -> bool {
) )
if !ok do return false if !ok do return false
return strings.contains(string(out), PROJECT_NAME + ".exe") return strings.contains(string(out), PROJECT_NAME + ".exe")
} else { }
else {
_, ok, code := exec([]string{"pgrep", "-x", PROJECT_NAME}, false) _, ok, code := exec([]string{"pgrep", "-x", PROJECT_NAME}, false)
if !ok do return false if !ok do return false
return code == 0 return code == 0
+1
View File
@@ -3,6 +3,7 @@
"align_comments": true, "align_comments": true,
"align_struct_fields": true, "align_struct_fields": true,
"align_struct_values": true, "align_struct_values": true,
"brace_style": "Stroustrup",
"character_width": 80, "character_width": 80,
"indent_cases": true, "indent_cases": true,
"newline_limit": 1, "newline_limit": 1,
+8 -4
View File
@@ -241,7 +241,8 @@ write_snapshot :: proc() -> os.Error {
snapshot: ^os.File snapshot: ^os.File
if hr.write_full_snapshot || !os.exists(hr.snapshot_path) { if hr.write_full_snapshot || !os.exists(hr.snapshot_path) {
snapshot = os.create(hr.snapshot_path) or_return snapshot = os.create(hr.snapshot_path) or_return
} else { }
else {
snapshot = os.open(hr.snapshot_path, {.Read, .Write}) or_return snapshot = os.open(hr.snapshot_path, {.Read, .Write}) or_return
} }
defer os.close(snapshot) defer os.close(snapshot)
@@ -284,11 +285,13 @@ write_snapshot :: proc() -> os.Error {
delete(region.digest, hr.allocator) delete(region.digest, hr.allocator)
region.digest = digest region.digest = digest
os.write_at(snapshot, data_bytes, offset) or_return os.write_at(snapshot, data_bytes, offset) or_return
} else if mem.compare(digest, region.digest) != 0 { }
else if mem.compare(digest, region.digest) != 0 {
delete(region.digest, hr.allocator) delete(region.digest, hr.allocator)
region.digest = digest region.digest = digest
write_diff_at(snapshot, data_bytes, offset) or_return write_diff_at(snapshot, data_bytes, offset) or_return
} else { }
else {
delete(digest, hr.allocator) delete(digest, hr.allocator)
} }
offset += cast(i64)header.data_size offset += cast(i64)header.data_size
@@ -321,7 +324,8 @@ write_diff_at :: proc(
) or_return ) or_return
diff_idx = -1 diff_idx = -1
} }
} else if diff_idx < 0 { }
else if diff_idx < 0 {
diff_idx = i diff_idx = i
} }
} }
+4 -2
View File
@@ -87,7 +87,8 @@ load_obj_model :: proc(
slash2 := strings.index_byte(token[slash + 1:], '/') slash2 := strings.index_byte(token[slash + 1:], '/')
if slash2 != -1 { if slash2 != -1 {
vti_str = token[slash + 1:slash + 1 + slash2] vti_str = token[slash + 1:slash + 1 + slash2]
} else { }
else {
vti_str = token[slash + 1:] vti_str = token[slash + 1:]
} }
} }
@@ -103,7 +104,8 @@ load_obj_model :: proc(
if vti >= 0 && vti < len(uvs) { if vti >= 0 && vti < len(uvs) {
uv = uvs[vti] uv = uvs[vti]
} }
} else if vi < len(uvs) { }
else if vi < len(uvs) {
uv = uvs[vi] uv = uvs[vi]
} }
+2 -1
View File
@@ -71,7 +71,8 @@ add :: proc(t: ^Things) -> Thing_Ref {
slot = t.next_free slot = t.next_free
t.next_free = t.free_list[t.next_free] t.next_free = t.free_list[t.next_free]
t.free_list[slot] = THING_NIL // clean up the pop'ed free-slot t.free_list[slot] = THING_NIL // clean up the pop'ed free-slot
} else if (t.next_unused < THINGS_MAX) { }
else if (t.next_unused < THINGS_MAX) {
if t.next_unused == THING_NIL do t.next_unused = 1 // first ever add() if t.next_unused == THING_NIL do t.next_unused = 1 // first ever add()
slot = t.next_unused slot = t.next_unused
t.next_unused += 1 t.next_unused += 1
+1 -1
View File
@@ -30,7 +30,7 @@ main :: proc() {
defer api.destroy() defer api.destroy()
settings := api.settings() settings := api.settings()
// Event system // Event systems
base.event_bus_init() base.event_bus_init()
defer base.event_bus_destroy() defer base.event_bus_destroy()
+2 -1
View File
@@ -290,7 +290,8 @@ joystick_callback :: proc "c" (id, connected: i32) {
context = state.ctx context = state.ctx
if connected == glfw.CONNECTED { if connected == glfw.CONNECTED {
base.on_event(base.Joystick_Connect_Event{id = id}) base.on_event(base.Joystick_Connect_Event{id = id})
} else { }
else {
base.on_event(base.Joystick_Disconnect_Event{id = id}) base.on_event(base.Joystick_Disconnect_Event{id = id})
} }
} // GLFWjoystickfun } // GLFWjoystickfun
+4 -2
View File
@@ -808,7 +808,8 @@ pick_present_mode :: proc(vsync: bool) -> wgpu.PresentMode {
if slice.contains(present_modes, wgpu.PresentMode.FifoRelaxed) { if slice.contains(present_modes, wgpu.PresentMode.FifoRelaxed) {
return .FifoRelaxed // Adaptive Vsync return .FifoRelaxed // Adaptive Vsync
} }
} else { }
else {
if slice.contains(present_modes, wgpu.PresentMode.Immediate) { if slice.contains(present_modes, wgpu.PresentMode.Immediate) {
return .Immediate // Vsync Off return .Immediate // Vsync Off
} }
@@ -913,7 +914,8 @@ create_diffuse_texture :: proc(
pixels[idx + 1] = 240 pixels[idx + 1] = 240
pixels[idx + 2] = 240 pixels[idx + 2] = 240
pixels[idx + 3] = 255 pixels[idx + 3] = 255
} else { }
else {
pixels[idx + 0] = 64 pixels[idx + 0] = 64
pixels[idx + 1] = 64 pixels[idx + 1] = 64
pixels[idx + 2] = 64 pixels[idx + 2] = 64
+8 -4
View File
@@ -52,7 +52,8 @@ to_wgsl_struct :: proc(
names[i], names[i],
wgsl_type, wgsl_type,
) )
} else { }
else {
fmt.sbprintf(&b, "\t%s: %s,\n", names[i], wgsl_type) fmt.sbprintf(&b, "\t%s: %s,\n", names[i], wgsl_type)
} }
} }
@@ -188,7 +189,8 @@ to_vertex_format :: proc(
case 4: case 4:
return .Sint32, true return .Sint32, true
} }
} else { }
else {
switch ti.size { switch ti.size {
case 1: case 1:
return .Uint8, true return .Uint8, true
@@ -210,7 +212,8 @@ to_vertex_format :: proc(
case 4: case 4:
return .Float16x4, true return .Float16x4, true
} }
} else if elem.size == 4 { }
else if elem.size == 4 {
switch v.count { switch v.count {
case 2: case 2:
return .Float32x2, true return .Float32x2, true
@@ -248,7 +251,8 @@ to_vertex_format :: proc(
return .Sint32x4, true return .Sint32x4, true
} }
} }
} else { }
else {
switch elem.size { switch elem.size {
case 1: case 1:
switch v.count { switch v.count {