mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-04-30 16:31:46 -04:00
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:
parent
02827893df
commit
c8e8d41fb8
7 changed files with 84 additions and 30 deletions
16
.github/workflows/build.yml
vendored
16
.github/workflows/build.yml
vendored
|
@ -12,7 +12,7 @@ jobs:
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [macos-latest, windows-latest]
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
@ -21,7 +21,21 @@ jobs:
|
||||||
run: zig build
|
run: zig build
|
||||||
- name: Test
|
- name: Test
|
||||||
run: zig build 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:
|
lint:
|
||||||
|
needs: build
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
10
README.md
10
README.md
|
@ -1,14 +1,14 @@
|
||||||
# zTSO
|
# zTSO
|
||||||
|
|
||||||
zTSO is intended to be an experimental reimplementation of The Sims Online written in Zig that directly accesses NioTSO's C-based libraries.
|
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
|
## 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.
|
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 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.
|
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.
|
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
|
## 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**:
|
2. **Navigate to the Repository**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd zsandbox
|
cd ztso
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Run the Examples**: Execute the code examples using the Zig compiler. For instance:
|
3. **Run the Examples**: Execute the code examples using the Zig compiler. For instance:
|
||||||
|
|
|
@ -26,6 +26,7 @@ pub fn build(b: *std.Build) void {
|
||||||
exe.linkLibC();
|
exe.linkLibC();
|
||||||
exe.addIncludePath(.{ .path = "./library/formats" });
|
exe.addIncludePath(.{ .path = "./library/formats" });
|
||||||
exe.addIncludePath(.{ .path = "./library/libvitaboy" });
|
exe.addIncludePath(.{ .path = "./library/libvitaboy" });
|
||||||
|
exe.addIncludePath(.{ .path = "./tools" });
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
const raylib_dep = b.dependency("raylib-zig", .{
|
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.linkLibC();
|
||||||
exe_unit_tests.addIncludePath(.{ .path = "./library/formats" });
|
exe_unit_tests.addIncludePath(.{ .path = "./library/formats" });
|
||||||
exe_unit_tests.addIncludePath(.{ .path = "./library/libvitaboy" });
|
exe_unit_tests.addIncludePath(.{ .path = "./library/libvitaboy" });
|
||||||
|
exe_unit_tests.addIncludePath(.{ .path = "./tools" });
|
||||||
|
|
||||||
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
||||||
|
|
||||||
|
|
27
src/io/filehandler.zig
Normal file
27
src/io/filehandler.zig
Normal 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
4
src/io/iff.zig
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
const iff = @cImport({
|
||||||
|
@cInclude("./iff/iff.h");
|
||||||
|
@cInclude("./iff/iffparser.h");
|
||||||
|
});
|
36
src/main.zig
36
src/main.zig
|
@ -8,28 +8,36 @@ pub fn main() !void {
|
||||||
rl.initWindow(screenWidth, screenHeight, "Basic Window");
|
rl.initWindow(screenWidth, screenHeight, "Basic Window");
|
||||||
defer rl.closeWindow();
|
defer rl.closeWindow();
|
||||||
|
|
||||||
// var ballPos = rl.Vector2.init(screenWidth / 2, screenHeight / 2);
|
var ballPos = rl.Vector2.init(screenWidth / 2, screenHeight / 2);
|
||||||
|
|
||||||
rl.setTargetFPS(60);
|
rl.setTargetFPS(60);
|
||||||
|
|
||||||
while (!rl.windowShouldClose()) {
|
while (!rl.windowShouldClose()) {
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
// if (rl.isKeyDown(rl.KeyboardKey.key_right)) {
|
if (rl.isKeyDown(rl.KeyboardKey.key_right) or
|
||||||
// ballPos.x += 2.0;
|
rl.isKeyDown(rl.KeyboardKey.key_d))
|
||||||
// }
|
{
|
||||||
|
ballPos.x += 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
// if (rl.isKeyDown(rl.KeyboardKey.key_left)) {
|
if (rl.isKeyDown(rl.KeyboardKey.key_left) or
|
||||||
// ballPos.x -= 2.0;
|
rl.isKeyDown(rl.KeyboardKey.key_a))
|
||||||
// }
|
{
|
||||||
|
ballPos.x -= 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
// if (rl.isKeyDown(rl.KeyboardKey.key_up)) {
|
if (rl.isKeyDown(rl.KeyboardKey.key_up) or
|
||||||
// ballPos.y -= 2.0;
|
rl.isKeyDown(rl.KeyboardKey.key_w))
|
||||||
// }
|
{
|
||||||
|
ballPos.y -= 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
// if (rl.isKeyDown(rl.KeyboardKey.key_down)) {
|
if (rl.isKeyDown(rl.KeyboardKey.key_down) or
|
||||||
// ballPos.y -= 2.0;
|
rl.isKeyDown(rl.KeyboardKey.key_s))
|
||||||
// }
|
{
|
||||||
|
ballPos.y += 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
rl.beginDrawing();
|
rl.beginDrawing();
|
||||||
|
@ -39,6 +47,6 @@ pub fn main() !void {
|
||||||
|
|
||||||
rl.drawText("Hello, zTSO!", 190, 200, 20, rl.Color.sky_blue);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const iff = @cImport({
|
const rl = @import("raylib");
|
||||||
@cInclude("./iff/iff.h");
|
const fh = @import("./io/filehandler.zig");
|
||||||
});
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue