mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-04-30 08:21:47 -04:00
Floor rendering almost works
Almost. For some reason, it suffers from a buffer overflow during the parsing phase. On the other hand, we can just use Raylib's own IO function for reading files!
This commit is contained in:
parent
cbe28d6c78
commit
2331d092d1
7 changed files with 25042 additions and 25027 deletions
|
@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void {
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = "ztso",
|
.name = "mysimulation",
|
||||||
.root_source_file = b.path("src/main.zig"),
|
.root_source_file = b.path("src/main.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
24928
resources/house001.json
24928
resources/house001.json
File diff suppressed because it is too large
Load diff
|
@ -27,7 +27,7 @@ pub fn main() anyerror!void {
|
||||||
.projection = rl.CameraProjection.camera_perspective,
|
.projection = rl.CameraProjection.camera_perspective,
|
||||||
};
|
};
|
||||||
|
|
||||||
const planePosition = rl.Vector3.init(0.0, 0.0, 0.0);
|
// const planePosition = rl.Vector3.init(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
// var textBox = rl.Rectangle.init(screen_width / 2.0 - 100, 180, 50);
|
// var textBox = rl.Rectangle.init(screen_width / 2.0 - 100, 180, 50);
|
||||||
// var mouseOnText = false;
|
// var mouseOnText = false;
|
||||||
|
@ -87,7 +87,8 @@ pub fn main() anyerror!void {
|
||||||
camera.begin();
|
camera.begin();
|
||||||
defer camera.end();
|
defer camera.end();
|
||||||
|
|
||||||
rl.drawPlane(planePosition, rl.Vector2.init(2, 2), rl.Color.green);
|
// rl.drawPlane(planePosition, rl.Vector2.init(2, 2), rl.Color.green);
|
||||||
|
try world.draw_floors("resources/empty_lot_mysim.json");
|
||||||
rl.drawGrid(64, 1.0);
|
rl.drawGrid(64, 1.0);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +1,77 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const rl = @import("raylib");
|
const rl = @import("raylib");
|
||||||
|
const Allocator = std.mem.Allocator;
|
||||||
const json = std.json;
|
const json = std.json;
|
||||||
|
const dbg = std.debug;
|
||||||
|
const fmt = std.fmt;
|
||||||
|
const fs = std.fs;
|
||||||
|
|
||||||
pub const Floor = struct {
|
pub const Floor = struct {
|
||||||
level: u8,
|
level: i32,
|
||||||
x: u8,
|
x: f32,
|
||||||
y: u8,
|
y: f32,
|
||||||
value: u8,
|
value: i32,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Wall = struct {
|
pub const Wall = struct {
|
||||||
level: u8,
|
level: i32,
|
||||||
x: u8,
|
x: f32,
|
||||||
y: u8,
|
y: f32,
|
||||||
value: u8,
|
value: i32,
|
||||||
tls: u8,
|
tls: i32,
|
||||||
trs: u8,
|
trs: i32,
|
||||||
tlp: u8,
|
tlp: i32,
|
||||||
trp: u8,
|
trp: i32,
|
||||||
blp: u8,
|
blp: i32,
|
||||||
brp: u8,
|
brp: i32,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const World = struct {
|
pub const World = struct {
|
||||||
floors: []Floor,
|
floors: []Floor,
|
||||||
walls: []Wall,
|
walls: ?[]Wall,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Item = struct {
|
pub const Item = struct {
|
||||||
guid: u8,
|
guid: i32,
|
||||||
level: u8,
|
level: i32,
|
||||||
x: u8,
|
x: i32,
|
||||||
y: u8,
|
y: i32,
|
||||||
dir: u8,
|
dir: i32,
|
||||||
group: u8,
|
group: i32,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const House = struct {
|
pub const House = struct {
|
||||||
version: f32,
|
version: f32,
|
||||||
size: u8,
|
size: i32,
|
||||||
category: u8,
|
category: i32,
|
||||||
world: World,
|
world: World,
|
||||||
items: []Item,
|
items: []Item,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const Blueprint = struct {
|
||||||
|
house: House,
|
||||||
|
};
|
||||||
|
|
||||||
/// Draws floors from JSON Blueprint files
|
/// Draws floors from JSON Blueprint files
|
||||||
pub fn draw_floors(json_file: [:0]const u8) void {
|
pub fn draw_floors(json_file: [:0]const u8) !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
defer _ = gpa.deinit();
|
defer _ = gpa.deinit();
|
||||||
const allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
const floorLevel = rl.Vector3.init(0.0, 0.0, 0.0);
|
// Load file
|
||||||
|
const lot = rl.loadFileText(json_file);
|
||||||
|
defer rl.unloadFileText(lot);
|
||||||
|
|
||||||
const parsed = try json.parseFromSlice(House, allocator, json_file, .{});
|
// Parse JSON
|
||||||
|
const parsed = try json.parseFromSlice(Blueprint, allocator, lot, .{});
|
||||||
defer parsed.deinit();
|
defer parsed.deinit();
|
||||||
|
|
||||||
const blueprint = parsed.value;
|
const blueprint = parsed.value;
|
||||||
|
|
||||||
for (blueprint.world.floors) |flr| {
|
const floorLevel = rl.Vector3.init(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
for (blueprint.house.world.floors) |flr| {
|
||||||
|
// Draw grass
|
||||||
rl.drawPlane(floorLevel, rl.Vector2.init(flr.x, flr.y), rl.Color.green);
|
rl.drawPlane(floorLevel, rl.Vector2.init(flr.x, flr.y), rl.Color.green);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue