Floor drawing function

- Draw floors from JSON files, untested at the moment.
- Renamed lot.zig to world.zig
This commit is contained in:
Tony Bark 2024-05-04 04:57:22 -04:00
parent aa284c424f
commit cbe28d6c78
6 changed files with 78 additions and 38 deletions

View file

@ -6,7 +6,8 @@ set(IFF2HTML_SOURCES
md5.c
image.c
opngreduc.c
../../Libraries/FileHandler/bmp/read_bmp.c
../../library/formats/iff/iff.h
../../library/formats/bmp/read_bmp.c
)
include_directories(${FILEHANDLER_INCLUDE} ${LIBPNG_INCLUDE})

View file

@ -24,6 +24,7 @@ pub fn build(b: *std.Build) void {
// C headers
exe.linkLibC();
exe.linkLibCpp();
exe.addIncludePath(.{ .path = "./library/formats" });
exe.addIncludePath(.{ .path = "./library/libvitaboy" });
exe.addIncludePath(.{ .path = "./tools" });

View file

@ -1,5 +1,5 @@
.{
.name = "ztso",
.name = "mysimulation",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.1.100",

View file

@ -1,28 +0,0 @@
pub const Floor = struct {
level: u8,
x: u8,
y: u8,
value: u8,
};
pub const World = struct {
floors: []Floor,
walls: u8,
};
pub const Item = struct {
guid: u8,
level: u8,
x: u8,
y: u8,
dir: u8,
group: u8,
};
pub const House = struct {
version: f32,
size: u8,
category: u8,
world: World,
items: []Item,
};

View file

@ -1,7 +1,6 @@
const std = @import("std");
const rl = @import("raylib");
const MAX_INPUT_CHARS = 9;
const world = @import("world.zig");
const GameScreen = enum {
login,
@ -9,13 +8,11 @@ const GameScreen = enum {
world,
};
// Still in the proof of concept phase, don't midn the mess
// Still in the proof of concept phase, don't mind the mess
pub fn main() anyerror!void {
const screen_width = 800;
const screen_height = 600;
// var timePlayed: f32 = 0.0;
rl.initWindow(screen_width, screen_height, "My Simulation");
defer rl.closeWindow();
@ -23,13 +20,15 @@ pub fn main() anyerror!void {
var frame_counter: i32 = 0;
var camera = rl.Camera3D{
.position = rl.Vector3.init(5.0, 4.0, 5.0),
.target = rl.Vector3.init(0, 2.0, 0),
.position = rl.Vector3.init(0.0, 10.0, 10.0),
.target = rl.Vector3.init(0, 0.0, 0),
.up = rl.Vector3.init(0, 1.0, 0),
.fovy = 60,
.projection = rl.CameraProjection.camera_perspective,
};
const planePosition = rl.Vector3.init(0.0, 0.0, 0.0);
// var textBox = rl.Rectangle.init(screen_width / 2.0 - 100, 180, 50);
// var mouseOnText = false;
// var letterCount = 0;
@ -70,6 +69,7 @@ pub fn main() anyerror!void {
defer rl.endDrawing();
switch (current_screen) {
// Mockup loading screen, skips straight to world
.login => {
// Splash screen
rl.drawTexture(splash, 0, 0, rl.Color.white);
@ -78,13 +78,16 @@ pub fn main() anyerror!void {
// Loading text
rl.drawText("Reticulating splines...", 20, screen_height - 30, 20, rl.Color.white);
},
// Skip this for now
.cas => {},
//
// "World" (i.e. lot view)
.world => {
rl.clearBackground(rl.Color.ray_white);
camera.begin();
defer camera.end();
rl.drawPlane(planePosition, rl.Vector2.init(2, 2), rl.Color.green);
rl.drawGrid(64, 1.0);
},
}

63
src/world.zig Normal file
View file

@ -0,0 +1,63 @@
const std = @import("std");
const rl = @import("raylib");
const json = std.json;
pub const Floor = struct {
level: u8,
x: u8,
y: u8,
value: u8,
};
pub const Wall = struct {
level: u8,
x: u8,
y: u8,
value: u8,
tls: u8,
trs: u8,
tlp: u8,
trp: u8,
blp: u8,
brp: u8,
};
pub const World = struct {
floors: []Floor,
walls: []Wall,
};
pub const Item = struct {
guid: u8,
level: u8,
x: u8,
y: u8,
dir: u8,
group: u8,
};
pub const House = struct {
version: f32,
size: u8,
category: u8,
world: World,
items: []Item,
};
/// Draws floors from JSON Blueprint files
pub fn draw_floors(json_file: [:0]const u8) void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const floorLevel = rl.Vector3.init(0.0, 0.0, 0.0);
const parsed = try json.parseFromSlice(House, allocator, json_file, .{});
defer parsed.deinit();
const blueprint = parsed.value;
for (blueprint.world.floors) |flr| {
rl.drawPlane(floorLevel, rl.Vector2.init(flr.x, flr.y), rl.Color.green);
}
}