This commit is contained in:
Nishi 2025-12-19 15:18:15 +09:00
commit 3aa9facf8e
Signed by: nishi
GPG key ID: 27EF69B208EB9343
17 changed files with 17023 additions and 76 deletions

View file

@ -14,9 +14,11 @@ file(GLOB CLIENT_SRC client/*.c)
add_executable(af_server ${SERVER_SRC})
add_executable(af_client ${CLIENT_SRC})
add_executable(af_dumpfont tools/af_dumpfont.c external/stb/stb_image_write.c)
target_include_directories(af_server PRIVATE include ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(af_client PRIVATE include ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(af_server PRIVATE include external/stb ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(af_client PRIVATE include external/stb ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(af_dumpfont PRIVATE include external/stb ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(af_server PRIVATE AF_SERVER)
target_compile_definitions(af_client PRIVATE AF_CLIENT)
@ -24,16 +26,28 @@ target_compile_definitions(af_client PRIVATE AF_CLIENT)
target_link_libraries(af_server PRIVATE fishsoup)
target_link_libraries(af_client PRIVATE fishsoup Mw glad)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(af_client PRIVATE glu32)
else()
find_package(PkgConfig)
pkg_check_modules(GLU REQUIRED glu)
target_compile_options(af_client PRIVATE ${GLU_CFLAGS_OTHER})
target_include_directories(af_client PRIVATE ${GLU_INCLUDE_DIRS})
target_link_options(af_client PRIVATE ${GLU_LDFLAGS_OTHER})
target_link_directories(af_client PRIVATE ${GLU_LIBRARY_DIRS})
target_link_libraries(af_client PRIVATE ${GLU_LIBRARIES} m)
endif()
configure_file(include/af_config.h.in af_config.h)
install(
TARGETS af_server af_client
TARGETS af_server af_client af_dumpfont
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
FILES logo.png
FILES resource/logo.png resource/font.png
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/assaultfish
)

View file

@ -1,8 +1,41 @@
#include <af_common.h>
void gl_init(void){
double gl_cam_lr = 0;
double gl_cam_ud = 0;
double gl_cam_x;
double gl_cam_y;
double gl_cam_z;
int gl_scene = AF_SCENE_MAIN;
gl_scene_t gl_scenes[] = {
{gl_main_init, gl_main_draw}};
void gl_resize(int width, int height) {
glViewport(0, 0, width, height);
}
void gl_render(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
void gl_init(void) {
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void gl_render(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl_scenes[gl_scene].init();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (double)MwGetInteger(opengl, MwNwidth) / MwGetInteger(opengl, MwNheight), 0.01, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(gl_cam_x, gl_cam_y, gl_cam_z, gl_cam_x + cos(gl_cam_lr / 180.0 * M_PI), gl_cam_y + sin(gl_cam_ud / 180.0 * M_PI), gl_cam_z + sin(gl_cam_lr / 180.0 * M_PI), 0, 1, 0);
gl_scenes[gl_scene].draw();
}

35
client/gl_main.c Normal file
View file

@ -0,0 +1,35 @@
#include <af_common.h>
void gl_main_init(void) {
gl_cam_x = 0;
gl_cam_y = 0;
gl_cam_z = -1;
gl_cam_lr = 90;
gl_cam_ud = 0;
}
void gl_main_draw(void) {
int i;
static double r = 0;
glDisable(GL_DEPTH_TEST);
glPushMatrix();
glRotatef(r, 1, 0, 0);
glRotatef(r, 0, 1, 0);
glRotatef(r, 0, 0, 1);
glBegin(GL_TRIANGLES);
for(i = 0; i < 8; i++) {
double r = i * 90 / 180.0 * M_PI;
int c = ((i + (i / 4)) % 2) == 0 ? 1 : 0;
glColor4f(c ? 0.75 : 0, 0, c ? 0 : 0.75, 0.5);
glVertex3f(0, (i > 3 ? -1 : 1) * 0.5, 0);
glVertex3f(cos(r) / 2, 0, sin(r) / 2);
glVertex3f(cos(r + 90 / 180.0 * M_PI) / 2, 0, sin(r + 90 / 180.0 * M_PI) / 2);
}
glEnd();
glPopMatrix();
glEnable(GL_DEPTH_TEST);
r += 1;
}

View file

@ -2,11 +2,11 @@
MwWidget root, window, opengl;
static const MwRect sizes[] ={
{0, 0, 640, 480},
{0, 0, 800, 600},
{0, 0, 1024, 768},
{0, 0, 1280, 1024},
static const MwRect sizes[] = {
{0, 0, 640, 480},
{0, 0, 800, 600},
{0, 0, 1024, 768},
{0, 0, 1280, 1024},
};
static void resize(MwWidget handle, void* user, void* client) {
@ -18,7 +18,7 @@ static void resize(MwWidget handle, void* user, void* client) {
MwNheight, wh,
NULL);
glViewport(0, 0, ww, wh);
gl_resize(ww, wh);
}
static void tick(MwWidget handle, void* user, void* client) {
@ -31,10 +31,16 @@ static void* gl_load(const char* name) {
return MwOpenGLGetProcAddress(opengl, name);
}
void scene_change(int scene) {
gl_scene = scene;
ui_scene();
}
int main(int argc, char** argv) {
MwSizeHints sh;
MwRect rc;
int i;
MwRect rc;
int i;
MwLibraryInit();
@ -48,29 +54,29 @@ int main(int argc, char** argv) {
MwGetScreenSize(window, &rc);
for(i = sizeof(sizes) / sizeof(sizes[0]) - 1; i >= 0; i--){
if(sizes[i].width < rc.width && sizes[i].height < rc.height){
for(i = sizeof(sizes) / sizeof(sizes[0]) - 1; i >= 0; i--) {
if(sizes[i].width < rc.width && sizes[i].height < rc.height) {
sh.min_width = sh.max_width = sizes[i].width;
sh.min_height = sh.max_height = sizes[i].height;
break;
}
}
for(i = 1; i < argc; i++){
if(strcmp(argv[i], "--width") == 0 && (i + 1) < argc){
for(i = 1; i < argc; i++) {
if(strcmp(argv[i], "--width") == 0 && (i + 1) < argc) {
sh.min_width = sh.max_width = atoi(argv[i + 1]);
}else if(strcmp(argv[i], "--height") == 0 && (i + 1) < argc){
} else if(strcmp(argv[i], "--height") == 0 && (i + 1) < argc) {
sh.min_height = sh.max_height = atoi(argv[i + 1]);
}
}
MwVaApply(window,
MwNsizeHints, &sh,
MwNx, (rc.width - sh.max_width) / 2,
MwNy, (rc.height - sh.max_height) / 2,
MwNwidth, sh.max_width,
MwNheight, sh.max_height,
NULL);
MwNsizeHints, &sh,
MwNx, (rc.width - sh.max_width) / 2,
MwNy, (rc.height - sh.max_height) / 2,
MwNwidth, sh.max_width,
MwNheight, sh.max_height,
NULL);
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 0, 0, sh.max_width, sh.max_height);
@ -83,6 +89,8 @@ int main(int argc, char** argv) {
gl_init();
ui_init();
scene_change(AF_SCENE_MAIN);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
MwAddUserHandler(root, MwNtickHandler, tick, NULL);

View file

@ -1,78 +1,91 @@
#include <af_common.h>
MwWidget ui_notice(int width, int height){
if(width == 0 && height == 0){
width = 400;
MwWidget ui_notice(int width, int height) {
if(width == 0 && height == 0) {
width = 400;
height = 300;
}
return MwVaCreateWidget(MwFrameClass, "notice", window, (MwGetInteger(window, MwNwidth) - width) / 2, (MwGetInteger(window, MwNheight) - height) / 2, width, height,
MwNhasBorder, 1,
MwNinverted, 0,
NULL);
MwNhasBorder, 1,
MwNinverted, 0,
NULL);
}
void ui_notice_destroy(MwWidget widget){
void ui_notice_destroy(MwWidget widget) {
MwDestroyWidget(widget);
}
static void ui_login(void){
MwWidget wnd = ui_notice(0, 0);
int bw = MwDefaultBorderWidth(wnd);
MwWidget join = MwVaCreateWidget(MwButtonClass, "join", wnd, MwGetInteger(wnd, MwNwidth) - bw - 10 - 96, MwGetInteger(wnd, MwNheight) - bw - 10 - 24, 96, 24,
MwNtext, "Join",
NULL);
MwWidget box = MwVaCreateWidget(MwBoxClass, "box", wnd, bw, bw, MwGetInteger(wnd, MwNwidth) - bw * 2, MwGetInteger(wnd, MwNheight) - bw * 2 - 10 - 24,
MwNorientation, MwVERTICAL,
MwNmargin, 10,
MwNpadding, 10,
NULL);
MwWidget icon = MwVaCreateWidget(MwImageClass, "icon", box, 0, 0, 0, 0,
MwNfillArea, 0,
MwNfixedSize, 100,
NULL);
MwWidget entrybox[3];
MwLLPixmap px = MwLoadImage(wnd, DATAROOTDIR "/assaultfish/logo.png");
static void ui_login_join(MwWidget handle, void* user, void* client) {
MwLLDestroyPixmap(MwGetVoid(user, MwNpixmap));
ui_notice_destroy(user);
}
static void ui_login(void) {
MwWidget wnd = ui_notice(0, 0);
int bw = MwDefaultBorderWidth(wnd);
MwWidget join = MwVaCreateWidget(MwButtonClass, "join", wnd, MwGetInteger(wnd, MwNwidth) - bw - 10 - 96, MwGetInteger(wnd, MwNheight) - bw - 10 - 24, 96, 24,
MwNtext, "Join",
NULL);
MwWidget box = MwVaCreateWidget(MwBoxClass, "box", wnd, bw, bw, MwGetInteger(wnd, MwNwidth) - bw * 2, MwGetInteger(wnd, MwNheight) - bw * 2 - 10 - 24,
MwNorientation, MwVERTICAL,
MwNmargin, 10,
MwNpadding, 10,
NULL);
MwWidget icon = MwVaCreateWidget(MwImageClass, "icon", box, 0, 0, 0, 0,
MwNfillArea, 0,
MwNfixedSize, 100,
NULL);
MwWidget entrybox[3];
MwLLPixmap px = MwLoadImage(wnd, DATAROOTDIR "/assaultfish/logo.png");
const char* labels[3] = {
"Username",
"Hostname",
"Port"
};
"Username",
"Hostname",
"Port"};
const char* entries[3] = {
"JohnDoe",
"127.0.0.1",
"",
"JohnDoe",
"127.0.0.1",
"",
};
int i;
int i;
char buf[16];
sprintf(buf, "%d", AF_DEFAULT_PORT);
entries[2] = buf;
for(i = 0; i < 3; i++){
for(i = 0; i < 3; i++) {
entrybox[i] = MwVaCreateWidget(MwBoxClass, "entrybox", box, 0, 0, 0, 0,
MwNfixedSize, 24,
MwNmargin, 10,
NULL);
MwVaCreateWidget(MwLabelClass, "label", entrybox[i], 0, 0, 0, 0,
MwNfixedSize, 100,
MwNtext, labels[i],
MwNalignment, MwALIGNMENT_END,
NULL);
MwNfixedSize, 24,
MwNmargin, 10,
NULL);
MwVaCreateWidget(MwLabelClass, "label", entrybox[i], 0, 0, 0, 0,
MwNfixedSize, 100,
MwNtext, labels[i],
MwNalignment, MwALIGNMENT_END,
NULL);
MwVaCreateWidget(MwEntryClass, "entry", entrybox[i], 0, 0, 0, 0,
MwNtext, entries[i],
NULL);
MwNtext, entries[i],
NULL);
}
MwVaApply(icon,
MwNpixmap, px,
NULL);
MwNpixmap, px,
NULL);
MwVaApply(wnd,
MwNpixmap, px,
NULL);
MwAddUserHandler(join, MwNactivateHandler, ui_login_join, wnd);
}
void ui_init(void){
void ui_scene(void) {
if(gl_scene == AF_SCENE_MAIN) {
ui_login();
}
}
void ui_init(void) {
MwToggleDarkTheme(root, 1);
ui_login();
}

2
external/stb/stb_ds.c vendored Normal file
View file

@ -0,0 +1,2 @@
#define STB_DS_IMPLEMENTATION
#include <stb_ds.h>

1895
external/stb/stb_ds.h vendored Normal file

File diff suppressed because it is too large Load diff

2
external/stb/stb_image.c vendored Normal file
View file

@ -0,0 +1,2 @@
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>

7988
external/stb/stb_image.h vendored Normal file

File diff suppressed because it is too large Load diff

2
external/stb/stb_image_write.c vendored Normal file
View file

@ -0,0 +1,2 @@
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>

1724
external/stb/stb_image_write.h vendored Normal file

File diff suppressed because it is too large Load diff

5132
fonts/8x16.bdf Normal file

File diff suppressed because it is too large Load diff

BIN
fonts/font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View file

@ -1,2 +1,2 @@
#!/bin/sh
clang-format --verbose -i `find include server client -name "*.c" -or -name "*.h"`
clang-format --verbose -i `find include server client tools -name "*.c" -or -name "*.h"`

View file

@ -5,16 +5,43 @@
#include <Mw/Milsko.h>
#include <Mw/Widget/OpenGL.h>
#include <GL/glu.h>
enum AF_SCENES {
AF_SCENE_MAIN = 0
};
/* main.c */
extern MwWidget root, window, opengl;
void scene_change(int scene);
/* gl.c */
typedef struct gl_scene {
void (*init)(void);
void (*draw)(void);
} gl_scene_t;
extern int gl_scene;
extern gl_scene_t gl_scenes[];
extern double gl_cam_lr;
extern double gl_cam_ud;
extern double gl_cam_x;
extern double gl_cam_y;
extern double gl_cam_z;
void gl_init(void);
void gl_render(void);
void gl_resize(int width, int height);
/* gl_main.c */
void gl_main_init(void);
void gl_main_draw(void);
/* ui.c */
MwWidget ui_notice(int width, int height);
void ui_notice_destroy(MwWidget widget);
void ui_init(void);
void ui_notice_destroy(MwWidget widget);
void ui_init(void);
void ui_scene(void);
#endif

View file

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Before After
Before After

72
tools/af_dumpfont.c Normal file
View file

@ -0,0 +1,72 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stb_image_write.h>
#define CHECK(s) ((linelen > strlen(s)) && memcmp(line, s, strlen(s)) == 0)
int main() {
char* line = NULL;
size_t linesize;
ssize_t linelen;
int iw, ih;
unsigned char* font = NULL;
int c;
int p = 0;
int y = 0;
int w, h;
while((linelen = getline(&line, &linesize, stdin)) != -1) {
linelen--;
line[linelen] = 0;
if(CHECK("FONTBOUNDINGBOX ")) {
sscanf(line, "FONTBOUNDINGBOX %d %d", &w, &h);
printf("%dx%d font\n", w, h);
if(font != NULL) free(font);
iw = w * 16;
ih = h * 16;
font = malloc(iw * ih * 4);
memset(font, 0, iw * ih * 4);
} else if(CHECK("ENCODING ")) {
sscanf(line, "ENCODING %d", &c);
} else if(strcmp(line, "BITMAP") == 0) {
p = 1;
y = 0;
} else if(strcmp(line, "ENDCHAR") == 0) {
p = 0;
} else if(p && y < h) {
int bx = c % 16;
int by = c / 16;
int i;
int n = 0;
for(i = 0; i < w; i++) {
if((i % 4) == 0) {
char buf[2];
buf[0] = line[i / 4];
buf[1] = 0;
n = strtol(buf, NULL, 16);
}
if(n & (1 << 3)) {
unsigned char* px = &font[((by * h + y) * iw + bx * w + i) * 4];
memset(px, 255, 4);
}
n = n << 1;
}
y++;
}
}
if(font != NULL) stbi_write_png("font.png", iw, ih, 4, font, 0);
return 0;
}