From c8e8d41fb899b5c1e248de294718b5a5e85872c9 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Tue, 30 Apr 2024 23:00:03 -0400 Subject: [PATCH] Zig port of FileHandler - io directly with iff.zig and filehandler.zig - Added OpenGL ubuntu build step and made sure lint doesn't start until build is done - Rewrote motivation section in README --- .github/workflows/build.yml | 16 +++++++++++++++- README.md | 24 ++++++++++++------------ build.zig | 2 ++ src/io/filehandler.zig | 27 +++++++++++++++++++++++++++ src/io/iff.zig | 4 ++++ src/main.zig | 36 ++++++++++++++++++++++-------------- src/vitaboy.zig | 5 ++--- 7 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 src/io/filehandler.zig create mode 100644 src/io/iff.zig diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7945524..e4983d5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: continue-on-error: true strategy: matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + os: [macos-latest, windows-latest] runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v2 @@ -21,7 +21,21 @@ jobs: run: zig build - name: Test run: zig build test + ubuntu-build: + timeout-minutes: 15 + continue-on-error: true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: goto-bus-stop/setup-zig@v2 + - name: Install OpenGL + run: apt-get libglu1-mesa-dev freeglut3-dev mesa-common-dev + - name: Build + run: zig build + - name: Test + run: zig build test lint: + needs: build timeout-minutes: 15 continue-on-error: true runs-on: ubuntu-latest diff --git a/README.md b/README.md index a3f4a20..36b840c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -# zTSO - -zTSO is intended to be an experimental reimplementation of The Sims Online written in Zig that directly accesses NioTSO's C-based libraries. - -## Motivation - -Although an existing and established reimplementation project already exists, it has excess legacy baggage due to it originally being based on .NET Framework 3.5 and XNA, among other things. This has limited its accessibility. Although NioTSO has been abandoned for quite some time now, the foundation remains solid. The client perfectly simulates a loading screen, plus it can render Sims and objects flawlessly. - -The problem is C is, well, C. ¯\\\_(ツ)\_/¯ Accessing NioTSO's code in safer languages like Go or Rust has been historically been difficult. While Zig is still in its infancy, it has proven to be perfectly capable of doing this without jumping through hoops. Making it well worth giving it a try. - -Will this succeed? *I have no idea*. I'm not much of a game developer, but that hasn't stopped me from dreaming. +# zTSO + +zTSO (working title) is intended to be an experimental reimplementation of The Sims Online written in Zig. It directly accesses NioTSO's C-based libraries and uses RayLib for the game engine. + +## Motivation + +Although an established reimplementation project already exists, it has excess legacy baggage due to it originally being based on .NET Framework 3.5 and XNA, causing plenty of performance issues in its current form. Meanwhile, NioTSO's foundation remains solid, even though it was never finished. The client perfectly simulates a loading screen, plus it can render Sims and objects flawlessly. + +The problem is C is, well, C. ¯\\\_(ツ)\_/¯ Accessing NioTSO's code in safer languages like Go or Rust has been historically difficult. While Zig is still in its infancy, the language's FFI is perfectly capable of directly accessing C headers without jumping through hoops. Finally, although Zig itself has not yet hit 1.0, the RayLib game engine is mature. Making it well worth giving it a try. + +Will this succeed? *I have no idea*. I'm not much of a game developer, but that hasn't stopped me from dreaming. Your help is most welcome. ## To do @@ -32,7 +32,7 @@ Will this succeed? *I have no idea*. I'm not much of a game developer, but that 2. **Navigate to the Repository**: ```bash - cd zsandbox + cd ztso ``` 3. **Run the Examples**: Execute the code examples using the Zig compiler. For instance: diff --git a/build.zig b/build.zig index 562fb19..afdffed 100644 --- a/build.zig +++ b/build.zig @@ -26,6 +26,7 @@ pub fn build(b: *std.Build) void { exe.linkLibC(); exe.addIncludePath(.{ .path = "./library/formats" }); exe.addIncludePath(.{ .path = "./library/libvitaboy" }); + exe.addIncludePath(.{ .path = "./tools" }); // Modules const raylib_dep = b.dependency("raylib-zig", .{ @@ -80,6 +81,7 @@ pub fn build(b: *std.Build) void { exe_unit_tests.linkLibC(); exe_unit_tests.addIncludePath(.{ .path = "./library/formats" }); exe_unit_tests.addIncludePath(.{ .path = "./library/libvitaboy" }); + exe_unit_tests.addIncludePath(.{ .path = "./tools" }); const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); diff --git a/src/io/filehandler.zig b/src/io/filehandler.zig new file mode 100644 index 0000000..1cbcc89 --- /dev/null +++ b/src/io/filehandler.zig @@ -0,0 +1,27 @@ +pub const Asset = struct { + Group: u32, + File: u32, + Type: u32, +}; + +pub const FileError = enum { + FERR_NOT_FOUND, + FERR_OPEN, + FERR_BLANK, + FERR_MEMORY, + FERR_READ, + FERR_UNRECOGNIZED, + FERR_INVALIDDATA, +}; + +pub const ImageFormat = enum { + FIMG_BGR24, + FIMG_BGRA32, +}; + +pub const Image = struct { + Width: u8, + Height: u8, + Format: ImageFormat, + Data: u8, +}; diff --git a/src/io/iff.zig b/src/io/iff.zig new file mode 100644 index 0000000..4ab3b32 --- /dev/null +++ b/src/io/iff.zig @@ -0,0 +1,4 @@ +const iff = @cImport({ + @cInclude("./iff/iff.h"); + @cInclude("./iff/iffparser.h"); +}); diff --git a/src/main.zig b/src/main.zig index 2a0e2d0..05ffe91 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,28 +8,36 @@ pub fn main() !void { rl.initWindow(screenWidth, screenHeight, "Basic Window"); defer rl.closeWindow(); - // var ballPos = rl.Vector2.init(screenWidth / 2, screenHeight / 2); + var ballPos = rl.Vector2.init(screenWidth / 2, screenHeight / 2); rl.setTargetFPS(60); while (!rl.windowShouldClose()) { // Update - // if (rl.isKeyDown(rl.KeyboardKey.key_right)) { - // ballPos.x += 2.0; - // } + if (rl.isKeyDown(rl.KeyboardKey.key_right) or + rl.isKeyDown(rl.KeyboardKey.key_d)) + { + ballPos.x += 2.0; + } - // if (rl.isKeyDown(rl.KeyboardKey.key_left)) { - // ballPos.x -= 2.0; - // } + if (rl.isKeyDown(rl.KeyboardKey.key_left) or + rl.isKeyDown(rl.KeyboardKey.key_a)) + { + ballPos.x -= 2.0; + } - // if (rl.isKeyDown(rl.KeyboardKey.key_up)) { - // ballPos.y -= 2.0; - // } + if (rl.isKeyDown(rl.KeyboardKey.key_up) or + rl.isKeyDown(rl.KeyboardKey.key_w)) + { + ballPos.y -= 2.0; + } - // if (rl.isKeyDown(rl.KeyboardKey.key_down)) { - // ballPos.y -= 2.0; - // } + if (rl.isKeyDown(rl.KeyboardKey.key_down) or + rl.isKeyDown(rl.KeyboardKey.key_s)) + { + ballPos.y += 2.0; + } // Draw rl.beginDrawing(); @@ -39,6 +47,6 @@ pub fn main() !void { rl.drawText("Hello, zTSO!", 190, 200, 20, rl.Color.sky_blue); - // rl.drawCircle(ballPos, 50, rl.Color.maroon); + rl.drawCircleV(ballPos, 50, rl.Color.maroon); } } diff --git a/src/vitaboy.zig b/src/vitaboy.zig index 9548b1a..9008bea 100644 --- a/src/vitaboy.zig +++ b/src/vitaboy.zig @@ -1,4 +1,3 @@ const std = @import("std"); -const iff = @cImport({ - @cInclude("./iff/iff.h"); -}); +const rl = @import("raylib"); +const fh = @import("./io/filehandler.zig");