From d9d8a201e8696be6aefb820052305e655b97aa62 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sun, 16 Aug 2020 18:21:34 -0700 Subject: [PATCH] Implement miscellaneous HLL functions Reduce console spam by implementing some commonly used functions. DrawGraph.SetFontName SACT2.Mouse_SetPos SACT2.Sound_ReverseLR --- include/audio.h | 2 +- include/gfx/gfx.h | 1 + include/input.h | 1 + src/audio.c | 20 +++++++++++++++++++- src/hll/DrawGraph.c | 6 +++++- src/hll/SACT2.c | 18 ++++++++++++++---- src/input.c | 5 +++++ src/text.c | 15 +++++++++++++++ 8 files changed, 61 insertions(+), 7 deletions(-) diff --git a/include/audio.h b/include/audio.h index 5de674e..5e92738 100644 --- a/include/audio.h +++ b/include/audio.h @@ -66,7 +66,7 @@ int bgm_fade(int ch, int time, int volume, bool stop); //int bgm_seek(int channel, int pos); int wav_get_unused_channel(void); int bgm_get_unused_channel(void); -//int wav_reverse_LR(int channel); +int wav_reverse_LR(int ch); //int bgm_reverse_LR(int channel); //int wav_get_volume(int channel); //int bgm_get_volume(int channel); diff --git a/include/gfx/gfx.h b/include/gfx/gfx.h index fe0e1a3..a7de5e7 100644 --- a/include/gfx/gfx.h +++ b/include/gfx/gfx.h @@ -171,6 +171,7 @@ bool gfx_get_font_underline(void); bool gfx_get_font_strikeout(void); int gfx_get_font_space(void); SDL_Color gfx_get_font_color(void); +void gfx_set_font_name(const char *name); int gfx_render_text(Texture *dst, Point pos, char *msg, struct text_metrics *tm, int char_space); void gfx_draw_text_to_amap(Texture *dst, int x, int y, char *text); diff --git a/include/input.h b/include/input.h index 0e11e6e..7fb76eb 100644 --- a/include/input.h +++ b/include/input.h @@ -141,6 +141,7 @@ void handle_events(void); bool key_is_down(enum sact_keycode code); void key_clear_flag(void); void mouse_get_pos(int *x, int *y); +void mouse_set_pos(int x, int y); void mouse_get_wheel(int *forward, int *back); void mouse_clear_wheel(void); void register_input_handler(void(*handler)(const char*)); diff --git a/src/audio.c b/src/audio.c index d8340a9..ef3e668 100644 --- a/src/audio.c +++ b/src/audio.c @@ -28,6 +28,7 @@ struct wav_slot { Mix_Chunk *chunk; int channel; int no; + bool reverse; }; struct bgm_slot { @@ -135,6 +136,7 @@ static void wav_realloc(int new_size) for (int i = wav.nr_slots; i < new_size; i++) { wav.slots[i].chunk = NULL; wav.slots[i].channel = -1; + wav.slots[i].reverse = false; } wav.nr_slots = new_size; } @@ -323,7 +325,11 @@ int wav_play(int ch) return 1; } slot->channel = Mix_PlayChannel(-1, slot->chunk, 0); - return slot->channel >= 0; + if (slot->channel < 0) + return 0; + + Mix_SetReverseStereo(slot->channel, slot->reverse); + return 1; } int bgm_play(int ch) @@ -384,6 +390,18 @@ int bgm_fade(int ch, possibly_unused int time, possibly_unused int volume, bool return 1; } +int wav_reverse_LR(int ch) +{ + struct wav_slot *slot = wav_get_slot(ch); + if (!slot) + return 0; + slot->reverse = true; + if (slot->channel >= 0) { + Mix_SetReverseStereo(slot->channel, 1); + } + return 1; +} + int wav_get_time_length(int ch) { struct wav_slot *slot = wav_get_slot(ch); diff --git a/src/hll/DrawGraph.c b/src/hll/DrawGraph.c index c97034d..012752a 100644 --- a/src/hll/DrawGraph.c +++ b/src/hll/DrawGraph.c @@ -155,6 +155,11 @@ bool DrawGraph_GetAlphaColor(int surface, int x, int y, int *a) return true; } +void DrawGraph_SetFontName(struct string *text) +{ + gfx_set_font_name(text->text); +} + HLL_UNIMPLEMENTED(void, DrawGraph, CopyColorReverse, int dst, int dx, int dy, int src, int sx, int sy, int w, int h); HLL_UNIMPLEMENTED(void, DrawGraph, Blend, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha); HLL_UNIMPLEMENTED(void, DrawGraph, BlendSrcBright, int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate); @@ -185,7 +190,6 @@ HLL_UNIMPLEMENTED(void, DrawGraph, CopyStretchBlend, int dst, int dx, int dy, in HLL_UNIMPLEMENTED(void, DrawGraph, CopyStretchBlendAMap, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh); HLL_UNIMPLEMENTED(void, DrawGraph, CopyStretchInterp, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh); HLL_UNIMPLEMENTED(void, DrawGraph, CopyStretchAMapInterp, int dst, int dx, int dy, int dw, int dh, int src, int sx, int sy, int sw, int sh); -HLL_WARN_UNIMPLEMENTED( , void, DrawGraph, SetFontName, struct string *text); HLL_WARN_UNIMPLEMENTED(&EMPTY_STRING, struct string*, DrawGraph, GetFontName, void); HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotZoom2Bilinear, int dst, float cx, float cy, int src, float scx, float scy, float rot, float mag); HLL_UNIMPLEMENTED(void, DrawGraph, CopyRotateY, int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag); diff --git a/src/hll/SACT2.c b/src/hll/SACT2.c index fa2d932..21b11a7 100644 --- a/src/hll/SACT2.c +++ b/src/hll/SACT2.c @@ -63,6 +63,13 @@ int sact_Mouse_GetPos(int *x, int *y) return mouse_focus && keyboard_focus; } +int sact_Mouse_SetPos(int x, int y) +{ + handle_events(); + mouse_set_pos(x, y); + return mouse_focus && keyboard_focus; +} + void sact_Mouse_ClearWheel(void) { mouse_clear_wheel(); @@ -193,6 +200,11 @@ int sact_Sound_Fade(int ch, int time, int volume, int stop) return wav_fade(ch, time, volume, stop); } +int sact_Sound_ReverseLR(int ch) +{ + return wav_reverse_LR(ch); +} + int sact_Sound_GetTimeLength(int ch) { return wav_get_time_length(ch); @@ -241,7 +253,6 @@ HLL_UNIMPLEMENTED(int, SACT2, SP_CreateCustom, int sp); HLL_UNIMPLEMENTED(int, SACT2, SP_TextBackSpace, int sp_no); HLL_UNIMPLEMENTED(void, SACT2, GAME_MSG_Get, int index, struct string **text); HLL_UNIMPLEMENTED(int, SACT2, StringPopFront, struct string **dst, struct string **src); -HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Mouse_SetPos, int x, int y); HLL_UNIMPLEMENTED(int, SACT2, Joypad_GetNumof, void); HLL_WARN_UNIMPLEMENTED( , void, SACT2, JoypadQuake_Set, int num, int type, int magnitude); HLL_UNIMPLEMENTED(int, SACT2, CSV_Load, struct string *filename); @@ -274,7 +285,6 @@ HLL_UNIMPLEMENTED(int, SACT2, Sound_StopFade, int ch); HLL_UNIMPLEMENTED(int, SACT2, Sound_IsFade, int ch); HLL_UNIMPLEMENTED(int, SACT2, Sound_GetPos, int ch); HLL_UNIMPLEMENTED(int, SACT2, Sound_GetLength, int ch); -HLL_WARN_UNIMPLEMENTED(1, int, SACT2, Sound_ReverseLR, int ch); HLL_UNIMPLEMENTED(int, SACT2, Sound_GetVolume, int ch); HLL_UNIMPLEMENTED(int, SACT2, Sound_GetGroupNum, int ch); HLL_UNIMPLEMENTED(bool, SACT2, Sound_PrepareFromFile, int ch, struct string *filename); @@ -353,7 +363,7 @@ HLL_LIBRARY(SACT2, HLL_EXPORT(IntToHankaku, sact_IntToHankaku), HLL_EXPORT(StringPopFront, SACT2_StringPopFront), HLL_EXPORT(Mouse_GetPos, sact_Mouse_GetPos), - HLL_EXPORT(Mouse_SetPos, SACT2_Mouse_SetPos), + HLL_EXPORT(Mouse_SetPos, sact_Mouse_SetPos), HLL_EXPORT(Mouse_ClearWheel, sact_Mouse_ClearWheel), HLL_EXPORT(Mouse_GetWheel, sact_Mouse_GetWheel), HLL_EXPORT(Joypad_ClearKeyDownFlag, sact_Joypad_ClearKeyDownFlag), @@ -412,7 +422,7 @@ HLL_LIBRARY(SACT2, HLL_EXPORT(Sound_IsFade, SACT2_Sound_IsFade), HLL_EXPORT(Sound_GetPos, SACT2_Sound_GetPos), HLL_EXPORT(Sound_GetLength, SACT2_Sound_GetLength), - HLL_EXPORT(Sound_ReverseLR, SACT2_Sound_ReverseLR), + HLL_EXPORT(Sound_ReverseLR, sact_Sound_ReverseLR), HLL_EXPORT(Sound_GetVolume, SACT2_Sound_GetVolume), HLL_EXPORT(Sound_GetTimeLength, sact_Sound_GetTimeLength), HLL_EXPORT(Sound_GetGroupNum, SACT2_Sound_GetGroupNum), diff --git a/src/input.c b/src/input.c index 080ba5b..f690e8f 100644 --- a/src/input.c +++ b/src/input.c @@ -54,6 +54,11 @@ void mouse_get_pos(int *x, int *y) SDL_GetMouseState(x, y); } +void mouse_set_pos(int x, int y) +{ + SDL_WarpMouseInWindow(sdl.window, x, y); +} + static int wheel_dir = 0; void mouse_get_wheel(int *forward, int *back) diff --git a/src/text.c b/src/text.c index 728b6df..502fbd1 100644 --- a/src/text.c +++ b/src/text.c @@ -203,6 +203,21 @@ SDL_Color gfx_get_font_color(void) return font_metrics.color; } +void gfx_set_font_name(const char *name) +{ + static const char mincho_name[] = { 0x82, 0x6c, 0x82, 0x72, 0x20, 0x96, 0xbe, 0x92, 0xa9, 0 }; + static const char gothic_name[] = { 0x82, 0x6c, 0x82, 0x72, 0x20, 0x83, 0x53, 0x83, 0x56, 0x83, 0x62, 0x83, 0x4e, 0 }; + if (!strcmp(name, mincho_name)) { + font_metrics.face = FONT_MINCHO; + } else if (!strcmp(name, gothic_name)) { + font_metrics.face = FONT_GOTHIC; + } else { + char *u = sjis2utf(name, 0); + WARNING("Unhandled font name: \"%s\"", u); + free(u); + } +} + static void get_glyph(TTF_Font *f, Texture *dst, char *msg, SDL_Color color) { SDL_Surface *s = TTF_RenderUTF8_Blended(f, msg, color);