Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Feb 28, 2025
1 parent c991459 commit 4bcac0f
Show file tree
Hide file tree
Showing 25 changed files with 273 additions and 28 deletions.
File renamed without changes
4 changes: 2 additions & 2 deletions base/sources/iron.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ i32 color_set_ab(i32 c, u8 i) {
// ██║ ██╗ ██║ ██║ ╚██████╔╝ ██║ ╚═╝ ██║
// ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝

void iron_init(string_t *title, i32 width, i32 height, bool vsync, i32 window_mode, i32 window_features, i32 x, i32 y, i32 frequency) {
void iron_init(string_t *title, i32 width, i32 height, bool vsync, i32 window_mode, i32 window_features, i32 x, i32 y, i32 frequency, bool use_depth) {
kinc_window_options_t win;
kinc_framebuffer_options_t frame;
win.title = title;
Expand All @@ -825,7 +825,7 @@ void iron_init(string_t *title, i32 width, i32 height, bool vsync, i32 window_mo
win.display_index = -1;
win.visible = enable_window;
frame.color_bits = 32;
frame.depth_bits = 0;
frame.depth_bits = use_depth ? 24 : 0;
kinc_init(title, win.width, win.height, &win, &frame);
kinc_random_init((int)(kinc_time() * 1000));

Expand Down
3 changes: 2 additions & 1 deletion base/sources/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ function config_get_options(): kinc_sys_ops_t {
mode: window_mode,
features: window_features,
vsync: config_raw.window_vsync,
frequency: config_raw.window_frequency
frequency: config_raw.window_frequency,
use_depth: false
};
return ops;
}
Expand Down
2 changes: 1 addition & 1 deletion base/sources/ts/iron/iron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ declare function color_set_gb(c: i32, i: u8): i32;
declare function color_set_bb(c: i32, i: u8): i32;
declare function color_set_ab(c: i32, i: u8): i32;

declare function iron_init(title: string, width: i32, height: i32, vsync: bool, window_mode: i32, window_features: i32, x: i32, y: i32, frequency: i32): void;
declare function iron_init(title: string, width: i32, height: i32, vsync: bool, window_mode: i32, window_features: i32, x: i32, y: i32, frequency: i32, use_depth: bool): void;
declare function iron_set_app_name(name: string): void;
declare function iron_log(v: any): void;
declare function iron_g4_clear(flags: i32, color: i32, depth: f32): void;
Expand Down
3 changes: 2 additions & 1 deletion base/sources/ts/iron/sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let _sys_window_title: string;
let _sys_shaders: map_t<string, shader_t> = map_create();

function sys_start(ops: kinc_sys_ops_t) {
iron_init(ops.title, ops.width, ops.height, ops.vsync, ops.mode, ops.features, ops.x, ops.y, ops.frequency);
iron_init(ops.title, ops.width, ops.height, ops.vsync, ops.mode, ops.features, ops.x, ops.y, ops.frequency, ops.use_depth);

_sys_start_time = iron_get_time();
g2_init();
Expand Down Expand Up @@ -419,6 +419,7 @@ type kinc_sys_ops_t = {
mode?: window_mode_t;
frequency?: i32;
vsync?: bool;
use_depth?: bool;
};

enum window_features_t {
Expand Down
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ let flags = globalThis.flags;
flags.with_iron = true;
flags.lite = true;

let project = new Project("Test");
project.add_project("../../../");
let project = new Project("test");
project.add_project("../../");
project.add_tsfiles("sources");
project.add_tsfiles("../../../sources/ts/iron");
project.add_shaders("../../../shaders/draw/*.glsl");
project.add_tsfiles("../../sources/ts/iron");
project.add_shaders("../../shaders/draw/*.glsl");
project.add_shaders("shaders/*.glsl");
project.add_assets("assets/*", { destination: "data/{name}" });

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added base/tests/fall/assets/cube.arm
Binary file not shown.
Binary file added base/tests/fall/assets/sphere.arm
Binary file not shown.
Binary file added base/tests/fall/assets/texture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions base/tests/fall/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

let flags = globalThis.flags;
flags.with_iron = true;
flags.lite = true;

let project = new Project("test");
project.add_project("../../");
project.add_tsfiles("sources");
project.add_cfiles("../../sources/libs/asim/asim.c");
project.add_tsfiles("../../sources/ts/iron");
project.add_shaders("../../shaders/draw/*.glsl");
project.add_shaders("shaders/*.glsl");
project.add_assets("assets/*", { destination: "data/{name}" });

return project;
18 changes: 18 additions & 0 deletions base/tests/fall/shaders/mesh.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#version 450

in vec2 tex_coord;
in vec3 normal;

out vec4 frag_color;

uniform sampler2D my_texture;

void main() {
vec3 l = vec3(0.5, 0.0, 0.5);
vec3 base_color = vec3(1.0, 1.0, 1.0); // texture(my_texture, tex_coord).rgb;
vec3 ambient = base_color * 0.5;
vec3 n = normalize(normal);
float dotnl = max(dot(n, l), 0.0);
vec3 diffuse = dotnl * base_color;
frag_color = vec4(ambient + diffuse, 1.0);
}
16 changes: 16 additions & 0 deletions base/tests/fall/shaders/mesh.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#version 450

in vec4 pos;
in vec2 nor;
in vec2 tex;

out vec3 normal;
out vec2 tex_coord;

uniform mat4 WVP;

void main() {
normal = vec3(nor.xy, pos.w);
tex_coord = tex;
gl_Position = WVP * vec4(pos.xyz, 1.0);
}
47 changes: 47 additions & 0 deletions base/tests/fall/sources/camera.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

function camera_update() {
let camera: camera_object_t = scene_camera;
let move_forward: bool = keyboard_down("w");
let move_backward: bool = keyboard_down("s");
let strafe_left: bool = keyboard_down("a");
let strafe_right: bool = keyboard_down("d");
let strafe_up: bool = keyboard_down("e");
let strafe_down: bool = keyboard_down("q");
let fast: f32 = keyboard_down("shift") ? 2.0 : 1.0;
let speed: f32 = 5.0;
let dir: vec4_t = vec4_create();

if (move_forward || move_backward || strafe_right || strafe_left || strafe_up || strafe_down) {
let clook: vec4_t = camera_object_look(camera);
let cright: vec4_t = camera_object_right(camera);

if (move_forward) {
dir = vec4_fadd(dir, clook.x, clook.y, clook.z);
}
if (move_backward) {
dir = vec4_fadd(dir, -clook.x, -clook.y, -clook.z);
}
if (strafe_right) {
dir = vec4_fadd(dir, cright.x, cright.y, cright.z);
}
if (strafe_left) {
dir = vec4_fadd(dir, -cright.x, -cright.y, -cright.z);
}
if (strafe_up) {
dir = vec4_fadd(dir, 0, 0, 1);
}
if (strafe_down) {
dir = vec4_fadd(dir, 0, 0, -1);
}
}

let d: f32 = time_delta() * speed * fast;
if (d > 0.0) {
transform_move(camera.base.transform, dir, d);
}

if (mouse_down()) {
transform_rotate(camera.base.transform, vec4_z_axis(), -mouse_movement_x / 200);
transform_rotate(camera.base.transform, camera_object_right(camera), -mouse_movement_y / 200);
}
}
163 changes: 163 additions & 0 deletions base/tests/fall/sources/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// ../../../make --graphics vulkan --run

///include "../../sources/libs/asim/asim.h"

function main() {
let ops: kinc_sys_ops_t = {
title: "Empty",
width: 1280,
height: 720,
x: -1,
y: -1,
features: window_features_t.RESIZABLE | window_features_t.MINIMIZABLE | window_features_t.MAXIMIZABLE,
mode: window_mode_t.WINDOWED,
frequency: 60,
vsync: true,
use_depth: true
};
sys_start(ops);
app_init();
app_ready();
}

function render_commands() {
render_path_set_target("");
render_path_clear_target(0xff6495ed, 1.0, clear_flag_t.COLOR | clear_flag_t.DEPTH);
render_path_draw_meshes("mesh");
}

function app_ready() {
render_path_commands = render_commands;

let scene: scene_t = {
name: "Scene",
objects: [
{
name: "Cube",
type: "mesh_object",
data_ref: "cube.arm/Cube",
material_refs: ["MyMaterial"],
visible: true,
spawn: true
},
{
name: "Sphere",
type: "mesh_object",
data_ref: "sphere.arm/Sphere",
material_refs: ["MyMaterial"],
visible: true,
spawn: true
},
{
name: "Camera",
type: "camera_object",
data_ref: "MyCamera",
visible: true,
spawn: true
}
],
camera_datas: [
{
name: "MyCamera",
near_plane: 0.1,
far_plane: 100.0,
fov: 0.85
}
],
camera_ref: "Camera",
material_datas: [
{
name: "MyMaterial",
shader: "MyShader",
contexts: [
{
name: "mesh",
bind_textures: [
{
name: "my_texture",
file: "texture.k"
}
]
}
]
}
],
shader_datas: [
{
name: "MyShader",
contexts: [
{
name: "mesh",
vertex_shader: "mesh.vert",
fragment_shader: "mesh.frag",
compare_mode: "less",
cull_mode: "clockwise",
depth_write: true,
vertex_elements: [
{
name: "pos",
data: "short4norm"
},
{
name: "nor",
data: "short2norm"
},
{
name: "tex",
data: "short2norm"
}
],
constants: [
{
name: "WVP",
type: "mat4",
link: "_world_view_proj_matrix"
}
],
texture_units: [
{
name: "my_texture"
}
]
}
]
}
]
};
map_set(data_cached_scene_raws, scene.name, scene);

// Instantiate scene
scene_create(scene);
scene_ready();
}

function scene_ready() {
// Set camera
let t: transform_t = scene_camera.base.transform;
t.loc = vec4_create(0, -10, 0);
t.rot = quat_from_to(vec4_create(0, 0, 1), vec4_create(0, -1, 0));
transform_build_matrix(t);

app_notify_on_update(scene_update);

let cube: object_t = scene_get_child("Cube");
let mesh: mesh_object_t = cube.ext;

asim_init(mesh.data.vertex_arrays[0].values, mesh.data.index_arrays[0].values, mesh.data.scale_pos);
}

function scene_update() {
asim_update();
camera_update();

if (keyboard_started("space")) {
asim_set_sphere(0, 0, 5);
}

let sphere: object_t = scene_get_child("Sphere");
let t: transform_t = sphere.transform;
t.loc.x = asim_get_sphere_x();
t.loc.y = asim_get_sphere_y();
t.loc.z = asim_get_sphere_z();
transform_build_matrix(t);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ let flags = globalThis.flags;
flags.with_iron = true;
flags.lite = true;

let project = new Project("Test");
project.add_project("../../../");
let project = new Project("test");
project.add_project("../../");
project.add_tsfiles("./");
project.add_tsfiles("../../../sources/ts/iron");
project.add_tsfiles("../../sources/ts/iron");
project.add_shaders("./*.glsl");
return project;
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions base/tools/tests/asim/project.js

This file was deleted.

3 changes: 0 additions & 3 deletions base/tools/tests/cube/tsconfig.json

This file was deleted.

0 comments on commit 4bcac0f

Please sign in to comment.