Got through parsing raylib.h, started to do some major refactors.

This commit is contained in:
Edward R. Gonzalez 2023-10-25 03:26:25 -04:00
parent d0f3b6187e
commit 041671762b
14 changed files with 8592 additions and 7039 deletions

View File

@ -97,35 +97,13 @@
// #define RLGL_SHOW_GL_DETAILS_INFO 1
// #define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 4096 // Default internal render batch elements limits
#define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
#define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
#define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
#define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack
#define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
#define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance
#define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance
// Default shader vertex attribute names to set location points
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
#define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
#define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
#define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
#define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
//------------------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -78,20 +78,23 @@
//----------------------------------------------------------------------------------
#if defined( RCAMERA_STANDALONE )
// Vector2, 2 components
typedef struct Vector2 {
typedef struct Vector2
{
float x; // Vector x component
float y; // Vector y component
} Vector2;
// Vector3, 3 components
typedef struct Vector3 {
typedef struct Vector3
{
float x; // Vector x component
float y; // Vector y component
float z; // Vector z component
} Vector3;
// Matrix, 4x4 components, column major, OpenGL style, right-handed
typedef struct Matrix {
typedef struct Matrix
{
float m0, m4, m8, m12; // Matrix first row (4 components)
float m1, m5, m9, m13; // Matrix second row (4 components)
float m2, m6, m10, m14; // Matrix third row (4 components)
@ -99,7 +102,8 @@
} Matrix;
// Camera type, defines a camera position/orientation in 3d space
typedef struct Camera3D {
typedef struct Camera3D
{
Vector3 position; // Camera position
Vector3 target; // Camera target it looks-at
Vector3 up; // Camera up vector (rotation over its axis)
@ -110,13 +114,15 @@
typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D
// Camera projection
typedef enum {
typedef enum
{
CAMERA_PERSPECTIVE = 0, // Perspective projection
CAMERA_ORTHOGRAPHIC // Orthographic projection
} CameraProjection;
// Camera system modes
typedef enum {
typedef enum
{
CAMERA_CUSTOM = 0, // Camera custom, controlled by user (UpdateCamera() does nothing)
CAMERA_FREE, // Camera free mode
CAMERA_ORBITAL, // Camera orbital, around target, zoom supported
@ -135,7 +141,8 @@
//----------------------------------------------------------------------------------
#if defined( __cplusplus )
extern "C" { // Prevents name mangling of functions
extern "C"
{ // Prevents name mangling of functions
#endif
RLAPI Vector3 GetCameraForward( Camera* camera );
@ -316,7 +323,8 @@ void CameraMoveToTarget(Camera *camera, float delta)
distance += delta;
// Distance must be greater than 0
if (distance <= 0) distance = 0.001f;
if ( distance <= 0 )
distance = 0.001f;
// Set new distance by moving the position along the forward vector
Vector3 forward = GetCameraForward( camera );
@ -371,13 +379,15 @@ void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAroundTa
// Clamp view up
float maxAngleUp = Vector3Angle( up, targetPosition );
maxAngleUp -= 0.001f; // avoid numerical errors
if (angle > maxAngleUp) angle = maxAngleUp;
if ( angle > maxAngleUp )
angle = maxAngleUp;
// Clamp view down
float maxAngleDown = Vector3Angle( Vector3Negate( up ), targetPosition );
maxAngleDown *= -1.0f; // downwards angle is negative
maxAngleDown += 0.001f; // avoid numerical errors
if (angle < maxAngleDown) angle = maxAngleDown;
if ( angle < maxAngleDown )
angle = maxAngleDown;
}
// Rotation axis
@ -463,12 +473,18 @@ void UpdateCamera(Camera *camera, int mode)
else
{
// Camera rotation
if (IsKeyDown(KEY_DOWN)) CameraPitch(camera, -CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
if (IsKeyDown(KEY_UP)) CameraPitch(camera, CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
if (IsKeyDown(KEY_RIGHT)) CameraYaw(camera, -CAMERA_ROTATION_SPEED, rotateAroundTarget);
if (IsKeyDown(KEY_LEFT)) CameraYaw(camera, CAMERA_ROTATION_SPEED, rotateAroundTarget);
if (IsKeyDown(KEY_Q)) CameraRoll(camera, -CAMERA_ROTATION_SPEED);
if (IsKeyDown(KEY_E)) CameraRoll(camera, CAMERA_ROTATION_SPEED);
if ( IsKeyDown( KEY_DOWN ) )
CameraPitch( camera, -CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp );
if ( IsKeyDown( KEY_UP ) )
CameraPitch( camera, CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp );
if ( IsKeyDown( KEY_RIGHT ) )
CameraYaw( camera, -CAMERA_ROTATION_SPEED, rotateAroundTarget );
if ( IsKeyDown( KEY_LEFT ) )
CameraYaw( camera, CAMERA_ROTATION_SPEED, rotateAroundTarget );
if ( IsKeyDown( KEY_Q ) )
CameraRoll( camera, -CAMERA_ROTATION_SPEED );
if ( IsKeyDown( KEY_E ) )
CameraRoll( camera, CAMERA_ROTATION_SPEED );
// Camera movement
if ( ! IsGamepadAvailable( 0 ) )
@ -477,10 +493,14 @@ void UpdateCamera(Camera *camera, int mode)
if ( ( mode == CAMERA_FREE ) && ( IsMouseButtonDown( MOUSE_BUTTON_MIDDLE ) ) )
{
const Vector2 mouseDelta = GetMouseDelta();
if (mouseDelta.x > 0.0f) CameraMoveRight(camera, CAMERA_PAN_SPEED, moveInWorldPlane);
if (mouseDelta.x < 0.0f) CameraMoveRight(camera, -CAMERA_PAN_SPEED, moveInWorldPlane);
if (mouseDelta.y > 0.0f) CameraMoveUp(camera, -CAMERA_PAN_SPEED);
if (mouseDelta.y < 0.0f) CameraMoveUp(camera, CAMERA_PAN_SPEED);
if ( mouseDelta.x > 0.0f )
CameraMoveRight( camera, CAMERA_PAN_SPEED, moveInWorldPlane );
if ( mouseDelta.x < 0.0f )
CameraMoveRight( camera, -CAMERA_PAN_SPEED, moveInWorldPlane );
if ( mouseDelta.y > 0.0f )
CameraMoveUp( camera, -CAMERA_PAN_SPEED );
if ( mouseDelta.y < 0.0f )
CameraMoveUp( camera, CAMERA_PAN_SPEED );
}
else
{
@ -490,27 +510,43 @@ void UpdateCamera(Camera *camera, int mode)
}
// Keyboard support
if (IsKeyDown(KEY_W)) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_A)) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_S)) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (IsKeyDown(KEY_D)) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
if ( IsKeyDown( KEY_W ) )
CameraMoveForward( camera, CAMERA_MOVE_SPEED, moveInWorldPlane );
if ( IsKeyDown( KEY_A ) )
CameraMoveRight( camera, -CAMERA_MOVE_SPEED, moveInWorldPlane );
if ( IsKeyDown( KEY_S ) )
CameraMoveForward( camera, -CAMERA_MOVE_SPEED, moveInWorldPlane );
if ( IsKeyDown( KEY_D ) )
CameraMoveRight( camera, CAMERA_MOVE_SPEED, moveInWorldPlane );
}
else
{
// Gamepad controller support
CameraYaw( camera, -( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_RIGHT_X ) * 2 ) * CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget );
CameraPitch(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y) * 2)*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
CameraPitch(
camera,
-( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_RIGHT_Y ) * 2 ) * CAMERA_MOUSE_MOVE_SENSITIVITY,
lockView,
rotateAroundTarget,
rotateUp
);
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) <= -0.25f) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) <= -0.25f) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) >= 0.25f) CameraMoveForward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) >= 0.25f) CameraMoveRight(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
if ( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_LEFT_Y ) <= -0.25f )
CameraMoveForward( camera, CAMERA_MOVE_SPEED, moveInWorldPlane );
if ( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_LEFT_X ) <= -0.25f )
CameraMoveRight( camera, -CAMERA_MOVE_SPEED, moveInWorldPlane );
if ( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_LEFT_Y ) >= 0.25f )
CameraMoveForward( camera, -CAMERA_MOVE_SPEED, moveInWorldPlane );
if ( GetGamepadAxisMovement( 0, GAMEPAD_AXIS_LEFT_X ) >= 0.25f )
CameraMoveRight( camera, CAMERA_MOVE_SPEED, moveInWorldPlane );
}
if ( mode == CAMERA_FREE )
{
if (IsKeyDown(KEY_SPACE)) CameraMoveUp(camera, CAMERA_MOVE_SPEED);
if (IsKeyDown(KEY_LEFT_CONTROL)) CameraMoveUp(camera, -CAMERA_MOVE_SPEED);
if ( IsKeyDown( KEY_SPACE ) )
CameraMoveUp( camera, CAMERA_MOVE_SPEED );
if ( IsKeyDown( KEY_LEFT_CONTROL ) )
CameraMoveUp( camera, -CAMERA_MOVE_SPEED );
}
}
@ -518,8 +554,10 @@ void UpdateCamera(Camera *camera, int mode)
{
// Zoom target distance
CameraMoveToTarget( camera, -GetMouseWheelMove() );
if (IsKeyPressed(KEY_KP_SUBTRACT)) CameraMoveToTarget(camera, 2.0f);
if (IsKeyPressed(KEY_KP_ADD)) CameraMoveToTarget(camera, -2.0f);
if ( IsKeyPressed( KEY_KP_SUBTRACT ) )
CameraMoveToTarget( camera, 2.0f );
if ( IsKeyPressed( KEY_KP_ADD ) )
CameraMoveToTarget( camera, -2.0f );
}
}
#endif // !RCAMERA_STANDALONE

View File

@ -103,12 +103,23 @@
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef struct { int x; int y; } Point;
typedef struct { unsigned int width; unsigned int height; } Size;
typedef struct
{
int x;
int y;
} Point;
typedef struct
{
unsigned int width;
unsigned int height;
} Size;
// Core global state context data
typedef struct CoreData {
struct {
typedef struct CoreData
{
struct
{
const char* title; // Window text title const pointer
unsigned int flags; // Configuration flags (bit based), keeps window state
bool ready; // Check if window has been initialized successfully
@ -133,12 +144,17 @@ typedef struct CoreData {
unsigned int dropFileCount; // Count dropped files strings
} Window;
struct {
struct
{
const char* basePath; // Base path for data storage
} Storage;
struct {
struct {
struct
{
struct
{
int exitKey; // Default exit key
char currentKeyState[ MAX_KEYBOARD_KEYS ]; // Registers current frame key state
char previousKeyState[ MAX_KEYBOARD_KEYS ]; // Registers previous frame key state
@ -153,7 +169,9 @@ typedef struct CoreData {
int charPressedQueueCount; // Input characters queue count
} Keyboard;
struct {
struct
{
Vector2 offset; // Mouse offset
Vector2 scale; // Mouse scaling
Vector2 currentPosition; // Mouse position on screen
@ -169,7 +187,9 @@ typedef struct CoreData {
Vector2 previousWheelMove; // Registers previous mouse wheel variation
} Mouse;
struct {
struct
{
int pointCount; // Number of touch points active
int pointId[ MAX_TOUCH_POINTS ]; // Point identifiers
Vector2 position[ MAX_TOUCH_POINTS ]; // Touch position on screen
@ -177,7 +197,9 @@ typedef struct CoreData {
char previousTouchState[ MAX_TOUCH_POINTS ]; // Registers previous touch state
} Touch;
struct {
struct
{
int lastButtonPressed; // Register last gamepad button pressed
int axisCount[ MAX_GAMEPADS ]; // Register number of available gamepad axis
bool ready[ MAX_GAMEPADS ]; // Flag to know if gamepad is ready
@ -188,7 +210,9 @@ typedef struct CoreData {
} Gamepad;
} Input;
struct {
struct
{
double current; // Current time measure
double previous; // Previous time measure
double update; // Time measure for frame update

View File

@ -62,12 +62,17 @@
#if ( defined( __STDC__ ) && __STDC_VERSION__ >= 199901L ) || ( defined( _MSC_VER ) && _MSC_VER >= 1800 )
#include <stdbool.h>
#elif ! defined( __cplusplus ) && ! defined( bool ) && ! defined( RL_BOOL_TYPE )
typedef enum bool { false = 0, true = !false } bool;
typedef enum bool
{
false = 0,
true = ! false
} bool;
#endif
#if ! defined( RL_VECTOR2_TYPE )
// Vector2 type
typedef struct Vector2 {
typedef struct Vector2
{
float x;
float y;
} Vector2;
@ -76,7 +81,8 @@ typedef struct Vector2 {
#if defined( RGESTURES_STANDALONE )
// Gestures type
// NOTE: It could be used as flags to enable only some gestures
typedef enum {
typedef enum
{
GESTURE_NONE = 0,
GESTURE_TAP = 1,
GESTURE_DOUBLETAP = 2,
@ -91,7 +97,8 @@ typedef enum {
} Gesture;
#endif
typedef enum {
typedef enum
{
TOUCH_ACTION_UP = 0,
TOUCH_ACTION_DOWN,
TOUCH_ACTION_MOVE,
@ -99,7 +106,8 @@ typedef enum {
} TouchAction;
// Gesture event
typedef struct {
typedef struct
{
int touchAction;
int pointCount;
int pointId[ MAX_TOUCH_POINTS ];
@ -116,7 +124,8 @@ typedef struct {
//----------------------------------------------------------------------------------
#if defined( __cplusplus )
extern "C" { // Prevents name mangling of functions
extern "C"
{ // Prevents name mangling of functions
#endif
void ProcessGestureEvent( GestureEvent event ); // Process gesture event and translate it into gestures
@ -151,7 +160,8 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
#if defined( RGESTURES_STANDALONE )
#if defined( _WIN32 )
#if defined( __cplusplus )
extern "C" { // Prevents name mangling of functions
extern "C"
{ // Prevents name mangling of functions
#endif
// Functions required to query time on Windows
int __stdcall QueryPerformanceCounter( unsigned long long int* lpPerformanceCount );
@ -191,10 +201,13 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
//----------------------------------------------------------------------------------
// Gestures module state context [136 bytes]
typedef struct {
typedef struct
{
unsigned int current; // Current detected gesture
unsigned int enabledFlags; // Enabled gestures flags
struct {
struct
{
int firstId; // Touch id for first touch point
int pointCount; // Touch points counter
double eventTime; // Time stamp when an event happened
@ -208,20 +221,28 @@ typedef struct {
Vector2 previousPositionB; // Previous position B to compare for pinch gestures
int tapCounter; // TAP counter (one tap implies TOUCH_ACTION_DOWN and TOUCH_ACTION_UP actions)
} Touch;
struct {
struct
{
bool resetRequired; // HOLD reset to get first touch point again
double timeDuration; // HOLD duration in seconds
} Hold;
struct {
struct
{
Vector2 vector; // DRAG vector (between initial and current position)
float angle; // DRAG angle (relative to x-axis)
float distance; // DRAG distance (from initial touch point to final) (normalized [0..1])
float intensity; // DRAG intensity, how far why did the DRAG (pixels per frame)
} Drag;
struct {
struct
{
double startTime; // SWIPE start time to calculate drag intensity
} Swipe;
struct {
struct
{
Vector2 vector; // PINCH vector (between first and second touch points)
float angle; // PINCH angle (relative to x-axis)
float distance; // PINCH displacement distance (normalized [0..1])
@ -257,8 +278,10 @@ void SetGesturesEnabled(unsigned int flags)
// Check if a gesture have been detected
bool IsGestureDetected( unsigned int gesture )
{
if ((GESTURES.enabledFlags & GESTURES.current) == gesture) return true;
else return false;
if ( ( GESTURES.enabledFlags & GESTURES.current ) == gesture )
return true;
else
return false;
}
// Process gesture event and translate it into gestures
@ -274,7 +297,9 @@ void ProcessGestureEvent(GestureEvent event)
GESTURES.Touch.tapCounter++; // Tap counter
// Detect GESTURE_DOUBLE_TAP
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) && ((rgGetCurrentTime() - GESTURES.Touch.eventTime) < TAP_TIMEOUT) && (rgVector2Distance(GESTURES.Touch.downPositionA, event.position[0]) < DOUBLETAP_RANGE))
if ( ( GESTURES.current == GESTURE_NONE ) && ( GESTURES.Touch.tapCounter >= 2 )
&& ( ( rgGetCurrentTime() - GESTURES.Touch.eventTime ) < TAP_TIMEOUT )
&& ( rgVector2Distance( GESTURES.Touch.downPositionA, event.position[ 0 ] ) < DOUBLETAP_RANGE ) )
{
GESTURES.current = GESTURE_DOUBLETAP;
GESTURES.Touch.tapCounter = 0;
@ -298,7 +323,8 @@ void ProcessGestureEvent(GestureEvent event)
else if ( event.touchAction == TOUCH_ACTION_UP )
{
// A swipe can happen while the current gesture is drag, but (specially for web) also hold, so set upPosition for both cases
if (GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD) GESTURES.Touch.upPosition = event.position[0];
if ( GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD )
GESTURES.Touch.upPosition = event.position[ 0 ];
// NOTE: GESTURES.Drag.intensity dependent on the resolution of the screen
GESTURES.Drag.distance = rgVector2Distance( GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition );
@ -310,11 +336,16 @@ void ProcessGestureEvent(GestureEvent event)
// NOTE: Angle should be inverted in Y
GESTURES.Drag.angle = 360.0f - rgVector2Angle( GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition );
if ((GESTURES.Drag.angle < 30) || (GESTURES.Drag.angle > 330)) GESTURES.current = GESTURE_SWIPE_RIGHT; // Right
else if ((GESTURES.Drag.angle >= 30) && (GESTURES.Drag.angle <= 150)) GESTURES.current = GESTURE_SWIPE_UP; // Up
else if ((GESTURES.Drag.angle > 150) && (GESTURES.Drag.angle < 210)) GESTURES.current = GESTURE_SWIPE_LEFT; // Left
else if ((GESTURES.Drag.angle >= 210) && (GESTURES.Drag.angle <= 330)) GESTURES.current = GESTURE_SWIPE_DOWN; // Down
else GESTURES.current = GESTURE_NONE;
if ( ( GESTURES.Drag.angle < 30 ) || ( GESTURES.Drag.angle > 330 ) )
GESTURES.current = GESTURE_SWIPE_RIGHT; // Right
else if ( ( GESTURES.Drag.angle >= 30 ) && ( GESTURES.Drag.angle <= 150 ) )
GESTURES.current = GESTURE_SWIPE_UP; // Up
else if ( ( GESTURES.Drag.angle > 150 ) && ( GESTURES.Drag.angle < 210 ) )
GESTURES.current = GESTURE_SWIPE_LEFT; // Left
else if ( ( GESTURES.Drag.angle >= 210 ) && ( GESTURES.Drag.angle <= 330 ) )
GESTURES.current = GESTURE_SWIPE_DOWN; // Down
else
GESTURES.current = GESTURE_NONE;
}
else
{
@ -334,7 +365,8 @@ void ProcessGestureEvent(GestureEvent event)
if ( GESTURES.current == GESTURE_HOLD )
{
if (GESTURES.Hold.resetRequired) GESTURES.Touch.downPositionA = event.position[0];
if ( GESTURES.Hold.resetRequired )
GESTURES.Touch.downPositionA = event.position[ 0 ];
GESTURES.Hold.resetRequired = false;
@ -378,10 +410,14 @@ void ProcessGestureEvent(GestureEvent event)
GESTURES.Pinch.vector.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x;
GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y;
if ((rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (rgVector2Distance(GESTURES.Touch.previousPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH))
if ( ( rgVector2Distance( GESTURES.Touch.previousPositionA, GESTURES.Touch.moveDownPositionA ) >= MINIMUM_PINCH )
|| ( rgVector2Distance( GESTURES.Touch.previousPositionB, GESTURES.Touch.moveDownPositionB ) >= MINIMUM_PINCH ) )
{
if ( rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.previousPositionB) > rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) ) GESTURES.current = GESTURE_PINCH_IN;
else GESTURES.current = GESTURE_PINCH_OUT;
if ( rgVector2Distance( GESTURES.Touch.previousPositionA, GESTURES.Touch.previousPositionB )
> rgVector2Distance( GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB ) )
GESTURES.current = GESTURE_PINCH_IN;
else
GESTURES.current = GESTURE_PINCH_OUT;
}
else
{
@ -421,7 +457,8 @@ void UpdateGestures(void)
}
// Detect GESTURE_NONE
if ((GESTURES.current == GESTURE_SWIPE_RIGHT) || (GESTURES.current == GESTURE_SWIPE_UP) || (GESTURES.current == GESTURE_SWIPE_LEFT) || (GESTURES.current == GESTURE_SWIPE_DOWN))
if ( ( GESTURES.current == GESTURE_SWIPE_RIGHT ) || ( GESTURES.current == GESTURE_SWIPE_UP ) || ( GESTURES.current == GESTURE_SWIPE_LEFT )
|| ( GESTURES.current == GESTURE_SWIPE_DOWN ) )
{
GESTURES.current = GESTURE_NONE;
}
@ -441,7 +478,8 @@ float GetGestureHoldDuration(void)
double time = 0.0;
if (GESTURES.current == GESTURE_HOLD) time = rgGetCurrentTime() - GESTURES.Hold.timeDuration;
if ( GESTURES.current == GESTURE_HOLD )
time = rgGetCurrentTime() - GESTURES.Hold.timeDuration;
return ( float )time;
}
@ -488,7 +526,8 @@ static float rgVector2Angle(Vector2 v1, Vector2 v2)
{
float angle = atan2f( v2.y - v1.y, v2.x - v1.x ) * ( 180.0f / PI );
if (angle < 0) angle += 360.0f;
if ( angle < 0 )
angle += 360.0f;
return angle;
}

File diff suppressed because it is too large Load Diff

View File

@ -66,7 +66,8 @@
// Module Functions Declaration
//----------------------------------------------------------------------------------
#if defined( __cplusplus )
extern "C" { // Prevents name mangling of functions
extern "C"
{ // Prevents name mangling of functions
#endif
#if defined( PLATFORM_ANDROID )

View File

@ -0,0 +1,9 @@
__VERSION 1
word SUPPORT_MODULE_RSHAPES, RL_SUPPORT_MODULE_RSHAPES
word SUPPORT_MODULE_RTEXTURES, RL_SUPPORT_MODULE_RTEXTURES
word SUPPORT_MODULE_RTEXT, RL_SUPPORT_MODULE_RTEXT
word SUPPORT_MODULE_RMODELS, RL_SUPPORT_MODULE_RMODELS
word SUPPORT_MODULE_RAUDIO, RL_SUPPORT_MODULE_RAUDIO

View File

@ -17,41 +17,272 @@ constexpr char const* path_rtext = "rtext.h";
using namespace gen;
void refactor_file( CodeBody code_file )
StringCached upper_snake_to_mixed_snake(StringCached str)
{
local_persist String scratch = String::make_reserve(GlobalAllocator, kilobytes(1));
scratch.clear();
bool capitalizeNext = true;
for (s32 index = 0; index < str.length(); ++index)
{
char c = str[index];
if (c == '_')
{
scratch.append(c);
capitalizeNext = true;
}
else if (capitalizeNext)
{
if (c >= 'a' && c <= 'z')
{
scratch.append(c - 32); // Convert to uppercase
}
else
{
scratch.append(c);
}
capitalizeNext = false;
}
else
{
if (c >= 'A' && c <= 'Z')
{
scratch.append(c + 32); // Convert to lowercase
}
else
{
scratch.append(c);
}
}
}
StringCached result = get_cached_string(scratch);
return result;
}
StringCached pascal_to_lower_snake(StringCached str)
{
local_persist String scratch = String::make_reserve(GlobalAllocator, kilobytes(1));
scratch.clear();
for (s32 index = 0; index < str.length(); ++index)
{
char c = str[index];
char next = (index + 1 < str.length()) ? str[index + 1] : '\0'; // Ensure we don't go out of bounds
// Whitelist check for "2D" and "3D"
if ((c == '2' || c == '3' | c == '4') && (next == 'D' || next == 'd'))
{
if (index > 0) // If it's not the start of the string, append an underscore
{
char* prev = str.Data + index - 1;
if (*prev != '_') // Avoid double underscores
{
scratch.append('_');
}
}
scratch.append(c);
scratch.append('d'); // Convert to lowercase
index++; // Skip the next character since we've already processed it
continue;
}
if (c >= 'A' && c <= 'Z')
{
char* prev = (index > 0) ? str.Data + index - 1 : nullptr;
if ((index > 0 && prev && *prev >= 'a' && *prev <= 'z') ||
(prev && char_is_digit(*prev) && (next >= 'A' && next <= 'Z')))
{
scratch.append('_');
}
scratch.append(c + 32);
}
else if (char_is_digit(c) && (next >= 'A' && next <= 'Z')) // Check for a number followed by an uppercase letter
{
scratch.append(c);
scratch.append('_');
}
else
{
scratch.append(c);
}
}
StringCached result = get_cached_string(scratch);
return result;
}
void refactor_enum( CodeEnum& code )
{
for ( Code elem : code->Body )
{
if ( elem->Type == ECode::Untyped )
{
elem->Content = upper_snake_to_mixed_snake( elem->Content );
}
}
}
void refactor_typename( CodeType& type )
{
local_persist CodeType t_unsigned_char = parse_type( code(unsigned char) );
local_persist CodeType t_unsigned_char_ptr = parse_type( code(unsigned char*) );
local_persist CodeType t_unsigned_short_ptr = parse_type( code(unsigned short*) );
local_persist CodeType t_int = parse_type( code(int) );
local_persist CodeType t_int_ptr = parse_type( code(int*) );
local_persist CodeType t_unsigned_int = parse_type( code(unsigned int) );
local_persist CodeType t_float = parse_type( code(float) );
local_persist CodeType t_float_ptr = parse_type( code(float*) );
local_persist CodeType t_f32_ptr = parse_type( code(f32*) );
local_persist CodeType t_u8_ptr = parse_type( code(u8*) );
local_persist CodeType t_s32_ptr = parse_type( code(s32*) );
String type_str = type.to_string();
if ( str_compare( type_str, t_unsigned_char.to_string() ) == 0 )
{
type.ast = t_u8.ast;
}
if ( str_compare( type_str, t_unsigned_char_ptr.to_string() ) == 0 )
{
type.ast = t_u8_ptr.ast;
}
if ( str_compare( type_str, t_unsigned_short_ptr.to_string() ) == 0 )
{
type.ast = t_u8_ptr.ast;
}
if ( str_compare( type_str, t_int.to_string() ) == 0 )
{
type.ast = t_s32.ast;
}
if ( str_compare( type_str, t_int_ptr.to_string() ) == 0 )
{
type.ast = t_s32_ptr.ast;
}
if ( str_compare( type_str, t_unsigned_int.to_string() ) == 0 )
{
type.ast = t_u32.ast;
}
if ( str_compare( type_str, t_float.to_string() ) == 0 )
{
type.ast = t_f32.ast;
}
if ( str_compare( type_str, t_float_ptr.to_string() ) == 0 )
{
type.ast = t_f32_ptr.ast;
}
}
void refactor_fn( CodeFn& fn )
{
fn->Name = pascal_to_lower_snake( fn->Name );
for ( CodeParam param : fn->Params )
{
refactor_typename( param->ValueType );
}
}
void refactor_struct( CodeStruct& code )
{
for ( Code field : code->Body )
{
if ( field->Type == ECode::Variable )
{
CodeVar var = field.cast<CodeVar>();
refactor_typename( var->ValueType );
}
}
}
void refactor_file( char const* path )
{
FileContents contents = file_read_contents( GlobalAllocator, true, path );
CodeBody code = parse_global_body( { contents.size, rcast(char const*, contents.data) } );
String name_scratch = String::make_reserve( GlobalAllocator, kilobytes(1) );
for ( Code elem : code_file )
// CodeBody includes
// CodeBody nspace_body = def_body( ECode::Namespace );
CodeBody new_code = def_body( ECode::Global_Body );
for ( Code elem : code )
{
if ( elem->Type == ECode::Preprocess_Define )
{
if ( str_compare( elem->Name, txt("RL_"), 2 ) == 0 )
if ( str_compare( elem->Name, txt("RL"), 2 ) == 0 || str_compare( elem->Name, txt("RAYLIB"), 6 ) == 0 )
continue;
name_scratch.append_fmt( "%RL_%S", elem->Name );
elem->Name = get_cached_string( name_scratch );
name_scratch.clear();
}
if ( elem->Type == ECode::Enum )
{
refactor_enum( elem.cast<CodeEnum>() );
}
if ( elem->Type == ECode::Typedef )
{
CodeTypedef td = elem.cast<CodeTypedef>();
if ( td->UnderlyingType->Type == ECode::Enum )
{
CodeEnum code = td->UnderlyingType.cast<CodeEnum>();
refactor_enum( code );
}
if ( td->UnderlyingType->Type == ECode::Struct )
{
CodeStruct code = td->UnderlyingType.cast<CodeStruct>();
refactor_struct( code );
}
}
if ( elem->Type == ECode::Struct )
{
refactor_struct( elem.cast<CodeStruct>() );
}
if ( elem->Type == ECode::Function || elem->Type == ECode::Function_Fwd )
{
refactor_fn( elem.cast<CodeFn>() );
}
if ( elem->Type == ECode::Extern_Linkage )
{
CodeBody body = elem.cast<CodeExtern>()->Body;
for ( Code elem : body )
{
if ( elem->Type == ECode::Function || elem->Type == ECode::Function_Fwd )
{
refactor_fn( elem.cast<CodeFn>() );
}
}
Code nspace = def_namespace( txt("raylib"), def_namespace_body( args(elem) ) );
elem = nspace;
}
new_code.append( elem );
}
Builder builder = Builder::open( path );
builder.print( new_code );
builder.write();
}
int gen_main()
{
gen::init();
FileContents config_file_content = file_read_contents( GlobalAllocator, true, path_config );
CodeBody config_code = parse_global_body( { config_file_content.size, rcast(char const*, config_file_content.data) } );
refactor_file( config_code );
Builder config_builder = Builder::open( path_config );
config_builder.print( config_code );
config_builder.write();
FileContents raylib_file_content = file_read_contents( GlobalAllocator, true, path_raylib );
CodeBody raylib_code = parse_global_body( { raylib_file_content.size, rcast(char const*, raylib_file_content.data) } );
refactor_file( raylib_code );
Builder raylib_builder = Builder::open( path_raylib );
config_builder.print( raylib_code );
config_builder.write();
refactor_file( path_config );
refactor_file( path_raylib );
refactor_file( path_raymath );
return 0;
}

View File

@ -85,8 +85,12 @@ function setup-raylib {
New-Item $path_build -ItemType Directory
}
$raylib_headers = Get-ChildItem -Path $path_raylib_src -Filter "*.h" -File
$raylib_modules = get-childitem -path $path_raylib_src -filter "*.c" -file
# Refactor raylib
if ( $true ) {
# if ( $false ) {
$path_gencpp = join-path $path_root 'project/gen'
$includes = @(
@ -114,6 +118,18 @@ function setup-raylib {
}
}
Pop-Location
push-location $path_scripts
# Time to format
$fmt_includes = @()
foreach ( $header in $raylib_headers ) {
$fmt_includes += split-path $header -leaf
}
foreach ( $module in $raylib_modules ) {
$fmt_includes += split-path $module -leaf
}
format-cpp $path_raylib_src $fmt_includes $null
pop-location
}
# Build raylib
@ -151,12 +167,10 @@ function setup-raylib {
$dll = join-path $path_raylib_lib 'raylib.dll'
# $build_result = build-simple $path_build $includes $compiler_args $linker_args $unit $dll
$raylib_modules = get-childitem -path $path_raylib_src -filter "*.c" -file
$build_result = build $path_build $includes $compiler_args $linker_args $raylib_modules $dll
}
# Move headers to used include
$raylib_headers = Get-ChildItem -Path $path_raylib_src -Filter "*.h" -File
foreach ($header in $raylib_headers) {
Copy-Item -Path $header -Destination (join-path $path_raylib_inc (split-path $header -Leaf))
}

View File

@ -475,7 +475,8 @@ struct CodeParam
}
CodeParam end()
{
return { (AST_Param*) rcast( AST*, ast)->Last };
// return { (AST_Param*) rcast( AST*, ast)->Last };
return { nullptr }
}
CodeParam& operator++();
CodeParam operator*()

View File

@ -7,7 +7,7 @@
#pragma region Constants
#ifndef GEN_GLOBAL_BUCKET_SIZE
# define GEN_GLOBAL_BUCKET_SIZE megabytes(4)
# define GEN_GLOBAL_BUCKET_SIZE megabytes(8)
#endif
#ifndef GEN_CODEPOOL_NUM_BLOCKS
# define GEN_CODEPOOL_NUM_BLOCKS kilobytes(16)
@ -31,7 +31,7 @@
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
#endif
#ifndef GEN_BUILDER_STR_BUFFER_RESERVE
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(1)
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(2)
#endif
// These constexprs are used for allocation behavior of data structures

View File

@ -1294,7 +1294,7 @@ internal Code parse_compilcated_definition ();
internal CodeBody parse_class_struct_body ( Parser::TokType which, Parser::Token name = Parser::NullToken );
internal Code parse_class_struct ( Parser::TokType which, bool inplace_def );
internal CodeDefine parse_define ();
internal Code parse_foward_or_definition ( Parser::TokType which, bool is_inplace );
internal Code parse_forward_or_definition ( Parser::TokType which, bool is_inplace );
internal CodeFn parse_function_after_name ( ModuleFlag mflags, CodeAttributes attributes, CodeSpecifiers specifiers, CodeType ret_type, Parser::Token name );
internal Code parse_function_body ();
internal Code parse_global_nspace ();
@ -1317,7 +1317,7 @@ internal CodeDestructor parse_destructor ( CodeSpecifiers specifiers = NoC
internal CodeEnum parse_enum ( bool inplace_def = false );
internal CodeBody parse_export_body ();
internal CodeBody parse_extern_link_body();
internal CodeExtern parse_exten_link ();
internal CodeExtern parse_extern_link ();
internal CodeFriend parse_friend ();
internal CodeFn parse_function ();
internal CodeNS parse_namespace ();
@ -1784,7 +1784,7 @@ Code parse_complicated_definition( Parser::TokType which )
if ( (idx - 2 ) == tokens.Idx )
{
// Its a forward declaration only
Code result = parse_foward_or_definition( which, is_inplace );
Code result = parse_forward_or_definition( which, is_inplace );
Context.pop();
return result;
}
@ -1834,7 +1834,7 @@ Code parse_complicated_definition( Parser::TokType which )
{
// Its a definition
// <which> { ... };
Code result = parse_foward_or_definition( which, is_inplace );
Code result = parse_forward_or_definition( which, is_inplace );
Context.pop();
return result;
}
@ -2267,7 +2267,7 @@ CodeDefine parse_define()
}
internal inline
Code parse_foward_or_definition( Parser::TokType which, bool is_inplace )
Code parse_forward_or_definition( Parser::TokType which, bool is_inplace )
{
using namespace Parser;
@ -2499,7 +2499,7 @@ CodeBody parse_global_nspace( CodeT which )
if ( which == Extern_Linkage_Body )
log_failure( "Nested extern linkage\n%s", Context.to_string() );
member = parse_extern_link_body();
member = parse_extern_link();
break;
case TokType::Decl_Namespace:
@ -3693,7 +3693,10 @@ CodeVar parse_variable_after_name(
result->InlineCmt = inline_cmt;
if ( next_var )
{
result->NextVar = next_var;
result->NextVar->Parent = result;
}
Context.pop();
return result;
@ -3758,15 +3761,18 @@ internal CodeVar parse_variable_declaration_list()
eat( TokType::Identifier );
CodeVar var = parse_variable_after_name( ModuleFlag::None, NoCode, specifiers, NoCode, name );
// TODO(Ed) : CodeVar is going to need a procedure to append comma-defined vars to itself.
if ( ! result )
{
result = var;
last_var = var;
result.ast = var.ast;
last_var.ast = var.ast;
}
else
{
last_var->NextVar = var;
last_var = var;
last_var->NextVar.ast = var.ast;
last_var->NextVar->Parent.ast = rcast(AST*, var.ast);
last_var.ast = var.ast;
}
}
@ -5319,7 +5325,7 @@ CodeTypedef parse_typedef()
if ( (idx - 2 ) == tokens.Idx )
{
// Its a forward declaration only
type = parse_foward_or_definition( currtok.Type, from_typedef );
type = parse_forward_or_definition( currtok.Type, from_typedef );
}
Token tok = tokens[ idx - 1 ];
@ -5360,13 +5366,13 @@ CodeTypedef parse_typedef()
// TODO(Ed) : I'm not sure if I have to use parse_type here, I'd rather not as that would complicate parse_type.
// type = parse_type();
type = parse_foward_or_definition( currtok.Type, from_typedef );
type = parse_forward_or_definition( currtok.Type, from_typedef );
}
else if ( tok.Type == TokType::BraceCurly_Close )
{
// Its a definition
// <which> { ... };
type = parse_foward_or_definition( currtok.Type, from_typedef );
type = parse_forward_or_definition( currtok.Type, from_typedef );
}
else if ( tok.Type == TokType::BraceSquare_Close)
{