many stuffs
This commit is contained in:
parent
ce81cbd9d8
commit
a88fce53e2
27 changed files with 4343 additions and 16 deletions
|
|
@ -20,17 +20,25 @@ file(GLOB_RECURSE SRCS src/**.cc src/**.c)
|
|||
|
||||
add_library(fishbone SHARED ${SRCS})
|
||||
target_include_directories(fishbone PUBLIC include)
|
||||
target_compile_definitions(fishbone PRIVATE _FISHBONE)
|
||||
|
||||
find_package(PkgConfig)
|
||||
|
||||
macro(pkg_add)
|
||||
pkg_check_modules(${ARGV0} ${ARGV1} ${ARGV0})
|
||||
target_include_directories(fishbone PRIVATE ${${ARGV0}_INCLUDE_DIRS})
|
||||
target_link_directories(fishbone PRIVATE ${${ARGV0}_LIBRARY_DIRS})
|
||||
target_link_libraries(fishbone PRIVATE ${${ARGV0}_LIBRARIES})
|
||||
pkg_check_modules(${ARGV1} ${ARGV2} ${ARGV1})
|
||||
target_include_directories(${ARGV0} PRIVATE ${${ARGV1}_INCLUDE_DIRS})
|
||||
target_link_directories(${ARGV0} PRIVATE ${${ARGV1}_LIBRARY_DIRS})
|
||||
target_link_libraries(${ARGV0} PRIVATE ${${ARGV1}_LIBRARIES})
|
||||
endmacro()
|
||||
|
||||
pkg_add(sdl2 REQUIRED)
|
||||
pkg_add(fishbone sdl2 REQUIRED)
|
||||
|
||||
set(FISHBONE_SOUND_USE_SDL2 ON)
|
||||
set(FISHBONE_WINDOW_USE_SDL2 ON)
|
||||
set(FISHBONE_THREAD_USE_SDL2 ON)
|
||||
|
||||
configure_file(config.h.in fishbone/config.h)
|
||||
target_include_directories(fishbone PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# Physics
|
||||
fb_add_dep(fishbone ode)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,2 @@
|
|||
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPM.cmake")
|
||||
|
||||
CPMAddPackage(
|
||||
NAME "jar"
|
||||
GITHUB_REPOSITORY "pyrite-dev/jar"
|
||||
GIT_TAG master
|
||||
)
|
||||
|
||||
add_library(jar INTERFACE)
|
||||
target_include_directories(jar INTERFACE ${jar_SOURCE_DIR})
|
||||
target_include_directories(jar INTERFACE jar)
|
||||
|
|
|
|||
|
|
@ -9,3 +9,4 @@ if(NOT DEFINED stb_SOURCE_DIR)
|
|||
endif()
|
||||
|
||||
add_library(stb_vorbis ${stb_SOURCE_DIR}/stb_vorbis.c)
|
||||
target_include_directories(stb_vorbis PUBLIC ${stb_SOURCE_DIR})
|
||||
|
|
|
|||
8
engine/config.h.in
Normal file
8
engine/config.h.in
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef __FISHBONE_CONFIG_H__
|
||||
#define __FISHBONE_CONFIG_H__
|
||||
|
||||
#cmakedefine FISHBONE_SOUND_USE_SDL2
|
||||
#cmakedefine FISHBONE_WINDOW_USE_SDL2
|
||||
#cmakedefine FISHBONE_THREAD_USE_SDL2
|
||||
|
||||
#endif
|
||||
|
|
@ -4,5 +4,6 @@
|
|||
#include <fishbone/client.h>
|
||||
#include <fishbone/sound.h>
|
||||
#include <fishbone/mixer.h>
|
||||
#include <fishbone/thread.h>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,4 +3,20 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include <fishbone/config.h>
|
||||
|
||||
#ifdef _FISHBONE
|
||||
#if defined(FISHBONE_AUDIO_USE_SDL2) || defined(FISHBONE_WINDOW_USE_SDL2) || defined(FISHBONE_THREAD_USE_SDL2)
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
#define STB_VORBIS_HEADER_ONLY
|
||||
#include <jar_xm.h>
|
||||
#include <jar_mod.h>
|
||||
#include <dr_mp3.h>
|
||||
#include <dr_wav.h>
|
||||
#include <dr_flac.h>
|
||||
#include <stb_vorbis.c>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,12 +7,22 @@ namespace fishbone {
|
|||
|
||||
#include <fishbone/machdep.h>
|
||||
#include <fishbone/sound.h>
|
||||
#include <fishbone/thread.h>
|
||||
|
||||
namespace fishbone {
|
||||
class Mixer {
|
||||
public:
|
||||
fishbone::Mutex mutex;
|
||||
|
||||
public:
|
||||
Mixer();
|
||||
~Mixer();
|
||||
|
||||
void read(short* buffer, size_t frames);
|
||||
fishbone::Sound* open(const char* path);
|
||||
|
||||
static const int rate = 44100;
|
||||
std::vector<fishbone::SoundLoader*> loaders;
|
||||
std::vector<fishbone::Sound*> sounds;
|
||||
std::vector<fishbone::Sound*> sounds;
|
||||
};
|
||||
}; // namespace fishbone
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,44 @@ namespace fishbone {
|
|||
#include <fishbone/machdep.h>
|
||||
#include <fishbone/mixer.h>
|
||||
|
||||
#ifdef _FISHBONE
|
||||
#if defined(FISHBONE_SOUND_USE_SDL2)
|
||||
typedef size_t FISHBONE_SOUNDDRV_HANDLE;
|
||||
#endif
|
||||
#else
|
||||
typedef void* FISHBONE_SOUNDDRV_HANDLE;
|
||||
#endif
|
||||
|
||||
namespace fishbone {
|
||||
class SoundDriver {
|
||||
FISHBONE_SOUNDDRV_HANDLE sound;
|
||||
|
||||
public:
|
||||
SoundDriver();
|
||||
~SoundDriver();
|
||||
|
||||
fishbone::Mixer mixer;
|
||||
};
|
||||
|
||||
class SoundLoader {
|
||||
public:
|
||||
SoundLoader();
|
||||
~SoundLoader();
|
||||
|
||||
virtual Sound* open(void* buffer, size_t size);
|
||||
virtual int read(Sound* sound, short* buffer, size_t frames);
|
||||
};
|
||||
|
||||
class Sound {
|
||||
SoundLoader* loader;
|
||||
|
||||
public:
|
||||
Sound(SoundLoader* loader);
|
||||
|
||||
int read(short* buffer, size_t frames);
|
||||
|
||||
int rate;
|
||||
int channels;
|
||||
};
|
||||
}; // namespace fishbone
|
||||
|
||||
|
|
|
|||
44
engine/include/fishbone/thread.h
Normal file
44
engine/include/fishbone/thread.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef __FISHBONE_THREAD_H__
|
||||
#define __FISHBONE_THREAD_H__
|
||||
|
||||
namespace fishbone {
|
||||
class Thread;
|
||||
class Mutex;
|
||||
}; // namespace fishbone
|
||||
|
||||
#include <fishbone/machdep.h>
|
||||
|
||||
#ifdef _FISHBONE
|
||||
#if defined(FISHBONE_THREAD_USE_SDL2)
|
||||
typedef SDL_mutex* FISHBONE_MUTEX_HANDLE;
|
||||
typedef SDL_Thread* FISHBONE_THREAD_HANDLE;
|
||||
#endif
|
||||
#else
|
||||
typedef void* FISHBONE_MUTEX_HANDLE;
|
||||
typedef void* FISHBONE_THREAD_HANDLE;
|
||||
#endif
|
||||
|
||||
namespace fishbone {
|
||||
class Thread {
|
||||
FISHBONE_THREAD_HANDLE thread;
|
||||
|
||||
public:
|
||||
Thread(void (*call)(fishbone::Thread* thread, void* arg), void* arg);
|
||||
~Thread();
|
||||
|
||||
void join();
|
||||
};
|
||||
|
||||
class Mutex {
|
||||
FISHBONE_MUTEX_HANDLE mutex;
|
||||
|
||||
public:
|
||||
Mutex();
|
||||
~Mutex();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
};
|
||||
}; // namespace fishbone
|
||||
|
||||
#endif
|
||||
14
engine/jar/LICENSE
Normal file
14
engine/jar/LICENSE
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
||||
1396
engine/jar/jar_mod.h
Normal file
1396
engine/jar/jar_mod.h
Normal file
File diff suppressed because it is too large
Load diff
2605
engine/jar/jar_xm.h
Normal file
2605
engine/jar/jar_xm.h
Normal file
File diff suppressed because it is too large
Load diff
2
engine/src/external/dr_flac.c
vendored
Normal file
2
engine/src/external/dr_flac.c
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define DR_FLAC_IMPLEMENTATION
|
||||
#include <dr_flac.h>
|
||||
2
engine/src/external/dr_mp3.c
vendored
Normal file
2
engine/src/external/dr_mp3.c
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define DR_MP3_IMPLEMENTATION
|
||||
#include <dr_mp3.h>
|
||||
2
engine/src/external/dr_wav.c
vendored
Normal file
2
engine/src/external/dr_wav.c
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define DR_WAV_IMPLEMENTATION
|
||||
#include <dr_wav.h>
|
||||
2
engine/src/external/jar_mod.c
vendored
Normal file
2
engine/src/external/jar_mod.c
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define JAR_MOD_IMPLEMENTATION
|
||||
#include <jar_mod.h>
|
||||
2
engine/src/external/jar_xm.c
vendored
Normal file
2
engine/src/external/jar_xm.c
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define JAR_XM_IMPLEMENTATION
|
||||
#include <jar_xm.h>
|
||||
2
engine/src/external/stb_image.c
vendored
Normal file
2
engine/src/external/stb_image.c
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
24
engine/src/mixer.cc
Normal file
24
engine/src/mixer.cc
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include <fishbone/foundation.h>
|
||||
|
||||
fishbone::Mixer::Mixer() {
|
||||
}
|
||||
|
||||
fishbone::Mixer::~Mixer() {
|
||||
for(int i = 0; i < this->sounds.size(); i++) {
|
||||
delete this->sounds[i];
|
||||
}
|
||||
for(int i = 0; i < this->loaders.size(); i++) {
|
||||
delete this->loaders[i];
|
||||
}
|
||||
}
|
||||
|
||||
void fishbone::Mixer::read(short* buffer, size_t frames) {
|
||||
}
|
||||
|
||||
fishbone::Sound* fishbone::Mixer::open(const char* path) {
|
||||
for(int i = 0; i < this->loaders.size(); i++) {
|
||||
// this->loaders[i]->open();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
28
engine/src/sound.cc
Normal file
28
engine/src/sound.cc
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <fishbone/foundation.h>
|
||||
|
||||
fishbone::SoundLoader::SoundLoader() {
|
||||
}
|
||||
|
||||
fishbone::SoundLoader::~SoundLoader() {
|
||||
}
|
||||
|
||||
fishbone::Sound* fishbone::SoundLoader::open(void* buffer, size_t size) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int fishbone::SoundLoader::read(fishbone::Sound* sound, short* buffer, size_t frames) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fishbone::Sound::Sound(SoundLoader* loader) {
|
||||
this->loader = loader;
|
||||
}
|
||||
|
||||
int fishbone::Sound::read(short* buffer, size_t frames) {
|
||||
int seek = 0;
|
||||
int l;
|
||||
|
||||
while((l = this->loader->read(this, buffer + seek * this->channels, frames - seek)) > 0) seek += l;
|
||||
|
||||
return seek;
|
||||
}
|
||||
41
engine/src/sounddrv/sdl2.cc
Normal file
41
engine/src/sounddrv/sdl2.cc
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include <fishbone/config.h>
|
||||
#ifdef FISHBONE_SOUND_USE_SDL2
|
||||
#include <fishbone/foundation.h>
|
||||
|
||||
static int sdl_audio_init = 0;
|
||||
|
||||
static void SDLCALL sound_callback(void* userdata, Uint8* stream, int len) {
|
||||
fishbone::Mixer* mixer = (fishbone::Mixer*)userdata;
|
||||
|
||||
SDL_memset(stream, 0, len);
|
||||
|
||||
mixer->read((short*)stream, len / 4);
|
||||
}
|
||||
|
||||
fishbone::SoundDriver::SoundDriver() {
|
||||
SDL_AudioSpec spec;
|
||||
|
||||
if(!sdl_audio_init) {
|
||||
SDL_InitSubSystem(SDL_INIT_AUDIO);
|
||||
sdl_audio_init = 1;
|
||||
}
|
||||
|
||||
SDL_memset(&spec, 0, sizeof(spec));
|
||||
|
||||
spec.freq = Mixer::rate;
|
||||
spec.format = AUDIO_S16SYS;
|
||||
spec.channels = 2;
|
||||
spec.samples = 4096;
|
||||
spec.callback = sound_callback;
|
||||
spec.userdata = this;
|
||||
|
||||
if((this->sound = SDL_OpenAudioDevice(NULL, 0, &spec, NULL, 0)) > 0) {
|
||||
SDL_PauseAudioDevice(this->sound, 0);
|
||||
}
|
||||
}
|
||||
|
||||
fishbone::SoundDriver::~SoundDriver() {
|
||||
SDL_PauseAudioDevice(this->sound, 1);
|
||||
SDL_CloseAudioDevice(this->sound);
|
||||
}
|
||||
#endif
|
||||
54
engine/src/thread/sdl2.cc
Normal file
54
engine/src/thread/sdl2.cc
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <fishbone/config.h>
|
||||
#ifdef FISHBONE_THREAD_USE_SDL2
|
||||
#include <fishbone/foundation.h>
|
||||
|
||||
struct call_arg {
|
||||
void (*call)(fishbone::Thread* thread, void* arg);
|
||||
fishbone::Thread* thread;
|
||||
void* arg;
|
||||
};
|
||||
|
||||
static int SDLCALL thread_call(void* data) {
|
||||
struct call_arg* arg = (struct call_arg*)data;
|
||||
|
||||
arg->call(arg->thread, arg->arg);
|
||||
|
||||
delete arg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
fishbone::Thread::Thread(void (*call)(fishbone::Thread* thread, void* arg), void* arg) {
|
||||
struct call_arg* data = new struct call_arg();
|
||||
|
||||
data->call = call;
|
||||
data->thread = this;
|
||||
data->arg = arg;
|
||||
|
||||
this->thread = SDL_CreateThread(thread_call, "FBThread", data);
|
||||
}
|
||||
|
||||
fishbone::Thread::~Thread() {
|
||||
this->join();
|
||||
}
|
||||
|
||||
void fishbone::Thread::join() {
|
||||
SDL_WaitThread(this->thread, nullptr);
|
||||
}
|
||||
|
||||
fishbone::Mutex::Mutex() {
|
||||
this->mutex = SDL_CreateMutex();
|
||||
}
|
||||
|
||||
fishbone::Mutex::~Mutex() {
|
||||
SDL_DestroyMutex(this->mutex);
|
||||
}
|
||||
|
||||
void fishbone::Mutex::lock() {
|
||||
SDL_LockMutex(this->mutex);
|
||||
}
|
||||
|
||||
void fishbone::Mutex::unlock() {
|
||||
SDL_UnlockMutex(this->mutex);
|
||||
}
|
||||
#endif
|
||||
4
engine/src/window/sdl2.cc
Normal file
4
engine/src/window/sdl2.cc
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include <fishbone/config.h>
|
||||
#ifdef FISHBONE_WINDOW_USE_SDL2
|
||||
#include <fishbone/foundation.h>
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue