Brainstorm now compiles

This commit is contained in:
John Alanbrook 2022-06-23 07:34:51 +00:00
parent e6ca94c2df
commit 41b8632b32
7 changed files with 3570 additions and 45 deletions

View file

@ -1,5 +1,5 @@
procs != nproc
MAKEFLAGS = --jobs=$(procs)
#procs != nproc
#MAKEFLAGS = --jobs=$(procs)
UNAME != uname
@ -10,7 +10,7 @@ endif
UNAME_P != uname -m
#CC specifies which compiler we're using
CC = tcc -std=c99
CC = clang
MUSL = /usr/local/musl/include
@ -57,7 +57,7 @@ edirs != find ./source/engine -type d -name include
edirs += ./source/engine
ehead != $(call findindir,./source/engine,*.h)
eobjects != $(call make_objs, ./source/engine)
eobjects != $(call rm,$(eobjects),sqlite pl_mpeg_extract_frames pl_mpeg_player yugine.c yugine.c)
eobjects != $(call rm,$(eobjects),sqlite pl_mpeg_extract_frames pl_mpeg_player yugine)
eddirs != find ./source/editor -type d
eddirs += ./source/editor
@ -76,7 +76,7 @@ includeflag != $(call prefix,$(edirs) $(eddirs) $(pindirs) $(bsdirs),-I)
COMPINCLUDE = $(edirs) $(eddirs) $(pindirs) $(bsdirs)
#COMPILER_FLAGS specifies the additional compilation options we're using
WARNING_FLAGS = #-Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Wno-incompatible-function-pointer-types -Wno-gnu-statement-expression -Wno-complex-component-init -pedantic
WARNING_FLAGS = -Wno-everything#-Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Wno-incompatible-function-pointer-types -Wno-gnu-statement-expression -Wno-complex-component-init -pedantic
#COMPILER_FLAGS = $(includeflag) -g -O0 $(WARNING_FLAGS) -DGLEW_STATIC -D_GLFW_X11 -D_POSIX_C_SOURCE=1993809L -c -MMD -MP $< -o $@
COMPILER_FLAGS = $(includeflag) -I/usr/local/include -g -O0 $(WARNING_FLAGS) -DGLEW_STATIC -D_GLFW_X11 -D_POSIX_C_SOURCE=1993809L -c $< -o $@
@ -90,7 +90,7 @@ ifeq ($(UNAME), Windows_NT)
EXT = .exe
else
LINKER_FLAGS = -fPIC -rdynamic
ELIBS = editor engine glfw3 m c tcc tcc1
ELIBS = m c engine editor glfw3
CLIBS =
EXT =
endif
@ -117,27 +117,27 @@ LINK = $(LIBPATH) $(LINKER_FLAGS) $(LELIBS) -o $@
engine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE)
@echo Linking engine
@$(CC) $< $(LINK)
@$(CC) $^ $(LINK)
@echo Finished build
editor: $(yuginec:.%.c=$(objprefix)%.o) $(EDITOR) $(ENGINE)
@echo Linking editor
$(CC) $< $(LINK)
$(CC) $^ $(LINK)
@echo Finished build
$(ENGINE): $(eobjects) bin/libglfw3.a
@echo Making library engine.a
@ar -r $(ENGINE) $(eobjects)
@ar -r $(ENGINE) $^
@cp -u -r $(ehead) $(INCLUDE)
$(EDITOR): $(edobjects)
@echo Making editor library
@ar -r $(EDITOR) $(edobjects)
@ar -r $(EDITOR) $^
@cp -u -r $(edhead) $(INCLUDE)
xbrainstorm: $(ENGINE) $(bsobjects)
xbrainstorm: $(bsobjects) $(ENGINE) $(EDITOR)
@echo Making brainstorm
@$(CC) $(bsobjects) $(LINK) -o $@
$(CC) $^ $(LINK)
@mv xbrainstorm brainstorm/brainstorm$(EXT)
pinball: $(ENGINE) $(pinobjects)

View file

@ -488,6 +488,16 @@ void editor_project_gui()
NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|
NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_row_dynamic(ctx, 25, 2);
static struct sound *ss;
if (nk_button_label(ctx, "Load sound")) {
ss = make_sound("alert.wav");
}
if (nk_button_label(ctx, "Play sound")) {
play_sound(ss);
}
nk_layout_row_dynamic(ctx, 30, 2);
nk_label(ctx, "Floating point:", NK_TEXT_RIGHT);

View file

@ -3,10 +3,15 @@
#define STB_DS_IMPLEMENTATION
#include <stb_ds.h>
//#define STB_TRUETYPE_IMPLEMENTATION
//#include <stb_truetype.h>
#define PL_MPEG_IMPLEMENTATION
#include <pl_mpeg.h>
#define MINIAUDIO_IMPLEMENTATION
#include <miniaudio.h>
#ifdef EDITOR
#include "editor.h"
#endif

View file

