diff --git a/nasm.code-workspace b/nasm.code-workspace index 4d2ea5a..c4af2c1 100644 --- a/nasm.code-workspace +++ b/nasm.code-workspace @@ -23,7 +23,9 @@ "string_view": "c", "ranges": "c", "span": "c", - "vector": "c" + "vector": "c", + "regex": "c", + "__node_handle": "c" }, } } diff --git a/wayland/CMakeLists.txt b/wayland/CMakeLists.txt index 4cac788..ded74ab 100644 --- a/wayland/CMakeLists.txt +++ b/wayland/CMakeLists.txt @@ -4,7 +4,7 @@ project(wayland) enable_language(ASM_NASM) -set(CMAKE_ASM_NASM_FLAGS "-f elf64") +set(CMAKE_ASM_NASM_FLAGS "-f elf64 -I${CMAKE_CURRENT_BINARY_DIR}") set(CMAKE_ASM_NASM_FLAGS_DEBUG "-gdwarf") find_package(PkgConfig REQUIRED) @@ -39,6 +39,19 @@ add_custom_command( # Цель для генерации протокола add_custom_target(generate-xdg-shell DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.h ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protocol.c) +# Генерируем offsets.inc +add_executable(generate-offsets ${CMAKE_CURRENT_SOURCE_DIR}/generate-offsets.c) +target_include_directories(generate-offsets PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) + +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/offsets.inc + COMMAND generate-offsets > ${CMAKE_CURRENT_BINARY_DIR}/offsets.inc + DEPENDS generate-offsets + COMMENT "Generating offsets.inc" +) + +add_custom_target(generate-offsets-file DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/offsets.inc) + # Создаем исполняемый файл из ассемблерного, C и сгенерированного кода file(GLOB_RECURSE WAYLAND_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c" @@ -53,7 +66,7 @@ list(APPEND WAYLAND_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell-client-protoco add_executable(wayland ${WAYLAND_SOURCES}) # Ensure generated files are produced before building the target -add_dependencies(wayland generate-xdg-shell) +add_dependencies(wayland generate-xdg-shell generate-offsets-file) # Include headers and binary dir where generated headers are written target_include_directories(wayland PRIVATE diff --git a/wayland/generate-offsets.c b/wayland/generate-offsets.c new file mode 100644 index 0000000..565e698 --- /dev/null +++ b/wayland/generate-offsets.c @@ -0,0 +1,29 @@ +/* generate-offsets.c + * Генерирует offsets.inc с смещениями полей структур + */ + +#include +#include +#include "window.h" + +int main(void) { + printf("; offsets.inc — generated automatically\n"); + + // window_draw_info offsets + printf("WDI_DATA equ %zu\n", offsetof(struct window_draw_info, data)); + printf("WDI_WIDTH equ %zu\n", offsetof(struct window_draw_info, width)); + printf("WDI_HEIGHT equ %zu\n", offsetof(struct window_draw_info, height)); + printf("WDI_FIGURE equ %zu\n", offsetof(struct window_draw_info, figure)); + printf("WDI_FIGURE_MUTEX equ %zu\n", offsetof(struct window_draw_info, figure_mutex)); + printf("\n"); + + // figure_animation_info offsets + printf("FIG_TYPE equ %zu\n", offsetof(struct figure_animation_info, type)); + printf("FIG_POSITION equ %zu\n", offsetof(struct figure_animation_info, position)); + printf("FIG_VELOCITY equ %zu\n", offsetof(struct figure_animation_info, velocity)); + printf("FIG_ANGLE equ %zu\n", offsetof(struct figure_animation_info, angle)); + printf("FIG_ANG_VEL equ %zu\n", offsetof(struct figure_animation_info, angular_velocity)); + printf("FIG_SPEED equ %zu\n", offsetof(struct figure_animation_info, speed)); + + return 0; +} diff --git a/wayland/include/figure-animate.h b/wayland/include/figure-animate.h index 7e3218e..3919e54 100644 --- a/wayland/include/figure-animate.h +++ b/wayland/include/figure-animate.h @@ -4,6 +4,6 @@ #include "window.h" /* Провести один шаг анимации на окне */ -void animation_step(struct window_draw_info* draw_info); +void figure_animation_step(struct window_draw_info* draw_info); #endif diff --git a/wayland/src/figure-animate.asm b/wayland/src/figure-animate.asm index e69de29..6591c31 100644 --- a/wayland/src/figure-animate.asm +++ b/wayland/src/figure-animate.asm @@ -0,0 +1,39 @@ +; Подключаем автоматически сгенерированные offsets из C структур +%include "offsets.inc" + +section .text + +; void animation_step(struct window_draw_info* draw_info); +; Параметры: +; rdi - указатель на struct window_draw_info +global figure_animation_step +figure_animation_step: + enter 0, 0 + + ; Сохранение регистров (если будут использоваться) + ; push rbx + ; push r12 + ; push r13 + + ; rdi содержит указатель на window_draw_info + ; Доступ к полям через константы из offsets.inc: + mov rax, WDI_FIGURE ; указатель на данные + ; mov edx, [rdi + WD_WIDTH] ; ширина окна + ; mov ecx, [rdi + WD_HEIGHT] ; высота окна + ; lea rsi, [rdi + WD_FIGURE] ; указатель на figure_animation_info + ; + ; Доступ к полям figure_animation_info (относительно rsi): + ; mov eax, [rsi + FIG_TYPE] ; тип фигуры + ; movss xmm0, [rsi + FIG_ANGLE] ; угол поворота + ; movss xmm1, [rsi + FIG_SPEED] ; скорость + + ; --- Здесь будет логика анимации --- + + + ; Восстановление регистров + ; pop r13 + ; pop r12 + ; pop rbx + + leave + ret diff --git a/wayland/src/wayland-runtime.c b/wayland/src/wayland-runtime.c index 8a8c716..8d537b5 100644 --- a/wayland/src/wayland-runtime.c +++ b/wayland/src/wayland-runtime.c @@ -11,6 +11,7 @@ #include "registry.h" #include "wayland-runtime.h" #include "window.h" +#include "figure-animate.h" #define MAX_WINDOW_THREADS 128 @@ -48,8 +49,9 @@ static void *window_aux_loop(void *arg) { /* На время обновления позиции фигуры локаем мутекс */ pthread_mutex_lock(&draw_info->figure_mutex); - usleep(10 * 1000); + figure_animation_step(draw_info); pthread_mutex_unlock(&draw_info->figure_mutex); + usleep(100 * 1000); } return NULL;