Compare commits
5 Commits
0187ed9442
...
6664860dbf
| Author | SHA1 | Date | |
|---|---|---|---|
| 6664860dbf | |||
| b72ed8557b | |||
| 6e13ceb267 | |||
| 2655c2be3e | |||
| 29d8d8cc8a |
@ -1,10 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.30)
|
||||
project(prototype1 C)
|
||||
project(prototype1 C CXX)
|
||||
|
||||
#include_directories(${CMAKE_SOURCE_DIR})
|
||||
set(CMAKE_C_FLAGS "-Wno-unused-parameter \
|
||||
-Wall -Wextra -Werror=implicit-function-declaration -Werror=return-type \
|
||||
--std=c99 -g -ggdb -O0")
|
||||
set(CMAKE_CXX_FLAGS "-Wno-unused-parameter \
|
||||
-Wall -Wextra -Werror=return-type \
|
||||
--std=c++20 -g -ggdb -O0")
|
||||
|
||||
execute_process(
|
||||
COMMAND pkg-config --cflags libpipewire-0.3
|
||||
@ -66,3 +69,11 @@ target_link_libraries(l2_tex_gen -lm -lpng)
|
||||
|
||||
add_executable(l3_r4 src/l3/r4/r4.c gen/l_wl_protocols/xdg-shell-private.c)
|
||||
target_link_libraries(l3_r4 -lvulkan -lwayland-client -lm -lxkbcommon -lpng -lfreetype)
|
||||
|
||||
add_executable(codegen_l1_allie_cpp src/l1/allie_cpp/anne/codegen.cpp)
|
||||
|
||||
add_executable(l3_r4c
|
||||
src/l3/r4/r4c.cpp
|
||||
src/l2/allie_cpp/glue.c
|
||||
gen/l_wl_protocols/xdg-shell-private.c)
|
||||
target_link_libraries(l3_r4c -lvulkan -lwayland-client -lm -lxkbcommon -lpng -lfreetype)
|
||||
|
||||
104
Makefile
104
Makefile
@ -19,7 +19,7 @@ HEADERS_gen_l2 := gen/l2/dorothy.txt
|
||||
HEADERS_src_l3 := $(HEADERS_gen_l2) $(call find_headers,l3)
|
||||
|
||||
cflags := -Wall -Wextra -Werror=implicit-function-declaration -Werror=return-type -Wno-unused-parameter \
|
||||
--std=c99 -g -ggdb -O0 \
|
||||
--std=c99 -g -ggdb -O0 -D_FORTIFY_SOURCE=0 \
|
||||
-fno-trapping-math -D_POSIX_C_SOURCE=200112L -D_GNU_SOURCE
|
||||
cc := gcc
|
||||
|
||||
@ -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 $@ $<
|
||||
@ -95,6 +86,7 @@ gen/l_adele/dorothy.txt: $(ASSETS_src_l_adele)
|
||||
$(call compile_shader,alice/0gen,0gen)
|
||||
$(call compile_shader,alice/0sh,0sh)
|
||||
$(call compile_shader,alice/1,1)
|
||||
$(call compile_shader,drawer_2d/plain,plain)
|
||||
touch gen/l_adele/dorothy.txt
|
||||
|
||||
out/l2/t0: src/l2/tests/data_structures/t0.c $(HEADERS_gen_l1_5)
|
||||
@ -131,22 +123,6 @@ out/l2/r3: src/l2/tests/r3/r3.c $(HEADERS_src_l2) $(l_wl_protocols)
|
||||
run_r3: out/l2/r3
|
||||
./out/l2/r3
|
||||
|
||||
# Whoever needs this will also need out/l_wl_protocols
|
||||
out/l2/allie.o: src/l2/allie/allie.c $(HEADERS_src_l2) $(xdg_shell_client_h) gen/l_adele/dorothy.txt $(HEADERS_gen_l2)
|
||||
mkdir -p out/l2
|
||||
$(cc) $(cflags) -o $@ -c $< -lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
|
||||
|
||||
full_allie_obj := out/l2/allie.o $(xdg_shell_private_o)
|
||||
|
||||
out/l3/r4: src/l3/r4/R4.hs src/l2/allie/Allie.hs $(full_allie_obj)
|
||||
mkdir -p out/l3
|
||||
ghc -isrc/l2/allie -hidir out/l3/ -odir out/l3 -o $@ $< $(full_allie_obj) \
|
||||
-lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
|
||||
|
||||
.PHONY: run_r4
|
||||
run_r4: out/l3/r4
|
||||
./out/l3/r4
|
||||
|
||||
out/l3/r4b: src/l3/r4/r4.c $(HEADERS_src_l3) $(l_wl_protocols) $(ASSETS_gen_l_adele)
|
||||
mkdir -p out/l3
|
||||
$(cc) $(cflags) -o $@ $< $(xdg_shell_private_c) -lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
|
||||
@ -157,4 +133,78 @@ run_r4b: out/l3/r4b
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf gen out
|
||||
rm -rf gen out
|
||||
|
||||
# ======================= Daria ВСЁ ===========================
|
||||
# =============================================================
|
||||
# -------------------------------------------------------------
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# =============================================================
|
||||
# ====================== ПЛЮСЫ ================================
|
||||
|
||||
find_hpp_cpp = $(shell find src/$(1) -type f -name '*.hpp' )
|
||||
|
||||
HEADERS_src_l1_allie_cpp := $(call find_hpp_cpp,l1/allie_cpp)
|
||||
|
||||
cxx_cpp := g++
|
||||
cxxflags_cpp := -Wall -Wextra -Werror=return-type -Wno-unused-parameter \
|
||||
--std=c++20 -g -ggdb -O0 -D_FORTIFY_SOURCE=0 \
|
||||
-fno-trapping-math -D_POSIX_C_SOURCE=200112L -D_GNU_SOURCE
|
||||
|
||||
out/l1/allie_cpp/codegen: src/l1/allie_cpp/anne/codegen.cpp $(HEADERS_src_l1_allie_cpp)
|
||||
mkdir -p out/l1/allie_cpp
|
||||
$(cxx_cpp) $(cxxflags_cpp) -o $@ $<
|
||||
|
||||
gen/l1/allie_cpp/dorothy.txt: out/l1/allie_cpp/codegen
|
||||
mkdir -p gen
|
||||
cd gen && ../out/l1/allie_cpp/codegen
|
||||
|
||||
out/l2/allie_cpp/glue.o: src/l2/allie_cpp/glue.c $(HEADERS_src_l2) $(xdg_shell_client_h) gen/l_adele/dorothy.txt $(HEADERS_gen_l2)
|
||||
mkdir -p out/l2/allie_cpp/
|
||||
$(cc) $(cflags) -o $@ -c $< -lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
|
||||
|
||||
full_allie_cpp_obj := out/l2/allie_cpp/glue.o $(xdg_shell_private_o)
|
||||
|
||||
# todo: add a call to a function that obtains all .hpp files from l2/allie_cpp
|
||||
out/l3/allie_cpp/r4c: src/l3/r4/r4c.cpp src/l1/allie_cpp/anne/utils.hpp \
|
||||
src/l2/allie_cpp/alice.hpp $(full_allie_cpp_obj)
|
||||
mkdir -p out/l3/allie_cpp
|
||||
$(cxx_cpp) $(cxxflags_cpp) -o $@ $< $(full_allie_cpp_obj) \
|
||||
-lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
|
||||
|
||||
.PHONY: run_r4c
|
||||
run_r4c: out/l3/allie_cpp/r4c
|
||||
./out/l3/allie_cpp/r4c
|
||||
|
||||
# ======================== ПЛЮСЫ ВСЁ ==========================
|
||||
# =============================================================
|
||||
# -------------------------------------------------------------
|
||||
|
||||
# -------------------------------------------------------------
|
||||
# =============================================================
|
||||
# ========================== ХАСКЕЛЬ ==========================
|
||||
|
||||
find_haskell_hs = $(shell find src/$(1) -type f -name '*.hs' )
|
||||
|
||||
# Whoever needs this will also need out/l_wl_protocols
|
||||
out/l2/allie_hs/glue.o: src/l2/allie_hs/glue.c $(HEADERS_src_l2) $(xdg_shell_client_h) gen/l_adele/dorothy.txt $(HEADERS_gen_l2)
|
||||
mkdir -p out/l2/allie_hs/
|
||||
$(cc) $(cflags) -o $@ -c $< -lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
|
||||
|
||||
full_allie_hs_obj := out/l2/allie_hs/glue.o $(xdg_shell_private_o)
|
||||
|
||||
# todo: write a function that gets all .hs files from l2/allie_hs. Call it
|
||||
out/l3/allie_hs/r4: src/l3/r4/R4.hs src/l2/allie_hs/Alice.hs \
|
||||
src/l2/allie_hs/Geom.hs $(full_allie_hs_obj)
|
||||
mkdir -p out/l3/allie_hs
|
||||
ghc -isrc/l2/allie_hs -hidir out/l3/ -odir out/l3 -o $@ $< $(full_allie_hs_obj) \
|
||||
-lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
|
||||
|
||||
.PHONY: run_r4
|
||||
run_r4: out/l3/allie_hs/r4
|
||||
./out/l3/allie_hs/r4
|
||||
|
||||
# ========================== ХАСКЕЛЬ ВСЁ ======================
|
||||
# =============================================================
|
||||
# -------------------------------------------------------------
|
||||
|
||||
@ -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` для трейта (инстанциация
|
||||
'громадных' ссылок).
|
||||
|
||||
7
src/l1/allie_cpp/anne/codegen.cpp
Normal file
7
src/l1/allie_cpp/anne/codegen.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "geom.hpp"
|
||||
|
||||
int main() {
|
||||
l1_generate_geom_hpp();
|
||||
touch_file("l1/allie_cpp/dorothy.txt");
|
||||
return 0;
|
||||
}
|
||||
533
src/l1/allie_cpp/anne/geom.hpp
Normal file
533
src/l1/allie_cpp/anne/geom.hpp
Normal file
@ -0,0 +1,533 @@
|
||||
#pragma once
|
||||
|
||||
#include "../codegen.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <concepts>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
/* This file is vibecoded. It requires more rewriting */
|
||||
|
||||
inline constexpr std::array<std::string_view, 4> kGeomFieldNames = {"x", "y", "z", "w"};
|
||||
|
||||
struct GeomVecFamilySpec {
|
||||
std::string_view prefix;
|
||||
std::string_view scalar;
|
||||
bool geometric_methods;
|
||||
};
|
||||
|
||||
struct GeomMatFamilySpec {
|
||||
std::string_view mat_prefix;
|
||||
std::string_view vec_prefix;
|
||||
std::string_view scalar;
|
||||
};
|
||||
|
||||
template <class F>
|
||||
concept GeomIndexCallable =
|
||||
requires(F&& f) {
|
||||
std::invoke(std::forward<F>(f), int{});
|
||||
};
|
||||
|
||||
template <class F>
|
||||
concept GeomIndexStringCallable =
|
||||
requires(F&& f) {
|
||||
{ std::invoke(std::forward<F>(f), int{}) } -> std::convertible_to<std::string>;
|
||||
};
|
||||
|
||||
template <class F>
|
||||
concept GeomIndexPairStringCallable =
|
||||
requires(F&& f) {
|
||||
{ std::invoke(std::forward<F>(f), int{}, int{}) } -> std::convertible_to<std::string>;
|
||||
};
|
||||
|
||||
template <GeomIndexCallable F>
|
||||
inline void geom_append_joined(std::string& out, int count, std::string_view separator, F&& emit_one) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (i > 0) {
|
||||
out += separator;
|
||||
}
|
||||
emit_one(i);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string_view geom_field_name(int index) {
|
||||
return kGeomFieldNames[index];
|
||||
}
|
||||
|
||||
inline std::string geom_vec_name(std::string_view prefix, int n) {
|
||||
return std::string(prefix) + std::to_string(n);
|
||||
}
|
||||
|
||||
inline std::string geom_mat_name(std::string_view prefix, int cols, int rows) {
|
||||
if (cols == rows) {
|
||||
return std::string(prefix) + std::to_string(cols);
|
||||
}
|
||||
return std::string(prefix) + std::to_string(cols) + "x" + std::to_string(rows);
|
||||
}
|
||||
|
||||
template <GeomIndexStringCallable F>
|
||||
inline void geom_append_constructor_call(std::string& out, std::string_view type_name, int count, F&& arg_expression) {
|
||||
out += std::string(type_name);
|
||||
out += "(";
|
||||
geom_append_joined(out, count, ", ", [&](int index) {
|
||||
out += arg_expression(index);
|
||||
});
|
||||
out += ")";
|
||||
}
|
||||
|
||||
template <GeomIndexStringCallable F>
|
||||
inline void geom_append_vector_return(std::string& out, std::string_view vec_name, int count, F&& component_expression) {
|
||||
out += " return ";
|
||||
geom_append_constructor_call(out, vec_name, count, component_expression);
|
||||
out += ";\n";
|
||||
}
|
||||
|
||||
template <GeomIndexPairStringCallable F>
|
||||
inline void geom_append_matrix_return(
|
||||
std::string& out,
|
||||
std::string_view mat_name,
|
||||
std::string_view vec_name,
|
||||
int cols,
|
||||
int rows,
|
||||
F&& component_expression) {
|
||||
out += " return ";
|
||||
out += std::string(mat_name);
|
||||
out += "(";
|
||||
geom_append_joined(out, cols, ", ", [&](int col) {
|
||||
geom_append_constructor_call(out, vec_name, rows, [&](int row) {
|
||||
return component_expression(col, row);
|
||||
});
|
||||
});
|
||||
out += ");\n";
|
||||
}
|
||||
|
||||
template <GeomIndexStringCallable F>
|
||||
inline void geom_append_matrix_column_return(std::string& out, std::string_view mat_name, int cols, F&& column_expression) {
|
||||
out += " return ";
|
||||
geom_append_constructor_call(out, mat_name, cols, column_expression);
|
||||
out += ";\n";
|
||||
}
|
||||
|
||||
inline void geom_append_vector_family(std::string& out, GeomVecFamilySpec spec, int n) {
|
||||
const std::string vec_name = geom_vec_name(spec.prefix, n);
|
||||
|
||||
out += "struct " + vec_name + " {\n";
|
||||
for (int i = 0; i < n; ++i) {
|
||||
out += " " + std::string(spec.scalar) + " " + std::string(geom_field_name(i)) + ";\n";
|
||||
}
|
||||
out += "\n";
|
||||
out += " constexpr " + vec_name + "() noexcept = default;\n";
|
||||
out += " constexpr " + vec_name + "(";
|
||||
geom_append_joined(out, n, ", ", [&](int index) {
|
||||
out += std::string(spec.scalar) + " " + std::string(geom_field_name(index));
|
||||
});
|
||||
out += ") noexcept : ";
|
||||
geom_append_joined(out, n, ", ", [&](int index) {
|
||||
const std::string field = std::string(geom_field_name(index));
|
||||
out += field + "(" + field + ")";
|
||||
});
|
||||
out += " {}\n";
|
||||
out += "};\n\n";
|
||||
|
||||
out += "inline " + vec_name + " operator+(" + vec_name + " A, " + vec_name + " B) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_name, n, [&](int index) {
|
||||
const std::string field = std::string(geom_field_name(index));
|
||||
return "A." + field + " + B." + field;
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + vec_name + " operator-(" + vec_name + " A, " + vec_name + " B) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_name, n, [&](int index) {
|
||||
const std::string field = std::string(geom_field_name(index));
|
||||
return "A." + field + " - B." + field;
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + vec_name + " operator-(" + vec_name + " A) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_name, n, [&](int index) {
|
||||
return "-A." + std::string(geom_field_name(index));
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + vec_name + " operator*(" + vec_name + " A, " + std::string(spec.scalar) + " B) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_name, n, [&](int index) {
|
||||
return "A." + std::string(geom_field_name(index)) + " * B";
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + vec_name + " operator*(" + std::string(spec.scalar) + " A, " + vec_name + " B) noexcept {\n";
|
||||
out += " return B * A;\n}\n\n";
|
||||
|
||||
out += "inline " + vec_name + " operator/(" + vec_name + " A, " + std::string(spec.scalar) + " B) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_name, n, [&](int index) {
|
||||
return "A." + std::string(geom_field_name(index)) + " / B";
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + vec_name + " operator*(" + vec_name + " A, " + vec_name + " B) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_name, n, [&](int index) {
|
||||
const std::string field = std::string(geom_field_name(index));
|
||||
return "A." + field + " * B." + field;
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + std::string(spec.scalar) + " dot(" + vec_name + " A, " + vec_name + " B) noexcept {\n";
|
||||
out += " return " + [&]() {
|
||||
std::string expression;
|
||||
geom_append_joined(expression, n, " + ", [&](int index) {
|
||||
const std::string field = std::string(geom_field_name(index));
|
||||
expression += "A." + field + " * B." + field;
|
||||
});
|
||||
return expression;
|
||||
}() + ";\n}\n\n";
|
||||
|
||||
if (spec.geometric_methods) {
|
||||
out += "inline " + std::string(spec.scalar) + " length(" + vec_name + " A) noexcept {\n";
|
||||
out += " return std::sqrt(dot(A, A));\n}\n\n";
|
||||
|
||||
out += "inline " + vec_name + " normalize(" + vec_name + " A) noexcept {\n";
|
||||
out += " return A / length(A);\n}\n\n";
|
||||
|
||||
if (n == 3) {
|
||||
out += "inline " + vec_name + " cross(" + vec_name + " A, " + vec_name + " B) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_name, 3, [&](int index) {
|
||||
if (index == 0) {
|
||||
return "A.y * B.z - A.z * B.y";
|
||||
}
|
||||
if (index == 1) {
|
||||
return "-A.x * B.z + A.z * B.x";
|
||||
}
|
||||
return "A.x * B.y - A.y * B.x";
|
||||
});
|
||||
out += "}\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void geom_append_vector_and_one(std::string& out, GeomVecFamilySpec spec, int n) {
|
||||
const std::string vec_name = geom_vec_name(spec.prefix, n);
|
||||
const std::string vec_next = geom_vec_name(spec.prefix, n + 1);
|
||||
|
||||
out += "inline " + vec_next + " and_one(" + vec_name + " A) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_next, n + 1, [&](int index) {
|
||||
if (index == n) {
|
||||
return std::string("1");
|
||||
}
|
||||
return "A." + std::string(geom_field_name(index));
|
||||
});
|
||||
out += "}\n\n";
|
||||
}
|
||||
|
||||
inline void geom_append_matrix_struct(std::string& out, GeomMatFamilySpec spec, int cols, int rows) {
|
||||
const std::string mat_name = geom_mat_name(spec.mat_prefix, cols, rows);
|
||||
const std::string vec_rows = geom_vec_name(spec.vec_prefix, rows);
|
||||
|
||||
out += "struct " + mat_name + " {\n";
|
||||
for (int col = 0; col < cols; ++col) {
|
||||
out += " " + vec_rows + " " + std::string(geom_field_name(col)) + ";\n";
|
||||
}
|
||||
out += "\n";
|
||||
out += " constexpr " + mat_name + "() noexcept = default;\n";
|
||||
out += " constexpr " + mat_name + "(";
|
||||
geom_append_joined(out, cols, ", ", [&](int col) {
|
||||
out += vec_rows + " " + std::string(geom_field_name(col));
|
||||
});
|
||||
out += ") noexcept : ";
|
||||
geom_append_joined(out, cols, ", ", [&](int col) {
|
||||
const std::string field = std::string(geom_field_name(col));
|
||||
out += field + "(" + field + ")";
|
||||
});
|
||||
out += " {}\n";
|
||||
out += "};\n\n";
|
||||
}
|
||||
|
||||
inline void geom_append_matrix_new(std::string& out, GeomMatFamilySpec spec, int cols, int rows) {
|
||||
const std::string mat_name = geom_mat_name(spec.mat_prefix, cols, rows);
|
||||
const std::string vec_rows = geom_vec_name(spec.vec_prefix, rows);
|
||||
|
||||
out += "inline " + mat_name + " " + mat_name + "_new(";
|
||||
bool first = true;
|
||||
for (int row = 0; row < rows; ++row) {
|
||||
for (int col = 0; col < cols; ++col) {
|
||||
if (!first) {
|
||||
out += ", ";
|
||||
}
|
||||
first = false;
|
||||
out += std::string(spec.scalar) + " ";
|
||||
out += std::string(geom_field_name(col));
|
||||
out += std::string(geom_field_name(row));
|
||||
}
|
||||
}
|
||||
out += ") noexcept {\n";
|
||||
geom_append_matrix_return(out, mat_name, vec_rows, cols, rows, [&](int col, int row) {
|
||||
return std::string(geom_field_name(col)) + std::string(geom_field_name(row));
|
||||
});
|
||||
out += "}\n\n";
|
||||
}
|
||||
|
||||
inline void geom_append_matrix_base_operators(std::string& out, GeomMatFamilySpec spec, int cols, int rows) {
|
||||
const std::string mat_name = geom_mat_name(spec.mat_prefix, cols, rows);
|
||||
const std::string scalar = std::string(spec.scalar);
|
||||
const std::string vec_cols = geom_vec_name(spec.vec_prefix, cols);
|
||||
const std::string vec_rows = geom_vec_name(spec.vec_prefix, rows);
|
||||
|
||||
out += "inline " + mat_name + " operator+(" + mat_name + " A, " + mat_name + " B) noexcept {\n";
|
||||
geom_append_matrix_column_return(out, mat_name, cols, [&](int col) {
|
||||
const std::string field = std::string(geom_field_name(col));
|
||||
return "A." + field + " + B." + field;
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + mat_name + " operator-(" + mat_name + " A, " + mat_name + " B) noexcept {\n";
|
||||
geom_append_matrix_column_return(out, mat_name, cols, [&](int col) {
|
||||
const std::string field = std::string(geom_field_name(col));
|
||||
return "A." + field + " - B." + field;
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + mat_name + " operator-(" + mat_name + " A) noexcept {\n";
|
||||
geom_append_matrix_column_return(out, mat_name, cols, [&](int col) {
|
||||
return "-A." + std::string(geom_field_name(col));
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + mat_name + " operator*(" + mat_name + " A, " + scalar + " B) noexcept {\n";
|
||||
geom_append_matrix_column_return(out, mat_name, cols, [&](int col) {
|
||||
return "A." + std::string(geom_field_name(col)) + " * B";
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + mat_name + " operator*(" + scalar + " A, " + mat_name + " B) noexcept {\n";
|
||||
out += " return B * A;\n}\n\n";
|
||||
|
||||
out += "inline " + mat_name + " operator/(" + mat_name + " A, " + scalar + " B) noexcept {\n";
|
||||
geom_append_matrix_column_return(out, mat_name, cols, [&](int col) {
|
||||
return "A." + std::string(geom_field_name(col)) + " / B";
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + vec_rows + " operator*(" + mat_name + " A, " + vec_cols + " B) noexcept {\n";
|
||||
geom_append_vector_return(out, vec_rows, rows, [&](int row) {
|
||||
std::string expression;
|
||||
geom_append_joined(expression, cols, " + ", [&](int col) {
|
||||
expression += "A." + std::string(geom_field_name(col));
|
||||
expression += ".";
|
||||
expression += std::string(geom_field_name(row));
|
||||
expression += " * B.";
|
||||
expression += std::string(geom_field_name(col));
|
||||
});
|
||||
return expression;
|
||||
});
|
||||
out += "}\n\n";
|
||||
}
|
||||
|
||||
inline void geom_append_matrix_transpose(std::string& out, GeomMatFamilySpec spec, int cols, int rows) {
|
||||
const std::string mat_name = geom_mat_name(spec.mat_prefix, cols, rows);
|
||||
const std::string mat_transposed = geom_mat_name(spec.mat_prefix, rows, cols);
|
||||
const std::string vec_cols = geom_vec_name(spec.vec_prefix, cols);
|
||||
|
||||
out += "inline " + mat_transposed + " transpose(" + mat_name + " A) noexcept {\n";
|
||||
geom_append_matrix_return(out, mat_transposed, vec_cols, rows, cols, [&](int new_col, int new_row) {
|
||||
return "A." + std::string(geom_field_name(new_row)) + "." + std::string(geom_field_name(new_col));
|
||||
});
|
||||
out += "}\n\n";
|
||||
}
|
||||
|
||||
inline void geom_append_square_identity(std::string& out, GeomMatFamilySpec spec, int n) {
|
||||
const std::string mat_name = geom_mat_name(spec.mat_prefix, n, n);
|
||||
const std::string vec_name = geom_vec_name(spec.vec_prefix, n);
|
||||
|
||||
out += "inline constexpr " + mat_name + " " + mat_name + "_E = ";
|
||||
geom_append_constructor_call(out, mat_name, n, [&](int col) {
|
||||
std::string column;
|
||||
geom_append_constructor_call(column, vec_name, n, [&](int row) {
|
||||
return std::string(col == row ? "1" : "0");
|
||||
});
|
||||
return column;
|
||||
});
|
||||
out += ";\n\n";
|
||||
}
|
||||
|
||||
inline void geom_append_square_outer_product(std::string& out, GeomMatFamilySpec spec, int n) {
|
||||
const std::string mat_name = geom_mat_name(spec.mat_prefix, n, n);
|
||||
const std::string vec_name = geom_vec_name(spec.vec_prefix, n);
|
||||
|
||||
out += "inline " + mat_name + " outer_product(" + vec_name + " v) noexcept {\n";
|
||||
geom_append_matrix_return(out, mat_name, vec_name, n, n, [&](int col, int row) {
|
||||
const std::string col_field = std::string(geom_field_name(col));
|
||||
return "v." + col_field + " * v." + std::string(geom_field_name(row));
|
||||
});
|
||||
out += "}\n\n";
|
||||
|
||||
out += "inline " + mat_name + " " + mat_name + "_new_for_proj(" + vec_name + " v) noexcept {\n";
|
||||
out += " return outer_product(v);\n}\n\n";
|
||||
}
|
||||
|
||||
inline void geom_append_matrix_times_matrix(std::string& out, GeomMatFamilySpec spec, int n, int m, int k) {
|
||||
const std::string left_name = geom_mat_name(spec.mat_prefix, n, m);
|
||||
const std::string right_name = geom_mat_name(spec.mat_prefix, k, n);
|
||||
const std::string result_name = geom_mat_name(spec.mat_prefix, k, m);
|
||||
const std::string vec_m = geom_vec_name(spec.vec_prefix, m);
|
||||
|
||||
out += "inline " + result_name + " operator*(" + left_name + " A, " + right_name + " B) noexcept {\n";
|
||||
geom_append_matrix_return(out, result_name, vec_m, k, m, [&](int result_col, int result_row) {
|
||||
std::string expression;
|
||||
geom_append_joined(expression, n, " + ", [&](int inner) {
|
||||
expression += "A." + std::string(geom_field_name(inner));
|
||||
expression += ".";
|
||||
expression += std::string(geom_field_name(result_row));
|
||||
expression += " * B.";
|
||||
expression += std::string(geom_field_name(result_col));
|
||||
expression += ".";
|
||||
expression += std::string(geom_field_name(inner));
|
||||
});
|
||||
return expression;
|
||||
});
|
||||
out += "}\n\n";
|
||||
}
|
||||
|
||||
inline void geom_append_det_function(std::string& out, GeomMatFamilySpec spec, int n) {
|
||||
const std::string mat_name = geom_mat_name(spec.mat_prefix, n, n);
|
||||
const std::string scalar = std::string(spec.scalar);
|
||||
|
||||
out += "inline " + scalar + " det(" + mat_name + " a) noexcept {\n";
|
||||
out += " return " + [&]() {
|
||||
std::string expression;
|
||||
if (n == 2) {
|
||||
expression = "a.x.x * a.y.y - a.x.y * a.y.x";
|
||||
return expression;
|
||||
}
|
||||
geom_append_joined(expression, n, "\n ", [&](int i) {
|
||||
if (i > 0) {
|
||||
expression += "";
|
||||
}
|
||||
for (int j = 0; j < n; ++j) {
|
||||
if (j == i) {
|
||||
continue;
|
||||
}
|
||||
const int k = (n == 3) ? (3 - i - j) : -1;
|
||||
if (n == 3) {
|
||||
const bool minus =
|
||||
(((i > j) ? 1 : 0) + ((j > k) ? 1 : 0) + ((i > k) ? 1 : 0)) % 2 != 0;
|
||||
if (!expression.empty()) {
|
||||
expression += " ";
|
||||
}
|
||||
expression += minus ? "-" : "+";
|
||||
expression += " a.x.";
|
||||
expression += std::string(geom_field_name(i));
|
||||
expression += " * a.y.";
|
||||
expression += std::string(geom_field_name(j));
|
||||
expression += " * a.z.";
|
||||
expression += std::string(geom_field_name(k));
|
||||
}
|
||||
}
|
||||
if (n == 4) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
if (j == i) {
|
||||
continue;
|
||||
}
|
||||
for (int k = 0; k < 4; ++k) {
|
||||
if (k == i || k == j) {
|
||||
continue;
|
||||
}
|
||||
const int u = 6 - i - j - k;
|
||||
const bool minus =
|
||||
(((i > j) ? 1 : 0) + ((j > k) ? 1 : 0) + ((i > k) ? 1 : 0) +
|
||||
((i > u) ? 1 : 0) + ((j > u) ? 1 : 0) + ((k > u) ? 1 : 0)) % 2 != 0;
|
||||
if (!expression.empty()) {
|
||||
expression += " ";
|
||||
}
|
||||
expression += minus ? "-" : "+";
|
||||
expression += " a.x.";
|
||||
expression += std::string(geom_field_name(i));
|
||||
expression += " * a.y.";
|
||||
expression += std::string(geom_field_name(j));
|
||||
expression += " * a.z.";
|
||||
expression += std::string(geom_field_name(k));
|
||||
expression += " * a.w.";
|
||||
expression += std::string(geom_field_name(u));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return expression;
|
||||
}() + ";\n}\n\n";
|
||||
}
|
||||
|
||||
inline std::string geom_build_hpp() {
|
||||
std::string out;
|
||||
out.reserve(131072);
|
||||
|
||||
out += "#pragma once\n";
|
||||
out += "/* Automatically generated file. Do not edit it. */\n\n";
|
||||
out += "#include <cmath>\n";
|
||||
out += "#include <cstdint>\n\n";
|
||||
|
||||
constexpr std::array<GeomVecFamilySpec, 6> vec_specs = {{
|
||||
{"cvec", "std::uint8_t", false},
|
||||
{"uvec", "std::uint32_t", false},
|
||||
{"s64vec", "std::int64_t", false},
|
||||
{"ivec", "std::int32_t", false},
|
||||
{"vec", "float", true},
|
||||
{"dvec", "double", true},
|
||||
}};
|
||||
|
||||
for (const GeomVecFamilySpec& spec : vec_specs) {
|
||||
for (int n = 2; n <= 4; ++n) {
|
||||
geom_append_vector_family(out, spec, n);
|
||||
}
|
||||
if (spec.geometric_methods) {
|
||||
for (int n = 2; n <= 3; ++n) {
|
||||
geom_append_vector_and_one(out, spec, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int n = 2; n <= 4; ++n) {
|
||||
out += "using s32vec" + std::to_string(n) + " = ivec" + std::to_string(n) + ";\n";
|
||||
}
|
||||
out += "\n";
|
||||
|
||||
constexpr std::array<GeomMatFamilySpec, 2> mat_specs = {{
|
||||
{"mat", "vec", "float"},
|
||||
{"s64mat", "s64vec", "std::int64_t"},
|
||||
}};
|
||||
|
||||
for (const GeomMatFamilySpec& spec : mat_specs) {
|
||||
for (int cols = 2; cols <= 4; ++cols) {
|
||||
for (int rows = 2; rows <= 4; ++rows) {
|
||||
geom_append_matrix_struct(out, spec, cols, rows);
|
||||
geom_append_matrix_new(out, spec, cols, rows);
|
||||
geom_append_matrix_base_operators(out, spec, cols, rows);
|
||||
}
|
||||
}
|
||||
for (int cols = 2; cols <= 4; ++cols) {
|
||||
for (int rows = 2; rows <= 4; ++rows) {
|
||||
geom_append_matrix_transpose(out, spec, cols, rows);
|
||||
}
|
||||
}
|
||||
for (int n = 2; n <= 4; ++n) {
|
||||
geom_append_square_identity(out, spec, n);
|
||||
geom_append_square_outer_product(out, spec, n);
|
||||
}
|
||||
for (int n = 2; n <= 4; ++n) {
|
||||
for (int m = 2; m <= 4; ++m) {
|
||||
for (int k = 2; k <= 4; ++k) {
|
||||
geom_append_matrix_times_matrix(out, spec, n, m, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int n = 2; n <= 4; ++n) {
|
||||
geom_append_det_function(out, spec, n);
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
inline void l1_generate_geom_hpp() {
|
||||
write_text_file("l1/allie_cpp/geom.hpp", geom_build_hpp());
|
||||
}
|
||||
97
src/l1/allie_cpp/anne/utils.hpp
Normal file
97
src/l1/allie_cpp/anne/utils.hpp
Normal file
@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <string_view>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
typedef uint8_t U8;
|
||||
typedef uint16_t U16;
|
||||
typedef uint32_t U32;
|
||||
typedef uint64_t U64;
|
||||
typedef int8_t S8;
|
||||
typedef int16_t S16;
|
||||
typedef int32_t S32;
|
||||
typedef int64_t S64;
|
||||
|
||||
struct allie_SpanU8 {
|
||||
const U8* data;
|
||||
U64 len;
|
||||
|
||||
explicit allie_SpanU8(std::string_view cpp_span): data(reinterpret_cast<const U8*>(cpp_span.data())), len(cpp_span.size()){}
|
||||
};
|
||||
|
||||
struct allie_VecU8 {
|
||||
const U8* buf;
|
||||
U64 len;
|
||||
};
|
||||
|
||||
struct U32Segment {
|
||||
U32 start;
|
||||
U32 len;
|
||||
};
|
||||
|
||||
struct allie_VecU32Segment {
|
||||
U32Segment* buf;
|
||||
U64 len;
|
||||
U64 capacity;
|
||||
};
|
||||
|
||||
#define ALLIE_CPP_OPAQUE(T) \
|
||||
void* opa; \
|
||||
T& operator=(T&)=delete; \
|
||||
T(T&)=delete; \
|
||||
T& operator=(T&& other) noexcept { \
|
||||
std::swap(opa, other.opa); \
|
||||
return *this; \
|
||||
} \
|
||||
T(T&& other) noexcept: opa(other.opa){ \
|
||||
other.opa = NULL; \
|
||||
}
|
||||
|
||||
void* safe_malloc(size_t n) {
|
||||
void* res = malloc(n);
|
||||
if (!res) {
|
||||
std::fprintf(stderr, "Allocation failure");
|
||||
abort();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void* safe_calloc(size_t nmemb, size_t size) {
|
||||
void* res = calloc(nmemb, size);
|
||||
if (!res) {
|
||||
std::fprintf(stderr, "Calloc died");
|
||||
abort();
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
20
src/l1/allie_cpp/codegen.hpp
Normal file
20
src/l1/allie_cpp/codegen.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
inline void write_text_file(std::string_view path_string, std::string_view text) {
|
||||
const std::filesystem::path path(path_string);
|
||||
std::ofstream out(path);
|
||||
if (!out) {
|
||||
throw std::runtime_error("failed to open " + path.string());
|
||||
}
|
||||
out << text;
|
||||
}
|
||||
|
||||
inline void touch_file(std::string_view path_string) {
|
||||
write_text_file(path_string, "");
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
#include "../codegen/util_template_inst.h"
|
||||
|
||||
void generate_util_temp_geom_headers() {
|
||||
SpanU8 T[] = {cstr("cvec3"), cstr("cvec4"), cstr("vec2"), cstr("vec3"), cstr("vec4"), cstr("s64vec2")};
|
||||
SpanU8 T[] = {cstr("cvec3"), cstr("cvec4"), cstr("vec2"), cstr("vec3"), cstr("vec4"), cstr("s64vec2"), cstr("ivec2")};
|
||||
for (size_t i = 0; i < ARRAY_SIZE(T); i++) {
|
||||
generate_guarded_span_company_for_primitive(cstr("l1"), cstr(""), T[i],
|
||||
cstr("#include \"geom.h\"\n"), true, true);
|
||||
|
||||
@ -73,4 +73,8 @@ void generate_util_temp_very_base_headers() {
|
||||
|
||||
generate_Option_templ_inst_eve_header(l, ns,
|
||||
(option_template_instantiation_op){.T = cstr("Json"), .t_clonable = false});
|
||||
|
||||
mkdir_nofail("l1/gui");
|
||||
generate_guarded_span_company_for_primitive(l, cstr("gui"), cstr("MutRefWidget"),
|
||||
cstr("#include \"../../../src/l2/gui/widget.h\""), true, false);
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ mat4 marie_mat3_to_mat4_transposed(mat3 A) {
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
mat4 marie_3d_rot_mat4(vec3 r, double a) {
|
||||
mat4 marie_3d_rot_mat4(vec3 r, float a) {
|
||||
return marie_mat3_to_mat4(marie_3d_rot_mat3(r, a));
|
||||
}
|
||||
|
||||
@ -100,3 +100,26 @@ mat4 marie_3d_scal_mat4(float scale){
|
||||
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){
|
||||
{MAX_S32(a.lt.x, b.lt.x), MAX_S32(a.lt.y, b.lt.y)},
|
||||
{MIN_S32(a.rb.x, b.rb.x), MIN_S32(a.rb.y, b.rb.y)},
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -4,7 +4,11 @@
|
||||
#include "../../l1/marie/geom_alg_utils.h"
|
||||
#include "../margaret/vulkan_utils.h"
|
||||
#include "transfer_in_mainloop.h"
|
||||
#include "../drawer_2d.h"
|
||||
#include "../lucy/glyph_render.h"
|
||||
#include "../gui/widget.h"
|
||||
|
||||
typedef struct Alice Alice;
|
||||
|
||||
typedef struct {
|
||||
size_t indexes;
|
||||
@ -15,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"
|
||||
@ -24,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;
|
||||
@ -611,25 +594,27 @@ 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;
|
||||
/* guest data, button, button action (wl_pointer_button_state) */
|
||||
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 {
|
||||
@ -674,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;
|
||||
@ -689,7 +678,7 @@ typedef struct {
|
||||
|
||||
struct Alice {
|
||||
AliceCallbacks callbacks;
|
||||
void* guest;
|
||||
|
||||
AliceWaylandApp wl;
|
||||
|
||||
MargaretInstanceAndItsDebug instance_and_debug;
|
||||
@ -735,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;
|
||||
@ -743,9 +734,12 @@ struct Alice {
|
||||
MargaretImg IT1_image;
|
||||
MargaretImg zbuffer_image;
|
||||
|
||||
Plain2dShapeRenderer plain_shape_renderer;
|
||||
FT_Library ft_library;
|
||||
LucyGlyphCache lucy_cache;
|
||||
LucyRenderer lucy_renderer;
|
||||
/* For now all my ui is placed 'on top' of the scene */
|
||||
// MutRefWidget overlay_ui_root;
|
||||
|
||||
VkImageView zbuffer_view;
|
||||
VkImageView IT1_view;
|
||||
@ -763,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);
|
||||
@ -853,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,
|
||||
@ -882,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);
|
||||
@ -938,6 +930,7 @@ void alice_reset_and_record_command_buffer_1(
|
||||
sizeof(Pipeline1PushRangeVertex), sizeof(Pipeline1PushRangeFragment), ®_and_params_fragment);
|
||||
vkCmdDraw(alice->rendering_command_buf_1, 3, 1, 0, 0);
|
||||
|
||||
Plain2dShapeRenderer_frame_rec_drawing(&alice->plain_shape_renderer, alice->rendering_command_buf_1, image_extent);
|
||||
LucyRenderer_another_frame_rec_drawing(&alice->lucy_renderer, alice->rendering_command_buf_1, image_extent);
|
||||
|
||||
vkCmdEndRenderPass(alice->rendering_command_buf_1);
|
||||
@ -1060,12 +1053,12 @@ void alice_frame_drawing(Alice* alice) {
|
||||
abortf("vkAcquireNextImageKHR");
|
||||
}
|
||||
|
||||
mat4 projection_matrix = marie_perspective_projection_fov_mat4(
|
||||
(float)alice->wl.width_confirmed, (float)alice->wl.height_confirmed,
|
||||
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));
|
||||
U32 win_width = alice->wl.width_confirmed;
|
||||
U32 win_height = alice->wl.height_confirmed;
|
||||
|
||||
/* This is not related to command recording */
|
||||
Plain2dShapeRenderer_clear(&alice->plain_shape_renderer);
|
||||
LucyRenderer_clear(&alice->lucy_renderer);
|
||||
|
||||
if (!alice->transfer_command_buf_already_reset) {
|
||||
Abigail_wipe_old_staging(&alice->abigail, alice->device, alice->staging_buffers);
|
||||
@ -1075,14 +1068,19 @@ void alice_frame_drawing(Alice* alice) {
|
||||
}
|
||||
margaret_reset_and_begin_command_buffer(alice->compute_command_buf);
|
||||
|
||||
alice->callbacks.on_another_frame(alice->guest, (float)(alice->wl.cur_frame_time - alice->wl.last_frame_time) / 1000);
|
||||
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
|
||||
// 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});
|
||||
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){
|
||||
@ -1267,7 +1265,7 @@ static void alice_mainloop_h_wl_keyboard_key(
|
||||
} else if (keysym < 0x80 && key_action == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
alice->wl.first_0x80_keys[keysym] = true;
|
||||
}
|
||||
alice->callbacks.on_wl_keyboard_key(alice->guest, keysym, key_action);
|
||||
alice->callbacks.on_wl_keyboard_key(alice->callbacks.guest, keysym, key_action);
|
||||
if (key_action == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||
if (keysym == XKB_KEY_1) {
|
||||
} else if (keysym == XKB_KEY_2) {
|
||||
@ -1317,16 +1315,15 @@ 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(
|
||||
void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t btn_action
|
||||
) {
|
||||
Alice* alice = data;
|
||||
alice->callbacks.on_wl_pointer_button(alice->guest, button, btn_action);
|
||||
alice->callbacks.on_wl_pointer_button(alice->callbacks.guest, button, btn_action);
|
||||
}
|
||||
|
||||
static void alice_mainloop_h_wl_pointer_axis(
|
||||
@ -1598,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,
|
||||
@ -1613,6 +1609,8 @@ Alice* Alice_new(){
|
||||
.linear_sampler = alice->linear_sampler, .nearest_sampler = alice->nearest_sampler
|
||||
};
|
||||
|
||||
alice->plain_shape_renderer = Plain2dShapeRenderer_new(engine_reference, root_dir, alice->render_pass_1, 0);
|
||||
|
||||
FT_Error ft_init_err = FT_Init_FreeType(&alice->ft_library);
|
||||
if (ft_init_err)
|
||||
abortf("Can't init free type library\n");
|
||||
@ -1621,6 +1619,8 @@ 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};
|
||||
|
||||
// Creating framebuffer for IT1, image views for IT1 and zbuffer
|
||||
// Creating descriptor set for pipeline 0b and for pipeline 1 (containing IT1 sampler)
|
||||
alice_create_mem_dependant_vk_obj(alice);
|
||||
@ -1711,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);
|
||||
@ -1773,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;
|
||||
|
||||
@ -1845,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(
|
||||
@ -1876,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;
|
||||
@ -1914,7 +1917,10 @@ 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;
|
||||
while (wl_display_dispatch(alice->wl.wl_display) >= 0) {
|
||||
if (alice->wl.closed)
|
||||
break;
|
||||
@ -1960,5 +1966,31 @@ void Alice_mainloop(Alice* alice, const AliceCallbacks* callbacks) {
|
||||
// if (alice->wl.wl_seat)
|
||||
// wl_seat_destroy(alice->wl.wl_seat);
|
||||
// wl_registry_destroy(alice->wl.wl_registry);
|
||||
wl_display_disconnect(alice->wl.wl_display);
|
||||
// wl_display_disconnect(alice->wl.wl_display);
|
||||
}
|
||||
|
||||
/* Direct alice methods */
|
||||
|
||||
LucyFace* Alice_new_LucyFace(Alice* alice, VecU8 path) {
|
||||
return LucyFace_new(alice->ft_library, &alice->lucy_cache, path);
|
||||
}
|
||||
|
||||
void Alice_lucy_cache_add_glyphs(Alice* alice, VecLucyGlyphCachingRequest req){
|
||||
LucyGlyphCache_add_glyphs(&alice->lucy_cache, req);
|
||||
}
|
||||
|
||||
void Alice_lucy_renderer_add_simple_label(Alice* alice, RBTreeNodeLucyFaceFixedSize* ffs,
|
||||
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;
|
||||
}
|
||||
|
||||
166
src/l2/allie_cpp/alice.hpp
Normal file
166
src/l2/allie_cpp/alice.hpp
Normal file
@ -0,0 +1,166 @@
|
||||
#include "../../l1/allie_cpp/anne/utils.hpp"
|
||||
|
||||
#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)
|
||||
/* For internal use, don't actually use it */
|
||||
explicit LucyFaceFixedSize(void* new_opa) noexcept : opa(new_opa) {}
|
||||
/* Need to implement */
|
||||
~LucyFaceFixedSize() = default;
|
||||
};
|
||||
|
||||
struct allie_LucyGlyphCachingRequest {
|
||||
allie_LucyFaceFixedSize sized_face;
|
||||
allie_VecU32Segment codepoint_ranges;
|
||||
};
|
||||
|
||||
struct allie_VecLucyGlyphCachingRequest {
|
||||
allie_LucyGlyphCachingRequest* buf;
|
||||
U64 len;
|
||||
U64 capacity;
|
||||
};
|
||||
|
||||
struct LucyGlyphCachingRequest {
|
||||
LucyFaceFixedSize& sized_face;
|
||||
std::vector<U32Segment> codepoint_ranges;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
allie_LucyFaceFixedSize allie_LucyFace_of_size(allie_LucyFace self, U32 size);
|
||||
}
|
||||
|
||||
struct LucyFace {
|
||||
ALLIE_CPP_OPAQUE(LucyFace)
|
||||
/* For internal use, don't actually use it */
|
||||
explicit LucyFace(void* new_opa) noexcept : opa(new_opa) {}
|
||||
/* I just don't have it right now */
|
||||
~LucyFace() = default;
|
||||
|
||||
LucyFaceFixedSize of_size(U32 size) noexcept {
|
||||
return LucyFaceFixedSize{allie_LucyFace_of_size(opa, size)};
|
||||
}
|
||||
};
|
||||
|
||||
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 {
|
||||
void* guest;
|
||||
/* guest data, button, button action (wl_pointer_button_state) */
|
||||
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);
|
||||
void (*on_another_frame)(void*, float);
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
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)
|
||||
Alice() noexcept: opa(allie_Alice_new()){}
|
||||
~Alice() {
|
||||
// todo: do something about it
|
||||
}
|
||||
|
||||
void mainloop(const AliceCallbacks& callbacks) noexcept {
|
||||
allie_Alice_mainloop(opa, &callbacks);
|
||||
}
|
||||
|
||||
LucyFace new_lucy_face (std::string_view path) noexcept {
|
||||
return LucyFace{allie_Alice_new_LucyFace(opa, allie_SpanU8(path))};
|
||||
}
|
||||
|
||||
void lucy_cache_add_glyphs(std::vector<LucyGlyphCachingRequest>&& reqs) {
|
||||
allie_VecLucyGlyphCachingRequest a_reqs{};
|
||||
a_reqs.len = a_reqs.capacity = reqs.size();
|
||||
a_reqs.buf = static_cast<allie_LucyGlyphCachingRequest*>( safe_malloc(reqs.size() * sizeof(allie_LucyGlyphCachingRequest) ));
|
||||
for (U64 i = 0; i < reqs.size(); i++) {
|
||||
allie_LucyGlyphCachingRequest& a_r = a_reqs.buf[i];
|
||||
LucyGlyphCachingRequest& r = reqs[i];
|
||||
a_r.sized_face = r.sized_face.opa;
|
||||
a_r.codepoint_ranges.len = a_r.codepoint_ranges.capacity = r.codepoint_ranges.size();
|
||||
a_r.codepoint_ranges.buf = static_cast<U32Segment*>(safe_malloc( r.codepoint_ranges.size() * sizeof(U32Segment) ));
|
||||
memcpy(a_r.codepoint_ranges.buf, r.codepoint_ranges.data(), r.codepoint_ranges.size() * sizeof(U32Segment) );
|
||||
}
|
||||
allie_Alice_lucy_cache_add_glyphs(opa, a_reqs);
|
||||
}
|
||||
|
||||
void lucy_renderer_add_simple_label(LucyFaceFixedSize& ffs,
|
||||
vec4 color, S32 additional_y_advance,std::string_view text, ivec2 start_pos
|
||||
) noexcept {
|
||||
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;
|
||||
// };
|
||||
59
src/l2/allie_cpp/glue.c
Normal file
59
src/l2/allie_cpp/glue.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include "../alice/engine.h"
|
||||
|
||||
Alice* allie_Alice_new(){
|
||||
return Alice_new();
|
||||
}
|
||||
|
||||
void allie_Alice_mainloop(Alice* self, const AliceCallbacks* callbacks) {
|
||||
Alice_mainloop(self, callbacks);
|
||||
}
|
||||
|
||||
void allie_Alice_drop(Alice* self) {
|
||||
// todo: implment
|
||||
}
|
||||
|
||||
LucyFace* allie_Alice_new_LucyFace(Alice* alice, SpanU8 path) {
|
||||
return Alice_new_LucyFace(alice, VecU8_from_span(path));
|
||||
}
|
||||
|
||||
|
||||
RBTreeNodeLucyFaceFixedSize* allie_LucyFace_of_size(LucyFace* self, U32 size) {
|
||||
return LucyFace_of_size(self, size);
|
||||
}
|
||||
|
||||
void allie_Alice_lucy_cache_add_glyphs(Alice* alice, VecLucyGlyphCachingRequest req) {
|
||||
Alice_lucy_cache_add_glyphs(alice, req);
|
||||
}
|
||||
|
||||
void allie_Alice_lucy_renderer_add_simple_label(Alice* alice, RBTreeNodeLucyFaceFixedSize* ffs,
|
||||
vec4 color, S32 additional_y_advance, SpanU8 text, ivec2 start_pos
|
||||
) {
|
||||
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)},
|
||||
};
|
||||
}
|
||||
@ -20,6 +20,7 @@ RBTreeNodeLucyFaceFixedSize* allie_alice_lucy_face_of_size(LucyFace* face, U32 h
|
||||
return LucyFace_of_size(face, height);
|
||||
}
|
||||
|
||||
// todo: rewrite this too
|
||||
/* lol */
|
||||
void allie_lucy_face_add_glyphs(RBTreeNodeLucyFaceFixedSize* face_fs, U32 start, U32 seg_len){
|
||||
VecLucyGlyphCachingRequest lucy_requests = VecLucyGlyphCachingRequest_new();
|
||||
@ -28,12 +29,12 @@ void allie_lucy_face_add_glyphs(RBTreeNodeLucyFaceFixedSize* face_fs, U32 start,
|
||||
VecLucyGlyphCachingRequest_append(&lucy_requests, (LucyGlyphCachingRequest){
|
||||
.sized_face = face_fs, .codepoint_ranges = ranges_needed,
|
||||
});
|
||||
LucyGlyphCache_add_glyphs(lucy_requests);
|
||||
// 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,
|
||||
118
src/l2/drawer_2d.h
Normal file
118
src/l2/drawer_2d.h
Normal file
@ -0,0 +1,118 @@
|
||||
#pragma once
|
||||
|
||||
#include "margaret/vulkan_utils.h"
|
||||
#include "../../gen/l1/geom.h"
|
||||
#include "../l1_5/marie/graphics_geom.h"
|
||||
|
||||
/* todo: replace vec4 color with cvec4 color */
|
||||
typedef struct {
|
||||
vec2 pos;
|
||||
vec4 color;
|
||||
} Plain2dShapeVertex;
|
||||
|
||||
typedef struct {
|
||||
MargaretEngineReference ve;
|
||||
VkPipelineLayout pipeline_layout;
|
||||
VkPipeline pipeline;
|
||||
|
||||
U64 vertex_count;
|
||||
MargaretSubbuf staging_vbo;
|
||||
MargaretSubbuf vbo;
|
||||
bool need_to_transfer;
|
||||
} Plain2dShapeRenderer;
|
||||
|
||||
Plain2dShapeRenderer Plain2dShapeRenderer_new(MargaretEngineReference ve, SpanU8 root_dir,
|
||||
VkRenderPass render_pass, U32 renderpass_subpass) {
|
||||
VkPipelineLayout pipeline_layout;
|
||||
vkCreatePipelineLayout(ve.device, &(VkPipelineLayoutCreateInfo){
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||
.pushConstantRangeCount = 1,
|
||||
.pPushConstantRanges = (VkPushConstantRange[]){{
|
||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT, .offset = 0, .size = sizeof(vec2)
|
||||
}},
|
||||
}, NULL, &pipeline_layout);
|
||||
|
||||
VkPipeline pipeline = margaret_create_triangle_pipeline_one_attachment(ve.device,
|
||||
render_pass, renderpass_subpass, (MargaretMostImportantPipelineOptions){
|
||||
.pipeline_layout = pipeline_layout,
|
||||
.vertex_shader_code = read_file_by_path(VecU8_fmt("%s/gen/l_adele/drawer_2d/plain/vert.spv", root_dir)),
|
||||
.fragment_shader_code = read_file_by_path(VecU8_fmt("%s/gen/l_adele/drawer_2d/plain/frag.spv", root_dir)),
|
||||
.vertexBindingDescriptionCount = 1,
|
||||
.pVertexBindingDescriptions = (VkVertexInputBindingDescription[]){
|
||||
{ .binding = 0, .stride = sizeof(Plain2dShapeVertex), .inputRate = VK_VERTEX_INPUT_RATE_VERTEX } },
|
||||
.vertexAttributeDescriptionCount = 2,
|
||||
.pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]){
|
||||
{.location = 0, .binding = 0,
|
||||
.format = VK_FORMAT_R32G32_SFLOAT, .offset = offsetof(Plain2dShapeVertex, pos)},
|
||||
{.location = 1, .binding = 0,
|
||||
.format = VK_FORMAT_R32G32B32A32_SFLOAT, .offset = offsetof(Plain2dShapeVertex, color)},
|
||||
},
|
||||
.depthTestEnable = false, .depthWriteEnable = false, .blendEnable = true,
|
||||
});
|
||||
|
||||
return (Plain2dShapeRenderer){
|
||||
.ve = ve, .pipeline_layout = pipeline_layout, .pipeline = pipeline,
|
||||
.vertex_count = 0,
|
||||
.staging_vbo = MargaretBufAllocator_alloc(ve.staging_buffers, 67),
|
||||
.vbo = MargaretBufAllocator_alloc(ve.dev_local_buffers, 67)
|
||||
};
|
||||
}
|
||||
|
||||
void Plain2dShapeRenderer_clear(Plain2dShapeRenderer* self) {
|
||||
self->vertex_count = 0;
|
||||
}
|
||||
|
||||
/* Sadly, we don't use rbo right now. Might fix it when I get enough rizz */
|
||||
void Plain2dShapeRenderer_add_triangle(Plain2dShapeRenderer* self, vec4 color, vec2 A, vec2 B, vec2 C) {
|
||||
U64 needed_vbo_length = (self->vertex_count + 3) * sizeof(Plain2dShapeVertex);
|
||||
if (needed_vbo_length > self->staging_vbo.len) {
|
||||
MargaretBufAllocator_expand_or_move_old_host_visible(
|
||||
self->ve.staging_buffers, &self->staging_vbo, needed_vbo_length);
|
||||
}
|
||||
Plain2dShapeVertex* vbo_data = (Plain2dShapeVertex*)MargaretSubbuf_get_mapped(&self->staging_vbo);
|
||||
vbo_data[self->vertex_count++] = (Plain2dShapeVertex){.pos = A, .color = color};
|
||||
vbo_data[self->vertex_count++] = (Plain2dShapeVertex){.pos = B, .color = color};
|
||||
vbo_data[self->vertex_count++] = (Plain2dShapeVertex){.pos = C, .color = color};
|
||||
self->need_to_transfer = true;
|
||||
}
|
||||
|
||||
void Plain2dShapeRenderer_another_frame(Plain2dShapeRenderer* self){
|
||||
U64 needed_vbo_length = self->vertex_count * sizeof(Plain2dShapeVertex);
|
||||
if (self->vbo.len < needed_vbo_length) {
|
||||
MargaretBufAllocator_expand_or_free_old(self->ve.dev_local_buffers, &self->vbo, needed_vbo_length);
|
||||
}
|
||||
if ((self->need_to_transfer) && self->vertex_count > 0) {
|
||||
self->need_to_transfer = false;
|
||||
margaret_rec_cmd_copy_buffer_one_to_one_part(self->ve.transfer_cmd_buffer,
|
||||
&self->staging_vbo, &self->vbo, 0, needed_vbo_length);
|
||||
}
|
||||
}
|
||||
|
||||
void Plain2dShapeRenderer_frame_rec_drawing(Plain2dShapeRenderer* self,
|
||||
VkCommandBuffer drawing_cmd_buf, VkExtent2D image_extent
|
||||
){
|
||||
vkCmdBindPipeline(drawing_cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, self->pipeline);
|
||||
vkCmdBindVertexBuffers(drawing_cmd_buf, 0, 1,
|
||||
(VkBuffer[]){MargaretSubbuf_get_buffer( &self->vbo )}, (U64[]){ self->vbo.start });
|
||||
vkCmdPushConstants(drawing_cmd_buf, self->pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT,
|
||||
0, sizeof(vec2), &(vec2){
|
||||
.x /* aka width */ = (float)image_extent.width, .y /* aka height */ = (float)image_extent.height });
|
||||
vkCmdDraw(drawing_cmd_buf, self->vertex_count, 1, 0, 0);
|
||||
}
|
||||
|
||||
void Plain2dShapeRenderer_add_rectangle(Plain2dShapeRenderer* self, vec4 color, vec2 start, float width, float height) {
|
||||
Plain2dShapeRenderer_add_triangle(self, color,
|
||||
(vec2){start.x + width, start.y}, start, (vec2){start.x, start.y + height});
|
||||
Plain2dShapeRenderer_add_triangle(self, color,
|
||||
(vec2){start.x + width, start.y}, (vec2){start.x, start.y + height}, (vec2){start.x + width, start.y + height});
|
||||
}
|
||||
|
||||
void Plain2dShapeRenderer_add_rect_clipped(Plain2dShapeRenderer* self, vec4 color,
|
||||
ivec2 start, S32 width, S32 height, BorderS32 border) {
|
||||
BorderS32 rect = BorderS32_intersect(border,
|
||||
(BorderS32){.lt = start, .rb.x = start.x + width, .rb.y = start.y + height});
|
||||
if (!BorderS32_empty(rect)) {
|
||||
Plain2dShapeRenderer_add_rectangle(self, color, ivec2_to_vec2(rect.lt),
|
||||
(float)(rect.rb.x - rect.lt.x), (float)(rect.rb.y - rect.lt.y));
|
||||
}
|
||||
}
|
||||
41
src/l2/gui/colorblock.h
Normal file
41
src/l2/gui/colorblock.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "../drawer_2d.h"
|
||||
#include "widget.h"
|
||||
|
||||
typedef struct {
|
||||
EmptyWidget base;
|
||||
Plain2dShapeRenderer* drawer;
|
||||
vec4 color;
|
||||
} ColorblockWidget;
|
||||
|
||||
uvec2 Widget_Table_ColorblockWidget_DRAW_PREPARE(Widget* ug, uvec2 limits) {
|
||||
return Widget_Table_EmptyWidget_DRAW_PREPARE(ug, limits);
|
||||
}
|
||||
|
||||
void Widget_Table_ColorblockWidget_DRAW(Widget* ug, ivec2 drawing_offset, uvec2 surface_sz, BorderS32 border) {
|
||||
ColorblockWidget* self = (ColorblockWidget*)ug;
|
||||
assert_sane_widget_size(self->base.base.sz_my_choice);
|
||||
S32 width = (S32)self->base.base.sz_my_choice.x;
|
||||
S32 height = (S32)self->base.base.sz_my_choice.y;
|
||||
Plain2dShapeRenderer_add_rect_clipped(self->drawer, self->color, drawing_offset, width, height, border);
|
||||
}
|
||||
|
||||
void Widget_Table_ColorblockWidget_drop(Widget* ug) {}
|
||||
|
||||
const Widget_Table Widget_Table_ColorblockWidget = {
|
||||
.DRAW_PREPARE = Widget_Table_ColorblockWidget_DRAW_PREPARE,
|
||||
.DRAW = Widget_Table_ColorblockWidget_DRAW,
|
||||
.drop = Widget_Table_ColorblockWidget_drop,
|
||||
};
|
||||
|
||||
ColorblockWidget ColorblockWidget_new(S32 width, S32 height, vec4 color, Plain2dShapeRenderer* drawer) {
|
||||
return (ColorblockWidget){.base = (EmptyWidget){.base = Widget_new(), .width = width, .height = height},
|
||||
.color = color, .drawer = drawer};
|
||||
}
|
||||
|
||||
// BoxWidget ColorblockWidget_new_box(U32 width, U32 height, vec4 color, Plain2dShapeRenderer* drawer){
|
||||
// ColorblockWidget* r = (ColorblockWidget*)safe_malloc(sizeof(ColorblockWidget));
|
||||
// *r = ColorblockWidget_new(width, height, color, drawer);
|
||||
// return (BoxWidget){.r = (Widget*)r, .t = &Widget_Table_ColorblockWidget};
|
||||
// }
|
||||
63
src/l2/gui/colorframe.h
Normal file
63
src/l2/gui/colorframe.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "../drawer_2d.h"
|
||||
#include "widget.h"
|
||||
|
||||
typedef struct {
|
||||
Widget base;
|
||||
S32 left_p, right_p, bottom_p, top_p;
|
||||
Plain2dShapeRenderer* drawer;
|
||||
vec4 color;
|
||||
MutRefWidget child;
|
||||
} ColorframeWidget;
|
||||
|
||||
uvec2 Widget_Table_ColorframeWidget_DRAW_PREPARE(Widget* ug, uvec2 limits) {
|
||||
ColorframeWidget* self = (ColorframeWidget*)ug;
|
||||
S32 taken_width = self->left_p + self->right_p;
|
||||
S32 taken_height = self->top_p + self->bottom_p;
|
||||
S32 rem_width = MAX_S32((S32)limits.x - taken_width, 0);
|
||||
S32 rem_height = MAX_S32((S32)limits.y - taken_height, 0);
|
||||
/* It can be useful even when one of the dimensions is zero */
|
||||
uvec2 child_chose = MutRefWidget_draw_prepare(self->child, (uvec2){rem_width, rem_height});
|
||||
return widget_size_min_of_all(limits, (uvec2){child_chose.x + taken_width, child_chose.y + taken_height});
|
||||
}
|
||||
|
||||
void Widget_Table_ColorframeWidget_DRAW(Widget* ug, ivec2 drawing_offset, uvec2 surface_sz, BorderS32 border) {
|
||||
ColorframeWidget* self = (ColorframeWidget*)ug;
|
||||
S32 taken_width = self->left_p + self->right_p;
|
||||
S32 taken_height = self->top_p + self->bottom_p;
|
||||
S32 width = (S32)self->base.sz_my_choice.x;
|
||||
S32 height = (S32)self->base.sz_my_choice.y;
|
||||
if (width == 0 || height == 0)
|
||||
return;
|
||||
if (taken_width >= width || taken_height >= height) {
|
||||
Plain2dShapeRenderer_add_rect_clipped(self->drawer, self->color, drawing_offset, width, height, border);
|
||||
} else {
|
||||
Plain2dShapeRenderer_add_rect_clipped(self->drawer, self->color, drawing_offset, width, self->top_p, border);
|
||||
Plain2dShapeRenderer_add_rect_clipped(self->drawer, self->color,
|
||||
(ivec2){drawing_offset.x, drawing_offset.y + self->top_p}, self->left_p, height - taken_height, border);
|
||||
Plain2dShapeRenderer_add_rect_clipped(self->drawer, self->color,
|
||||
(ivec2){drawing_offset.x + width - self->right_p, drawing_offset.y + self->top_p}, self->right_p, height - taken_height, border);
|
||||
Plain2dShapeRenderer_add_rect_clipped(self->drawer, self->color,
|
||||
(ivec2){drawing_offset.x, drawing_offset.y + height - self->bottom_p}, width, self->bottom_p, border);
|
||||
MutRefWidget_draw(self->child, (ivec2){drawing_offset.x + self->left_p, drawing_offset.y + self->top_p}, surface_sz, border);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget_Table_ColorframeWidget_drop(Widget* ug){}
|
||||
|
||||
const Widget_Table Widget_Table_ColorframeWidget = {
|
||||
.DRAW_PREPARE = Widget_Table_ColorframeWidget_DRAW_PREPARE,
|
||||
.DRAW = Widget_Table_ColorframeWidget_DRAW,
|
||||
.drop = Widget_Table_ColorframeWidget_drop,
|
||||
};
|
||||
|
||||
|
||||
ColorframeWidget ColorframeWidget_new(S32 left_p, S32 right_p, S32 bottom_p, S32 top_p,
|
||||
Plain2dShapeRenderer* drawer, vec4 color, MutRefWidget child
|
||||
) {
|
||||
return (ColorframeWidget){.base = Widget_new(),
|
||||
.left_p = left_p, .right_p = right_p, .bottom_p = bottom_p, .top_p = top_p,
|
||||
.drawer = drawer, .color = color, .child = child
|
||||
};
|
||||
}
|
||||
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "../lucy/glyph_render.h"
|
||||
|
||||
// todo: add что-то
|
||||
57
src/l2/gui/stacks.h
Normal file
57
src/l2/gui/stacks.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "widget.h"
|
||||
#include "../../../gen/l1/gui/VecMutRefWidget.h"
|
||||
#include "../../../gen/l1/VecAndSpan_S32.h"
|
||||
|
||||
typedef struct {
|
||||
Widget base;
|
||||
VecMutRefWidget children;
|
||||
VecS32 decided_positions;
|
||||
} LtoRStackWidget;
|
||||
|
||||
uvec2 Widget_Table_LtoRStackWidget_DRAW_PREPARE(Widget* ug, uvec2 limits) {
|
||||
LtoRStackWidget* self = (LtoRStackWidget*)ug;
|
||||
S32 pos = 0;
|
||||
S32 max_w = 0;
|
||||
self->decided_positions.len = 0;
|
||||
U64 n = self->children.len;
|
||||
for (U64 i = 0; i < n; i++) {
|
||||
if (pos >= (S32)limits.y)
|
||||
break;
|
||||
uvec2 child_sz = MutRefWidget_draw_prepare(self->children.buf[i], (uvec2){.x = limits.x, .y = limits.y - pos});
|
||||
max_w = MAX_S32(max_w, child_sz.x);
|
||||
VecS32_append(&self->decided_positions, pos);
|
||||
pos += (S32)child_sz.y;
|
||||
}
|
||||
return (uvec2){max_w, pos};
|
||||
}
|
||||
|
||||
void Widget_Table_LtoRStackWidget_DRAW(Widget* ug, ivec2 drawing_offset, uvec2 surface_sz, BorderS32 border) {
|
||||
LtoRStackWidget* self = (LtoRStackWidget*)ug;
|
||||
for (U64 i = 0; i < self->decided_positions.len; i++) {
|
||||
S32 pos = self->decided_positions.buf[i];
|
||||
assert(i < self->children.len);
|
||||
MutRefWidget_draw(self->children.buf[i], (ivec2){drawing_offset.x, drawing_offset.y + pos}, surface_sz, border);
|
||||
}
|
||||
}
|
||||
|
||||
void LtoRStackWidget_drop(LtoRStackWidget self) {
|
||||
VecMutRefWidget_drop(self.children);
|
||||
VecS32_drop(self.decided_positions);
|
||||
}
|
||||
|
||||
void Widget_Table_LtoRStackWidget_drop(Widget* self) {
|
||||
LtoRStackWidget_drop(*(LtoRStackWidget*)self);
|
||||
}
|
||||
|
||||
const Widget_Table Widget_Table_LtoRStack = {
|
||||
.DRAW_PREPARE = Widget_Table_LtoRStackWidget_DRAW_PREPARE,
|
||||
.DRAW = Widget_Table_LtoRStackWidget_DRAW,
|
||||
.drop = Widget_Table_LtoRStackWidget_drop,
|
||||
};
|
||||
|
||||
LtoRStackWidget LtoRStackWidget_new() {
|
||||
return (LtoRStackWidget){.base = Widget_new(),
|
||||
.children = VecMutRefWidget_new(), .decided_positions = VecS32_new()};
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../gen/l1/geom.h"
|
||||
#include "../../l1/core/util.h"
|
||||
#include "../../l1_5/marie/graphics_geom.h"
|
||||
|
||||
#define WIDGET_DIM_INF 1000000
|
||||
|
||||
@ -17,21 +16,6 @@ void assert_sane_widget_size_limits(uvec2 max_limits){
|
||||
assert(max_limits.x <= WIDGET_DIM_INF || max_limits.y <= WIDGET_DIM_INF);
|
||||
}
|
||||
|
||||
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){
|
||||
{MAX_S32(a.lt.x, b.lt.x), MAX_S32(a.lt.y, b.lt.y)},
|
||||
{MAX_S32(a.rb.x, b.rb.x), MAX_S32(a.rb.y, b.rb.y)},
|
||||
};
|
||||
}
|
||||
|
||||
uvec2 widget_size_max_of_all(uvec2 a, uvec2 b){
|
||||
return (uvec2){MAX_U32(a.x, b.x), MAX_U32(a.y, b.y)};
|
||||
}
|
||||
@ -53,6 +37,7 @@ Widget Widget_new(){
|
||||
|
||||
#include "../../../gen/l1_5/eve/gui/Widget.h"
|
||||
|
||||
/* NULL can be passed here */
|
||||
uvec2 MutRefWidget_draw_prepare(MutRefWidget self, uvec2 max_limits){
|
||||
if (!self.r)
|
||||
return (uvec2){0};
|
||||
@ -61,12 +46,13 @@ uvec2 MutRefWidget_draw_prepare(MutRefWidget self, uvec2 max_limits){
|
||||
return self.r->sz_my_choice;
|
||||
}
|
||||
|
||||
/* NULL can be passed here */
|
||||
void MutRefWidget_draw(MutRefWidget self, ivec2 drawing_offset, uvec2 surface_sz, BorderS32 border){
|
||||
if (!self.r)
|
||||
return;
|
||||
if (self.r->sz_my_choice.x >= WIDGET_DIM_INF)
|
||||
abortf("Drawing widget before negotiating it's size\n");
|
||||
MutRefWidget_draw(self, drawing_offset, surface_sz, border);
|
||||
MutRefWidget_DRAW(self, drawing_offset, surface_sz, border);
|
||||
self.r->sz_my_choice = (uvec2){WIDGET_DIM_INF, 0};
|
||||
}
|
||||
|
||||
@ -74,16 +60,18 @@ void MutRefWidget_draw(MutRefWidget self, ivec2 drawing_offset, uvec2 surface_sz
|
||||
|
||||
typedef struct {
|
||||
Widget base;
|
||||
U32 width;
|
||||
U32 height;
|
||||
S32 width;
|
||||
S32 height;
|
||||
} EmptyWidget;
|
||||
|
||||
uvec2 Widget_Table_EmptyWidget_DRAW_PREPARE(Widget* ug, uvec2 limits){
|
||||
EmptyWidget* self = (EmptyWidget*)ug;
|
||||
uvec2 R = widget_size_min_of_all((uvec2){self->width, self->height}, limits);
|
||||
/* Please, do not put infinite widget into infinite box, I don't want to see what happens */
|
||||
return is_widget_size_limit_contain_inf(R) ? (uvec2){0, 0} : R;
|
||||
}
|
||||
|
||||
// todo: remove `surface_sz` argument
|
||||
void Widget_Table_EmptyWidget_DRAW(Widget* ug, ivec2 drawing_offset, uvec2 surface_sz, BorderS32 border){}
|
||||
|
||||
void Widget_Table_EmptyWidget_drop(Widget* ug){}
|
||||
@ -94,8 +82,13 @@ const Widget_Table Widget_Table_EmptyWidget = {
|
||||
.drop = Widget_Table_EmptyWidget_drop,
|
||||
};
|
||||
|
||||
BoxWidget EmptyWidget_new_box(U32 width, U32 height){
|
||||
EmptyWidget* r = safe_malloc(sizeof(EmptyWidget));
|
||||
*r = (EmptyWidget){.base = Widget_new(), .width = width, .height = height};
|
||||
return (BoxWidget){.r = (Widget*)r, .t = &Widget_Table_EmptyWidget};
|
||||
EmptyWidget EmptyWidget_new(S32 width, S32 height) {
|
||||
assert(width >= 0 && height >= 0);
|
||||
return (EmptyWidget){.base = Widget_new(), .width = width, .height = height};
|
||||
}
|
||||
|
||||
// BoxWidget EmptyWidget_new_box(U32 width, U32 height){
|
||||
// EmptyWidget* r = safe_malloc(sizeof(EmptyWidget));
|
||||
// *r = (EmptyWidget){.base = Widget_new(), .width = width, .height = height};
|
||||
// return (BoxWidget){.r = (Widget*)r, .t = &Widget_Table_EmptyWidget};
|
||||
// }
|
||||
|
||||
@ -202,10 +202,7 @@ void LucyGlyphCache_add_glyphs__close_img(
|
||||
}, 0, NULL);
|
||||
}
|
||||
|
||||
void LucyGlyphCache_add_glyphs(VecLucyGlyphCachingRequest requests_for_faces){
|
||||
if (requests_for_faces.len == 0)
|
||||
return;
|
||||
LucyGlyphCache* cache = requests_for_faces.buf[0].sized_face->value.p->p;
|
||||
void LucyGlyphCache_add_glyphs(LucyGlyphCache* cache, VecLucyGlyphCachingRequest requests_for_faces){
|
||||
for (size_t fi = 0; fi < requests_for_faces.len; fi++) {
|
||||
assert(cache == requests_for_faces.buf[fi].sized_face->value.p->p);
|
||||
}
|
||||
|
||||
@ -103,8 +103,6 @@ void LucyRenderer_draw_char_glyph(LucyRenderer* self, vec4 color, ivec2 pos, Luc
|
||||
|
||||
U64 needed_vbo_length = (self->glyphs_count + 1) * sizeof(LucyRenderInstance);
|
||||
if (self->staging_vbo.len < needed_vbo_length) {
|
||||
//printf("LucyRenderer Staging Buffer: Gotta replace %lu with %lu\n",
|
||||
// self->staging_vbo.len, needed_vbo_length);
|
||||
MargaretBufAllocator_expand_or_move_old_host_visible(
|
||||
self->ve.staging_buffers, &self->staging_vbo, needed_vbo_length);
|
||||
}
|
||||
@ -131,7 +129,7 @@ void LucyRenderer_draw_char_glyph(LucyRenderer* self, vec4 color, ivec2 pos, Luc
|
||||
*/
|
||||
void LucyRenderer_add_simple_label(
|
||||
LucyRenderer* self, RBTreeNodeLucyFaceFixedSize* ffs, vec4 color,
|
||||
U32 additional_y_advance, SpanU8 text, ivec2 start_pos
|
||||
S32 additional_y_advance, SpanU8 text, ivec2 start_pos
|
||||
){
|
||||
self->need_to_transfer = true;
|
||||
U32 font_height = ffs->key;
|
||||
@ -140,7 +138,7 @@ void LucyRenderer_add_simple_label(
|
||||
while (text.len > 0) {
|
||||
U32 codepoint = SpanU8_decode_as_utf8(&text);
|
||||
if (codepoint == (U32)'\n') {
|
||||
pos = (ivec2){start_pos.x, pos.y + (S32)font_height + (S32)additional_y_advance};
|
||||
pos = (ivec2){start_pos.x, pos.y + (S32)font_height + additional_y_advance};
|
||||
continue;
|
||||
}
|
||||
BufRBTree_MapU32ToLucyStoredGlyph *glyphs = &ffs->value.glyphs;
|
||||
|
||||
@ -3,7 +3,10 @@
|
||||
#include "../../l1_5/marie/prim_shape_geom.h"
|
||||
#include "../../../gen/l1/VecAndSpan_vec3.h"
|
||||
#include "../../l1_5/core/color.h"
|
||||
|
||||
#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"
|
||||
|
||||
|
||||
@ -25,7 +28,7 @@ typedef struct{
|
||||
|
||||
typedef struct {
|
||||
float mass; /* In kg, Not zero */
|
||||
quad_form3_t inertia_moment; /* Qadratic form, yields kg*m^2 */
|
||||
quad_form3_t inertia_moment; /* Quadratic form, yields kg*m^2 */
|
||||
/* Center of mass relative to "center of mesh" */
|
||||
vec3 mass_center;
|
||||
} RigidBodyConfig;
|
||||
@ -83,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;
|
||||
@ -101,7 +106,13 @@ typedef struct{
|
||||
U64 hits_count;
|
||||
Vecvec3 bullets_stuck_on_ROA;
|
||||
|
||||
MargaretSubbuf sb;
|
||||
/* overlay ui */
|
||||
ColorblockWidget gui_0;
|
||||
ColorframeWidget gui_1;
|
||||
ColorblockWidget gui_2;
|
||||
ColorblockWidget gui_3;
|
||||
LtoRStackWidget gui_4;
|
||||
ColorframeWidget gui_5;
|
||||
} R4BetaState;
|
||||
|
||||
/* We are surrounded by a giant cubic mesh of light sources */
|
||||
@ -144,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;
|
||||
@ -220,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));
|
||||
@ -244,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),
|
||||
});
|
||||
|
||||
@ -259,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),
|
||||
});
|
||||
@ -273,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),
|
||||
@ -282,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));
|
||||
@ -295,7 +324,7 @@ void main_h_on_another_frame(void* data, float fl){
|
||||
if (st->hits_count > 0) {
|
||||
VecU8_append_fmt(&text, "You hit ROA %u times\n", st->hits_count);
|
||||
}
|
||||
LucyRenderer_add_simple_label(&alice->lucy_renderer, st->font_face_of_size_40, (vec4){0, 0, 0, 1}, 0,
|
||||
Alice_lucy_renderer_add_simple_label(alice, st->font_face_of_size_40, (vec4){0, 0, 0, 1}, 0,
|
||||
VecU8_to_span(&text), (ivec2){10, 10});
|
||||
VecU8_drop(text);
|
||||
}
|
||||
@ -303,12 +332,12 @@ 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;
|
||||
st.alice->guest = &st;
|
||||
|
||||
st.font_face = LucyFace_new(st.alice->ft_library, &st.alice->lucy_cache,
|
||||
vcstr("./src/l3/fonts/DMSerifText-Regular.ttf"));
|
||||
st.font_face = Alice_new_LucyFace(alice, vcstr("./src/l3/fonts/DMSerifText-Regular.ttf"));
|
||||
st.font_face_of_size_40 = LucyFace_of_size(st.font_face, 40);
|
||||
VecLucyGlyphCachingRequest lucy_requests = VecLucyGlyphCachingRequest_new();
|
||||
VecU32Segment ranges_needed = VecU32Segment_new();
|
||||
@ -316,18 +345,32 @@ void run_app(){
|
||||
VecLucyGlyphCachingRequest_append(&lucy_requests, (LucyGlyphCachingRequest){
|
||||
.sized_face = st.font_face_of_size_40, .codepoint_ranges = ranges_needed,
|
||||
});
|
||||
LucyGlyphCache_add_glyphs(lucy_requests);
|
||||
Alice_lucy_cache_add_glyphs(alice, lucy_requests);
|
||||
lucy_requests = VecLucyGlyphCachingRequest_new();
|
||||
ranges_needed = VecU32Segment_new();
|
||||
VecU32Segment_append(&ranges_needed, (U32Segment){.start = 0x430, .len = 0x44f - 0x430 + 1});
|
||||
VecLucyGlyphCachingRequest_append(&lucy_requests, (LucyGlyphCachingRequest){
|
||||
.sized_face = st.font_face_of_size_40, .codepoint_ranges = ranges_needed,
|
||||
});
|
||||
Alice_lucy_cache_add_glyphs(alice, lucy_requests);
|
||||
|
||||
LucyGlyphCache_add_glyphs(lucy_requests);
|
||||
LucyRenderer_add_simple_label(&st.alice->lucy_renderer, st.font_face_of_size_40, (vec4){0, 0, 0, 1}, 0,
|
||||
Alice_lucy_renderer_add_simple_label(alice, st.font_face_of_size_40, (vec4){0, 0, 0, 1}, 0,
|
||||
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};
|
||||
|
||||
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);
|
||||
|
||||
@ -338,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,
|
||||
@ -386,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;
|
||||
@ -394,9 +437,11 @@ void run_app(){
|
||||
st.bullets_stuck_on_ROA = Vecvec3_new();
|
||||
|
||||
Alice_mainloop(st.alice, &(AliceCallbacks){
|
||||
.guest = &st,
|
||||
.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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
62
src/l3/r4/r4c.cpp
Normal file
62
src/l3/r4/r4c.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include "../../l2/allie_cpp/alice.hpp"
|
||||
#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>;
|
||||
|
||||
struct AppMem {
|
||||
float gr = 0;
|
||||
};
|
||||
|
||||
struct R4C_State {
|
||||
unique<Alice> alice;
|
||||
unique<LucyFace> face;
|
||||
unique<LucyFaceFixedSize> sized_face;
|
||||
|
||||
AppMem app;
|
||||
};
|
||||
|
||||
vec4 funky_color(float time) {
|
||||
return vec4{(sinf(0.95f * time + 0.6f) + 1) / 2, (sinf(0.233f * time + 0.2f) + 1) / 2, (sinf(1.433f * time) + 1) / 2, 1};
|
||||
}
|
||||
|
||||
void main_h_on_another_frame(void* data, float fl) {
|
||||
R4C_State& st = *(R4C_State*)data;
|
||||
Alice& alice = *st.alice;
|
||||
LucyFaceFixedSize& ffs = *st.sized_face;
|
||||
st.app.gr += fl;
|
||||
alice.lucy_renderer_add_simple_label(ffs, funky_color(st.app.gr), 0, "Hello from C++", ivec2(500, 50));
|
||||
}
|
||||
|
||||
void main_h_on_wl_keyboard_key(void* data, U32 keysym, U32 act) {
|
||||
|
||||
}
|
||||
|
||||
void main_h_on_wl_pointer_button(void* data, U32 button, U32 act) {
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
R4C_State st{};
|
||||
st.alice = std::make_unique<Alice>();
|
||||
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,
|
||||
.on_wl_keyboard_key = main_h_on_wl_keyboard_key,
|
||||
.on_another_frame = main_h_on_another_frame,
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
9
src/l_adele/drawer_2d/plain/plain.frag
Normal file
9
src/l_adele/drawer_2d/plain/plain.frag
Normal file
@ -0,0 +1,9 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec4 color;
|
||||
|
||||
layout(location = 0) out vec4 fin_color;
|
||||
|
||||
void main(){
|
||||
fin_color = color;
|
||||
}
|
||||
24
src/l_adele/drawer_2d/plain/plain.vert
Normal file
24
src/l_adele/drawer_2d/plain/plain.vert
Normal file
@ -0,0 +1,24 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 pos;
|
||||
layout(location = 1) in vec4 color;
|
||||
|
||||
layout(push_constant, std430) uniform pc {
|
||||
float width;
|
||||
float height;
|
||||
};
|
||||
|
||||
layout (location = 0) out vec4 vsout_color;
|
||||
|
||||
float lint(float A1, float B1, float A2, float B2, float x){
|
||||
return A2 + (B2 - A2) * (x - A1) / (B1 - A1);
|
||||
}
|
||||
|
||||
float deng(float B1, float x){
|
||||
return lint(0, B1, -1, 1, x);
|
||||
}
|
||||
|
||||
void main(){
|
||||
vsout_color = color;
|
||||
gl_Position = vec4(deng(width, pos.x), deng(height, pos.y), 0, 1);
|
||||
}
|
||||
@ -38,5 +38,4 @@ void main(){
|
||||
vsout_tex_ind = tex_ind;
|
||||
vec2 pos = all_v_pos[gl_VertexIndex % 6];
|
||||
gl_Position = vec4(deng(width, pos.x), deng(height, pos.y), 0, 1);
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user