mirror of
https://github.com/raysan5/raylib.git
synced 2025-10-18 07:41:47 +00:00
Added comments and review some functions #3313
This commit is contained in:
244
src/rcore.c
244
src/rcore.c
@@ -315,14 +315,12 @@ const char *TextFormat(const char *text, ...); // Formatting of text with
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Window and OpenGL Context Functions
|
||||
// Module Functions Definition: Window and Graphics Device
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: Multiple window/display/monitor management functions have been moved to platform-specific modules
|
||||
|
||||
// Platform-specific functions:
|
||||
//void InitWindow(int width, int height, const char *title);
|
||||
//void CloseWindow(void);
|
||||
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
|
||||
//void InitWindow(int width, int height, const char *title)
|
||||
//void CloseWindow(void)
|
||||
//bool WindowShouldClose(void)
|
||||
//bool IsWindowHidden(void)
|
||||
//bool IsWindowMinimized(void)
|
||||
@@ -364,9 +362,6 @@ const char *TextFormat(const char *text, ...); // Formatting of text with
|
||||
//void HideCursor(void)
|
||||
//void EnableCursor(void)
|
||||
//void DisableCursor(void)
|
||||
//double GetTime(void)
|
||||
//void TakeScreenshot(const char *fileName)
|
||||
//void OpenURL(const char *url)
|
||||
|
||||
|
||||
// Check if window has been initialized successfully
|
||||
@@ -435,6 +430,19 @@ bool IsCursorOnScreen(void)
|
||||
return CORE.Input.Mouse.cursorOnScreen;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Custom frame control
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
|
||||
//void SwapScreenBuffer(void);
|
||||
//void PollInputEvents(void);
|
||||
//void WaitTime(double seconds);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Screen Drawing
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Set background color (framebuffer clear color)
|
||||
void ClearBackground(Color color)
|
||||
{
|
||||
@@ -741,6 +749,10 @@ void EndScissorMode(void)
|
||||
rlDisableScissorTest();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: VR Stereo Rendering
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Begin VR drawing configuration
|
||||
void BeginVrStereoMode(VrStereoConfig config)
|
||||
{
|
||||
@@ -837,6 +849,10 @@ void UnloadVrStereoConfig(VrStereoConfig config)
|
||||
TRACELOG(LOG_INFO, "UnloadVrStereoConfig not implemented in rcore.c");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Shaders Management
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Load shader from files and bind default locations
|
||||
// NOTE: If shader string is NULL, using default vertex/fragment shaders
|
||||
Shader LoadShader(const char *vsFileName, const char *fsFileName)
|
||||
@@ -1002,6 +1018,10 @@ void SetShaderValueTexture(Shader shader, int locIndex, Texture2D texture)
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Screen-space Queries
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Get a ray trace from mouse position
|
||||
Ray GetMouseRay(Vector2 mouse, Camera camera)
|
||||
{
|
||||
@@ -1161,6 +1181,13 @@ Vector2 GetScreenToWorld2D(Vector2 position, Camera2D camera)
|
||||
return (Vector2){ transform.x, transform.y };
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Timming
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
|
||||
//double GetTime(void)
|
||||
|
||||
// Set target FPS (maximum)
|
||||
void SetTargetFPS(int fps)
|
||||
{
|
||||
@@ -1209,6 +1236,63 @@ float GetFrameTime(void)
|
||||
return (float)CORE.Time.frame;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Misc
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
|
||||
//void OpenURL(const char *url)
|
||||
|
||||
// Get a random value between min and max (both included)
|
||||
// WARNING: Ranges higher than RAND_MAX will return invalid results
|
||||
// More specifically, if (max - min) > INT_MAX there will be an overflow,
|
||||
// and otherwise if (max - min) > RAND_MAX the random value will incorrectly never exceed a certain threshold
|
||||
int GetRandomValue(int min, int max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
int tmp = max;
|
||||
max = min;
|
||||
min = tmp;
|
||||
}
|
||||
|
||||
if ((unsigned int)(max - min) > (unsigned int)RAND_MAX)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "Invalid GetRandomValue() arguments, range should not be higher than %i", RAND_MAX);
|
||||
}
|
||||
|
||||
return (rand()%(abs(max - min) + 1) + min);
|
||||
}
|
||||
|
||||
// Set the seed for the random number generator
|
||||
void SetRandomSeed(unsigned int seed)
|
||||
{
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
// Takes a screenshot of current screen (saved a .png)
|
||||
void TakeScreenshot(const char *fileName)
|
||||
{
|
||||
#if defined(SUPPORT_MODULE_RTEXTURES)
|
||||
// Security check to (partially) avoid malicious code
|
||||
if (strchr(fileName, '\'') != NULL) { TRACELOG(LOG_WARNING, "SYSTEM: Provided fileName could be potentially malicious, avoid [\'] character"); return; }
|
||||
|
||||
Vector2 scale = GetWindowScaleDPI();
|
||||
unsigned char *imgData = rlReadScreenPixels((int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
|
||||
Image image = { imgData, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y), 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
|
||||
|
||||
char path[512] = { 0 };
|
||||
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, fileName));
|
||||
|
||||
ExportImage(image, path); // WARNING: Module required: rtextures
|
||||
RL_FREE(imgData);
|
||||
|
||||
TRACELOG(LOG_INFO, "SYSTEM: [%s] Screenshot taken successfully", path);
|
||||
#else
|
||||
TRACELOG(LOG_WARNING,"IMAGE: ExportImage() requires module: rtextures");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Setup window configuration flags (view FLAGS)
|
||||
// NOTE: This function is expected to be called before window creation,
|
||||
// because it sets up some flags for the window creation process.
|
||||
@@ -1221,7 +1305,7 @@ void SetConfigFlags(unsigned int flags)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: FileSystem
|
||||
// Module Functions Definition: File system
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Check if the file exists
|
||||
@@ -1669,36 +1753,9 @@ long GetFileModTime(const char *fileName)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Misc
|
||||
// Module Functions Definition: Compression and Encoding
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Get a random value between min and max (both included)
|
||||
// WARNING: Ranges higher than RAND_MAX will return invalid results
|
||||
// More specifically, if (max - min) > INT_MAX there will be an overflow,
|
||||
// and otherwise if (max - min) > RAND_MAX the random value will incorrectly never exceed a certain threshold
|
||||
int GetRandomValue(int min, int max)
|
||||
{
|
||||
if (min > max)
|
||||
{
|
||||
int tmp = max;
|
||||
max = min;
|
||||
min = tmp;
|
||||
}
|
||||
|
||||
if ((unsigned int)(max - min) > (unsigned int)RAND_MAX)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "Invalid GetRandomValue() arguments, range should not be higher than %i", RAND_MAX);
|
||||
}
|
||||
|
||||
return (rand()%(abs(max - min) + 1) + min);
|
||||
}
|
||||
|
||||
// Set the seed for the random number generator
|
||||
void SetRandomSeed(unsigned int seed)
|
||||
{
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
// Compress data (DEFLATE algorithm)
|
||||
unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize)
|
||||
{
|
||||
@@ -1841,26 +1898,9 @@ unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Inputs
|
||||
// Module Functions Definition: Input Handling: Keyboard
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Platform-specific functions
|
||||
//void SetExitKey(int key)
|
||||
//const char *GetGamepadName(int gamepad)
|
||||
//int GetGamepadAxisCount(int gamepad)
|
||||
//int SetGamepadMappings(const char *mappings)
|
||||
//int GetMouseX(void)
|
||||
//int GetMouseY(void)
|
||||
//Vector2 GetMousePosition(void)
|
||||
//void SetMousePosition(int x, int y)
|
||||
//float GetMouseWheelMove(void)
|
||||
//void SetMouseCursor(int cursor)
|
||||
//int GetTouchX(void)
|
||||
//int GetTouchY(void)
|
||||
//Vector2 GetTouchPosition(int index)
|
||||
//void SwapScreenBuffer(void)
|
||||
//void PollInputEvents(void)
|
||||
|
||||
// Check if a key has been pressed once
|
||||
bool IsKeyPressed(int key)
|
||||
{
|
||||
@@ -1971,6 +2011,22 @@ int GetCharPressed(void)
|
||||
return value;
|
||||
}
|
||||
|
||||
// Set a custom key to exit program
|
||||
// NOTE: default exitKey is set to ESCAPE
|
||||
void SetExitKey(int key)
|
||||
{
|
||||
CORE.Input.Keyboard.exitKey = key;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Input Handling: Gamepad
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
|
||||
//int GetGamepadAxisCount(int gamepad) **
|
||||
//const char *GetGamepadName(int gamepad) **
|
||||
//int SetGamepadMappings(const char *mappings)
|
||||
|
||||
// Check if a gamepad is available
|
||||
bool IsGamepadAvailable(int gamepad)
|
||||
{
|
||||
@@ -1981,16 +2037,11 @@ bool IsGamepadAvailable(int gamepad)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Get axis movement vector for a gamepad
|
||||
float GetGamepadAxisMovement(int gamepad, int axis)
|
||||
{
|
||||
float value = 0;
|
||||
|
||||
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS) &&
|
||||
(fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]) > 0.1f)) value = CORE.Input.Gamepad.axisState[gamepad][axis]; // 0.1f = GAMEPAD_AXIS_MINIMUM_DRIFT/DELTA
|
||||
|
||||
return value;
|
||||
}
|
||||
// Get gamepad internal name id
|
||||
//const char *GetGamepadName(int gamepad)
|
||||
//{
|
||||
// return CORE.Input.Gamepad.ready[gamepad];
|
||||
//}
|
||||
|
||||
// Check if a gamepad button has been pressed once
|
||||
bool IsGamepadButtonPressed(int gamepad, int button)
|
||||
@@ -2042,6 +2093,35 @@ int GetGamepadButtonPressed(void)
|
||||
return CORE.Input.Gamepad.lastButtonPressed;
|
||||
}
|
||||
|
||||
// Get gamepad axis count
|
||||
//int GetGamepadAxisCount(int gamepad)
|
||||
//{
|
||||
// return CORE.Input.Gamepad.axisCount;
|
||||
//}
|
||||
|
||||
// Get axis movement vector for a gamepad
|
||||
float GetGamepadAxisMovement(int gamepad, int axis)
|
||||
{
|
||||
float value = 0;
|
||||
|
||||
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS) &&
|
||||
(fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]) > 0.1f)) value = CORE.Input.Gamepad.axisState[gamepad][axis]; // 0.1f = GAMEPAD_AXIS_MINIMUM_DRIFT/DELTA
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Input Handling: Mouse
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
|
||||
//int GetMouseX(void) **
|
||||
//int GetMouseY(void) **
|
||||
//Vector2 GetMousePosition(void) **
|
||||
//void SetMousePosition(int x, int y)
|
||||
//float GetMouseWheelMove(void) **
|
||||
//void SetMouseCursor(int cursor)
|
||||
|
||||
// Check if a mouse button has been pressed once
|
||||
bool IsMouseButtonPressed(int button)
|
||||
{
|
||||
@@ -2129,6 +2209,15 @@ Vector2 GetMouseWheelMoveV(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition: Input Handling: Touch
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
|
||||
//int GetTouchX(void)
|
||||
//int GetTouchY(void)
|
||||
//Vector2 GetTouchPosition(int index)
|
||||
|
||||
// Get touch point identifier for given index
|
||||
int GetTouchPointId(int index)
|
||||
{
|
||||
@@ -2329,29 +2418,6 @@ void WaitTime(double seconds)
|
||||
#endif
|
||||
}
|
||||
|
||||
// Takes a screenshot of current screen (saved a .png)
|
||||
void TakeScreenshot(const char *fileName)
|
||||
{
|
||||
#if defined(SUPPORT_MODULE_RTEXTURES)
|
||||
// Security check to (partially) avoid malicious code
|
||||
if (strchr(fileName, '\'') != NULL) { TRACELOG(LOG_WARNING, "SYSTEM: Provided fileName could be potentially malicious, avoid [\'] character"); return; }
|
||||
|
||||
Vector2 scale = GetWindowScaleDPI();
|
||||
unsigned char *imgData = rlReadScreenPixels((int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y));
|
||||
Image image = { imgData, (int)((float)CORE.Window.render.width*scale.x), (int)((float)CORE.Window.render.height*scale.y), 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
|
||||
|
||||
char path[512] = { 0 };
|
||||
strcpy(path, TextFormat("%s/%s", CORE.Storage.basePath, fileName));
|
||||
|
||||
ExportImage(image, path); // WARNING: Module required: rtextures
|
||||
RL_FREE(imgData);
|
||||
|
||||
TRACELOG(LOG_INFO, "SYSTEM: [%s] Screenshot taken successfully", path);
|
||||
#else
|
||||
TRACELOG(LOG_WARNING,"IMAGE: ExportImage() requires module: rtextures");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Scan all files and directories in a base path
|
||||
// WARNING: files.paths[] must be previously allocated and
|
||||
// contain enough space to store all required paths
|
||||
|
Reference in New Issue
Block a user