Moved alice engine to a separate file, fixed json parsing bug, really want to parse more glb stuff
This commit is contained in:
parent
11de21a90b
commit
658d645992
@ -35,6 +35,12 @@ void SpanU8_fprint(SpanU8 str, FILE* stream) {
|
||||
putc((int)*SpanU8_at(str, i), stream);
|
||||
}
|
||||
|
||||
/* Not thread safe */
|
||||
void VecU8_print(VecU8 self){
|
||||
SpanU8_print(VecU8_to_span(&self));
|
||||
VecU8_drop(self);
|
||||
}
|
||||
|
||||
NODISCARD VecU8 VecU8_format(const char *fmt, ...) {
|
||||
assert(fmt);
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ int SpanU8_read_U64(SpanU8* rem_ret, U64* res_ret){
|
||||
}
|
||||
|
||||
/* Returns positive on error, 0 on success, rem_ret is untouched on error */
|
||||
int SpanU8_read_S64(SpanU8* rem_ret, S64* ret){
|
||||
int SpanU8_read_S64(SpanU8* rem_ret, S64* ret, bool allow_leading_zero){
|
||||
SpanU8 rem = *rem_ret;
|
||||
U64 x = 0;
|
||||
bool saw_minus = false;
|
||||
@ -92,7 +92,7 @@ int SpanU8_read_S64(SpanU8* rem_ret, S64* ret){
|
||||
U8 ch = *rem.data;
|
||||
if ('0' <= ch && ch <= '9') {
|
||||
U64 d = (U64)(ch - '0');
|
||||
if (x == 0 && rem_ret->len - rem.len > (U64)saw_minus) {
|
||||
if (!allow_leading_zero && x == 0 && rem_ret->len - rem.len > (U64)saw_minus) {
|
||||
return 1;
|
||||
}
|
||||
if (x > 9223372036854775808UL / 10) {
|
||||
@ -193,7 +193,7 @@ int SpanU8_read_float(SpanU8* rem_ret, float* res_ret){
|
||||
if (SpanU8_parsing_is_char_ahead(rem, '+'))
|
||||
SpanU8_parsing_skip_char(&rem);
|
||||
S64 exp;
|
||||
int ret = SpanU8_read_S64(&rem, &exp);
|
||||
int ret = SpanU8_read_S64(&rem, &exp, true);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (res == 0.f)
|
||||
|
||||
2086
src/l2/alice/engine.h
Normal file
2086
src/l2/alice/engine.h
Normal file
File diff suppressed because it is too large
Load Diff
2082
src/l2/allie/allie.c
2082
src/l2/allie/allie.c
File diff suppressed because it is too large
Load Diff
@ -62,6 +62,8 @@ int glb_file_get_segments(SpanU8 file, GLBFileSegments* ret){
|
||||
/* Illegal, no json segment */
|
||||
return 8;
|
||||
}
|
||||
SpanU8_print(json_segment);
|
||||
printf("\n");
|
||||
OptionJson parsed_json = json_decode(json_segment, 15);
|
||||
if (parsed_json.variant == Option_None) {
|
||||
return 9;
|
||||
|
||||
@ -173,15 +173,20 @@ OptionJson json_decoding_h_no_spaces(SpanU8* rem, U32 depth_rem){
|
||||
if (depth_rem == 0) {
|
||||
return None_Json();
|
||||
}
|
||||
S64 int_value;
|
||||
int int_code = SpanU8_read_S64(rem, &int_value);
|
||||
if (int_code == 0)
|
||||
return Some_Json(Json_from_int(int_value));
|
||||
|
||||
float fl_value;
|
||||
SpanU8 was = *rem;
|
||||
int fl_code = SpanU8_read_float(rem, &fl_value);
|
||||
if (fl_code == 0)
|
||||
return Some_Json(Json_from_float(fl_value));
|
||||
if (fl_code == 0) {
|
||||
S64 int_value;
|
||||
int int_code = SpanU8_read_S64(&was, &int_value, false);
|
||||
if (was.data == rem->data) {
|
||||
assert(int_code == 0);
|
||||
return Some_Json(Json_from_int(int_value));
|
||||
} else {
|
||||
return Some_Json(Json_from_float(fl_value));
|
||||
}
|
||||
}
|
||||
|
||||
bool false_code = SpanU8_parsing_try_read_prefix(rem, cstr("false"));
|
||||
if (false_code)
|
||||
|
||||
@ -126,7 +126,7 @@ void tt13(){
|
||||
void test_s64_reading_with_ill_formed_inp(SpanU8 str){
|
||||
SpanU8 rem = str;
|
||||
S64 val;
|
||||
int c = SpanU8_read_S64(&rem, &val);
|
||||
int c = SpanU8_read_S64(&rem, &val, false);
|
||||
check(c > 0);
|
||||
check(SpanU8_equal(str, rem));
|
||||
}
|
||||
@ -149,7 +149,7 @@ void tt14(){
|
||||
void test_s64_reading_with_good_inp(SpanU8 str, S64 right_val, U64 leftovers){
|
||||
SpanU8 rem = str;
|
||||
S64 val;
|
||||
int c = SpanU8_read_S64(&rem, &val);
|
||||
int c = SpanU8_read_S64(&rem, &val, false);
|
||||
check(c == 0);
|
||||
check(rem.data == str.data + str.len - leftovers && rem.len == leftovers);
|
||||
check(val == right_val);
|
||||
@ -193,6 +193,8 @@ void tt16(){
|
||||
test_float_reading_with_good_inp(cstr("-1e-50"), -1e-50f, 0.00001f, 0);
|
||||
test_float_reading_with_good_inp(cstr("-1e50"), -1e50f, 0.00001f, 0);
|
||||
test_float_reading_with_good_inp(cstr("-15e+4"), -150000, 0.00001f, 0);
|
||||
test_float_reading_with_good_inp(cstr("0.012307405471801758"), 0.012307405471801758f, 0.1f, 0);
|
||||
test_float_reading_with_good_inp(cstr("-0.012307405471801758"), -0.012307405471801758f, 0.1f, 0);
|
||||
}
|
||||
|
||||
void test_float_reading_with_ill_formed_inp(SpanU8 str){
|
||||
@ -369,6 +371,7 @@ void tt27(){
|
||||
test_json_decoding_ok(" { } ", Json_from_MapVecU8ToJson(RBTree_MapVecU8ToJson_new()));
|
||||
test_json_decoding_ok(" \"7\" ", Json_from_SpanU8(cstr("7")));
|
||||
test_json_decoding_ok(" \"XXX\" ", Json_from_SpanU8(cstr("XXX")));
|
||||
test_json_decoding_ok(" -0.012307405471801758", Json_from_float(-0.012307405471801758f));
|
||||
{
|
||||
VecJson x = VecJson_new();
|
||||
VecJson_append(&x, Json_from_int(12));
|
||||
|
||||
BIN
src/l3/models/skeleton.glb
Normal file
BIN
src/l3/models/skeleton.glb
Normal file
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
#include "../../l2/core/json.h"
|
||||
#include "../../l2/allie/allie.c"
|
||||
#include "../../l2/core/glb_file.h"
|
||||
#include "../../l2/alice/engine.h"
|
||||
|
||||
AliceGenericMeshPath AliceGenericMeshPath_for_log(SpanU8 root_dir, U64 w, U64 r, U64 k) {
|
||||
return (AliceGenericMeshPath){
|
||||
@ -59,7 +59,7 @@ void main_h_on_another_frame(void* data, float fl){
|
||||
// VecU8_to_span(&text), (ivec2){100, 100});
|
||||
}
|
||||
|
||||
int main(){
|
||||
void run_app(){
|
||||
R4AlphaStuff st;
|
||||
st.hero_pos = (vec3){0, 0.81f, 0};
|
||||
Alice* alice = Alice_new();
|
||||
@ -168,5 +168,18 @@ int main(){
|
||||
.on_wl_keyboard_key = main_h_on_wayland_keyboard_key,
|
||||
.on_another_frame = main_h_on_another_frame,
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
run_app();
|
||||
VecU8 file = read_file_by_path(vcstr("./src/l3/models/skeleton.glb"));
|
||||
GLBFileSegments data;
|
||||
int c = glb_file_get_segments(VecU8_to_span(&file), &data);
|
||||
if (c > 0) {
|
||||
abortf("Incorrect glb ==> %d\n", c);
|
||||
}
|
||||
VecU8 json_text = json_encode(&data.gltf);
|
||||
VecU8_print(json_text);
|
||||
GLBFileSegments_drop(data);
|
||||
VecU8_drop(file);
|
||||
}
|
||||
|
||||
62
src/l_adele/alice/0simp/0simp.frag
Normal file
62
src/l_adele/alice/0simp/0simp.frag
Normal file
@ -0,0 +1,62 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 1) in vec2 tex;
|
||||
layout(location = 2) in vec3 pos;
|
||||
layout(location = 3) in vec3 norm;
|
||||
|
||||
/* Right now all in set 0 */
|
||||
layout(location = 0) out vec4 fin_color;
|
||||
/* Yes, even these guys */
|
||||
layout(binding = 1) uniform sampler2D color_tex;
|
||||
|
||||
layout(push_constant, std430) uniform pc {
|
||||
layout(offset = 64) vec3 camera_pos;
|
||||
};
|
||||
|
||||
struct Pipeline0PointLight {
|
||||
vec3 pos;
|
||||
vec3 color;
|
||||
};
|
||||
|
||||
struct Pipeline0Spotlight {
|
||||
vec3 pos;
|
||||
vec3 dir;
|
||||
vec3 color;
|
||||
float range;
|
||||
};
|
||||
|
||||
layout(std140, binding = 0) uniform Pipeline0UBO {
|
||||
int point_light_count;
|
||||
int spotlight_count;
|
||||
Pipeline0PointLight point_light_arr[120];
|
||||
Pipeline0Spotlight spotlight_arr [20];
|
||||
};
|
||||
|
||||
float get_intensity(float dist){
|
||||
return 1 / (dist * dist * 1.8 + dist * 0.7 + 1);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec3 norm = normalize(mat3(tang_U, tang_norm, tang_V) * correct_norm_on_tang);
|
||||
vec3 diffuse_illumination = vec3(0);
|
||||
vec3 specular_illumination = vec3(0);
|
||||
for (int i = 0; i < point_light_count; i++) {
|
||||
Pipeline0PointLight lamp = point_light_arr[i];
|
||||
vec3 to_light = -pos + lamp.pos;
|
||||
float dist = length(to_light);
|
||||
vec3 U = to_light / dist;
|
||||
diffuse_illumination += get_intensity(dist) * max(0, dot(U, norm)) * lamp.color;
|
||||
vec3 A = reflect(-U, norm);
|
||||
vec3 to_cam = -pos+camera_pos;
|
||||
float dist_to_cam = length(to_cam);
|
||||
vec3 B = to_cam / dist_to_cam;
|
||||
specular_illumination += get_intensity(dist) * pow(max(0, dot(A, B)), 32) * lamp.color;
|
||||
}
|
||||
for (int i = 0; i < spotlight_count; i++) {
|
||||
Pipeline0Spotlight lamp = spotlight_arr[i];
|
||||
}
|
||||
vec3 natural_color = texture(color_tex, tex).xyz;
|
||||
float specular_c = 0.1;
|
||||
vec3 color = natural_color * diffuse_illumination + specular_c * specular_illumination+;
|
||||
fin_color = vec4(color, 1);
|
||||
}
|
||||
27
src/l_adele/alice/0simp/0simp.vert
Normal file
27
src/l_adele/alice/0simp/0simp.vert
Normal file
@ -0,0 +1,27 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec2 tex;
|
||||
|
||||
layout(location = 5) in mat4 model_t;
|
||||
/* 5 <- 6, 7, 8 */
|
||||
layout(location = 9) in mat3 normal_t;
|
||||
/* 9 <- 10, 11 */
|
||||
|
||||
layout(location = 0) out vec3 out_norm;
|
||||
layout(location = 1) out vec3 out_tang_U;
|
||||
layout(location = 2) out vec3 out_tang_V;
|
||||
layout(location = 3) out vec2 out_tex;
|
||||
layout(location = 4) out vec3 out_pos;
|
||||
|
||||
layout(push_constant, std430) uniform pc {
|
||||
mat4 proj_cam_t;
|
||||
};
|
||||
|
||||
void main(){
|
||||
out_norm = normalize(normal_t * norm);
|
||||
out_tex = tex;
|
||||
vec4 real_pos = model_t * vec4(pos, 1);
|
||||
out_pos = real_pos.xyz;
|
||||
gl_Position = proj_cam_t * real_pos;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user