Music and sound
This commit is contained in:
parent
b8f67a8f9e
commit
2731d01bc1
|
@ -481,19 +481,6 @@ static cpBool script_phys_cb_begin(cpArbiter *arb, cpSpace *space, void *data) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static cpBool s7_phys_cb_presolve(cpArbiter *arb, cpSpace *space, void *data) {
|
||||
|
||||
}
|
||||
|
||||
static void s7_phys_cb_postsolve(cpArbiter *arb, cpSpace *space, void *data) {
|
||||
|
||||
}
|
||||
|
||||
static void s7_phys_cb_separate(cpArbiter *Arb, cpSpace *space, void *data) {
|
||||
//struct gameobject *go = data;
|
||||
//script_call_sym(go->cbs->separate);
|
||||
}
|
||||
|
||||
void phys2d_add_handler_type(int cmd, int go, struct callee c) {
|
||||
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ static int grid1_draw = true;
|
|||
static int grid2_draw = true;
|
||||
|
||||
static float tex_scale = 1.f;
|
||||
static struct TexAnimation tex_gui_anim = {0};
|
||||
static struct anim2d tex_gui_anim = {0};
|
||||
|
||||
char current_level[MAXNAME] = {'\0'};
|
||||
char levelname[MAXNAME] = {'\0'};
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "anim.h"
|
||||
#include "yugine.h"
|
||||
#include "nuke.h"
|
||||
#include "sound.h"
|
||||
#include "font.h"
|
||||
|
||||
cpVect duk2vec2(duk_context *duk, int p) {
|
||||
|
@ -118,6 +119,22 @@ duk_ret_t duk_cmd(duk_context *duk) {
|
|||
play_song(duk_to_string(duk, 1), duk_to_string(duk, 2));
|
||||
break;
|
||||
|
||||
case 14:
|
||||
play_sound(make_sound(duk_to_string(duk, 1)));
|
||||
break;
|
||||
|
||||
case 15:
|
||||
|
||||
break;
|
||||
|
||||
case 16:
|
||||
|
||||
break;
|
||||
|
||||
case 17:
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -347,7 +364,10 @@ duk_ret_t duk_make_sprite(duk_context *duk) {
|
|||
duk_ret_t duk_make_anim2d(duk_context *duk) {
|
||||
int go = duk_to_int(duk, 0);
|
||||
const char *path = duk_to_string(duk, 1);
|
||||
cpVect pos = duk2vec2(duk, 2);
|
||||
int frames = duk_to_int(duk, 2);
|
||||
int fps = duk_to_int(duk, 3);
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -437,7 +457,7 @@ void ffi_load()
|
|||
DUK_FUNC(win_make, 3);
|
||||
|
||||
DUK_FUNC(make_sprite, 3);
|
||||
DUK_FUNC(make_anim2d, 3);
|
||||
DUK_FUNC(make_anim2d, 4);
|
||||
DUK_FUNC(make_box2d, 3);
|
||||
DUK_FUNC(make_circle2d, 3);
|
||||
DUK_FUNC(cmd, DUK_VARARGS);
|
||||
|
|
|
@ -22,7 +22,7 @@ static uint32_t VAO = 0;
|
|||
struct sFont *font;
|
||||
static struct shader *shader;
|
||||
|
||||
char *slurp_file(const char *filename) {
|
||||
unsigned char *slurp_file(const char *filename) {
|
||||
FILE *f = fopen(filename, "rb");
|
||||
|
||||
if (!f) return NULL;
|
||||
|
@ -31,13 +31,12 @@ char *slurp_file(const char *filename) {
|
|||
long fsize = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
unsigned char *slurp = malloc(fsize);
|
||||
size_t r = fread(slurp, fsize, 1, f);
|
||||
fclose(f);
|
||||
|
||||
return slurp;
|
||||
}
|
||||
|
||||
char *slurp_text(const char *filename) {
|
||||
unsigned char *slurp_text(const char *filename) {
|
||||
FILE *f = fopen(filename, "r'");
|
||||
if (!f) return NULL;
|
||||
|
||||
|
@ -117,9 +116,6 @@ struct sFont *MakeFont(const char *fontfile, int height)
|
|||
YughError("Failed to make font %s", fontfile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float scale = stbtt_ScaleForPixelHeight(&fontinfo, height);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glGenTextures(1, &newfont->texID);
|
||||
glBindTexture(GL_TEXTURE_2D, newfont->texID);
|
||||
|
|
|
@ -31,7 +31,7 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
|
|||
void text_settype(struct sFont *font);
|
||||
void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3], float lw);
|
||||
|
||||
char *slurp_file(const char *filename);
|
||||
char *slurp_text(const char *filename);
|
||||
unsigned char *slurp_file(const char *filename);
|
||||
unsigned char *slurp_text(const char *filename);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -118,7 +118,6 @@ void print_devices()
|
|||
|
||||
void sound_init()
|
||||
{
|
||||
|
||||
PaError err = Pa_Initialize();
|
||||
check_pa_err(err);
|
||||
|
||||
|
@ -151,18 +150,20 @@ void audio_close()
|
|||
//Mix_CloseAudio();
|
||||
}
|
||||
|
||||
struct wav make_sound(const char *wav)
|
||||
static struct wav mwav;
|
||||
|
||||
struct wav *make_sound(const char *wav)
|
||||
{
|
||||
struct wav mwav;
|
||||
mwav.data = drwav_open_file_and_read_pcm_frames_s16("sounds/alert.wav", &mwav.ch, &mwav.samplerate, &mwav.frames, NULL);
|
||||
mwav.data = drwav_open_file_and_read_pcm_frames_s16(wav, &mwav.ch, &mwav.samplerate, &mwav.frames, NULL);
|
||||
|
||||
if (mwav.samplerate != SAMPLERATE) {
|
||||
YughInfo("Changing samplerate of %s.", wav);
|
||||
mwav = change_samplerate(mwav, 48000);
|
||||
}
|
||||
|
||||
mwav.gain = 1.f;
|
||||
|
||||
return mwav;
|
||||
return &mwav;
|
||||
}
|
||||
|
||||
struct soundstream *soundstream_make()
|
||||
|
|
|
@ -61,7 +61,7 @@ void audio_close();
|
|||
|
||||
void sound_fillbuf(struct sound *s, short *buf, int n);
|
||||
|
||||
struct wav make_sound(const char *wav);
|
||||
struct wav *make_sound(const char *wav);
|
||||
void wav_norm_gain(struct wav *w, double lv);
|
||||
struct sound *play_sound(struct wav *wav);
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
struct datastream;
|
||||
struct gameobject;
|
||||
struct Texture;
|
||||
|
||||
struct sprite {
|
||||
mfloat_t pos[2];
|
||||
|
@ -17,11 +16,12 @@ struct sprite {
|
|||
mfloat_t color[3];
|
||||
int go;
|
||||
int id;
|
||||
struct TexAnimation anim;
|
||||
struct anim2d anim;
|
||||
struct Texture *tex;
|
||||
int next;
|
||||
};
|
||||
|
||||
|
||||
int make_sprite(int go);
|
||||
struct sprite *id2sprite(int id);
|
||||
void sprite_delete(int id);
|
||||
|
|
|
@ -134,38 +134,38 @@ void tex_gpu_reload(struct Texture *tex)
|
|||
//tex_gpu_load(tex);
|
||||
}
|
||||
|
||||
void tex_incr_anim(struct TexAnimation *tex_anim)
|
||||
void tex_incr_anim(struct anim2d *tex_anim)
|
||||
{
|
||||
anim_incr(tex_anim);
|
||||
|
||||
if (!tex_anim->loop && tex_anim->frame == arrlen(tex_anim->anim->st_frames))
|
||||
if (!tex_anim->anim->loop && tex_anim->frame == arrlen(tex_anim->anim->st_frames))
|
||||
anim_pause(tex_anim);
|
||||
}
|
||||
|
||||
void anim_incr(struct TexAnimation *anim)
|
||||
void anim_incr(struct anim2d *anim)
|
||||
{
|
||||
anim->frame = (anim->frame + 1) % arrlen(anim->anim->st_frames);
|
||||
//tex_anim_calc_uv(anim);
|
||||
}
|
||||
|
||||
void anim_decr(struct TexAnimation *anim)
|
||||
void anim_decr(struct anim2d *anim)
|
||||
{
|
||||
anim->frame = (anim->frame + arrlen(anim->anim->st_frames) - 1) % arrlen(anim->anim->st_frames);
|
||||
//tex_anim_calc_uv(anim);
|
||||
}
|
||||
|
||||
struct glrect anim_get_rect(struct TexAnimation *anim)
|
||||
struct glrect anim_get_rect(struct anim2d *anim)
|
||||
{
|
||||
return anim->anim->st_frames[anim->frame];
|
||||
}
|
||||
|
||||
void anim_setframe(struct TexAnimation *anim, int frame)
|
||||
void anim_setframe(struct anim2d *anim, int frame)
|
||||
{
|
||||
anim->frame = frame;
|
||||
//tex_anim_calc_uv(anim);
|
||||
}
|
||||
|
||||
void tex_anim_set(struct TexAnimation *anim)
|
||||
void tex_anim_set(struct anim2d *anim)
|
||||
{
|
||||
if (anim->playing) {
|
||||
timer_remove(anim->timer);
|
||||
|
@ -203,7 +203,7 @@ void tex_bind(struct Texture *tex)
|
|||
glBindTexture(GL_TEXTURE_2D_ARRAY, tex->id);
|
||||
}
|
||||
|
||||
void anim_play(struct TexAnimation *anim)
|
||||
void anim_play(struct anim2d *anim)
|
||||
{
|
||||
if (anim->playing)
|
||||
return;
|
||||
|
@ -221,7 +221,7 @@ void anim_play(struct TexAnimation *anim)
|
|||
timer_start(anim->timer);
|
||||
}
|
||||
|
||||
void anim_stop(struct TexAnimation *anim)
|
||||
void anim_stop(struct anim2d *anim)
|
||||
{
|
||||
if (!anim->playing)
|
||||
return;
|
||||
|
@ -233,7 +233,7 @@ void anim_stop(struct TexAnimation *anim)
|
|||
//tex_anim_calc_uv(anim);
|
||||
}
|
||||
|
||||
void anim_pause(struct TexAnimation *anim)
|
||||
void anim_pause(struct anim2d *anim)
|
||||
{
|
||||
if (!anim->playing)
|
||||
return;
|
||||
|
@ -242,12 +242,12 @@ void anim_pause(struct TexAnimation *anim)
|
|||
timer_pause(anim->timer);
|
||||
}
|
||||
|
||||
void anim_fwd(struct TexAnimation *anim)
|
||||
void anim_fwd(struct anim2d *anim)
|
||||
{
|
||||
anim_incr(anim);
|
||||
}
|
||||
|
||||
void anim_bkwd(struct TexAnimation *anim)
|
||||
void anim_bkwd(struct anim2d *anim)
|
||||
{
|
||||
anim_decr(anim);
|
||||
}
|
||||
|
|
|
@ -30,13 +30,13 @@ struct uvrect {
|
|||
};
|
||||
|
||||
/* Tracks a playing animation */
|
||||
struct TexAnimation {
|
||||
struct anim2d {
|
||||
int frame;
|
||||
int playing;
|
||||
int pausetime;
|
||||
struct timer *timer;
|
||||
struct TexAnim *anim;
|
||||
int loop;
|
||||
|
||||
};
|
||||
|
||||
/* Describes an animation on a particular texture */
|
||||
|
@ -44,6 +44,7 @@ struct TexAnim {
|
|||
struct glrect *st_frames; /* Dynamic array of frames of animation */
|
||||
int ms;
|
||||
struct Texture *tex;
|
||||
int loop;
|
||||
};
|
||||
|
||||
struct TextureOptions {
|
||||
|
@ -70,20 +71,20 @@ void tex_bind(struct Texture *tex); // Bind to gl context
|
|||
|
||||
char * tex_get_path(struct Texture *tex); // Get image path for texture
|
||||
|
||||
void anim_play(struct TexAnimation *anim);
|
||||
void anim_setframe(struct TexAnimation *anim, int frame);
|
||||
void anim_stop(struct TexAnimation *anim);
|
||||
void anim_pause(struct TexAnimation *anim);
|
||||
void anim_fwd(struct TexAnimation *anim);
|
||||
void anim_bkwd(struct TexAnimation *anim);
|
||||
void anim_incr(struct TexAnimation *anim);
|
||||
void anim_decr(struct TexAnimation *anim);
|
||||
void anim_play(struct anim2d *anim);
|
||||
void anim_setframe(struct anim2d *anim, int frame);
|
||||
void anim_stop(struct anim2d *anim);
|
||||
void anim_pause(struct anim2d *anim);
|
||||
void anim_fwd(struct anim2d *anim);
|
||||
void anim_bkwd(struct anim2d *anim);
|
||||
void anim_incr(struct anim2d *anim);
|
||||
void anim_decr(struct anim2d *anim);
|
||||
|
||||
void tex_incr_anim(struct TexAnimation *tex_anim);
|
||||
void tex_anim_set(struct TexAnimation *anim);
|
||||
void tex_incr_anim(struct anim2d *tex_anim);
|
||||
void tex_anim_set(struct anim2d *anim);
|
||||
|
||||
struct glrect tex_get_rect(struct Texture *tex);
|
||||
struct glrect anim_get_rect(struct TexAnimation *anim);
|
||||
struct glrect anim_get_rect(struct anim2d *anim);
|
||||
|
||||
int anim_frames(struct TexAnim *a);
|
||||
|
||||
|
|
Loading…
Reference in a new issue