Skip to content

Commit

Permalink
Fix arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
pwbh committed Aug 31, 2024
1 parent 5b5deaf commit ea57737
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 41 deletions.
68 changes: 68 additions & 0 deletions resources/shader.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
shaders:
- slang: glsl430
programs:
- name: default
vs:
path: /Users/ccuddigan/Github/delve-framework/assets/shaders/built/default/default_default_glsl430_vs.glsl
is_binary: false
entry_point: main
inputs:
- slot: 10
name: pos
sem_name: TEXCOORD
sem_index: 0
- slot: 1
name: color0
sem_name: TEXCOORD
sem_index: 1
- slot: 2
name: texcoord0
sem_name: TEXCOORD
sem_index: 2
outputs:
- slot: 20
name: color
sem_name: TEXCOORD
sem_index: 30
- slot: 1
name: uv
sem_name: TEXCOORD
sem_index: 1
uniform_blocks:
- slot: 40
size: 144
struct_name: vs_params
inst_name: _19
uniforms:
- name: u_projViewMatrix
type: vec4
array_count: 4
offset: 50
fs:
path: /Users/ccuddigan/Github/delve-framework/assets/shaders/built/default/default_default_glsl430_fs.glsl
is_binary: false
entry_point: main
inputs:
- slot: 70
name: color
sem_name: TEXCOORD
sem_index: 80
- slot: 1
name: uv
sem_name: TEXCOORD
sem_index: 1
outputs:
- slot: 90
name: frag_color
sem_name: TEXCOORD
sem_index: 100
uniform_blocks:
- slot: 110
size: 32
struct_name: fs_params
inst_name: _36
uniforms:
- name: u_color_override
type: vec4
array_count: 1
offset: 120
21 changes: 9 additions & 12 deletions resources/tutorial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ education: |
3 A-Levels
BSc in the Internet of Things
tutorial:
- yml:
name: "YAML Ain't Markup Language"
type: awesome
born: 2001
- json:
name: JavaScript Object Notation
type: great
born: 2001
- xml:
name: Extensible Markup Language
type: good
born: 1996
- name: "YAML Ain't Markup Language"
type: awesome
born: 2001
- name: JavaScript Object Notation
type: great
born: 2001
- name: Extensible Markup Language
type: good
born: 1996
39 changes: 39 additions & 0 deletions src/Suspense.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const Self = @This();

const std = @import("std");

arr: std.ArrayList([]const u8),
current_index: usize,

pub fn init(allocator: std.mem.Allocator) Self {
return .{
.arr = std.ArrayList([]const u8).init(allocator),
.current_index = 0,
};
}

pub fn deinit(self: *Self) void {
self.arr.deinit();
}

pub fn set(self: *Self, data: []const u8) !void {
try self.arr.append(data);
}

pub fn get(self: *Self) ?[]const u8 {
if (self.arr.items.len == 0) {
return null;
}

if (self.current_index == self.arr.items.len) {
self.current_index = 0;
self.arr.clearAndFree();
return null;
}

const element = self.arr.items[self.current_index];

self.current_index += 1;

return element;
}
63 changes: 41 additions & 22 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,50 @@ const std = @import("std");

const Ymlz = @import("root.zig").Ymlz;