@ -1,25 +1,46 @@
#define MINIAUDIO_IMPLEMENTATION
#include "sound.h"
#include "resources.h"
ma_engine engine;
const char *audioDriver;
static int mus_ch = -1;
struct sound *mus_cur;
ma_sound_group mus_grp;
void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount)
{
// In playback mode copy data to pOutput. In capture mode read data from pInput. In full-duplex mode, both
// pOutput and pInput will be valid and you can move data from pInput into pOutput. Never process more than
// frameCount frames.
}
void sound_init()
{
/*
int flags = MIX_INIT_MP3 | MIX_INIT_OGG;
int err = Mix_Init(flags);
if ((err&flags) != flags) {
printf("MIX did not init!!");
}
*/
//mus_ch = Mix_AllocateChannels(1);
ma_device_config cnf = ma_device_config_init(ma_device_type_playback);
cnf.playback.format = ma_format_f32;
cnf.playback.channels = 0;
cnf.sampleRate = 0;
cnf.dataCallback = data_callback;
//Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
ma_device device;
ma_device_init(NULL, &cnf, &device);
ma_device_start(&device);
*/
ma_result result = ma_engine_init(NULL, &engine);
if (result != MA_SUCCESS) {
printf("UHOH!!!");
}
ma_sound_group_init(&engine, 0, NULL, &mus_grp);
}
void audio_open(const char *device)
@ -35,28 +56,35 @@ void audio_close()
struct sound *make_sound(const char *wav)
{
struct sound *new = calloc(1, sizeof(struct sound));
//new->sound = Mix_LoadWAV(wav);
ma_result res = ma_sound_init_from_file(&engine, wav, 0, NULL, NULL, &new->sound);
if (res != MA_SUCCESS) {
printf("HONO!!!!");
}
return new;
}
struct music *make_music(const char *ogg)
struct sound *make_music(const char *ogg)
{
struct music *sound = calloc(1, sizeof(struct music));
//sound->music = Mix_LoadMUS(make_path(ogg));
struct sound *sound = calloc(1, sizeof(struct sound));
ma_result res = ma_sound_init_from_file(&engine, ogg, 0, NULL, &mus_grp, &sound->sound);
return sound;
}
void play_sound(struct sound *sound)
{
//Mix_VolumeChunk(sound->sound, sound->volume);
//Mix_PlayChannel(-1, sound->sound, 0);
//ma_sound_set_volume(&sound->sound, (float)sound->volume/127);
ma_sound_start(&sound->sound);
sound->state = MUS_PLAY;
}
void play_music(struct sound *music)
{
//Mix_PlayChannel(mus_ch, music->sound, -1);
ma_sound_start(&music->sound);
music->state = MUS_PLAY;
mus_cur = music;
}
void music_set(struct sound *music)
@ -66,34 +94,35 @@ void music_set(struct sound *music)
void music_volume(unsigned char vol)
{
//Mix_Volume(mus_ch, vol);
ma_sound_group_set_volume(&mus_grp, (float)vol/127);
}
int music_playing()
{
//return Mix_Playing(mus_ch);
return 0;
return ma_sound_is_playing(&mus_cur->sound);
}
int music_paused()
{
//return Mix_Paused(mus_ch);
return 0;
return mus_cur->state == MUS_PAUSE;
}
void music_resume()
{
//Mix_Resume(mus_ch);
ma_sound_start(&mus_cur->sound);
}
void music_pause()
{
//Mix_Pause(mus_ch);
ma_sound_stop(&mus_cur->sound);
mus_cur->state = MUS_PAUSE;
}
void music_stop()
{
//Mix_HaltChannel(mus_ch);
ma_sound_stop(&mus_cur->sound);
mus_cur->state = MUS_STOP;
ma_sound_seek_to_pcm_frame(&mus_cur->sound, 0);
}
@ -119,6 +148,7 @@ void clear_raw(int device)
int open_device(const char *adriver)
{
/*
SDL_AudioSpec audio_spec;
SDL_memset(&audio_spec, 0, sizeof(audio_spec));

View file

@ -3,6 +3,8 @@
#include <miniaudio.h>
struct Mix_Chunk {
int i;
};
@ -11,13 +13,15 @@ struct Mix_Music {
int i;
};
struct sound {
struct Mix_Chunk *sound;
unsigned char volume;
enum MUS {
MUS_STOP,
MUS_PLAY,
MUS_PAUSE
};
struct music {
struct Mix_Music *music;
struct sound {
ma_sound sound;
enum MUS state;
unsigned char volume;
};
@ -28,7 +32,7 @@ void audio_open(const char *device);
void audio_close();
struct sound *make_sound(const char *wav);
struct music *make_music(const char *ogg);
struct sound *make_music(const char *ogg);
void play_sound(struct sound *sound);

3476
source/engine/thirdparty/pl_mpeg/pl_mpeg.c vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,7 @@ struct mSDLWindow *MakeSDLWindow(const char *name, int width, int height,
struct mSDLWindow *w = calloc(1, sizeof(struct mSDLWindow));
w->width = width;
w->height = height;
w->window = glfwCreateWindow(width, height, "New Game", NULL, NULL);
w->window = glfwCreateWindow(width, height, name, NULL, NULL);
if (!w->window) {
printf("Couldn't make GLFW window\n");