Skip to content

Commit

Permalink
修复本机测试程序动态链接的问题,修正资源文件目录
Browse files Browse the repository at this point in the history
  • Loading branch information
copi143 committed Jan 26, 2025
1 parent 7bc71f5 commit 33d2aa6
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 39 deletions.
15 changes: 15 additions & 0 deletions cmake/mklib
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,18 @@ macro(utillib arg1)
file(GLOB_RECURSE cpp_files "${PROJECT_SOURCE_DIR}/src/${arg1}/*.cpp")
addlib(util-${arg1} ${asm_files} ${c_files} ${cpp_files})
endmacro(utillib)

macro(utillib_exclude arg1)
set(without_files)
foreach(file ${ARGN})
get_filename_component(absolute_path "${PROJECT_SOURCE_DIR}/src/${arg1}/${file}" ABSOLUTE)
list(APPEND without_files ${absolute_path})
endforeach()
file(GLOB_RECURSE asm_files "${PROJECT_SOURCE_DIR}/src/${arg1}/*.asm")
file(GLOB_RECURSE c_files "${PROJECT_SOURCE_DIR}/src/${arg1}/*.c")
file(GLOB_RECURSE cpp_files "${PROJECT_SOURCE_DIR}/src/${arg1}/*.cpp")
list(REMOVE_ITEM asm_files ${without_files})
list(REMOVE_ITEM c_files ${without_files})
list(REMOVE_ITEM cpp_files ${without_files})
addlib(util-${arg1} ${asm_files} ${c_files} ${cpp_files})
endmacro(utillib_exclude)
6 changes: 3 additions & 3 deletions include/data-structure/sorted-map/avltree.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ static avltree_t avltree_delete_with(avltree_t root, int32_t key,
return avltree_balance(root);
}

