Skip to content

Commit

Permalink
Added some comments and tweaks #3313
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Oct 10, 2023
1 parent 67a1e1f commit b94e629
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 46 deletions.
3 changes: 2 additions & 1 deletion src/rcore_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void InitWindow(int width, int height, const char *title)
// Initialize base path for storage
CORE.Storage.basePath = platform.app->activity->internalDataPath;

TRACELOG(LOG_INFO, "ANDROID: App initialized successfully");
TRACELOG(LOG_INFO, "PLATFORM: ANDROID: Application initialized successfully");

// Android ALooper_pollAll() variables
int pollResult = 0;
Expand All @@ -247,6 +247,7 @@ void InitWindow(int width, int height, const char *title)
//if (platform.app->destroyRequested != 0) CORE.Window.shouldClose = true;
}
}
//--------------------------------------------------------------
}

// Close window and unload OpenGL context
Expand Down
68 changes: 61 additions & 7 deletions src/rcore_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,70 @@ void InitWindow(int width, int height, const char *title)
CORE.Window.currentFbo.width = width;
CORE.Window.currentFbo.height = height;

// TODO: Initialize window/display system

// TODO: Initialize input events system
// Initialize graphics device
// NOTE: returns true if window and graphic device has been initialized successfully
CORE.Window.ready = InitGraphicsDevice(width, height);

// If graphic device is no properly initialized, we end program
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return; }

// Initialize hi-res timer
InitTimer();

// Initialize random seed
SetRandomSeed((unsigned int)time(NULL));

// Initialize base path for storage
CORE.Storage.basePath = GetWorkingDirectory();

#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
// Load default font
// WARNING: External function: Module required: rtext
LoadFontDefault();
#if defined(SUPPORT_MODULE_RSHAPES)
// Set font white rectangle for shapes drawing, so shapes and text can be batched together
// WARNING: rshapes module is required, if not available, default internal white rectangle is used
Rectangle rec = GetFontDefault().recs[95];
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
{
// NOTE: We try to maxime rec padding to avoid pixel bleeding on MSAA filtering
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 2, rec.y + 2, 1, 1 });
}
else
{
// NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding
SetShapesTexture(GetFontDefault().texture, (Rectangle){ rec.x + 1, rec.y + 1, rec.width - 2, rec.height - 2 });
}
#endif
#else
#if defined(SUPPORT_MODULE_RSHAPES)
// Set default texture and rectangle to be used for shapes drawing
// NOTE: rlgl default texture is a 1x1 pixel UNCOMPRESSED_R8G8B8A8
Texture2D texture = { rlGetTextureIdDefault(), 1, 1, 1, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 };
SetShapesTexture(texture, (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }); // WARNING: Module required: rshapes
#endif
#endif
#if defined(SUPPORT_MODULE_RTEXT) && defined(SUPPORT_DEFAULT_FONT)
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
{
// Set default font texture filter for HighDPI (blurry)
// RL_TEXTURE_FILTER_LINEAR - tex filter: BILINEAR, no mipmaps
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MIN_FILTER, RL_TEXTURE_FILTER_LINEAR);
rlTextureParameters(GetFontDefault().texture.id, RL_TEXTURE_MAG_FILTER, RL_TEXTURE_FILTER_LINEAR);
}
#endif

// TODO: Initialize assets manager
#if defined(SUPPORT_EVENTS_AUTOMATION)
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
CORE.Time.frameCounter = 0;
#endif

// TODO: Initialize base path for storage
//CORE.Storage.basePath = platform.app->activity->internalDataPath;
// TODO: Platform specific init window
//--------------------------------------------------------------
// ...
//--------------------------------------------------------------

TRACELOG(LOG_INFO, "PLATFORM: Application initialized successfully");
TRACELOG(LOG_INFO, "PLATFORM: CUSTOM: Application initialized successfully");
}

// Close window and unload OpenGL context
Expand Down
32 changes: 17 additions & 15 deletions src/rcore_desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,19 @@ void InitWindow(int width, int height, const char *title)
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
CORE.Window.eventWaiting = false;

// Initialize graphics device (display device and OpenGL context)
// Initialize graphics device
// NOTE: returns true if window and graphic device has been initialized successfully
CORE.Window.ready = InitGraphicsDevice(width, height);

// If graphic device is no properly initialized, we end program
if (!CORE.Window.ready)
{
TRACELOG(LOG_FATAL, "Failed to initialize Graphic Device");
return;
}
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return; }
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2);

// Initialize hi-res timer
InitTimer();

// Initialize random seed
srand((unsigned int)time(NULL));
SetRandomSeed((unsigned int)time(NULL));

// Initialize base path for storage
CORE.Storage.basePath = GetWorkingDirectory();
Expand Down Expand Up @@ -248,6 +244,8 @@ void InitWindow(int width, int height, const char *title)
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
CORE.Time.frameCounter = 0;
#endif

TRACELOG(LOG_INFO, "PLATFORM: DESKTOP: Application initialized successfully");
}

