Skip to content

Commit

Permalink
Fix g++-11 and clang-tidy-12.0.1 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
balintkissdev committed Aug 27, 2021
1 parent 8b6b83d commit 86ef050
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
24 changes: 20 additions & 4 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,17 @@ void Game::drawMap()

// Watch out: row/column is not the same as x/y. This was a source of a nasty bug.
rect = {0 + squareSize * column, 0 + squareSize * row, squareSize, squareSize};
renderer_->fillRectangle(rect.x, rect.y, rect.width, rect.height);
renderer_->fillRectangle(
static_cast<int>(rect.x),
static_cast<int>(rect.y),
static_cast<int>(rect.width),
static_cast<int>(rect.height));
renderer_->setDrawColor(0, 0, 0);
renderer_->drawRectangle(rect.x, rect.y, rect.width, rect.height);
renderer_->drawRectangle(
static_cast<int>(rect.x),
static_cast<int>(rect.y),
static_cast<int>(rect.width),
static_cast<int>(rect.height));
}
}

Expand All @@ -253,9 +261,17 @@ void Game::drawMap()
squareSize * static_cast<int>(camera_.position().x) + squareSize / 4,
squareSize / 2,
squareSize / 2};
renderer_->fillRectangle(rect.x, rect.y, rect.width, rect.height);
renderer_->fillRectangle(
static_cast<int>(rect.x),
static_cast<int>(rect.y),
static_cast<int>(rect.width),
static_cast<int>(rect.height));
renderer_->setDrawColor(0, 0, 0, 255);
renderer_->drawRectangle(rect.x, rect.y, rect.width, rect.height);
renderer_->drawRectangle(
static_cast<int>(rect.x),
static_cast<int>(rect.y),
static_cast<int>(rect.width),
static_cast<int>(rect.height));
}

int main(int /*argc*/, char** /*argv*/)
Expand Down
34 changes: 20 additions & 14 deletions src/RayCaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void RayCaster::drawBottom()

const size_t screenCenterDistance = y - screenHeight_ / 2;
const float cameraVerticalPosition = 0.5f * static_cast<float>(screenHeight_);
const float cameraToRowDistance = cameraVerticalPosition / screenCenterDistance;
const float cameraToRowDistance = cameraVerticalPosition / static_cast<float>(screenCenterDistance);

const Vector2<float> floorStep =
cameraToRowDistance * (rightmostRayDirection - leftmostRayDirection) / static_cast<float>(screenWidth_);
Expand All @@ -63,8 +63,12 @@ void RayCaster::drawBottom()
const Vector2<size_t> cell = {static_cast<size_t>(floor.x), static_cast<size_t>(floor.y)};

const Vector2<size_t> texCoord = {
static_cast<size_t>(bottomTexture_->width * (floor.x - cell.x)) & (bottomTexture_->width - 1),
static_cast<size_t>(bottomTexture_->height * (floor.y - cell.y)) & (bottomTexture_->height - 1)};
static_cast<size_t>(
static_cast<float>(bottomTexture_->width) * (floor.x - static_cast<float>(cell.x))) &
(bottomTexture_->width - 1),
static_cast<size_t>(
static_cast<float>(bottomTexture_->height) * (floor.y - static_cast<float>(cell.y))) &
(bottomTexture_->height - 1)};

floor += floorStep;

Expand Down Expand Up @@ -115,22 +119,22 @@ std::pair<Vector2<int>, Vector2<float>> RayCaster::calculateInitialStep(
if (rayDirection.x < 0)
{
stepDirection.x = -1;
sideDistance.x = (camera_.position().x - mapSquarePosition.x) * rayStepDistance.x;
sideDistance.x = (camera_.position().x - static_cast<float>(mapSquarePosition.x)) * rayStepDistance.x;
}
else
{
stepDirection.x = 1;
sideDistance.x = (mapSquarePosition.x + 1.0 - camera_.position().x) * rayStepDistance.x;
sideDistance.x = (static_cast<float>(mapSquarePosition.x) + 1.0f - camera_.position().x) * rayStepDistance.x;
}
if (rayDirection.y < 0)
{
stepDirection.y = -1;
sideDistance.y = (camera_.position().y - mapSquarePosition.y) * rayStepDistance.y;
sideDistance.y = (camera_.position().y - static_cast<float>(mapSquarePosition.y)) * rayStepDistance.y;
}
else
{
stepDirection.y = 1;
sideDistance.y = (mapSquarePosition.y + 1.0 - camera_.position().y) * rayStepDistance.y;
sideDistance.y = (static_cast<float>(mapSquarePosition.y) + 1.0f - camera_.position().y) * rayStepDistance.y;
}

return {stepDirection, sideDistance};
Expand Down Expand Up @@ -178,11 +182,12 @@ float RayCaster::calculateWallDistance(
const Vector2<int>& stepDirection,
const Vector2<float>& rayDirection)
{
return (side == VERTICAL)
? ((mapSquarePosition.x - camera_.position().x + static_cast<float>(1 - stepDirection.x) / 2) /
rayDirection.x)
: ((mapSquarePosition.y - camera_.position().y + static_cast<float>(1 - stepDirection.y) / 2) /
rayDirection.y);
return (side == VERTICAL) ? ((static_cast<float>(mapSquarePosition.x) - camera_.position().x +
static_cast<float>(1 - stepDirection.x) / 2) /
rayDirection.x)
: ((static_cast<float>(mapSquarePosition.y) - camera_.position().y +
static_cast<float>(1 - stepDirection.y) / 2) /
rayDirection.y);
}

std::pair<int, int> RayCaster::calculateDrawLocations(const int wallColumnHeight) const
Expand Down Expand Up @@ -226,7 +231,7 @@ void RayCaster::drawTexturedColumn(
}
wallHitX -= std::floor((wallHitX));

auto texCoordX = static_cast<size_t>(wallHitX * wallTexture.width);
auto texCoordX = static_cast<size_t>(wallHitX * static_cast<float>(wallTexture.width));
if (side == VERTICAL && ray.x > 0)
{
texCoordX = wallTexture.width - texCoordX - 1;
Expand All @@ -237,7 +242,8 @@ void RayCaster::drawTexturedColumn(
}

// How much to increase the texture coordinate per screen pixel
const float texCoordIncreaseStep = 1.0f * wallTexture.height / static_cast<float>(wallColumnHeight);
const float texCoordIncreaseStep =
1.0f * static_cast<float>(wallTexture.height) / static_cast<float>(wallColumnHeight);
float startingTexCoordY = (static_cast<float>(drawStart) - static_cast<float>(screenHeight_) / 2 +
static_cast<float>(wallColumnHeight) / 2) *
texCoordIncreaseStep;
Expand Down
1 change: 1 addition & 0 deletions src/Texture.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef TEXTURE_H
#define TEXTURE_H

#include <cstddef>
#include <cstdint>
#include <vector>

Expand Down

0 comments on commit 86ef050

Please sign in to comment.