Remove trailing spaces
This commit is contained in:
parent
e40c26dea5
commit
b75511248d
13 changed files with 304 additions and 304 deletions
74
src/camera.h
74
src/camera.h
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
* #define CAMERA_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
*
|
||||
* #define CAMERA_STANDALONE
|
||||
|
@ -77,7 +77,7 @@
|
|||
} Camera3D;
|
||||
|
||||
typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D
|
||||
|
||||
|
||||
// Camera system modes
|
||||
typedef enum {
|
||||
CAMERA_CUSTOM = 0,
|
||||
|
@ -113,8 +113,8 @@ void UpdateCamera(Camera *camera); // Update camera pos
|
|||
void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera)
|
||||
void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera)
|
||||
void SetCameraSmoothZoomControl(int szoomKey); // Set camera smooth zoom key to combine with mouse (free camera)
|
||||
void SetCameraMoveControls(int frontKey, int backKey,
|
||||
int rightKey, int leftKey,
|
||||
void SetCameraMoveControls(int frontKey, int backKey,
|
||||
int rightKey, int leftKey,
|
||||
int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras)
|
||||
#endif
|
||||
|
||||
|
@ -188,21 +188,21 @@ void SetCameraMoveControls(int frontKey, int backKey,
|
|||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
// Camera move modes (first person and third person cameras)
|
||||
typedef enum {
|
||||
MOVE_FRONT = 0,
|
||||
MOVE_BACK,
|
||||
MOVE_RIGHT,
|
||||
MOVE_LEFT,
|
||||
MOVE_UP,
|
||||
MOVE_DOWN
|
||||
typedef enum {
|
||||
MOVE_FRONT = 0,
|
||||
MOVE_BACK,
|
||||
MOVE_RIGHT,
|
||||
MOVE_LEFT,
|
||||
MOVE_UP,
|
||||
MOVE_DOWN
|
||||
} CameraMove;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
static Vector2 cameraAngle = { 0.0f, 0.0f }; // Camera angle in plane XZ
|
||||
static float cameraTargetDistance = 0.0f; // Camera distance from position to target
|
||||
static float playerEyesPosition = 1.85f; // Default player eyes position from ground (in meters)
|
||||
static float cameraTargetDistance = 0.0f; // Camera distance from position to target
|
||||
static float playerEyesPosition = 1.85f; // Default player eyes position from ground (in meters)
|
||||
|
||||
static int cameraMoveControl[6] = { 'W', 'S', 'D', 'A', 'E', 'Q' };
|
||||
static int cameraPanControlKey = 2; // raylib: MOUSE_MIDDLE_BUTTON
|
||||
|
@ -236,21 +236,21 @@ void SetCameraMode(Camera camera, int mode)
|
|||
{
|
||||
Vector3 v1 = camera.position;
|
||||
Vector3 v2 = camera.target;
|
||||
|
||||
|
||||
float dx = v2.x - v1.x;
|
||||
float dy = v2.y - v1.y;
|
||||
float dz = v2.z - v1.z;
|
||||
|
||||
|
||||
cameraTargetDistance = sqrtf(dx*dx + dy*dy + dz*dz);
|
||||
|
||||
|
||||
Vector2 distance = { 0.0f, 0.0f };
|
||||
distance.x = sqrtf(dx*dx + dz*dz);
|
||||
distance.y = sqrtf(dx*dx + dy*dy);
|
||||
|
||||
|
||||
// Camera angle calculation
|
||||
cameraAngle.x = asinf( (float)fabs(dx)/distance.x); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
||||
cameraAngle.y = -asinf( (float)fabs(dy)/distance.y); // Camera angle in plane XY (0 aligned with X, move positive CW)
|
||||
|
||||
|
||||
playerEyesPosition = camera.position.y;
|
||||
|
||||
// Lock cursor for first person and third person cameras
|
||||
|
@ -272,24 +272,24 @@ void UpdateCamera(Camera *camera)
|
|||
static Vector2 previousMousePosition = { 0.0f, 0.0f };
|
||||
|
||||
// TODO: Compute cameraTargetDistance and cameraAngle here
|
||||
|
||||
|
||||
// Mouse movement detection
|
||||
Vector2 mousePositionDelta = { 0.0f, 0.0f };
|
||||
Vector2 mousePosition = GetMousePosition();
|
||||
int mouseWheelMove = GetMouseWheelMove();
|
||||
|
||||
|
||||
// Keys input detection
|
||||
bool panKey = IsMouseButtonDown(cameraPanControlKey);
|
||||
bool altKey = IsKeyDown(cameraAltControlKey);
|
||||
bool szoomKey = IsKeyDown(cameraSmoothZoomControlKey);
|
||||
|
||||
|
||||
bool direction[6] = { IsKeyDown(cameraMoveControl[MOVE_FRONT]),
|
||||
IsKeyDown(cameraMoveControl[MOVE_BACK]),
|
||||
IsKeyDown(cameraMoveControl[MOVE_RIGHT]),
|
||||
IsKeyDown(cameraMoveControl[MOVE_LEFT]),
|
||||
IsKeyDown(cameraMoveControl[MOVE_UP]),
|
||||
IsKeyDown(cameraMoveControl[MOVE_DOWN]) };
|
||||
|
||||
|
||||
// TODO: Consider touch inputs for camera
|
||||
|
||||
if (cameraMode != CAMERA_CUSTOM)
|
||||
|
@ -384,7 +384,7 @@ void UpdateCamera(Camera *camera)
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update camera position with changes
|
||||
camera->position.x = sinf(cameraAngle.x)*cameraTargetDistance*cosf(cameraAngle.y) + camera->target.x;
|
||||
camera->position.y = ((cameraAngle.y <= 0.0f)? 1 : -1)*sinf(cameraAngle.y)*cameraTargetDistance*sinf(cameraAngle.y) + camera->target.y;
|
||||
|
@ -395,15 +395,15 @@ void UpdateCamera(Camera *camera)
|
|||
{
|
||||
cameraAngle.x += CAMERA_ORBITAL_SPEED; // Camera orbit angle
|
||||
cameraTargetDistance -= (mouseWheelMove*CAMERA_MOUSE_SCROLL_SENSITIVITY); // Camera zoom
|
||||
|
||||
|
||||
// Camera distance clamp
|
||||
if (cameraTargetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) cameraTargetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP;
|
||||
|
||||
|
||||
// Update camera position with changes
|
||||
camera->position.x = sinf(cameraAngle.x)*cameraTargetDistance*cosf(cameraAngle.y) + camera->target.x;
|
||||
camera->position.y = ((cameraAngle.y <= 0.0f)? 1 : -1)*sinf(cameraAngle.y)*cameraTargetDistance*sinf(cameraAngle.y) + camera->target.y;
|
||||
camera->position.z = cosf(cameraAngle.x)*cameraTargetDistance*cosf(cameraAngle.y) + camera->target.z;
|
||||
|
||||
|
||||
} break;
|
||||
case CAMERA_FIRST_PERSON:
|
||||
{
|
||||
|
@ -411,11 +411,11 @@ void UpdateCamera(Camera *camera)
|
|||
sinf(cameraAngle.x)*direction[MOVE_FRONT] -
|
||||
cosf(cameraAngle.x)*direction[MOVE_LEFT] +
|
||||
cosf(cameraAngle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||
|
||||
|
||||
camera->position.y += (sinf(cameraAngle.y)*direction[MOVE_FRONT] -
|
||||
sinf(cameraAngle.y)*direction[MOVE_BACK] +
|
||||
1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||
|
||||
|
||||
camera->position.z += (cosf(cameraAngle.x)*direction[MOVE_BACK] -
|
||||
cosf(cameraAngle.x)*direction[MOVE_FRONT] +
|
||||
sinf(cameraAngle.x)*direction[MOVE_LEFT] -
|
||||
|
@ -424,11 +424,11 @@ void UpdateCamera(Camera *camera)
|
|||
bool isMoving = false; // Required for swinging
|
||||
|
||||
for (int i = 0; i < 6; i++) if (direction[i]) { isMoving = true; break; }
|
||||
|
||||
|
||||
// Camera orientation calculation
|
||||
cameraAngle.x += (mousePositionDelta.x*-CAMERA_MOUSE_MOVE_SENSITIVITY);
|
||||
cameraAngle.y += (mousePositionDelta.y*-CAMERA_MOUSE_MOVE_SENSITIVITY);
|
||||
|
||||
|
||||
// Angle clamp
|
||||
if (cameraAngle.y > CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD) cameraAngle.y = CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD;
|
||||
else if (cameraAngle.y < CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD) cameraAngle.y = CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD;
|
||||
|
@ -437,7 +437,7 @@ void UpdateCamera(Camera *camera)
|
|||
camera->target.x = camera->position.x - sinf(cameraAngle.x)*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 - cosf(cameraAngle.x)*CAMERA_FIRST_PERSON_FOCUS_DISTANCE;
|
||||
|
||||
|
||||
if (isMoving) swingCounter++;
|
||||
|
||||
// Camera position update
|
||||
|
@ -446,8 +446,8 @@ void UpdateCamera(Camera *camera)
|
|||
|
||||
camera->up.x = sinf(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;
|
||||
case CAMERA_THIRD_PERSON:
|
||||
{
|
||||
|
@ -455,11 +455,11 @@ void UpdateCamera(Camera *camera)
|
|||
sinf(cameraAngle.x)*direction[MOVE_FRONT] -
|
||||
cosf(cameraAngle.x)*direction[MOVE_LEFT] +
|
||||
cosf(cameraAngle.x)*direction[MOVE_RIGHT])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||
|
||||
|
||||
camera->position.y += (sinf(cameraAngle.y)*direction[MOVE_FRONT] -
|
||||
sinf(cameraAngle.y)*direction[MOVE_BACK] +
|
||||
1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])/PLAYER_MOVEMENT_SENSITIVITY;
|
||||
|
||||
|
||||
camera->position.z += (cosf(cameraAngle.x)*direction[MOVE_BACK] -
|
||||
cosf(cameraAngle.x)*direction[MOVE_FRONT] +
|
||||
sinf(cameraAngle.x)*direction[MOVE_LEFT] -
|
||||
|
@ -468,7 +468,7 @@ void UpdateCamera(Camera *camera)
|
|||
// Camera orientation calculation
|
||||
cameraAngle.x += (mousePositionDelta.x*-CAMERA_MOUSE_MOVE_SENSITIVITY);
|
||||
cameraAngle.y += (mousePositionDelta.y*-CAMERA_MOUSE_MOVE_SENSITIVITY);
|
||||
|
||||
|
||||
// Angle clamp
|
||||
if (cameraAngle.y > CAMERA_THIRD_PERSON_MIN_CLAMP*DEG2RAD) cameraAngle.y = CAMERA_THIRD_PERSON_MIN_CLAMP*DEG2RAD;
|
||||
else if (cameraAngle.y < CAMERA_THIRD_PERSON_MAX_CLAMP*DEG2RAD) cameraAngle.y = CAMERA_THIRD_PERSON_MAX_CLAMP*DEG2RAD;
|
||||
|
@ -487,7 +487,7 @@ void UpdateCamera(Camera *camera)
|
|||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set camera pan key to combine with mouse movement (free camera)
|
||||
|
|
50
src/core.c
50
src/core.c
|
@ -579,7 +579,7 @@ static void InitTerminal(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
ioctl(STDIN_FILENO, KDSKBMODE, K_XLATE);
|
||||
}
|
||||
|
||||
|
@ -590,7 +590,7 @@ static void InitTerminal(void)
|
|||
static void RestoreTerminal(void)
|
||||
{
|
||||
TraceLog(LOG_INFO, "Restore Terminal ...");
|
||||
|
||||
|
||||
// Reset to default keyboard settings
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &defaultKeyboardSettings);
|
||||
|
||||
|
@ -774,7 +774,7 @@ void CloseWindow(void)
|
|||
pthread_join(eventWorkers[i].threadId, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (gamepadThreadId) pthread_join(gamepadThreadId, NULL);
|
||||
#endif
|
||||
|
||||
|
@ -1207,7 +1207,7 @@ void EndDrawing(void)
|
|||
// we draw a small rectangle for user reference
|
||||
DrawRectangle(mousePosition.x, mousePosition.y, 3, 3, MAROON);
|
||||
#endif
|
||||
|
||||
|
||||
rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
|
||||
|
||||
#if defined(SUPPORT_GIF_RECORDING)
|
||||
|
@ -1270,10 +1270,10 @@ void BeginMode2D(Camera2D camera)
|
|||
rlglDraw(); // Draw Buffers (Only OpenGL 3+ and ES2)
|
||||
|
||||
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
|
||||
|
||||
|
||||
// Apply screen scaling if required
|
||||
rlMultMatrixf(MatrixToFloat(screenScaling));
|
||||
|
||||
|
||||
// Apply 2d camera transformation to modelview
|
||||
rlMultMatrixf(MatrixToFloat(GetCameraMatrix2D(camera)));
|
||||
}
|
||||
|
@ -1465,7 +1465,7 @@ Matrix GetCameraMatrix(Camera camera)
|
|||
}
|
||||
|
||||
// Returns camera 2d transform matrix
|
||||
Matrix GetCameraMatrix2D(Camera2D camera)
|
||||
Matrix GetCameraMatrix2D(Camera2D camera)
|
||||
{
|
||||
Matrix matTransform = { 0 };
|
||||
// The camera in world-space is set by
|
||||
|
@ -1486,9 +1486,9 @@ Matrix GetCameraMatrix2D(Camera2D camera)
|
|||
Matrix matRotation = MatrixRotate((Vector3){ 0.0f, 0.0f, 1.0f }, camera.rotation*DEG2RAD);
|
||||
Matrix matScale = MatrixScale(camera.zoom, camera.zoom, 1.0f);
|
||||
Matrix matTranslation = MatrixTranslate(camera.offset.x, camera.offset.y, 0.0f);
|
||||
|
||||
|
||||
matTransform = MatrixMultiply(MatrixMultiply(matOrigin, MatrixMultiply(matScale, matRotation)), matTranslation);
|
||||
|
||||
|
||||
return matTransform;
|
||||
}
|
||||
|
||||
|
@ -1535,20 +1535,20 @@ Vector2 GetWorldToScreen(Vector3 position, Camera camera)
|
|||
}
|
||||
|
||||
// Returns the screen space position for a 2d camera world space position
|
||||
Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera)
|
||||
Vector2 GetWorldToScreen2D(Vector2 position, Camera2D camera)
|
||||
{
|
||||
Matrix matCamera = GetCameraMatrix2D(camera);
|
||||
Vector3 transform = Vector3Transform((Vector3){ position.x, position.y, 0 }, matCamera);
|
||||
|
||||
|
||||
return (Vector2){ transform.x, transform.y };
|
||||
}
|
||||
|
||||
// Returns the world space position for a 2d camera screen space position
|
||||
Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera)
|
||||
Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera)
|
||||
{
|
||||
Matrix invMatCamera = MatrixInvert(GetCameraMatrix2D(camera));
|
||||
Vector3 transform = Vector3Transform((Vector3){ position.x, position.y, 0 }, invMatCamera);
|
||||
|
||||
|
||||
return (Vector2){ transform.x, transform.y };
|
||||
}
|
||||
|
||||
|
@ -1797,10 +1797,10 @@ bool IsFileExtension(const char *fileName, const char *ext)
|
|||
{
|
||||
bool result = false;
|
||||
const char *fileExt = GetExtension(fileName);
|
||||
|
||||
|
||||
int extCount = 0;
|
||||
const char **checkExts = TextSplit(ext, ';', &extCount);
|
||||
|
||||
|
||||
for (int i = 0; i < extCount; i++)
|
||||
{
|
||||
if (strcmp(fileExt, checkExts[i] + 1) == 0)
|
||||
|
@ -1905,9 +1905,9 @@ const char *GetPrevDirectoryPath(const char *dirPath)
|
|||
static char prevDirPath[MAX_FILEPATH_LENGTH];
|
||||
memset(prevDirPath, 0, MAX_FILEPATH_LENGTH);
|
||||
int pathLen = strlen(dirPath);
|
||||
|
||||
|
||||
if (pathLen <= 3) strcpy(prevDirPath, dirPath);
|
||||
|
||||
|
||||
for (int i = (pathLen - 1); (i > 0) && (pathLen > 3); i--)
|
||||
{
|
||||
if ((dirPath[i] == '\\') || (dirPath[i] == '/'))
|
||||
|
@ -1917,7 +1917,7 @@ const char *GetPrevDirectoryPath(const char *dirPath)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return prevDirPath;
|
||||
}
|
||||
|
||||
|
@ -2034,9 +2034,9 @@ long GetFileModTime(const char *fileName)
|
|||
unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLength)
|
||||
{
|
||||
#define COMPRESSION_QUALITY_DEFLATE 8
|
||||
|
||||
|
||||
unsigned char *compData = NULL;
|
||||
|
||||
|
||||
#if defined(SUPPORT_COMPRESSION_API)
|
||||
compData = stbi_zlib_compress(data, dataLength, compDataLength, COMPRESSION_QUALITY_DEFLATE);
|
||||
#endif
|
||||
|
@ -2048,7 +2048,7 @@ unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLe
|
|||
unsigned char *DecompressData(unsigned char *compData, int compDataLength, int *dataLength)
|
||||
{
|
||||
char *data = NULL;
|
||||
|
||||
|
||||
#if defined(SUPPORT_COMPRESSION_API)
|
||||
data = stbi_zlib_decode_malloc((char *)compData, compDataLength, dataLength);
|
||||
#endif
|
||||
|
@ -2653,9 +2653,9 @@ static bool InitGraphicsDevice(int width, int height)
|
|||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
|
||||
#else
|
||||
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
|
||||
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -4920,7 +4920,7 @@ static void *EventThread(void *arg)
|
|||
// TODO: This fifo is not fully threadsafe with multiple writers, so multiple keyboards hitting a key at the exact same time could miss a key (double write to head before it was incremented)
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
currentKeyState[keycode] = event.value;
|
||||
if (event.value == 1) lastKeyPressed = keycode; // Register last key pressed
|
||||
|
||||
|
@ -4934,7 +4934,7 @@ static void *EventThread(void *arg)
|
|||
#endif
|
||||
|
||||
if (currentKeyState[exitKey] == 1) windowShouldClose = true;
|
||||
|
||||
|
||||
TraceLog(LOG_DEBUG, "KEY%s ScanCode: %4i KeyCode: %4i",event.value == 0 ? "UP":"DOWN", event.code, keycode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
* #define GESTURES_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
*
|
||||
* #define GESTURES_STANDALONE
|
||||
|
@ -216,8 +216,8 @@ static float pinchDistance = 0.0f; // PINCH displacement distance (
|
|||
|
||||
static int currentGesture = GESTURE_NONE; // Current detected gesture
|
||||
|
||||
// Enabled gestures flags, all gestures enabled by default
|
||||
static unsigned int enabledGestures = 0b0000001111111111;
|
||||
// Enabled gestures flags, all gestures enabled by default
|
||||
static unsigned int enabledGestures = 0b0000001111111111;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
|
@ -251,13 +251,13 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
{
|
||||
// Reset required variables
|
||||
pointCount = event.pointCount; // Required on UpdateGestures()
|
||||
|
||||
|
||||
if (pointCount < 2)
|
||||
{
|
||||
if (event.touchAction == TOUCH_DOWN)
|
||||
{
|
||||
tapCounter++; // Tap counter
|
||||
|
||||
|
||||
// Detect GESTURE_DOUBLE_TAP
|
||||
if ((currentGesture == GESTURE_NONE) && (tapCounter >= 2) && ((GetCurrentTime() - eventTime) < TAP_TIMEOUT) && (Vector2Distance(touchDownPosition, event.position[0]) < DOUBLETAP_RANGE))
|
||||
{
|
||||
|
@ -269,15 +269,15 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
tapCounter = 1;
|
||||
currentGesture = GESTURE_TAP;
|
||||
}
|
||||
|
||||
|
||||
touchDownPosition = event.position[0];
|
||||
touchDownDragPosition = event.position[0];
|
||||
|
||||
|
||||
touchUpPosition = touchDownPosition;
|
||||
eventTime = GetCurrentTime();
|
||||
|
||||
|
||||
firstTouchId = event.pointerId[0];
|
||||
|
||||
|
||||
dragVector = (Vector2){ 0.0f, 0.0f };
|
||||
}
|
||||
else if (event.touchAction == TOUCH_UP)
|
||||
|
@ -287,15 +287,15 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
// NOTE: dragIntensity dependend on the resolution of the screen
|
||||
dragDistance = Vector2Distance(touchDownPosition, touchUpPosition);
|
||||
dragIntensity = dragDistance/(float)((GetCurrentTime() - swipeTime));
|
||||
|
||||
|
||||
startMoving = false;
|
||||
|
||||
|
||||
// Detect GESTURE_SWIPE
|
||||
if ((dragIntensity > FORCE_TO_SWIPE) && (firstTouchId == event.pointerId[0]))
|
||||
{
|
||||
// NOTE: Angle should be inverted in Y
|
||||
dragAngle = 360.0f - Vector2Angle(touchDownPosition, touchUpPosition);
|
||||
|
||||
|
||||
if ((dragAngle < 30) || (dragAngle > 330)) currentGesture = GESTURE_SWIPE_RIGHT; // Right
|
||||
else if ((dragAngle > 30) && (dragAngle < 120)) currentGesture = GESTURE_SWIPE_UP; // Up
|
||||
else if ((dragAngle > 120) && (dragAngle < 210)) currentGesture = GESTURE_SWIPE_LEFT; // Left
|
||||
|
@ -307,31 +307,31 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
dragDistance = 0.0f;
|
||||
dragIntensity = 0.0f;
|
||||
dragAngle = 0.0f;
|
||||
|
||||
|
||||
currentGesture = GESTURE_NONE;
|
||||
}
|
||||
|
||||
|
||||
touchDownDragPosition = (Vector2){ 0.0f, 0.0f };
|
||||
pointCount = 0;
|
||||
}
|
||||
else if (event.touchAction == TOUCH_MOVE)
|
||||
{
|
||||
if (currentGesture == GESTURE_DRAG) eventTime = GetCurrentTime();
|
||||
|
||||
|
||||
if (!startMoving)
|
||||
{
|
||||
swipeTime = GetCurrentTime();
|
||||
startMoving = true;
|
||||
}
|
||||
|
||||
|
||||
moveDownPosition = event.position[0];
|
||||
|
||||
|
||||
if (currentGesture == GESTURE_HOLD)
|
||||
{
|
||||
if (resetHold) touchDownPosition = event.position[0];
|
||||
|
||||
|
||||
resetHold = false;
|
||||
|
||||
|
||||
// Detect GESTURE_DRAG
|
||||
if (Vector2Distance(touchDownPosition, moveDownPosition) >= MINIMUM_DRAG)
|
||||
{
|
||||
|
@ -339,7 +339,7 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
currentGesture = GESTURE_DRAG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dragVector.x = moveDownPosition.x - touchDownDragPosition.x;
|
||||
dragVector.y = moveDownPosition.y - touchDownDragPosition.y;
|
||||
}
|
||||
|
@ -350,28 +350,28 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
{
|
||||
touchDownPosition = event.position[0];
|
||||
touchDownPosition2 = event.position[1];
|
||||
|
||||
|
||||
//pinchDistance = Vector2Distance(touchDownPosition, touchDownPosition2);
|
||||
|
||||
|
||||
pinchVector.x = touchDownPosition2.x - touchDownPosition.x;
|
||||
pinchVector.y = touchDownPosition2.y - touchDownPosition.y;
|
||||
|
||||
|
||||
currentGesture = GESTURE_HOLD;
|
||||
timeHold = GetCurrentTime();
|
||||
}
|
||||
else if (event.touchAction == TOUCH_MOVE)
|
||||
{
|
||||
pinchDistance = Vector2Distance(moveDownPosition, moveDownPosition2);
|
||||
|
||||
|
||||
touchDownPosition = moveDownPosition;
|
||||
touchDownPosition2 = moveDownPosition2;
|
||||
|
||||
|
||||
moveDownPosition = event.position[0];
|
||||
moveDownPosition2 = event.position[1];
|
||||
|
||||
|
||||
pinchVector.x = moveDownPosition2.x - moveDownPosition.x;
|
||||
pinchVector.y = moveDownPosition2.y - moveDownPosition.y;
|
||||
|
||||
|
||||
if ((Vector2Distance(touchDownPosition, moveDownPosition) >= MINIMUM_PINCH) || (Vector2Distance(touchDownPosition2, moveDownPosition2) >= MINIMUM_PINCH))
|
||||
{
|
||||
if ((Vector2Distance(moveDownPosition, moveDownPosition2) - pinchDistance) < 0) currentGesture = GESTURE_PINCH_IN;
|
||||
|
@ -382,7 +382,7 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
currentGesture = GESTURE_HOLD;
|
||||
timeHold = GetCurrentTime();
|
||||
}
|
||||
|
||||
|
||||
// NOTE: Angle should be inverted in Y
|
||||
pinchAngle = 360.0f - Vector2Angle(moveDownPosition, moveDownPosition2);
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
pinchAngle = 0.0f;
|
||||
pinchVector = (Vector2){ 0.0f, 0.0f };
|
||||
pointCount = 0;
|
||||
|
||||
|
||||
currentGesture = GESTURE_NONE;
|
||||
}
|
||||
}
|
||||
|
@ -409,14 +409,14 @@ void UpdateGestures(void)
|
|||
currentGesture = GESTURE_HOLD;
|
||||
timeHold = GetCurrentTime();
|
||||
}
|
||||
|
||||
|
||||
if (((GetCurrentTime() - eventTime) > TAP_TIMEOUT) && (currentGesture == GESTURE_DRAG) && (pointCount < 2))
|
||||
{
|
||||
currentGesture = GESTURE_HOLD;
|
||||
timeHold = GetCurrentTime();
|
||||
resetHold = true;
|
||||
}
|
||||
|
||||
|
||||
// Detect GESTURE_NONE
|
||||
if ((currentGesture == GESTURE_SWIPE_RIGHT) || (currentGesture == GESTURE_SWIPE_UP) || (currentGesture == GESTURE_SWIPE_LEFT) || (currentGesture == GESTURE_SWIPE_DOWN))
|
||||
{
|
||||
|
@ -428,7 +428,7 @@ void UpdateGestures(void)
|
|||
int GetTouchPointsCount(void)
|
||||
{
|
||||
// NOTE: point count is calculated when ProcessGestureEvent(GestureEvent event) is called
|
||||
|
||||
|
||||
return pointCount;
|
||||
}
|
||||
|
||||
|
@ -443,11 +443,11 @@ int GetGestureDetected(void)
|
|||
float GetGestureHoldDuration(void)
|
||||
{
|
||||
// NOTE: time is calculated on current gesture HOLD
|
||||
|
||||
|
||||
double time = 0.0;
|
||||
|
||||
|
||||
if (currentGesture == GESTURE_HOLD) time = GetCurrentTime() - timeHold;
|
||||
|
||||
|
||||
return (float)time;
|
||||
}
|
||||
|
||||
|
@ -455,7 +455,7 @@ float GetGestureHoldDuration(void)
|
|||
Vector2 GetGestureDragVector(void)
|
||||
{
|
||||
// NOTE: drag vector is calculated on one touch points TOUCH_MOVE
|
||||
|
||||
|
||||
return dragVector;
|
||||
}
|
||||
|
||||
|
@ -464,7 +464,7 @@ Vector2 GetGestureDragVector(void)
|
|||
float GetGestureDragAngle(void)
|
||||
{
|
||||
// NOTE: drag angle is calculated on one touch points TOUCH_UP
|
||||
|
||||
|
||||
return dragAngle;
|
||||
}
|
||||
|
||||
|
@ -473,7 +473,7 @@ Vector2 GetGesturePinchVector(void)
|
|||
{
|
||||
// NOTE: The position values used for pinchDistance are not modified like the position values of [core.c]-->GetTouchPosition(int index)
|
||||
// NOTE: pinch distance is calculated on two touch points TOUCH_MOVE
|
||||
|
||||
|
||||
return pinchVector;
|
||||
}
|
||||
|
||||
|
@ -482,7 +482,7 @@ Vector2 GetGesturePinchVector(void)
|
|||
float GetGesturePinchAngle(void)
|
||||
{
|
||||
// NOTE: pinch angle is calculated on two touch points TOUCH_MOVE
|
||||
|
||||
|
||||
return pinchAngle;
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ float GetGesturePinchAngle(void)
|
|||
static float Vector2Angle(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI);
|
||||
|
||||
|
||||
if (angle < 0) angle += 360.0f;
|
||||
|
||||
return angle;
|
||||
|
@ -518,13 +518,13 @@ static float Vector2Distance(Vector2 v1, Vector2 v2)
|
|||
static double GetCurrentTime(void)
|
||||
{
|
||||
double time = 0;
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
unsigned long long int clockFrequency, currentTime;
|
||||
|
||||
|
||||
QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation!
|
||||
QueryPerformanceCounter(¤tTime);
|
||||
|
||||
|
||||
time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds
|
||||
#endif
|
||||
|
||||
|
@ -533,24 +533,24 @@ static double GetCurrentTime(void)
|
|||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
uint64_t nowTime = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec; // Time in nanoseconds
|
||||
|
||||
|
||||
time = ((double)nowTime/1000000.0); // Time in miliseconds
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
//#define CLOCK_REALTIME CALENDAR_CLOCK // returns UTC time since 1970-01-01
|
||||
//#define CLOCK_MONOTONIC SYSTEM_CLOCK // returns the time since boot time
|
||||
|
||||
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t now;
|
||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
||||
|
||||
|
||||
// NOTE: OS X does not have clock_gettime(), using clock_get_time()
|
||||
clock_get_time(cclock, &now);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
uint64_t nowTime = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec; // Time in nanoseconds
|
||||
|
||||
time = ((double)nowTime/1000000.0); // Time in miliseconds
|
||||
time = ((double)nowTime/1000000.0); // Time in miliseconds
|
||||
#endif
|
||||
|
||||
return time;
|
||||
|
|
|
@ -1896,7 +1896,7 @@ static Vector2 TriangleBarycenter(Vector2 v1, Vector2 v2, Vector2 v3)
|
|||
static void InitTimer(void)
|
||||
{
|
||||
srand(time(NULL)); // Initialize random seed
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
QueryPerformanceFrequency((unsigned long long int *) &frequency);
|
||||
#endif
|
||||
|
@ -1911,7 +1911,7 @@ static void InitTimer(void)
|
|||
mach_timebase_info(&timebase);
|
||||
frequency = (timebase.denom*1e9)/timebase.numer;
|
||||
#endif
|
||||
|
||||
|
||||
baseTime = GetTimeCount(); // Get MONOTONIC clock time offset
|
||||
startTime = GetCurrentTime(); // Get current time
|
||||
}
|
||||
|
@ -1920,7 +1920,7 @@ static void InitTimer(void)
|
|||
static uint64_t GetTimeCount(void)
|
||||
{
|
||||
uint64_t value = 0;
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
QueryPerformanceCounter((unsigned long long int *) &value);
|
||||
#endif
|
||||
|
|
74
src/raudio.c
74
src/raudio.c
|
@ -198,10 +198,10 @@ typedef enum { AUDIO_BUFFER_USAGE_STATIC = 0, AUDIO_BUFFER_USAGE_STREAM } AudioB
|
|||
// playback device depending on whether or not data is streamed
|
||||
struct rAudioBuffer {
|
||||
ma_pcm_converter dsp; // PCM data converter
|
||||
|
||||
|
||||
float volume; // Audio buffer volume
|
||||
float pitch; // Audio buffer pitch
|
||||
|
||||
|
||||
bool playing; // Audio buffer state: AUDIO_PLAYING
|
||||
bool paused; // Audio buffer state: AUDIO_PAUSED
|
||||
bool looping; // Audio buffer looping, always true for AudioStreams
|
||||
|
@ -209,11 +209,11 @@ struct rAudioBuffer {
|
|||
|
||||
bool isSubBufferProcessed[2]; // SubBuffer processed (virtual double buffer)
|
||||
unsigned int frameCursorPos; // Frame cursor position
|
||||
unsigned int bufferSizeInFrames; // Total buffer size in frames
|
||||
unsigned int bufferSizeInFrames; // Total buffer size in frames
|
||||
unsigned int totalFramesProcessed; // Total frames processed in this buffer (required for play timming)
|
||||
|
||||
|
||||
unsigned char *buffer; // Data buffer, on music stream keeps filling
|
||||
|
||||
|
||||
rAudioBuffer *next; // Next audio buffer on the list
|
||||
rAudioBuffer *prev; // Previous audio buffer on the list
|
||||
};
|
||||
|
@ -289,7 +289,7 @@ static void OnSendAudioDataToDevice(ma_device *pDevice, void *pFramesOut, const
|
|||
if (!audioBuffer->playing || audioBuffer->paused) continue;
|
||||
|
||||
ma_uint32 framesRead = 0;
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (framesRead > frameCount)
|
||||
|
@ -302,7 +302,7 @@ static void OnSendAudioDataToDevice(ma_device *pDevice, void *pFramesOut, const
|
|||
|
||||
// Just read as much data as we can from the stream
|
||||
ma_uint32 framesToRead = (frameCount - framesRead);
|
||||
|
||||
|
||||
while (framesToRead > 0)
|
||||
{
|
||||
float tempBuffer[1024]; // 512 frames for stereo
|
||||
|
@ -387,7 +387,7 @@ static ma_uint32 OnAudioBufferDSPRead(ma_pcm_converter *pDSP, void *pFramesOut,
|
|||
{
|
||||
if (framesRead >= frameCount) break;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (isSubBufferProcessed[currentSubBufferIndex]) break;
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ static void MixAudioFrames(float *framesOut, const float *framesIn, ma_uint32 fr
|
|||
static void InitAudioBufferPool()
|
||||
{
|
||||
// Dummy buffers
|
||||
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++)
|
||||
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++)
|
||||
{
|
||||
audioBufferPool[i] = InitAudioBuffer(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, 0, AUDIO_BUFFER_USAGE_STATIC);
|
||||
}
|
||||
|
@ -486,7 +486,7 @@ void InitAudioDevice(void)
|
|||
// Init audio context
|
||||
ma_context_config contextConfig = ma_context_config_init();
|
||||
contextConfig.logCallback = OnLog;
|
||||
|
||||
|
||||
ma_result result = ma_context_init(NULL, 0, &contextConfig, &context);
|
||||
if (result != MA_SUCCESS)
|
||||
{
|
||||
|
@ -589,7 +589,7 @@ AudioBuffer *InitAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sam
|
|||
{
|
||||
AudioBuffer *audioBuffer = (AudioBuffer *)RL_CALLOC(1, sizeof(AudioBuffer));
|
||||
audioBuffer->buffer = RL_CALLOC(bufferSizeInFrames*channels*ma_get_bytes_per_sample(format), 1);
|
||||
|
||||
|
||||
if (audioBuffer == NULL)
|
||||
{
|
||||
TraceLog(LOG_ERROR, "InitAudioBuffer() : Failed to allocate memory for audio buffer");
|
||||
|
@ -608,7 +608,7 @@ AudioBuffer *InitAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sam
|
|||
dspConfig.onRead = OnAudioBufferDSPRead; // Callback on data reading
|
||||
dspConfig.pUserData = audioBuffer; // Audio data pointer
|
||||
dspConfig.allowDynamicSampleRate = true; // Required for pitch shifting
|
||||
|
||||
|
||||
ma_result result = ma_pcm_converter_init(&dspConfig, &audioBuffer->dsp);
|
||||
|
||||
if (result != MA_SUCCESS)
|
||||
|
@ -655,7 +655,7 @@ void CloseAudioBuffer(AudioBuffer *buffer)
|
|||
bool IsAudioBufferPlaying(AudioBuffer *buffer)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
|
||||
if (buffer != NULL) result = (buffer->playing && !buffer->paused);
|
||||
else TraceLog(LOG_ERROR, "IsAudioBufferPlaying() : No audio buffer");
|
||||
|
||||
|
@ -698,7 +698,7 @@ void StopAudioBuffer(AudioBuffer *buffer)
|
|||
void PauseAudioBuffer(AudioBuffer *buffer)
|
||||
{
|
||||
if (buffer != NULL) buffer->paused = true;
|
||||
else TraceLog(LOG_ERROR, "PauseAudioBuffer() : No audio buffer");
|
||||
else TraceLog(LOG_ERROR, "PauseAudioBuffer() : No audio buffer");
|
||||
}
|
||||
|
||||
// Resume an audio buffer
|
||||
|
@ -722,8 +722,8 @@ void SetAudioBufferPitch(AudioBuffer *buffer, float pitch)
|
|||
{
|
||||
float pitchMul = pitch/buffer->pitch;
|
||||
|
||||
// Pitching is just an adjustment of the sample rate.
|
||||
// Note that this changes the duration of the sound:
|
||||
// Pitching is just an adjustment of the sample rate.
|
||||
// Note that this changes the duration of the sound:
|
||||
// - higher pitches will make the sound faster
|
||||
// - lower pitches make it slower
|
||||
ma_uint32 newOutputSampleRate = (ma_uint32)((float)buffer->dsp.src.config.sampleRateOut/pitchMul);
|
||||
|
@ -816,7 +816,7 @@ Sound LoadSoundFromWave(Wave wave)
|
|||
|
||||
if (wave.data != NULL)
|
||||
{
|
||||
// When using miniaudio we need to do our own mixing.
|
||||
// When using miniaudio we need to do our own mixing.
|
||||
// To simplify this we need convert the format of each sound to be consistent with
|
||||
// the format used to open the playback device. We can do this two ways:
|
||||
//
|
||||
|
@ -909,7 +909,7 @@ void ExportWaveAsCode(Wave wave, const char *fileName)
|
|||
int dataSize = wave.sampleCount*wave.channels*wave.sampleSize/8;
|
||||
|
||||
FILE *txtFile = fopen(fileName, "wt");
|
||||
|
||||
|
||||
if (txtFile != NULL)
|
||||
{
|
||||
fprintf(txtFile, "\n//////////////////////////////////////////////////////////////////////////////////\n");
|
||||
|
@ -967,7 +967,7 @@ void PlaySoundMulti(Sound sound)
|
|||
oldAge = audioBufferPoolChannels[i];
|
||||
oldIndex = i;
|
||||
}
|
||||
|
||||
|
||||
if (!IsAudioBufferPlaying(audioBufferPool[i]))
|
||||
{
|
||||
index = i;
|
||||
|
@ -979,17 +979,17 @@ void PlaySoundMulti(Sound sound)
|
|||
if (index == -1)
|
||||
{
|
||||
TraceLog(LOG_WARNING,"pool age %i ended a sound early no room in buffer pool", audioBufferPoolCounter);
|
||||
|
||||
|
||||
if (oldIndex == -1)
|
||||
{
|
||||
// Shouldn't be able to get here... but just in case something odd happens!
|
||||
TraceLog(LOG_ERROR,"sound buffer pool couldn't determine oldest buffer not playing sound");
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
index = oldIndex;
|
||||
|
||||
|
||||
// Just in case...
|
||||
StopAudioBuffer(audioBufferPool[index]);
|
||||
}
|
||||
|
@ -1000,7 +1000,7 @@ void PlaySoundMulti(Sound sound)
|
|||
|
||||
audioBufferPoolChannels[index] = audioBufferPoolCounter;
|
||||
audioBufferPoolCounter++;
|
||||
|
||||
|
||||
audioBufferPool[index]->volume = sound.stream.buffer->volume;
|
||||
audioBufferPool[index]->pitch = sound.stream.buffer->pitch;
|
||||
audioBufferPool[index]->looping = sound.stream.buffer->looping;
|
||||
|
@ -1023,12 +1023,12 @@ void StopSoundMulti(void)
|
|||
int GetSoundsPlaying(void)
|
||||
{
|
||||
int counter = 0;
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_AUDIO_BUFFER_POOL_CHANNELS; i++)
|
||||
{
|
||||
if (IsAudioBufferPlaying(audioBufferPool[i])) counter++;
|
||||
}
|
||||
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
@ -1211,7 +1211,7 @@ Music LoadMusicStream(const char *fileName)
|
|||
{
|
||||
drmp3 *ctxMp3 = RL_MALLOC(sizeof(drmp3));
|
||||
music.ctxData = ctxMp3;
|
||||
|
||||
|
||||
int result = drmp3_init_file(ctxMp3, fileName, NULL);
|
||||
|
||||
if (result > 0)
|
||||
|
@ -1242,7 +1242,7 @@ Music LoadMusicStream(const char *fileName)
|
|||
music.sampleCount = (unsigned int)jar_xm_get_remaining_samples(ctxXm);
|
||||
music.loopCount = 0; // Infinite loop by default
|
||||
musicLoaded = true;
|
||||
|
||||
|
||||
music.ctxData = ctxXm;
|
||||
}
|
||||
}
|
||||
|
@ -1252,7 +1252,7 @@ Music LoadMusicStream(const char *fileName)
|
|||
{
|
||||
jar_mod_context_t *ctxMod = RL_MALLOC(sizeof(jar_mod_context_t));
|
||||
music.ctxData = ctxMod;
|
||||
|
||||
|
||||
jar_mod_init(ctxMod);
|
||||
int result = jar_mod_load_file(ctxMod, fileName);
|
||||
|
||||
|
@ -1335,7 +1335,7 @@ void PlayMusicStream(Music music)
|
|||
{
|
||||
// For music streams, we need to make sure we maintain the frame cursor position
|
||||
// This is a hack for this section of code in UpdateMusicStream()
|
||||
// NOTE: In case window is minimized, music stream is stopped, just make sure to
|
||||
// NOTE: In case window is minimized, music stream is stopped, just make sure to
|
||||
// play again on window restore: if (IsMusicPlaying(music)) PlayMusicStream(music);
|
||||
ma_uint32 frameCursorPos = audioBuffer->frameCursorPos;
|
||||
PlayAudioStream(music.stream); // WARNING: This resets the cursor position.
|
||||
|
@ -1395,7 +1395,7 @@ void UpdateMusicStream(Music music)
|
|||
void *pcm = RL_CALLOC(subBufferSizeInFrames*music.stream.channels*music.stream.sampleSize/8, 1);
|
||||
|
||||
int samplesCount = 0; // Total size of data streamed in L+R samples for xm floats, individual L or R for ogg shorts
|
||||
|
||||
|
||||
// TODO: Get the sampleLeft using totalFramesProcessed... but first, get total frames processed correctly...
|
||||
//ma_uint32 frameSizeInBytes = ma_get_bytes_per_sample(music.stream.buffer->dsp.formatConverterIn.config.formatIn)*music.stream.buffer->dsp.formatConverterIn.config.channels;
|
||||
int sampleLeft = music.sampleCount - (music.stream.buffer->totalFramesProcessed*music.stream.channels);
|
||||
|
@ -1449,7 +1449,7 @@ void UpdateMusicStream(Music music)
|
|||
}
|
||||
|
||||
UpdateAudioStream(music.stream, pcm, samplesCount);
|
||||
|
||||
|
||||
if ((music.ctxType == MUSIC_MODULE_XM) || (music.ctxType == MUSIC_MODULE_MOD))
|
||||
{
|
||||
if (samplesCount > 1) sampleLeft -= samplesCount/2;
|
||||
|
@ -1549,11 +1549,11 @@ AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, un
|
|||
// The size of a streaming buffer must be at least double the size of a period
|
||||
unsigned int periodSize = device.playback.internalBufferSizeInFrames/device.playback.internalPeriods;
|
||||
unsigned int subBufferSize = AUDIO_BUFFER_SIZE;
|
||||
|
||||
|
||||
if (subBufferSize < periodSize) subBufferSize = periodSize;
|
||||
|
||||
stream.buffer = InitAudioBuffer(formatIn, stream.channels, stream.sampleRate, subBufferSize*2, AUDIO_BUFFER_USAGE_STREAM);
|
||||
|
||||
|
||||
if (stream.buffer != NULL)
|
||||
{
|
||||
stream.buffer->looping = true; // Always loop for streaming buffers
|
||||
|
@ -1578,7 +1578,7 @@ void CloseAudioStream(AudioStream stream)
|
|||
void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount)
|
||||
{
|
||||
AudioBuffer *audioBuffer = stream.buffer;
|
||||
|
||||
|
||||
if (audioBuffer != NULL)
|
||||
{
|
||||
if (audioBuffer->isSubBufferProcessed[0] || audioBuffer->isSubBufferProcessed[1])
|
||||
|
@ -1587,7 +1587,7 @@ void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount)
|
|||
|
||||
if (audioBuffer->isSubBufferProcessed[0] && audioBuffer->isSubBufferProcessed[1])
|
||||
{
|
||||
// Both buffers are available for updating.
|
||||
// Both buffers are available for updating.
|
||||
// Update the first one and make sure the cursor is moved back to the front.
|
||||
subBufferToUpdate = 0;
|
||||
audioBuffer->frameCursorPos = 0;
|
||||
|
@ -1604,7 +1604,7 @@ void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount)
|
|||
// TODO: Get total frames processed on this buffer... DOES NOT WORK.
|
||||
audioBuffer->totalFramesProcessed += subBufferSizeInFrames;
|
||||
|
||||
// Does this API expect a whole buffer to be updated in one go?
|
||||
// Does this API expect a whole buffer to be updated in one go?
|
||||
// Assuming so, but if not will need to change this logic.
|
||||
if (subBufferSizeInFrames >= (ma_uint32)samplesCount/stream.channels)
|
||||
{
|
||||
|
|
|
@ -110,7 +110,7 @@ typedef struct Sound {
|
|||
typedef struct Music {
|
||||
int ctxType; // Type of music context (audio filetype)
|
||||
void *ctxData; // Audio context data, depends on type
|
||||
|
||||
|
||||
unsigned int sampleCount; // Total number of samples
|
||||
unsigned int loopCount; // Loops count (times music will play), 0 means infinite loop
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* rglfw - raylib GLFW single file compilation
|
||||
*
|
||||
* This file includes latest GLFW sources (https://github.com/glfw/glfw) to be compiled together
|
||||
* This file includes latest GLFW sources (https://github.com/glfw/glfw) to be compiled together
|
||||
* with raylib for all supported platforms, this way, no external dependencies are required.
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
|
|
|
@ -2967,7 +2967,7 @@ char *LoadText(const char *fileName)
|
|||
Shader LoadShader(const char *vsFileName, const char *fsFileName)
|
||||
{
|
||||
Shader shader = { 0 };
|
||||
|
||||
|
||||
// NOTE: Shader.locs is allocated by LoadShaderCode()
|
||||
|
||||
char *vShaderStr = NULL;
|
||||
|
|
122
src/rmem.h
122
src/rmem.h
|
@ -54,7 +54,7 @@
|
|||
#else
|
||||
#define RMEMAPI // We are building or using library as a static library (or Linux shared library)
|
||||
#endif
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -139,9 +139,9 @@ RMEMAPI void ObjPoolCleanUp(ObjPool *objpool, void **ptrref);
|
|||
|
||||
#if defined(RMEM_IMPLEMENTATION)
|
||||
|
||||
#include <stdio.h> // Required for:
|
||||
#include <stdlib.h> // Required for:
|
||||
#include <string.h> // Required for:
|
||||
#include <stdio.h> // Required for:
|
||||
#include <stdlib.h> // Required for:
|
||||
#include <string.h> // Required for:
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
|
@ -163,8 +163,8 @@ RMEMAPI void ObjPoolCleanUp(ObjPool *objpool, void **ptrref);
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
static inline size_t __AlignSize(const size_t size, const size_t align)
|
||||
{
|
||||
static inline size_t __AlignSize(const size_t size, const size_t align)
|
||||
{
|
||||
return (size + (align - 1)) & -align;
|
||||
}
|
||||
|
||||
|
@ -175,9 +175,9 @@ static inline size_t __AlignSize(const size_t size, const size_t align)
|
|||
MemPool CreateMemPool(const size_t size)
|
||||
{
|
||||
MemPool mempool = { 0 };
|
||||
|
||||
|
||||
if (size == 0UL) return mempool;
|
||||
else
|
||||
else
|
||||
{
|
||||
// Align the mempool size to at least the size of an alloc node.
|
||||
mempool.stack.size = size;
|
||||
|
@ -188,7 +188,7 @@ MemPool CreateMemPool(const size_t size)
|
|||
mempool.stack.size = 0UL;
|
||||
return mempool;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
mempool.stack.base = mempool.stack.mem + mempool.stack.size;
|
||||
return mempool;
|
||||
|
@ -199,9 +199,9 @@ MemPool CreateMemPool(const size_t size)
|
|||
MemPool CreateMemPoolFromBuffer(void *buf, const size_t size)
|
||||
{
|
||||
MemPool mempool = { 0 };
|
||||
|
||||
|
||||
if ((size == 0UL) || (buf == NULL) || (size <= sizeof(MemNode))) return mempool;
|
||||
else
|
||||
else
|
||||
{
|
||||
mempool.stack.size = size;
|
||||
mempool.stack.mem = buf;
|
||||
|
@ -213,7 +213,7 @@ MemPool CreateMemPoolFromBuffer(void *buf, const size_t size)
|
|||
void DestroyMemPool(MemPool *const mempool)
|
||||
{
|
||||
if ((mempool == NULL) || (mempool->stack.mem == NULL)) return;
|
||||
else
|
||||
else
|
||||
{
|
||||
free(mempool->stack.mem);
|
||||
*mempool = (MemPool){ 0 };
|
||||
|
@ -228,7 +228,7 @@ void *MemPoolAlloc(MemPool *const mempool, const size_t size)
|
|||
MemNode *new_mem = NULL;
|
||||
const size_t ALLOC_SIZE = __AlignSize(size + sizeof *new_mem, sizeof(intptr_t));
|
||||
const size_t BUCKET_INDEX = (ALLOC_SIZE >> MEMPOOL_BUCKET_BITS) - 1;
|
||||
|
||||
|
||||
// If the size is small enough, let's check if our buckets has a fitting memory block.
|
||||
if (BUCKET_INDEX < MEMPOOL_BUCKET_SIZE && mempool->buckets[BUCKET_INDEX] != NULL && mempool->buckets[BUCKET_INDEX]->size >= ALLOC_SIZE)
|
||||
{
|
||||
|
@ -240,7 +240,7 @@ void *MemPoolAlloc(MemPool *const mempool, const size_t size)
|
|||
else if (mempool->freeList.head != NULL)
|
||||
{
|
||||
const size_t MEM_SPLIT_THRESHOLD = 16;
|
||||
|
||||
|
||||
// If the freelist is valid, let's allocate FROM the freelist then!
|
||||
for (MemNode *inode = mempool->freeList.head; inode != NULL; inode = inode->next)
|
||||
{
|
||||
|
@ -251,10 +251,10 @@ void *MemPoolAlloc(MemPool *const mempool, const size_t size)
|
|||
new_mem = inode;
|
||||
(inode->prev != NULL)? (inode->prev->next = inode->next) : (mempool->freeList.head = inode->next);
|
||||
(inode->next != NULL)? (inode->next->prev = inode->prev) : (mempool->freeList.tail = inode->prev);
|
||||
|
||||
|
||||
if (mempool->freeList.head != NULL) mempool->freeList.head->prev = NULL;
|
||||
else mempool->freeList.tail = NULL;
|
||||
|
||||
|
||||
if (mempool->freeList.tail != NULL) mempool->freeList.tail->next = NULL;
|
||||
mempool->freeList.len--;
|
||||
break;
|
||||
|
@ -269,7 +269,7 @@ void *MemPoolAlloc(MemPool *const mempool, const size_t size)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (new_mem == NULL)
|
||||
{
|
||||
// not enough memory to support the size!
|
||||
|
@ -279,13 +279,13 @@ void *MemPoolAlloc(MemPool *const mempool, const size_t size)
|
|||
// Couldn't allocate from a freelist, allocate from available mempool.
|
||||
// Subtract allocation size from the mempool.
|
||||
mempool->stack.base -= ALLOC_SIZE;
|
||||
|
||||
|
||||
// Use the available mempool space as the new node.
|
||||
new_mem = (MemNode *)mempool->stack.base;
|
||||
new_mem->size = ALLOC_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Visual of the allocation block.
|
||||
// --------------
|
||||
// | mem size | lowest addr of block
|
||||
|
@ -314,7 +314,7 @@ void *MemPoolRealloc(MemPool *const restrict mempool, void *ptr, const size_t si
|
|||
MemNode *const node = (MemNode *)((uint8_t *)ptr - sizeof *node);
|
||||
const size_t NODE_SIZE = sizeof *node;
|
||||
uint8_t *const resized_block = MemPoolAlloc(mempool, size);
|
||||
|
||||
|
||||
if (resized_block == NULL) return NULL;
|
||||
else
|
||||
{
|
||||
|
@ -329,16 +329,16 @@ void *MemPoolRealloc(MemPool *const restrict mempool, void *ptr, const size_t si
|
|||
void MemPoolFree(MemPool *const restrict mempool, void *ptr)
|
||||
{
|
||||
if ((mempool == NULL) || (ptr == NULL) || ((uintptr_t)ptr - sizeof(MemNode) < (uintptr_t)mempool->stack.mem)) return;
|
||||
else
|
||||
else
|
||||
{
|
||||
// Behind the actual pointer data is the allocation info.
|
||||
MemNode *const mem_node = (MemNode *)((uint8_t *)ptr - sizeof *mem_node);
|
||||
const size_t BUCKET_INDEX = (mem_node->size >> MEMPOOL_BUCKET_BITS) - 1;
|
||||
|
||||
|
||||
// Make sure the pointer data is valid.
|
||||
if (((uintptr_t)mem_node < (uintptr_t)mempool->stack.base) ||
|
||||
(((uintptr_t)mem_node - (uintptr_t)mempool->stack.mem) > mempool->stack.size) ||
|
||||
(mem_node->size == 0UL) ||
|
||||
if (((uintptr_t)mem_node < (uintptr_t)mempool->stack.base) ||
|
||||
(((uintptr_t)mem_node - (uintptr_t)mempool->stack.mem) > mempool->stack.size) ||
|
||||
(mem_node->size == 0UL) ||
|
||||
(mem_node->size > mempool->stack.size)) return;
|
||||
// If the mem_node is right at the stack base ptr, then add it to the stack.
|
||||
else if ((uintptr_t)mem_node == (uintptr_t)mempool->stack.base)
|
||||
|
@ -362,13 +362,13 @@ void MemPoolFree(MemPool *const restrict mempool, void *ptr)
|
|||
else /*if ((mempool->freeList.len == 0UL) || ((uintptr_t)mempool->freeList.head >= (uintptr_t)mempool->stack.mem && (uintptr_t)mempool->freeList.head - (uintptr_t)mempool->stack.mem < mempool->stack.size))*/
|
||||
{
|
||||
for (MemNode *n = mempool->freeList.head; n != NULL; n = n->next) if (n == mem_node) return;
|
||||
|
||||
|
||||
// This code insertion sorts where largest size is last.
|
||||
if (mempool->freeList.head == NULL)
|
||||
{
|
||||
mempool->freeList.head = mempool->freeList.tail = mem_node;
|
||||
mempool->freeList.len++;
|
||||
}
|
||||
}
|
||||
else if (mempool->freeList.head->size >= mem_node->size)
|
||||
{
|
||||
mem_node->next = mempool->freeList.head;
|
||||
|
@ -383,7 +383,7 @@ void MemPoolFree(MemPool *const restrict mempool, void *ptr)
|
|||
mempool->freeList.tail = mem_node;
|
||||
mempool->freeList.len++;
|
||||
}
|
||||
|
||||
|
||||
if (mempool->freeList.autoDefrag && (mempool->freeList.maxNodes != 0UL) && (mempool->freeList.len > mempool->freeList.maxNodes)) MemPoolDefrag(mempool);
|
||||
}
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ void MemPoolFree(MemPool *const restrict mempool, void *ptr)
|
|||
void MemPoolCleanUp(MemPool *const restrict mempool, void **ptrref)
|
||||
{
|
||||
if ((mempool == NULL) || (ptrref == NULL) || (*ptrref == NULL)) return;
|
||||
else
|
||||
else
|
||||
{
|
||||
MemPoolFree(mempool, *ptrref);
|
||||
*ptrref = NULL;
|
||||
|
@ -402,11 +402,11 @@ void MemPoolCleanUp(MemPool *const restrict mempool, void **ptrref)
|
|||
size_t GetMemPoolFreeMemory(const MemPool mempool)
|
||||
{
|
||||
size_t total_remaining = (uintptr_t)mempool.stack.base - (uintptr_t)mempool.stack.mem;
|
||||
|
||||
|
||||
for (MemNode *n=mempool.freeList.head; n != NULL; n = n->next) total_remaining += n->size;
|
||||
|
||||
|
||||
for (size_t i=0; i<MEMPOOL_BUCKET_SIZE; i++) for (MemNode *n = mempool.buckets[i]; n != NULL; n = n->next) total_remaining += n->size;
|
||||
|
||||
|
||||
return total_remaining;
|
||||
}
|
||||
|
||||
|
@ -423,12 +423,12 @@ bool MemPoolDefrag(MemPool *const mempool)
|
|||
for (size_t i = 0; i < MEMPOOL_BUCKET_SIZE; i++) mempool->buckets[i] = NULL;
|
||||
mempool->stack.base = mempool->stack.mem + mempool->stack.size;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i=0; i<MEMPOOL_BUCKET_SIZE; i++)
|
||||
{
|
||||
while (mempool->buckets[i] != NULL)
|
||||
while (mempool->buckets[i] != NULL)
|
||||
{
|
||||
if ((uintptr_t)mempool->buckets[i] == (uintptr_t)mempool->stack.base)
|
||||
{
|
||||
|
@ -440,42 +440,42 @@ bool MemPoolDefrag(MemPool *const mempool)
|
|||
else break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const size_t PRE_DEFRAG_LEN = mempool->freeList.len;
|
||||
MemNode **node = &mempool->freeList.head;
|
||||
|
||||
|
||||
while (*node != NULL)
|
||||
{
|
||||
if ((uintptr_t)*node == (uintptr_t)mempool->stack.base)
|
||||
if ((uintptr_t)*node == (uintptr_t)mempool->stack.base)
|
||||
{
|
||||
// If node is right at the stack, merge it back into the stack.
|
||||
mempool->stack.base += (*node)->size;
|
||||
(*node)->size = 0UL;
|
||||
((*node)->prev != NULL)? ((*node)->prev->next = (*node)->next) : (mempool->freeList.head = (*node)->next);
|
||||
((*node)->next != NULL)? ((*node)->next->prev = (*node)->prev) : (mempool->freeList.tail = (*node)->prev);
|
||||
|
||||
|
||||
if (mempool->freeList.head != NULL) mempool->freeList.head->prev = NULL;
|
||||
else mempool->freeList.tail = NULL;
|
||||
|
||||
|
||||
if (mempool->freeList.tail != NULL) mempool->freeList.tail->next = NULL;
|
||||
mempool->freeList.len--;
|
||||
node = &mempool->freeList.head;
|
||||
}
|
||||
}
|
||||
else if (((uintptr_t)*node + (*node)->size) == (uintptr_t)(*node)->next)
|
||||
{
|
||||
// Next node is at a higher address.
|
||||
(*node)->size += (*node)->next->size;
|
||||
(*node)->next->size = 0UL;
|
||||
|
||||
|
||||
// <-[P Curr N]-> <-[P Next N]-> <-[P NextNext N]->
|
||||
//
|
||||
//
|
||||
// |--------------------|
|
||||
// <-[P Curr N]-> <-[P Next N]-> [P NextNext N]->
|
||||
if ((*node)->next->next != NULL) (*node)->next->next->prev = *node;
|
||||
|
||||
|
||||
// <-[P Curr N]-> <-[P NextNext N]->
|
||||
(*node)->next = (*node)->next->next;
|
||||
|
||||
|
||||
mempool->freeList.len--;
|
||||
node = &mempool->freeList.head;
|
||||
}
|
||||
|
@ -484,16 +484,16 @@ bool MemPoolDefrag(MemPool *const mempool)
|
|||
// Prev node is at a higher address.
|
||||
(*node)->size += (*node)->prev->size;
|
||||
(*node)->prev->size = 0UL;
|
||||
|
||||
|
||||
// <-[P PrevPrev N]-> <-[P Prev N]-> <-[P Curr N]->
|
||||
//
|
||||
// |--------------------|
|
||||
// <-[P PrevPrev N] <-[P Prev N]-> <-[P Curr N]->
|
||||
(*node)->prev->prev->next = *node;
|
||||
|
||||
|
||||
// <-[P PrevPrev N]-> <-[P Curr N]->
|
||||
(*node)->prev = (*node)->prev->prev;
|
||||
|
||||
|
||||
mempool->freeList.len--;
|
||||
node = &mempool->freeList.head;
|
||||
}
|
||||
|
@ -501,12 +501,12 @@ bool MemPoolDefrag(MemPool *const mempool)
|
|||
{
|
||||
// Next node is at a lower address.
|
||||
(*node)->next->size += (*node)->size;
|
||||
|
||||
|
||||
(*node)->size = 0UL;
|
||||
(*node)->next->prev = (*node)->prev;
|
||||
(*node)->prev->next = (*node)->next;
|
||||
*node = (*node)->next;
|
||||
|
||||
|
||||
mempool->freeList.len--;
|
||||
node = &mempool->freeList.head;
|
||||
}
|
||||
|
@ -514,21 +514,21 @@ bool MemPoolDefrag(MemPool *const mempool)
|
|||
{
|
||||
// Prev node is at a lower address.
|
||||
(*node)->prev->size += (*node)->size;
|
||||
|
||||
|
||||
(*node)->size = 0UL;
|
||||
(*node)->next->prev = (*node)->prev;
|
||||
(*node)->prev->next = (*node)->next;
|
||||
*node = (*node)->prev;
|
||||
|
||||
|
||||
mempool->freeList.len--;
|
||||
node = &mempool->freeList.head;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
node = &(*node)->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return PRE_DEFRAG_LEN > mempool->freeList.len;
|
||||
}
|
||||
}
|
||||
|
@ -551,19 +551,19 @@ union ObjInfo {
|
|||
ObjPool CreateObjPool(const size_t objsize, const size_t len)
|
||||
{
|
||||
ObjPool objpool = { 0 };
|
||||
|
||||
|
||||
if ((len == 0UL) || (objsize == 0UL)) return objpool;
|
||||
else
|
||||
{
|
||||
objpool.objSize = __AlignSize(objsize, sizeof(size_t));
|
||||
objpool.stack.size = objpool.freeBlocks = len;
|
||||
objpool.stack.mem = calloc(objpool.stack.size, objpool.objSize);
|
||||
|
||||
|
||||
if (objpool.stack.mem == NULL)
|
||||
{
|
||||
objpool.stack.size = 0UL;
|
||||
return objpool;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i=0; i<objpool.freeBlocks; i++)
|
||||
|
@ -571,7 +571,7 @@ ObjPool CreateObjPool(const size_t objsize, const size_t len)
|
|||
union ObjInfo block = { .byte = &objpool.stack.mem[i*objpool.objSize] };
|
||||
*block.index = i + 1;
|
||||
}
|
||||
|
||||
|
||||
objpool.stack.base = objpool.stack.mem;
|
||||
return objpool;
|
||||
}
|
||||
|
@ -581,7 +581,7 @@ ObjPool CreateObjPool(const size_t objsize, const size_t len)
|
|||
ObjPool CreateObjPoolFromBuffer(void *const buf, const size_t objsize, const size_t len)
|
||||
{
|
||||
ObjPool objpool = { 0 };
|
||||
|
||||
|
||||
// If the object size isn't large enough to align to a size_t, then we can't use it.
|
||||
if ((buf == NULL) || (len == 0UL) || (objsize < sizeof(size_t)) || (objsize*len != __AlignSize(objsize, sizeof(size_t))*len)) return objpool;
|
||||
else
|
||||
|
@ -589,13 +589,13 @@ ObjPool CreateObjPoolFromBuffer(void *const buf, const size_t objsize, const siz
|
|||
objpool.objSize = __AlignSize(objsize, sizeof(size_t));
|
||||
objpool.stack.size = objpool.freeBlocks = len;
|
||||
objpool.stack.mem = buf;
|
||||
|
||||
|
||||
for (size_t i=0; i<objpool.freeBlocks; i++)
|
||||
{
|
||||
union ObjInfo block = { .byte = &objpool.stack.mem[i*objpool.objSize] };
|
||||
*block.index = i + 1;
|
||||
}
|
||||
|
||||
|
||||
objpool.stack.base = objpool.stack.mem;
|
||||
return objpool;
|
||||
}
|
||||
|
@ -623,7 +623,7 @@ void *ObjPoolAlloc(ObjPool *const objpool)
|
|||
// ret = Head == ret = &pool[0];
|
||||
union ObjInfo ret = { .byte = objpool->stack.base };
|
||||
objpool->freeBlocks--;
|
||||
|
||||
|
||||
// after allocating, we set head to the address of the index that *Head holds.
|
||||
// Head = &pool[*Head * pool.objsize];
|
||||
objpool->stack.base = (objpool->freeBlocks != 0UL)? objpool->stack.mem + (*ret.index*objpool->objSize) : NULL;
|
||||
|
|
|
@ -95,10 +95,10 @@
|
|||
// Platform type definitions
|
||||
// From: https://github.com/DFHack/clsocket/blob/master/src/Host.h
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
typedef int socklen_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RESULT_SUCCESS
|
||||
# define RESULT_SUCCESS 0
|
||||
|
@ -171,7 +171,7 @@ typedef int socklen_t;
|
|||
#define SOCKET_MAX_QUEUE_SIZE (16) // Maximum socket queue size
|
||||
#define SOCKET_MAX_SOCK_OPTS (4) // Maximum socket options
|
||||
#define SOCKET_MAX_UDPCHANNELS (32) // Maximum UDP channels
|
||||
#define SOCKET_MAX_UDPADDRESSES (4) // Maximum bound UDP addresses
|
||||
#define SOCKET_MAX_UDPADDRESSES (4) // Maximum bound UDP addresses
|
||||
|
||||
|
||||
// Network address related defines
|
||||
|
@ -386,7 +386,7 @@ int AddSocket(SocketSet *set, Socket *sock);
|
|||
int RemoveSocket(SocketSet *set, Socket *sock);
|
||||
int CheckSockets(SocketSet *set, unsigned int timeout);
|
||||
|
||||
// Packet API
|
||||
// Packet API
|
||||
void PacketSend(Packet *packet);
|
||||
void PacketReceive(Packet *packet);
|
||||
void PacketWrite8(Packet *packet, uint16_t value);
|
||||
|
|
126
src/text.c
126
src/text.c
|
@ -323,7 +323,7 @@ Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCou
|
|||
{
|
||||
Image atlas = GenImageFontAtlas(font.chars, &font.recs, font.charsCount, font.baseSize, 2, 0);
|
||||
font.texture = LoadTextureFromImage(atlas);
|
||||
|
||||
|
||||
// Update chars[i].image to use alpha, required to be used on ImageDrawText()
|
||||
for (int i = 0; i < font.charsCount; i++)
|
||||
{
|
||||
|
@ -441,7 +441,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
|
|||
for (int i = 0; i < spriteFont.charsCount; i++)
|
||||
{
|
||||
spriteFont.chars[i].value = tempCharValues[i];
|
||||
|
||||
|
||||
// Get character rectangle in the font atlas texture
|
||||
spriteFont.recs[i] = tempCharRecs[i];
|
||||
|
||||
|
@ -449,7 +449,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
|
|||
spriteFont.chars[i].offsetX = 0;
|
||||
spriteFont.chars[i].offsetY = 0;
|
||||
spriteFont.chars[i].advanceX = 0;
|
||||
|
||||
|
||||
// Fill character image data from fontClear data
|
||||
spriteFont.chars[i].image = ImageFromImage(fontClear, tempCharRecs[i]);
|
||||
}
|
||||
|
@ -589,7 +589,7 @@ Image GenImageFontAtlas(const CharInfo *chars, Rectangle **charRecs, int charsCo
|
|||
|
||||
// In case no chars count provided we suppose default of 95
|
||||
charsCount = (charsCount > 0)? charsCount : 95;
|
||||
|
||||
|
||||
// NOTE: Rectangles memory is loaded here!
|
||||
Rectangle *recs = (Rectangle *)RL_MALLOC(charsCount*sizeof(Rectangle));
|
||||
|
||||
|
@ -713,7 +713,7 @@ Image GenImageFontAtlas(const CharInfo *chars, Rectangle **charRecs, int charsCo
|
|||
RL_FREE(atlas.data);
|
||||
atlas.data = dataGrayAlpha;
|
||||
atlas.format = UNCOMPRESSED_GRAY_ALPHA;
|
||||
|
||||
|
||||
*charRecs = recs;
|
||||
|
||||
return atlas;
|
||||
|
@ -761,12 +761,12 @@ void DrawFPS(int posX, int posY)
|
|||
// Returns next codepoint in a UTF8 encoded text, scanning until '\0' is found
|
||||
// When a invalid UTF8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned
|
||||
// Total number of bytes processed are returned as a parameter
|
||||
// NOTE: the standard says U+FFFD should be returned in case of errors
|
||||
// NOTE: the standard says U+FFFD should be returned in case of errors
|
||||
// but that character is not supported by the default font in raylib
|
||||
// TODO: optimize this code for speed!!
|
||||
int GetNextCodepoint(const char *text, int *bytesProcessed)
|
||||
{
|
||||
/*
|
||||
/*
|
||||
UTF8 specs from https://www.ietf.org/rfc/rfc3629.txt
|
||||
|
||||
Char. number range | UTF-8 octet sequence
|
||||
|
@ -777,26 +777,26 @@ int GetNextCodepoint(const char *text, int *bytesProcessed)
|
|||
0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
|
||||
0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
*/
|
||||
|
||||
|
||||
// NOTE: on decode errors we return as soon as possible
|
||||
|
||||
|
||||
int code = 0x3f; // Codepoint (defaults to '?')
|
||||
int octet = (unsigned char)(text[0]); // The first UTF8 octet
|
||||
*bytesProcessed = 1;
|
||||
|
||||
|
||||
if (octet <= 0x7f)
|
||||
{
|
||||
{
|
||||
// Only one octet (ASCII range x00-7F)
|
||||
code = text[0];
|
||||
}
|
||||
else if ((octet & 0xe0) == 0xc0)
|
||||
{
|
||||
// Two octets
|
||||
// Two octets
|
||||
// [0]xC2-DF [1]UTF8-tail(x80-BF)
|
||||
unsigned char octet1 = text[1];
|
||||
|
||||
|
||||
if ((octet1 == '\0') || ((octet1 >> 6) != 2)) { *bytesProcessed = 2; return code; } // Unexpected sequence
|
||||
|
||||
|
||||
if ((octet >= 0xc2) && (octet <= 0xdf))
|
||||
{
|
||||
code = ((octet & 0x1f) << 6) | (octet1 & 0x3f);
|
||||
|
@ -808,66 +808,66 @@ int GetNextCodepoint(const char *text, int *bytesProcessed)
|
|||
// Three octets
|
||||
unsigned char octet1 = text[1];
|
||||
unsigned char octet2 = '\0';
|
||||
|
||||
|
||||
if ((octet1 == '\0') || ((octet1 >> 6) != 2)) { *bytesProcessed = 2; return code; } // Unexpected sequence
|
||||
|
||||
|
||||
octet2 = text[2];
|
||||
|
||||
|
||||
if ((octet2 == '\0') || ((octet2 >> 6) != 2)) { *bytesProcessed = 3; return code; } // Unexpected sequence
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
[0]xE0 [1]xA0-BF [2]UTF8-tail(x80-BF)
|
||||
[0]xE1-EC [1]UTF8-tail [2]UTF8-tail(x80-BF)
|
||||
[0]xED [1]x80-9F [2]UTF8-tail(x80-BF)
|
||||
[0]xEE-EF [1]UTF8-tail [2]UTF8-tail(x80-BF)
|
||||
*/
|
||||
|
||||
if (((octet == 0xe0) && !((octet1 >= 0xa0) && (octet1 <= 0xbf))) ||
|
||||
|
||||
if (((octet == 0xe0) && !((octet1 >= 0xa0) && (octet1 <= 0xbf))) ||
|
||||
((octet == 0xed) && !((octet1 >= 0x80) && (octet1 <= 0x9f)))) { *bytesProcessed = 2; return code; }
|
||||
|
||||
|
||||
if ((octet >= 0xe0) && (0 <= 0xef))
|
||||
{
|
||||
code = ((octet & 0xf) << 12) | ((octet1 & 0x3f) << 6) | (octet2 & 0x3f);
|
||||
*bytesProcessed = 3;
|
||||
}
|
||||
}
|
||||
else if ((octet & 0xf8) == 0xf0)
|
||||
else if ((octet & 0xf8) == 0xf0)
|
||||
{
|
||||
// Four octets
|
||||
if (octet > 0xf4) return code;
|
||||
|
||||
|
||||
unsigned char octet1 = text[1];
|
||||
unsigned char octet2 = '\0';
|
||||
unsigned char octet3 = '\0';
|
||||
|
||||
|
||||
if ((octet1 == '\0') || ((octet1 >> 6) != 2)) { *bytesProcessed = 2; return code; } // Unexpected sequence
|
||||
|
||||
|
||||
octet2 = text[2];
|
||||
|
||||
|
||||
if ((octet2 == '\0') || ((octet2 >> 6) != 2)) { *bytesProcessed = 3; return code; } // Unexpected sequence
|
||||
|
||||
|
||||
octet3 = text[3];
|
||||
|
||||
|
||||
if ((octet3 == '\0') || ((octet3 >> 6) != 2)) { *bytesProcessed = 4; return code; } // Unexpected sequence
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
[0]xF0 [1]x90-BF [2]UTF8-tail [3]UTF8-tail
|
||||
[0]xF1-F3 [1]UTF8-tail [2]UTF8-tail [3]UTF8-tail
|
||||
[0]xF4 [1]x80-8F [2]UTF8-tail [3]UTF8-tail
|
||||
*/
|
||||
|
||||
if (((octet == 0xf0) && !((octet1 >= 0x90) && (octet1 <= 0xbf))) ||
|
||||
|
||||
if (((octet == 0xf0) && !((octet1 >= 0x90) && (octet1 <= 0xbf))) ||
|
||||
((octet == 0xf4) && !((octet1 >= 0x80) && (octet1 <= 0x8f)))) { *bytesProcessed = 2; return code; } // Unexpected sequence
|
||||
|
||||
|
||||
if (octet >= 0xf0)
|
||||
{
|
||||
code = ((octet & 0x7) << 18) | ((octet1 & 0x3f) << 12) | ((octet2 & 0x3f) << 6) | (octet3 & 0x3f);
|
||||
*bytesProcessed = 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (code > 0x10ffff) code = 0x3f; // Codepoints after U+10ffff are invalid
|
||||
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -876,7 +876,7 @@ int *GetCodepoints(const char *text, int *count)
|
|||
{
|
||||
static int codepoints[MAX_TEXT_UNICODE_CHARS] = { 0 };
|
||||
memset(codepoints, 0, MAX_TEXT_UNICODE_CHARS*sizeof(int));
|
||||
|
||||
|
||||
int bytesProcessed = 0;
|
||||
int textLength = strlen(text);
|
||||
int codepointsCount = 0;
|
||||
|
@ -888,7 +888,7 @@ int *GetCodepoints(const char *text, int *count)
|
|||
}
|
||||
|
||||
*count = codepointsCount;
|
||||
|
||||
|
||||
return codepoints;
|
||||
}
|
||||
|
||||
|
@ -931,12 +931,12 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f
|
|||
int next = 0;
|
||||
letter = GetNextCodepoint(&text[i], &next);
|
||||
index = GetGlyphIndex(font, letter);
|
||||
|
||||
|
||||
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
|
||||
// but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set 'next = 1'
|
||||
if (letter == 0x3f) next = 1;
|
||||
if (letter == 0x3f) next = 1;
|
||||
i += (next - 1);
|
||||
|
||||
|
||||
if (letter == '\n')
|
||||
{
|
||||
// NOTE: Fixed line spacing of 1.5 lines
|
||||
|
@ -984,17 +984,17 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
|
|||
int startLine = -1; // Index where to begin drawing (where a line begins)
|
||||
int endLine = -1; // Index where to stop drawing (where a line ends)
|
||||
int lastk = -1; // Holds last value of the character position
|
||||
|
||||
|
||||
for (int i = 0, k = 0; i < length; i++, k++)
|
||||
{
|
||||
int glyphWidth = 0;
|
||||
int next = 0;
|
||||
letter = GetNextCodepoint(&text[i], &next);
|
||||
index = GetGlyphIndex(font, letter);
|
||||
|
||||
|
||||
// NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
|
||||
// but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set next = 1
|
||||
if (letter == 0x3f) next = 1;
|
||||
if (letter == 0x3f) next = 1;
|
||||
i += next - 1;
|
||||
|
||||
if (letter != '\n')
|
||||
|
@ -1012,7 +1012,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
|
|||
if (state == MEASURE_STATE)
|
||||
{
|
||||
// TODO: there are multiple types of spaces in UNICODE, maybe it's a good idea to add support for more
|
||||
// See: http://jkorpela.fi/chars/spaces.html
|
||||
// See: http://jkorpela.fi/chars/spaces.html
|
||||
if ((letter == ' ') || (letter == '\t') || (letter == '\n')) endLine = i;
|
||||
|
||||
if ((textOffsetX + glyphWidth + 1) >= rec.width)
|
||||
|
@ -1037,7 +1037,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f
|
|||
textOffsetX = 0;
|
||||
i = startLine;
|
||||
glyphWidth = 0;
|
||||
|
||||
|
||||
// Save character position when we switch states
|
||||
int tmp = lastk;
|
||||
lastk = k - 1;
|
||||
|
@ -1138,16 +1138,16 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
|
|||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
lenCounter++;
|
||||
|
||||
|
||||
int next = 0;
|
||||
letter = GetNextCodepoint(&text[i], &next);
|
||||
index = GetGlyphIndex(font, letter);
|
||||
|
||||
// NOTE: normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
|
||||
// but we need to draw all of the bad bytes using the '?' symbol so to not skip any we set next = 1
|
||||
if (letter == 0x3f) next = 1;
|
||||
i += next - 1;
|
||||
|
||||
if (letter == 0x3f) next = 1;
|
||||
i += next - 1;
|
||||
|
||||
if (letter != '\n')
|
||||
{
|
||||
if (font.chars[index].advanceX != 0) textWidth += font.chars[index].advanceX;
|
||||
|
@ -1220,22 +1220,22 @@ unsigned int TextLength(const char *text)
|
|||
|
||||
// Returns total number of characters(codepoints) in a UTF8 encoded text, until '\0' is found
|
||||
// NOTE: If an invalid UTF8 sequence is encountered a '?'(0x3f) codepoint is counted instead
|
||||
unsigned int TextCountCodepoints(const char *text)
|
||||
unsigned int TextCountCodepoints(const char *text)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
char *ptr = (char *)&text[0];
|
||||
|
||||
|
||||
while (*ptr != '\0')
|
||||
{
|
||||
int next = 0;
|
||||
int letter = GetNextCodepoint(ptr, &next);
|
||||
|
||||
|
||||
if (letter == 0x3f) ptr += 1;
|
||||
else ptr += next;
|
||||
|
||||
|
||||
len++;
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
@ -1362,14 +1362,14 @@ const char *TextJoin(const char **textList, int count, const char *delimiter)
|
|||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int textListLength = strlen(textList[i]);
|
||||
|
||||
|
||||
// Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH
|
||||
if ((totalLength + textListLength) < MAX_TEXT_BUFFER_LENGTH)
|
||||
{
|
||||
strcat(text, textList[i]);
|
||||
totalLength += textListLength;
|
||||
|
||||
if ((delimiterLen > 0) && (i < (count - 1)))
|
||||
|
||||
if ((delimiterLen > 0) && (i < (count - 1)))
|
||||
{
|
||||
strcat(text, delimiter);
|
||||
totalLength += delimiterLen;
|
||||
|
@ -1397,11 +1397,11 @@ const char **TextSplit(const char *text, char delimiter, int *count)
|
|||
|
||||
result[0] = buffer;
|
||||
int counter = 0;
|
||||
|
||||
|
||||
if (text != NULL)
|
||||
{
|
||||
counter = 1;
|
||||
|
||||
|
||||
// Count how many substrings we have on text and point to every one
|
||||
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
||||
{
|
||||
|
@ -1603,7 +1603,7 @@ static Font LoadBMFont(const char *fileName)
|
|||
ImageAlphaMask(&imFont, imFont);
|
||||
for (int p = 0; p < (imFont.width*imFont.height*2); p += 2) ((unsigned char *)(imFont.data))[p] = 0xff;
|
||||
}
|
||||
|
||||
|
||||
font.texture = LoadTextureFromImage(imFont);
|
||||
|
||||
RL_FREE(texPath);
|
||||
|
@ -1621,7 +1621,7 @@ static Font LoadBMFont(const char *fileName)
|
|||
fgets(buffer, MAX_BUFFER_SIZE, fntFile);
|
||||
sscanf(buffer, "char id=%i x=%i y=%i width=%i height=%i xoffset=%i yoffset=%i xadvance=%i",
|
||||
&charId, &charX, &charY, &charWidth, &charHeight, &charOffsetX, &charOffsetY, &charAdvanceX);
|
||||
|
||||
|
||||
// Get character rectangle in the font atlas texture
|
||||
font.recs[i] = (Rectangle){ (float)charX, (float)charY, (float)charWidth, (float)charHeight };
|
||||
|
||||
|
@ -1630,7 +1630,7 @@ static Font LoadBMFont(const char *fileName)
|
|||
font.chars[i].offsetX = charOffsetX;
|
||||
font.chars[i].offsetY = charOffsetY;
|
||||
font.chars[i].advanceX = charAdvanceX;
|
||||
|
||||
|
||||
// Fill character image data from imFont data
|
||||
font.chars[i].image = ImageFromImage(imFont, font.recs[i]);
|
||||
}
|
||||
|
|
|
@ -850,7 +850,7 @@ void ExportImageAsCode(Image image, const char *fileName)
|
|||
#define BYTES_TEXT_PER_LINE 20
|
||||
|
||||
FILE *txtFile = fopen(fileName, "wt");
|
||||
|
||||
|
||||
if (txtFile != NULL)
|
||||
{
|
||||
char varFileName[256] = { 0 };
|
||||
|
@ -926,11 +926,11 @@ Image ImageCopy(Image image)
|
|||
Image ImageFromImage(Image image, Rectangle rec)
|
||||
{
|
||||
Image result = ImageCopy(image);
|
||||
|
||||
|
||||
#if defined(SUPPORT_IMAGE_MANIPULATION)
|
||||
ImageCrop(&result, rec);
|
||||
#endif
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1189,7 +1189,7 @@ void ImageAlphaMask(Image *image, Image alphaMask)
|
|||
data[k] = ((unsigned char *)image->data)[i];
|
||||
data[k + 1] = ((unsigned char *)mask.data)[i];
|
||||
}
|
||||
|
||||
|
||||
RL_FREE(image->data);
|
||||
image->data = data;
|
||||
image->format = UNCOMPRESSED_GRAY_ALPHA;
|
||||
|
@ -1343,13 +1343,13 @@ void ImageCrop(Image *image, Rectangle crop)
|
|||
{
|
||||
// Security check to avoid program crash
|
||||
if ((image->data == NULL) || (image->width == 0) || (image->height == 0)) return;
|
||||
|
||||
|
||||
// Security checks to validate crop rectangle
|
||||
if (crop.x < 0) { crop.width += crop.x; crop.x = 0; }
|
||||
if (crop.y < 0) { crop.height += crop.y; crop.y = 0; }
|
||||
if ((crop.x + crop.width) > image->width) crop.width = image->width - crop.x;
|
||||
if ((crop.y + crop.height) > image->height) crop.height = image->height - crop.y;
|
||||
|
||||
|
||||
if ((crop.x < image->width) && (crop.y < image->height))
|
||||
{
|
||||
// Start the cropping process
|
||||
|
@ -1823,7 +1823,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
|
|||
}
|
||||
|
||||
Image srcCopy = ImageCopy(src); // Make a copy of source image to work with it
|
||||
|
||||
|
||||
// Crop source image to desired source rectangle (if required)
|
||||
if ((src.width != (int)srcRec.width) && (src.height != (int)srcRec.height)) ImageCrop(&srcCopy, srcRec);
|
||||
|
||||
|
@ -1832,7 +1832,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
|
|||
{
|
||||
ImageResize(&srcCopy, (int)dstRec.width, (int)dstRec.height);
|
||||
}
|
||||
|
||||
|
||||
// Check that dstRec is inside dst image
|
||||
// Allow negative position within destination with cropping
|
||||
if (dstRec.x < 0)
|
||||
|
@ -1841,7 +1841,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
|
|||
dstRec.width = dstRec.width + dstRec.x;
|
||||
dstRec.x = 0;
|
||||
}
|
||||
|
||||
|
||||
if ((dstRec.x + dstRec.width) > dst->width)
|
||||
{
|
||||
ImageCrop(&srcCopy, (Rectangle) { 0, 0, dst->width - dstRec.x, dstRec.height });
|
||||
|
@ -1854,7 +1854,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
|
|||
dstRec.height = dstRec.height + dstRec.y;
|
||||
dstRec.y = 0;
|
||||
}
|
||||
|
||||
|
||||
if ((dstRec.y + dstRec.height) > dst->height)
|
||||
{
|
||||
ImageCrop(&srcCopy, (Rectangle) { 0, 0, dstRec.width, dst->height - dstRec.y });
|
||||
|
@ -1880,7 +1880,7 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
|
|||
|
||||
fdst = ColorNormalize(dstPixels[j*(int)dst->width + i]);
|
||||
fsrc = ColorNormalize(srcPixels[(j - (int)dstRec.y)*(int)dstRec.width + (i - (int)dstRec.x)]);
|
||||
|
||||
|
||||
// Apply color tint to source image
|
||||
fsrc.x *= ftint.x; fsrc.y *= ftint.y; fsrc.z *= ftint.z; fsrc.w *= ftint.w;
|
||||
|
||||
|
@ -1943,16 +1943,16 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
|
|||
|
||||
// Create image to store text
|
||||
Image imText = GenImageColor((int)imSize.x, (int)imSize.y, BLANK);
|
||||
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
int next = 0;
|
||||
letter = GetNextCodepoint(&text[i], &next);
|
||||
index = GetGlyphIndex(font, letter);
|
||||
|
||||
if (letter == 0x3f) next = 1;
|
||||
|
||||
if (letter == 0x3f) next = 1;
|
||||
i += (next - 1);
|
||||
|
||||
|
||||
if (letter == '\n')
|
||||
{
|
||||
// TODO: Support line break
|
||||
|
@ -1962,7 +1962,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co
|
|||
if (letter != ' ')
|
||||
{
|
||||
ImageDraw(&imText, font.chars[index].image, (Rectangle){ 0, 0, font.chars[index].image.width, font.chars[index].image.height },
|
||||
(Rectangle){ (float)(positionX + font.chars[index].offsetX),(float)font.chars[index].offsetY,
|
||||
(Rectangle){ (float)(positionX + font.chars[index].offsetX),(float)font.chars[index].offsetY,
|
||||
font.chars[index].image.width, font.chars[index].image.height }, tint);
|
||||
}
|
||||
|
||||
|
@ -2717,9 +2717,9 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V
|
|||
{
|
||||
float width = (float)texture.width;
|
||||
float height = (float)texture.height;
|
||||
|
||||
|
||||
bool flipX = false;
|
||||
|
||||
|
||||
if (sourceRec.width < 0) { flipX = true; sourceRec.width *= -1; }
|
||||
if (sourceRec.height < 0) sourceRec.y -= sourceRec.height;
|
||||
|
||||
|
@ -2981,12 +2981,12 @@ static Image LoadAnimatedGIF(const char *fileName, int *frames, int **delays)
|
|||
fseek(gifFile, 0L, SEEK_END);
|
||||
int size = ftell(gifFile);
|
||||
fseek(gifFile, 0L, SEEK_SET);
|
||||
|
||||
|
||||
unsigned char *buffer = (unsigned char *)RL_CALLOC(size, sizeof(char));
|
||||
fread(buffer, sizeof(char), size, gifFile);
|
||||
|
||||
|
||||
fclose(gifFile); // Close file pointer
|
||||
|
||||
|
||||
int comp = 0;
|
||||
image.data = stbi_load_gif_from_memory(buffer, size, delays, &image.width, &image.height, frames, &comp, 4);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
// Some basic Defines
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
#define fopen(name, mode) android_fopen(name, mode)
|
||||
#define fopen(name, mode) android_fopen(name, mode)
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -86,8 +86,8 @@ typedef enum {
|
|||
|
||||
typedef struct UWPMessage {
|
||||
UWPMessageType type; // Message type
|
||||
|
||||
Vector2 paramVector0; // Vector parameters
|
||||
|
||||
Vector2 paramVector0; // Vector parameters
|
||||
int paramInt0; // Int parameter
|
||||
int paramInt1; // Int parameter
|
||||
char paramChar0; // Char parameters
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue