2026-01-31 18:55:31 +01:00

77 lines
3.2 KiB
C

#include <engine.h>
/*
// Input-related functions: keyboard
bool IsKeyPressed(int key); // Check if a key has been pressed once
bool IsKeyPressedRepeat(int key); // Check if a key has been pressed again
bool IsKeyDown(int key); // Check if a key is being pressed
bool IsKeyReleased(int key); // Check if a key has been released once
bool IsKeyUp(int key); // Check if a key is NOT being pressed
int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
// Input-related functions: mouse
bool IsMouseButtonPressed(int button); // Check if a mouse button has been pressed once
bool IsMouseButtonDown(int button); // Check if a mouse button is being pressed
bool IsMouseButtonReleased(int button); // Check if a mouse button has been released once
bool IsMouseButtonUp(int button); // Check if a mouse button is NOT being pressed
int GetMouseX(void); // Get mouse position X
int GetMouseY(void); // Get mouse position Y
Vector2 GetMousePosition(void); // Get mouse position XY
Vector2 GetMouseDelta(void); // Get mouse delta between frames
void SetMousePosition(int x, int y); // Set mouse position XY
void SetMouseOffset(int offsetX, int offsetY); // Set mouse offset
void SetMouseScale(float scaleX, float scaleY); // Set mouse scaling
float GetMouseWheelMove(void); // Get mouse wheel movement for X or Y, whichever is larger
Vector2 GetMouseWheelMoveV(void); // Get mouse wheel movement for both X and Y
void SetMouseCursor(int cursor); // Set mouse cursor
*/
void UpdateInput() {
const Input input;
int key = GetKeyPressed();
Vector2 mouse_pos = GetMousePosition();
Vector2 mouse_delta = GetMouseDelta();
while (key) {
for (PLAYER_ACTION action = 0; action < 4; action++) {
if (input.key[action] == key) {
//emit("player_intent", action)l
break;
}
}
key = GetKeyPressed();
}
}
//may be able to dispatch it
void GameLoop(const double tick_time) {
__thread static double time = 0;
time += GetFrameTime();
if (time >= tick_time) {
// interaction
// simulation
time = 0;
}
}
int main(void) {
double tick_time = 0.4;
SetTraceLogLevel(LOG_ALL);
LoadPipeline();
LoadAssets();
SetExitKey(KEY_NULL);
while (!WindowShouldClose()) {
UpdateInput();
ComputeIntent();
//DispatchWorker
GameLoop(tick_time);
//joinWorker
Rendering();
}
UnloadAssets();
UnloadPipeline();
return (0);
}