Скелет функции анимации

This commit is contained in:
2025-11-17 15:04:05 +03:00
parent 743b8336a3
commit 5ac43bb236
6 changed files with 90 additions and 5 deletions

View File

@@ -23,7 +23,9 @@
"string_view": "c",
"ranges": "c",
"span": "c",
"vector": "c"
"vector": "c",
"regex": "c",
"__node_handle": "c"
},
}
}

View File

@@ -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

View File

@@ -0,0 +1,29 @@
/* generate-offsets.c
* Генерирует offsets.inc с смещениями полей структур
*/
#include <stdio.h>
#include <stddef.h>
#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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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;