Some code tweaks

Correcting details that pop-up when testing the different platforms
This commit is contained in:
raysan5 2016-11-18 13:39:57 +01:00
parent c7f0350182
commit f7b706263a
5 changed files with 51 additions and 37 deletions

View file

@ -39,7 +39,7 @@ PLATFORM ?= PLATFORM_DESKTOP
SHARED ?= NO SHARED ?= NO
# define NO to use OpenAL Soft as static library (or shared by default) # 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 # on PLATFORM_WEB force OpenAL Soft shared library
ifeq ($(PLATFORM),PLATFORM_WEB) ifeq ($(PLATFORM),PLATFORM_WEB)
@ -188,6 +188,11 @@ else
# compile raylib static library for desktop platforms. # compile raylib static library for desktop platforms.
ar rcs $(OUTPUT_PATH)/libraylib.a $(OBJS) ar rcs $(OUTPUT_PATH)/libraylib.a $(OBJS)
@echo "libraylib.a generated (static library)!" @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
endif endif

View file

@ -49,8 +49,11 @@
#if defined(AUDIO_STANDALONE) #if defined(AUDIO_STANDALONE)
#include "audio.h" #include "audio.h"
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
#else #else
#include "raylib.h" #include "raylib.h"
#include "utils.h" // Required for: DecompressData()
// NOTE: Includes Android fopen() function map
#endif #endif
#include "AL/al.h" // OpenAL basic header #include "AL/al.h" // OpenAL basic header
@ -68,13 +71,6 @@
#define AL_FORMAT_STEREO_FLOAT32 0x10011 #define AL_FORMAT_STEREO_FLOAT32 0x10011
#endif #endif
#if defined(AUDIO_STANDALONE)
#include <stdarg.h> // 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 //#define STB_VORBIS_HEADER_ONLY
#include "external/stb_vorbis.h" // OGG loading functions #include "external/stb_vorbis.h" // OGG loading functions
@ -122,7 +118,7 @@ typedef struct MusicData {
bool loop; // Repeat music after finish (loop) bool loop; // Repeat music after finish (loop)
unsigned int totalSamples; // Total number of samples unsigned int totalSamples; // Total number of samples
unsigned int samplesLeft; // Number of samples left to end unsigned int samplesLeft; // Number of samples left to end
} MusicData, *Music; } MusicData;
#if defined(AUDIO_STANDALONE) #if defined(AUDIO_STANDALONE)
typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType; typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;

View file

