-
Notifications
You must be signed in to change notification settings - Fork 0
System
This section contains all System functions.
- CP_System_SetWindowSize
- CP_System_SetWindowPosition NEW
- CP_System_Fullscreen
- CP_System_FullscreenAdvanced
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_System_GetDisplayWidth NEW
- CP_System_GetDisplayHeight NEW
- CP_System_GetWindowRefreshRate NEW
- CP_System_GetWindowHandle
- CP_System_SetWindowTitle
- CP_System_ShowCursor
- CP_System_GetFrameCount
- CP_System_GetFrameRate
- CP_System_SetFrameRate
- CP_System_GetDt
- CP_System_GetMillis
- CP_System_GetSeconds
This function modifies the size of the window. Typically, the window size is set in the init function.
void CP_System_SetWindowSize(int new_width, int new_height);
- new_width (int) - The width to set the window to.
- new_height (int) - The height to set the window to.
This function does not return anything.
void init()
{
// Set the window size to a small square
CP_System_SetWindowSize(10, 10);
// Set the background to white
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
}
This function sets the position of the application window within the user's monitor screen. The top-left corner of the window will be set to the position provided. Note: The position (0, 0) is at the top left of the monitor screen.
void CP_System_SetWindowPosition(int x, int y);
- x (int) - The X coordinate of the window's top-left corner.
- y (int) - The Y coordinate of the window's top-left corner.
This function does not return anything.
void init()
{
// Set the window position to be 100 pixels from the top of the screen
// and 200 pixels from the left edge of the screen
CP_System_SetWindowPosition(200, 100);
}
This function sets the window to fullscreen. It will automatically sets the window's pixel width and height to the monitor's width and height. Use CP_System_FullscreenAdvanced to specify a pixel width and height for the fullscreen window.
void CP_System_Fullscreen(void);
This function has no parameters.
This function does not return anything.
void init()
{
// Set the window to fill the screen
CP_System_Fullscreen();
// Set the background to black
CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
}
This function sets the window to fullscreen like CP_System_Fullscreen but lets you set the pixel aspect ratio of the screen as well. If you try to set the screen to an aspect ratio unsupported by the monitor, it will be set to the closest aspect ratio possible.
void CP_System_FullscreenAdvanced(int targetWidth, int targetHeight);
- targetWidth (int) - The pixel width of the window.
- targetHeight (int) - The pixel height of the window.
This function does not return anything.
// Horizontal position of the square
float x_pos;
void init()
{
// Start the square at the left of the screen
x_pos = 0;
// Set the square to draw yellow
CP_Settings_Fill(CP_Color_Create(255, 255, 0, 255));
// Set the window to fullscreen 1280x720
CP_System_FullscreenAdvanced(1280, 720);
}
void update()
{
// Set background to black
CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
// Draw the square
CP_Graphics_DrawRect(x_pos, CP_System_GetWindowHeight() / 2.0f, 100, 100);
x_pos += 2;
// If space pressed, reset the state
if (CP_Input_KeyTriggered(KEY_SPACE))
CP_Engine_SetNextGameStateForced(init, update, NULL);
else if (CP_Input_KeyTriggered(KEY_Q))
CP_Engine_Terminate();
}
- CP_Graphics_ClearBackground
- CP_Graphics_DrawRect
- CP_Color_Create
- CP_Settings_Fill
- CP_Engine_SetNextGameStateForced
- CP_Engine_Terminate
- CP_Input_KeyTriggered
- CP_System_GetWindowHeight
Gets the display width of the window excluding the window frame. This is the width of the canvas you are drawing to.
int CP_System_GetWindowWidth(void);
This function has no parameters.
- int - The width of the game window.
void update()
{
// Clear the background to a blue color
CP_Graphics_ClearBackground(CP_Color_Create(20, 200, 255, 255));
// Draw a rectangle at the mouse position
CP_Graphics_DrawRect(CP_System_GetWindowWidth() / 2.0f, CP_System_GetWindowHeight() / 2.0f, 25.0f, 25.0f);
}
Gets the display height of the window excluding the window frame. This is the height of the canvas you are drawing to.
int CP_System_GetWindowHeight(void);
This function has no parameters.
- int - The height of the game window.
void update()
{
// Clear the background to a blue color
CP_Graphics_ClearBackground(CP_Color_Create(20, 200, 255, 255));
// Draw a rectangle at the mouse position
CP_Graphics_DrawRect(CP_System_GetWindowWidth() / 2.0f, CP_System_GetWindowHeight() / 2.0f, 25.0f, 25.0f);
}
Gets the width of the user's monitor in pixels.
int CP_System_GetDisplayWidth(void);
This function has no parameters.
- int - The width of the monitor.
void init()
{
// Set the window size to the same size as the screen
CP_System_SetWindowSize(CP_System_GetDisplayWidth(), CP_System_GetDisplayHeight());
}
Gets the height of the user's monitor in pixels.
int CP_System_GetDisplayHeight(void);
This function has no parameters.
- int - The height of the monitor.
void init()
{
// Set the window size to the same size as the screen
CP_System_SetWindowSize(CP_System_GetDisplayWidth(), CP_System_GetDisplayHeight());
}
Gets the refresh rate of the monitor. Like 30 FPS or 60 FPS.
float CP_System_GetWindowRefreshRate(void);
This function has no parameters.
- float - The refresh rate of the monitor in frames per second.
void init()
{
// Set the window size to the same size as the screen
CP_System_SetFrameRate(CP_System_GetWindowRefreshRate());
}
Returns the window handle (HWND) of the program running. See https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-api-list for windows.h documentation and examples.
HWND CP_System_GetWindowHandle(void);
This function has no parameters.
- HWND - Windows type that represents the handle to the window.
Sets the title of the running program.
void CP_System_SetWindowTitle(const char* title);
- title (const char*) - The string containing the title to change the title bar to.
This function does not return anything.
void update()
{
// Set the window title to the number of frames that have passed.
char buffer[256] = { 0 };
sprintf_s(buffer, 256, "%d frames have passed", frameCount);
CP_System_SetWindowTitle(buffer);
}
This function sets whether the cursor is visible or not. Typically, it is used in the init function.
void CP_System_ShowCursor(CP_BOOL show);
- show (CP_BOOL) - True/False for whether the cursor is visible.
This function does not return anything.
CP_BOOL cursor = TRUE;
void init()
{
// Set the window to fullscreen
CP_System_Fullscreen();
// Show the cursor
CP_System_ShowCursor(cursor);
}
void update()
{
// Check if the spacebar is triggered
if (CP_Input_KeyTriggered(KEY_SPACE))
{
// Swap whether the cursor is shown
cursor = !cursor;
CP_System_ShowCursor(cursor);
}
}
Returns the current frame count. The frame count starts at 0 when the program launches and increments every frame until the program ends.
Note: the frame count can't be set by the user and isn't reset when changing game states.
int CP_System_GetFrameCount();
This function has no parameters.
- int - The current frame count.
void update(void)
{
// print the current frame count to the center of the window
CP_Settings_TextSize(200);
CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
CP_Graphics_ClearBackground(CP_Color_Create(200, 200, 200, 255));
CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
int currentFrameCount = CP_System_GetFrameCount();
char buffer[16] = { 0 };
sprintf_s(buffer, _countof(buffer), "%i", currentFrameCount);
CP_Font_DrawText(buffer, 200, 200);
}
- CP_Settings_TextSize
- CP_Settings_TextAlignment
- CP_Graphics_ClearBackground
- CP_Settings_Fill
- CP_Font_DrawText
Returns the current frames per second.
float CP_System_GetFrameRate(void);
This function has no parameters.
- float - The current number of frames per second.
void update(void)
{
// print the current frame rate to the center of the window
CP_Settings_TextSize(200);
CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
CP_Graphics_ClearBackground(CP_Color_Create(200, 200, 200, 255));
CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
float currentFrameRate = CP_System_GetFrameRate();
char buffer[16] = { 0 };
sprintf_s(buffer, _countof(buffer), "%.1f", currentFrameRate );
CP_Font_DrawText(buffer, 200, 200);
}
- CP_System_GetWindowRefreshRate
- CP_Settings_TextSize
- CP_Settings_TextAlignment
- CP_Settings_Fill
- CP_Font_DrawText
- CP_Graphics_ClearBackground
- CP_Color_Create
Sets the target frame rate (fps) for the application.
The internal frame rate controller manages when each update call happens. If the processing required to complete one update finishes quickly then the frame rate controller will idle the CPU. Once the total desired frame time has passed it will then start the next frame. If the processing required to complete one update takes longer than one frame's worth of time then the next frame will start immediately.
void CP_System_SetFrameRate(float fps)
- fps - the target application update speed in frames per second.
This function does not return anything.
void init(void)
{
// set framerate to 2 fps (slow)
CP_System_SetFrameRate(2.0f);
// initialize settings
CP_Settings_TextSize(200);
CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
}
void update(void)
{
// clear the screen
CP_Graphics_ClearBackground(CP_Color_Create(200, 200, 200, 255));
// print the current frame count to the center of the window
int currentFrameCount = CP_System_GetFrameCount();
char buffer[16] = { 0 };
sprintf_s(buffer, _countof(buffer), "%i", currentFrameCount);
CP_Font_DrawText(buffer, 200, 200);
}
- CP_System_GetWindowRefreshRate
- CP_System_GetFrameCount
- CP_Settings_TextSize
- CP_Settings_TextAlignment
- CP_Settings_Fill
- CP_Color_Create
- CP_Graphics_ClearBackground
- CP_Font_DrawText
Returns the elapsed time (in seconds) from the last frame. This is very important when making frame independent calculations such as movement or physics.
float CP_System_GetDt(void);
This function has no parameters.
- float - The fraction of a second that has passed since the last frame.
void init(void)
{
// initialize settings
CP_Settings_TextSize(150);
CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
}
void update(void)
{
// clear the background
CP_Graphics_ClearBackground(CP_Color_Create(200, 200, 200, 255));
// get dt and then print total elapsed time
float currentElapsedTime = CP_System_GetDt();
static float totalElapsedTime = 0;
totalElapsedTime += currentElapsedTime;
char buffer[16] = { 0 };
sprintf_s(buffer, _countof(buffer), "%.2f", totalElapsedTime);
CP_Font_DrawText(buffer, 200, 200);
}
- CP_Settings_TextSize
- CP_Settings_TextAlignment
- CP_Settings_Fill
- CP_Color_Create
- CP_Graphics_ClearBackground
- CP_Font_DrawText
Returns the total milliseconds from the start of the program.
NOTE: This number is always increasing and cannot be changed or reset by the user.
float CP_System_GetMillis(void);
This function has no parameters.
- float - The milliseconds that have passed since the program started.
void init(void)
{
// initialize settings
CP_Settings_TextSize(150);
CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
}
void update(void)
{
// clear the background
CP_Graphics_ClearBackground(CP_Color_Create(200, 200, 200, 255));
// print milliseconds since program start
float totalMillis = CP_System_GetMillis();
char buffer[16] = { 0 };
sprintf_s(buffer, _countof(buffer), "%.1f", totalMillis);
CP_Font_DrawText(buffer, 200, 200);
}
- CP_Settings_TextSize
- CP_Settings_TextAlignment
- CP_Settings_Fill
- CP_Color_Create
- CP_Graphics_ClearBackground
- CP_Font_DrawText
Returns the total number of seconds from the start of the program.
NOTE: This number is always increasing and cannot be changed or reset by the user.
float CP_System_GetSeconds(void);
This function has no parameters.
- float - The number of seconds that have passed since the program started.
void init(void)
{
// initialize settings
CP_Settings_TextSize(150);
CP_Settings_TextAlignment(CP_TEXT_ALIGN_H_CENTER, CP_TEXT_ALIGN_V_MIDDLE);
CP_Settings_Fill(CP_Color_Create(100, 20, 100, 255));
}
void update(void)
{
// clear the background
CP_Graphics_ClearBackground(CP_Color_Create(200, 200, 200, 255));
// print seconds since program start
float totalSeconds = CP_System_GetSeconds();
char buffer[16] = { 0 };
sprintf_s(buffer, _countof(buffer), "%.2f", totalSeconds);
CP_Font_DrawText(buffer, 200, 200);
}