Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <memory>

#include <cstddef>
#include <stdio.h>
#include <math.h>
#include <cstdio>
#include <cmath>

/// Constants

Expand All @@ -36,4 +36,4 @@ constexpr float LIGHT_ABSOLUTE = 80.f;
#define _METHOD(x) std::bind(x, this, std::placeholders::_1)

// Only usable in TileMap
#define FOR_EACH_TILE(action) for (uint x = 0; x < width; x++) { for (uint y = 0; y < height; y++) { action; } }
#define FOR_EACH_TILE(action) for (uint x = 0; x < width; x++) { for (uint y = 0; y < height; y++) { action; } }
2 changes: 1 addition & 1 deletion src/app/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../events/Events.h"

constexpr bool VSYNC_ENABLED = true;
constexpr bool VSYNC_DISABLED = false;
constexpr bool VSYNC_DISABLED = !VSYNC_DISABLED;

class Application : public Events::IEventListener
{
Expand Down
10 changes: 5 additions & 5 deletions src/graphics/Animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ namespace Graphics
if (!animFound)
return;

float animLength = anim->length / (float)anim->fps;
const float animLength = anim->length / (float)anim->fps;
if (m_timer >= animLength)
m_timer -= animLength;
uint frameIndex = static_cast<uint>((m_timer / animLength) * anim->length);
uint textureX = anim->xpos + frameIndex * anim->stride;
uint textureY = anim->ypos;
const uint frameIndex = static_cast<uint>((m_timer / animLength) * anim->length);
const uint textureX = anim->xpos + frameIndex * anim->stride;
const uint textureY = anim->ypos;
destsprite.setTextureRect(sf::IntRect(textureX, textureY, destsprite.getTextureRect().width, destsprite.getTextureRect().height));
}
}
}
6 changes: 3 additions & 3 deletions src/graphics/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace Graphics

void Label::updateBounds()
{
sf::FloatRect rect = m_text.getLocalBounds();
Vec2 size(rect.width, rect.height);
const sf::FloatRect rect = m_text.getLocalBounds();
const Vec2 size(rect.width, rect.height);
switch (m_alignment)
{
case Alignment::LEFT:
Expand All @@ -50,4 +50,4 @@ namespace Graphics
}
m_text.setPosition(m_position + m_alignmentOffset);
}
}
}
6 changes: 3 additions & 3 deletions src/graphics/gui/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace GUI

bool Button::mouseMoved(Events::MouseMovedEvent& e)
{
Vec2 mouse = Application::get().uiMousePos();
const Vec2 mouse = Application::get().uiMousePos();
if (!m_bounds.contains(mouse))
m_state = ButtonState::UNPRESSED;

Expand All @@ -62,7 +62,7 @@ namespace GUI

void Button::update()
{
Vec2 mouse = Application::get().uiMousePos();
const Vec2 mouse = Application::get().uiMousePos();
m_hovered = m_bounds.contains(mouse);
updateTexture();
}
Expand All @@ -73,4 +73,4 @@ namespace GUI
window.draw(*m_sprite, m_states);
m_label->render(window, m_states);
}
}
}
18 changes: 8 additions & 10 deletions src/graphics/gui/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ namespace GUI

bool Panel::mousePressed(Events::MousePressedEvent& e)
{
Vec2 mouse = Application::get().uiMousePos();
for (uint i = 0; i < m_widgets.size(); i++)
const Vec2 mouse = Application::get().uiMousePos();
for (Widget* const widget : m_widgets)
{
Widget* widget = m_widgets[i];
if (widget->getBounds().contains(mouse))
{
if (widget->isActive())
Expand All @@ -73,10 +72,9 @@ namespace GUI

bool Panel::mouseReleased(Events::MouseReleasedEvent& e)
{
Vec2 mouse = Application::get().uiMousePos();
for (uint i = 0; i < m_widgets.size(); i++)
const Vec2 mouse = Application::get().uiMousePos();
for (Widget* const widget : m_widgets)
{
Widget* widget = m_widgets[i];
if (widget->getBounds().contains(mouse))
{
if (widget->isActive())
Expand All @@ -91,7 +89,7 @@ namespace GUI
{
for (uint i = 0; i < m_widgets.size(); i++)
{
Widget* widget = m_widgets[i];
Widget* const widget = m_widgets[i];
if (widget->isActive())
if (widget->mouseMoved(e))
return true;
Expand All @@ -101,7 +99,7 @@ namespace GUI

void Panel::update()
{
for (Widget* widget : m_widgets)
for (Widget* const widget : m_widgets)
{
if (widget->isActive())
widget->update();
Expand All @@ -110,10 +108,10 @@ namespace GUI

void Panel::render(sf::RenderWindow& window)
{
for (Widget* widget : m_widgets)
for (Widget* const widget : m_widgets)
{
if (widget->isActive())
widget->render(window);
}
}
}
}
8 changes: 4 additions & 4 deletions src/graphics/gui/Slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace GUI
, m_atlas((sf::Texture*)&Application::get().getTexture("/gui/slider"))
, m_bgSprite(new sf::RectangleShape(m_bounds.size))
{
float size = vertical ? bounds.width : bounds.height;
const float size = vertical ? bounds.width : bounds.height;
m_headBounds = FloatRectangle(bounds.x, bounds.y, size, size);

m_headSprite = new sf::RectangleShape(m_headBounds.size);
Expand All @@ -44,7 +44,7 @@ namespace GUI

bool Slider::mousePressed(Events::MousePressedEvent& e)
{
Vec2 mouse = Application::get().uiMousePos();
const Vec2 mouse = Application::get().uiMousePos();
if (m_hovered)
{
m_state = SliderState::PRESSEDHEAD;
Expand All @@ -62,7 +62,7 @@ namespace GUI

bool Slider::mouseMoved(Events::MouseMovedEvent& e)
{
Vec2 mouse = Application::get().uiMousePos();
const Vec2 mouse = Application::get().uiMousePos();
if (m_state == SliderState::PRESSEDHEAD)
{
if (m_vertical)
Expand All @@ -79,7 +79,7 @@ namespace GUI
if (!sf::Mouse::isButtonPressed(sf::Mouse::Left))
m_state = SliderState::UNPRESSED;

Vec2 mouse = Application::get().uiMousePos();
const Vec2 mouse = Application::get().uiMousePos();
m_hovered = m_headBounds.contains(mouse);
updateTexture();

Expand Down
10 changes: 5 additions & 5 deletions src/graphics/gui/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace GUI
updateButtons();

// Setup shader and texture
sf::Shader* transparency = new sf::Shader();
sf::Shader* const transparency = new sf::Shader();
transparency->loadFromMemory(getFileContents("res/shaders/transparency.frag"), sf::Shader::Fragment);
transparency->setUniform("u_Opacity", .9f);
transparency->setUniform("u_Texture", sf::Shader::CurrentTexture);
Expand All @@ -32,7 +32,7 @@ namespace GUI

bool Window::mousePressed(Events::MousePressedEvent& e)
{
Vec2 mouse = Application::get().uiMousePos();
const Vec2 mouse = Application::get().uiMousePos();

if (close_button.contains(mouse))
{
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace GUI

bool Window::mouseMoved(Events::MouseMovedEvent& e)
{
Vec2 mouse = Application::get().uiMousePos();
const Vec2 mouse = Application::get().uiMousePos();

if (m_resizing.active)
{
Expand Down Expand Up @@ -123,8 +123,8 @@ namespace GUI
{
m_vao.clear();

float width = m_bounds.width;
float height = m_bounds.height;
const float width = m_bounds.width;
const float height = m_bounds.height;

///@TODO: Get rid of these hardcoded values
// Top left corner
Expand Down
8 changes: 3 additions & 5 deletions src/item/ItemFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ namespace Item

void ItemFactory::createTemplate(std::string filePath)
{
std::string source = getFileContents("res/items" + filePath);
const std::string source = getFileContents("res/items" + filePath);
nlohmann::json json = nlohmann::json::parse(source.c_str());

std::unique_ptr<Item> item = std::make_unique<Item>();

std::vector<nlohmann::json> componentsJSON = json["components"];
const std::vector<nlohmann::json> componentsJSON = json["components"];

for (unsigned int i=0; i < componentsJSON.size(); i++)
for (const auto& componentJSON : componentsJSON)
{
nlohmann::json componentJSON = componentsJSON[i];

using namespace Components;

if (componentJSON["componentType"].get<std::string>() == "Sprite")
Expand Down
16 changes: 7 additions & 9 deletions src/level/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ namespace Level

auto data = m_worldGen.getMap();

TileMap::AddList addList;

addList = data.addList;
TileMap::AddList addList = data.addList;

m_tiles.addTiles(0, addList);

Expand Down Expand Up @@ -48,8 +46,8 @@ namespace Level

std::sort(m_entities.begin(), m_entities.end(),
[](const std::unique_ptr<Entity::Entity>& lhs, const std::unique_ptr<Entity::Entity>& rhs) {
Components::PhysicsComponent* c_lhs = lhs.get()->getComponent<Components::PhysicsComponent>();
Components::PhysicsComponent* c_rhs = rhs.get()->getComponent<Components::PhysicsComponent>();
const auto* c_lhs = lhs.get()->getComponent<Components::PhysicsComponent>();
const auto* c_rhs = rhs.get()->getComponent<Components::PhysicsComponent>();
return c_lhs->pos.y + c_lhs->sortOffset < c_rhs->pos.y + c_rhs->sortOffset;
});

Expand Down Expand Up @@ -86,9 +84,9 @@ namespace Level

m_tiles.light();

Components::PhysicsComponent* c_pos = player->getComponent<Components::PhysicsComponent>();
const Components::PhysicsComponent* const c_pos = player->getComponent<Components::PhysicsComponent>();

Vec2 offset = (Vec2(Application::get().getInputManager()->getMouse()) - Vec2(Application::get().getWindow().getSize()) / 2.f) * .1f;
const Vec2 offset = (Vec2(Application::get().getInputManager()->getMouse()) - Vec2(Application::get().getWindow().getSize()) / 2.f) * .1f;
m_view.setCenter(c_pos->pos + offset);

/*
Expand All @@ -100,8 +98,8 @@ namespace Level
for (int i = -1; i <= 1; i++)
for (int j = -1; j <= 1; j++)
{
int x = int(c_pos->pos.x) / 32 + i;
int y = int(c_pos->pos.y + 16) / 32 + j;
const int x = int(c_pos->pos.x) / 32 + i;
const int y = int(c_pos->pos.y + 16) / 32 + j;

if (m_tiles.getTile(0, x, y)->id != TileID::Dungeon_BrickFloor)
x3.push_back({x, y, byte(TileID::Dungeon_BrickFloor), 0 });
Expand Down
8 changes: 4 additions & 4 deletions src/level/gen/Leaf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace WGenerator
if (block.width > block.height && block.width / block.height >= 1.25) splitOrientation = false;
else if (block.height > block.width && block.height / block.width >= 1.25) splitOrientation = true;

uint max = (splitOrientation ? block.height : block.width) - m_minSize;
const uint max = (splitOrientation ? block.height : block.width) - m_minSize;
if (max <= m_minSize) return false;

uint splitPosition = (uint)generator->uint64InRange(m_minSize, max);
const uint splitPosition = (uint)generator->uint64InRange(m_minSize, max);

if (splitOrientation)
{
Expand Down Expand Up @@ -75,8 +75,8 @@ namespace WGenerator
point1 = std::make_pair((uint)(left->x + (left->width / 2)), (uint)(left->y + (left->height / 2)));
point2 = std::make_pair((uint)(right->x + (right->width / 2)), (uint)(right->y + (right->height) / 2));

int w = point2.first - point1.first;
int h = point2.second - point1.second;
const int w = point2.first - point1.first;
const int h = point2.second - point1.second;

uint hall = (uint)generator->uint64InRange(m_minHall, m_maxHall);

Expand Down
14 changes: 7 additions & 7 deletions src/level/tile/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace Level
renderTilePos.x = x * TILE_SIZE;
renderTilePos.y = y * TILE_SIZE;

float tx = m_texture.x * TILE_SIZE;
float ty = m_texture.y * TILE_SIZE;
const float tx = m_texture.x * TILE_SIZE;
const float ty = m_texture.y * TILE_SIZE;

// Pointer arithmetic is faster than [] operator
Vec2* uvPtr = const_cast<Vec2*>(&renderable->getUVs()[0]);
Expand Down Expand Up @@ -55,8 +55,8 @@ namespace Level
{
renderTilePos.y = y * TILE_SIZE;

float tx = m_sideTexture.x * TILE_SIZE;
float ty = m_sideTexture.y * TILE_SIZE;
const float tx = m_sideTexture.x * TILE_SIZE;
const float ty = m_sideTexture.y * TILE_SIZE;

// Pointer arithmetic is faster than [] operator
Vec2* uvPtr = const_cast<Vec2*>(&renderable->getUVs()[0]);
Expand All @@ -71,8 +71,8 @@ namespace Level
/// Render top
renderTilePos.y = y * TILE_SIZE - 32;

float tx = m_topTexture.x * TILE_SIZE;
float ty = m_topTexture.y * TILE_SIZE;
const float tx = m_topTexture.x * TILE_SIZE;
const float ty = m_topTexture.y * TILE_SIZE;

// Pointer arithmetic is faster than [] operator
Vec2* uvPtr = const_cast<Vec2*>(&renderable->getUVs()[0]);
Expand All @@ -83,4 +83,4 @@ namespace Level

renderer.submit(renderable, Graphics::Renderer2D::RenderOrder::AFTER);
}
}
}
12 changes: 6 additions & 6 deletions src/level/tile/TileCollision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace Level
{
std::pair<bool, bool> tileCollision(Vec2 position, Vec2 velocity, FloatRectangle& bounds, const Timestep& ts)
{
Vec2 dest = position + velocity * ts.asSeconds();
const Vec2 dest = position + velocity * ts.asSeconds();

Vec2i from = Vec2i((dest + bounds.getMinimumBound()) / TILE_SIZE);
Vec2i to = Vec2i((dest + bounds.getMaximumBound()) / TILE_SIZE) + Vec2i{ 2, 2 };
const Vec2i from = Vec2i((dest + bounds.getMinimumBound()) / TILE_SIZE);
const Vec2i to = Vec2i((dest + bounds.getMaximumBound()) / TILE_SIZE) + Vec2i{ 2, 2 };

bool collidingX = false, collidingY = false;
for (int32 x = from.x; x < to.x; x++)
for (int32 y = from.y; y < to.y; y++)
for (int32 x = from.x; x < to.x; ++x)
for (int32 y = from.y; y < to.y; ++y)
{
if (!State::Playing::get().isTilePassable(0, x, y))
{
Expand All @@ -39,4 +39,4 @@ namespace Level

return std::make_pair(collidingX, collidingY);
}
}
}
Loading