@ -62,12 +62,6 @@
#endif #endif
#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 // Wave type, defines audio wave data
typedef struct Wave { typedef struct Wave {
unsigned int sampleCount; // Number of samples unsigned int sampleCount; // Number of samples
@ -77,9 +71,16 @@ typedef struct Wave {
void *data; // Buffer data pointer void *data; // Buffer data pointer
} Wave; } 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) // Music type (file streaming from memory)
// NOTE: Anything longer than ~10 seconds should be streamed // NOTE: Anything longer than ~10 seconds should be streamed
typedef struct Music *Music; typedef struct MusicData *Music;
// Audio stream type // Audio stream type
// NOTE: Useful to create custom audio streams not bound to a specific file // 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 // Module Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
void InitAudioDevice(void); // Initialize audio device and context 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 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 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) 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 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 UnloadSound(Sound sound); // Unload sound
void PlaySound(Sound sound); // Play a sound void PlaySound(Sound sound); // Play a sound
void PauseSound(Sound sound); // Pause 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 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 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) void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
Music LoadMusicStream(char *fileName); // Load music stream from file 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 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 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 PauseMusicStream(Music music); // Pause music playing
void ResumeMusicStream(Music music); // Resume playing paused music void ResumeMusicStream(Music music); // Resume playing paused music
bool IsMusicPlaying(Music music); // Check if music is playing 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 GetMusicTimeLength(Music music); // Get music time length (in seconds)
float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
AudioStream InitAudioStream(unsigned int sampleRate, AudioStream InitAudioStream(unsigned int sampleRate,
unsigned int sampleSize, unsigned int sampleSize,
unsigned int channels); // Init audio stream (to stream audio pcm data) 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 UpdateAudioStream(AudioStream stream, void *data, int numSamples); // Update audio stream buffers with data
void CloseAudioStream(AudioStream stream); // Close audio stream and free memory void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill

View file

@ -1175,9 +1175,10 @@ bool IsGamepadAvailable(int gamepad)
bool IsGamepadName(int gamepad, const char *name) bool IsGamepadName(int gamepad, const char *name)
{ {
bool result = false; bool result = false;
const char *gamepadName = NULL;
#if !defined(PLATFORM_ANDROID) #if !defined(PLATFORM_ANDROID)
const char *gamepadName = NULL;
if (gamepadReady[gamepad]) gamepadName = GetGamepadName(gamepad); if (gamepadReady[gamepad]) gamepadName = GetGamepadName(gamepad);
if ((name != NULL) && (gamepadName != NULL)) result = (strcmp(name, gamepadName) == 0); if ((name != NULL) && (gamepadName != NULL)) result = (strcmp(name, gamepadName) == 0);
#endif #endif
@ -1977,7 +1978,11 @@ static void PollInputEvents(void)
previousMouseWheelY = currentMouseWheelY; previousMouseWheelY = currentMouseWheelY;
currentMouseWheelY = 0; 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 // Check if gamepads are ready
// NOTE: We do it here in case of disconection // NOTE: We do it here in case of disconection
for (int i = 0; i < MAX_GAMEPADS; i++) for (int i = 0; i < MAX_GAMEPADS; i++)

View file

@ -1817,6 +1817,7 @@ static Material LoadMTL(const char *fileName)
char buffer[MAX_BUFFER_SIZE]; char buffer[MAX_BUFFER_SIZE];
Vector3 color = { 1.0f, 1.0f, 1.0f }; Vector3 color = { 1.0f, 1.0f, 1.0f };
char mapFileName[128]; char mapFileName[128];
int result = 0;
FILE *mtlFile; FILE *mtlFile;
@ -1901,13 +1902,13 @@ static Material LoadMTL(const char *fileName)
{ {
if (buffer[5] == 'd') // map_Kd string Diffuse color texture map. if (buffer[5] == 'd') // map_Kd string Diffuse color texture map.
{ {
sscanf(buffer, "map_Kd %s", mapFileName); result = sscanf(buffer, "map_Kd %s", mapFileName);
if (mapFileName != NULL) material.texDiffuse = LoadTexture(mapFileName); if (result != EOF) material.texDiffuse = LoadTexture(mapFileName);
} }
else if (buffer[5] == 's') // map_Ks string Specular color texture map. else if (buffer[5] == 's') // map_Ks string Specular color texture map.
{ {
sscanf(buffer, "map_Ks %s", mapFileName); result = sscanf(buffer, "map_Ks %s", mapFileName);
if (mapFileName != NULL) material.texSpecular = LoadTexture(mapFileName); if (result != EOF) material.texSpecular = LoadTexture(mapFileName);
} }
else if (buffer[5] == 'a') // map_Ka string Ambient color texture map. else if (buffer[5] == 'a') // map_Ka string Ambient color texture map.
{ {
@ -1916,13 +1917,13 @@ static Material LoadMTL(const char *fileName)
} break; } break;
case 'B': // map_Bump string Bump texture map. case 'B': // map_Bump string Bump texture map.
{ {
sscanf(buffer, "map_Bump %s", mapFileName); result = sscanf(buffer, "map_Bump %s", mapFileName);
if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); if (result != EOF) material.texNormal = LoadTexture(mapFileName);
} break; } break;
case 'b': // map_bump string Bump texture map. case 'b': // map_bump string Bump texture map.
{ {
sscanf(buffer, "map_bump %s", mapFileName); result = sscanf(buffer, "map_bump %s", mapFileName);
if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); if (result != EOF) material.texNormal = LoadTexture(mapFileName);
} break; } break;
case 'd': // map_d string Opacity texture map. case 'd': // map_d string Opacity texture map.
{ {
@ -1946,8 +1947,8 @@ static Material LoadMTL(const char *fileName)
} break; } break;
case 'b': // bump string Bump texture map case 'b': // bump string Bump texture map
{ {
sscanf(buffer, "bump %s", mapFileName); result = sscanf(buffer, "bump %s", mapFileName);
if (mapFileName != NULL) material.texNormal = LoadTexture(mapFileName); if (result != EOF) material.texNormal = LoadTexture(mapFileName);
} break; } break;
case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d
{ {