const Tutorial = struct {
const Uniform = struct {
name: []const u8,
type: []const u8,
born: u16,
array_count: i32,
offset: usize,
};

const Tester = struct {
first: i32,
second: i64,
const UniformBlock = struct {
slot: u64,
size: u64,
struct_name: []const u8,
inst_name: []const u8,
uniforms: []Uniform,
};

const Input = struct {
slot: u64,
name: []const u8,
fourth: f32,
foods: [][]const u8,
// inner: struct {
// sd: i32,
// k: u8,
// l: []const u8,
// another: struct {
// new: f32,
// stringed: []const u8,
// },
// },
sem_name: []const u8,
sem_index: usize,
};

const Details = struct {
path: []const u8,
is_binary: bool,
entry_point: []const u8,
inputs: []Input,
outputs: []Input,
uniform_blocks: []UniformBlock,
};

const Program = struct {
name: []const u8,
vs: Details,
fs: Details,
};

const Shader = struct {
slang: []const u8,
programs: []Program,
};

const Experiment = struct {
shaders: []Shader,
};

pub fn main() !void {
Expand All @@ -45,13 +68,9 @@ pub fn main() !void {
);
defer allocator.free(yml_path);

var ymlz = try Ymlz(Tester).init(allocator);
var ymlz = try Ymlz(Experiment).init(allocator);
const result = try ymlz.loadFile(yml_path);
defer ymlz.deinit(result);

std.debug.print("Tester: {any}\n", .{result});
std.debug.print("Tester.name: {s}\n", .{result.name});
std.debug.print("Tester.forth: {}\n", .{result.fourth});
std.debug.print("Tester.foods: {any}\n", .{result.foods});
// std.debug.print("Tester.inner: {any}\n", .{result.inner});
std.debug.print("Tester: {s}\n", .{result.shaders[0].programs[0].name});
}
32 changes: 25 additions & 7 deletions src/root.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const std = @import("std");

const Suspense = @import("./Suspense.zig");

const Allocator = std.mem.Allocator;
const AnyReader = std.io.AnyReader;

Expand All @@ -26,12 +28,14 @@ const Expression = struct {
raw: []const u8,
};

const Suspensed = std.DoublyLinkedList([]const u8);

pub fn Ymlz(comptime Destination: type) type {
return struct {
allocator: Allocator,
reader: ?AnyReader,
allocations: std.ArrayList([]const u8),
suspensed: ?[]const u8,
suspense: Suspense,

const Self = @This();

Expand All @@ -40,7 +44,7 @@ pub fn Ymlz(comptime Destination: type) type {
.allocator = allocator,
.reader = null,
.allocations = std.ArrayList([]const u8).init(allocator),
.suspensed = null,
.suspense = Suspense.init(allocator),
};
}

Expand All @@ -52,6 +56,8 @@ pub fn Ymlz(comptime Destination: type) type {
}

self.deinitRecursively(st);

self.suspense.deinit();
}

/// Uses absolute path for the yml file path. Can be used in conjunction
Expand Down Expand Up @@ -117,6 +123,16 @@ pub fn Ymlz(comptime Destination: type) type {
return INDENT_SIZE * depth;
}

fn printFieldWithIdent(self: *Self, depth: usize, field_name: []const u8, raw_line: []const u8) void {
_ = self;
// std.debug.print("printFieldWithIdent:", .{});
for (0..depth) |_| {
std.debug.print(" ", .{});
}

std.debug.print("{s}\t{s}\n", .{ field_name, raw_line });
}

fn parse(self: *Self, comptime T: type, depth: usize) !T {
var destination: T = undefined;

Expand All @@ -127,15 +143,16 @@ pub fn Ymlz(comptime Destination: type) type {

var raw_line: []const u8 = undefined;

if (self.suspensed) |s| {
if (self.suspense.get()) |s| {
raw_line = s;
self.suspensed = null;
} else {
raw_line = try self.readLine() orelse break;
}

if (raw_line.len == 0) break;

self.printFieldWithIdent(depth, field.name, raw_line);

switch (typeInfo) {
.Bool => {
@field(destination, field.name) = try self.parseBooleanExpression(raw_line, depth);
Expand Down Expand Up @@ -238,7 +255,7 @@ pub fn Ymlz(comptime Destination: type) type {
const raw_value_line = try self.readLine() orelse break;

if (self.isNewExpression(raw_value_line, depth)) {
self.suspensed = raw_value_line;
try self.suspense.set(raw_value_line);
break;
}

Expand All @@ -257,8 +274,9 @@ pub fn Ymlz(comptime Destination: type) type {
while (true) {
const raw_value_line = try self.readLine() orelse break;

try self.suspense.set(raw_value_line);

if (self.isNewExpression(raw_value_line, depth)) {
self.suspensed = raw_value_line;
break;
}

Expand Down Expand Up @@ -293,7 +311,7 @@ pub fn Ymlz(comptime Destination: type) type {
const raw_value_line = try self.readLine() orelse break;

if (self.isNewExpression(raw_value_line, depth)) {
self.suspensed = raw_value_line;
try self.suspense.set(raw_value_line);
if (preserve_new_line)
_ = list.pop();
break;
Expand Down

0 comments on commit ea57737

Please sign in to comment.