Merge aaea2eb9a6 into 17f09cb034
This commit is contained in:
commit
ac05e039b1
28 changed files with 226 additions and 552 deletions
14
.gitignore
vendored
14
.gitignore
vendored
|
|
@ -51,6 +51,17 @@ ipch/
|
||||||
*.exe
|
*.exe
|
||||||
!tools/rREM/rrem.exe
|
!tools/rREM/rrem.exe
|
||||||
|
|
||||||
|
# Ignore all examples files
|
||||||
|
examples/*
|
||||||
|
# Unignore all examples dirs
|
||||||
|
!examples/*/
|
||||||
|
# Unignore all examples files with extension
|
||||||
|
!examples/*.c
|
||||||
|
!examples/*.lua
|
||||||
|
!examples/*.png
|
||||||
|
# Unignore examples Makefile
|
||||||
|
!examples/Makefile
|
||||||
|
|
||||||
# Ignore files build by xcode
|
# Ignore files build by xcode
|
||||||
*.mode*v*
|
*.mode*v*
|
||||||
*.pbxuser
|
*.pbxuser
|
||||||
|
|
@ -68,9 +79,6 @@ DerivedData/
|
||||||
src/libraylib.a
|
src/libraylib.a
|
||||||
src/libraylib.bc
|
src/libraylib.bc
|
||||||
|
|
||||||
# oculus example
|
|
||||||
!examples/oculus_glfw_sample/
|
|
||||||
|
|
||||||
# external libraries DLLs
|
# external libraries DLLs
|
||||||
!src/external/glfw3/lib/win32/glfw3.dll
|
!src/external/glfw3/lib/win32/glfw3.dll
|
||||||
!src/external/openal_soft/lib/win32/OpenAL32.dll
|
!src/external/openal_soft/lib/win32/OpenAL32.dll
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ NOTE:
|
||||||
It includes some interesting new features and is a stepping stone towards raylib future.
|
It includes some interesting new features and is a stepping stone towards raylib future.
|
||||||
|
|
||||||
HUGE changes:
|
HUGE changes:
|
||||||
[rlua] LUA BINDING: Complete raylib LUA binding, ALL raylib functions ported to LUA plus the +60 code examples.
|
[rlua] Lua BINDING: Complete raylib Lua binding, ALL raylib functions ported to Lua plus the +60 code examples.
|
||||||
[audio] COMPLETE REDESIGN: Improved music support and also raw audio data processing and playing, +20 new functions added.
|
[audio] COMPLETE REDESIGN: Improved music support and also raw audio data processing and playing, +20 new functions added.
|
||||||
[physac] COMPLETE REWRITE: Improved performance, functionality and simplified usage, moved to own repository and added multiple examples!
|
[physac] COMPLETE REWRITE: Improved performance, functionality and simplified usage, moved to own repository and added multiple examples!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ notes on raylib 1.6
|
||||||
|
|
||||||
On November 2016, only 4 months after raylib 1.5, arrives raylib 1.6. This new version represents another big review of the library and includes some interesting additions. This version conmmemorates raylib 3rd anniversary (raylib 1.0 was published on November 2013) and it is a stepping stone for raylib future. raylib roadmap has been reviewed and redefined to focus on its primary objective: create a simple and easy-to-use library to learn videogames programming. Some of the new features:
|
On November 2016, only 4 months after raylib 1.5, arrives raylib 1.6. This new version represents another big review of the library and includes some interesting additions. This version conmmemorates raylib 3rd anniversary (raylib 1.0 was published on November 2013) and it is a stepping stone for raylib future. raylib roadmap has been reviewed and redefined to focus on its primary objective: create a simple and easy-to-use library to learn videogames programming. Some of the new features:
|
||||||
|
|
||||||
Complete raylib LUA binding. All raylib functions plus the +60 code examples have been ported to LUA, now LUA users can enjoy coding videogames in LUA while using all the internal power of raylib. This addition also open the doors to LUA scripting support for a future raylib-based engine, being able to move game logic (Init, Update, Draw, De-Init) to LUA scripts while keep using raylib functionality.
|
Complete raylib Lua binding. All raylib functions plus the +60 code examples have been ported to Lua, now Lua users can enjoy coding videogames in Lua while using all the internal power of raylib. This addition also open the doors to Lua scripting support for a future raylib-based engine, being able to move game logic (Init, Update, Draw, De-Init) to Lua scripts while keep using raylib functionality.
|
||||||
|
|
||||||
Completely redesigned audio module. Based on the new direction taken in raylib 1.5, it has been further improved and more functionality added (+20 new functions) to allow raw audio processing and streaming. FLAC file format support has also been added. In the same line, OpenAL Soft backend is now provided as a static library in Windows to allow static linking and get ride of OpenAL32.dll. Now raylib Windows games are completey self-contained, no external libraries required any more!
|
Completely redesigned audio module. Based on the new direction taken in raylib 1.5, it has been further improved and more functionality added (+20 new functions) to allow raw audio processing and streaming. FLAC file format support has also been added. In the same line, OpenAL Soft backend is now provided as a static library in Windows to allow static linking and get ride of OpenAL32.dll. Now raylib Windows games are completey self-contained, no external libraries required any more!
|
||||||
|
|
||||||
|
|
@ -273,6 +273,9 @@ contributing (in some way or another) to make raylib project better. Huge thanks
|
||||||
- [Emanuele Petriglia](https://github.com/LelixSuper) for working on multiple GNU/Linux improvements and developing [TicTacToe](https://github.com/LelixSuper/TicTacToe) raylib game.
|
- [Emanuele Petriglia](https://github.com/LelixSuper) for working on multiple GNU/Linux improvements and developing [TicTacToe](https://github.com/LelixSuper/TicTacToe) raylib game.
|
||||||
- [Joshua Reisenauer](https://github.com/kd7tck) for adding audio modules support (XM, MOD) and reviewing audio system.
|
- [Joshua Reisenauer](https://github.com/kd7tck) for adding audio modules support (XM, MOD) and reviewing audio system.
|
||||||
- Marcelo Paez (paezao) for his help on OSX to solve High DPI display issue. Thanks Marcelo!
|
- Marcelo Paez (paezao) for his help on OSX to solve High DPI display issue. Thanks Marcelo!
|
||||||
|
- [Ghassan Al-Mashareqa](https://github.com/ghassanpl) for his amazing contribution with raylib Lua module, I just work over his code to implement [rlua](https://github.com/raysan5/raylib/blob/master/src/rlua.h)
|
||||||
|
- [Teodor Stoenescu](https://github.com/teodor-stoenescu) for his improvements on OBJ object loading.
|
||||||
|
|
||||||
|
Please, if I forget someone in this list, excuse me and write me an email to remind me to add you!
|
||||||
|
|
||||||
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"
|
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ raylib 1.x
|
||||||
|
|
||||||
raylib 1.6
|
raylib 1.6
|
||||||
|
|
||||||
[DONE] LUA scripting support (raylib lua wrapper)
|
[DONE] Lua scripting support (raylib Lua wrapper)
|
||||||
[DONE] Redesigned audio module
|
[DONE] Redesigned audio module
|
||||||
|
|
||||||
raylib 1.5
|
raylib 1.5
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ int main()
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(WHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,52 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#if defined(_WIN32)
|
||||||
#include <conio.h> // Windows only, no stardard library
|
#include <conio.h> // Windows only, no stardard library
|
||||||
|
#endif
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
|
|
||||||
|
#if defined(__linux)
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
static int kbhit(void)
|
||||||
|
{
|
||||||
|
struct termios oldt, newt;
|
||||||
|
int ch;
|
||||||
|
int oldf;
|
||||||
|
|
||||||
|
tcgetattr(STDIN_FILENO, &oldt);
|
||||||
|
newt = oldt;
|
||||||
|
newt.c_lflag &= ~(ICANON | ECHO);
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||||
|
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||||
|
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
|
||||||
|
|
||||||
|
ch = getchar();
|
||||||
|
|
||||||
|
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||||
|
fcntl(STDIN_FILENO, F_SETFL, oldf);
|
||||||
|
|
||||||
|
if(ch != EOF)
|
||||||
|
{
|
||||||
|
ungetc(ch, stdin);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char getch()
|
||||||
|
{
|
||||||
|
return getchar();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#define KEY_ESCAPE 27
|
#define KEY_ESCAPE 27
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
@ -78,4 +120,4 @@ int main()
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "..\src\physac.h"
|
#include "../src/physac.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "..\src\physac.h"
|
#include "../src/physac.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "..\src\physac.h"
|
#include "../src/physac.h"
|
||||||
|
|
||||||
#define VELOCITY 0.5f
|
#define VELOCITY 0.5f
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "..\src\physac.h"
|
#include "../src/physac.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "..\src\physac.h"
|
#include "../src/physac.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateOculusTracking();
|
UpdateOculusTracking(&camera);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
========================================================================
|
|
||||||
STATIC LIBRARY : raylib Project Overview
|
|
||||||
========================================================================
|
|
||||||
|
|
||||||
AppWizard has created this raylib library project for you.
|
|
||||||
|
|
||||||
No source files were created as part of your project.
|
|
||||||
|
|
||||||
|
|
||||||
raylib.vcxproj
|
|
||||||
This is the main project file for VC++ projects generated using an Application Wizard.
|
|
||||||
It contains information about the version of Visual C++ that generated the file, and
|
|
||||||
information about the platforms, configurations, and project features selected with the
|
|
||||||
Application Wizard.
|
|
||||||
|
|
||||||
raylib.vcxproj.filters
|
|
||||||
This is the filters file for VC++ projects generated using an Application Wizard.
|
|
||||||
It contains information about the association between the files in your project
|
|
||||||
and the filters. This association is used in the IDE to show grouping of files with
|
|
||||||
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
|
|
||||||
"Source Files" filter).
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
Other notes:
|
|
||||||
|
|
||||||
AppWizard uses "TODO:" comments to indicate parts of the source code you
|
|
||||||
should add to or customize.
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
136
src/audio.c
136
src/audio.c
|
|
@ -52,8 +52,7 @@
|
||||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
#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()
|
#include "utils.h" // Required for: fopen() Android mapping, TraceLog()
|
||||||
// NOTE: Includes Android fopen() function map
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "AL/al.h" // OpenAL basic header
|
#include "AL/al.h" // OpenAL basic header
|
||||||
|
|
@ -324,117 +323,6 @@ Sound LoadSoundFromWave(Wave wave)
|
||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load sound to memory from rRES file (raylib Resource)
|
|
||||||
// TODO: Maybe rresName could be directly a char array with all the data?
|
|
||||||
Sound LoadSoundFromRES(const char *rresName, int resId)
|
|
||||||
{
|
|
||||||
Sound sound = { 0 };
|
|
||||||
|
|
||||||
#if defined(AUDIO_STANDALONE)
|
|
||||||
TraceLog(WARNING, "Sound loading from rRES resource file not supported on standalone mode");
|
|
||||||
#else
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
char id[4]; // rRES file identifier
|
|
||||||
unsigned char version; // rRES file version and subversion
|
|
||||||
char useless; // rRES header reserved data
|
|
||||||
short numRes;
|
|
||||||
|
|
||||||
ResInfoHeader infoHeader;
|
|
||||||
|
|
||||||
FILE *rresFile = fopen(rresName, "rb");
|
|
||||||
|
|
||||||
if (rresFile == NULL) TraceLog(WARNING, "[%s] rRES raylib resource file could not be opened", rresName);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Read rres file (basic file check - id)
|
|
||||||
fread(&id[0], sizeof(char), 1, rresFile);
|
|
||||||
fread(&id[1], sizeof(char), 1, rresFile);
|
|
||||||
fread(&id[2], sizeof(char), 1, rresFile);
|
|
||||||
fread(&id[3], sizeof(char), 1, rresFile);
|
|
||||||
fread(&version, sizeof(char), 1, rresFile);
|
|
||||||
fread(&useless, sizeof(char), 1, rresFile);
|
|
||||||
|
|
||||||
if ((id[0] != 'r') && (id[1] != 'R') && (id[2] != 'E') &&(id[3] != 'S'))
|
|
||||||
{
|
|
||||||
TraceLog(WARNING, "[%s] This is not a valid raylib resource file", rresName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Read number of resources embedded
|
|
||||||
fread(&numRes, sizeof(short), 1, rresFile);
|
|
||||||
|
|
||||||
for (int i = 0; i < numRes; i++)
|
|
||||||
{
|
|
||||||
fread(&infoHeader, sizeof(ResInfoHeader), 1, rresFile);
|
|
||||||
|
|
||||||
if (infoHeader.id == resId)
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
// Check data is of valid SOUND type
|
|
||||||
if (infoHeader.type == 1) // SOUND data type
|
|
||||||
{
|
|
||||||
// TODO: Check data compression type
|
|
||||||
// NOTE: We suppose compression type 2 (DEFLATE - default)
|
|
||||||
|
|
||||||
// Reading SOUND parameters
|
|
||||||
Wave wave;
|
|
||||||
short sampleRate, bps;
|
|
||||||
char channels, reserved;
|
|
||||||
|
|
||||||
fread(&sampleRate, sizeof(short), 1, rresFile); // Sample rate (frequency)
|
|
||||||
fread(&bps, sizeof(short), 1, rresFile); // Bits per sample
|
|
||||||
fread(&channels, 1, 1, rresFile); // Channels (1 - mono, 2 - stereo)
|
|
||||||
fread(&reserved, 1, 1, rresFile); // <reserved>
|
|
||||||
|
|
||||||
wave.sampleRate = sampleRate;
|
|
||||||
wave.sampleSize = bps;
|
|
||||||
wave.channels = (short)channels;
|
|
||||||
|
|
||||||
unsigned char *data = malloc(infoHeader.size);
|
|
||||||
|
|
||||||
fread(data, infoHeader.size, 1, rresFile);
|
|
||||||
|
|
||||||
wave.data = DecompressData(data, infoHeader.size, infoHeader.srcSize);
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
sound = LoadSoundFromWave(wave);
|
|
||||||
|
|
||||||
// Sound is loaded, we can unload wave data
|
|
||||||
UnloadWave(wave);
|
|
||||||
}
|
|
||||||
else TraceLog(WARNING, "[%s] Required resource do not seem to be a valid SOUND resource", rresName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Depending on type, skip the right amount of parameters
|
|
||||||
switch (infoHeader.type)
|
|
||||||
{
|
|
||||||
case 0: fseek(rresFile, 6, SEEK_CUR); break; // IMAGE: Jump 6 bytes of parameters
|
|
||||||
case 1: fseek(rresFile, 6, SEEK_CUR); break; // SOUND: Jump 6 bytes of parameters
|
|
||||||
case 2: fseek(rresFile, 5, SEEK_CUR); break; // MODEL: Jump 5 bytes of parameters (TODO: Review)
|
|
||||||
case 3: break; // TEXT: No parameters
|
|
||||||
case 4: break; // RAW: No parameters
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jump DATA to read next infoHeader
|
|
||||||
fseek(rresFile, infoHeader.size, SEEK_CUR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(rresFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) TraceLog(WARNING, "[%s] Required resource id [%i] could not be found in the raylib resource file", rresName, resId);
|
|
||||||
#endif
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unload Wave data
|
// Unload Wave data
|
||||||
void UnloadWave(Wave wave)
|
void UnloadWave(Wave wave)
|
||||||
{
|
{
|
||||||
|
|
@ -454,7 +342,7 @@ void UnloadSound(Sound sound)
|
||||||
|
|
||||||
// Update sound buffer with new data
|
// Update sound buffer with new data
|
||||||
// NOTE: data must match sound.format
|
// NOTE: data must match sound.format
|
||||||
void UpdateSound(Sound sound, void *data, int numSamples)
|
void UpdateSound(Sound sound, const void *data, int numSamples)
|
||||||
{
|
{
|
||||||
ALint sampleRate, sampleSize, channels;
|
ALint sampleRate, sampleSize, channels;
|
||||||
alGetBufferi(sound.buffer, AL_FREQUENCY, &sampleRate);
|
alGetBufferi(sound.buffer, AL_FREQUENCY, &sampleRate);
|
||||||
|
|
@ -604,7 +492,7 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
|
||||||
// Copy a wave to a new wave
|
// Copy a wave to a new wave
|
||||||
Wave WaveCopy(Wave wave)
|
Wave WaveCopy(Wave wave)
|
||||||
{
|
{
|
||||||
Wave newWave;
|
Wave newWave = { 0 };
|
||||||
|
|
||||||
if (wave.sampleSize == 8) newWave.data = (unsigned char *)malloc(wave.sampleCount*wave.channels*sizeof(unsigned char));
|
if (wave.sampleSize == 8) newWave.data = (unsigned char *)malloc(wave.sampleCount*wave.channels*sizeof(unsigned char));
|
||||||
else if (wave.sampleSize == 16) newWave.data = (short *)malloc(wave.sampleCount*wave.channels*sizeof(short));
|
else if (wave.sampleSize == 16) newWave.data = (short *)malloc(wave.sampleCount*wave.channels*sizeof(short));
|
||||||
|
|
@ -822,8 +710,8 @@ void UpdateMusicStream(Music music)
|
||||||
if (processed > 0)
|
if (processed > 0)
|
||||||
{
|
{
|
||||||
bool active = true;
|
bool active = true;
|
||||||
short pcm[AUDIO_BUFFER_SIZE];
|
short pcm[AUDIO_BUFFER_SIZE]; // TODO: Dynamic allocation (uses more than 16KB of stack)
|
||||||
float pcmf[AUDIO_BUFFER_SIZE];
|
float pcmf[AUDIO_BUFFER_SIZE]; // TODO: Dynamic allocation (uses more than 16KB of stack)
|
||||||
int numBuffersToProcess = processed;
|
int numBuffersToProcess = processed;
|
||||||
|
|
||||||
int numSamples = 0; // Total size of data steamed in L+R samples for xm floats,
|
int numSamples = 0; // Total size of data steamed in L+R samples for xm floats,
|
||||||
|
|
@ -952,7 +840,7 @@ float GetMusicTimePlayed(Music music)
|
||||||
float secondsPlayed = 0.0f;
|
float secondsPlayed = 0.0f;
|
||||||
|
|
||||||
unsigned int samplesPlayed = music->totalSamples - music->samplesLeft;
|
unsigned int samplesPlayed = music->totalSamples - music->samplesLeft;
|
||||||
secondsPlayed = (float)samplesPlayed/(music->stream.sampleRate*music->stream.channels);
|
secondsPlayed = (float)(samplesPlayed/(music->stream.sampleRate*music->stream.channels));
|
||||||
|
|
||||||
return secondsPlayed;
|
return secondsPlayed;
|
||||||
}
|
}
|
||||||
|
|
@ -1004,17 +892,17 @@ AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, un
|
||||||
{
|
{
|
||||||
if (stream.sampleSize == 8)
|
if (stream.sampleSize == 8)
|
||||||
{
|
{
|
||||||
unsigned char pcm[AUDIO_BUFFER_SIZE] = { 0 };
|
unsigned char pcm[AUDIO_BUFFER_SIZE] = { 0 }; // TODO: Dynamic allocation (uses more than 16KB of stack)
|
||||||
alBufferData(stream.buffers[i], stream.format, pcm, AUDIO_BUFFER_SIZE*sizeof(unsigned char), stream.sampleRate);
|
alBufferData(stream.buffers[i], stream.format, pcm, AUDIO_BUFFER_SIZE*sizeof(unsigned char), stream.sampleRate);
|
||||||
}
|
}
|
||||||
else if (stream.sampleSize == 16)
|
else if (stream.sampleSize == 16)
|
||||||
{
|
{
|
||||||
short pcm[AUDIO_BUFFER_SIZE] = { 0 };
|
short pcm[AUDIO_BUFFER_SIZE] = { 0 }; // TODO: Dynamic allocation (uses more than 16KB of stack)
|
||||||
alBufferData(stream.buffers[i], stream.format, pcm, AUDIO_BUFFER_SIZE*sizeof(short), stream.sampleRate);
|
alBufferData(stream.buffers[i], stream.format, pcm, AUDIO_BUFFER_SIZE*sizeof(short), stream.sampleRate);
|
||||||
}
|
}
|
||||||
else if (stream.sampleSize == 32)
|
else if (stream.sampleSize == 32)
|
||||||
{
|
{
|
||||||
float pcm[AUDIO_BUFFER_SIZE] = { 0.0f };
|
float pcm[AUDIO_BUFFER_SIZE] = { 0.0f }; // TODO: Dynamic allocation (uses more than 16KB of stack)
|
||||||
alBufferData(stream.buffers[i], stream.format, pcm, AUDIO_BUFFER_SIZE*sizeof(float), stream.sampleRate);
|
alBufferData(stream.buffers[i], stream.format, pcm, AUDIO_BUFFER_SIZE*sizeof(float), stream.sampleRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1195,11 +1083,13 @@ static Wave LoadWAV(const char *fileName)
|
||||||
// Read in the sound data into the soundData variable
|
// Read in the sound data into the soundData variable
|
||||||
fread(wave.data, waveData.subChunkSize, 1, wavFile);
|
fread(wave.data, waveData.subChunkSize, 1, wavFile);
|
||||||
|
|
||||||
// Now we set the variables that we need later
|
// Store wave parameters
|
||||||
wave.sampleCount = waveData.subChunkSize;
|
|
||||||
wave.sampleRate = waveFormat.sampleRate;
|
wave.sampleRate = waveFormat.sampleRate;
|
||||||
wave.sampleSize = waveFormat.bitsPerSample;
|
wave.sampleSize = waveFormat.bitsPerSample;
|
||||||
wave.channels = waveFormat.numChannels;
|
wave.channels = waveFormat.numChannels;
|
||||||
|
|
||||||
|
// NOTE: subChunkSize comes in bytes, we need to translate it to number of samples
|
||||||
|
wave.sampleCount = waveData.subChunkSize/(waveFormat.bitsPerSample/8);
|
||||||
|
|
||||||
TraceLog(INFO, "[%s] WAV file loaded successfully (SampleRate: %i, SampleSize: %i, Channels: %i)", fileName, wave.sampleRate, wave.sampleSize, wave.channels);
|
TraceLog(INFO, "[%s] WAV file loaded successfully (SampleRate: %i, SampleSize: %i, Channels: %i)", fileName, wave.sampleRate, wave.sampleSize, wave.channels);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ Wave LoadWaveEx(float *data, int sampleCount, int sampleRate, int sampleSize, in
|
||||||
Sound LoadSound(const char *fileName); // Load sound to memory
|
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, const void *data, int numSamples); // Update sound buffer with new data
|
||||||
void UnloadWave(Wave wave); // Unload wave 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
|
||||||
|
|
|
||||||
70
src/camera.h
70
src/camera.h
|
|
@ -223,15 +223,15 @@ void SetCameraMode(Camera camera, int mode)
|
||||||
float dy = v2.y - v1.y;
|
float dy = v2.y - v1.y;
|
||||||
float dz = v2.z - v1.z;
|
float dz = v2.z - v1.z;
|
||||||
|
|
||||||
cameraTargetDistance = sqrt(dx*dx + dy*dy + dz*dz);
|
cameraTargetDistance = sqrtf(dx*dx + dy*dy + dz*dz);
|
||||||
|
|
||||||
Vector2 distance = { 0.0f, 0.0f };
|
Vector2 distance = { 0.0f, 0.0f };
|
||||||
distance.x = sqrt(dx*dx + dz*dz);
|
distance.x = sqrtf(dx*dx + dz*dz);
|
||||||
distance.y = sqrt(dx*dx + dy*dy);
|
distance.y = sqrtf(dx*dx + dy*dy);
|
||||||
|
|
||||||
// Camera angle calculation
|
// Camera angle calculation
|
||||||
cameraAngle.x = asin(fabs(dx)/distance.x); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
cameraAngle.x = asinf(fabsf(dx)/distance.x); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
||||||
cameraAngle.y = -asin(fabs(dy)/distance.y); // Camera angle in plane XY (0 aligned with X, move positive CW)
|
cameraAngle.y = -asinf(fabsf(dy)/distance.y); // Camera angle in plane XY (0 aligned with X, move positive CW)
|
||||||
|
|
||||||
// NOTE: Just testing what cameraAngle means
|
// NOTE: Just testing what cameraAngle means
|
||||||
//cameraAngle.x = 0.0f*DEG2RAD; // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
//cameraAngle.x = 0.0f*DEG2RAD; // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
||||||
|
|
@ -285,10 +285,10 @@ void UpdateCamera(Camera *camera)
|
||||||
{
|
{
|
||||||
HideCursor();
|
HideCursor();
|
||||||
|
|
||||||
if (mousePosition.x < screenHeight/3) SetMousePosition((Vector2){ screenWidth - screenHeight/3, mousePosition.y });
|
if (mousePosition.x < (float)screenHeight/3.0f) SetMousePosition((Vector2){ screenWidth - screenHeight/3, mousePosition.y });
|
||||||
else if (mousePosition.y < screenHeight/3) SetMousePosition((Vector2){ mousePosition.x, screenHeight - screenHeight/3 });
|
else if (mousePosition.y < (float)screenHeight/3.0f) SetMousePosition((Vector2){ mousePosition.x, screenHeight - screenHeight/3 });
|
||||||
else if (mousePosition.x > (screenWidth - screenHeight/3)) SetMousePosition((Vector2){ screenHeight/3, mousePosition.y });
|
else if (mousePosition.x > (screenWidth - (float)screenHeight/3.0f)) SetMousePosition((Vector2){ screenHeight/3, mousePosition.y });
|
||||||
else if (mousePosition.y > (screenHeight - screenHeight/3)) SetMousePosition((Vector2){ mousePosition.x, screenHeight/3 });
|
else if (mousePosition.y > (screenHeight - (float)screenHeight/3.0f)) SetMousePosition((Vector2){ mousePosition.x, screenHeight/3 });
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
|
mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
|
||||||
|
|
@ -321,6 +321,7 @@ void UpdateCamera(Camera *camera)
|
||||||
if (cameraTargetDistance > CAMERA_FREE_DISTANCE_MAX_CLAMP) cameraTargetDistance = CAMERA_FREE_DISTANCE_MAX_CLAMP;
|
if (cameraTargetDistance > CAMERA_FREE_DISTANCE_MAX_CLAMP) cameraTargetDistance = CAMERA_FREE_DISTANCE_MAX_CLAMP;
|
||||||
}
|
}
|
||||||
// Camera looking down
|
// Camera looking down
|
||||||
|
// TODO: Review, weird comparisson of cameraTargetDistance == 120.0f?
|
||||||
else if ((camera->position.y > camera->target.y) && (cameraTargetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
|
else if ((camera->position.y > camera->target.y) && (cameraTargetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
|
||||||
{
|
{
|
||||||
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/cameraTargetDistance;
|
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/cameraTargetDistance;
|
||||||
|
|
@ -341,6 +342,7 @@ void UpdateCamera(Camera *camera)
|
||||||
if (cameraTargetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) cameraTargetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP;
|
if (cameraTargetDistance < CAMERA_FREE_DISTANCE_MIN_CLAMP) cameraTargetDistance = CAMERA_FREE_DISTANCE_MIN_CLAMP;
|
||||||
}
|
}
|
||||||
// Camera looking up
|
// Camera looking up
|
||||||
|
// TODO: Review, weird comparisson of cameraTargetDistance == 120.0f?
|
||||||
else if ((camera->position.y < camera->target.y) && (cameraTargetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
|
else if ((camera->position.y < camera->target.y) && (cameraTargetDistance == CAMERA_FREE_DISTANCE_MAX_CLAMP) && (mouseWheelMove < 0))
|
||||||
{
|
{
|
||||||
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/cameraTargetDistance;
|
camera->target.x += mouseWheelMove*(camera->target.x - camera->position.x)*CAMERA_MOUSE_SCROLL_SENSITIVITY/cameraTargetDistance;
|
||||||
|
|
@ -385,9 +387,9 @@ void UpdateCamera(Camera *camera)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Camera panning
|
// Camera panning
|
||||||
camera->target.x += ((mousePositionDelta.x*-CAMERA_FREE_MOUSE_SENSITIVITY)*cos(cameraAngle.x) + (mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*sin(cameraAngle.x)*sin(cameraAngle.y))*(cameraTargetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
camera->target.x += ((mousePositionDelta.x*-CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(cameraAngle.x) + (mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*sinf(cameraAngle.x)*sinf(cameraAngle.y))*(cameraTargetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
||||||
camera->target.y += ((mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cos(cameraAngle.y))*(cameraTargetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
camera->target.y += ((mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(cameraAngle.y))*(cameraTargetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
||||||
camera->target.z += ((mousePositionDelta.x*CAMERA_FREE_MOUSE_SENSITIVITY)*sin(cameraAngle.x) + (mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cos(cameraAngle.x)*sin(cameraAngle.y))*(cameraTargetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
camera->target.z += ((mousePositionDelta.x*CAMERA_FREE_MOUSE_SENSITIVITY)*sinf(cameraAngle.x) + (mousePositionDelta.y*CAMERA_FREE_MOUSE_SENSITIVITY)*cosf(cameraAngle.x)*sinf(cameraAngle.y))*(cameraTargetDistance/CAMERA_FREE_PANNING_DIVIDER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -404,19 +406,19 @@ void UpdateCamera(Camera *camera)
|
||||||
case CAMERA_FIRST_PERSON:
|
case CAMERA_FIRST_PERSON:
|
||||||
case CAMERA_THIRD_PERSON:
|
case CAMERA_THIRD_PERSON:
|
||||||
{
|
{
|
||||||
camera->position.x += (sin(cameraAngle.x)*direction[MOVE_BACK] -
|
camera->position.x += (sinf(cameraAngle.x)*direction[MOVE_BACK] -
|
||||||
sin(cameraAngle.x)*direction[MOVE_FRONT] -
|
sinf(cameraAngle.x)*direction[MOVE_FRONT] -
|
||||||
cos(cameraAngle.x)*direction[MOVE_LEFT] +
|
cosf(cameraAngle.x)*direction[MOVE_LEFT] +
|
||||||
cos(cameraAngle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
cosf(cameraAngle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
camera->position.y += (sin(cameraAngle.y)*direction[MOVE_FRONT] -
|
camera->position.y += (sinf(cameraAngle.y)*direction[MOVE_FRONT] -
|
||||||
sin(cameraAngle.y)*direction[MOVE_BACK] +
|
sinf(cameraAngle.y)*direction[MOVE_BACK] +
|
||||||
1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])/PLAYER_MOVEMENT_SENSITIVITY;
|
1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
camera->position.z += (cos(cameraAngle.x)*direction[MOVE_BACK] -
|
camera->position.z += (cosf(cameraAngle.x)*direction[MOVE_BACK] -
|
||||||
cos(cameraAngle.x)*direction[MOVE_FRONT] +
|
cosf(cameraAngle.x)*direction[MOVE_FRONT] +
|
||||||
sin(cameraAngle.x)*direction[MOVE_LEFT] -
|
sinf(cameraAngle.x)*direction[MOVE_LEFT] -
|
||||||
sin(cameraAngle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
sinf(cameraAngle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||||
|
|
||||||
bool isMoving = false; // Required for swinging
|
bool isMoving = false; // Required for swinging
|
||||||
|
|
||||||
|
|
@ -439,9 +441,9 @@ void UpdateCamera(Camera *camera)
|
||||||
if (cameraTargetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) cameraTargetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP;
|
if (cameraTargetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) cameraTargetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP;
|
||||||
|
|
||||||
// Camera is always looking at player
|
// Camera is always looking at player
|
||||||
camera->target.x = camera->position.x + CAMERA_THIRD_PERSON_OFFSET.x*cos(cameraAngle.x) + CAMERA_THIRD_PERSON_OFFSET.z*sin(cameraAngle.x);
|
camera->target.x = camera->position.x + CAMERA_THIRD_PERSON_OFFSET.x*cosf(cameraAngle.x) + CAMERA_THIRD_PERSON_OFFSET.z*sinf(cameraAngle.x);
|
||||||
camera->target.y = camera->position.y + CAMERA_THIRD_PERSON_OFFSET.y;
|
camera->target.y = camera->position.y + CAMERA_THIRD_PERSON_OFFSET.y;
|
||||||
camera->target.z = camera->position.z + CAMERA_THIRD_PERSON_OFFSET.z*sin(cameraAngle.x) - CAMERA_THIRD_PERSON_OFFSET.x*sin(cameraAngle.x);
|
camera->target.z = camera->position.z + CAMERA_THIRD_PERSON_OFFSET.z*sinf(cameraAngle.x) - CAMERA_THIRD_PERSON_OFFSET.x*sinf(cameraAngle.x);
|
||||||
}
|
}
|
||||||
else // CAMERA_FIRST_PERSON
|
else // CAMERA_FIRST_PERSON
|
||||||
{
|
{
|
||||||
|
|
@ -450,18 +452,18 @@ void UpdateCamera(Camera *camera)
|
||||||
else if (cameraAngle.y < CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD) cameraAngle.y = CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD;
|
else if (cameraAngle.y < CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD) cameraAngle.y = CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD;
|
||||||
|
|
||||||
// Camera is always looking at player
|
// Camera is always looking at player
|
||||||
camera->target.x = camera->position.x - sin(cameraAngle.x)*CAMERA_FIRST_PERSON_FOCUS_DISTANCE;
|
camera->target.x = camera->position.x - sinf(cameraAngle.x)*CAMERA_FIRST_PERSON_FOCUS_DISTANCE;
|
||||||
camera->target.y = camera->position.y + sin(cameraAngle.y)*CAMERA_FIRST_PERSON_FOCUS_DISTANCE;
|
camera->target.y = camera->position.y + sinf(cameraAngle.y)*CAMERA_FIRST_PERSON_FOCUS_DISTANCE;
|
||||||
camera->target.z = camera->position.z - cos(cameraAngle.x)*CAMERA_FIRST_PERSON_FOCUS_DISTANCE;
|
camera->target.z = camera->position.z - cosf(cameraAngle.x)*CAMERA_FIRST_PERSON_FOCUS_DISTANCE;
|
||||||
|
|
||||||
if (isMoving) swingCounter++;
|
if (isMoving) swingCounter++;
|
||||||
|
|
||||||
// Camera position update
|
// Camera position update
|
||||||
// NOTE: On CAMERA_FIRST_PERSON player Y-movement is limited to player 'eyes position'
|
// NOTE: On CAMERA_FIRST_PERSON player Y-movement is limited to player 'eyes position'
|
||||||
camera->position.y = playerEyesPosition - sin(swingCounter/CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER)/CAMERA_FIRST_PERSON_STEP_DIVIDER;
|
camera->position.y = playerEyesPosition - sinf(swingCounter/CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER)/CAMERA_FIRST_PERSON_STEP_DIVIDER;
|
||||||
|
|
||||||
camera->up.x = sin(swingCounter/(CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER*2))/CAMERA_FIRST_PERSON_WAVING_DIVIDER;
|
camera->up.x = sinf(swingCounter/(CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER*2))/CAMERA_FIRST_PERSON_WAVING_DIVIDER;
|
||||||
camera->up.z = -sin(swingCounter/(CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER*2))/CAMERA_FIRST_PERSON_WAVING_DIVIDER;
|
camera->up.z = -sinf(swingCounter/(CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER*2))/CAMERA_FIRST_PERSON_WAVING_DIVIDER;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
|
|
@ -473,10 +475,10 @@ void UpdateCamera(Camera *camera)
|
||||||
(cameraMode == CAMERA_THIRD_PERSON))
|
(cameraMode == CAMERA_THIRD_PERSON))
|
||||||
{
|
{
|
||||||
// TODO: It seems camera->position is not correctly updated or some rounding issue makes the camera move straight to camera->target...
|
// TODO: It seems camera->position is not correctly updated or some rounding issue makes the camera move straight to camera->target...
|
||||||
camera->position.x = sin(cameraAngle.x)*cameraTargetDistance*cos(cameraAngle.y) + camera->target.x;
|
camera->position.x = sinf(cameraAngle.x)*cameraTargetDistance*cosf(cameraAngle.y) + camera->target.x;
|
||||||
if (cameraAngle.y <= 0.0f) camera->position.y = sin(cameraAngle.y)*cameraTargetDistance*sin(cameraAngle.y) + camera->target.y;
|
if (cameraAngle.y <= 0.0f) camera->position.y = sinf(cameraAngle.y)*cameraTargetDistance*sinf(cameraAngle.y) + camera->target.y;
|
||||||
else camera->position.y = -sin(cameraAngle.y)*cameraTargetDistance*sin(cameraAngle.y) + camera->target.y;
|
else camera->position.y = -sinf(cameraAngle.y)*cameraTargetDistance*sinf(cameraAngle.y) + camera->target.y;
|
||||||
camera->position.z = cos(cameraAngle.x)*cameraTargetDistance*cos(cameraAngle.y) + camera->target.z;
|
camera->position.z = cosf(cameraAngle.x)*cameraTargetDistance*cosf(cameraAngle.y) + camera->target.z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
47
src/core.c
47
src/core.c
|
|
@ -42,13 +42,14 @@
|
||||||
*
|
*
|
||||||
**********************************************************************************************/
|
**********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h" // raylib main header
|
#include "raylib.h"
|
||||||
|
|
||||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||||
#include "utils.h" // Includes Android fopen map, InitAssetManager(), TraceLog()
|
#include "utils.h" // Required for: fopen() Android mapping, TraceLog()
|
||||||
|
|
||||||
#define RAYMATH_IMPLEMENTATION // Use raymath as a header-only library (includes implementation)
|
#define RAYMATH_IMPLEMENTATION // Use raymath as a header-only library (includes implementation)
|
||||||
#define RAYMATH_EXTERN_INLINE // Compile raymath functions as static inline (remember, it's a compiler hint)
|
#define RAYMATH_EXTERN_INLINE // Compile raymath functions as static inline (remember, it's a compiler hint)
|
||||||
#include "raymath.h" // Required for Vector3 and Matrix functions
|
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
||||||
|
|
||||||
#define GESTURES_IMPLEMENTATION
|
#define GESTURES_IMPLEMENTATION
|
||||||
#include "gestures.h" // Gestures detection functionality
|
#include "gestures.h" // Gestures detection functionality
|
||||||
|
|
@ -264,6 +265,7 @@ static void SwapBuffers(void); // Copy back buffer to f
|
||||||
static void LogoAnimation(void); // Plays raylib logo appearing animation
|
static void LogoAnimation(void); // Plays raylib logo appearing animation
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
static void TakeScreenshot(void); // Takes a screenshot and saves it in the same folder as executable
|
static void TakeScreenshot(void); // Takes a screenshot and saves it in the same folder as executable
|
||||||
|
static void SetupViewport(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
|
|
@ -744,8 +746,7 @@ void EndTextureMode(void)
|
||||||
rlDisableRenderTexture(); // Disable render target
|
rlDisableRenderTexture(); // Disable render target
|
||||||
|
|
||||||
// Set viewport to default framebuffer size (screen size)
|
// Set viewport to default framebuffer size (screen size)
|
||||||
// TODO: consider possible viewport offsets
|
SetupViewport();
|
||||||
rlViewport(0, 0, GetScreenWidth(), GetScreenHeight());
|
|
||||||
|
|
||||||
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
|
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
|
||||||
rlLoadIdentity(); // Reset current matrix (PROJECTION)
|
rlLoadIdentity(); // Reset current matrix (PROJECTION)
|
||||||
|
|
@ -779,7 +780,7 @@ float GetFrameTime(void)
|
||||||
// As we are operate quite a lot with frameTime,
|
// As we are operate quite a lot with frameTime,
|
||||||
// it could be no stable, so we round it before passing it around
|
// it could be no stable, so we round it before passing it around
|
||||||
// NOTE: There are still problems with high framerates (>500fps)
|
// NOTE: There are still problems with high framerates (>500fps)
|
||||||
double roundedFrameTime = round(frameTime*10000)/10000.0;
|
double roundedFrameTime = round(frameTime*10000)/10000.0;
|
||||||
|
|
||||||
return (float)roundedFrameTime; // Time in seconds to run a frame
|
return (float)roundedFrameTime; // Time in seconds to run a frame
|
||||||
}
|
}
|
||||||
|
|
@ -1089,7 +1090,7 @@ Vector2 GetWorldToScreen(Vector3 position, Camera camera)
|
||||||
QuaternionTransform(&worldPos, matProj);
|
QuaternionTransform(&worldPos, matProj);
|
||||||
|
|
||||||
// Calculate normalized device coordinates (inverted y)
|
// Calculate normalized device coordinates (inverted y)
|
||||||
Vector3 ndcPos = { worldPos.x/worldPos.w, -worldPos.y/worldPos.w, worldPos.z/worldPos.z };
|
Vector3 ndcPos = { worldPos.x/worldPos.w, -worldPos.y/worldPos.w, worldPos.z/worldPos.w };
|
||||||
|
|
||||||
// Calculate 2d screen position vector
|
// Calculate 2d screen position vector
|
||||||
Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() };
|
Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() };
|
||||||
|
|
@ -1776,19 +1777,8 @@ static void InitGraphicsDevice(int width, int height)
|
||||||
// NOTE: screenWidth and screenHeight not used, just stored as globals
|
// NOTE: screenWidth and screenHeight not used, just stored as globals
|
||||||
rlglInit(screenWidth, screenHeight);
|
rlglInit(screenWidth, screenHeight);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
// Setup default viewport
|
||||||
// Get framebuffer size of current window
|
SetupViewport();
|
||||||
// NOTE: Required to handle HighDPI display correctly on OSX because framebuffer
|
|
||||||
// is automatically reasized to adapt to new DPI.
|
|
||||||
// When OS does that, it can be detected using GLFW3 callback: glfwSetFramebufferSizeCallback()
|
|
||||||
int fbWidth, fbHeight;
|
|
||||||
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
|
|
||||||
rlViewport(renderOffsetX/2, renderOffsetY/2, fbWidth - renderOffsetX, fbHeight - renderOffsetY);
|
|
||||||
#else
|
|
||||||
// Initialize screen viewport (area of the screen that you will actually draw to)
|
|
||||||
// NOTE: Viewport must be recalculated if screen is resized
|
|
||||||
rlViewport(renderOffsetX/2, renderOffsetY/2, renderWidth - renderOffsetX, renderHeight - renderOffsetY);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize internal projection and modelview matrices
|
// Initialize internal projection and modelview matrices
|
||||||
// NOTE: Default to orthographic projection mode with top-left corner at (0,0)
|
// NOTE: Default to orthographic projection mode with top-left corner at (0,0)
|
||||||
|
|
@ -1805,6 +1795,23 @@ static void InitGraphicsDevice(int width, int height)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SetupViewport(void)
|
||||||
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Get framebuffer size of current window
|
||||||
|
// NOTE: Required to handle HighDPI display correctly on OSX because framebuffer
|
||||||
|
// is automatically reasized to adapt to new DPI.
|
||||||
|
// When OS does that, it can be detected using GLFW3 callback: glfwSetFramebufferSizeCallback()
|
||||||
|
int fbWidth, fbHeight;
|
||||||
|
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
|
||||||
|
rlViewport(renderOffsetX/2, renderOffsetY/2, fbWidth - renderOffsetX, fbHeight - renderOffsetY);
|
||||||
|
#else
|
||||||
|
// Initialize screen viewport (area of the screen that you will actually draw to)
|
||||||
|
// NOTE: Viewport must be recalculated if screen is resized
|
||||||
|
rlViewport(renderOffsetX/2, renderOffsetY/2, renderWidth - renderOffsetX, renderHeight - renderOffsetY);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Compute framebuffer size relative to screen size and display size
|
// Compute framebuffer size relative to screen size and display size
|
||||||
// NOTE: Global variables renderWidth/renderHeight and renderOffsetX/renderOffsetY can be modified
|
// NOTE: Global variables renderWidth/renderHeight and renderOffsetX/renderOffsetY can be modified
|
||||||
static void SetupFramebufferSize(int displayWidth, int displayHeight)
|
static void SetupFramebufferSize(int displayWidth, int displayHeight)
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ static int tapCounter = 0; // TAP counter (one tap implies
|
||||||
|
|
||||||
// Hold gesture variables
|
// Hold gesture variables
|
||||||
static bool resetHold = false; // HOLD reset to get first touch point again
|
static bool resetHold = false; // HOLD reset to get first touch point again
|
||||||
static float timeHold = 0.0f; // HOLD duration in milliseconds
|
static double timeHold = 0.0f; // HOLD duration in milliseconds
|
||||||
|
|
||||||
// Drag gesture variables
|
// Drag gesture variables
|
||||||
static Vector2 dragVector = { 0.0f , 0.0f }; // DRAG vector (between initial and current position)
|
static Vector2 dragVector = { 0.0f , 0.0f }; // DRAG vector (between initial and current position)
|
||||||
|
|
@ -423,11 +423,11 @@ float GetGestureHoldDuration(void)
|
||||||
{
|
{
|
||||||
// NOTE: time is calculated on current gesture HOLD
|
// NOTE: time is calculated on current gesture HOLD
|
||||||
|
|
||||||
float time = 0.0f;
|
double time = 0.0;
|
||||||
|
|
||||||
if (currentGesture == GESTURE_HOLD) time = (float)GetCurrentTime() - timeHold;
|
if (currentGesture == GESTURE_HOLD) time = GetCurrentTime() - timeHold;
|
||||||
|
|
||||||
return time;
|
return (float)time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get drag vector (between initial touch point to current)
|
// Get drag vector (between initial touch point to current)
|
||||||
|
|
@ -474,7 +474,7 @@ static float Vector2Angle(Vector2 initialPosition, Vector2 finalPosition)
|
||||||
{
|
{
|
||||||
float angle;
|
float angle;
|
||||||
|
|
||||||
angle = atan2(finalPosition.y - initialPosition.y, finalPosition.x - initialPosition.x)*(180.0f/PI);
|
angle = atan2f(finalPosition.y - initialPosition.y, finalPosition.x - initialPosition.x)*(180.0f/PI);
|
||||||
|
|
||||||
if (angle < 0) angle += 360.0f;
|
if (angle < 0) angle += 360.0f;
|
||||||
|
|
||||||
|
|
@ -489,7 +489,7 @@ static float Vector2Distance(Vector2 v1, Vector2 v2)
|
||||||
float dx = v2.x - v1.x;
|
float dx = v2.x - v1.x;
|
||||||
float dy = v2.y - v1.y;
|
float dy = v2.y - v1.y;
|
||||||
|
|
||||||
result = sqrt(dx*dx + dy*dy);
|
result = (float)sqrt(dx*dx + dy*dy);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
87
src/models.c
87
src/models.c
|
|
@ -648,89 +648,6 @@ Model LoadModelEx(Mesh data, bool dynamic)
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a 3d model from rRES file (raylib Resource)
|
|
||||||
Model LoadModelFromRES(const char *rresName, int resId)
|
|
||||||
{
|
|
||||||
Model model = { 0 };
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
char id[4]; // rRES file identifier
|
|
||||||
unsigned char version; // rRES file version and subversion
|
|
||||||
char useless; // rRES header reserved data
|
|
||||||
short numRes;
|
|
||||||
|
|
||||||
ResInfoHeader infoHeader;
|
|
||||||
|
|
||||||
FILE *rresFile = fopen(rresName, "rb");
|
|
||||||
|
|
||||||
if (rresFile == NULL)
|
|
||||||
{
|
|
||||||
TraceLog(WARNING, "[%s] rRES raylib resource file could not be opened", rresName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Read rres file (basic file check - id)
|
|
||||||
fread(&id[0], sizeof(char), 1, rresFile);
|
|
||||||
fread(&id[1], sizeof(char), 1, rresFile);
|
|
||||||
fread(&id[2], sizeof(char), 1, rresFile);
|
|
||||||
fread(&id[3], sizeof(char), 1, rresFile);
|
|
||||||
fread(&version, sizeof(char), 1, rresFile);
|
|
||||||
fread(&useless, sizeof(char), 1, rresFile);
|
|
||||||
|
|
||||||
if ((id[0] != 'r') && (id[1] != 'R') && (id[2] != 'E') &&(id[3] != 'S'))
|
|
||||||
{
|
|
||||||
TraceLog(WARNING, "[%s] This is not a valid raylib resource file", rresName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Read number of resources embedded
|
|
||||||
fread(&numRes, sizeof(short), 1, rresFile);
|
|
||||||
|
|
||||||
for (int i = 0; i < numRes; i++)
|
|
||||||
{
|
|
||||||
fread(&infoHeader, sizeof(ResInfoHeader), 1, rresFile);
|
|
||||||
|
|
||||||
if (infoHeader.id == resId)
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
// Check data is of valid MODEL type
|
|
||||||
if (infoHeader.type == 8)
|
|
||||||
{
|
|
||||||
// TODO: Load model data
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TraceLog(WARNING, "[%s] Required resource do not seem to be a valid MODEL resource", rresName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Depending on type, skip the right amount of parameters
|
|
||||||
switch (infoHeader.type)
|
|
||||||
{
|
|
||||||
case 0: fseek(rresFile, 6, SEEK_CUR); break; // IMAGE: Jump 6 bytes of parameters
|
|
||||||
case 1: fseek(rresFile, 6, SEEK_CUR); break; // SOUND: Jump 6 bytes of parameters
|
|
||||||
case 2: fseek(rresFile, 5, SEEK_CUR); break; // MODEL: Jump 5 bytes of parameters (TODO: Review)
|
|
||||||
case 3: break; // TEXT: No parameters
|
|
||||||
case 4: break; // RAW: No parameters
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jump DATA to read next infoHeader
|
|
||||||
fseek(rresFile, infoHeader.size, SEEK_CUR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(rresFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) TraceLog(WARNING, "[%s] Required resource id [%i] could not be found in the raylib resource file", rresName, resId);
|
|
||||||
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load a heightmap image as a 3d model
|
// Load a heightmap image as a 3d model
|
||||||
// NOTE: model map size is defined in generic units
|
// NOTE: model map size is defined in generic units
|
||||||
Model LoadHeightmap(Image heightmap, Vector3 size)
|
Model LoadHeightmap(Image heightmap, Vector3 size)
|
||||||
|
|
@ -1517,8 +1434,8 @@ bool CheckCollisionRayBox(Ray ray, BoundingBox box)
|
||||||
t[3] = (box.max.y - ray.position.y)/ray.direction.y;
|
t[3] = (box.max.y - ray.position.y)/ray.direction.y;
|
||||||
t[4] = (box.min.z - ray.position.z)/ray.direction.z;
|
t[4] = (box.min.z - ray.position.z)/ray.direction.z;
|
||||||
t[5] = (box.max.z - ray.position.z)/ray.direction.z;
|
t[5] = (box.max.z - ray.position.z)/ray.direction.z;
|
||||||
t[6] = fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5]));
|
t[6] = (float)fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5]));
|
||||||
t[7] = fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5]));
|
t[7] = (float)fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5]));
|
||||||
|
|
||||||
collision = !(t[7] < 0 || t[6] > t[7]);
|
collision = !(t[7] < 0 || t[6] > t[7]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -239,9 +239,10 @@ PHYSACDEF void ClosePhysics(void);
|
||||||
// Functions required to query time on Windows
|
// Functions required to query time on Windows
|
||||||
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
||||||
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
||||||
#elif defined(__linux)
|
#elif defined(__linux) || defined(PLATFORM_WEB)
|
||||||
#include <sys/time.h> // Required for: timespec
|
#include <sys/time.h> // Required for: timespec
|
||||||
#include <time.h> // Required for: clock_gettime()
|
#include <time.h> // Required for: clock_gettime()
|
||||||
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -266,7 +267,7 @@ PHYSACDEF void ClosePhysics(void);
|
||||||
static unsigned int usedMemory = 0; // Total allocated dynamic memory
|
static unsigned int usedMemory = 0; // Total allocated dynamic memory
|
||||||
static bool physicsThreadEnabled = false; // Physics thread enabled state
|
static bool physicsThreadEnabled = false; // Physics thread enabled state
|
||||||
static double currentTime = 0; // Current time in milliseconds
|
static double currentTime = 0; // Current time in milliseconds
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux) || defined(PLATFORM_WEB)
|
||||||
static double baseTime = 0; // Android and RPI platforms base time
|
static double baseTime = 0; // Android and RPI platforms base time
|
||||||
#endif
|
#endif
|
||||||
static double startTime = 0; // Start time in milliseconds
|
static double startTime = 0; // Start time in milliseconds
|
||||||
|
|
@ -1942,7 +1943,7 @@ static double GetCurrentTime(void)
|
||||||
{
|
{
|
||||||
double time = 0;
|
double time = 0;
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(_WIN32)
|
||||||
unsigned long long int clockFrequency, currentTime;
|
unsigned long long int clockFrequency, currentTime;
|
||||||
|
|
||||||
QueryPerformanceFrequency(&clockFrequency);
|
QueryPerformanceFrequency(&clockFrequency);
|
||||||
|
|
@ -1951,7 +1952,7 @@ static double GetCurrentTime(void)
|
||||||
time = (double)((double)currentTime/clockFrequency)*1000;
|
time = (double)((double)currentTime/clockFrequency)*1000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux) || defined(PLATFORM_WEB)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
uint64_t temp = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
uint64_t temp = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue