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
|
* 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,
|
* 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)
|
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
|
* /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
|
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 volume, /* default: 1.0f, range: 0.0f to 1.0f */
|
||||||
float panning); /* default: 0.0f, range: -1.0 to 1.0f */
|
float panning); /* default: 0.0f, range: -1.0 to 1.0f */
|
||||||
|
|
||||||
typedef enum {
|
/* possible parameter options: "volume", "panning", "repeat" */
|
||||||
AUDIO_PARAM_REPEAT,
|
TWN_API void audio_set_parameter(const char *channel, const char *parameter, float value);
|
||||||
AUDIO_PARAM_VOLUME,
|
|
||||||
AUDIO_PARAM_PANNING,
|
|
||||||
} AudioParam;
|
|
||||||
|
|
||||||
TWN_API void audio_set(const char *channel, AudioParam param, float value);
|
|
||||||
|
|
||||||
/* TODO */
|
/* TODO */
|
||||||
// TWN_API bool audio_ended(const char *channel);
|
// TWN_API bool audio_ended(const char *channel);
|
||||||
|
@ -37,7 +37,7 @@ TWN_API int draw_text_width(char const *string,
|
|||||||
int height_px, /* TODO: make optional */
|
int height_px, /* TODO: make optional */
|
||||||
char const *font);
|
char const *font);
|
||||||
|
|
||||||
TWN_API void draw_9slice(char const *texture_path,
|
TWN_API void draw_nine_slice(char const *texture_path,
|
||||||
int texture_w,
|
int texture_w,
|
||||||
int texture_h,
|
int texture_h,
|
||||||
int border_thickness,
|
int border_thickness,
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#ifndef TWN_ENGINE_API_H
|
#ifndef TWN_ENGINE_API_H
|
||||||
#define 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)
|
#define TWN_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define TWN_API __attribute__((visibility("default")))
|
#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 bt = (float)border_thickness; /* i know! */
|
||||||
const float bt2 = bt * 2; /* combined size of the two borders in an axis */
|
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);
|
AudioChannelItem *pair = shgetp_null(ctx.audio_channels, channel);
|
||||||
if (!pair) {
|
if (!pair) {
|
||||||
log_warn("No channel by the name of %s to set a parameter for", channel);
|
log_warn("No channel by the name of %s to set a parameter for", channel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (param) {
|
if (SDL_strcmp(param, "repeat") == 0) {
|
||||||
case AUDIO_PARAM_REPEAT:
|
|
||||||
pair->value.repeat = (bool)value;
|
pair->value.repeat = (bool)value;
|
||||||
break;
|
|
||||||
case AUDIO_PARAM_VOLUME:
|
} else if (SDL_strcmp(param, "volume") == 0) {
|
||||||
if (value > 1.0f) {
|
if (value > 1.0f || value < 0.0f) {
|
||||||
log_warn("Out of range volume for channel %s set", channel);
|
log_warn("Out of range volume for channel %s set", channel);
|
||||||
value = 1.0f;
|
value = clampf(value, 0.0f, 1.0f);
|
||||||
}
|
|
||||||
if (value < 0.0f) {
|
|
||||||
log_warn("Out of range volume for channel %s set", channel);
|
|
||||||
value = 0.0f;
|
|
||||||
}
|
}
|
||||||
pair->value.volume = value;
|
pair->value.volume = value;
|
||||||
break;
|
|
||||||
case AUDIO_PARAM_PANNING:
|
} else if (SDL_strcmp(param, "panning") == 0) {
|
||||||
if (value > 1.0f) {
|
if (value > 1.0f || value < -1.0f) {
|
||||||
log_warn("Out of range panning for channel %s set", channel);
|
log_warn("Out of range panning for channel %s set", channel);
|
||||||
value = 1.0f;
|
value = clampf(value, -1.0f, +1.0f);
|
||||||
}
|
|
||||||
if (value < -1.0f) {
|
|
||||||
log_warn("Out of range panning for channel %s set", channel);
|
|
||||||
value = -1.0f;
|
|
||||||
}
|
}
|
||||||
pair->value.panning = value;
|
pair->value.panning = value;
|
||||||
break;
|
|
||||||
default:
|
} else
|
||||||
CRY("Audio channel parameter setting failed", "Invalid parameter enum given");
|
CRY("Audio channel parameter setting failed", "Invalid parameter enum given");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user