mirror of
https://github.com/raysan5/raylib.git
synced 2026-07-13 09:01:56 -04:00
Compare commits
5 Commits
65abee1cba
...
d631a5a466
| Author | SHA1 | Date | |
|---|---|---|---|
| d631a5a466 | |||
| 5992929e56 | |||
| 3d640698d8 | |||
| 088177b269 | |||
| 2e03c9c266 |
@ -1829,7 +1829,7 @@ int InitPlatform(void)
|
||||
{
|
||||
CORE.Input.Gamepad.ready[i] = true;
|
||||
CORE.Input.Gamepad.axisCount[i] = GLFW_GAMEPAD_AXIS_LAST + 1;
|
||||
strncpy(CORE.Input.Gamepad.name[i], glfwGetJoystickName(i), MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
snprintf(CORE.Input.Gamepad.name[i], MAX_GAMEPAD_NAME_LENGTH, "%s", glfwGetJoystickName(i));
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
@ -2044,7 +2044,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
|
||||
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++)
|
||||
{
|
||||
CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||
strncpy(CORE.Window.dropFilepaths[i], paths[i], MAX_FILEPATH_LENGTH - 1);
|
||||
snprintf(CORE.Window.dropFilepaths[i], MAX_FILEPATH_LENGTH, "%s", paths[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2191,7 +2191,7 @@ static void JoystickCallback(int jid, int event)
|
||||
// WARNING: If glfwGetJoystickName() is longer than MAX_GAMEPAD_NAME_LENGTH,
|
||||
// only copy up to (MAX_GAMEPAD_NAME_LENGTH -1) to destination string
|
||||
memset(CORE.Input.Gamepad.name[jid], 0, MAX_GAMEPAD_NAME_LENGTH);
|
||||
strncpy(CORE.Input.Gamepad.name[jid], glfwGetJoystickName(jid), MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
snprintf(CORE.Input.Gamepad.name[jid], MAX_GAMEPAD_NAME_LENGTH, "%s", glfwGetJoystickName(jid));
|
||||
}
|
||||
else if (event == GLFW_DISCONNECTED)
|
||||
{
|
||||
|
||||
@ -486,14 +486,14 @@ static void RGFW_cb_dropfunc(const RGFW_event *e)
|
||||
CORE.Window.dropFilepaths = (char **)RL_CALLOC(1024, sizeof(char *));
|
||||
|
||||
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||
strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], e->drop.value->data);
|
||||
snprintf(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], MAX_FILEPATH_LENGTH, "%s", e->drop.value->data);
|
||||
|
||||
CORE.Window.dropFileCount++;
|
||||
}
|
||||
else if (CORE.Window.dropFileCount < 1024)
|
||||
{
|
||||
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||
strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], e->drop.value->data);
|
||||
snprintf(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], MAX_FILEPATH_LENGTH, "%s", e->drop.value->data);
|
||||
|
||||
CORE.Window.dropFileCount++;
|
||||
}
|
||||
@ -1609,74 +1609,76 @@ void PollInputEvents(void)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
mg_event gamepad_event;
|
||||
while (mg_gamepads_check_event(&platform.minigamepad, &gamepad_event)) {
|
||||
while (mg_gamepads_check_event(&platform.minigamepad, &gamepad_event))
|
||||
{
|
||||
int gamepadIndex = gamepad_event.gamepad->index;
|
||||
switch (gamepad_event.type) {
|
||||
|
||||
switch (gamepad_event.type)
|
||||
{
|
||||
case MG_EVENT_BUTTON_PRESS:
|
||||
{
|
||||
int button = mg_buttonConvertTable[gamepad_event.button];
|
||||
if (button >= 0)
|
||||
{
|
||||
int button = mg_buttonConvertTable[gamepad_event.button];
|
||||
if (button >= 0)
|
||||
{
|
||||
CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = 1;
|
||||
CORE.Input.Gamepad.lastButtonPressed = button;
|
||||
}
|
||||
} break;
|
||||
CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = 1;
|
||||
CORE.Input.Gamepad.lastButtonPressed = button;
|
||||
}
|
||||
} break;
|
||||
case MG_EVENT_BUTTON_RELEASE:
|
||||
{
|
||||
int button = mg_buttonConvertTable[gamepad_event.button];
|
||||
if (button >= 0)
|
||||
{
|
||||
int button = mg_buttonConvertTable[gamepad_event.button];
|
||||
if (button >= 0)
|
||||
{
|
||||
CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = 0;
|
||||
if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||
}
|
||||
} break;
|
||||
CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = 0;
|
||||
if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||
}
|
||||
} break;
|
||||
case MG_EVENT_AXIS_MOVE:
|
||||
{
|
||||
int axis = mg_axisConvertTable[gamepad_event.axis];
|
||||
{
|
||||
int axis = mg_axisConvertTable[gamepad_event.axis];
|
||||
|
||||
switch (axis) {
|
||||
case GAMEPAD_AXIS_LEFT_X:
|
||||
case GAMEPAD_AXIS_LEFT_Y:
|
||||
case GAMEPAD_AXIS_RIGHT_X:
|
||||
case GAMEPAD_AXIS_RIGHT_Y:
|
||||
CORE.Input.Gamepad.axisState[gamepadIndex][axis] = platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value;
|
||||
break;
|
||||
case GAMEPAD_AXIS_LEFT_TRIGGER:
|
||||
case GAMEPAD_AXIS_RIGHT_TRIGGER:
|
||||
CORE.Input.Gamepad.axisState[gamepadIndex][axis] = platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value;
|
||||
switch (axis) {
|
||||
case GAMEPAD_AXIS_LEFT_X:
|
||||
case GAMEPAD_AXIS_LEFT_Y:
|
||||
case GAMEPAD_AXIS_RIGHT_X:
|
||||
case GAMEPAD_AXIS_RIGHT_Y:
|
||||
{
|
||||
CORE.Input.Gamepad.axisState[gamepadIndex][axis] = platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value;
|
||||
} break;
|
||||
case GAMEPAD_AXIS_LEFT_TRIGGER:
|
||||
case GAMEPAD_AXIS_RIGHT_TRIGGER:
|
||||
{
|
||||
CORE.Input.Gamepad.axisState[gamepadIndex][axis] = platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value;
|
||||
|
||||
// Trigger button press when axis is all the way
|
||||
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER) ? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
|
||||
int pressed = (platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value >= 1.0f);
|
||||
// Trigger button press when axis is all the way
|
||||
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER) ? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
|
||||
int pressed = (platform.minigamepad.gamepads[gamepadIndex].axes[gamepad_event.axis].value >= 1.0f);
|
||||
|
||||
CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = pressed;
|
||||
if (pressed) CORE.Input.Gamepad.lastButtonPressed = button;
|
||||
else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||
break;
|
||||
}
|
||||
} break;
|
||||
CORE.Input.Gamepad.currentButtonState[gamepadIndex][button] = pressed;
|
||||
if (pressed) CORE.Input.Gamepad.lastButtonPressed = button;
|
||||
else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
} break;
|
||||
case MG_EVENT_GAMEPAD_CONNECT:
|
||||
{
|
||||
CORE.Input.Gamepad.ready[gamepadIndex] = true;
|
||||
CORE.Input.Gamepad.axisState[gamepadIndex][GAMEPAD_AXIS_LEFT_TRIGGER] = -1.0f;
|
||||
CORE.Input.Gamepad.axisState[gamepadIndex][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
|
||||
|
||||
int axisCount = 0;
|
||||
for (int i = 0; i < MG_AXIS_COUNT; i += 1) {
|
||||
if (platform.minigamepad.gamepads[gamepadIndex].axes[i].supported)
|
||||
{
|
||||
axisCount += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < MG_AXIS_COUNT; i += 1)
|
||||
{
|
||||
if (platform.minigamepad.gamepads[gamepadIndex].axes[i].supported) axisCount += 1;
|
||||
else break;
|
||||
}
|
||||
|
||||
CORE.Input.Gamepad.axisCount[gamepadIndex] = axisCount;
|
||||
strcpy(CORE.Input.Gamepad.name[gamepadIndex], platform.minigamepad.gamepads[gamepadIndex].name);
|
||||
break;
|
||||
case MG_EVENT_GAMEPAD_DISCONNECT:
|
||||
CORE.Input.Gamepad.ready[gamepadIndex] = false;
|
||||
break;
|
||||
snprintf(CORE.Input.Gamepad.name[gamepadIndex], MAX_GAMEPAD_NAME_LENGTH, "%s", platform.minigamepad.gamepads[gamepadIndex].name);
|
||||
|
||||
} break;
|
||||
case MG_EVENT_GAMEPAD_DISCONNECT: CORE.Input.Gamepad.ready[gamepadIndex] = false; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1512,9 +1512,9 @@ void PollInputEvents(void)
|
||||
// Event memory is now managed by SDL, so it should not be freed in SDL_EVENT_DROP_FILE,
|
||||
// in case data needs to be hold onto the text in SDL_EVENT_TEXT_EDITING and SDL_EVENT_TEXT_INPUT events,
|
||||
// a copy is required, SDL_TEXTINPUTEVENT_TEXT_SIZE is no longer necessary and has been removed
|
||||
strncpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event.drop.data, MAX_FILEPATH_LENGTH - 1);
|
||||
snprintf(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], MAX_FILEPATH_LENGTH, "%s", event.drop.data);
|
||||
#else
|
||||
strncpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event.drop.file, MAX_FILEPATH_LENGTH - 1);
|
||||
snprintf(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], MAX_FILEPATH_LENGTH, "%s", event.drop.file);
|
||||
SDL_free(event.drop.file);
|
||||
#endif
|
||||
|
||||
@ -1525,9 +1525,9 @@ void PollInputEvents(void)
|
||||
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||
|
||||
#if defined(USING_VERSION_SDL3)
|
||||
strncpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event.drop.data, MAX_FILEPATH_LENGTH - 1);
|
||||
snprintf(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], MAX_FILEPATH_LENGTH, "%s", event.drop.data);
|
||||
#else
|
||||
strncpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event.drop.file, MAX_FILEPATH_LENGTH - 1);
|
||||
snprintf(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], MAX_FILEPATH_LENGTH, "%s", event.drop.file);
|
||||
SDL_free(event.drop.file);
|
||||
#endif
|
||||
|
||||
@ -1812,8 +1812,8 @@ void PollInputEvents(void)
|
||||
CORE.Input.Gamepad.axisState[nextAvailableSlot][GAMEPAD_AXIS_RIGHT_TRIGGER] = -1.0f;
|
||||
memset(CORE.Input.Gamepad.name[nextAvailableSlot], 0, MAX_GAMEPAD_NAME_LENGTH);
|
||||
const char *controllerName = SDL_GameControllerNameForIndex(nextAvailableSlot);
|
||||
if (controllerName != NULL) strncpy(CORE.Input.Gamepad.name[nextAvailableSlot], controllerName, MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
else strncpy(CORE.Input.Gamepad.name[nextAvailableSlot], "noname", 6);
|
||||
if (controllerName != NULL) snprintf(CORE.Input.Gamepad.name[nextAvailableSlot], MAX_GAMEPAD_NAME_LENGTH, "%s", controllerName);
|
||||
else memcpy(CORE.Input.Gamepad.name[nextAvailableSlot], "noname", 6);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError());
|
||||
}
|
||||
@ -2191,7 +2191,7 @@ int InitPlatform(void)
|
||||
#else
|
||||
const char *joystickName = SDL_GameControllerNameForIndex(i);
|
||||
#endif
|
||||
strncpy(CORE.Input.Gamepad.name[i], joystickName, MAX_GAMEPAD_NAME_LENGTH - 1);
|
||||
snprintf(CORE.Input.Gamepad.name[i], MAX_GAMEPAD_NAME_LENGTH, "%s", joystickName);
|
||||
CORE.Input.Gamepad.name[i][MAX_GAMEPAD_NAME_LENGTH - 1] = '\0';
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "PLATFORM: Unable to open game controller [ERROR: %s]", SDL_GetError());
|
||||
|
||||
@ -1579,7 +1579,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
|
||||
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++)
|
||||
{
|
||||
CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||
strncpy(CORE.Window.dropFilepaths[i], paths[i], MAX_FILEPATH_LENGTH - 1);
|
||||
snprintf(CORE.Window.dropFilepaths[i], MAX_FILEPATH_LENGTH, "%s", paths[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1439,7 +1439,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
|
||||
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++)
|
||||
{
|
||||
CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||
strncpy(CORE.Window.dropFilepaths[i], paths[i], MAX_FILEPATH_LENGTH - 1);
|
||||
snprintf(CORE.Window.dropFilepaths[i], MAX_FILEPATH_LENGTH, "%s", paths[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1154,7 +1154,7 @@ bool ExportWaveAsCode(Wave wave, const char *fileName)
|
||||
|
||||
// Get file name from path and convert variable name to uppercase
|
||||
char varFileName[256] = { 0 };
|
||||
strncpy(varFileName, GetFileNameWithoutExt(fileName), 256 - 1);
|
||||
snprintf(varFileName, 256, "%s", GetFileNameWithoutExt(fileName)); // NOTE: Using function provided by [rcore] module
|
||||
for (int i = 0; varFileName[i] != '\0'; i++) if (varFileName[i] >= 'a' && varFileName[i] <= 'z') { varFileName[i] = varFileName[i] - 32; }
|
||||
|
||||
// Add wave information
|
||||
@ -2827,7 +2827,7 @@ static const char *GetFileNameWithoutExt(const char *filePath)
|
||||
static char fileName[MAX_FILENAMEWITHOUTEXT_LENGTH] = { 0 };
|
||||
memset(fileName, 0, MAX_FILENAMEWITHOUTEXT_LENGTH);
|
||||
|
||||
if (filePath != NULL) strncpy(fileName, GetFileName(filePath), MAX_FILENAMEWITHOUTEXT_LENGTH - 1); // Get filename with extension
|
||||
if (filePath != NULL) snprintf(fileName, MAX_FILENAMEWITHOUTEXT_LENGTH, "%s", GetFileName(filePath));
|
||||
|
||||
int fileNameLength = (int)strlen(fileName); // Get size in bytes
|
||||
|
||||
|
||||
@ -409,7 +409,7 @@ typedef struct BoneInfo {
|
||||
|
||||
// Skeleton, animation bones hierarchy
|
||||
typedef struct ModelSkeleton {
|
||||
int boneCount; // Number of bones
|
||||
unsigned int boneCount; // Number of bones
|
||||
BoneInfo *bones; // Bones information (skeleton)
|
||||
ModelAnimPose bindPose; // Bones base transformation (Transform[])
|
||||
} ModelSkeleton;
|
||||
@ -436,7 +436,7 @@ typedef struct Model {
|
||||
typedef struct ModelAnimation {
|
||||
char name[32]; // Animation name
|
||||
|
||||
int boneCount; // Number of bones (per pose)
|
||||
unsigned int boneCount; // Number of bones (per pose)
|
||||
int keyframeCount; // Number of animation key frames
|
||||
ModelAnimPose *keyframePoses; // Animation sequence keyframe poses [keyframe][pose]
|
||||
} ModelAnimation;
|
||||
|
||||
33
src/rcore.c
33
src/rcore.c
@ -108,7 +108,7 @@
|
||||
|
||||
#include <stdlib.h> // Required for: srand(), rand(), exit()
|
||||
#include <stdio.h> // Required for: FILE, fopen(), fseek(), ftell(), fread(), fwrite(), fprintf(), vprintf(), fclose(), sprintf() [Used in OpenURL()]
|
||||
#include <string.h> // Required for: strlen(), strncpy(), strcmp(), strrchr(), memset(), strcat()
|
||||
#include <string.h> // Required for: strlen(), strcmp(), strrchr(), memset(), memcpy(), strcat()
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), va_end() [Used in TraceLog()]
|
||||
#include <time.h> // Required for: time() [Used in InitTimer()]
|
||||
#include <math.h> // Required for: tan() [Used in BeginMode3D()], atan2f() [Used in LoadVrStereoConfig()]
|
||||
@ -1819,7 +1819,7 @@ void TakeScreenshot(const char *fileName)
|
||||
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[MAX_FILEPATH_LENGTH] = { 0 };
|
||||
strncpy(path, TextFormat("%s/%s", CORE.Storage.basePath, fileName), MAX_FILEPATH_LENGTH - 1);
|
||||
snprintf(path, MAX_FILEPATH_LENGTH, "%s", TextFormat("%s/%s", CORE.Storage.basePath, fileName));
|
||||
|
||||
ExportImage(image, path); // WARNING: Module required: rtextures
|
||||
RL_FREE(imgData);
|
||||
@ -1885,12 +1885,12 @@ void TraceLog(int logType, const char *text, ...)
|
||||
|
||||
switch (logType)
|
||||
{
|
||||
case LOG_TRACE: strncpy(buffer, "TRACE: ", 8); break;
|
||||
case LOG_DEBUG: strncpy(buffer, "DEBUG: ", 8); break;
|
||||
case LOG_INFO: strncpy(buffer, "INFO: ", 7); break;
|
||||
case LOG_WARNING: strncpy(buffer, "WARNING: ", 10); break;
|
||||
case LOG_ERROR: strncpy(buffer, "ERROR: ", 8); break;
|
||||
case LOG_FATAL: strncpy(buffer, "FATAL: ", 8); break;
|
||||
case LOG_TRACE: memcpy(buffer, "TRACE: ", 7); break;
|
||||
case LOG_DEBUG: memcpy(buffer, "DEBUG: ", 7); break;
|
||||
case LOG_INFO: memcpy(buffer, "INFO: ", 6); break;
|
||||
case LOG_WARNING: memcpy(buffer, "WARNING: ", 9); break;
|
||||
case LOG_ERROR: memcpy(buffer, "ERROR: ", 7); break;
|
||||
case LOG_FATAL: memcpy(buffer, "FATAL: ", 7); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@ -2063,7 +2063,7 @@ bool ExportDataAsCode(const unsigned char *data, int dataSize, const char *fileN
|
||||
|
||||
// Get file name from path
|
||||
char varFileName[256] = { 0 };
|
||||
strncpy(varFileName, GetFileNameWithoutExt(fileName), 256 - 1);
|
||||
snprintf(varFileName, 256, "%s", GetFileNameWithoutExt(fileName));
|
||||
for (int i = 0; varFileName[i] != '\0'; i++)
|
||||
{
|
||||
// Convert variable name to uppercase
|
||||
@ -2507,7 +2507,7 @@ const char *GetFileNameWithoutExt(const char *filePath)
|
||||
|
||||
if (filePath != NULL)
|
||||
{
|
||||
strncpy(fileName, GetFileName(filePath), MAX_FILENAME_LENGTH - 1); // Get filename.ext without path
|
||||
snprintf(fileName, MAX_FILENAME_LENGTH, "%s", GetFileName(filePath)); // Get filename.ext without path
|
||||
int fileNameLength = (int)strlen(fileName); // Get size in bytes
|
||||
|
||||
for (int i = fileNameLength; i > 0; i--) // Reverse search '.'
|
||||
@ -2561,7 +2561,6 @@ const char *GetDirectoryPath(const char *filePath)
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOTE: Be careful, strncpy() is not safe, it does not care about '\0'
|
||||
char *dirPathPtr = dirPath;
|
||||
if ((filePath[1] != ':') && (filePath[0] != '\\') && (filePath[0] != '/')) dirPathPtr += 2; // Skip drive letter, "C:"
|
||||
memcpy(dirPathPtr, filePath, strlen(filePath) - (strlen(lastSlash) - 1));
|
||||
@ -2579,7 +2578,7 @@ const char *GetPrevDirectoryPath(const char *dirPath)
|
||||
memset(prevDirPath, 0, MAX_FILEPATH_LENGTH);
|
||||
int dirPathLength = (int)strlen(dirPath);
|
||||
|
||||
if (dirPathLength <= 3) strncpy(prevDirPath, dirPath, MAX_FILEPATH_LENGTH - 1);
|
||||
if (dirPathLength <= 3) snprintf(prevDirPath, MAX_FILEPATH_LENGTH, "%s", dirPath);
|
||||
|
||||
for (int i = (dirPathLength - 1); (i >= 0) && (dirPathLength > 3); i--)
|
||||
{
|
||||
@ -2588,7 +2587,7 @@ const char *GetPrevDirectoryPath(const char *dirPath)
|
||||
// Check for root: "C:\" or "/"
|
||||
if (((i == 2) && (dirPath[1] ==':')) || (i == 0)) i++;
|
||||
|
||||
strncpy(prevDirPath, dirPath, i);
|
||||
memcpy(prevDirPath, dirPath, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -3379,10 +3378,10 @@ unsigned int *ComputeSHA1(const unsigned char *data, int dataSize)
|
||||
unsigned int w[80] = { 0 };
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
w[i] = (msg[offset + (i*4) + 0] << 24) |
|
||||
(msg[offset + (i*4) + 1] << 16) |
|
||||
(msg[offset + (i*4) + 2] << 8) |
|
||||
(msg[offset + (i*4) + 3]);
|
||||
w[i] = ((unsigned int)msg[offset + (i*4) + 0] << 24) |
|
||||
((unsigned int)msg[offset + (i*4) + 1] << 16) |
|
||||
((unsigned int)msg[offset + (i*4) + 2] << 8) |
|
||||
((unsigned int)msg[offset + (i*4) + 3]);
|
||||
}
|
||||
|
||||
// Message schedule: extend the sixteen 32-bit words into eighty 32-bit words:
|
||||
|
||||
@ -2469,7 +2469,7 @@ void rlLoadExtensions(void *loader)
|
||||
// NOTE: String duplication rquired because glGetString() returns a const string
|
||||
int extensionsLength = (int)strlen(extensions); // Get extensions string size in bytes
|
||||
char *extensionsDup = (char *)RL_CALLOC(extensionsLength + 1, sizeof(char)); // Allocate space for copy with additional EOL byte
|
||||
strncpy(extensionsDup, extensions, extensionsLength);
|
||||
snprintf(extensionsDup, extensionsLength, "%s", extensions);
|
||||
extList[numExt] = extensionsDup;
|
||||
|
||||
for (int i = 0; i < extensionsLength; i++)
|
||||
|
||||
@ -50,9 +50,9 @@
|
||||
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
|
||||
#include "raymath.h" // Required for: Vector3, Quaternion and Matrix functionality
|
||||
|
||||
#include <stdio.h> // Required for: sprintf()
|
||||
#include <stdio.h> // Required for: sprintf(), snprintf()
|
||||
#include <stdlib.h> // Required for: malloc(), calloc(), free()
|
||||
#include <string.h> // Required for: memcmp(), strlen(), strncpy()
|
||||
#include <string.h> // Required for: strlen(), memcmp()
|
||||
#include <math.h> // Required for: sinf(), cosf(), sqrtf(), fabsf()
|
||||
|
||||
#if SUPPORT_FILEFORMAT_OBJ || SUPPORT_FILEFORMAT_MTL
|
||||
@ -2073,7 +2073,7 @@ bool ExportMeshAsCode(Mesh mesh, const char *fileName)
|
||||
|
||||
// Get file name from path and convert variable name to uppercase
|
||||
char varFileName[256] = { 0 };
|
||||
strncpy(varFileName, GetFileNameWithoutExt(fileName), 256 - 1); // NOTE: Using function provided by [rcore] module
|
||||
snprintf(varFileName, 256, "%s", GetFileNameWithoutExt(fileName)); // NOTE: Using function provided by [rcore] module
|
||||
for (int i = 0; varFileName[i] != '\0'; i++) if ((varFileName[i] >= 'a') && (varFileName[i] <= 'z')) { varFileName[i] = varFileName[i] - 32; }
|
||||
|
||||
// Add image information
|
||||
@ -4421,7 +4421,7 @@ static Model LoadOBJ(const char *fileName)
|
||||
}
|
||||
|
||||
char currentDir[MAX_FILEPATH_LENGTH] = { 0 };
|
||||
strncpy(currentDir, GetWorkingDirectory(), MAX_FILEPATH_LENGTH - 1); // Save current working directory
|
||||
snprintf(currentDir, MAX_FILEPATH_LENGTH, "%s", GetWorkingDirectory()); // Save current working directory
|
||||
const char *workingDir = GetDirectoryPath(fileName); // Switch to OBJ directory for material path correctness
|
||||
if (CHDIR(workingDir) != 0) TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir);
|
||||
|
||||
@ -5369,15 +5369,15 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
|
||||
}
|
||||
|
||||
// Load bone info from GLTF skin data
|
||||
static BoneInfo *LoadBoneInfoGLTF(cgltf_skin skin, int *boneCount)
|
||||
static BoneInfo *LoadBoneInfoGLTF(cgltf_skin skin, unsigned int *boneCount)
|
||||
{
|
||||
*boneCount = (int)skin.joints_count;
|
||||
*boneCount = skin.joints_count;
|
||||
BoneInfo *bones = (BoneInfo *)RL_CALLOC(skin.joints_count, sizeof(BoneInfo));
|
||||
|
||||
for (unsigned int i = 0; i < skin.joints_count; i++)
|
||||
{
|
||||
cgltf_node node = *skin.joints[i];
|
||||
if (node.name != NULL) strncpy(bones[i].name, node.name, sizeof(bones[i].name) - 1);
|
||||
if (node.name != NULL) snprintf(bones[i].name, sizeof(bones[i].name), "%s", node.name);
|
||||
|
||||
// Find parent bone index by walking up the node tree past any
|
||||
// non-joint ancestors (intermediate transform nodes used by some
|
||||
@ -6660,7 +6660,7 @@ static ModelAnimation *LoadModelAnimationsGLTF(const char *fileName, int *animCo
|
||||
animDuration = (time > animDuration)? time : animDuration;
|
||||
}
|
||||
|
||||
if (animData.name != NULL) strncpy(animations[a].name, animData.name, sizeof(animations[a].name) - 1);
|
||||
if (animData.name != NULL) snprintf(animations[a].name, sizeof(animations[a].name), "%s", animData.name);
|
||||
|
||||
animations[a].keyframeCount = (int)(animDuration*GLTF_FRAMERATE) + 1;
|
||||
animations[a].keyframePoses = (Transform **)RL_CALLOC(animations[a].keyframeCount, sizeof(Transform *));
|
||||
@ -7150,7 +7150,7 @@ static Model LoadM3D(const char *fileName)
|
||||
for (i = 0; i < (int)m3d->numbone; i++)
|
||||
{
|
||||
model.skeleton.bones[i].parent = m3d->bone[i].parent;
|
||||
strncpy(model.skeleton.bones[i].name, m3d->bone[i].name, sizeof(model.skeleton.bones[i].name) - 1);
|
||||
snprintf(model.skeleton.bones[i].name, sizeof(model.skeleton.bones[i].name), "%s", m3d->bone[i].name);
|
||||
model.skeleton.bindPose[i].translation.x = m3d->vertex[m3d->bone[i].pos].x*m3d->scale;
|
||||
model.skeleton.bindPose[i].translation.y = m3d->vertex[m3d->bone[i].pos].y*m3d->scale;
|
||||
model.skeleton.bindPose[i].translation.z = m3d->vertex[m3d->bone[i].pos].z*m3d->scale;
|
||||
@ -7258,14 +7258,14 @@ static ModelAnimation *LoadModelAnimationsM3D(const char *fileName, int *animCou
|
||||
|
||||
animations[a].keyframeCount = m3d->action[a].durationmsec/M3D_ANIMDELAY;
|
||||
animations[a].keyframePoses = (Transform **)RL_CALLOC(animations[a].keyframeCount, sizeof(Transform *));
|
||||
strncpy(animations[a].name, m3d->action[a].name, sizeof(animations[a].name) - 1);
|
||||
snprintf(animations[a].name, sizeof(animations[a].name), "%s", m3d->action[a].name);
|
||||
|
||||
TRACELOG(LOG_INFO, "MODEL: [%s] Loaded animation: %s | Frames: %d | Duration: %fs", fileName, animations[a].name, animations[a].keyframeCount, m3d->action[a].durationmsec);
|
||||
|
||||
for (i = 0; i < (int)m3d->numbone; i++)
|
||||
{
|
||||
bones[i].parent = m3d->bone[i].parent;
|
||||
strncpy(bones[i].name, m3d->bone[i].name, sizeof(bones[i].name) - 1);
|
||||
snprintf(bones[i].name, sizeof(bones[i].name), "%s", m3d->bone[i].name);
|
||||
}
|
||||
|
||||
// A special, never transformed "no bone" bone, used for boneless vertices
|
||||
|
||||
22
src/rtext.c
22
src/rtext.c
@ -58,8 +58,8 @@
|
||||
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 -> Only DrawTextPro()
|
||||
|
||||
#include <stdlib.h> // Required for: malloc(), free()
|
||||
#include <stdio.h> // Required for: vsprintf()
|
||||
#include <string.h> // Required for: strcmp(), strstr(), strncpy() [Used in TextReplace()], sscanf() [Used in LoadBMFont()]
|
||||
#include <stdio.h> // Required for: vsprintf(), snprintf()
|
||||
#include <string.h> // Required for: strcmp(), strstr(), strncpy(), sscanf() [Used in LoadBMFont()]
|
||||
#include <stdarg.h> // Required for: va_list, va_start(), vsprintf(), va_end() [Used in TextFormat()]
|
||||
#include <ctype.h> // Required for: toupper(), tolower() [Used in TextToUpper(), TextToLower()]
|
||||
|
||||
@ -536,7 +536,7 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
|
||||
Font font = { 0 };
|
||||
|
||||
char fileExtLower[16] = { 0 };
|
||||
strncpy(fileExtLower, TextToLower(fileType), 16 - 1);
|
||||
snprintf(fileExtLower, 16, "%s", TextToLower(fileType));
|
||||
|
||||
font.baseSize = fontSize;
|
||||
font.glyphPadding = 0;
|
||||
@ -1030,7 +1030,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
|
||||
|
||||
// Get file name from path
|
||||
char fileNamePascal[256] = { 0 };
|
||||
strncpy(fileNamePascal, TextToPascal(GetFileNameWithoutExt(fileName)), 256 - 1);
|
||||
snprintf(fileNamePascal, 256, "%s", TextToPascal(GetFileNameWithoutExt(fileName)));
|
||||
|
||||
// Get font atlas image and size, required to estimate code file size
|
||||
// NOTE: This mechanism is highly coupled to raylib
|
||||
@ -1532,7 +1532,7 @@ char **LoadTextLines(const char *text, int *count)
|
||||
if ((text[i] == '\n') || (text[i] == '\0'))
|
||||
{
|
||||
lines[l] = (char *)RL_CALLOC(lineLen + 1, 1);
|
||||
strncpy(lines[l], &text[i - lineLen], lineLen);
|
||||
memcpy(lines[l], &text[i - lineLen], lineLen);
|
||||
lineLen = 0;
|
||||
l++;
|
||||
}
|
||||
@ -1755,8 +1755,8 @@ char *GetTextBetween(const char *text, const char *begin, const char *end)
|
||||
{
|
||||
endIndex += (beginIndex + beginLen);
|
||||
int len = (endIndex - beginIndex - beginLen);
|
||||
if (len < (MAX_TEXT_BUFFER_LENGTH - 1)) strncpy(buffer, text + beginIndex + beginLen, len);
|
||||
else strncpy(buffer, text + beginIndex + beginLen, MAX_TEXT_BUFFER_LENGTH - 1);
|
||||
if (len < (MAX_TEXT_BUFFER_LENGTH - 1)) memcpy(buffer, text + beginIndex + beginLen, len);
|
||||
else snprintf(buffer, MAX_TEXT_BUFFER_LENGTH, "%s", text + beginIndex + beginLen);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1764,7 +1764,7 @@ char *GetTextBetween(const char *text, const char *begin, const char *end)
|
||||
}
|
||||
|
||||
// Replace text string
|
||||
// REQUIRES: strstr(), strncpy()
|
||||
// REQUIRES: strstr(), memcpy()
|
||||
// NOTE: Limited text replace functionality, using static string
|
||||
char *TextReplace(const char *text, const char *search, const char *replacement)
|
||||
{
|
||||
@ -1821,7 +1821,7 @@ char *TextReplace(const char *text, const char *search, const char *replacement)
|
||||
|
||||
// Copy remaind text part after replacement to result (pointed by moving temp)
|
||||
// NOTE: Text pointer internal copy has been updated along the process
|
||||
strncpy(tempPtr, text, TextLength(text));
|
||||
memcpy(tempPtr, text, TextLength(text));
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "Text with replacement is longer than internal buffer, use TextReplaceAlloc()");
|
||||
}
|
||||
@ -1830,7 +1830,7 @@ char *TextReplace(const char *text, const char *search, const char *replacement)
|
||||
}
|
||||
|
||||
// Replace text string
|
||||
// REQUIRES: strstr(), strncpy()
|
||||
// REQUIRES: strstr(), memcpy()
|
||||
// WARNING: Allocated memory must be manually freed
|
||||
char *TextReplaceAlloc(const char *text, const char *search, const char *replacement)
|
||||
{
|
||||
@ -1887,7 +1887,7 @@ char *TextReplaceAlloc(const char *text, const char *search, const char *replace
|
||||
|
||||
// Copy remaind text part after replacement to result (pointed by moving temp)
|
||||
// NOTE: Text pointer internal copy has been updated along the process
|
||||
strncpy(temp, text, TextLength(text));
|
||||
memcpy(temp, text, TextLength(text));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -813,7 +813,7 @@ bool ExportImageAsCode(Image image, const char *fileName)
|
||||
|
||||
// Get file name from path and convert variable name to uppercase
|
||||
char varFileName[256] = { 0 };
|
||||
strncpy(varFileName, GetFileNameWithoutExt(fileName), 256 - 1); // NOTE: Using function provided by [rcore] module
|
||||
snprintf(varFileName, 256, "%s", GetFileNameWithoutExt(fileName)); // NOTE: Using function provided by [rcore] module
|
||||
for (int i = 0; varFileName[i] != '\0'; i++) if ((varFileName[i] >= 'a') && (varFileName[i] <= 'z')) { varFileName[i] = varFileName[i] - 32; }
|
||||
|
||||
// Add image information
|
||||
|
||||
@ -2331,7 +2331,7 @@ static rlExampleInfo *LoadExampleInfo(const char *exFileName)
|
||||
// Example found in collection
|
||||
exInfo = (rlExampleInfo *)RL_CALLOC(1, sizeof(rlExampleInfo));
|
||||
|
||||
strncpy(exInfo->name, GetFileNameWithoutExt(exFileName), 128 - 1);
|
||||
snprintf(exInfo->name, 128, "%s", GetFileNameWithoutExt(exFileName));
|
||||
strncpy(exInfo->category, exInfo->name, TextFindIndex(exInfo->name, "_"));
|
||||
|
||||
char *exText = LoadFileText(exFileName);
|
||||
@ -2377,7 +2377,7 @@ static rlExampleInfo *LoadExampleInfo(const char *exFileName)
|
||||
int copyrightIndex = TextFindIndex(exText, "Copyright (c) ");
|
||||
int yearStartIndex = copyrightIndex + 14;
|
||||
char yearText[5] = { 0 };
|
||||
strncpy(yearText, exText + yearStartIndex, 4);
|
||||
snprintf(yearText, 5, "%s", exText + yearStartIndex);
|
||||
exInfo->yearCreated = TextToInteger(yearText);
|
||||
// Check for review year included (or just use creation year)
|
||||
if (exText[yearStartIndex + 4] == '-') strncpy(yearText, exText + yearStartIndex + 5, 4);
|
||||
@ -2425,7 +2425,7 @@ static int ParseExampleInfoLine(const char *line, rlExampleInfo *entry)
|
||||
#define MAX_EXAMPLE_INFO_LINE_LEN 512
|
||||
|
||||
char temp[MAX_EXAMPLE_INFO_LINE_LEN] = { 0 };
|
||||
strncpy(temp, line, MAX_EXAMPLE_INFO_LINE_LEN);
|
||||
snprintf(temp, MAX_EXAMPLE_INFO_LINE_LEN, "%s", line);
|
||||
temp[MAX_EXAMPLE_INFO_LINE_LEN - 1] = '\0'; // Ensure null termination
|
||||
|
||||
int tokenCount = 0;
|
||||
@ -2902,7 +2902,7 @@ static void UpdateWebMetadata(const char *exHtmlPath, const char *exFilePath)
|
||||
char exTitle[64] = { 0 }; // Example title: fileName without extension, replacing underscores by spaces
|
||||
|
||||
// Get example name: replace underscore by spaces
|
||||
strncpy(exName, GetFileNameWithoutExt(exHtmlPathCopy), 64 - 1);
|
||||
snprintf(exName, 64, "%s", GetFileNameWithoutExt(exHtmlPathCopy));
|
||||
strcpy(exTitle, exName);
|
||||
for (int i = 0; (i < 64) && (exTitle[i] != '\0'); i++) { if (exTitle[i] == '_') exTitle[i] = ' '; }
|
||||
|
||||
|
||||
@ -968,7 +968,7 @@
|
||||
"description": "Skeleton, animation bones hierarchy",
|
||||
"fields": [
|
||||
{
|
||||
"type": "int",
|
||||
"type": "unsigned int",
|
||||
"name": "boneCount",
|
||||
"description": "Number of bones"
|
||||
},
|
||||
@ -1045,7 +1045,7 @@
|
||||
"description": "Animation name"
|
||||
},
|
||||
{
|
||||
"type": "int",
|
||||
"type": "unsigned int",
|
||||
"name": "boneCount",
|
||||
"description": "Number of bones (per pose)"
|
||||
},
|
||||
|
||||
@ -968,7 +968,7 @@ return {
|
||||
description = "Skeleton, animation bones hierarchy",
|
||||
fields = {
|
||||
{
|
||||
type = "int",
|
||||
type = "unsigned int",
|
||||
name = "boneCount",
|
||||
description = "Number of bones"
|
||||
},
|
||||
@ -1045,7 +1045,7 @@ return {
|
||||
description = "Animation name"
|
||||
},
|
||||
{
|
||||
type = "int",
|
||||
type = "unsigned int",
|
||||
name = "boneCount",
|
||||
description = "Number of bones (per pose)"
|
||||
},
|
||||
|
||||
@ -611,7 +611,7 @@
|
||||
((name "ModelSkeleton")
|
||||
(description "Skeleton, animation bones hierarchy")
|
||||
(fields
|
||||
((type "int")
|
||||
((type "unsigned int")
|
||||
(name "boneCount")
|
||||
(description "Number of bones"))
|
||||
((type "BoneInfo *")
|
||||
@ -658,7 +658,7 @@
|
||||
((type "char[32]")
|
||||
(name "name")
|
||||
(description "Animation name"))
|
||||
((type "int")
|
||||
((type "unsigned int")
|
||||
(name "boneCount")
|
||||
(description "Number of bones (per pose)"))
|
||||
((type "int")
|
||||
|
||||
@ -448,7 +448,7 @@ Struct 20: BoneInfo (2 fields)
|
||||
Struct 21: ModelSkeleton (3 fields)
|
||||
Name: ModelSkeleton
|
||||
Description: Skeleton, animation bones hierarchy
|
||||
Field[1]: int boneCount // Number of bones
|
||||
Field[1]: unsigned int boneCount // Number of bones
|
||||
Field[2]: BoneInfo * bones // Bones information (skeleton)
|
||||
Field[3]: ModelAnimPose bindPose // Bones base transformation (Transform[])
|
||||
Struct 22: Model (9 fields)
|
||||
@ -467,7 +467,7 @@ Struct 23: ModelAnimation (4 fields)
|
||||
Name: ModelAnimation
|
||||
Description: ModelAnimation, contains a full animation sequence
|
||||
Field[1]: char[32] name // Animation name
|
||||
Field[2]: int boneCount // Number of bones (per pose)
|
||||
Field[2]: unsigned int boneCount // Number of bones (per pose)
|
||||
Field[3]: int keyframeCount // Number of animation key frames
|
||||
Field[4]: ModelAnimPose * keyframePoses // Animation sequence keyframe poses [keyframe][pose]
|
||||
Struct 24: Ray (2 fields)
|
||||
|
||||
@ -201,7 +201,7 @@
|
||||
<Field type="int" name="parent" desc="Bone parent" />
|
||||
</Struct>
|
||||
<Struct name="ModelSkeleton" fieldCount="3" desc="Skeleton, animation bones hierarchy">
|
||||
<Field type="int" name="boneCount" desc="Number of bones" />
|
||||
<Field type="unsigned int" name="boneCount" desc="Number of bones" />
|
||||
<Field type="BoneInfo *" name="bones" desc="Bones information (skeleton)" />
|
||||
<Field type="ModelAnimPose" name="bindPose" desc="Bones base transformation (Transform[])" />
|
||||
</Struct>
|
||||
@ -218,7 +218,7 @@
|
||||
</Struct>
|
||||
<Struct name="ModelAnimation" fieldCount="4" desc="ModelAnimation, contains a full animation sequence">
|
||||
<Field type="char[32]" name="name" desc="Animation name" />
|
||||
<Field type="int" name="boneCount" desc="Number of bones (per pose)" />
|
||||
<Field type="unsigned int" name="boneCount" desc="Number of bones (per pose)" />
|
||||
<Field type="int" name="keyframeCount" desc="Number of animation key frames" />
|
||||
<Field type="ModelAnimPose *" name="keyframePoses" desc="Animation sequence keyframe poses [keyframe][pose]" />
|
||||
</Struct>
|
||||
|
||||
Reference in New Issue
Block a user