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
This commit is contained in:
Tony Bark 2024-04-30 23:00:03 -04:00
parent 02827893df
commit c8e8d41fb8
7 changed files with 84 additions and 30 deletions

View file

@ -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

View file

@ -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:

View file

@ -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);

27
src/io/filehandler.zig Normal file
View file

@ -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,
};

4
src/io/iff.zig Normal file
View file

@ -0,0 +1,4 @@
const iff = @cImport({
@cInclude("./iff/iff.h");
@cInclude("./iff/iffparser.h");
});

View file

@ -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);
}
}

View file

@ -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");