diff --git a/docs/interop.txt b/docs/interop.txt index f539d64..fd6101f 100644 --- a/docs/interop.txt +++ b/docs/interop.txt @@ -4,7 +4,7 @@ for that certain steps are taken: * number of public api calls is kept at the minimum * procedure signatures can only use basic types, no aggregates, with exception of Vec/Matrix types and alike, with no expectation on new additions (see /include/twn_types.h) -* optionals can be expressed via pointer passage of value primitives, with NULL expressive default +* optionals can be expressed via pointer passage of value primitives, with NULL expressive default, but they should be immutable * /include/twn_game_api.json file is hand-kept with a schema to aid automatic generation and other tooling one of main inspirations for that is opengl model diff --git a/include/twn_audio.h b/include/twn_audio.h index 70a4b6c..28a6638 100644 --- a/include/twn_audio.h +++ b/include/twn_audio.h @@ -15,13 +15,8 @@ TWN_API void audio_play(const char *path, float volume, /* default: 1.0f, range: 0.0f to 1.0f */ float panning); /* default: 0.0f, range: -1.0 to 1.0f */ -typedef enum { - AUDIO_PARAM_REPEAT, - AUDIO_PARAM_VOLUME, - AUDIO_PARAM_PANNING, -} AudioParam; - -TWN_API void audio_set(const char *channel, AudioParam param, float value); +/* possible parameter options: "volume", "panning", "repeat" */ +TWN_API void audio_set_parameter(const char *channel, const char *parameter, float value); /* TODO */ // TWN_API bool audio_ended(const char *channel); diff --git a/include/twn_draw.h b/include/twn_draw.h index 59850b3..161dfdb 100644 --- a/include/twn_draw.h +++ b/include/twn_draw.h @@ -37,12 +37,12 @@ TWN_API int draw_text_width(char const *string, int height_px, /* TODO: make optional */ char const *font); -TWN_API void draw_9slice(char const *texture_path, - int texture_w, - int texture_h, - int border_thickness, - Rect rect, - Color color); /* TODO: make optional */ +TWN_API void draw_nine_slice(char const *texture_path, + int texture_w, + int texture_h, + int border_thickness, + Rect rect, + Color color); /* TODO: make optional */ /* pushes a textured 3d triangle onto the render queue */ /* vertices are in absolute coordinates, relative to world origin */ diff --git a/include/twn_engine_api.h b/include/twn_engine_api.h index 72db8b0..7f4c0ce 100644 --- a/include/twn_engine_api.h +++ b/include/twn_engine_api.h @@ -1,7 +1,9 @@ #ifndef TWN_ENGINE_API_H #define TWN_ENGINE_API_H -#if defined(__WIN32) +#if defined(TWN_NOT_C) + #define TWN_API +#elif defined(__WIN32) #define TWN_API __declspec(dllexport) #else #define TWN_API __attribute__((visibility("default"))) diff --git a/src/rendering/twn_draw.c b/src/rendering/twn_draw.c index 38e98b5..80489ec 100644 --- a/src/rendering/twn_draw.c +++ b/src/rendering/twn_draw.c @@ -35,7 +35,7 @@ void render_queue_clear(void) { } -void draw_9slice(const char *texture_path, int texture_w, int texture_h, int border_thickness, Rect rect, Color color) { +void draw_nine_slice(const char *texture_path, int texture_w, int texture_h, int border_thickness, Rect rect, Color color) { const float bt = (float)border_thickness; /* i know! */ const float bt2 = bt * 2; /* combined size of the two borders in an axis */ diff --git a/src/twn_audio.c b/src/twn_audio.c index 9a78ddf..4900346 100644 --- a/src/twn_audio.c +++ b/src/twn_audio.c @@ -191,42 +191,32 @@ void audio_play(const char *path, } -TWN_API void audio_set(const char *channel, AudioParam param, float value) { +TWN_API void audio_set_parameter(const char *channel, const char *param, float value) { AudioChannelItem *pair = shgetp_null(ctx.audio_channels, channel); if (!pair) { log_warn("No channel by the name of %s to set a parameter for", channel); return; } - switch (param) { - case AUDIO_PARAM_REPEAT: + if (SDL_strcmp(param, "repeat") == 0) { pair->value.repeat = (bool)value; - break; - case AUDIO_PARAM_VOLUME: - if (value > 1.0f) { + + } else if (SDL_strcmp(param, "volume") == 0) { + if (value > 1.0f || value < 0.0f) { log_warn("Out of range volume for channel %s set", channel); - value = 1.0f; - } - if (value < 0.0f) { - log_warn("Out of range volume for channel %s set", channel); - value = 0.0f; + value = clampf(value, 0.0f, 1.0f); } pair->value.volume = value; - break; - case AUDIO_PARAM_PANNING: - if (value > 1.0f) { + + } else if (SDL_strcmp(param, "panning") == 0) { + if (value > 1.0f || value < -1.0f) { log_warn("Out of range panning for channel %s set", channel); - value = 1.0f; - } - if (value < -1.0f) { - log_warn("Out of range panning for channel %s set", channel); - value = -1.0f; + value = clampf(value, -1.0f, +1.0f); } pair->value.panning = value; - break; - default: + + } else CRY("Audio channel parameter setting failed", "Invalid parameter enum given"); - } }