Merge branch 'raysan5:master' into master

This commit is contained in:
Luiz Pestana 2022-06-09 10:31:51 -03:00 • committed by GitHub
commit b701ad2a94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 1576 additions and 3926 deletions

View file

@ -82,8 +82,11 @@ RAYLIB_MODULE_MODELS ?= TRUE
RAYLIB_MODULE_RAYGUI ?= FALSE
RAYLIB_MODULE_PHYSAC ?= FALSE
RAYLIB_MODULE_RAYGUI_PATH ?= $(RAYLIB_SRC_PATH)/extras
RAYLIB_MODULE_PHYSAC_PATH ?= $(RAYLIB_SRC_PATH)/extras
# NOTE: Additional libraries have been moved to their own repos:
# raygui: https://github.com/raysan5/raygui
# physac: https://github.com/raysan5/physac
RAYLIB_MODULE_RAYGUI_PATH ?= $(RAYLIB_SRC_PATH)/../../raygui/src
RAYLIB_MODULE_PHYSAC_PATH ?= $(RAYLIB_SRC_PATH)/../../physac/src
# Use external GLFW library instead of rglfw module
USE_EXTERNAL_GLFW ?= FALSE

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/**********************************************************************************************
*
* raylib v4.1-dev - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
* raylib v4.2-dev - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
*
* FEATURES:
* - NO external dependencies, all required libraries included with raylib
@ -80,7 +80,7 @@
#include <stdarg.h> // Required for: va_list - Only used by TraceLogCallback
#define RAYLIB_VERSION "4.1-dev"
#define RAYLIB_VERSION "4.2-dev"
// Function specifiers in case library is build/used as a shared library (Windows)
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
@ -843,7 +843,7 @@ typedef enum {
BLEND_MULTIPLIED, // Blend textures multiplying colors
BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
BLEND_ALPHA_PREMUL, // Blend premultiplied textures considering alpha
BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha
BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendMode())
} BlendMode;
@ -958,7 +958,7 @@ RLAPI void DisableEventWaiting(void); // Disable wai
// To avoid that behaviour and control frame processes manually, enable in config.h: SUPPORT_CUSTOM_FRAME_CONTROL
RLAPI void SwapScreenBuffer(void); // Swap back buffer with front buffer (screen drawing)
RLAPI void PollInputEvents(void); // Register all input events
RLAPI void WaitTime(float ms); // Wait for some milliseconds (halt program execution)
RLAPI void WaitTime(double seconds); // Wait for some time (halt program execution)
// Cursor-related functions
RLAPI void ShowCursor(void); // Shows cursor
@ -1008,9 +1008,9 @@ RLAPI Ray GetMouseRay(Vector2 mousePosition, Camera camera); // Get a ray t
RLAPI Matrix GetCameraMatrix(Camera camera); // Get camera transform matrix (view matrix)
RLAPI Matrix GetCameraMatrix2D(Camera2D camera); // Get camera 2d transform matrix
RLAPI Vector2 GetWorldToScreen(Vector3 position, Camera camera); // Get the screen space position for a 3d world space position
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
RLAPI Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int height); // Get size position for a 3d world space position
RLAPI Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera); // Get the screen space position for a 2d camera world space position
RLAPI Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera); // Get the world space position for a 2d camera screen space position
// Timing-related functions
RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum)
@ -1057,12 +1057,12 @@ RLAPI const char *GetDirectoryPath(const char *filePath); // Get full pa
RLAPI const char *GetPrevDirectoryPath(const char *dirPath); // Get previous directory path for a given path (uses static string)
RLAPI const char *GetWorkingDirectory(void); // Get current working directory (uses static string)
RLAPI const char *GetApplicationDirectory(void); // Get the directory if the running application (uses static string)
RLAPI char **GetDirectoryFiles(const char *dirPath, int *count); // Get filenames in a directory path (memory must be freed)
RLAPI void ClearDirectoryFiles(void); // Clear directory files paths buffers (free memory)
RLAPI bool ChangeDirectory(const char *dir); // Change working directory, return true on success
RLAPI char **LoadDirectoryFiles(const char *dirPath, int *count); // Load directory filepaths
RLAPI void UnloadDirectoryFiles(void); // Unload directory filepaths
RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window
RLAPI char **GetDroppedFiles(int *count); // Get dropped files names (memory must be freed)
RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer (free memory)
RLAPI char **LoadDroppedFiles(int *count); // Load dropped filepaths
RLAPI void UnloadDroppedFiles(void); // Unload dropped filepaths
RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
// Compression/Encoding functionality

View file

@ -194,9 +194,9 @@
#define DIRENT_MALLOC RL_MALLOC
#define DIRENT_FREE RL_FREE
#include "external/dirent.h" // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()]
#include "external/dirent.h" // Required for: DIR, opendir(), closedir() [Used in LoadDirectoryFiles()]
#else
#include <dirent.h> // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()]
#include <dirent.h> // Required for: DIR, opendir(), closedir() [Used in LoadDirectoryFiles()]
#endif
#if defined(_WIN32)
@ -422,7 +422,7 @@ typedef struct CoreData {
Point renderOffset; // Offset from render area (must be divided by 2)
Matrix screenScale; // Matrix to scale screen (framebuffer rendering)
char **dropFilesPath; // Store dropped files paths as strings
char **dropFilepaths; // Store dropped files paths as strings
int dropFileCount; // Count dropped files strings
} Window;
@ -2087,8 +2087,8 @@ void EndDrawing(void)
// Get image data for the current frame (from backbuffer)
// NOTE: This process is quite slow... :(
Vector2 scale = GetWindowScaleDPI();
unsigned char *screenData = rlReadScreenPixels(CORE.Window.render.width*scale.x, CORE.Window.render.height*scale.y);
msf_gif_frame(&gifState, screenData, 10, 16, CORE.Window.render.width*scale.x*4);
unsigned char *screenData = rlReadScreenPixels((int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
msf_gif_frame(&gifState, screenData, 10, 16, (int)((float)CORE.Window.render.width*scale.x)*4);
RL_FREE(screenData); // Free image data
}
@ -2146,7 +2146,7 @@ void EndDrawing(void)
// Wait for some milliseconds...
if (CORE.Time.frame < CORE.Time.target)
{
WaitTime((float)(CORE.Time.target - CORE.Time.frame)*1000.0f);
WaitTime(CORE.Time.target - CORE.Time.frame);
CORE.Time.current = GetTime();
double waitTime = CORE.Time.current - CORE.Time.previous;
@ -2811,8 +2811,8 @@ void TakeScreenshot(const char *fileName)
{
#if defined(SUPPORT_MODULE_RTEXTURES)
Vector2 scale = GetWindowScaleDPI();
unsigned char *imgData = rlReadScreenPixels(CORE.Window.render.width*scale.x, CORE.Window.render.height*scale.y);
Image image = { imgData, CORE.Window.render.width*scale.x, CORE.Window.render.height*scale.y, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
unsigned char *imgData = rlReadScreenPixels((int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
Image image = { imgData, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y), 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
char path[2048] = { 0 };
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, fileName));
@ -3146,11 +3146,11 @@ const char *GetApplicationDirectory(void)
return appDir;
}
// Get filenames in a directory path
// Load directory filepaths
// NOTE: Files count is returned by parameters pointer
char **GetDirectoryFiles(const char *dirPath, int *fileCount)
char **LoadDirectoryFiles(const char *dirPath, int *fileCount)
{
ClearDirectoryFiles();
UnloadDirectoryFiles();
int counter = 0;
struct dirent *entity;
@ -3181,8 +3181,8 @@ char **GetDirectoryFiles(const char *dirPath, int *fileCount)
return dirFilesPath;
}
// Clear directory files paths buffers
void ClearDirectoryFiles(void)
// Unload directory filepaths
void UnloadDirectoryFiles(void)
{
if (dirFileCount > 0)
{
@ -3211,21 +3211,21 @@ bool IsFileDropped(void)
else return false;
}
// Get dropped files names
char **GetDroppedFiles(int *count)
// Load dropped filepaths
char **LoadDroppedFiles(int *count)
{
*count = CORE.Window.dropFileCount;
return CORE.Window.dropFilesPath;
return CORE.Window.dropFilepaths;
}
// Clear dropped files paths buffer
void ClearDroppedFiles(void)
// Unload dropped filepaths
void UnloadDroppedFiles(void)
{
if (CORE.Window.dropFileCount > 0)
{
for (int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilesPath[i]);
for (int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]);
RL_FREE(CORE.Window.dropFilesPath);
RL_FREE(CORE.Window.dropFilepaths);
CORE.Window.dropFileCount = 0;
}
@ -4872,49 +4872,46 @@ static void InitTimer(void)
CORE.Time.previous = GetTime(); // Get time as double
}
// Wait for some milliseconds (stop program execution)
// Wait for some time (stop program execution)
// NOTE: Sleep() granularity could be around 10 ms, it means, Sleep() could
// take longer than expected... for that reason we use the busy wait loop
// Ref: http://stackoverflow.com/questions/43057578/c-programming-win32-games-sleep-taking-longer-than-expected
// Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timming on Win32!
void WaitTime(float ms)
void WaitTime(double seconds)
{
#if defined(SUPPORT_BUSY_WAIT_LOOP)
double previousTime = GetTime();
double currentTime = 0.0;
#if defined(SUPPORT_BUSY_WAIT_LOOP) || defined(SUPPORT_PARTIALBUSY_WAIT_LOOP)
double destinationTime = GetTime() + seconds;
#endif
// Busy wait loop
while ((currentTime - previousTime) < ms/1000.0f) currentTime = GetTime();
#if defined(SUPPORT_BUSY_WAIT_LOOP)
while (GetTime() < destinationTime) { }
#else
#if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP)
double busyWait = ms*0.05; // NOTE: We are using a busy wait of 5% of the time
ms -= (float)busyWait;
double sleepSeconds = seconds - seconds*0.05; // NOTE: We reserve a percentage of the time for busy waiting
#else
double sleepSeconds = seconds;
#endif
// System halt functions
#if defined(_WIN32)
Sleep((unsigned int)ms);
Sleep((unsigned long)(sleepSeconds*1000.0));
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__EMSCRIPTEN__)
struct timespec req = { 0 };
time_t sec = (int)(ms/1000.0f);
ms -= (sec*1000);
time_t sec = sleepSeconds;
long nsec = (sleepSeconds - sec)*1000000000L;
req.tv_sec = sec;
req.tv_nsec = ms*1000000L;
req.tv_nsec = nsec;
// NOTE: Use nanosleep() on Unix platforms... usleep() it's deprecated.
while (nanosleep(&req, &req) == -1) continue;
#endif
#if defined(__APPLE__)
usleep(ms*1000.0f);
usleep(sleepSeconds*1000000.0);
#endif
#if defined(SUPPORT_PARTIALBUSY_WAIT_LOOP)
double previousTime = GetTime();
double currentTime = 0.0;
// Partial busy wait loop (only a fraction of the total wait time)
while ((currentTime - previousTime) < (busyWait/1000.0f)) currentTime = GetTime();
while (GetTime() < destinationTime) { }
#endif
#endif
}
@ -5537,7 +5534,7 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i
gifFrameCounter = 0;
Vector2 scale = GetWindowScaleDPI();
msf_gif_begin(&gifState, CORE.Window.render.width*scale.x, CORE.Window.render.height*scale.y);
msf_gif_begin(&gifState, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
screenshotCounter++;
TRACELOG(LOG_INFO, "SYSTEM: Start animated GIF recording: %s", TextFormat("screenrec%03i.gif", screenshotCounter));
@ -5674,14 +5671,14 @@ static void CursorEnterCallback(GLFWwindow *window, int enter)
// Everytime new files are dropped, old ones are discarded
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths)
{
ClearDroppedFiles();
UnloadDroppedFiles();
CORE.Window.dropFilesPath = (char **)RL_MALLOC(count*sizeof(char *));
CORE.Window.dropFilepaths = (char **)RL_MALLOC(count*sizeof(char *));
for (int i = 0; i < count; i++)
{
CORE.Window.dropFilesPath[i] = (char *)RL_MALLOC(MAX_FILEPATH_LENGTH*sizeof(char));
strcpy(CORE.Window.dropFilesPath[i], paths[i]);
CORE.Window.dropFilepaths[i] = (char *)RL_MALLOC(MAX_FILEPATH_LENGTH*sizeof(char));
strcpy(CORE.Window.dropFilepaths[i], paths[i]);
}
CORE.Window.dropFileCount = count;
@ -6314,12 +6311,13 @@ static void ConfigureEvdevDevice(char *device)
fd = open(device, O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
TRACELOG(LOG_WARNING, "RPI: Failed to open input device %s", device);
TRACELOG(LOG_WARNING, "RPI: Failed to open input device: %s", device);
return;
}
worker->fd = fd;
// Grab number on the end of the devices name "event<N>"
// TODO: Grab number on the end of the device name "mouse<N>"
int devNum = 0;
char *ptrDevName = strrchr(device, 't');
worker->eventNum = -1;
@ -6328,6 +6326,7 @@ static void ConfigureEvdevDevice(char *device)
{
if (sscanf(ptrDevName, "t%d", &devNum) == 1) worker->eventNum = devNum;
}
else worker->eventNum = 0; // HACK for mouse0 device!
// At this point we have a connection to the device, but we don't yet know what the device is.
// It could be many things, even as simple as a power button...
@ -6706,7 +6705,7 @@ static void *EventThread(void *arg)
#endif
}
WaitTime(5); // Sleep for 5ms to avoid hogging CPU time
WaitTime(0.005); // Sleep for 5ms to avoid hogging CPU time
}
close(worker->fd);
@ -6794,7 +6793,7 @@ static void *GamepadThread(void *arg)
}
}
}
else WaitTime(1); // Sleep for 1 ms to avoid hogging CPU time
else WaitTime(0.001); // Sleep for 1 ms to avoid hogging CPU time
}
}

View file

@ -433,7 +433,7 @@ typedef enum {
RL_BLEND_MULTIPLIED, // Blend textures multiplying colors
RL_BLEND_ADD_COLORS, // Blend textures adding colors (alternative)
RL_BLEND_SUBTRACT_COLORS, // Blend textures subtracting colors (alternative)
RL_BLEND_ALPHA_PREMUL, // Blend premultiplied textures considering alpha
RL_BLEND_ALPHA_PREMULTIPLY, // Blend premultiplied textures considering alpha
RL_BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors())
} rlBlendMode;
@ -1783,7 +1783,7 @@ void rlSetBlendMode(int mode)
case RL_BLEND_MULTIPLIED: glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_ADD_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_SUBTRACT_COLORS: glBlendFunc(GL_ONE, GL_ONE); glBlendEquation(GL_FUNC_SUBTRACT); break;
case RL_BLEND_ALPHA_PREMUL: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_ALPHA_PREMULTIPLY: glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_FUNC_ADD); break;
case RL_BLEND_CUSTOM:
{
// NOTE: Using GL blend src/dst factors and GL equation configured with rlSetBlendFactors()

View file

@ -4844,7 +4844,7 @@ static Model LoadGLTF(const char *fileName)
LOAD_ATTRIBUTE(attribute, 4, unsigned short, temp);
// Convert data to raylib color data type (4 bytes)
for (int c = 0; c < attribute->count*4; c++) model.meshes[meshIndex].colors[c] = (unsigned char)(((float)temp[c]/65535.0f)*255.0f);
for (unsigned int c = 0; c < attribute->count*4; c++) model.meshes[meshIndex].colors[c] = (unsigned char)(((float)temp[c]/65535.0f)*255.0f);
RL_FREE(temp);
}
@ -4858,7 +4858,7 @@ static Model LoadGLTF(const char *fileName)
LOAD_ATTRIBUTE(attribute, 4, float, temp);
// Convert data to raylib color data type (4 bytes), we expect the color data normalized
for (int c = 0; c < attribute->count*4; c++) model.meshes[meshIndex].colors[c] = (unsigned char)(temp[c]*255.0f);
for (unsigned int c = 0; c < attribute->count*4; c++) model.meshes[meshIndex].colors[c] = (unsigned char)(temp[c]*255.0f);
RL_FREE(temp);
}
@ -4893,7 +4893,7 @@ static Model LoadGLTF(const char *fileName)
LOAD_ATTRIBUTE(attribute, 1, unsigned int, temp);
// Convert data to raylib indices data type (unsigned short)
for (int d = 0; d < attribute->count; d++) model.meshes[meshIndex].indices[d] = (unsigned short)temp[d];
for (unsigned int d = 0; d < attribute->count; d++) model.meshes[meshIndex].indices[d] = (unsigned short)temp[d];
TRACELOG(LOG_WARNING, "MODEL: [%s] Indices data converted from u32 to u16, possible loss of data", fileName);
@ -4905,7 +4905,7 @@ static Model LoadGLTF(const char *fileName)
// Assign to the primitive mesh the corresponding material index
// NOTE: If no material defined, mesh uses the already assigned default material (index: 0)
for (int m = 0; m < data->materials_count; m++)
for (unsigned int m = 0; m < data->materials_count; m++)
{
// The primitive actually keeps the pointer to the corresponding material,
// raylib instead assigns to the mesh the by its index, as loaded in model.materials array

View file

@ -300,7 +300,7 @@ bool ExportDataAsCode(const char *data, unsigned int size, const char *fileName)
for (int i = 0; varFileName[i] != '\0'; i++) if ((varFileName[i] >= 'a') && (varFileName[i] <= 'z')) { varFileName[i] = varFileName[i] - 32; }
byteCount += sprintf(txtData + byteCount, "static unsigned char %s_DATA[%i] = { ", varFileName, size);
for (int i = 0; i < size - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), data[i]);
for (unsigned int i = 0; i < size - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), data[i]);
byteCount += sprintf(txtData + byteCount, "0x%x };\n", data[size - 1]);
// NOTE: Text data size exported is determined by '\0' (NULL) character