// Close window and unload OpenGL context
Expand Down Expand Up @@ -834,10 +832,12 @@ void SetWindowMinSize(int width, int height)
{
CORE.Window.screenMin.width = width;
CORE.Window.screenMin.height = height;
int minWidth = (CORE.Window.screenMin.width == 0)? GLFW_DONT_CARE : CORE.Window.screenMin.width;
int minHeight = (CORE.Window.screenMin.height == 0)? GLFW_DONT_CARE : CORE.Window.screenMin.height;
int maxWidth = (CORE.Window.screenMax.width == 0)? GLFW_DONT_CARE : CORE.Window.screenMax.width;
int maxHeight = (CORE.Window.screenMax.height == 0)? GLFW_DONT_CARE : CORE.Window.screenMax.height;

int minWidth = (CORE.Window.screenMin.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.width;
int minHeight = (CORE.Window.screenMin.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.height;
int maxWidth = (CORE.Window.screenMax.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.width;
int maxHeight = (CORE.Window.screenMax.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.height;

glfwSetWindowSizeLimits(platform.handle, minWidth, minHeight, maxWidth, maxHeight);
}

Expand All @@ -846,10 +846,12 @@ void SetWindowMaxSize(int width, int height)
{
CORE.Window.screenMax.width = width;
CORE.Window.screenMax.height = height;
int minWidth = (CORE.Window.screenMin.width == 0)? GLFW_DONT_CARE : CORE.Window.screenMin.width;
int minHeight = (CORE.Window.screenMin.height == 0)? GLFW_DONT_CARE : CORE.Window.screenMin.height;
int maxWidth = (CORE.Window.screenMax.width == 0)? GLFW_DONT_CARE : CORE.Window.screenMax.width;
int maxHeight = (CORE.Window.screenMax.height == 0)? GLFW_DONT_CARE : CORE.Window.screenMax.height;

int minWidth = (CORE.Window.screenMin.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.width;
int minHeight = (CORE.Window.screenMin.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMin.height;
int maxWidth = (CORE.Window.screenMax.width == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.width;
int maxHeight = (CORE.Window.screenMax.height == 0)? GLFW_DONT_CARE : (int)CORE.Window.screenMax.height;

glfwSetWindowSizeLimits(platform.handle, minWidth, minHeight, maxWidth, maxHeight);
}

Expand Down
26 changes: 13 additions & 13 deletions src/rcore_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,14 @@ void InitWindow(int width, int height, const char *title)
CORE.Window.ready = InitGraphicsDevice(width, height);

// If graphic device is no properly initialized, we end program
if (!CORE.Window.ready)
{
TRACELOG(LOG_FATAL, "Failed to initialize Graphic Device");
return;
}
else
SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2);
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return; }
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2);

// Initialize hi-res timer
InitTimer();

// Initialize random seed
srand((unsigned int)time(NULL));
SetRandomSeed((unsigned int)time(NULL));

// Initialize base path for storage
CORE.Storage.basePath = GetWorkingDirectory();
Expand Down Expand Up @@ -274,15 +269,20 @@ void InitWindow(int width, int height, const char *title)
}
#endif

// Initialize raw input system
InitEvdevInput(); // Evdev inputs initialization
InitGamepad(); // Gamepad init
InitKeyboard(); // Keyboard init (stdin)

#if defined(SUPPORT_EVENTS_AUTOMATION)
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
CORE.Time.frameCounter = 0;
#endif

// Platform specific init window
//--------------------------------------------------------------
// Initialize raw input system
InitEvdevInput(); // Evdev inputs initialization
InitGamepad(); // Gamepad init
InitKeyboard(); // Keyboard init (stdin)
//--------------------------------------------------------------

TRACELOG(LOG_INFO, "PLATFORM: DRM: Application initialized successfully");
}

// Close window and unload OpenGL context
Expand Down
21 changes: 11 additions & 10 deletions src/rcore_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,14 @@ void InitWindow(int width, int height, const char *title)
CORE.Window.ready = InitGraphicsDevice(width, height);

// If graphic device is no properly initialized, we end program
if (!CORE.Window.ready)
{
TRACELOG(LOG_FATAL, "Failed to initialize Graphic Device");
return;
}
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return; }
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2);

// Initialize hi-res timer
InitTimer();

// Initialize random seed
srand((unsigned int)time(NULL));
SetRandomSeed((unsigned int)time(NULL));

// Initialize base path for storage
CORE.Storage.basePath = GetWorkingDirectory();
Expand Down Expand Up @@ -229,6 +225,13 @@ void InitWindow(int width, int height, const char *title)
}
#endif

#if defined(SUPPORT_EVENTS_AUTOMATION)
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
CORE.Time.frameCounter = 0;
#endif

// Platform specific init window
//--------------------------------------------------------------
// Setup callback functions for the DOM events
emscripten_set_fullscreenchange_callback("#canvas", NULL, 1, EmscriptenFullscreenChangeCallback);

Expand Down Expand Up @@ -257,11 +260,9 @@ void InitWindow(int width, int height, const char *title)
// Support gamepad events (not provided by GLFW3 on emscripten)
emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback);
emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback);
//--------------------------------------------------------------

#if defined(SUPPORT_EVENTS_AUTOMATION)
events = (AutomationEvent *)RL_CALLOC(MAX_CODE_AUTOMATION_EVENTS, sizeof(AutomationEvent));
CORE.Time.frameCounter = 0;
#endif
TRACELOG(LOG_INFO, "PLATFORM: WEB: Application initialized successfully");
}

// Close window and unload OpenGL context
Expand Down

0 comments on commit b94e629

Please sign in to comment.