diff options
| author | nathan <nathansmith@disroot.org> | 2026-01-05 10:08:59 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2026-01-05 10:08:59 +0000 |
| commit | 80346819885df71d1b61b4248df6bb8a442b9d83 (patch) | |
| tree | 6f7a1dad29af5e39f4c73f674ed42f4bd238c65a | |
| parent | a8d803916883e49790981beed6438726406e0995 (diff) | |
| download | FindThings-80346819885df71d1b61b4248df6bb8a442b9d83.tar.gz FindThings-80346819885df71d1b61b4248df6bb8a442b9d83.tar.bz2 FindThings-80346819885df71d1b61b4248df6bb8a442b9d83.zip | |
Make thingy speedy quick
| -rw-r--r-- | src/game.c | 5 | ||||
| -rw-r--r-- | src/player.c | 37 | ||||
| -rw-r--r-- | src/player.h | 2 | ||||
| -rw-r--r-- | src/settings.c | 1 | ||||
| -rw-r--r-- | src/settings.h | 1 |
5 files changed, 30 insertions, 16 deletions
@@ -59,6 +59,11 @@ void initGame(Game* game) "Find Things"); SetWindowState(FLAG_WINDOW_RESIZABLE); + if (game->settings.maxFPS != 0) + { + SetTargetFPS(game->settings.maxFPS); + } + // Screen. game->screen.render = LoadRenderTexture(game->settings.screenWidth, game->settings.screenHeight); diff --git a/src/player.c b/src/player.c index 7917545..6cce443 100644 --- a/src/player.c +++ b/src/player.c @@ -7,7 +7,6 @@ Player createPlayer() .position = Vector3Zero(), .direction = (Vector3){0.0, 0.0, 0.0}, .velocity = Vector3Zero(), - .speed = 0.0, .relativeBox = (BoundingBox){ .min = (Vector3){-PLAYER_WIDTH / 2.0, -PLAYER_HEIGHT / 2.0, -PLAYER_WIDTH / 2.0}, @@ -119,10 +118,9 @@ bool playerHandleCollisionWithBuildingBlock(Player* player, if (Vector3DotProduct(player->velocity, normal) < 0.0) { // Handle collision. - float dotProduct = Vector3DotProduct(player->direction, normal); - player->velocity = Vector3Subtract(player->direction, + float dotProduct = Vector3DotProduct(player->velocity, normal); + player->velocity = Vector3Subtract(player->velocity, Vector3Scale(normal, dotProduct)); - player->velocity = Vector3Scale(player->velocity, player->speed); // Is at a corner. if (!*isFirstCollision && !Vector3Equals(*lastNormal, normal)) @@ -138,7 +136,6 @@ bool playerHandleCollisionWithBuildingBlock(Player* player, return false; } -// TODO: Make this fucker speedy quick void playerHandleCollisionWithBuilding(Player* player, Game* game, WorldUID uid) { @@ -157,10 +154,28 @@ void playerHandleCollisionWithBuilding(Player* player, Game* game, bool isFirstCollision = true; Vector3 lastNormal = (Vector3){0.0, 0.0, 0.0}; - for (int y = 0; y < building->height; ++y) + int playerX = (player->position.x - place->position.x) / + ENTITY_BUILDING_CUBE_SIZE.x; + int playerY = (player->position.z - place->position.z) / + ENTITY_BUILDING_CUBE_SIZE.y; + + // Scan near by blocks for collision. + int scanDistance = 2; + + for (int yOffset = -scanDistance; yOffset < scanDistance; ++yOffset) { - for (int x = 0; x < building->width; ++x) + for (int xOffset = -scanDistance; xOffset < scanDistance; ++xOffset) { + int x = playerX + xOffset; + int y = playerY + yOffset; + + // Out of bounds. + if (x < 0 || x >= building->width || + y < 0 || y >= building->height) + { + continue; + } + Color color = building->pixelMap[y * building->width + x]; if (color.r == 0) @@ -168,6 +183,7 @@ void playerHandleCollisionWithBuilding(Player* player, Game* game, continue; } + // Get wall position and bounding box. Vector3 wallPosition = (Vector3){ place->position.x + x * ENTITY_BUILDING_CUBE_SIZE.x, place->position.y + ENTITY_BUILDING_CUBE_SIZE.y / 2.0, @@ -180,7 +196,6 @@ void playerHandleCollisionWithBuilding(Player* player, Game* game, if (CheckCollisionBoxes(player->box, box)) { - DrawBoundingBox(box, PURPLE); if (playerHandleCollisionWithBuildingBlock(player, building, box, wallPosition, x, y, &isFirstCollision, @@ -229,7 +244,6 @@ void updatePlayerMovement(Player* player, Game* game) } player->velocity = Vector3Scale(player->velocity, PLAYER_SPEED); - player->speed = Vector3Length(player->velocity); // Check collision with buildings. WorldUID buildingUID = playerCheckCollisionWithBuildings(player, game); @@ -378,11 +392,6 @@ void updatePlayer(Player* player, Game* game) .direction = player->direction }; - if (game->isCrossHairEnabled) - { - DrawRay(ray, YELLOW); - } - if (player->isInteracting) { playerUpdateSelectedEntity(player, player->selectedEntity, game); diff --git a/src/player.h b/src/player.h index 3dac500..7755ef9 100644 --- a/src/player.h +++ b/src/player.h @@ -12,9 +12,7 @@ typedef struct { Vector3 position; Vector3 direction; - Vector3 velocity; - float speed; BoundingBox relativeBox; BoundingBox box; diff --git a/src/settings.c b/src/settings.c index c047090..056c5bc 100644 --- a/src/settings.c +++ b/src/settings.c @@ -8,6 +8,7 @@ Settings defaultSettings() .screenWidth = 596, .screenHeight = 447, .fov = 90.0, + .maxFPS = 0, .showFPSDefault = true, .backgroundColor = (Color){74, 42, 74, 255}, .useBackgroundTexture = true, diff --git a/src/settings.h b/src/settings.h index b8ab5ee..3aa9eb3 100644 --- a/src/settings.h +++ b/src/settings.h @@ -14,6 +14,7 @@ typedef struct { // Render. float fov; + int maxFPS; bool showFPSDefault; Color backgroundColor; bool useBackgroundTexture; |