static void avltree_print_inorder(avltree_t root, int depth) {
static void avltree_print_inorder(avltree_t root, int depth) noexcept {
if (depth == 0) printf("In-order traversal of the AVL Tree: \n");
if (root == null) return;
avltree_print_inorder(root->left, depth + 1);
Expand All @@ -371,7 +371,7 @@ static void avltree_print_inorder(avltree_t root, int depth) {
avltree_print_inorder(root->right, depth + 1);
}

static void avltree_print_preorder(avltree_t root, int depth) {
static void avltree_print_preorder(avltree_t root, int depth) noexcept {
if (depth == 0) printf("Pre-order traversal of the AVL Tree: \n");
if (root == null) return;
for (int i = 0; i < depth; i++)
Expand All @@ -381,7 +381,7 @@ static void avltree_print_preorder(avltree_t root, int depth) {
avltree_print_preorder(root->right, depth + 1);
}

static void avltree_print_postorder(avltree_t root, int depth) {
static void avltree_print_postorder(avltree_t root, int depth) noexcept {
if (depth == 0) printf("Post-order traversal of the AVL Tree: \n");
if (root == null) return;
avltree_print_postorder(root->left, depth + 1);
Expand Down
10 changes: 5 additions & 5 deletions include/pl2d/texture/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace pl2d {

// 显式模板实例化
#define BaseTextureInstantiation \
template class BaseTexture<PixelB>; \
template class BaseTexture<PixelS>; \
template class BaseTexture<PixelF>; \
template class BaseTexture<PixelD>;
template class dlexport BaseTexture<PixelB>; \
template class dlexport BaseTexture<PixelS>; \
template class dlexport BaseTexture<PixelF>; \
template class dlexport BaseTexture<PixelD>;

// BaseTexture 参数约定:
// 图像宽度与高度必须是 2 的整数倍
Expand Down Expand Up @@ -38,7 +38,7 @@ struct BaseTexture {
BaseTexture(T *pixels, u32 width, u32 height, u32 pitch); // 使用外部数据创建纹理
BaseTexture(const BaseTexture &) = delete; // 隐式地复制是不允许的
BaseTexture(BaseTexture &&) noexcept; // 移动是可以的
~BaseTexture() noexcept;
dlexport ~BaseTexture() noexcept;
auto operator=(const BaseTexture &) -> BaseTexture & = delete; // 隐式地复制是不允许的
auto operator=(BaseTexture &&) noexcept -> BaseTexture &; // 移动是可以的

Expand Down
2 changes: 1 addition & 1 deletion src/asio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mklib(asio)
# mklib(asio)
22 changes: 11 additions & 11 deletions src/audio/plac.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static void _plac_decompress_block(f32 *block, void *_plac);

#define block_len 2048

plac_compress_t plac_compress_alloc() {
dlexport plac_compress_t plac_compress_alloc() {
plac_compress_t plac = malloc(sizeof(struct plac_compress));
if (plac == null) return null;
plac->mdct = mdctf_alloc(2 * block_len, false, _plac_compress_block);
Expand All @@ -35,7 +35,7 @@ plac_compress_t plac_compress_alloc() {
return plac;
}

void plac_compress_free(plac_compress_t plac) {
dlexport void plac_compress_free(plac_compress_t plac) {
if (plac == null) return;
mdctf_free(plac->mdct);
mostream_free(plac->stream);
Expand All @@ -61,11 +61,11 @@ void plac_write_header_v1(plac_compress_t plac, u32 samplerate, u64 nsamples) {
mostream_write(plac->stream, &nsamples, 8);
}

void plac_write_header(plac_compress_t plac, u32 samplerate, u64 nsamples) {
dlexport void plac_write_header(plac_compress_t plac, u32 samplerate, u64 nsamples) {
plac_write_header_v1(plac, samplerate, nsamples);
}

void plac_write_data(plac_compress_t plac, quantized_t q) {
dlexport void plac_write_data(plac_compress_t plac, quantized_t q) {
mostream_write(plac->stream, &q->nbit, 2);
mostream_write(plac->stream, &q->max, 2);
if (q->nbit == 0) return;
Expand Down Expand Up @@ -95,15 +95,15 @@ static void _plac_compress_block(f32 *block, void *_plac) {
plac_write_data(plac, &plac->q);
}

void plac_compress_block(plac_compress_t plac, f32 *block, size_t len) {
dlexport void plac_compress_block(plac_compress_t plac, f32 *block, size_t len) {
mdctf_put(plac->mdct, block, len);
}

void plac_compress_final(plac_compress_t plac) {
dlexport void plac_compress_final(plac_compress_t plac) {
mdctf_final(plac->mdct);
}

plac_decompress_t plac_decompress_alloc(const void *buffer, size_t size) {
dlexport plac_decompress_t plac_decompress_alloc(const void *buffer, size_t size) {
plac_decompress_t plac = malloc(sizeof(struct plac_decompress));
if (plac == null) return null;
plac->mdct = mdctf_alloc(2 * block_len, true, _plac_decompress_block);
Expand All @@ -127,7 +127,7 @@ plac_decompress_t plac_decompress_alloc(const void *buffer, size_t size) {
return plac;
}

void plac_decompress_free(plac_decompress_t plac) {
dlexport void plac_decompress_free(plac_decompress_t plac) {
if (plac == null) return;
mdctf_free(plac->mdct);
mistream_free(plac->stream);
Expand All @@ -136,7 +136,7 @@ void plac_decompress_free(plac_decompress_t plac) {
free(plac);
}

bool plac_read_header(plac_decompress_t plac, u32 *samplerate, u64 *nsamples) {
dlexport bool plac_read_header(plac_decompress_t plac, u32 *samplerate, u64 *nsamples) {
u32 magic;
mistream_read(plac->stream, &magic, 4);
if (magic != MAGIC32('p', 'l', 'a', 'c')) return false;
Expand All @@ -154,7 +154,7 @@ bool plac_read_header(plac_decompress_t plac, u32 *samplerate, u64 *nsamples) {
return true;
}

void plac_read_data(plac_decompress_t plac, quantized_t q) {
dlexport void plac_read_data(plac_decompress_t plac, quantized_t q) {
mistream_read(plac->stream, &q->nbit, 2);
mistream_read(plac->stream, &q->max, 2);
if (q->nbit == 0) return;
Expand Down Expand Up @@ -183,7 +183,7 @@ static void _plac_decompress_block(f32 *block, void *_plac) {
if (plac->callback) plac->callback(block, block_len, plac->userdata);
}

bool plac_decompress_block(plac_decompress_t plac) {
dlexport bool plac_decompress_block(plac_decompress_t plac) {
if (plac->stream->pos == plac->stream->size) return false;
plac_read_data(plac, &plac->q);
dequantize(&plac->q);
Expand Down
1 change: 0 additions & 1 deletion src/kernel/drivers/storage/ahci.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ void port_rebase(HBA_PORT *port, int portno) {
// return (regs[1] >> 8) & 0xFF;
// }

#define PAGE_SIZE 4096
int cache_line_size = 0;
// 刷新缓存函数
void flush_cache(void *addr) {
Expand Down
11 changes: 11 additions & 0 deletions src/libc-base/xmalloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <libc-base.h>

#if !NO_STD

dlexport void *xmalloc(usize size) {
void *ptr = malloc(size);
if (ptr == null) abort();
return ptr;
}

#endif
3 changes: 2 additions & 1 deletion src/libc/exit.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <libc-base.h>

void __cxa_atexit() {
dlexport void __cxa_atexit() {
// TODO 目前暂时忽略
}
4 changes: 2 additions & 2 deletions src/misc/math/gaussian-kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ f32 gaussian_kernel_f15[15] = {
4.4318483882e-03, 1.3383022505e-04, 1.4867195068e-06, 6.0758828173e-09, 9.1347203595e-12};

// 一维高斯模糊卷积核
void gaussian_kernel_1(f64 *kernel, i32 size, f64 sigma) {
dlexport void gaussian_kernel_1(f64 *kernel, i32 size, f64 sigma) {
i32 center = size / 2;
f64 sum = 0;
f64 k = -1 / (2 * sigma * sigma);
Expand All @@ -56,7 +56,7 @@ void gaussian_kernel_1(f64 *kernel, i32 size, f64 sigma) {
kernel[i] /= sum;
}
}
void gaussian_kernel_1(f32 *kernel, i32 size, f32 sigma) {
dlexport void gaussian_kernel_1(f32 *kernel, i32 size, f32 sigma) {
i32 center = size / 2;
f32 sum = 0;
f32 k = -1 / (2 * sigma * sigma);
Expand Down
4 changes: 2 additions & 2 deletions src/sound/ima-adpcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const int step_table[89] = {
3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487,
12635, 13899, 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767};

void sound_ima_adpcm_encode(ImaAdpcmCtx *ctx, void *dst, const i16 *src, size_t len) {
dlexport void sound_ima_adpcm_encode(ImaAdpcmCtx *ctx, void *dst, const i16 *src, size_t len) {
for (size_t i = 0; i < len; i++) {
int delta = src[i] - ctx->prev_sample;
int sb = delta < 0 ? 8 : 0;
Expand All @@ -30,7 +30,7 @@ void sound_ima_adpcm_encode(ImaAdpcmCtx *ctx, void *dst, const i16 *src, size_t
}
}

void sound_ima_adpcm_decode(ImaAdpcmCtx *ctx, i16 *dst, const void *src, size_t len) {
dlexport void sound_ima_adpcm_decode(ImaAdpcmCtx *ctx, i16 *dst, const void *src, size_t len) {
for (size_t i = 0; i < len; i++) {
int code = i % 2 == 0 ? ((byte *)src)[i / 2] & 0x0f : ((byte *)src)[i / 2] >> 4;
bool sb = code & 8;
Expand Down
2 changes: 1 addition & 1 deletion test/plui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
file(GLOB_RECURSE c_files "*.c")
file(GLOB_RECURSE cpp_files "*.cpp")
testexec(plui ${c_files} ${cpp_files})
testlib(plui util-misc util-pl2d util-plds util-plui)
testlib(plui util-misc-s util-pl2d-s util-plds-s util-plui-s)
testlib(plui X11 Xext)
18 changes: 10 additions & 8 deletions test/plui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void program_exit() {
}

void create_img(u32 width, u32 height) {
image = XShmCreateImage(display, NULL, 24, ZPixmap, 0, &shm_info, width, height);
image = XShmCreateImage(display, null, 24, ZPixmap, 0, &shm_info, width, height);
shm_info.shmid = shmalloc((size_t)width * height * 4);
shm_info.shmaddr = image->data = shmref(shm_info.shmid, null);
shm_info.readOnly = false;
Expand All @@ -65,7 +65,7 @@ void recreate_img(u32 width, u32 height) {
static void init_xlib(u32 width, u32 height) {
screen_width = width, screen_height = height;

display = XOpenDisplay(NULL);
display = XOpenDisplay(null);
screen = DefaultScreen(display);
Window root = RootWindow(display, screen);
window = XCreateSimpleWindow(display, root, 0, 0, width, height, 1, BlackPixel(display, screen),
Expand Down Expand Up @@ -128,26 +128,28 @@ int loop_body(XEvent e, int pending) {
if (e.type == Expose) {}

if (e.type == ButtonPress) {
if (--e.xbutton.button < 3) plds_on_button_down(e.xbutton.button, e.xbutton.x, e.xbutton.y);
if (e.xbutton.button == 3) plds_on_scroll(-3);
if (e.xbutton.button == 4) plds_on_scroll(3);
val btn = e.xbutton.button - 1;
if (btn < 3) plds_on_button_down(btn, e.xbutton.x, e.xbutton.y);
if (btn == 3) plds_on_scroll(-3);
if (btn == 4) plds_on_scroll(3);
}

if (e.type == ButtonRelease) {
if (--e.xbutton.button < 3) plds_on_button_up(e.xbutton.button, e.xbutton.x, e.xbutton.y);
val btn = e.xbutton.button - 1;
if (btn < 3) plds_on_button_up(btn, e.xbutton.x, e.xbutton.y);
}

if (e.type == MotionNotify) { plds_on_mouse_move(e.xmotion.x, e.xmotion.y); }

if (e.type == KeyPress) {
KeySym key;
XLookupString(&e.xkey, NULL, 0, &key, NULL);
XLookupString(&e.xkey, null, 0, &key, null);
plds_on_key_down(key);
}

if (e.type == KeyRelease) {
KeySym key;
XLookupString(&e.xkey, NULL, 0, &key, NULL);
XLookupString(&e.xkey, null, 0, &key, null);
plds_on_key_up(key);
}

Expand Down
4 changes: 2 additions & 2 deletions test/plui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ auto load_qoi_to_tex(const char *filename, T &tex) {

auto init(void *buffer, u32 width, u32 height, pl2d::PixFmt fmt) -> int {
for (int i = 0; i < 18; i++) {
load_qoi_to_tex(("frame" + std::to_string(i) + ".qoi").c_str(), frame_tex[i]);
load_qoi_to_tex(("../resource/frame" + std::to_string(i) + ".qoi").c_str(), frame_tex[i]);
frame_tex[i].transform([](auto &pix) {
if (pix.brightness() > 240) pix = 0;
});
frame_tex[i].gaussian_blur(11, 2);
}

load_qoi_to_tex("test.qoi", image_tex);
load_qoi_to_tex("../resource/test.qoi", image_tex);

return on::screen_resize(buffer, width, height, fmt);
}
Expand Down
5 changes: 3 additions & 2 deletions util/src.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
utillib(asio)
# utillib(asio)

utillib(libc-base)
utillib_exclude(libc-base math/i64-div.asm)
libdef(util-libc-base NO_STD=0)

utillib(misc)
tgtlib(util-misc util-libc-base)
libdef(util-misc NO_STD=0)

utillib(data-structure)
tgtlib(util-data-structure util-libc-base)
libdef(util-data-structure NO_STD=0)

utillib(font)
Expand Down

0 comments on commit 33d2aa6

Please sign in to comment.