Update C sources

This commit is contained in:
Milan Nikolic 2024-05-07 21:54:39 +02:00
parent 2a66186c7d
commit 1868520849
No known key found for this signature in database
GPG key ID: 9229D0EAA3AA4E75
27 changed files with 4582 additions and 2234 deletions

View file

@ -63,7 +63,7 @@
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2013-2023 Ramon Santamaria (@raysan5) and contributors
* Copyright (c) 2013-2024 Ramon Santamaria (@raysan5) and contributors
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
@ -82,6 +82,19 @@
*
**********************************************************************************************/
//----------------------------------------------------------------------------------
// Feature Test Macros required for this module
//----------------------------------------------------------------------------------
#if (defined(__linux__) || defined(PLATFORM_WEB)) && (_XOPEN_SOURCE < 500)
#undef _XOPEN_SOURCE
#define _XOPEN_SOURCE 500 // Required for: readlink if compiled with c99 without gnu ext.
#endif
#if (defined(__linux__) || defined(PLATFORM_WEB)) && (_POSIX_C_SOURCE < 199309L)
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199309L // Required for: CLOCK_MONOTONIC if compiled with c99 without gnu ext.
#endif
#include "raylib.h" // Declares module functions
// Check if config flags have been externally provided on compilation line
@ -105,12 +118,12 @@
#if defined(SUPPORT_GESTURES_SYSTEM)
#define RGESTURES_IMPLEMENTATION
#include "rgestures.h" // Gestures detection functionality
#include "rgestures.h" // Gestures detection functionality
#endif
#if defined(SUPPORT_CAMERA_SYSTEM)
#define RCAMERA_IMPLEMENTATION
#include "rcamera.h" // Camera system functionality
#include "rcamera.h" // Camera system functionality
#endif
#if defined(SUPPORT_GIF_RECORDING)
@ -141,13 +154,15 @@
#endif
// Platform specific defines to handle GetApplicationDirectory()
#if defined(_WIN32)
#if (defined(_WIN32) && !defined(PLATFORM_DESKTOP_RGFW)) || (defined(_MSC_VER) && defined(PLATFORM_DESKTOP_RGFW))
#ifndef MAX_PATH
#define MAX_PATH 1025
#endif
__declspec(dllimport) unsigned long __stdcall GetModuleFileNameA(void *hModule, void *lpFilename, unsigned long nSize);
__declspec(dllimport) unsigned long __stdcall GetModuleFileNameW(void *hModule, void *lpFilename, unsigned long nSize);
__declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, void *widestr, int cchwide, void *str, int cbmb, void *defchar, int *used_default);
unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
#elif defined(__linux__)
#include <unistd.h>
#elif defined(__APPLE__)
@ -211,6 +226,9 @@ __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigne
#ifndef MAX_GAMEPAD_BUTTONS
#define MAX_GAMEPAD_BUTTONS 32 // Maximum number of buttons supported (per gamepad)
#endif
#ifndef MAX_GAMEPAD_VIBRATION_TIME
#define MAX_GAMEPAD_VIBRATION_TIME 2.0f // Maximum vibration time in seconds
#endif
#ifndef MAX_TOUCH_POINTS
#define MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
#endif
@ -235,11 +253,6 @@ __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigne
#define FLAG_TOGGLE(n, f) ((n) ^= (f))
#define FLAG_CHECK(n, f) ((n) & (f))
#if (defined(__linux__) || defined(PLATFORM_WEB)) && (_POSIX_C_SOURCE < 199309L)
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199309L // Required for: CLOCK_MONOTONIC if compiled with c99 without gnu ext.
#endif
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
@ -281,16 +294,16 @@ typedef struct CoreData {
struct {
struct {
int exitKey; // Default exit key
char currentKeyState[MAX_KEYBOARD_KEYS]; // Registers current frame key state
char previousKeyState[MAX_KEYBOARD_KEYS]; // Registers previous frame key state
char currentKeyState[MAX_KEYBOARD_KEYS]; // Registers current frame key state
char previousKeyState[MAX_KEYBOARD_KEYS]; // Registers previous frame key state
// NOTE: Since key press logic involves comparing prev vs cur key state, we need to handle key repeats specially
char keyRepeatInFrame[MAX_KEYBOARD_KEYS]; // Registers key repeats for current frame.
char keyRepeatInFrame[MAX_KEYBOARD_KEYS]; // Registers key repeats for current frame
int keyPressedQueue[MAX_KEY_PRESSED_QUEUE]; // Input keys queue
int keyPressedQueue[MAX_KEY_PRESSED_QUEUE]; // Input keys queue
int keyPressedQueueCount; // Input keys queue count
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
int charPressedQueueCount; // Input characters queue count
} Keyboard;
@ -320,7 +333,7 @@ typedef struct CoreData {
} Touch;
struct {
int lastButtonPressed; // Register last gamepad button pressed
int axisCount[MAX_GAMEPADS]; // Register number of available gamepad axis
int axisCount[MAX_GAMEPADS]; // Register number of available gamepad axis
bool ready[MAX_GAMEPADS]; // Flag to know if gamepad is ready
char name[MAX_GAMEPADS][64]; // Gamepad name holder
char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
@ -354,7 +367,7 @@ static int screenshotCounter = 0; // Screenshots counter
#endif
#if defined(SUPPORT_GIF_RECORDING)
int gifFrameCounter = 0; // GIF frames counter
unsigned int gifFrameCounter = 0; // GIF frames counter
bool gifRecording = false; // GIF recording state
MsfGifState gifState = { 0 }; // MSGIF context state
#endif
@ -471,7 +484,7 @@ static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *li
static void RecordAutomationEvent(void); // Record frame events (to internal events array)
#endif
#if defined(_WIN32)
#if defined(_WIN32) && !defined(PLATFORM_DESKTOP_RGFW)
// NOTE: We declare Sleep() function symbol to avoid including windows.h (kernel32.lib linkage required)
void __stdcall Sleep(unsigned long msTimeout); // Required for: WaitTime()
#endif
@ -485,6 +498,8 @@ const char *TextFormat(const char *text, ...); // Formatting of tex
#include "platforms/rcore_desktop.c"
#elif defined(PLATFORM_DESKTOP_SDL)
#include "platforms/rcore_desktop_sdl.c"
#elif defined(PLATFORM_DESKTOP_RGFW)
#include "platforms/rcore_desktop_rgfw.c"
#elif defined(PLATFORM_WEB)
#include "platforms/rcore_web.c"
#elif defined(PLATFORM_DRM)
@ -795,7 +810,7 @@ bool IsCursorHidden(void)
return CORE.Input.Mouse.cursorHidden;
}
// Check if cursor is on the current screen.
// Check if cursor is on the current screen
bool IsCursorOnScreen(void)
{
return CORE.Input.Mouse.cursorOnScreen;
@ -838,23 +853,33 @@ void EndDrawing(void)
// Draw record indicator
if (gifRecording)
{
#ifndef GIF_RECORD_FRAMERATE
#define GIF_RECORD_FRAMERATE 10
gifFrameCounter++;
#endif
gifFrameCounter += GetFrameTime()*1000;
// NOTE: We record one gif frame every 10 game frames
if ((gifFrameCounter%GIF_RECORD_FRAMERATE) == 0)
// NOTE: We record one gif frame depending on the desired gif framerate
if (gifFrameCounter > 1000/GIF_RECORD_FRAMERATE)
{
// Get image data for the current frame (from backbuffer)
// NOTE: This process is quite slow... :(
Vector2 scale = GetWindowScaleDPI();
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);
#ifndef GIF_RECORD_BITRATE
#define GIF_RECORD_BITRATE 16
#endif
// Add the frame to the gif recording, given how many frames have passed in centiseconds
msf_gif_frame(&gifState, screenData, gifFrameCounter/10, GIF_RECORD_BITRATE, (int)((float)CORE.Window.render.width*scale.x)*4);
gifFrameCounter -= 1000/GIF_RECORD_FRAMERATE;
RL_FREE(screenData); // Free image data
}
#if defined(SUPPORT_MODULE_RSHAPES) && defined(SUPPORT_MODULE_RTEXT)
if (((gifFrameCounter/15)%2) == 1)
// Display the recording indicator every half-second
if ((int)(GetTime()/0.5)%2 == 1)
{
DrawCircle(30, CORE.Window.screen.height - 20, 10, MAROON); // WARNING: Module required: rshapes
DrawText("GIF RECORDING", 50, CORE.Window.screen.height - 25, 10, RED); // WARNING: Module required: rtext
@ -944,9 +969,6 @@ void BeginMode2D(Camera2D camera)
// Apply 2d camera transformation to modelview
rlMultMatrixf(MatrixToFloat(GetCameraMatrix2D(camera)));
// Apply screen scaling if required
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale));
}
// Ends 2D mode with custom camera
@ -955,7 +977,8 @@ void EndMode2D(void)
rlDrawRenderBatchActive(); // Update and draw internal render batch
rlLoadIdentity(); // Reset current matrix (modelview)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
if (rlGetActiveFramebuffer() == 0) rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
}
// Initializes 3D mode with custom camera (3D)
@ -973,10 +996,10 @@ void BeginMode3D(Camera camera)
if (camera.projection == CAMERA_PERSPECTIVE)
{
// Setup perspective projection
double top = RL_CULL_DISTANCE_NEAR*tan(camera.fovy*0.5*DEG2RAD);
double top = rlGetCullDistanceNear()*tan(camera.fovy*0.5*DEG2RAD);
double right = top*aspect;
rlFrustum(-right, right, -top, top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
rlFrustum(-right, right, -top, top, rlGetCullDistanceNear(), rlGetCullDistanceFar());
}
else if (camera.projection == CAMERA_ORTHOGRAPHIC)
{
@ -984,7 +1007,7 @@ void BeginMode3D(Camera camera)
double top = camera.fovy/2.0;
double right = top*aspect;
rlOrtho(-right, right, -top,top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
rlOrtho(-right, right, -top,top, rlGetCullDistanceNear(), rlGetCullDistanceFar());
}
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
@ -1008,7 +1031,7 @@ void EndMode3D(void)
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
rlLoadIdentity(); // Reset current matrix (modelview)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
if (rlGetActiveFramebuffer() == 0) rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
rlDisableDepthTest(); // Disable DEPTH_TEST for 2D
}
@ -1054,6 +1077,11 @@ void EndTextureMode(void)
// Set viewport to default framebuffer size
SetupViewport(CORE.Window.render.width, CORE.Window.render.height);
// Go back to the modelview state from BeginDrawing since we are back to the default FBO
rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix
rlLoadIdentity(); // Reset current matrix (modelview)
rlMultMatrixf(MatrixToFloat(CORE.Window.screenScale)); // Apply screen scaling if required
// Reset current fbo to screen size
CORE.Window.currentFbo.width = CORE.Window.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height;
@ -1183,17 +1211,17 @@ VrStereoConfig LoadVrStereoConfig(VrDeviceInfo device)
// Compute camera projection matrices
float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1]
Matrix proj = MatrixPerspective(fovy, aspect, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
Matrix proj = MatrixPerspective(fovy, aspect, rlGetCullDistanceNear(), rlGetCullDistanceFar());
config.projection[0] = MatrixMultiply(proj, MatrixTranslate(projOffset, 0.0f, 0.0f));
config.projection[1] = MatrixMultiply(proj, MatrixTranslate(-projOffset, 0.0f, 0.0f));
// Compute camera transformation matrices
// NOTE: Camera movement might seem more natural if we model the head.
// NOTE: Camera movement might seem more natural if we model the head
// Our axis of rotation is the base of our head, so we might want to add
// some y (base of head to eye level) and -z (center of head to eye protrusion) to the camera positions.
config.viewOffset[0] = MatrixTranslate(-device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
config.viewOffset[1] = MatrixTranslate(device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
// some y (base of head to eye level) and -z (center of head to eye protrusion) to the camera positions
config.viewOffset[0] = MatrixTranslate(device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
config.viewOffset[1] = MatrixTranslate(-device.interpupillaryDistance*0.5f, 0.075f, 0.045f);
// Compute eyes Viewports
/*
@ -1392,15 +1420,23 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
// Module Functions Definition: Screen-space Queries
//----------------------------------------------------------------------------------
// Get a ray trace from mouse position
Ray GetMouseRay(Vector2 mouse, Camera camera)
// Get a ray trace from screen position (i.e mouse)
Ray GetScreenToWorldRay(Vector2 position, Camera camera)
{
Ray ray = GetScreenToWorldRayEx(position, camera, GetScreenWidth(), GetScreenHeight());
return ray;
}
// Get a ray trace from the screen position (i.e mouse) within a specific section of the screen
Ray GetScreenToWorldRayEx(Vector2 position, Camera camera, int width, int height)
{
Ray ray = { 0 };
// Calculate normalized device coordinates
// NOTE: y value is negative
float x = (2.0f*mouse.x)/(float)GetScreenWidth() - 1.0f;
float y = 1.0f - (2.0f*mouse.y)/(float)GetScreenHeight();
float x = (2.0f*position.x)/(float)width - 1.0f;
float y = 1.0f - (2.0f*position.y)/(float)height;
float z = 1.0f;
// Store values in a vector
@ -1414,11 +1450,11 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
if (camera.projection == CAMERA_PERSPECTIVE)
{
// Calculate projection matrix from perspective
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), rlGetCullDistanceNear(), rlGetCullDistanceFar());
}
else if (camera.projection == CAMERA_ORTHOGRAPHIC)
{
double aspect = (double)CORE.Window.screen.width/(double)CORE.Window.screen.height;
double aspect = (double)width/(double)height;
double top = camera.fovy/2.0;
double right = top*aspect;
@ -1430,9 +1466,10 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
Vector3 nearPoint = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView);
Vector3 farPoint = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView);
// Unproject the mouse cursor in the near plane.
// We need this as the source position because orthographic projects, compared to perspective doesn't have a
// convergence point, meaning that the "eye" of the camera is more like a plane than a point.
// Unproject the mouse cursor in the near plane
// We need this as the source position because orthographic projects,
// compared to perspective doesn't have a convergence point,
// meaning that the "eye" of the camera is more like a plane than a point
Vector3 cameraPlanePointerPos = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, -1.0f }, matProj, matView);
// Calculate normalized direction vector
@ -1450,7 +1487,9 @@ Ray GetMouseRay(Vector2 mouse, Camera camera)
// Get transform matrix for camera
Matrix GetCameraMatrix(Camera camera)
{
return MatrixLookAt(camera.position, camera.target, camera.up);
Matrix mat = MatrixLookAt(camera.position, camera.target, camera.up);
return mat;
}
// Get camera 2d transform matrix
@ -1461,12 +1500,12 @@ Matrix GetCameraMatrix2D(Camera2D camera)
// 1. Move it to target
// 2. Rotate by -rotation and scale by (1/zoom)
// When setting higher scale, it's more intuitive for the world to become bigger (= camera become smaller),
// not for the camera getting bigger, hence the invert. Same deal with rotation.
// not for the camera getting bigger, hence the invert. Same deal with rotation
// 3. Move it by (-offset);
// Offset defines target transform relative to screen, but since we're effectively "moving" screen (camera)
// we need to do it into opposite direction (inverse transform)
// Having camera transform in world-space, inverse of it gives the modelview transform.
// Having camera transform in world-space, inverse of it gives the modelview transform
// Since (A*B*C)' = C'*B'*A', the modelview is
// 1. Move to offset
// 2. Rotate and Scale
@ -1498,7 +1537,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh
if (camera.projection == CAMERA_PERSPECTIVE)
{
// Calculate projection matrix from perspective
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)width/(double)height), rlGetCullDistanceNear(), rlGetCullDistanceFar());
}
else if (camera.projection == CAMERA_ORTHOGRAPHIC)
{
@ -1507,7 +1546,7 @@ Vector2 GetWorldToScreenEx(Vector3 position, Camera camera, int width, int heigh
double right = top*aspect;
// Calculate projection matrix from orthographic
matProj = MatrixOrtho(-right, right, -top, top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR);
matProj = MatrixOrtho(-right, right, -top, top, rlGetCullDistanceNear(), rlGetCullDistanceFar());
}
// Calculate view matrix from camera look at (and transpose it)
@ -1631,7 +1670,7 @@ float GetFrameTime(void)
// Ref: http://www.geisswerks.com/ryan/FAQS/timing.html --> All about timing on Win32!
void WaitTime(double seconds)
{
if (seconds < 0) return;
if (seconds < 0) return; // Security check
#if defined(SUPPORT_BUSY_WAIT_LOOP) || defined(SUPPORT_PARTIALBUSY_WAIT_LOOP)
double destinationTime = GetTime() + seconds;
@ -1657,7 +1696,7 @@ void WaitTime(double seconds)
req.tv_sec = sec;
req.tv_nsec = nsec;
// NOTE: Use nanosleep() on Unix platforms... usleep() it's deprecated.
// NOTE: Use nanosleep() on Unix platforms... usleep() it's deprecated
while (nanosleep(&req, &req) == -1) continue;
#endif
#if defined(__APPLE__)
@ -1677,7 +1716,6 @@ void WaitTime(double seconds)
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
//void OpenURL(const char *url)
// Set the seed for the random number generator
void SetRandomSeed(unsigned int seed)
{
@ -1725,7 +1763,7 @@ int *LoadRandomSequence(unsigned int count, int min, int max)
#if defined(SUPPORT_RPRAND_GENERATOR)
values = rprand_load_sequence(count, min, max);
#else
if (count > ((unsigned int)abs(max - min) + 1)) return values;
if (count > ((unsigned int)abs(max - min) + 1)) return values; // Security check
values = (int *)RL_CALLOC(count, sizeof(int));
@ -1780,7 +1818,7 @@ void TakeScreenshot(const char *fileName)
char path[512] = { 0 };
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, GetFileName(fileName)));
ExportImage(image, path); // WARNING: Module required: rtextures
RL_FREE(imgData);
@ -1793,7 +1831,7 @@ void TakeScreenshot(const char *fileName)
// Setup window configuration flags (view FLAGS)
// NOTE: This function is expected to be called before window creation,
// because it sets up some flags for the window creation process.
// because it sets up some flags for the window creation process
// To configure window states after creation, just use SetWindowState()
void SetConfigFlags(unsigned int flags)
{
@ -1829,7 +1867,7 @@ bool FileExists(const char *fileName)
// NOTE: Extensions checking is not case-sensitive
bool IsFileExtension(const char *fileName, const char *ext)
{
#define MAX_FILE_EXTENSION_SIZE 16
#define MAX_FILE_EXTENSION_LENGTH 16
bool result = false;
const char *fileExt = GetFileExtension(fileName);
@ -1840,8 +1878,8 @@ bool IsFileExtension(const char *fileName, const char *ext)
int extCount = 0;
const char **checkExts = TextSplit(ext, ';', &extCount); // WARNING: Module required: rtext
char fileExtLower[MAX_FILE_EXTENSION_SIZE + 1] = { 0 };
strncpy(fileExtLower, TextToLower(fileExt), MAX_FILE_EXTENSION_SIZE); // WARNING: Module required: rtext
char fileExtLower[MAX_FILE_EXTENSION_LENGTH + 1] = { 0 };
strncpy(fileExtLower, TextToLower(fileExt), MAX_FILE_EXTENSION_LENGTH); // WARNING: Module required: rtext
for (int i = 0; i < extCount; i++)
{
@ -1917,7 +1955,9 @@ const char *GetFileExtension(const char *fileName)
static const char *strprbrk(const char *s, const char *charset)
{
const char *latestMatch = NULL;
for (; s = strpbrk(s, charset), s != NULL; latestMatch = s++) { }
return latestMatch;
}
@ -1925,9 +1965,10 @@ static const char *strprbrk(const char *s, const char *charset)
const char *GetFileName(const char *filePath)
{
const char *fileName = NULL;
if (filePath != NULL) fileName = strprbrk(filePath, "\\/");
if (!fileName) return filePath;
if (fileName == NULL) return filePath;
return fileName + 1;
}
@ -1935,22 +1976,24 @@ const char *GetFileName(const char *filePath)
// Get filename string without extension (uses static string)
const char *GetFileNameWithoutExt(const char *filePath)
{
#define MAX_FILENAMEWITHOUTEXT_LENGTH 256
#define MAX_FILENAME_LENGTH 256
static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH] = { 0 };
memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH);
static char fileName[MAX_FILENAME_LENGTH] = { 0 };
memset(fileName, 0, MAX_FILENAME_LENGTH);
if (filePath != NULL) strcpy(fileName, GetFileName(filePath)); // Get filename with extension
int size = (int)strlen(fileName); // Get size in bytes
for (int i = 0; (i < size) && (i < MAX_FILENAMEWITHOUTEXT_LENGTH); i++)
if (filePath != NULL)
{
if (fileName[i] == '.')
strcpy(fileName, GetFileName(filePath)); // Get filename.ext without path
int size = (int)strlen(fileName); // Get size in bytes
for (int i = size; i > 0; i--) // Reverse search '.'
{
// NOTE: We break on first '.' found
fileName[i] = '\0';
break;
if (fileName[i] == '.')
{
// NOTE: We break on first '.' found
fileName[i] = '\0';
break;
}
}
}
@ -2204,8 +2247,11 @@ bool IsPathFile(const char *path)
// Check if a file has been dropped into window
bool IsFileDropped(void)
{
if (CORE.Window.dropFileCount > 0) return true;
else return false;
bool result = false;
if (CORE.Window.dropFileCount > 0) result = true;
return result;
}
// Load dropped filepaths
@ -2239,15 +2285,16 @@ void UnloadDroppedFiles(FilePathList files)
long GetFileModTime(const char *fileName)
{
struct stat result = { 0 };
long modTime = 0;
if (stat(fileName, &result) == 0)
{
time_t mod = result.st_mtime;
return (long)mod;
modTime = (long)mod;
}
return 0;
return modTime;
}
//----------------------------------------------------------------------------------
@ -2316,7 +2363,7 @@ char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize)
char *encodedData = (char *)RL_MALLOC(*outputSize);
if (encodedData == NULL) return NULL;
if (encodedData == NULL) return NULL; // Security check
for (int i = 0, j = 0; i < dataSize;)
{
@ -2480,13 +2527,10 @@ AutomationEventList LoadAutomationEventList(const char *fileName)
}
// Unload automation events list from file
void UnloadAutomationEventList(AutomationEventList *list)
void UnloadAutomationEventList(AutomationEventList list)
{
#if defined(SUPPORT_AUTOMATION_EVENTS)
RL_FREE(list->events);
list->events = NULL;
list->count = 0;
list->capacity = 0;
RL_FREE(list.events);
#endif
}
@ -2623,8 +2667,9 @@ void PlayAutomationEvent(AutomationEvent event)
{
CORE.Input.Gamepad.axisState[event.params[0]][event.params[1]] = ((float)event.params[2]/32768.0f);
} break;
#if defined(SUPPORT_GESTURES_SYSTEM)
case INPUT_GESTURE: GESTURES.current = event.params[0]; break; // param[0]: gesture (enum Gesture) -> rgestures.h: GESTURES.current
#endif
// Window event
case WINDOW_CLOSE: CORE.Window.shouldClose = true; break;
case WINDOW_MAXIMIZE: MaximizeWindow(); break;
@ -2632,11 +2677,13 @@ void PlayAutomationEvent(AutomationEvent event)
case WINDOW_RESIZE: SetWindowSize(event.params[0], event.params[1]); break;
// Custom event
#if defined(SUPPORT_SCREEN_CAPTURE)
case ACTION_TAKE_SCREENSHOT:
{
TakeScreenshot(TextFormat("screenshot%03i.png", screenshotCounter));
screenshotCounter++;
} break;
#endif
case ACTION_SETTARGETFPS: SetTargetFPS(event.params[0]); break;
default: break;
}
@ -2918,13 +2965,15 @@ bool IsMouseButtonUp(int button)
// Get mouse position X
int GetMouseX(void)
{
return (int)((CORE.Input.Mouse.currentPosition.x + CORE.Input.Mouse.offset.x)*CORE.Input.Mouse.scale.x);
int mouseX = (int)((CORE.Input.Mouse.currentPosition.x + CORE.Input.Mouse.offset.x)*CORE.Input.Mouse.scale.x);
return mouseX;
}
// Get mouse position Y
int GetMouseY(void)
{
return (int)((CORE.Input.Mouse.currentPosition.y + CORE.Input.Mouse.offset.y)*CORE.Input.Mouse.scale.y);
int mouseY = (int)((CORE.Input.Mouse.currentPosition.y + CORE.Input.Mouse.offset.y)*CORE.Input.Mouse.scale.y);
return mouseY;
}
// Get mouse position XY
@ -2991,13 +3040,15 @@ Vector2 GetMouseWheelMoveV(void)
// Get touch position X for touch point 0 (relative to screen size)
int GetTouchX(void)
{
return (int)CORE.Input.Touch.position[0].x;
int touchX = (int)CORE.Input.Touch.position[0].x;
return touchX;
}
// Get touch position Y for touch point 0 (relative to screen size)
int GetTouchY(void)
{
return (int)CORE.Input.Touch.position[0].y;
int touchY = (int)CORE.Input.Touch.position[0].y;
return touchY;
}
// Get touch position XY for a touch point index (relative to screen size)
@ -3039,10 +3090,10 @@ int GetTouchPointCount(void)
// Initialize hi-resolution timer
void InitTimer(void)
{
// Setting a higher resolution can improve the accuracy of time-out intervals in wait functions.
// However, it can also reduce overall system performance, because the thread scheduler switches tasks more often.
// High resolutions can also prevent the CPU power management system from entering power-saving modes.
// Setting a higher resolution does not improve the accuracy of the high-resolution performance counter.
// Setting a higher resolution can improve the accuracy of time-out intervals in wait functions
// However, it can also reduce overall system performance, because the thread scheduler switches tasks more often
// High resolutions can also prevent the CPU power management system from entering power-saving modes
// Setting a higher resolution does not improve the accuracy of the high-resolution performance counter
#if defined(_WIN32) && defined(SUPPORT_WINMM_HIGHRES_TIMER) && !defined(SUPPORT_BUSY_WAIT_LOOP) && !defined(PLATFORM_DESKTOP_SDL)
timeBeginPeriod(1); // Setup high-resolution timer to 1ms (granularity of 1-2 ms)
#endif
@ -3265,7 +3316,7 @@ static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *fi
#if defined(SUPPORT_AUTOMATION_EVENTS)
// Automation event recording
// NOTE: Recording is by default done at EndDrawing(), after PollInputEvents()
// NOTE: Recording is by default done at EndDrawing(), before PollInputEvents()
static void RecordAutomationEvent(void)
{
// Checking events in current frame and save them into currentEventList
@ -3507,6 +3558,7 @@ static void RecordAutomationEvent(void)
}
//-------------------------------------------------------------------------------------
#if defined(SUPPORT_GESTURES_SYSTEM)
// Gestures input currentEventList->events recording
//-------------------------------------------------------------------------------------
if (GESTURES.current != GESTURE_NONE)
@ -3524,16 +3576,7 @@ static void RecordAutomationEvent(void)
if (currentEventList->count == currentEventList->capacity) return; // Security check
}
//-------------------------------------------------------------------------------------
// Window events recording
//-------------------------------------------------------------------------------------
// TODO.
//-------------------------------------------------------------------------------------
// Custom actions events recording
//-------------------------------------------------------------------------------------
// TODO.
//-------------------------------------------------------------------------------------
#endif
}
#endif