I severely changed Alice api, but we still not even close to C++ rewrite
This commit is contained in:
parent
b72ed8557b
commit
6664860dbf
9
Makefile
9
Makefile
@ -44,15 +44,6 @@ gen/l1/dorothy.txt: out/l1/codegen
|
||||
mkdir -p gen
|
||||
cd gen && ../out/l1/codegen
|
||||
|
||||
out/l1_4/t0: src/l1_4/tests/t0.c $(HEADERS_gen_l1)
|
||||
mkdir -p out/l1_4
|
||||
$(cc) $(cflags) -o $@ $<
|
||||
|
||||
out/l1_4/t1: src/l1_4/tests/t1.c $(HEADERS_gen_l1)
|
||||
mkdir -p out/l1_4
|
||||
$(cc) $(cflags) -o $@ $<
|
||||
|
||||
|
||||
out/l1_5/codegen: src/l1_5/anne/codegen.c $(HEADERS_src_l1_5)
|
||||
mkdir -p out/l1_5
|
||||
$(cc) $(cflags) -o $@ $<
|
||||
|
||||
@ -69,7 +69,7 @@ haskell и rust. Самые высшие уровни Дарьи это те, ч
|
||||
|
||||
Вот какие уровни есть в данный момент:
|
||||
|
||||
`l_wl_protocls` (написан не мной, не нумеруется), `l1`, `l1_4`, `l1_5`, `l2`
|
||||
`l_wl_protocls` (написан не мной, не нумеруется), `l1`, `l1_5`, `l2`
|
||||
|
||||
Весь код хранится в папках `src/<имя уровня>` и `gen/<имя уровня>`.
|
||||
Код с более высокого уровня может использовать код с более низкого уровня.
|
||||
@ -133,8 +133,6 @@ _Не спрашивай как я написал `src/l1/core/chicken_VecU8.h`
|
||||
генерации.
|
||||
]]
|
||||
|
||||
- `l1_4` -- Тут просто лежат тесты для шаблонов `l1`.
|
||||
|
||||
- `l1_5`
|
||||
- - Инстанциация `Box`, `Ref`, `RefMut` для трейта (инстанциация
|
||||
'громадных' ссылок).
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
typedef uint8_t U8;
|
||||
typedef uint16_t U16;
|
||||
@ -70,3 +72,26 @@ void* safe_calloc(size_t nmemb, size_t size) {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
template <class F, class DstT, class SrcT>
|
||||
concept AllieCopyingFunction = requires(F&& f, DstT& dst, const SrcT& src) {
|
||||
std::invoke(std::forward<F>(f), dst, src);
|
||||
};
|
||||
|
||||
|
||||
template <typename T, typename VecT>
|
||||
void allie_form_a_cvec_of_matching_types(VecT& dst, const std::vector<T>& src) {
|
||||
dst.len = dst.capacity = src.size();
|
||||
dst.buf = static_cast<T*>(safe_malloc( src.size() * sizeof(T) ));
|
||||
memcpy(dst.buf, src.data(), src.size() * sizeof(T));
|
||||
}
|
||||
|
||||
template <typename DstT, typename SrcT, typename VecDstT, typename F>
|
||||
requires AllieCopyingFunction<F, DstT, SrcT>
|
||||
void allie_form_a_cvec_of_non_primitive_type(VecDstT& dst, const std::vector<SrcT>& src, F&& f) {
|
||||
dst.len = dst.capacity = src.size();
|
||||
dst.buf = static_cast<DstT*>(safe_malloc( src.size() * sizeof(DstT) ));
|
||||
for (U64 i = 0; i < src.size(); i++) {
|
||||
f(dst.buf[i], src[i]);
|
||||
}
|
||||
}
|
||||
32
src/l2/alice/camera.h
Normal file
32
src/l2/alice/camera.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../gen/l1/geom.h"
|
||||
|
||||
typedef struct {
|
||||
float fov;
|
||||
mat3 cam_basis;
|
||||
vec3 pos;
|
||||
} AliceCam;
|
||||
|
||||
typedef struct{
|
||||
AliceCam cam;
|
||||
float sensitivity;
|
||||
float pitch_cap;
|
||||
} AliceCamVerticalControl;
|
||||
|
||||
AliceCamVerticalControl AliceCamVerticalControl_new() {
|
||||
return (AliceCamVerticalControl){
|
||||
.cam.fov = 1.5f, .cam.cam_basis = marie_simple_camera_rot_m_basis_in_cols(0, 0, 0), .cam.pos = {0, 0, 0},
|
||||
.sensitivity = 0.5f * M_PIf / 180, .pitch_cap = M_PIf * 0.49f
|
||||
};
|
||||
}
|
||||
|
||||
void AliceCamVerticalControl_update_direction(
|
||||
AliceCamVerticalControl* self, int win_width, int win_height, float pointer_x, float pointer_y) {
|
||||
float yaw = ((float)win_width / 2 - pointer_x) * self->sensitivity;
|
||||
float pitch = marie_clamp_float(
|
||||
((float)win_height / 2 - pointer_y) * self->sensitivity,
|
||||
-self->pitch_cap, self->pitch_cap
|
||||
);
|
||||
self->cam.cam_basis = marie_simple_camera_rot_m_basis_in_cols(yaw, pitch, 0);
|
||||
}
|
||||
@ -8,6 +8,8 @@
|
||||
#include "../lucy/glyph_render.h"
|
||||
#include "../gui/widget.h"
|
||||
|
||||
typedef struct Alice Alice;
|
||||
|
||||
typedef struct {
|
||||
size_t indexes;
|
||||
|
||||
@ -17,6 +19,9 @@ typedef struct {
|
||||
PatriciaBuf instance_attr;
|
||||
|
||||
U32 diffuse_tex_slot, normal_tex_slot, specular_tex_slot;
|
||||
|
||||
/* Every good handler contains a reference to parent for debugging purposes */
|
||||
Alice* p;
|
||||
} AliceGenericMeshHand;
|
||||
|
||||
#include "../../../gen/l1/eve/alice/ListAliceGenericMeshHand.h"
|
||||
@ -26,38 +31,14 @@ typedef struct {
|
||||
MargaretSubbuf vbo;
|
||||
MargaretSubbuf ebo;
|
||||
PatriciaBuf instance_attr;
|
||||
|
||||
/* For debug */
|
||||
Alice* p;
|
||||
} AliceShinyMeshHand;
|
||||
|
||||
#include "../../../gen/l1/eve/alice/ListAliceShinyMeshHand.h"
|
||||
|
||||
typedef struct {
|
||||
float fov;
|
||||
mat3 cam_basis;
|
||||
vec3 pos;
|
||||
} AliceCam;
|
||||
|
||||
typedef struct{
|
||||
AliceCam cam;
|
||||
float sensitivity;
|
||||
float pitch_cap;
|
||||
} AliceCamVerticalControl;
|
||||
|
||||
AliceCamVerticalControl AliceCamVerticalControl_new() {
|
||||
return (AliceCamVerticalControl){
|
||||
.cam.fov = 1.5f, .cam.cam_basis = marie_simple_camera_rot_m_basis_in_cols(0, 0, 0), .cam.pos = {0, 0, 0},
|
||||
.sensitivity = 0.5f * M_PIf / 180, .pitch_cap = M_PIf * 0.49f
|
||||
};
|
||||
}
|
||||
|
||||
void AliceCamVerticalControl_update_direction(
|
||||
AliceCamVerticalControl* self, int win_width, int win_height, float pointer_x, float pointer_y) {
|
||||
float yaw = ((float)win_width / 2 - pointer_x) * self->sensitivity;
|
||||
float pitch = marie_clamp_float(
|
||||
((float)win_height / 2 - pointer_y) * self->sensitivity,
|
||||
-self->pitch_cap, self->pitch_cap
|
||||
);
|
||||
self->cam.cam_basis = marie_simple_camera_rot_m_basis_in_cols(yaw, pitch, 0);
|
||||
}
|
||||
#include "camera.h"
|
||||
|
||||
typedef struct {
|
||||
MargaretSubbuf num_ubo_staging;
|
||||
@ -613,12 +594,9 @@ void Jane_alice_destroy(VkDevice device, Jane_alice jane) {
|
||||
}
|
||||
|
||||
void alice_default_callback_on_wl_pointer_button(void* d, uint32_t button, uint32_t btn_action){}
|
||||
|
||||
void alice_default_callback_on_wl_keyboard_key(void* d, U32 keysym, U32 key_action){}
|
||||
|
||||
void alice_default_callback_on_another_frame(void* d, float fl){}
|
||||
|
||||
typedef struct Alice Alice;
|
||||
void alice_default_callback_on_wl_pointer_motion(void* d, vec2 pos){}
|
||||
|
||||
typedef struct{
|
||||
void* guest;
|
||||
@ -626,13 +604,17 @@ typedef struct{
|
||||
void (*on_wl_pointer_button)(void*, U32, U32);
|
||||
/* guest data, keysym, key action (wl_keyboard_key_state) */
|
||||
void (*on_wl_keyboard_key)(void*, U32, U32);
|
||||
/* guest data, passed time */
|
||||
void (*on_another_frame)(void*, float);
|
||||
/* guest data, */
|
||||
void (*on_wl_pointer_motion)(void*, vec2 pos);
|
||||
} AliceCallbacks;
|
||||
|
||||
void AliceCallbacks_set_default(AliceCallbacks* self){
|
||||
self->on_wl_pointer_button = alice_default_callback_on_wl_pointer_button;
|
||||
self->on_wl_keyboard_key = alice_default_callback_on_wl_keyboard_key;
|
||||
self->on_another_frame = alice_default_callback_on_another_frame;
|
||||
self->on_wl_pointer_motion = alice_default_callback_on_wl_pointer_motion;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
@ -677,12 +659,16 @@ float AliceWaylandApp_get_elapsed_time(const AliceWaylandApp* self){
|
||||
/* They are actually MutRef, but who cares lol, we won't have such distinction here anytime soon, so we shorten
|
||||
* it to Ref (while keeping in kind that it is actually MutRef). Also, these lines do nothing useful
|
||||
*/
|
||||
// todo: reconsider their existence
|
||||
typedef struct ListNodeAliceGenericMeshHand* RefListNodeAliceGenericMeshHand;
|
||||
#include "../../../gen/l1/eve/alice/VecRefListNodeAliceGenericMeshHand.h"
|
||||
|
||||
typedef struct ListNodeAliceShinyMeshHand* RefListNodeAliceShinyMeshHand;
|
||||
#include "../../../gen/l1/eve/alice/VecRefListNodeAliceShinyMeshHand.h"
|
||||
|
||||
typedef ListNodeAliceGenericMeshHand* AliceAcknGenericMesh;
|
||||
typedef ListNodeAliceShinyMeshHand* AliceAcknShinyMesh;
|
||||
|
||||
typedef struct {
|
||||
bool is_some;
|
||||
MargaretTexture tex;
|
||||
@ -738,7 +724,9 @@ struct Alice {
|
||||
|
||||
ListAliceGenericMeshHand generic_models;
|
||||
ListAliceShinyMeshHand shiny_models;
|
||||
AliceCamVerticalControl cam_info;
|
||||
mat4 cam_proj_t_mat;
|
||||
vec3 camera_pos;
|
||||
|
||||
/* stuff like background color, hdr factor and
|
||||
* postprocessing kernel. Mostly related to renderpass 1 */
|
||||
AliceRenderConfig rendering_config;
|
||||
@ -751,7 +739,7 @@ struct Alice {
|
||||
LucyGlyphCache lucy_cache;
|
||||
LucyRenderer lucy_renderer;
|
||||
/* For now all my ui is placed 'on top' of the scene */
|
||||
MutRefWidget overlay_ui_root;
|
||||
// MutRefWidget overlay_ui_root;
|
||||
|
||||
VkImageView zbuffer_view;
|
||||
VkImageView IT1_view;
|
||||
@ -769,13 +757,11 @@ struct Alice {
|
||||
};
|
||||
|
||||
/* No buffer rerecording, no buffer beginning, no buffer ending,
|
||||
* 1) It copies initial generic model and shiny model topology. Textures of generic models included
|
||||
* 2) For all models and for all light sources it copies EVERYTHING.
|
||||
* You won't normally need to copy every single thing, but here you have the most bold solution.
|
||||
* 3) As mentioned before, Pipeline0UBO also gets copied
|
||||
*/
|
||||
void AliceScene__another_frame(Alice* alice) {
|
||||
|
||||
for (ListNodeAliceGenericMeshHand* mm_node = alice->generic_models.first; mm_node; mm_node = mm_node->next) {
|
||||
AliceGenericMeshHand* mm = &mm_node->el;
|
||||
assert(mm->instance_attr.count * sizeof(GenericMeshInstance) <= mm->instance_attr.staging.len);
|
||||
@ -859,7 +845,7 @@ void alice_reset_and_record_command_buffer_0(Alice* alice, mat4 proj_cam_t) {
|
||||
vkCmdPushConstants(alice->rendering_command_buf_0, alice->pipeline_hands_0a.pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT,
|
||||
0, sizeof(mat4), &proj_cam_t);
|
||||
vkCmdPushConstants(alice->rendering_command_buf_0, alice->pipeline_hands_0a.pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
sizeof(mat4), sizeof(vec3), &alice->cam_info.cam.pos);
|
||||
sizeof(mat4), sizeof(vec3), &alice->camera_pos);
|
||||
vkCmdBindDescriptorSets(
|
||||
alice->rendering_command_buf_0, VK_PIPELINE_BIND_POINT_GRAPHICS, alice->pipeline_hands_0a.pipeline_layout,
|
||||
0, 2,
|
||||
@ -888,7 +874,7 @@ void alice_reset_and_record_command_buffer_0(Alice* alice, mat4 proj_cam_t) {
|
||||
vkCmdPushConstants(alice->rendering_command_buf_0, alice->pipeline_hands_0b.pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT,
|
||||
0, sizeof(mat4), &proj_cam_t);
|
||||
vkCmdPushConstants(alice->rendering_command_buf_0, alice->pipeline_hands_0b.pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
sizeof(mat4), sizeof(vec3), &alice->cam_info.cam.pos);
|
||||
sizeof(mat4), sizeof(vec3), &alice->camera_pos);
|
||||
vkCmdBindDescriptorSets(
|
||||
alice->rendering_command_buf_0, VK_PIPELINE_BIND_POINT_GRAPHICS, alice->pipeline_hands_0b.pipeline_layout,
|
||||
0, 1, &alice->descriptor_set0_for_pipeline_0, 0, NULL);
|
||||
@ -1069,12 +1055,6 @@ void alice_frame_drawing(Alice* alice) {
|
||||
|
||||
U32 win_width = alice->wl.width_confirmed;
|
||||
U32 win_height = alice->wl.height_confirmed;
|
||||
mat4 projection_matrix = marie_perspective_projection_fov_mat4(
|
||||
(float)win_width, (float)win_height,
|
||||
alice->cam_info.cam.fov, 0.01f, 1000);
|
||||
mat4 camera_rotation_matrix = marie_mat3_to_mat4_transposed(alice->cam_info.cam.cam_basis);
|
||||
mat4 camera_translation_matrix = marie_translation_mat4(vec3_minus(alice->cam_info.cam.pos));
|
||||
mat4 t_mat = mat4_mul_mat4(projection_matrix, mat4_mul_mat4(camera_rotation_matrix, camera_translation_matrix));
|
||||
|
||||
/* This is not related to command recording */
|
||||
Plain2dShapeRenderer_clear(&alice->plain_shape_renderer);
|
||||
@ -1091,15 +1071,16 @@ void alice_frame_drawing(Alice* alice) {
|
||||
alice->callbacks.on_another_frame(alice->callbacks.guest, (float)(alice->wl.cur_frame_time - alice->wl.last_frame_time) / 1000);
|
||||
AliceScene__another_frame(alice);
|
||||
// LucyGlyphCache_another_frame(&alice->lucy_cache); lucy cache has no business here... Well, maybe later
|
||||
MutRefWidget_draw_prepare(alice->overlay_ui_root, (uvec2){win_width, win_height});
|
||||
MutRefWidget_draw(alice->overlay_ui_root, (ivec2){0}, (uvec2){win_width, win_height}, (BorderS32){.lt = {0},
|
||||
.rb.x = (S32)win_width, .rb.y = (S32)win_height});
|
||||
|
||||
// MutRefWidget_draw_prepare(alice->overlay_ui_root, (uvec2){win_width, win_height});
|
||||
// MutRefWidget_draw(alice->overlay_ui_root, (ivec2){0}, (uvec2){win_width, win_height}, (BorderS32){.lt = {0},
|
||||
// .rb.x = (S32)win_width, .rb.y = (S32)win_height});
|
||||
Plain2dShapeRenderer_another_frame(&alice->plain_shape_renderer);
|
||||
LucyRenderer_another_frame(&alice->lucy_renderer);
|
||||
margaret_end_command_buffer(alice->transfer_command_buf);
|
||||
margaret_end_command_buffer(alice->compute_command_buf);
|
||||
|
||||
alice_reset_and_record_command_buffer_0(alice, t_mat);
|
||||
alice_reset_and_record_command_buffer_0(alice, alice->cam_proj_t_mat);
|
||||
alice_reset_and_record_command_buffer_1(alice, *VecVkFramebuffer_at(&alice->swfb.framebuffers, ij));
|
||||
|
||||
check(vkQueueSubmit(alice->queues.graphics, 1, &(VkSubmitInfo){
|
||||
@ -1334,9 +1315,8 @@ static void alice_mainloop_h_wl_pointer_motion(
|
||||
void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y
|
||||
) {
|
||||
Alice* alice = data;
|
||||
AliceCamVerticalControl_update_direction(&alice->cam_info,
|
||||
alice->wl.width_confirmed, alice->wl.height_confirmed,
|
||||
(float)surface_x / 256.f, (float)surface_y / 256.f);
|
||||
alice->callbacks.on_wl_pointer_motion(alice->callbacks.guest,
|
||||
(vec2){(float)surface_x / 256.f, (float)surface_y / 256.f});
|
||||
}
|
||||
|
||||
static void alice_mainloop_h_wl_pointer_button(
|
||||
@ -1615,7 +1595,6 @@ Alice* Alice_new(){
|
||||
|
||||
alice->texture_slots = VecAliceTextureSlot_new_zeroinit(ALICE_MAX_TEXTURES_COUNT);
|
||||
|
||||
alice->cam_info = AliceCamVerticalControl_new();
|
||||
alice->rendering_config = AliceRenderConfig_new();
|
||||
|
||||
alice->IT1_image = MargaretImgAllocator_alloc(alice->dev_local_images,
|
||||
@ -1640,7 +1619,7 @@ Alice* Alice_new(){
|
||||
|
||||
alice->lucy_renderer = LucyRenderer_new(engine_reference, &alice->lucy_cache, root_dir, alice->render_pass_1, 0);
|
||||
|
||||
alice->overlay_ui_root = (MutRefWidget){NULL, NULL};
|
||||
// alice->overlay_ui_root = (MutRefWidget){NULL, NULL};
|
||||
|
||||
// Creating framebuffer for IT1, image views for IT1 and zbuffer
|
||||
// Creating descriptor set for pipeline 0b and for pipeline 1 (containing IT1 sampler)
|
||||
@ -1732,6 +1711,8 @@ ListNodeAliceGenericMeshHand* Alice_add_generic_mesh(Alice* alice, const Generic
|
||||
){
|
||||
ListNodeAliceGenericMeshHand* mm_node = safe_calloc(1, sizeof(ListNodeAliceGenericMeshHand));
|
||||
AliceGenericMeshHand* mm = &mm_node->el;
|
||||
mm->p = alice;
|
||||
|
||||
mm->indexes = topology->indexes.len;
|
||||
mm->instance_attr.count = 0;
|
||||
mm->instance_attr.staging = MargaretBufAllocator_alloc(alice->staging_buffers, 200);
|
||||
@ -1794,6 +1775,7 @@ ListNodeAliceGenericMeshHand* Alice_add_generic_mesh(Alice* alice, const Generic
|
||||
ListNodeAliceShinyMeshHand* Alice_add_shiny_mesh(Alice* alice, const ShinyMeshTopology* topology){
|
||||
ListNodeAliceShinyMeshHand* mm_node = safe_calloc(1, sizeof(ListNodeAliceShinyMeshHand));
|
||||
AliceShinyMeshHand* mm = &mm_node->el;
|
||||
mm->p = alice;
|
||||
|
||||
mm->indexes = topology->indexes.len;
|
||||
|
||||
@ -1866,29 +1848,29 @@ void Alice_delete_shiny_mesh(Alice* alice, ListNodeAliceShinyMeshHand* hand) {
|
||||
}
|
||||
|
||||
|
||||
void AliceGenericMeshHand_resize_instance_arr(Alice* alice, AliceGenericMeshHand* self, U64 new_count){
|
||||
void AliceAcknGenericMesh_resize_instance_arr(AliceAcknGenericMesh self, U64 new_count){
|
||||
U64 needed_length = new_count * sizeof(GenericMeshInstance);
|
||||
if (self->instance_attr.staging.len < needed_length) {
|
||||
if (self->el.instance_attr.staging.len < needed_length) {
|
||||
printf("Alice generic model instance staging Buffer: Gotta replace %lu with %lu\n",
|
||||
self->instance_attr.staging.len, needed_length);
|
||||
self->el.instance_attr.staging.len, needed_length);
|
||||
MargaretBufAllocator_expand_or_move_old_host_visible(
|
||||
alice->staging_buffers, &self->instance_attr.staging, needed_length);
|
||||
self->el.p->staging_buffers, &self->el.instance_attr.staging, needed_length);
|
||||
}
|
||||
self->instance_attr.count = new_count;
|
||||
self->el.instance_attr.count = new_count;
|
||||
}
|
||||
|
||||
void AliceShinyMeshHand_resize_instance_arr(Alice* alice, AliceShinyMeshHand* self, U64 new_count){
|
||||
void AliceAcknShinyMesh_resize_instance_arr(AliceAcknShinyMesh self, U64 new_count){
|
||||
U64 needed_length = new_count * sizeof(ShinyMeshInstance);
|
||||
if (self->instance_attr.staging.len < needed_length) {
|
||||
if (self->el.instance_attr.staging.len < needed_length) {
|
||||
MargaretBufAllocator_expand_or_move_old_host_visible(
|
||||
alice->staging_buffers, &self->instance_attr.staging, needed_length);
|
||||
self->el.p->staging_buffers, &self->el.instance_attr.staging, needed_length);
|
||||
}
|
||||
self->instance_attr.count = new_count;
|
||||
self->el.instance_attr.count = new_count;
|
||||
}
|
||||
|
||||
void AliceGenericMeshHand_set_inst(AliceGenericMeshHand* self, size_t instance, GenericMeshInstanceInc uncomp){
|
||||
assert(instance < self->instance_attr.count);
|
||||
GenericMeshInstance* staging = (GenericMeshInstance*)MargaretSubbuf_get_mapped(&self->instance_attr.staging);
|
||||
void AliceAcknGenericMesh_set_inst(AliceAcknGenericMesh self, U64 instance, GenericMeshInstanceInc uncomp){
|
||||
assert(instance < self->el.instance_attr.count);
|
||||
GenericMeshInstance* staging = (GenericMeshInstance*)MargaretSubbuf_get_mapped(&self->el.instance_attr.staging);
|
||||
staging[instance].base = uncomp;
|
||||
mat4 tr_inv = mat4_transpose(mat4_inverse(uncomp.model_t));
|
||||
staging[instance].normal_t = mat3_new(
|
||||
@ -1897,7 +1879,7 @@ void AliceGenericMeshHand_set_inst(AliceGenericMeshHand* self, size_t instance,
|
||||
tr_inv.x.z, tr_inv.y.z, tr_inv.z.z );
|
||||
}
|
||||
|
||||
void AliceShinyMeshHand_set_inst(AliceShinyMeshHand* self, size_t instance, ShinyMeshInstanceInc uncomp){
|
||||
void AliceAcknShinyMesh_set_inst(AliceShinyMeshHand* self, U64 instance, ShinyMeshInstanceInc uncomp){
|
||||
assert(instance < self->instance_attr.count);
|
||||
ShinyMeshInstance* staging = (ShinyMeshInstance*)MargaretSubbuf_get_mapped(&self->instance_attr.staging);
|
||||
staging[instance].base = uncomp;
|
||||
@ -1935,6 +1917,7 @@ void Alice_mainloop(Alice* alice, const AliceCallbacks* callbacks) {
|
||||
alice->callbacks.on_wl_pointer_button = callbacks->on_wl_pointer_button,
|
||||
alice->callbacks.on_wl_keyboard_key = callbacks->on_wl_keyboard_key;
|
||||
alice->callbacks.on_another_frame = callbacks->on_another_frame;
|
||||
alice->callbacks.on_wl_pointer_motion = callbacks->on_wl_pointer_motion;
|
||||
alice->callbacks.guest = callbacks->guest;
|
||||
printf("ENTERING WAYLAND MAINLOOP\n");
|
||||
alice->wl.closed = false;
|
||||
@ -2000,4 +1983,14 @@ void Alice_lucy_renderer_add_simple_label(Alice* alice, RBTreeNodeLucyFaceFixedS
|
||||
vec4 color, S32 additional_y_advance, SpanU8 text, ivec2 start_pos
|
||||
) {
|
||||
LucyRenderer_add_simple_label(&alice->lucy_renderer, ffs, color, additional_y_advance, text, start_pos);
|
||||
}
|
||||
}
|
||||
|
||||
ivec2 Alice_get_wl_confirmed_win_sz(Alice* alice) {
|
||||
return (ivec2){alice->wl.width_confirmed, alice->wl.height_confirmed};
|
||||
}
|
||||
|
||||
void Alice_set_camera_info(Alice* alice, mat4 projection_matrix, vec3 cam_pos) {
|
||||
printf("DEBUG: we set camera info to something sane\n");
|
||||
alice->cam_proj_t_mat = projection_matrix;
|
||||
alice->camera_pos = cam_pos;
|
||||
}
|
||||
|
||||
@ -2,9 +2,15 @@
|
||||
|
||||
#include "../../../gen/l1/allie_cpp/geom.hpp"
|
||||
|
||||
#include "assets.hpp"
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
typedef void* allie_LucyFaceFixedSize;
|
||||
typedef void* allie_LucyFace;
|
||||
typedef void* allie_AliceAcknGenericMesh;
|
||||
typedef void* allie_Alice;
|
||||
|
||||
/* Actually it is RBTreeNodeLucyFaceFixedSize */
|
||||
struct LucyFaceFixedSize {
|
||||
ALLIE_CPP_OPAQUE(LucyFaceFixedSize)
|
||||
@ -15,7 +21,7 @@ struct LucyFaceFixedSize {
|
||||
};
|
||||
|
||||
struct allie_LucyGlyphCachingRequest {
|
||||
void* sized_face;
|
||||
allie_LucyFaceFixedSize sized_face;
|
||||
allie_VecU32Segment codepoint_ranges;
|
||||
};
|
||||
|
||||
@ -31,7 +37,7 @@ struct LucyGlyphCachingRequest {
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
void* allie_LucyFace_of_size(void* self, U32 size);
|
||||
allie_LucyFaceFixedSize allie_LucyFace_of_size(allie_LucyFace self, U32 size);
|
||||
}
|
||||
|
||||
struct LucyFace {
|
||||
@ -46,6 +52,28 @@ struct LucyFace {
|
||||
}
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
void allie_AliceAcknGenericMesh_resize_instance_arr(allie_AliceAcknGenericMesh self, U64 new_count);
|
||||
void allie_AliceAcknGenericMesh_set_inst(allie_AliceAcknGenericMesh self, U64 index, GenericMeshInstanceInc uncomp);
|
||||
}
|
||||
|
||||
struct AliceAcknGenericMesh {
|
||||
/* ListNodeAliceGenericMeshHand */
|
||||
ALLIE_CPP_OPAQUE(AliceAcknGenericMesh)
|
||||
explicit AliceAcknGenericMesh(void* opa): opa(opa){}
|
||||
|
||||
// todo: implement
|
||||
~AliceAcknGenericMesh() = default;
|
||||
|
||||
void resize_instance_arr(U64 new_count) noexcept {
|
||||
allie_AliceAcknGenericMesh_resize_instance_arr(opa, new_count);
|
||||
}
|
||||
|
||||
void set_inst(U64 index, GenericMeshInstanceInc uncomp) noexcept {
|
||||
allie_AliceAcknGenericMesh_set_inst(opa, index, uncomp);
|
||||
}
|
||||
};
|
||||
|
||||
struct Alice;
|
||||
|
||||
struct AliceCallbacks {
|
||||
@ -58,14 +86,22 @@ struct AliceCallbacks {
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
void* allie_Alice_new();
|
||||
void allie_Alice_mainloop(void*, const AliceCallbacks*);
|
||||
void* allie_Alice_new_LucyFace(void* alice, allie_SpanU8 path);
|
||||
void allie_Alice_lucy_cache_add_glyphs(void* alice, allie_VecLucyGlyphCachingRequest req);
|
||||
void allie_Alice_lucy_renderer_add_simple_label(void* alice, void* ffs,
|
||||
allie_Alice allie_Alice_new();
|
||||
void allie_Alice_mainloop(allie_Alice, const AliceCallbacks*);
|
||||
allie_LucyFace allie_Alice_new_LucyFace(allie_Alice alice, allie_SpanU8 path);
|
||||
void allie_Alice_lucy_cache_add_glyphs(allie_Alice alice, allie_VecLucyGlyphCachingRequest req);
|
||||
void allie_Alice_lucy_renderer_add_simple_label(allie_Alice alice, void* ffs,
|
||||
vec4 color, S32 additional_y_advance, allie_SpanU8 text, ivec2 start_pos);
|
||||
U32 allie_Alice_load_r8g8b8a8_texture(allie_Alice alice, allie_SpanU8 file_path);
|
||||
U32 allie_Alice_load_r8_texture(allie_Alice alice, allie_SpanU8 file_path);
|
||||
allie_AliceAcknGenericMesh allie_Alice_add_generic_mesh(allie_Alice alice,
|
||||
const allie_AliceGenericMeshTopology* topology, U32 diffuse_tex, U32 normal_tex, U32 specular_tex);
|
||||
}
|
||||
|
||||
struct AliceTextureSlot {
|
||||
U32 id;
|
||||
};
|
||||
|
||||
/* You are supposed to pass */
|
||||
struct Alice {
|
||||
ALLIE_CPP_OPAQUE(Alice)
|
||||
@ -103,4 +139,28 @@ struct Alice {
|
||||
allie_Alice_lucy_renderer_add_simple_label(opa, ffs.opa,
|
||||
color, additional_y_advance, allie_SpanU8(text), start_pos);
|
||||
}
|
||||
|
||||
AliceTextureSlot load_r8g8b8a8_texture(std::string_view path) {
|
||||
return {.id = allie_Alice_load_r8g8b8a8_texture(opa, allie_SpanU8(path))};
|
||||
}
|
||||
|
||||
AliceTextureSlot load_r8_texture(std::string_view path) {
|
||||
return {.id = allie_Alice_load_r8_texture(opa, allie_SpanU8(path))};
|
||||
}
|
||||
|
||||
AliceAcknGenericMesh add_generic_mesh(
|
||||
const AliceGenericMeshTopology& top,
|
||||
AliceTextureSlot& diffuse_tex, AliceTextureSlot& normal_tex, AliceTextureSlot& specular_tex) {
|
||||
|
||||
allie_AliceGenericMeshTopology a_top{};
|
||||
allie_form_a_cvec_of_matching_types<AliceGenericMeshVertexInc, allie_VecAliceGenericMeshVertexInc>(a_top.vertices, top.vertices);
|
||||
allie_form_a_cvec_of_matching_types<U32, allie_VecU32>(a_top.indexes, top.indexes);
|
||||
|
||||
allie_AliceAcknGenericMesh hand = allie_Alice_add_generic_mesh(opa, &a_top,
|
||||
diffuse_tex.id, normal_tex.id, specular_tex.id);
|
||||
|
||||
free(a_top.vertices.buf);
|
||||
free(a_top.indexes.buf);
|
||||
return AliceAcknGenericMesh(hand);
|
||||
}
|
||||
};
|
||||
|
||||
57
src/l2/allie_cpp/assets.hpp
Normal file
57
src/l2/allie_cpp/assets.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../gen/l1/allie_cpp/geom.hpp"
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
struct AliceGenericMeshVertexInc {
|
||||
vec3 pos;
|
||||
vec2 tex;
|
||||
};
|
||||
|
||||
struct allie_VecAliceGenericMeshVertexInc {
|
||||
AliceGenericMeshVertexInc* buf;
|
||||
U64 len;
|
||||
U64 capacity;
|
||||
};
|
||||
|
||||
struct allie_VecU32 {
|
||||
U32* buf;
|
||||
U64 len;
|
||||
U64 capacity;
|
||||
};
|
||||
|
||||
struct allie_AliceGenericMeshTopology {
|
||||
allie_VecAliceGenericMeshVertexInc vertices;
|
||||
allie_VecU32 indexes;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
allie_AliceGenericMeshTopology allie_alice_expect_read_generic_mesh_from_file(allie_SpanU8 file_path);
|
||||
}
|
||||
|
||||
struct AliceGenericMeshTopology {
|
||||
std::vector<AliceGenericMeshVertexInc> vertices;
|
||||
std::vector<U32> indexes;
|
||||
};
|
||||
|
||||
AliceGenericMeshTopology alice_expect_read_generic_mesh_from_file(std::string_view file_path) {
|
||||
allie_AliceGenericMeshTopology a_top = allie_alice_expect_read_generic_mesh_from_file(allie_SpanU8(file_path));
|
||||
AliceGenericMeshTopology top{};
|
||||
top.vertices.resize(a_top.vertices.len);
|
||||
memcpy(top.vertices.data(), a_top.vertices.buf, a_top.vertices.len * sizeof(AliceGenericMeshVertexInc));
|
||||
|
||||
top.indexes.resize(a_top.indexes.len);
|
||||
memcpy(top.indexes.data(), a_top.indexes.buf, a_top.indexes.len * sizeof(U32));
|
||||
return top;
|
||||
}
|
||||
|
||||
struct GenericMeshInstanceInc {
|
||||
mat4 model_t;
|
||||
};
|
||||
|
||||
|
||||
// struct AliceShinyMeshVertexInc {
|
||||
// vec3 pos;
|
||||
// vec3 color;
|
||||
// };
|
||||
@ -30,3 +30,30 @@ void allie_Alice_lucy_renderer_add_simple_label(Alice* alice, RBTreeNodeLucyFace
|
||||
) {
|
||||
Alice_lucy_renderer_add_simple_label(alice, ffs, color, additional_y_advance, text, start_pos);
|
||||
}
|
||||
|
||||
/* This has nothing to do with game engine API, GenericMeshTopology is just a datatype that holds model data */
|
||||
GenericMeshTopology allie_alice_expect_read_generic_mesh_from_file(SpanU8 file_path) {
|
||||
return alice_expect_read_generic_mesh_from_file(VecU8_from_span(file_path));
|
||||
}
|
||||
|
||||
U32 allie_Alice_load_r8g8b8a8_texture(Alice* alice, SpanU8 file_path) {
|
||||
return Alice_load_r8g8b8a8_texture(alice, VecU8_from_span(file_path));
|
||||
}
|
||||
|
||||
U32 allie_Alice_load_r8_texture(Alice* alice, SpanU8 file_path) {
|
||||
return Alice_load_r8_texture(alice, VecU8_from_span(file_path));
|
||||
}
|
||||
|
||||
|
||||
AliceAcknGenericMesh allie_Alice_add_generic_mesh(Alice* alice,
|
||||
const GenericMeshTopology* top, U32 diffuse_tex_slot, U32 normal_tex_slot, U32 specular_tex_slot) {
|
||||
return Alice_add_generic_mesh(alice, top, diffuse_tex_slot, normal_tex_slot, specular_tex_slot);
|
||||
}
|
||||
|
||||
void allie_AliceAcknGenericMesh_resize_instance_arr(AliceAcknGenericMesh self, U64 new_count) {
|
||||
AliceAcknGenericMesh_resize_instance_arr(self, new_count);
|
||||
}
|
||||
|
||||
void allie_AliceAcknGenericMesh_set_inst(AliceAcknGenericMesh self, U64 index, GenericMeshInstanceInc uncomp) {
|
||||
AliceAcknGenericMesh_set_inst(self, index, uncomp);
|
||||
}
|
||||
|
||||
127
src/l2/allie_cpp/graphics_geom.hpp
Normal file
127
src/l2/allie_cpp/graphics_geom.hpp
Normal file
@ -0,0 +1,127 @@
|
||||
/* This is just the exact copy of l1_5/marie/graphics_geom.h */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../../gen/l1/allie_cpp/geom.hpp"
|
||||
|
||||
// todo: rewrite this shit after I rewrite
|
||||
|
||||
mat4 marie_translation_mat4(vec3 vec) {
|
||||
return mat4_new(
|
||||
1, 0, 0, vec.x,
|
||||
0, 1, 0, vec.y,
|
||||
0, 0, 1, vec.z,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
mat2 marie_2d_rot_mat2(float a) {
|
||||
float cosa = cosf(a);
|
||||
float sina = sinf(a);
|
||||
return mat2_new(
|
||||
cosa, -sina,
|
||||
sina, cosa);
|
||||
}
|
||||
|
||||
mat3 marie_3d_rot_mat3(vec3 r, float a) {
|
||||
float cosa = cosf(a);
|
||||
float sina = sinf(a);
|
||||
return mat3_new(
|
||||
r.x * r.x * (1 - cosa) + cosa, r.x * r.y * (1 - cosa) - sina * r.z, r.x * r.z * (1 - cosa) + sina * r.y,
|
||||
r.x * r.y * (1 - cosa) + sina * r.z, r.y * r.y * (1 - cosa) + cosa, r.y * r.z * (1 - cosa) - sina * r.x,
|
||||
r.x * r.z * (1 - cosa) - sina * r.y, r.y * r.z * (1 - cosa) + sina * r.x, r.z * r.z * (1 - cosa) + cosa
|
||||
);
|
||||
}
|
||||
|
||||
mat4 marie_mat3_to_mat4(mat3 A) {
|
||||
return mat4_new(
|
||||
A.x.x, A.y.x, A.z.x, 0,
|
||||
A.x.y, A.y.y, A.z.y, 0,
|
||||
A.x.z, A.y.z, A.z.z, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
mat4 marie_mat3_to_mat4_transposed(mat3 A) {
|
||||
return mat4_new(
|
||||
A.x.x, A.x.y, A.x.z, 0,
|
||||
A.y.x, A.y.y, A.y.z, 0,
|
||||
A.z.x, A.z.y, A.z.z, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
mat4 marie_3d_rot_mat4(vec3 r, float a) {
|
||||
return marie_mat3_to_mat4(marie_3d_rot_mat3(r, a));
|
||||
}
|
||||
|
||||
|
||||
mat4 marie_perspective_projection_mat4(float right, float top, float near, float far) {
|
||||
return mat4_new(
|
||||
near/right, 0, 0, 0,
|
||||
0, -near/top, 0, 0,
|
||||
0, 0, (far + near) / (near - far), 2 * far * near / (near - far),
|
||||
0, 0, -1, 0 );
|
||||
}
|
||||
|
||||
mat4 marie_perspective_projection_fov_mat4(float win_width, float win_height, float fov,
|
||||
float spat_frustum_near, float spat_frustum_far) {
|
||||
float right = tanf(fov / 2) * spat_frustum_near;
|
||||
float top = win_height * right / win_width;
|
||||
return marie_perspective_projection_mat4(right, top, spat_frustum_near, spat_frustum_far);
|
||||
}
|
||||
|
||||
|
||||
mat3 marie_simple_camera_rot_m_basis_in_cols(float yaw, float pitch, float roll) {
|
||||
float cos_ya = cosf(yaw);
|
||||
float sin_ya = sinf(yaw);
|
||||
float cos_pi = cosf(pitch);
|
||||
float sin_pi = sinf(pitch);
|
||||
float cos_ro = cosf(roll);
|
||||
float sin_ro = sinf(roll);
|
||||
return mat3(
|
||||
vec3{cos_ro * cos_ya + sin_ro * sin_pi * sin_ya, sin_ro * cos_pi, -cos_ro * sin_ya + sin_ro * sin_pi * cos_ya},
|
||||
vec3{-sin_ro * cos_ya + cos_ro * sin_pi * sin_ya, cos_ro * cos_pi, sin_ro * sin_ya + cos_ro * sin_pi * cos_ya},
|
||||
vec3{cos_pi * sin_ya, -sin_pi, cos_pi * cos_ya}
|
||||
);
|
||||
}
|
||||
|
||||
vec2 marie_trigonom_circle(float angle) {
|
||||
return vec2{.x=cosf(angle), .y=sinf(angle)};
|
||||
}
|
||||
|
||||
vec3 marie_normal_from_tang_space_gradient(float delt_x, float delta_z) {
|
||||
float N = 1 / sqrtf(delt_x * delt_x + delta_z * delta_z + 1);
|
||||
return vec3(-delt_x * N, N, -delta_z * N);
|
||||
}
|
||||
|
||||
mat4 marie_3d_scal_mat4(float scale){
|
||||
return mat4_new(scale, 0, 0, 0,
|
||||
0, scale, 0, 0,
|
||||
0, 0, scale, 0,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
// vec2 ivec2_to_vec2(ivec2 v){
|
||||
// return (vec2){(float)v.x, (float)v.y};
|
||||
// }
|
||||
//
|
||||
// uvec2 ivec2_to_uvec2(ivec2 v) {
|
||||
// return uvec2{v.x, v.y};
|
||||
// }
|
||||
|
||||
// ivec2 uvec2_to_ivec2(uvec2 v) {
|
||||
// return (ivec2){(S32)v.x, (S32)v.y};
|
||||
// }
|
||||
|
||||
typedef struct{
|
||||
ivec2 lt, rb;
|
||||
} BorderS32;
|
||||
|
||||
bool BorderS32_empty(BorderS32 self){
|
||||
return self.lt.x >= self.rb.x || self.lt.y >= self.rb.y;
|
||||
}
|
||||
|
||||
BorderS32 BorderS32_intersect(BorderS32 a, BorderS32 b){
|
||||
return (BorderS32){
|
||||
{std::max(a.lt.x, b.lt.x), std::min(a.lt.y, b.lt.y)},
|
||||
{std::max(a.rb.x, b.rb.x), std::min(a.rb.y, b.rb.y)},
|
||||
};
|
||||
}
|
||||
@ -32,9 +32,9 @@ void allie_lucy_face_add_glyphs(RBTreeNodeLucyFaceFixedSize* face_fs, U32 start,
|
||||
// LucyGlyphCache_add_glyphs(lucy_requests, );
|
||||
}
|
||||
|
||||
void allie_alice_clear_text(Alice* alice){
|
||||
LucyRenderer_clear(&alice->lucy_renderer);
|
||||
}
|
||||
// void allie_alice_clear_text(Alice* alice){
|
||||
// LucyRenderer_clear(&alice->lucy_renderer);
|
||||
// }
|
||||
|
||||
void allie_alice_add_text(Alice* alice, RBTreeNodeLucyFaceFixedSize* ffs,
|
||||
float color_x, float color_y, float color_z, float color_w, const U8* text_data, U64 text_len,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#include "../../l2/gui/colorblock.h"
|
||||
#include "../../l2/gui/colorframe.h"
|
||||
#include "../../l2/gui/stacks.h"
|
||||
|
||||
#include "../../l2/alice/camera.h"
|
||||
#include "linux/input-event-codes.h"
|
||||
|
||||
|
||||
@ -86,6 +86,8 @@ typedef struct{
|
||||
Alice* alice;
|
||||
LucyFace* font_face;
|
||||
RBTreeNodeLucyFaceFixedSize* font_face_of_size_40;
|
||||
|
||||
AliceCamVerticalControl cam;
|
||||
vec3 hero_pos;
|
||||
|
||||
U32 ROA_diffuse_tex_slot;
|
||||
@ -153,8 +155,8 @@ void main_h_on_wl_pointer_button(void* data, U32 button, U32 act){
|
||||
R4BetaState *st = data;
|
||||
Alice* alice = st->alice;
|
||||
if (button == BTN_LEFT && act == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
vec3 P = alice->cam_info.cam.pos;
|
||||
vec3 dir = vec3_minus(alice->cam_info.cam.cam_basis.z);
|
||||
vec3 P = st->cam.cam.pos;
|
||||
vec3 dir = vec3_minus(st->cam.cam.cam_basis.z);
|
||||
vec3 Q = vec3_add_vec3(P, dir);
|
||||
bool hit = false;
|
||||
vec3 impact;
|
||||
@ -229,11 +231,27 @@ void main_h_on_wl_keyboard_key(void* data, U32 keysym, U32 act){
|
||||
}
|
||||
}
|
||||
|
||||
void main_h_on_wl_pointer_motion(void* data, vec2 pos) {
|
||||
R4BetaState* st = data;
|
||||
ivec2 win_sz = Alice_get_wl_confirmed_win_sz(st->alice);
|
||||
AliceCamVerticalControl_update_direction(&st->cam, win_sz.x, win_sz.y, pos.x, pos.y);
|
||||
}
|
||||
|
||||
// todo: fuck, return this to Alice. Frustum config is needed in uh, later it will be needed
|
||||
mat4 get_t_mat(R4BetaState* st) {
|
||||
ivec2 win_sz = Alice_get_wl_confirmed_win_sz(st->alice);
|
||||
mat4 projection_matrix = marie_perspective_projection_fov_mat4(
|
||||
(float)win_sz.x, (float)win_sz.y, st->cam.cam.fov, 0.01f, 1000);
|
||||
mat4 camera_rotation_matrix = marie_mat3_to_mat4_transposed(st->cam.cam.cam_basis);
|
||||
mat4 camera_translation_matrix = marie_translation_mat4(vec3_minus(st->cam.cam.pos));
|
||||
return mat4_mul_mat4(projection_matrix, mat4_mul_mat4(camera_rotation_matrix, camera_translation_matrix));
|
||||
}
|
||||
|
||||
void main_h_on_another_frame(void* data, float fl){
|
||||
R4BetaState *st = data;
|
||||
Alice* alice = st->alice;
|
||||
vec3 proj_back = project_dir_onto_plane_xz(alice->cam_info.cam.cam_basis.z);
|
||||
vec3 proj_right = project_dir_onto_plane_xz(alice->cam_info.cam.cam_basis.x);
|
||||
vec3 proj_back = project_dir_onto_plane_xz(st->cam.cam.cam_basis.z);
|
||||
vec3 proj_right = project_dir_onto_plane_xz(st->cam.cam.cam_basis.x);
|
||||
const float max_speed = 10.f;
|
||||
if (alice->wl.first_0x80_keys['w']) {
|
||||
st->hero_pos = vec3_minus_vec3(st->hero_pos, vec3_mul_scal(proj_back, fl * max_speed));
|
||||
@ -253,11 +271,11 @@ void main_h_on_another_frame(void* data, float fl){
|
||||
if (alice->wl.first_0x80_keys['q']) {
|
||||
st->hero_pos = vec3_add_vec3(st->hero_pos, (vec3){0, -max_speed * fl, 0});
|
||||
}
|
||||
alice->cam_info.cam.pos = st->hero_pos;
|
||||
st->cam.cam.pos = st->hero_pos;
|
||||
|
||||
physics_update(st, fl);
|
||||
|
||||
AliceGenericMeshHand_set_inst(&st->ROA_mesh->el, 0, (GenericMeshInstanceInc){
|
||||
AliceAcknGenericMesh_set_inst(st->ROA_mesh, 0, (GenericMeshInstanceInc){
|
||||
.model_t = RigidBodyState_get_tran_mat_of_mesh(&st->ROA_state),
|
||||
});
|
||||
|
||||
@ -268,12 +286,12 @@ void main_h_on_another_frame(void* data, float fl){
|
||||
Alice_set_point_light_count(alice, st->LS_state.len);
|
||||
}
|
||||
if (st->LS_state.len + st->bullets_stuck_on_ROA.len > st->LS_mesh->el.instance_attr.count) {
|
||||
AliceShinyMeshHand_resize_instance_arr(alice, &st->LS_mesh->el, st->LS_state.len + st->bullets_stuck_on_ROA.len);
|
||||
AliceAcknShinyMesh_resize_instance_arr(st->LS_mesh, st->LS_state.len + st->bullets_stuck_on_ROA.len);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < st->LS_state.len; i++) {
|
||||
LightSourceState* ls = &st->LS_state.buf[i];
|
||||
AliceShinyMeshHand_set_inst(&st->LS_mesh->el, i, (ShinyMeshInstanceInc){
|
||||
AliceAcknShinyMesh_set_inst(&st->LS_mesh->el, i, (ShinyMeshInstanceInc){
|
||||
.color_on = ls->color,
|
||||
.model_t = marie_translation_mat4(ls->pos),
|
||||
});
|
||||
@ -282,7 +300,7 @@ void main_h_on_another_frame(void* data, float fl){
|
||||
|
||||
for (size_t i = 0; i < st->bullets_stuck_on_ROA.len; i++) {
|
||||
vec3 bul_pos = st->bullets_stuck_on_ROA.buf[i];
|
||||
AliceShinyMeshHand_set_inst(&st->LS_mesh->el, st->LS_state.len + i, (ShinyMeshInstanceInc){
|
||||
AliceAcknShinyMesh_set_inst(&st->LS_mesh->el, st->LS_state.len + i, (ShinyMeshInstanceInc){
|
||||
.color_on = (vec3){2, 0, 0},
|
||||
.model_t = mat4_mul_mat4(mat4_mul_mat4(
|
||||
RigidBodyState_get_tran_mat(&st->ROA_state),
|
||||
@ -291,7 +309,9 @@ void main_h_on_another_frame(void* data, float fl){
|
||||
});
|
||||
}
|
||||
|
||||
LucyRenderer_clear(&alice->lucy_renderer);
|
||||
Alice_set_camera_info(alice, get_t_mat(st), st->cam.cam.pos);
|
||||
|
||||
|
||||
VecU8 text = VecU8_new();
|
||||
VecU8_append_fmt(&text, "Bullet mass = %v ; bullet velocity = %v\n",
|
||||
VecU8_format("%.4f", st->bullet_config.mass), VecU8_format("%.4f", st->bullet_config.velocity));
|
||||
@ -312,6 +332,8 @@ void main_h_on_another_frame(void* data, float fl){
|
||||
void run_app(){
|
||||
R4BetaState st;
|
||||
st.hero_pos = (vec3){0, 0.81f, 0};
|
||||
st.cam = AliceCamVerticalControl_new();
|
||||
|
||||
Alice* alice = Alice_new();
|
||||
st.alice = alice;
|
||||
|
||||
@ -336,18 +358,18 @@ void run_app(){
|
||||
cstr("..."), (ivec2){10, 10});
|
||||
|
||||
/* Recursion depth is 2 */
|
||||
st.gui_0 = ColorblockWidget_new(100, 50, (vec4){0.3f, 0.8f, 0.4f, 0.6f}, &alice->plain_shape_renderer);
|
||||
st.gui_1 = ColorframeWidget_new(100, 300, 150, 50, &alice->plain_shape_renderer, (vec4){0.7f, 0.4f, 0.2f, 0.5f},
|
||||
(MutRefWidget){.r = (Widget*)&st.gui_0, .t = &Widget_Table_ColorblockWidget});
|
||||
st.gui_2 = ColorblockWidget_new(5000, 30, (vec4){0.1f, 0.5f, 0.6f, 0.4f}, &alice->plain_shape_renderer);
|
||||
st.gui_3 = ColorblockWidget_new(120, 50, (vec4){0.2f, 0.67f, 0.4f, 0.5f}, &alice->plain_shape_renderer);
|
||||
st.gui_4 = LtoRStackWidget_new();
|
||||
VecMutRefWidget_append(&st.gui_4.children, (MutRefWidget){.r = (Widget*)&st.gui_1, &Widget_Table_ColorframeWidget});
|
||||
VecMutRefWidget_append(&st.gui_4.children, (MutRefWidget){.r = (Widget*)&st.gui_2, &Widget_Table_ColorblockWidget});
|
||||
VecMutRefWidget_append(&st.gui_4.children, (MutRefWidget){.r = (Widget*)&st.gui_3, &Widget_Table_ColorblockWidget});
|
||||
st.gui_5 = ColorframeWidget_new(70, 70, 0, 70, &alice->plain_shape_renderer, (vec4){0.1f, 0.5f, 0.3f, 0.8f},
|
||||
(MutRefWidget){.r = (Widget*)&st.gui_4, &Widget_Table_LtoRStack});
|
||||
alice->overlay_ui_root = (MutRefWidget){.r = &st.gui_5.base, .t = &Widget_Table_ColorframeWidget};
|
||||
// st.gui_0 = ColorblockWidget_new(100, 50, (vec4){0.3f, 0.8f, 0.4f, 0.6f}, &alice->plain_shape_renderer);
|
||||
// st.gui_1 = ColorframeWidget_new(100, 300, 150, 50, &alice->plain_shape_renderer, (vec4){0.7f, 0.4f, 0.2f, 0.5f},
|
||||
// (MutRefWidget){.r = (Widget*)&st.gui_0, .t = &Widget_Table_ColorblockWidget});
|
||||
// st.gui_2 = ColorblockWidget_new(5000, 30, (vec4){0.1f, 0.5f, 0.6f, 0.4f}, &alice->plain_shape_renderer);
|
||||
// st.gui_3 = ColorblockWidget_new(120, 50, (vec4){0.2f, 0.67f, 0.4f, 0.5f}, &alice->plain_shape_renderer);
|
||||
// st.gui_4 = LtoRStackWidget_new();
|
||||
// VecMutRefWidget_append(&st.gui_4.children, (MutRefWidget){.r = (Widget*)&st.gui_1, &Widget_Table_ColorframeWidget});
|
||||
// VecMutRefWidget_append(&st.gui_4.children, (MutRefWidget){.r = (Widget*)&st.gui_2, &Widget_Table_ColorblockWidget});
|
||||
// VecMutRefWidget_append(&st.gui_4.children, (MutRefWidget){.r = (Widget*)&st.gui_3, &Widget_Table_ColorblockWidget});
|
||||
// st.gui_5 = ColorframeWidget_new(70, 70, 0, 70, &alice->plain_shape_renderer, (vec4){0.1f, 0.5f, 0.3f, 0.8f},
|
||||
// (MutRefWidget){.r = (Widget*)&st.gui_4, &Widget_Table_LtoRStack});
|
||||
// alice->overlay_ui_root = (MutRefWidget){.r = &st.gui_5.base, .t = &Widget_Table_ColorframeWidget};
|
||||
|
||||
VecU8 ROA_mesh_path = vcstr("./gen/l2/models/log_10_2_6.AliceGenericMesh");
|
||||
st.ROA_topology = alice_expect_read_generic_mesh_from_file(ROA_mesh_path);
|
||||
@ -359,7 +381,7 @@ void run_app(){
|
||||
st.ROA_mesh = Alice_add_generic_mesh(st.alice, &st.ROA_topology,
|
||||
st.ROA_diffuse_tex_slot, st.ROA_normal_tex_slot, st.ROA_specular_tex_slot);
|
||||
|
||||
AliceGenericMeshHand_resize_instance_arr(st.alice, &st.ROA_mesh->el, 1);
|
||||
AliceAcknGenericMesh_resize_instance_arr(st.ROA_mesh, 1);
|
||||
const float gamma_l_c = 4.f / 3 / M_PIf;
|
||||
st.ROA_state = (RigidBodyState){
|
||||
.p.mass = 1.f * 1/4 * M_PIf * 2*2 * 10,
|
||||
@ -407,7 +429,7 @@ void run_app(){
|
||||
}
|
||||
}
|
||||
|
||||
AliceShinyMeshHand_resize_instance_arr(st.alice, &st.LS_mesh->el, st.LS_state.len);
|
||||
AliceAcknShinyMesh_resize_instance_arr(st.LS_mesh, st.LS_state.len);
|
||||
|
||||
st.bullet_config = (BulletConfig){.mass = 0.01f, .velocity = 1000};
|
||||
st.misses_count = 0;
|
||||
@ -419,6 +441,7 @@ void run_app(){
|
||||
.on_wl_pointer_button = main_h_on_wl_pointer_button,
|
||||
.on_wl_keyboard_key = main_h_on_wl_keyboard_key,
|
||||
.on_another_frame = main_h_on_another_frame,
|
||||
.on_wl_pointer_motion = main_h_on_wl_pointer_motion,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#include "../../../gen/l1/allie_cpp/geom.hpp"
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
#include "../../l2/allie_cpp/graphics_geom.hpp"
|
||||
|
||||
template<typename T>
|
||||
using unique = std::unique_ptr<T>;
|
||||
@ -44,6 +45,13 @@ int main() {
|
||||
st.face = std::make_unique<LucyFace>(st.alice->new_lucy_face("./src/l3/fonts/DMSerifText-Regular.ttf"));
|
||||
st.sized_face = std::make_unique<LucyFaceFixedSize>(st.face->of_size(40));
|
||||
st.alice->lucy_cache_add_glyphs({LucyGlyphCachingRequest{*st.sized_face, {{ .start = 32, .len = 126 - 32 + 1 }}}});
|
||||
AliceGenericMeshTopology ROA_topology = alice_expect_read_generic_mesh_from_file("./gen/l2/models/log_10_2_6.AliceGenericMesh");
|
||||
AliceTextureSlot ROA_diffuse_tex_slot = st.alice->load_r8g8b8a8_texture("./src/l3/textures/log_10_2_6_diffuse.png");
|
||||
AliceTextureSlot ROA_normal_tex_slot = st.alice->load_r8g8b8a8_texture("./gen/l2/textures/log_10_2_6_NORMAL.png");
|
||||
AliceTextureSlot ROA_specular_tex_slot = st.alice->load_r8_texture("./src/l3/textures/log_10_2_6_specular.png");
|
||||
AliceAcknGenericMesh ROA_mesh = st.alice->add_generic_mesh(ROA_topology, ROA_diffuse_tex_slot, ROA_normal_tex_slot, ROA_specular_tex_slot);
|
||||
ROA_mesh.resize_instance_arr(1);
|
||||
ROA_mesh.set_inst(0, {.model_t = marie_translation_mat4({0.2, -0.4, 0.6})});
|
||||
st.alice->mainloop({
|
||||
.guest = &st,
|
||||
.on_wl_pointer_button = main_h_on_wl_pointer_button,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user