audio_set() -> audio_set_parameter(), with string based convention
This commit is contained in:
parent
5a08c01208
commit
b390e9db23
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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")))
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user