From f7b706263a820034a93ab88e7582b7001819d8d0 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 18 Nov 2016 13:39:57 +0100 Subject: [PATCH] Some code tweaks Correcting details that pop-up when testing the different platforms --- src/Makefile | 7 ++++++- src/audio.c | 12 ++++-------- src/audio.h | 39 +++++++++++++++++++++++---------------- src/core.c | 9 +++++++-- src/models.c | 21 +++++++++++---------- 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/Makefile b/src/Makefile index 2433428fd..2e2631897 100644 --- a/src/Makefile +++ b/src/Makefile @@ -39,7 +39,7 @@ PLATFORM ?= PLATFORM_DESKTOP SHARED ?= NO # define NO to use OpenAL Soft as static library (or shared by default) -SHARED_OPENAL ?= NO +SHARED_OPENAL ?= YES # on PLATFORM_WEB force OpenAL Soft shared library ifeq ($(PLATFORM),PLATFORM_WEB) @@ -188,6 +188,11 @@ else # compile raylib static library for desktop platforms. ar rcs $(OUTPUT_PATH)/libraylib.a $(OBJS) @echo "libraylib.a generated (static library)!" + ifeq ($(SHARED_OPENAL),NO) + @echo "expected OpenAL Soft static library linking" + else + @echo "expected OpenAL Soft shared library linking" + endif endif endif diff --git a/src/audio.c b/src/audio.c index 3ddbf0ce4..49aca4b01 100644 --- a/src/audio.c +++ b/src/audio.c @@ -49,8 +49,11 @@ #if defined(AUDIO_STANDALONE) #include "audio.h" + #include // Required for: va_list, va_start(), vfprintf(), va_end() #else #include "raylib.h" + #include "utils.h" // Required for: DecompressData() + // NOTE: Includes Android fopen() function map #endif #include "AL/al.h" // OpenAL basic header @@ -68,13 +71,6 @@ #define AL_FORMAT_STEREO_FLOAT32 0x10011 #endif -#if defined(AUDIO_STANDALONE) - #include // Required for: va_list, va_start(), vfprintf(), va_end() -#else - #include "utils.h" // Required for: DecompressData() - // NOTE: Includes Android fopen() function map -#endif - //#define STB_VORBIS_HEADER_ONLY #include "external/stb_vorbis.h" // OGG loading functions @@ -122,7 +118,7 @@ typedef struct MusicData { bool loop; // Repeat music after finish (loop) unsigned int totalSamples; // Total number of samples unsigned int samplesLeft; // Number of samples left to end -} MusicData, *Music; +} MusicData; #if defined(AUDIO_STANDALONE) typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType; diff --git a/src/audio.h b/src/audio.h index 5de8f6139..2b3c59335 100644 --- a/src/audio.h +++ b/src/audio.h @@ -62,12 +62,6 @@ #endif #endif -// Sound source type -typedef struct Sound { - unsigned int source; // Sound audio source id - unsigned int buffer; // Sound audio buffer id -} Sound; - // Wave type, defines audio wave data typedef struct Wave { unsigned int sampleCount; // Number of samples @@ -77,9 +71,16 @@ typedef struct Wave { void *data; // Buffer data pointer } Wave; +// Sound source type +typedef struct Sound { + unsigned int source; // OpenAL audio source id + unsigned int buffer; // OpenAL audio buffer id + int format; // OpenAL audio format specifier +} Sound; + // Music type (file streaming from memory) // NOTE: Anything longer than ~10 seconds should be streamed -typedef struct Music *Music; +typedef struct MusicData *Music; // Audio stream type // NOTE: Useful to create custom audio streams not bound to a specific file @@ -106,13 +107,16 @@ extern "C" { // Prevents name mangling of functions // Module Functions Declaration //---------------------------------------------------------------------------------- void InitAudioDevice(void); // Initialize audio device and context -void CloseAudioDevice(void); // Close the audio device and context (and music stream) +void CloseAudioDevice(void); // Close the audio device and context bool IsAudioDeviceReady(void); // Check if audio device has been initialized successfully -Sound LoadSound(char *fileName); // Load sound to memory +Wave LoadWave(const char *fileName); // Load wave data from file into RAM +Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, int channels); // Load wave data from float array data (32bit) +Sound LoadSound(const char *fileName); // Load sound to memory Sound LoadSoundFromWave(Wave wave); // Load sound to memory from wave data Sound LoadSoundFromRES(const char *rresName, int resId); // Load sound to memory from rRES file (raylib Resource) void UpdateSound(Sound sound, void *data, int numSamples); // Update sound buffer with new data +void UnloadWave(Wave wave); // Unload wave data void UnloadSound(Sound sound); // Unload sound void PlaySound(Sound sound); // Play a sound void PauseSound(Sound sound); // Pause a sound @@ -121,12 +125,15 @@ void StopSound(Sound sound); // Stop playing bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level) void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level) - -Music LoadMusicStream(char *fileName); // Load music stream from file +void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format +Wave WaveCopy(Wave wave); // Copy a wave to a new wave +void WaveCrop(Wave *wave, int initSample, int finalSample); // Crop a wave to defined samples range +float *GetWaveData(Wave wave); // Get samples data from wave as a floats array +Music LoadMusicStream(const char *fileName); // Load music stream from file void UnloadMusicStream(Music music); // Unload music stream -void PlayMusicStream(Music music); // Start music playing (open stream) +void PlayMusicStream(Music music); // Start music playing void UpdateMusicStream(Music music); // Updates buffers for music streaming -void StopMusicStream(Music music); // Stop music playing (close stream) +void StopMusicStream(Music music); // Stop music playing void PauseMusicStream(Music music); // Pause music playing void ResumeMusicStream(Music music); // Resume playing paused music bool IsMusicPlaying(Music music); // Check if music is playing @@ -135,9 +142,9 @@ void SetMusicPitch(Music music, float pitch); // Set pitch for float GetMusicTimeLength(Music music); // Get music time length (in seconds) float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) -AudioStream InitAudioStream(unsigned int sampleRate, - unsigned int sampleSize, - unsigned int channels); // Init audio stream (to stream audio pcm data) +AudioStream InitAudioStream(unsigned int sampleRate, + unsigned int sampleSize, + unsigned int channels); // Init audio stream (to stream raw audio pcm data) void UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data void CloseAudioStream(AudioStream stream); // Close audio stream and free memory bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill diff --git a/src/core.c b/src/core.c index 7749eab7d..241772ecf 100644 --- a/src/core.c +++ b/src/core.c @@ -1175,9 +1175,10 @@ bool IsGamepadAvailable(int gamepad) bool IsGamepadName(int gamepad, const char *name) { bool result = false; - const char *gamepadName = NULL; #if !defined(PLATFORM_ANDROID) + const char *gamepadName = NULL; + if (gamepadReady[gamepad]) gamepadName = GetGamepadName(gamepad); if ((name != NULL) && (gamepadName != NULL)) result = (strcmp(name, gamepadName) == 0); #endif @@ -1977,7 +1978,11 @@ static void PollInputEvents(void) previousMouseWheelY = currentMouseWheelY; currentMouseWheelY = 0; - +#endif + +// NOTE: GLFW3 joystick functionality not available in web +// TODO: Support joysticks using emscripten API +#if defined(PLATFORM_DESKTOP) // Check if gamepads are ready // NOTE: We do it here in case of disconection for (int i = 0; i < MAX_GAMEPADS; i++) diff --git a/src/models.c b/src/models.c index be0e6ea4e..48f8b8131 100644 --- a/src/models.c +++ b/src/models.c @@ -1817,6 +1817,7 @@ static Material LoadMTL(const char *fileName) char buffer[MAX_BUFFER_SIZE]; Vector3 color = { 1.0f, 1.0f, 1.0f }; char mapFileName[128]; + int result = 0; FILE *mtlFile; @@ -1901,13 +1902,13 @@ static Material LoadMTL(const char *fileName) { if (buffer[5] == 'd') // map_Kd string Diffuse color texture map. { - sscanf(buffer, "map_Kd %s", mapFileName); - if (mapFileName != NULL) material.texDiffuse = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Kd %s", mapFileName); + if (result != EOF) material.texDiffuse = LoadTexture(mapFileName); } else if (buffer[5] == 's') // map_Ks string Specular color texture map. { - sscanf(buffer, "map_Ks %s", mapFileName); - if (mapFileName != NULL) material.texSpecular = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Ks %s", mapFileName); + if (result != EOF) material.texSpecular = LoadTexture(mapFileName); } else if (buffer[5] == 'a') // map_Ka string Ambient color texture map. { @@ -1916,13 +1917,13 @@ static Material LoadMTL(const char *fileName) } break; case 'B': // map_Bump string Bump texture map. { - sscanf(buffer, "map_Bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "map_Bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'b': // map_bump string Bump texture map. { - sscanf(buffer, "map_bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "map_bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'd': // map_d string Opacity texture map. { @@ -1946,8 +1947,8 @@ static Material LoadMTL(const char *fileName) } break; case 'b': // bump string Bump texture map { - sscanf(buffer, "bump %s", mapFileName); - if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); + result = sscanf(buffer, "bump %s", mapFileName); + if (result != EOF) material.texNormal = LoadTexture(mapFileName); } break; case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d {