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