Added -Wconversion and fixed warnings.

This mostly forces the casts to be explicit.
This commit is contained in:
Quentin Bazin 2021-06-09 04:36:26 +02:00
parent 7d3d231d3f
commit d5f5082bb0
117 changed files with 615 additions and 537 deletions

View File

@ -22,9 +22,9 @@ include_directories(external)
#------------------------------------------------------------------------------
# Compiler flags
#------------------------------------------------------------------------------
set(DEBUG_GCC_FLAGS -g -Og -Wall -Wextra -Wfatal-errors -Wno-unused-parameter)
set(RELEASE_GCC_FLAGS -O3 -Wall -Wextra -Wfatal-errors -Wno-unused-parameter)
set(RELWITHDEB_GCC_FLAGS -g -O3 -Wall -Wextra -Wfatal-errors -Wno-unused-parameter)
set(DEBUG_GCC_FLAGS -g -Og -Wall -Wextra -Wconversion -Wfatal-errors -Wno-unused-parameter)
set(RELEASE_GCC_FLAGS -O3 -Wall -Wextra -Wconversion -Wfatal-errors -Wno-unused-parameter)
set(RELWITHDEB_GCC_FLAGS -g -O3 -Wall -Wextra -Wconversion -Wfatal-errors -Wno-unused-parameter)
set(CMAKE_CXX_STANDARD 17)

View File

@ -201,13 +201,13 @@ void FastNoise::SetSeed(int seed)
std::mt19937_64 gen(seed);
for (int i = 0; i < 256; i++)
m_perm[i] = i;
m_perm[i] = (unsigned char)i;
for (int j = 0; j < 256; j++)
{
int rng = (int)(gen() % (256 - j));
int k = rng + j;
int l = m_perm[j];
unsigned char l = m_perm[j];
m_perm[j] = m_perm[j + 256] = m_perm[k];
m_perm[k] = l;
m_perm12[j] = m_perm12[j + 256] = m_perm[j] % 12;

2
external/entt vendored

@ -1 +1 @@
Subproject commit 18bd2eb72991882c313a47c6b81b2f7e1fd6a706
Subproject commit 5d15a3d69f433a0e3fce266caaeb87c77c10453c

2
external/gamekit vendored

@ -1 +1 @@
Subproject commit ca65aed9949a166e846bec09777ef821cf1949dc
Subproject commit d784564b849e19b4c8db8a106196244468f62e53

View File

@ -95,7 +95,7 @@ bool ClientApplication::init() {
if (m_argumentParser.getArgument("host").isFound)
m_host = m_argumentParser.getArgument("host").parameter;
if (m_argumentParser.getArgument("port").isFound)
m_port = std::stoi(m_argumentParser.getArgument("port").parameter);
m_port = (u16)std::stoi(m_argumentParser.getArgument("port").parameter);
Config::loadConfigFromFile("config/client.lua");

View File

@ -70,7 +70,7 @@ void ClientProfiler::dump(u64 tickDurationMin) {
maxActionDuration[actionName].first = std::max(maxActionDuration[actionName].first, actionDuration);
float actionPercentTotal = actionDuration / (float)tickDuration * 100.f;
float actionPercentTotal = (float)actionDuration / (float)tickDuration * 100.f;
gkDebug() << "Action" << actionName << j++ << "took" << actionDuration << "ms -" << actionPercentTotal << "% of tick";
}

View File

@ -78,7 +78,7 @@ void KeyboardHandler::loadKeysFromFile(const std::string &filename) {
}
}
else {
addKey(m_keys.size(), keyName, keycode, keyID);
addKey(gk::GameKey(m_keys.size()), keyName, keycode, keyID);
}
}
}

View File

@ -43,12 +43,12 @@ class KeyboardHandler : public gk::InputHandler {
bool isKeyPressed(gk::GameKey key) override;
SDL_Keycode getKeycode(gk::GameKey key) { return m_keys[key].keycode(); }
std::string getKeyName(gk::GameKey key) { return SDL_GetKeyName(m_keys[key].keycode()); }
void setKeycode(gk::GameKey key, SDL_Keycode keycode) { m_keys[key].setKeycode(keycode); }
SDL_Keycode getKeycode(gk::GameKey key) const { return m_keys.at(key).keycode(); }
std::string getKeyName(gk::GameKey key) const { return SDL_GetKeyName(m_keys.at(key).keycode()); }
void setKeycode(gk::GameKey key, SDL_Keycode keycode) { m_keys.at(key).setKeycode(keycode); }
void addKey(gk::GameKey id, const std::string &name, SDL_Keycode defaultKey, const std::string &stringID = "", Key *key = nullptr);
u32 keyCount() { return m_keys.size(); }
std::size_t keyCount() const { return m_keys.size(); }
const std::map<gk::GameKey, Key> &keys() const { return m_keys; }

View File

@ -67,8 +67,8 @@ void CelestialObject::updateVertexBuffer() const {
gk::FloatRect texRect{0, 0, 1, 1};
if (m_phaseCount && m_phaseSize && m_currentPhase < m_phaseCount) {
u16 currentPhaseX = m_currentPhase % (m_texture->getSize().x / m_phaseSize);
u16 currentPhaseY = m_currentPhase / (m_texture->getSize().x / m_phaseSize);
u16 currentPhaseX = u16(m_currentPhase % (m_texture->getSize().x / m_phaseSize));
u16 currentPhaseY = u16(m_currentPhase / (m_texture->getSize().x / m_phaseSize));
texRect.x = currentPhaseX * m_phaseSize / float(m_texture->getSize().x);
texRect.y = currentPhaseY * m_phaseSize / float(m_texture->getSize().y);
texRect.sizeX = m_phaseSize / float(m_texture->getSize().x);

View File

@ -273,7 +273,11 @@ void PlayerBox::updateVertexBuffer() {
void PlayerBox::draw(gk::RenderTarget &target, gk::RenderStates states) const {
// Subtract the camera position - see comment in ClientWorld::draw()
const gk::Vector3d &cameraPosition = m_camera.getDPosition();
states.transform.translate(m_x - cameraPosition.x, m_y - cameraPosition.y, m_z - cameraPosition.z);
states.transform.translate(
static_cast<float>(m_x - cameraPosition.x),
static_cast<float>(m_y - cameraPosition.y),
static_cast<float>(m_z - cameraPosition.z)
);
states.transform.rotateZ(m_viewAngleH);
states.transform *= getTransform();

View File

@ -67,7 +67,7 @@ void Skybox::loadSky(const Sky &sky) {
m_moon.setTexture(moon.texture);
}
catch (...) {
m_moon.setColor(gk::Color{240, 240, 240});
m_moon.setColor(gk::Color::fromRGBA32(240, 240, 240));
gkWarning() << "Failed to load moon texture" << moon.texture;
}
@ -76,7 +76,7 @@ void Skybox::loadSky(const Sky &sky) {
m_stars.reserve(stars.count);
for (int i = 0 ; i < stars.count ; ++i) {
auto &star = m_stars.emplace_back();
star.setColor(gk::Color{0, 0, 0, 0});
star.setColor(gk::Color::fromRGBA32(0, 0, 0, 0));
star.setSize(stars.size, stars.size);
// This formula makes the distribution uniform
@ -87,7 +87,7 @@ void Skybox::loadSky(const Sky &sky) {
// Generate a uniform random coordinate
// NOTE: MUST NOT USE FAST MATH!
// Otherwise it risks taking the square root of a negative!
v.y = (rand() % 32768 - 16383.5f) / 16383.5f;
v.y = (float(rand() % 32768) - 16383.5f) / 16383.5f;
// Project it to the +X semicircle in the XY plane
v.x = sqrtf(1.f - v.y*v.y);
}
@ -98,7 +98,7 @@ void Skybox::loadSky(const Sky &sky) {
star.rotateZ(atan2f(v.y, v.x) * float(180./M_PI));
// Set a random rotation in the day cycle
star.setRotationOffset(rand() % GameTime::dayLength);
star.setRotationOffset(u16(rand() % GameTime::dayLength));
star.setRotationSpeed(sky.daylightCycleSpeed());
// Maybe sometimes stars could have a random axis?

View File

@ -89,14 +89,14 @@ gk::FloatRect TextureAtlas::getTexCoords(const std::string &filename, bool norma
u16 textureID = getTextureID(filename);
float textureX = (textureID % (m_texture.getSize().x / m_tileSize)) * m_tileSize;
float textureY = (textureID / (m_texture.getSize().x / m_tileSize)) * m_tileSize;
float textureX = float((textureID % (m_texture.getSize().x / m_tileSize)) * m_tileSize);
float textureY = float((textureID / (m_texture.getSize().x / m_tileSize)) * m_tileSize);
if (normalized)
return gk::FloatRect{textureX / m_texture.getSize().x,
textureY / m_texture.getSize().y,
(float)m_tileSize / m_texture.getSize().x,
(float)m_tileSize / m_texture.getSize().y};
return gk::FloatRect{textureX / (float)m_texture.getSize().x,
textureY / (float)m_texture.getSize().y,
m_tileSize / (float)m_texture.getSize().x,
m_tileSize / (float)m_texture.getSize().y};
else
return gk::FloatRect{textureX,
textureY,
@ -118,7 +118,7 @@ void TextureAtlas::addFile(const std::string &path, const std::string &filename)
}
if (!m_tileSize)
m_tileSize = surface->w;
m_tileSize = (u16)surface->w;
if (m_tileSize != surface->w || m_tileSize != surface->h)
throw EXCEPTION("Texture size unexpected for", path + filename + ". Got", surface->w, surface->h, "instead of", m_tileSize, m_tileSize);
@ -144,7 +144,7 @@ void TextureAtlas::packTextures() {
const u16 atlasWidth = 16;
// Max amount of textures on one column
const u16 atlasHeight = std::ceil((float)m_textures.size() / atlasWidth);
const u16 atlasHeight = (u16)std::ceil((float)m_textures.size() / atlasWidth);
SurfacePtr atlas{nullptr, &SDL_FreeSurface};

View File

@ -33,7 +33,7 @@ CraftingWidget::CraftingWidget(ClientCommandHandler &client, Inventory &crafting
{
}
void CraftingWidget::init(unsigned int offset, unsigned int size) {
void CraftingWidget::init(u16 offset, u16 size) {
m_craftingInventoryWidget.init(m_craftingInventory, offset, size * size);
m_craftingResultInventoryWidget.init(m_craftingResultInventory);

View File

@ -35,7 +35,7 @@ class CraftingWidget : public AbstractInventoryWidget {
public:
CraftingWidget(ClientCommandHandler &client, Inventory &craftingInventory, Widget *parent = nullptr);
void init(unsigned int offset = 0, unsigned int size = 3);
void init(u16 offset = 0, u16 size = 3);
void onEvent(const SDL_Event &event) override;

View File

@ -40,12 +40,12 @@ Font::Font(const std::string &textureName, const std::string &configPath)
}
gk::Vector2f Font::getTexCoords(u8 c, u8 x, u8 y) const {
u8 tileX = c % (m_texture.getSize().x / m_width);
u8 tileY = c / (m_texture.getSize().x / m_width);
u8 tileX = u8(c % (m_texture.getSize().x / m_width));
u8 tileY = u8(c / (m_texture.getSize().x / m_width));
gk::Vector2f texCoords{
(tileX + x) * m_width / (float)m_texture.getSize().x,
(tileY + y) * m_height / (float)m_texture.getSize().y
float(tileX + x) * m_width / (float)m_texture.getSize().x,
float(tileY + y) * m_height / (float)m_texture.getSize().y
};
return texCoords;
@ -58,17 +58,17 @@ void Font::parseConfig(const std::string &configPath) {
while (std::getline(file, line, '\n')) {
if (line.empty()) continue;
u16 dot = line.find_first_of('.');
u16 equal = line.find_first_of('=');
size_t dot = line.find_first_of('.');
size_t equal = line.find_first_of('=');
std::string propertyName = line.substr(0, dot);
if (propertyName != "width")
throw EXCEPTION("Unexpected property for font:", propertyName);
int propertyKey = std::stoi(line.substr(dot + 1, equal - dot - 1));
u8 propertyValue = std::stoi(line.substr(equal + 1));
int propertyValue = std::stoi(line.substr(equal + 1));
m_charWidth[propertyKey] = propertyValue;
m_charWidth[propertyKey] = (u8)propertyValue;
}
}

View File

@ -46,7 +46,7 @@ InventoryCube::InventoryCube(float size, bool isEntity)
m_isEntity = isEntity;
if (!m_isEntity) {
m_transform.setOrigin(size * 0.5, size * 0.5, size * 0.5);
m_transform.setOrigin(size * 0.5f, size * 0.5f, size * 0.5f);
// NOTE: intrinsic rotations! The axis is the local axis of the object.
// Note also that we start looking at the bottom of the cube due to how
@ -120,8 +120,8 @@ void InventoryCube::updateVertexBuffer(const Block &block, u8 state) {
float U = (v == 0 || v == 3) ? U0 : U1;
float V = (v >= 2) ? V0 : V1;
vertices[f][v].texCoord[0] = gk::qlerp(blockTexCoords.x, blockTexCoords.x + blockTexCoords.sizeX, U);
vertices[f][v].texCoord[1] = gk::qlerp(blockTexCoords.y, blockTexCoords.y + blockTexCoords.sizeY, V);
vertices[f][v].texCoord[0] = gk::qlerpf(blockTexCoords.x, blockTexCoords.x + blockTexCoords.sizeX, U);
vertices[f][v].texCoord[1] = gk::qlerpf(blockTexCoords.y, blockTexCoords.y + blockTexCoords.sizeY, V);
const gk::Color &colorMultiplier = blockState.colorMultiplier();
vertices[f][v].color[0] = colorMultiplier.r;

View File

@ -46,11 +46,11 @@ void InventoryWidget::scroll(float scrolling) {
if (m_itemWidgets.size() < m_size)
return;
u16 offset = m_offset + floor((m_inventory->height() - m_size / m_inventory->width()) * scrolling) * m_inventory->width();
u16 offset = u16(m_offset + std::floor((m_inventory->height() - m_size / m_inventory->width()) * scrolling) * m_inventory->width());
u16 size = m_size;
if (offset + size > m_inventory->width() * m_inventory->height())
size = m_inventory->width() * m_inventory->height() - offset;
size = u16(m_inventory->width() * m_inventory->height() - offset);
loadItemWidgets(offset, size, m_lastSearch);
}
@ -62,7 +62,10 @@ void InventoryWidget::onEvent(const SDL_Event &event) {
if (m_itemWidgets[i].isPointInWidget(event.motion.x, event.motion.y)) {
m_currentItemWidget = &m_itemWidgets[i];
m_selectedItemBackground.setPosition(1 + (i % m_inventoryWidth) * 18, 1 + (i / m_inventoryWidth) * 18, 0);
m_selectedItemBackground.setPosition(
float(1 + i % m_inventoryWidth * 18),
float(1 + i / m_inventoryWidth * 18)
);
}
}
}
@ -143,8 +146,8 @@ void InventoryWidget::loadItemWidgets(u16 offset, u16 size, std::string search)
u16 itemCounter = 0;
for (u16 i = 0 ; itemCounter < size ; ++i) {
u16 x = (i + offset) % m_inventory->width();
u16 y = (i + offset) / m_inventory->width();
u16 x = u16((i + offset) % m_inventory->width());
u16 y = u16((i + offset) / m_inventory->width());
if (x >= m_inventory->width() || y >= m_inventory->height())
break;

View File

@ -76,7 +76,7 @@ class InventoryWidget : public AbstractInventoryWidget {
std::vector<ItemWidget> m_itemWidgets;
ItemWidget *m_currentItemWidget = nullptr;
gk::RectangleShape m_selectedItemBackground{16, 16, gk::Color{255, 255, 255, 80}};
gk::RectangleShape m_selectedItemBackground{16, 16, gk::Color::fromRGBA32(255, 255, 255, 80)};
std::string m_lastSearch;
};

View File

@ -55,7 +55,7 @@ void ItemWidget::update() {
updateImage();
m_text.setString(std::to_string(stack().amount()));
m_text.setPosition(16 - 4 - 6 * floor(log10(stack().amount())), 16 - 6, 0);
m_text.setPosition(16.f - 4.f - 6.f * floorf(log10f(stack().amount())), 16.f - 6.f, 0);
}
void ItemWidget::updateImage(const BlockState *blockState) {
@ -68,7 +68,7 @@ void ItemWidget::updateImage(const BlockState *blockState) {
}
gk::FloatRect clipRect = m_textureAtlas.getTexCoords(stack().item().tiles().getTextureForFace(0), false);
m_image.setClipRect(clipRect.x, clipRect.y, clipRect.sizeX, clipRect.sizeY);
m_image.setClipRect(clipRect.x, clipRect.y, (u16)clipRect.sizeX, (u16)clipRect.sizeY);
m_image.setScale(16.0f / clipRect.sizeX, 16.0f / clipRect.sizeY);
if (blockState)
@ -79,7 +79,7 @@ void ItemWidget::updateImage(const BlockState *blockState) {
m_isImage = true;
}
void ItemWidget::setStack(const std::string &name, unsigned int amount) {
void ItemWidget::setStack(const std::string &name, u16 amount) {
m_inventory.setStack(m_x, m_y, name, amount);
update();
}

View File

@ -44,10 +44,10 @@ class ItemWidget : public Widget {
void updateImage(const BlockState *blockState = nullptr);
const ItemStack &stack() const { return m_inventory.getStack(m_x, m_y); }
void setStack(const std::string &name, unsigned int amount = 1);
void setStack(const std::string &name, u16 amount = 1);
unsigned int x() const { return m_x; }
unsigned int y() const { return m_y; }
u16 x() const { return m_x; }
u16 y() const { return m_y; }
bool hasChanged() const { return m_hasChanged; }
void setChanged(bool hasChanged) { m_hasChanged = hasChanged; }
@ -58,8 +58,8 @@ class ItemWidget : public Widget {
private:
Inventory &m_inventory;
unsigned int m_x = 0;
unsigned int m_y = 0;
u16 m_x = 0;
u16 m_y = 0;
TextureAtlas &m_textureAtlas;

View File

@ -83,8 +83,8 @@ void MenuWidget::onGuiScaleChanged(const GuiScaleChangedEvent &event) {
}
TextButton &MenuWidget::addButton(const std::string &text, const TextButton::CppCallback &callback, u16 width) {
int x = (m_buttons.size() + m_sliders.size()) % m_width;
int y = (m_buttons.size() + m_sliders.size()) / m_width;
int x = int((m_buttons.size() + m_sliders.size()) % m_width);
int y = int((m_buttons.size() + m_sliders.size()) / m_width);
m_buttons.emplace_back(std::piecewise_construct,
std::forward_as_tuple(width, this), std::forward_as_tuple(x, y));
@ -106,8 +106,8 @@ void MenuWidget::setButtonEnabled(const std::string &text, bool isEnabled) {
}
SliderWidget &MenuWidget::addSlider(const std::string &text, const SliderWidget::CppCallback &callback, int min, int max, int initialValue) {
int x = (m_buttons.size() + m_sliders.size()) % m_width;
int y = (m_buttons.size() + m_sliders.size()) / m_width;
int x = int((m_buttons.size() + m_sliders.size()) % m_width);
int y = int((m_buttons.size() + m_sliders.size()) / m_width);
m_sliders.emplace_back(std::piecewise_construct,
std::forward_as_tuple(this), std::forward_as_tuple(x, y));
@ -124,14 +124,14 @@ SliderWidget &MenuWidget::addSlider(const std::string &text, const SliderWidget:
}
void MenuWidget::updateWidgetPosition(Widget &widget, int x, int y) {
widget.setPosition(x * (widget.width() + m_horizontalSpacing),
y * (widget.height() + m_verticalSpacing));
widget.setPosition(float(x * (widget.width() + m_horizontalSpacing)),
float(y * (widget.height() + m_verticalSpacing)));
if (widget.getPosition().x + widget.width() > Widget::m_width) {
Widget::m_width = widget.getPosition().x + widget.width();
if ((unsigned int)widget.getPosition().x + widget.width() > Widget::m_width) {
Widget::m_width = (unsigned int)widget.getPosition().x + widget.width();
}
if (widget.getPosition().y + widget.height() > Widget::m_height) {
Widget::m_height = widget.getPosition().y + widget.height();
if ((unsigned int)widget.getPosition().y + widget.height() > Widget::m_height) {
Widget::m_height = (unsigned int)widget.getPosition().y + widget.height();
}
}

View File

@ -29,13 +29,13 @@
#include "MouseItemWidget.hpp"
MouseItemWidget::MouseItemWidget(Widget *parent) : ItemWidget(m_inventory, 0, 0, parent) {
m_tooltipBackground.setColor(gk::Color{255, 255, 255, 240});
m_tooltipBackground.setColor(gk::Color::fromRGBA32(255, 255, 255, 240));
m_tooltipBackground.setPosition(20, 17, 0);
m_tooltipText.setPosition(26, 24, 0);
m_tooltipInfoText.setPosition(26, 35, 0);
m_tooltipInfoText.setColor({180, 180, 180});
m_tooltipInfoText.setColor(gk::Color::fromRGBA32(180, 180, 180));
}
void MouseItemWidget::onEvent(const SDL_Event &event) {
@ -142,7 +142,7 @@ void MouseItemWidget::draggingBehaviour(ItemWidget *newItemWidget) {
if (m_draggedSlots.size() > 1) {
if (m_isLeftClickDrag) {
for (auto &it : m_draggedSlots) {
u16 splitAmount = m_draggedStack.amount() / m_draggedSlots.size();
u16 splitAmount = u16(m_draggedStack.amount() / m_draggedSlots.size());
if (splitAmount > 0) {
it.first->setStack(m_draggedStack.item().stringID(), it.second.amount() + splitAmount);
@ -150,7 +150,7 @@ void MouseItemWidget::draggingBehaviour(ItemWidget *newItemWidget) {
}
}
u16 remainingAmount = (m_draggedStack.amount() == 1) ? 0 : m_draggedStack.amount() % std::min<u16>(m_draggedSlots.size(), m_draggedStack.amount());
u16 remainingAmount = (m_draggedStack.amount() == 1) ? 0 : m_draggedStack.amount() % std::min((u16)m_draggedSlots.size(), m_draggedStack.amount());
setStack(remainingAmount ? m_draggedStack.item().stringID() : BLOCK_AIR, remainingAmount);
}
@ -193,7 +193,7 @@ void MouseItemWidget::updateCurrentItem(ItemWidget *currentItemWidget) {
void MouseItemWidget::swapItems(ItemWidget &widget, bool isReadOnly) {
std::string widgetItemName = widget.stack().item().stringID();
u32 widgetItemAmount = widget.stack().amount();
u16 widgetItemAmount = widget.stack().amount();
if (!isReadOnly || stack().item().id() == 0 || stack().item().stringID() == widgetItemName) {
if (stack().item().stringID() != widgetItemName) {
@ -220,8 +220,8 @@ void MouseItemWidget::swapItems(ItemWidget &widget, bool isReadOnly) {
void MouseItemWidget::putItem(ItemWidget &widget) {
std::string widgetItemName = widget.stack().item().stringID();
u32 widgetItemID = widget.stack().item().id();
u32 widgetItemAmount = widget.stack().amount();
u16 widgetItemID = widget.stack().item().id();
u16 widgetItemAmount = widget.stack().amount();
if (!widgetItemID && stack().item().id()) {
widget.setStack(stack().item().stringID(), 1);
@ -232,7 +232,7 @@ void MouseItemWidget::putItem(ItemWidget &widget) {
setStack(stack().amount() > 1 ? stack().item().stringID() : "", stack().amount() - 1);
}
else if (stack().item().id() == 0) {
setStack(widgetItemName, ceil(widgetItemAmount / 2.0));
setStack(widgetItemName, (u16)ceil(widgetItemAmount / 2.0));
widget.setStack(widgetItemAmount > 1 ? widgetItemName : "", widgetItemAmount / 2);
}
}
@ -250,10 +250,10 @@ void MouseItemWidget::draw(gk::RenderTarget &target, gk::RenderStates states) co
}
}
void MouseItemWidget::updatePosition(float x, float y) {
x -= m_parent->getPosition().x + 10 * m_parent->getScale().x;
y -= m_parent->getPosition().y + 10 * m_parent->getScale().y;
void MouseItemWidget::updatePosition(s32 x, s32 y) {
float posX = (float)x - (m_parent->getPosition().x + 10 * m_parent->getScale().x);
float posY = (float)y - (m_parent->getPosition().y + 10 * m_parent->getScale().y);
setPosition(x / m_parent->getScale().x, y / m_parent->getScale().y, -20);
setPosition(posX / m_parent->getScale().x, posY / m_parent->getScale().y, -20.f);
}

View File

@ -60,7 +60,7 @@ class MouseItemWidget : public ItemWidget {
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
void updatePosition(float x, float y);
void updatePosition(s32 x, s32 y);
Inventory m_inventory{1, 1};

View File

@ -36,8 +36,8 @@ void ProgressBarWidget::init(const gk::FloatRect &clipRect, const gk::Vector2i &
m_clipRect = clipRect;
m_position = position;
m_image.setClipRect(clipRect.x, clipRect.y, clipRect.sizeX, clipRect.sizeY);
m_image.setPosition(position.x, position.y);
m_image.setClipRect(clipRect.x, clipRect.y, (u16)clipRect.sizeX, (u16)clipRect.sizeY);
m_image.setPosition((float)position.x, (float)position.y);
m_meta = meta;
m_maxMetaValue = maxMetaValue;
@ -47,8 +47,8 @@ void ProgressBarWidget::init(const gk::FloatRect &clipRect, const gk::Vector2i &
m_clipRect = clipRect;
m_position = position;
m_image.setClipRect(clipRect.x, clipRect.y, clipRect.sizeX, clipRect.sizeY);
m_image.setPosition(position.x, position.y);
m_image.setClipRect(clipRect.x, clipRect.y, (u16)clipRect.sizeX, (u16)clipRect.sizeY);
m_image.setPosition((float)position.x, (float)position.y);
m_meta = meta;
m_maxMeta = maxMeta;
@ -63,12 +63,12 @@ void ProgressBarWidget::update() {
m_image.setClipRect(0, 0, 0, 0);
}
else if (m_type == ProgressBarType::ItemProcess) {
m_image.setClipRect(m_clipRect.x, m_clipRect.y, (float)metaValue / m_maxMetaValue * m_clipRect.sizeX, m_clipRect.sizeY);
m_image.setClipRect(m_clipRect.x, m_clipRect.y, u16((float)metaValue / (float)m_maxMetaValue * m_clipRect.sizeX), (u16)m_clipRect.sizeY);
}
else if (m_type == ProgressBarType::BurnProcess) {
float height = ceil((float)metaValue / m_maxMetaValue * m_clipRect.sizeY);
m_image.setPosition(m_position.x, m_position.y + m_clipRect.sizeY - height);
m_image.setClipRect(m_clipRect.x, m_clipRect.y + m_clipRect.sizeY - height, m_clipRect.sizeX, height);
float height = ceilf((float)metaValue / (float)m_maxMetaValue * m_clipRect.sizeY);
m_image.setPosition((float)m_position.x, (float)m_position.y + m_clipRect.sizeY - height);
m_image.setClipRect(m_clipRect.x, m_clipRect.y + m_clipRect.sizeY - height, (u16)m_clipRect.sizeX, (u16)height);
}
}

View File

@ -41,7 +41,7 @@ void ScrollBarWidget::init(const gk::Texture &texture, const gk::FloatRect &clip
m_widget = &widget;
m_image.load(texture);
m_image.setClipRect(m_clipRect.x, m_clipRect.y, m_clipRect.sizeX, m_clipRect.sizeY);
m_image.setClipRect(m_clipRect.x, m_clipRect.y, (u16)m_clipRect.sizeX, (u16)m_clipRect.sizeY);
}
void ScrollBarWidget::onEvent(const SDL_Event &event) {
@ -49,14 +49,14 @@ void ScrollBarWidget::onEvent(const SDL_Event &event) {
if (isPointInWidget(event.button.x, event.button.y)) {
m_isDragging = true;
updateScrolling(event.button.y);
updateScrolling((u16)event.button.y);
}
}
else if (event.type == SDL_MOUSEBUTTONUP && event.button.button == SDL_BUTTON_LEFT) {
m_isDragging = false;
}
else if (event.type == SDL_MOUSEMOTION && m_isDragging) {
updateScrolling(event.motion.y);
updateScrolling((u16)event.motion.y);
}
}
@ -67,8 +67,8 @@ void ScrollBarWidget::draw(gk::RenderTarget &target, gk::RenderStates states) co
}
void ScrollBarWidget::updateScrolling(u16 y) {
s16 imageY = y - getPosition().y * Config::guiScale - m_parent->getPosition().y;
m_image.setPosition(0, glm::clamp<s16>(imageY / Config::guiScale - m_barHeight / 2, m_minY, m_maxY));
float imageY = floorf(y - getPosition().y * Config::guiScale - m_parent->getPosition().y);
m_image.setPosition(0, glm::clamp<float>(imageY / Config::guiScale - m_barHeight / 2, (float)m_minY, (float)m_maxY));
m_scrolling = m_image.getPosition().y / (m_maxY - m_minY);

View File

@ -38,19 +38,19 @@ ScrollableListElement::ScrollableListElement(u16 id, const std::string &line1, c
m_line2.setString(line2);
m_line2.updateVertexBuffer();
m_line2.setPosition(0, m_line1.getPosition().y + m_line1.getSize().y + 1);
m_line2.setColor(gk::Color{128, 128, 128});
m_line2.setPosition(0.f, m_line1.getPosition().y + (float)m_line1.getSize().y + 1.f);
m_line2.setColor(gk::Color::fromRGBA32(128, 128, 128));
m_line2.setShadowEnabled(false);
m_line3.setString(line3);
m_line3.updateVertexBuffer();
m_line3.setPosition(0, m_line2.getPosition().y + m_line2.getSize().y);
m_line3.setColor(gk::Color{128, 128, 128});
m_line3.setPosition(0.f, m_line2.getPosition().y + (float)m_line2.getSize().y);
m_line3.setColor(gk::Color::fromRGBA32(128, 128, 128));
m_line3.setShadowEnabled(false);
m_height = m_line3.getPosition().y + m_line3.getSize().y + 2;
m_height = (unsigned int)m_line3.getPosition().y + m_line3.getSize().y + 2;
m_icon.setPosRect(0, 0, m_height, m_height);
m_icon.setPosRect(0, 0, (u16)m_height, (u16)m_height);
m_line1.move(m_icon.posRect().sizeX + 3, 0);
m_line2.move(m_icon.posRect().sizeX + 3, 0);
m_line3.move(m_icon.posRect().sizeX + 3, 0);
@ -70,7 +70,7 @@ ScrollableList::ScrollableList() : Widget(ScrollableListElement::widgetWidth, 0)
m_cursor.setOutlineThickness(1);
m_cursor.setOutlineColor(gk::Color::White);
m_cursor.setFillColor(gk::Color::Transparent);
m_cursor.setSize(m_width, m_height);
m_cursor.setSize((float)m_width, (float)m_height);
}
void ScrollableList::onEvent(const SDL_Event &event) {
@ -87,7 +87,7 @@ void ScrollableList::addElement(const std::string &line1, const std::string &lin
m_elements.emplace_back(m_elements.size(), line1, line2, line3, this);
ScrollableListElement &element = m_elements.back();
element.setPosition(0, (m_elements.size() - 1) * (m_elements.back().height() + 4) + 2);
element.setPosition(0.f, float(m_elements.size() - 1) * float(m_elements.back().height() + 4) + 2.f);
m_height += m_elements.back().height();
@ -96,8 +96,8 @@ void ScrollableList::addElement(const std::string &line1, const std::string &lin
}
void ScrollableList::selectElement(ScrollableListElement &element) {
m_cursor.setSize(element.width() + 2, element.height() + 2);
m_cursor.setPosition(-1, element.getPosition().y - 1);
m_cursor.setSize((float)element.width() + 2.f, (float)element.height() + 2.f);
m_cursor.setPosition(-1.f, element.getPosition().y - 1.f);
m_selectedElement = &element;
}

View File

@ -32,7 +32,7 @@ SliderWidget::SliderWidget(Widget *parent) : SliderWidget(200, parent) {
SliderWidget::SliderWidget(u16 width, Widget *parent) : Widget(width, 20, parent) {
m_text.setColor(m_defaultTextColor);
m_text.setShadowColor({56, 56, 56});
m_text.setShadowColor(gk::Color::fromRGBA32(56, 56, 56));
m_slider.setClipRect(0, 66, 8, 20);
m_background.setClipRect(0, 46, width, 20);
@ -71,7 +71,7 @@ void SliderWidget::onEvent(const SDL_Event &event) {
}
void SliderWidget::setCurrentValue(int currentValue) {
m_percentage = (currentValue - m_min) / float(m_max - m_min);
m_percentage = float(currentValue - m_min) / float(m_max - m_min);
updateSliderPosition();
}
@ -79,13 +79,15 @@ void SliderWidget::setCurrentValue(int currentValue) {
void SliderWidget::setText(const std::string &text) {
m_text.setString(text);
m_text.updateVertexBuffer();
m_text.setPosition(m_width / 2 - m_text.getSize().x / 2,
m_height / 2 - m_text.getSize().y / 2, 0);
m_text.setPosition(
(float)(m_width / 2 - m_text.getSize().x / 2),
(float)(m_height / 2 - m_text.getSize().y / 2)
);
}
void SliderWidget::updatePercentage(s32 mouseX) {
if (m_isDragging) {
m_percentage = (mouseX - getGlobalBounds().x) / Config::guiScale / m_width;
m_percentage = ((float)mouseX - getGlobalBounds().x) / Config::guiScale / (float)m_width;
m_percentage = std::clamp(m_percentage, 0.f, 1.f);
updateSliderPosition();
@ -93,8 +95,8 @@ void SliderWidget::updatePercentage(s32 mouseX) {
}
void SliderWidget::updateSliderPosition() {
m_slider.setPosition(m_percentage * (m_width - 8), 0);
m_sliderBorder.setPosition(m_percentage * (m_width - 8) + 6, 0);
m_slider.setPosition(m_percentage * float(m_width - 8), 0.f);
m_sliderBorder.setPosition(m_percentage * float(m_width - 8) + 6.f, 0.f);
}
void SliderWidget::draw(gk::RenderTarget &target, gk::RenderStates states) const {

View File

@ -43,7 +43,7 @@ class SliderWidget : public Widget {
void onEvent(const SDL_Event &event) override;
int getCurrentValue() const { return m_min + (m_max - m_min) * m_percentage; }
int getCurrentValue() const { return m_min + int(float(m_max - m_min) * m_percentage); }
void setMinMaxValues(int min, int max) { m_min = min; m_max = max; }
void setCurrentValue(int currentValue);
@ -58,8 +58,8 @@ class SliderWidget : public Widget {
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
const gk::Color m_defaultTextColor{224, 224, 224};
const gk::Color m_hoverColor{255, 255, 160};
const gk::Color m_defaultTextColor = gk::Color::fromRGBA32(224, 224, 224);
const gk::Color m_hoverColor = gk::Color::fromRGBA32(255, 255, 160);
gk::Image m_slider{"texture-widgets"};
gk::Image m_background{"texture-widgets"};

View File

@ -76,7 +76,7 @@ void Text::draw(gk::RenderTarget &target, gk::RenderStates states) const {
if (m_verticesCount == 0) return;
states.transform.translate(m_padding.x, m_padding.y);
states.transform.translate((float)m_padding.x, (float)m_padding.y);
states.texture = &m_font.texture();
states.vertexAttributes = gk::VertexAttribute::All;
@ -132,7 +132,7 @@ void Text::updateVertexBuffer() const {
x += m_font.getCharWidth(c);
}
m_verticesCount = vertices.size();
m_verticesCount = (u32)vertices.size();
gk::VertexBuffer::bind(&m_vbo);
m_vbo.setData(sizeof(gk::Vertex) * m_verticesCount, vertices.data(), GL_DYNAMIC_DRAW);
@ -141,8 +141,8 @@ void Text::updateVertexBuffer() const {
m_size.x = std::max(x, maxX);
m_size.y = y + m_font.getTileSize().y + 1;
u32 backgroundX = std::max<s32>(m_background.getSize().x, m_size.x + m_padding.x);
u32 backgroundY = std::max<s32>(m_background.getSize().y, m_size.y + m_padding.y);
float backgroundX = std::max(m_background.getSize().x, float(m_size.x + m_padding.x));
float backgroundY = std::max(m_background.getSize().y, float(m_size.y + m_padding.y));
m_background.setSize(backgroundX, backgroundY);
}
@ -162,8 +162,8 @@ void Text::addCharacter(u32 x, u32 y, const gk::Color &color, u8 c, std::vector<
vertices.emplace_back();
gk::Vertex &vertex = vertices.back();
vertex.coord3d[0] = x + coords[i][0] * m_font.getTileSize().x;
vertex.coord3d[1] = y + coords[i][1] * m_font.getTileSize().y;
vertex.coord3d[0] = float(x + coords[i][0] * m_font.getTileSize().x);
vertex.coord3d[1] = float(y + coords[i][1] * m_font.getTileSize().y);
vertex.coord3d[2] = 0;
vertex.coord3d[3] = -1;

View File

@ -50,7 +50,7 @@ class Text : public gk::Drawable, public gk::Transformable {
gk::Vector2f getBackgroundSize() const { return m_background.getSize(); }
void setBackgroundColor(const gk::Color &color) { m_background.setFillColor(color); }
void setBackgroundSize(unsigned int width, unsigned int height) { m_background.setSize(width, height); }
void setBackgroundSize(unsigned int width, unsigned int height) { m_background.setSize((float)width, (float)height); }
void setBackgroundOutline(int thickness, const gk::Color &color) { m_background.setOutlineThickness(thickness); m_background.setOutlineColor(color); }
void setShadowEnabled(bool isShadowEnabled) { m_isShadowEnabled = isShadowEnabled; m_isUpdateNeeded = true; }
@ -68,7 +68,7 @@ class Text : public gk::Drawable, public gk::Transformable {
std::string m_string;
bool m_isShadowEnabled = true;
gk::Color m_shadowColor{70, 70, 70};
gk::Color m_shadowColor = gk::Color::fromRGBA32(70, 70, 70);
Font &m_font;

View File

@ -31,7 +31,7 @@ TextButton::TextButton(Widget *parent) : TextButton(200, parent) {
TextButton::TextButton(u16 width, Widget *parent) : Widget(width, 20, parent) {
m_text.setColor(m_defaultColor);
m_text.setShadowColor({56, 56, 56});
m_text.setShadowColor(gk::Color::fromRGBA32(56, 56, 56));
m_background.setClipRect(0, 66, width, 20);
m_hoverBackground.setClipRect(0, 86, width, 20);
@ -80,8 +80,8 @@ void TextButton::setText(const std::string &text) {
m_text.setString(text);
m_text.updateVertexBuffer();
m_text.setPosition(
std::roundf(m_width / 2.f - m_text.getSize().x / 2.f),
std::roundf(m_height / 2.f - m_text.getSize().y / 2.f)
std::roundf((float)m_width / 2.f - (float)m_text.getSize().x / 2.f),
std::roundf((float)m_height / 2.f - (float)m_text.getSize().y / 2.f)
);
}

View File

@ -62,9 +62,9 @@ class TextButton : public Widget {
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
const gk::Color m_defaultColor{224, 224, 224};
const gk::Color m_hoverColor{255, 255, 160};
const gk::Color m_disabledColor{160, 160, 160};
const gk::Color m_defaultColor = gk::Color::fromRGBA32(224, 224, 224);
const gk::Color m_hoverColor = gk::Color::fromRGBA32(255, 255, 160);
const gk::Color m_disabledColor = gk::Color::fromRGBA32(160, 160, 160);
gk::Image m_background{"texture-widgets"};
gk::Image m_hoverBackground{"texture-widgets"};

View File

@ -31,7 +31,7 @@
TextInput::TextInput(Widget *parent) : Widget(parent) {
m_cursor.setString("_");
m_placeholder.setColor(gk::Color(150, 150, 150));
m_placeholder.setColor(gk::Color::fromRGBA32(150, 150, 150));
}
void TextInput::onEvent(const SDL_Event &event) {
@ -44,7 +44,7 @@ void TextInput::onEvent(const SDL_Event &event) {
m_text.setString(m_content);
m_text.updateVertexBuffer();
m_cursor.setPosition(m_text.getSize().x, 0);
m_cursor.setPosition((float)m_text.getSize().x, 0.f);
}
if (event.type == SDL_TEXTINPUT) {
@ -56,7 +56,7 @@ void TextInput::onEvent(const SDL_Event &event) {
m_text.setString(m_content);
m_text.updateVertexBuffer();
m_cursor.setPosition(m_text.getSize().x, 0);
m_cursor.setPosition((float)m_text.getSize().x, 0.f);
}
}
}
@ -66,7 +66,7 @@ void TextInput::setString(const std::string &string) {
m_content = string;
m_text.setString(m_content);
m_text.updateVertexBuffer();
m_cursor.setPosition(m_text.getSize().x, 0);
m_cursor.setPosition((float)m_text.getSize().x, 0);
}
void TextInput::draw(gk::RenderTarget &target, gk::RenderStates states) const {

View File

@ -26,8 +26,8 @@
*/
#include "Widget.hpp"
bool Widget::isPointInWidget(float x, float y) {
return getGlobalBounds().intersects(gk::FloatRect{x, y, 1, 1});
bool Widget::isPointInWidget(int x, int y) {
return getGlobalBounds().intersects(gk::FloatRect{(float)x, (float)y, 1, 1});
}
gk::FloatRect Widget::getGlobalBounds() const {

View File

@ -41,7 +41,7 @@ class Widget : public gk::Drawable, public gk::Transformable {
virtual void onEvent(const SDL_Event &) {}
virtual void update() {}
bool isPointInWidget(float x, float y);
bool isPointInWidget(int x, int y);
gk::FloatRect getGlobalBounds() const;

View File

@ -53,7 +53,7 @@ void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
if (event.type == SDL_MOUSEBUTTONDOWN && m_selectedBlock.w != -1) {
if (event.button.button == SDL_BUTTON_LEFT) {
m_animationStart = gk::GameClock::getInstance().getTicks();
m_currentTool = &m_player.inventory().getStack(hotbar.cursorPos(), 0);
m_currentTool = &m_player.inventory().getStack((u16)hotbar.cursorPos(), 0);
}
else if (event.button.button == SDL_BUTTON_RIGHT)
activateBlock(hotbar);
@ -95,7 +95,7 @@ void BlockCursor::update(const Hotbar &hotbar) {
if (cursorPos != -1) {
float timeToBreak = 0;
if (m_animationStart) {
const ItemStack &currentStack = m_player.inventory().getStack(cursorPos, 0);
const ItemStack &currentStack = m_player.inventory().getStack((u16)cursorPos, 0);
if (m_currentTool->item().id() != currentStack.item().id()) {
m_animationStart = ticks;
m_currentTool = &currentStack;
@ -111,7 +111,7 @@ void BlockCursor::update(const Hotbar &hotbar) {
timeToBreak = m_currentBlock->timeToBreak(currentStack.item().harvestCapability(), currentStack.item().miningSpeed(), isEffective);
if (ticks > m_animationStart + timeToBreak * 1000) {
if (ticks > m_animationStart + u32(timeToBreak * 1000)) {
m_world.setBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z, 0);
m_animationStart = ticks;
@ -122,7 +122,7 @@ void BlockCursor::update(const Hotbar &hotbar) {
if (m_animationStart && m_currentBlock)
updateAnimationVertexBuffer(*m_currentBlock, orientation,
(ticks - m_animationStart) / (timeToBreak * 100));
(ticks - m_animationStart) / u32(timeToBreak * 100));
}
if (m_selectedBlock.w != -1)
@ -143,7 +143,7 @@ void BlockCursor::activateBlock(const Hotbar &hotbar) {
m_lastActivationTime = gk::GameClock::getInstance().getTicks();
u32 blockId = m_world.getBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z);
u16 blockId = m_world.getBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z);
const Block &block = Registry::getInstance().getBlock(blockId);
const Item &item = hotbar.currentItem();
@ -166,7 +166,7 @@ void BlockCursor::activateBlock(const Hotbar &hotbar) {
}
if (block.id() && !itemActivationSent && !blockActivationSent && hotbar.currentItem().id() && item.isBlock()) {
s8 face = m_selectedBlock.w;
s8 face = (s8)m_selectedBlock.w;
s32 x = m_selectedBlock.x;
s32 y = m_selectedBlock.y;
@ -191,7 +191,7 @@ void BlockCursor::activateBlock(const Hotbar &hotbar) {
// Second, we check if the new block is not inside the player
const Block &newBlock = Registry::getInstance().getBlock(hotbar.currentItem().id());
const BlockState &newBlockState = newBlock.getState(0); // FIXME: Get state from item stack
gk::FloatBox boundingBox = newBlockState.boundingBox() + gk::Vector3f(x - m_player.x(), y - m_player.y(), z - m_player.z());
gk::FloatBox boundingBox = newBlockState.boundingBox() + gk::Vector3f(float(x - m_player.x()), float(y - m_player.y()), float(z - m_player.z()));
gk::FloatBox playerBoundingBox = m_player.hitbox();
if (!boundingBox.intersects(playerBoundingBox) && newBlock.placementConstraints().check(m_world, {x, y, z})) {
u32 block = hotbar.currentItem().id();
@ -206,8 +206,11 @@ void BlockCursor::activateBlock(const Hotbar &hotbar) {
m_client.sendPlayerPlaceBlock(x, y, z, block);
const ItemStack &currentStack = m_player.inventory().getStack(hotbar.cursorPos(), 0);
m_player.inventory().setStack(hotbar.cursorPos(), 0, currentStack.amount() > 1 ? currentStack.item().stringID() : "", currentStack.amount() - 1);
const ItemStack &currentStack = m_player.inventory().getStack((u16)hotbar.cursorPos(), 0);
m_player.inventory().setStack((u16)hotbar.cursorPos(), 0, currentStack.amount() > 1
? currentStack.item().stringID()
: "", currentStack.amount() - 1
);
m_client.sendPlayerInvUpdate();
}
@ -275,7 +278,7 @@ void BlockCursor::updateAnimationVertexBuffer(const BlockState &blockState, u8f
memcpy(&vertices[f][v].color, &color[0], 4 * sizeof(GLfloat));
if (animationPos != -1) {
glm::vec4 blockTexCoords{0.1f * animationPos, 0.0, 0.1f + 0.1f * animationPos, 1.0};
glm::vec4 blockTexCoords{0.1f * (float)animationPos, 0.0f, 0.1f + 0.1f * (float)animationPos, 1.0f};
float faceTexCoords[nVertsPerFace][nCoordsPerUV] = {
{blockTexCoords.x, blockTexCoords.w},
{blockTexCoords.z, blockTexCoords.w},
@ -307,7 +310,11 @@ void BlockCursor::draw(gk::RenderTarget &target, gk::RenderStates states) const
// Subtract the camera position - see comment in ClientWorld::draw()
const gk::Vector3d &cameraPosition = m_player.camera().getDPosition();
states.transform.translate(m_selectedBlock.x - cameraPosition.x, m_selectedBlock.y - cameraPosition.y, m_selectedBlock.z - cameraPosition.z);
states.transform.translate(
float(m_selectedBlock.x - cameraPosition.x),
float(m_selectedBlock.y - cameraPosition.y),
float(m_selectedBlock.z - cameraPosition.z)
);
glCheck(glPolygonMode(GL_FRONT_AND_BACK, GL_LINE));
target.draw(m_vbo, GL_QUADS, 0, nFaces * nVertsPerFace, states);
@ -337,7 +344,7 @@ glm::ivec4 BlockCursor::findSelectedBlock() const {
s32f bestZ = s32f(floor(position.z));
// Deal with a degenerate case: camera in the middle of a block
const BlockState *blockState = m_world.getBlockState(bestX, bestY, bestZ);
const BlockState *blockState = m_world.getBlockState((int)bestX, (int)bestY, (int)bestZ);
if (blockState && blockState->block().id() && blockState->drawType() != BlockDrawType::Liquid) {
// We're inside a node, therefore there's no face, but we still need
// to return a valid block. We use face 6 for that. For rightclicks,
@ -355,7 +362,7 @@ glm::ivec4 BlockCursor::findSelectedBlock() const {
if (double(bestX) == position.x && double(bestY) == position.y) {
for (int y = -1; y <= 0; y++) {
for (int x = -1; x <= 0; x++) {
const BlockState *blockState = m_world.getBlockState(bestX + x, bestY + y, bestZ);
const BlockState *blockState = m_world.getBlockState((int)bestX + x, (int)bestY + y, (int)bestZ);
if (blockState && blockState->block().id() && blockState->drawType() != BlockDrawType::Liquid) {
return glm::ivec4{bestX + x, bestY + y, bestZ, 6};
}

View File

@ -28,11 +28,11 @@
#include "BlockInfoWidget.hpp"
BlockInfoWidget::BlockInfoWidget(Widget *parent) : Widget(160, 32, parent) {
m_itemWidget.setPosition(5, m_height / 2 - m_itemWidget.height() / 2, 0);
m_itemWidget.setPosition(5, float(m_height / 2 - m_itemWidget.height() / 2), 0);
m_background.setColor(gk::Color{255, 255, 255, 200});
m_background.setColor(gk::Color::fromRGBA32(255, 255, 255, 200));
m_text.setColor(gk::Color{240, 240, 240});
m_text.setColor(gk::Color::fromRGBA32(240, 240, 240));
m_text.setPosition(26, 8, 0);
}

View File

@ -46,7 +46,7 @@ void Chat::addChatMessage(u16 clientID, const std::string &message) {
m_posY += m_chatMessages.back().text().getSize().y + 1;
move(0, -m_chatMessages.back().text().getSize().y - 1);
move(0.f, (float)-m_chatMessages.back().text().getSize().y - 1.f);
}
void Chat::setMessageVisibility(bool areMessagesVisible) {

View File

@ -43,7 +43,7 @@ class Chat : public gk::Drawable, public gk::Transformable {
const std::string &getHistoryEntry(u32 id) const { return m_history.at(m_history.size() - id - 1); }
void addHistoryEntry(const std::string &entry) { m_history.emplace_back(entry); }
u32 historySize() const { return m_history.size(); }
u32 historySize() const { return (u32)m_history.size(); }
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;

View File

@ -33,8 +33,8 @@ ChatMessage::ChatMessage(const std::string &message, u32 posY, const Player *pla
else
m_text.setString(message);
m_text.setPosition(0, posY);
m_text.setBackgroundColor(gk::Color{0, 0, 0, 127});
m_text.setPosition(0.f, (float)posY);
m_text.setBackgroundColor(gk::Color::fromRGBA32(0, 0, 0, 127));
m_text.setBackgroundSize(300, 10);
m_text.setMaxLineLength(300);
m_text.setPadding(1, 1);

View File

@ -36,9 +36,9 @@ void Crosshair::setup() {
m_vShape1.setSize(4, 19);
m_vShape2.setSize(4, 19);
m_hShape.setFillColor(gk::Color{200, 200, 200, 180});
m_vShape1.setFillColor(gk::Color{200, 200, 200, 180});
m_vShape2.setFillColor(gk::Color{200, 200, 200, 180});
m_hShape.setFillColor(gk::Color::fromRGBA32(200, 200, 200, 180));
m_vShape1.setFillColor(gk::Color::fromRGBA32(200, 200, 200, 180));
m_vShape2.setFillColor(gk::Color::fromRGBA32(200, 200, 200, 180));
m_hShape.setPosition(Config::screenWidth / 2.0f - m_hShape.width() / 2, Config::screenHeight / 2.0f - m_hShape.height() / 2, 0);
m_vShape1.setPosition(Config::screenWidth / 2.0f - m_vShape1.width() / 2, Config::screenHeight / 2.0f - m_hShape.height() / 2 - m_vShape1.height(), 0);

View File

@ -47,7 +47,7 @@ void DebugLightmapViewer::update(const ClientWorld &world) {
for (u32 z = 0 ; z < CHUNK_HEIGHT ; ++z) {
Text &text = m_chunkLightmapValues[x][y][z];
text.setString(std::to_string(chunk->lightmap().getSunlight(x, y, z)));
text.setPosition(x * 8, (CHUNK_DEPTH - y - 1) * 8);
text.setPosition((float)x * 8.f, float(CHUNK_DEPTH - y - 1) * 8.f);
text.setScale(0.5f, 0.5f);
}
}
@ -55,9 +55,9 @@ void DebugLightmapViewer::update(const ClientWorld &world) {
}
}
s32 rx = gk::pmod(std::floor(m_player.x()), CHUNK_WIDTH);
s32 ry = gk::pmod(std::floor(m_player.y()), CHUNK_DEPTH);
m_playerRect.setPosition(rx * 8, (CHUNK_DEPTH - ry - 1) * 8);
u32 rx = gk::pmod((s32)std::floor(m_player.x()), CHUNK_WIDTH);
u32 ry = gk::pmod((s32)std::floor(m_player.y()), CHUNK_DEPTH);
m_playerRect.setPosition((float)rx * 8.f, float(CHUNK_DEPTH - ry - 1) * 8.f);
}
void DebugLightmapViewer::draw(gk::RenderTarget &target, gk::RenderStates states) const {
@ -67,6 +67,6 @@ void DebugLightmapViewer::draw(gk::RenderTarget &target, gk::RenderStates states
for (u32 x = 0 ; x < CHUNK_WIDTH ; ++x)
for (u32 y = 0 ; y < CHUNK_DEPTH ; ++y)
target.draw(m_chunkLightmapValues[x][y][gk::pmod(m_player.z(), CHUNK_HEIGHT)], states);
target.draw(m_chunkLightmapValues[x][y][gk::pmod((s32)m_player.z(), CHUNK_HEIGHT)], states);
}

View File

@ -59,9 +59,9 @@ DebugOverlay::DebugOverlay(const ClientPlayer &player, const ClientWorld &world)
}
void DebugOverlay::update(bool printOpenGLInfo) {
s32 px = std::floor(m_player.x());
s32 py = std::floor(m_player.y());
s32 pz = std::floor(m_player.z());
s32 px = (s32)std::floor(m_player.x());
s32 py = (s32)std::floor(m_player.y());
s32 pz = (s32)std::floor(m_player.z());
// Directions is now an angle4
const char *directions[4] = {"East", "North", "West", "South"};

View File

@ -55,19 +55,22 @@ HUD::HUD(ClientPlayer &player, ClientWorld &world, ClientCommandHandler &client)
void HUD::setup() {
m_orthoMatrix = glm::ortho(0.0f, (float)Config::screenWidth, (float)Config::screenHeight, 0.0f, DIST_2D_FAR, DIST_2D_NEAR);
m_hotbar.setPosition(Config::screenWidth / getScale().x / 2 - m_hotbar.width() / 2, Config::screenHeight / getScale().y - m_hotbar.height(), 0);
m_hotbar.setPosition(
Config::screenWidth / getScale().x / 2.f - (float)m_hotbar.width() / 2.f,
Config::screenHeight / getScale().y - (float)m_hotbar.height()
);
m_blockInfoWidget.setPosition(Config::screenWidth / getScale().x / 2 - m_blockInfoWidget.width() / 2, 2, 0);
m_blockInfoWidget.setPosition(Config::screenWidth / getScale().x / 2.f - (float)m_blockInfoWidget.width() / 2.f, 2.f);
m_fpsText.setPosition(Config::screenWidth / getScale().x - 36, 2);
m_fpsText.setPosition(Config::screenWidth / getScale().x - 36.f, 2.f);
m_crosshair.setup();
m_chat.setPosition(2, Config::screenHeight / Config::guiScale - 50);
m_chat.setPosition(2.f, Config::screenHeight / Config::guiScale - 50.f);
m_minimap.setPosition(Config::screenWidth / Config::guiScale - Minimap::minimapSize - 15, 15);
m_minimap.setPosition(float(Config::screenWidth / Config::guiScale - Minimap::minimapSize) - 15.f, 15.f);
m_debugLightmapViewer.setPosition(0, Config::screenHeight / Config::guiScale - DebugLightmapViewer::totalSize);
m_debugLightmapViewer.setPosition(0.f, float(Config::screenHeight / Config::guiScale - DebugLightmapViewer::totalSize));
}
void HUD::onEvent(const SDL_Event &event) {

View File

@ -47,16 +47,16 @@ void Hotbar::onEvent(const SDL_Event &event) {
if (event.type == SDL_MOUSEWHEEL) {
if (event.wheel.y < 0) {
m_cursorPos = (m_cursorPos + 1) % 9;
m_player.setHeldItemSlot(m_cursorPos);
m_client.sendPlayerHeldItemChanged(m_cursorPos, currentItem().id());
m_player.setHeldItemSlot((u8)m_cursorPos);
m_client.sendPlayerHeldItemChanged((u8)m_cursorPos, currentItem().id());
}
else if (event.wheel.y > 0) {
m_cursorPos = (m_cursorPos == 0) ? 8 : m_cursorPos - 1;
m_player.setHeldItemSlot(m_cursorPos);
m_client.sendPlayerHeldItemChanged(m_cursorPos, currentItem().id());
m_player.setHeldItemSlot((u8)m_cursorPos);
m_client.sendPlayerHeldItemChanged((u8)m_cursorPos, currentItem().id());
}
m_cursor.setPosition(-1 + 20 * m_cursorPos, -1, 0);
m_cursor.setPosition(-1.f + 20.f * (float)m_cursorPos, -1.f);
}
}
@ -66,7 +66,7 @@ void Hotbar::update() {
return;
m_cursorPos = m_player.heldItemSlot();
m_cursor.setPosition(-1 + 20 * m_cursorPos, -1, 0);
m_cursor.setPosition(-1.f + 20.f * (float)m_cursorPos, -1.f);
}
for (u16 i = 0 ; i < 9 ; ++i) {
@ -74,7 +74,7 @@ void Hotbar::update() {
m_items.emplace_back(m_player.inventory(), i, 0);
ItemWidget &widget = m_items.back();
widget.setPosition(5 + 20 * i - 3, 2, 0);
widget.setPosition(5.f + 20.f * (float)i - 3.f, 2.f);
}
m_items[i].setStack(
@ -85,7 +85,7 @@ void Hotbar::update() {
}
const Item &Hotbar::currentItem() const {
return m_player.inventory().getStack(m_cursorPos, 0).item();
return m_player.inventory().getStack((u16)m_cursorPos, 0).item();
}
void Hotbar::draw(gk::RenderTarget &target, gk::RenderStates states) const {

View File

@ -32,7 +32,7 @@
Minimap::Minimap() {
m_border.setFillColor(gk::Color::Transparent);
m_border.setOutlineColor(gk::Color{224, 224, 224});
m_border.setOutlineColor(gk::Color::fromRGBA32(224, 224, 224));
m_border.setOutlineThickness(1);
m_border.setSize(minimapSize, minimapSize);
@ -45,7 +45,10 @@ Minimap::Minimap() {
void Minimap::update(const ClientPlayer &player, class ClientWorld &world) {
m_playerChunkPos = player.getCurrentChunk();
m_playerChunk.setPosition(m_playerChunkPos.x * (chunkSize + 2), -m_playerChunkPos.y * (chunkSize + 2));
m_playerChunk.setPosition(
float(m_playerChunkPos.x * (chunkSize + 2)),
float(-m_playerChunkPos.y * (chunkSize + 2))
);
for (auto &it : m_chunks) {
if (it.first.z == m_playerChunkPos.z) {
@ -55,10 +58,10 @@ void Minimap::update(const ClientPlayer &player, class ClientWorld &world) {
it.second.first.setFillColor(gk::Color::Green);
}
else if (chunk->isInitialized()) {
it.second.first.setFillColor(gk::Color{224, 224, 224});
it.second.first.setFillColor(gk::Color::fromRGBA32(224, 224, 224));
}
else {
it.second.first.setFillColor(gk::Color{127, 127, 127});
it.second.first.setFillColor(gk::Color::fromRGBA32(127, 127, 127));
}
it.second.second.setString(std::to_string(chunk->debugTimesReceived));
@ -93,8 +96,8 @@ void Minimap::onChunkCreatedEvent(const ChunkCreatedEvent &event) {
if (Config::isChunkMinimapEnabled) {
auto &[rect, text] = m_chunks[event.chunkPos];
rect.setSize(chunkSize, chunkSize);
rect.setPosition(event.chunkPos.x * (chunkSize + 2), -event.chunkPos.y * (chunkSize + 2));
rect.setFillColor(event.isLoaded ? gk::Color{224, 224, 224} : gk::Color{127, 127, 127});
rect.setPosition(float(event.chunkPos.x * (chunkSize + 2)), float(-event.chunkPos.y * (chunkSize + 2)));
rect.setFillColor(event.isLoaded ? gk::Color::fromRGBA32(224, 224, 224) : gk::Color::fromRGBA32(127, 127, 127));
rect.setOutlineThickness(1);
rect.setOutlineColor(gk::Color::Transparent);
@ -118,10 +121,10 @@ void Minimap::updatePlayerFovVertexBuffer() {
vertices[0].coord3d[0] = 0.f;
vertices[0].coord3d[1] = 0.f;
vertices[1].coord3d[0] = -sin(glm::radians(Config::cameraFOV / 2.f)) * Config::renderDistance * (chunkSize + 2) / cos(glm::radians(Config::cameraFOV / 2.f));
vertices[1].coord3d[0] = -sinf(glm::radians(Config::cameraFOV / 2.f)) * Config::renderDistance * (chunkSize + 2) / cosf(glm::radians(Config::cameraFOV / 2.f));
vertices[1].coord3d[1] = -(Config::renderDistance * (chunkSize + 2));
vertices[2].coord3d[0] = sin(glm::radians(Config::cameraFOV / 2.f)) * Config::renderDistance * (chunkSize + 2) / cos(glm::radians(Config::cameraFOV / 2.f));
vertices[2].coord3d[0] = sinf(glm::radians(Config::cameraFOV / 2.f)) * Config::renderDistance * (chunkSize + 2) / cosf(glm::radians(Config::cameraFOV / 2.f));
vertices[2].coord3d[1] = -(Config::renderDistance * (chunkSize + 2));
gk::Color color = gk::Color::Blue;
@ -151,7 +154,10 @@ void Minimap::draw(gk::RenderTarget &target, gk::RenderStates states) const {
target.draw(m_vbo, GL_TRIANGLES, 0, 3, states2);
}
states.transform.translate(-m_playerChunkPos.x * (chunkSize + 2) + minimapSize / 2.f, m_playerChunkPos.y * (chunkSize + 2) + minimapSize / 2.f);
states.transform.translate(
float(-m_playerChunkPos.x * (chunkSize + 2)) + minimapSize / 2.f,
float(m_playerChunkPos.y * (chunkSize + 2)) + minimapSize / 2.f
);
for (auto &it : m_chunks)
if (it.first.z == m_playerChunkPos.z) {

View File

@ -101,7 +101,7 @@ void BlockCursorRaycast::rayCastToAxis(const Axis axis, const glm::dvec3 &positi
s32f firstNodeRow = lookAtCoord < 0. ? s32f(floor(posCoord)) : s32f(ceil(posCoord)) - 1;
s32f lastNodeRow = s32f(floor(posCoord + lookAtCoord * maxReach));
int_fast8_t dir = (lookAtCoord > 0.) - (lookAtCoord < 0.);
s8f dir = s8f((lookAtCoord > 0.) - (lookAtCoord < 0.));
if (!dir) {
// Can't cross any planes if it doesn't change in this axis
return;
@ -113,14 +113,14 @@ void BlockCursorRaycast::rayCastToAxis(const Axis axis, const glm::dvec3 &positi
isect = intersectAxisPlane(axis, double(nodeRow + (dir < 0)), position, lookAt);
s32f nx, ny, nz;
nx = axis == AXIS_X ? nodeRow : floor(isect.x);
ny = axis == AXIS_Y ? nodeRow : floor(isect.y);
nz = axis == AXIS_Z ? nodeRow : floor(isect.z);
nx = axis == AXIS_X ? nodeRow : (s32f)floor(isect.x);
ny = axis == AXIS_Y ? nodeRow : (s32f)floor(isect.y);
nz = axis == AXIS_Z ? nodeRow : (s32f)floor(isect.z);
const BlockState *blockState = world.getBlockState(nx, ny, nz);
const BlockState *blockState = world.getBlockState((int)nx, (int)ny, (int)nz);
if (!blockState) continue;
u8f orientation = blockState->block().isRotatable() ? world.getData(nx, ny, nz) & 0x1F : 0;
u8f orientation = blockState->block().isRotatable() ? world.getData((int)nx, (int)ny, (int)nz) & 0x1F : 0;
const gk::FloatBox &boundingBox = blockState->boundingBox();
glm::vec3 localCorner1{boundingBox.x, boundingBox.y, boundingBox.z};

View File

@ -216,8 +216,8 @@ void ClientCommandHandler::setupCallbacks() {
s32 x, y, z;
u32 block;
packet >> x >> y >> z >> block;
m_world.setBlock(x, y, z, block);
m_world.setData(x, y, z, block >> 16);
m_world.setBlock(x, y, z, u16(block & 0xffff));
m_world.setData(x, y, z, u16((block >> 16) & 0xffff));
});
m_client.setCommandCallback(Network::Command::PlayerInvUpdate, [this](Network::Packet &packet) {

View File

@ -38,7 +38,7 @@ void ClientScene::draw(gk::RenderTarget &target, gk::RenderStates states) const
// Subtract the camera position - see comment in ClientWorld::draw()
gk::Vector3d cameraPosition = m_camera->getDPosition();
states.transform.translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z);
states.transform.translate((float)-cameraPosition.x, (float)-cameraPosition.y, (float)-cameraPosition.z);
for (auto &controller : m_controllers)
controller->draw(m_registry, target, states);

View File

@ -52,7 +52,7 @@ void RenderingController::update(entt::registry &registry) {
void RenderingController::draw(entt::registry &registry, gk::RenderTarget &target, gk::RenderStates states) {
registry.view<DrawableComponent, PositionComponent, RotationComponent>().each([&](auto, auto &drawable, auto &position, auto &rotation) {
gk::Transformable transformable;
transformable.setPosition(position.x, position.y, position.z);
transformable.setPosition((float)position.x, (float)position.y, (float)position.z);
transformable.getRotationTransform().getMatrix() = glm::toMat4(rotation.quat);
gk::RenderStates drawStates = states;

View File

@ -42,7 +42,7 @@ ChatState::ChatState(ClientCommandHandler &clientCommandHandler, Chat &chat, boo
m_drawBackground = false;
m_textInput.setScale(Config::guiScale, Config::guiScale);
m_textInput.setBackgroundColor(gk::Color{0, 0, 0, 127});
m_textInput.setBackgroundColor(gk::Color::fromRGBA32(0, 0, 0, 127));
m_textInput.setPadding(1, 1);
updateWidgetPosition();
@ -102,7 +102,7 @@ void ChatState::onEvent(const SDL_Event &event) {
}
void ChatState::updateWidgetPosition() {
m_textInput.setPosition(4, Config::screenHeight - 12 * Config::guiScale);
m_textInput.setPosition(4.f, float(Config::screenHeight - 12 * Config::guiScale));
m_textInput.setBackgroundSize(Config::screenWidth / Config::guiScale - 4, 10);
}

View File

@ -40,14 +40,14 @@ ConnectionErrorState::ConnectionErrorState(const std::string &error, const std::
m_host = host;
m_port = port;
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_background.setScale(Config::guiScale * 2.f, Config::guiScale * 2.f);
m_filter.setFillColor(gk::Color(0, 0, 0, 192));
m_filter.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 192));
m_text.setString(error);
m_text.setColor(gk::Color::Red);
m_text.updateVertexBuffer();
m_text.setScale(Config::guiScale * 1.5, Config::guiScale * 1.5);
m_text.setScale(Config::guiScale * 1.5f, Config::guiScale * 1.5f);
m_text.setShadowEnabled(false);
m_menuWidget.setScale(Config::guiScale, Config::guiScale);
@ -81,17 +81,17 @@ void ConnectionErrorState::onEvent(const SDL_Event &event) {
}
void ConnectionErrorState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0, 0, u16(Config::screenWidth / m_background.getScale().x), u16(Config::screenHeight / m_background.getScale().y));
m_background.setClipRect(0, 0, u16(Config::screenWidth / m_background.getScale().x), u16(Config::screenHeight / m_background.getScale().y));
m_filter.setSize(Config::screenWidth, Config::screenHeight);
m_text.setPosition(Config::screenWidth / 2 - m_text.getSize().x * Config::guiScale * 1.5 / 2,
Config::screenHeight / 2 - m_text.getSize().y * Config::guiScale * 1.5 / 2);
m_text.setPosition(float(Config::screenWidth / 2 - m_text.getSize().x * Config::guiScale * 1.5 / 2),
float(Config::screenHeight / 2 - m_text.getSize().y * Config::guiScale * 1.5 / 2));
m_menuWidget.setPosition(
Config::screenWidth / 2.0f - m_menuWidget.getGlobalBounds().sizeX / 2,
Config::screenHeight - 110 * Config::guiScale
Config::screenHeight - 110.f * Config::guiScale
);
}

View File

@ -80,7 +80,7 @@ void GameState::onStateInactive() {
m_hud.pause();
}
void GameState::connect(const std::string &host, int port, const std::string &username) {
void GameState::connect(const std::string &host, u16 port, const std::string &username) {
m_player.setName(username.empty() ? "Player" : username);
m_client.connect(host, port, m_player);
m_player.setClientID(m_client.id());
@ -101,9 +101,9 @@ void GameState::onEvent(const SDL_Event &event) {
KeyboardHandler *keyboardHandler = (KeyboardHandler *)gk::GamePad::getInputHandler();
if (event.type == SDL_MOUSEMOTION) {
if(Config::screenWidth / 2.0f != event.motion.x || Config::screenHeight / 2.0f != event.motion.y) {
m_player.turnH(event.motion.xrel * -0.01 * Config::mouseSensitivity);
m_player.turnViewV(event.motion.yrel * -0.01 * Config::mouseSensitivity);
if(Config::screenWidth / 2 != event.motion.x || Config::screenHeight / 2 != event.motion.y) {
m_player.turnH((float)event.motion.xrel * -0.01f * Config::mouseSensitivity);
m_player.turnViewV((float)event.motion.yrel * -0.01f * Config::mouseSensitivity);
gk::Mouse::resetToWindowCenter();
}
@ -155,8 +155,8 @@ void GameState::onEvent(const SDL_Event &event) {
}
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
Config::screenWidth = event.window.data1;
Config::screenHeight = event.window.data2;
Config::screenWidth = (u16)event.window.data1;
Config::screenHeight = (u16)event.window.data2;
m_camera.setAspectRatio((float)Config::screenWidth / Config::screenHeight);
m_hud.setup();

View File

@ -54,7 +54,7 @@ class GameState : public gk::ApplicationState {
void init() override;
void onStateInactive() override;
void connect(const std::string &host, int port, const std::string &username);
void connect(const std::string &host, u16 port, const std::string &username);
void onEvent(const SDL_Event &event) override;

View File

@ -38,7 +38,7 @@ InterfaceState::InterfaceState(gk::ApplicationState *parent) : gk::ApplicationSt
m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/basic.f.glsl");
m_shader.linkProgram();
m_background.setFillColor(gk::Color{0, 0, 0, 127});
m_background.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 127));
setup();
}
@ -62,8 +62,8 @@ void InterfaceState::onEvent(const SDL_Event &event) {
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
if (!m_parent) {
Config::screenWidth = event.window.data1;
Config::screenHeight = event.window.data2;
Config::screenWidth = (u16)event.window.data1;
Config::screenHeight = (u16)event.window.data2;
}
setup();

View File

@ -242,8 +242,8 @@ void LuaGUIState::loadImage(const std::string &, s32 x, s32 y, sf::Packet &packe
gk::Texture &texture = loadTexture(textureFilename);
auto *image = new gk::Image(texture);
image->setPosition(x, y);
image->setClipRect(clipRect.x, clipRect.y, clipRect.sizeX, clipRect.sizeY);
image->setPosition((float)x, (float)y);
image->setClipRect(clipRect.x, clipRect.y, (u16)clipRect.sizeX, (u16)clipRect.sizeY);
m_drawables.emplace_back(image);
}
@ -252,7 +252,7 @@ void LuaGUIState::loadTextButton(const std::string &, s32 x, s32 y, sf::Packet &
packet >> text;
auto *button = new TextButton(&m_mainWidget);
button->setPosition(x, y);
button->setPosition((float)x, (float)y);
// button->setCallback(it.on_click);
button->setText(text);
m_widgets.emplace_back(button);
@ -306,7 +306,7 @@ void LuaGUIState::loadInventoryWidget(const std::string &name, s32 x, s32 y, sf:
m_inventoryWidgets.emplace(name, InventoryWidget{m_client, isReadOnly, &m_mainWidget});
auto &inventoryWidget = m_inventoryWidgets.at(name);
inventoryWidget.setPosition(x, y);
inventoryWidget.setPosition((float)x, (float)y);
inventoryWidget.init(*widgetInventory, offset, count);
inventoryWidget.setShiftDestination(shiftDestination);
inventoryWidget.setFilter(filter);
@ -348,8 +348,8 @@ void LuaGUIState::loadCraftingWidget(const std::string &name, s32 x, s32 y, sf::
auto &craftingWidget = m_craftingWidgets.at(name);
craftingWidget.setShiftDestination(shiftDestination);
craftingWidget.init(offset, size);
craftingWidget.craftingInventoryWidget().setPosition(x, y);
craftingWidget.craftingResultInventoryWidget().setPosition(resultX, resultY);
craftingWidget.craftingInventoryWidget().setPosition((float)x, (float)y);
craftingWidget.craftingResultInventoryWidget().setPosition((float)resultX, (float)resultY);
}
else {
gkError() << "Crafting inventory is invalid";
@ -393,7 +393,7 @@ void LuaGUIState::loadScrollBarWidget(const std::string &, s32 x, s32 y, sf::Pac
gk::Texture &texture = loadTexture(textureFilename);
ScrollBarWidget *scrollBarWidget = new ScrollBarWidget(&m_mainWidget);
scrollBarWidget->setPosition(x, y);
scrollBarWidget->setPosition((float)x, (float)y);
scrollBarWidget->init(texture, clipRect, minY, maxY, m_inventoryWidgets.at(widget));
m_widgets.emplace_back(scrollBarWidget);
@ -406,7 +406,7 @@ void LuaGUIState::loadTextInput(const std::string &name, s32 x, s32 y, sf::Packe
packet >> width >> height >> placeholder >> placeholderColor >> inventory;
TextInput textInput{&m_mainWidget};
textInput.setPosition(x, y);
textInput.setPosition((float)x, (float)y);
textInput.setFocus(false);
textInput.setBackgroundSize(width, height);
textInput.setPlaceholder(placeholder);
@ -434,8 +434,8 @@ gk::Texture &LuaGUIState::loadTexture(const std::string &textureFilename) {
}
void LuaGUIState::centerMainWidget() {
int x = floor(Config::screenWidth / 2.0f - m_width * Config::guiScale / 2.0f + 0.5f);
int y = floor(Config::screenHeight / 2.0f - m_height * Config::guiScale / 2.0f + 0.5f);
float x = floorf(Config::screenWidth / 2.0f - m_width * Config::guiScale / 2.0f + 0.5f);
float y = floorf(Config::screenHeight / 2.0f - m_height * Config::guiScale / 2.0f + 0.5f);
m_mainWidget.setPosition(x, y);
}

View File

@ -33,7 +33,7 @@
ServerConnectState::ServerConnectState(gk::ApplicationState *parent) : InterfaceState(parent) {
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_filter.setFillColor(gk::Color(0, 0, 0, 192));
m_filter.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 192));
m_title.setScale(Config::guiScale, Config::guiScale);
m_title.setString("Play Multiplayer");
@ -119,33 +119,40 @@ void ServerConnectState::update() {
}
void ServerConnectState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_background.setClipRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_filter.setSize(Config::screenWidth, Config::screenHeight);
m_title.setPosition(
Config::screenWidth / 2.0f - m_title.getSize().x * Config::guiScale / 2.0f,
12.5f * Config::guiScale - m_title.getSize().y * Config::guiScale / 2.0f
Config::screenWidth / 2.0f - float(m_title.getSize().x * Config::guiScale) / 2.0f,
12.5f * Config::guiScale - float(m_title.getSize().y * Config::guiScale) / 2.0f
);
m_usernameInput.setPosition(
Config::screenWidth / 2.0f - m_usernameInput.getBackgroundSize().x * Config::guiScale / 2.0f,
Config::screenHeight / 2.0f - m_usernameInput.getBackgroundSize().y * Config::guiScale / 2.0f - 30 * Config::guiScale
Config::screenWidth / 2.0f - float(m_usernameInput.getBackgroundSize().x * Config::guiScale) / 2.0f,
Config::screenHeight / 2.0f - float(m_usernameInput.getBackgroundSize().y * Config::guiScale) / 2.0f - 30 * Config::guiScale
);
m_addressInput.setPosition(
Config::screenWidth / 2.0f - m_addressInput.getBackgroundSize().x * Config::guiScale / 2.0f,
Config::screenHeight / 2.0f - m_addressInput.getBackgroundSize().y * Config::guiScale / 2.0f
Config::screenWidth / 2.0f - float(m_addressInput.getBackgroundSize().x * Config::guiScale) / 2.0f,
Config::screenHeight / 2.0f - float(m_addressInput.getBackgroundSize().y * Config::guiScale) / 2.0f
);
m_menuWidget.setPosition(
Config::screenWidth / 2.0f - m_menuWidget.getGlobalBounds().sizeX / 2,
Config::screenHeight - 0.10 * Config::screenHeight * Config::guiScale
Config::screenWidth / 2.0f - m_menuWidget.getGlobalBounds().sizeX / 2.f,
Config::screenHeight - 0.10f * Config::screenHeight * Config::guiScale
);
m_errorText.setPosition(
Config::screenWidth / 2.0f - m_errorText.getSize().x * Config::guiScale / 2.0f,
Config::screenWidth / 2.0f - float(m_errorText.getSize().x * Config::guiScale) / 2.0f,
Config::screenHeight / 2.0f + 30 * Config::guiScale
);
}

View File

@ -43,7 +43,7 @@ ServerLoadingState::ServerLoadingState(GameState &game, bool showLoadingState, c
{
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_filter.setFillColor(gk::Color(0, 0, 0, 192));
m_filter.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 192));
m_text.setString("Loading world...");
m_text.setColor(gk::Color::White);
@ -116,13 +116,20 @@ void ServerLoadingState::onServerOnlineEvent(const ServerOnlineEvent &event) {
}
void ServerLoadingState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0.f, 0.f,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_background.setClipRect(0.f, 0.f,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_filter.setSize(Config::screenWidth, Config::screenHeight);
m_text.setPosition(Config::screenWidth / 2 - m_text.getSize().x * Config::guiScale * 2 / 2,
Config::screenHeight / 2 - m_text.getSize().y * Config::guiScale * 2 / 2);
m_text.setPosition(Config::screenWidth / 2.f - float(m_text.getSize().x * Config::guiScale) * 2.f / 2.f,
Config::screenHeight / 2.f - float(m_text.getSize().y * Config::guiScale) * 2.f / 2.f);
}
void ServerLoadingState::draw(gk::RenderTarget &target, gk::RenderStates states) const {

View File

@ -46,8 +46,8 @@
SettingsMenuState::SettingsMenuState(gk::ApplicationState *parent) : InterfaceState(parent) {
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_filter1.setFillColor(gk::Color(0, 0, 0, 192));
m_filter2.setFillColor(gk::Color(0, 0, 0, 120));
m_filter1.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 192));
m_filter2.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 120));
m_title.setScale(Config::guiScale, Config::guiScale);
m_title.setString("Options");
@ -113,29 +113,36 @@ void SettingsMenuState::onGuiScaleChanged(const GuiScaleChangedEvent &event) {
}
void SettingsMenuState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_background.setClipRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_filter1.setSize(Config::screenWidth, Config::screenHeight);
const int topBorderSize = 25 * Config::guiScale;
const int bottomBorderSize = 25 * Config::guiScale;
m_filter2.setSize(Config::screenWidth, Config::screenHeight - topBorderSize - bottomBorderSize);
m_filter2.setPosition(0, topBorderSize);
m_filter2.setSize(Config::screenWidth, float(Config::screenHeight - topBorderSize - bottomBorderSize));
m_filter2.setPosition(0, (float)topBorderSize);
m_title.setPosition(
roundf(Config::screenWidth / 2.0f - m_title.getSize().x * Config::guiScale / 2.0f),
roundf(topBorderSize / 2.0f - m_title.getSize().y * Config::guiScale / 2.0f)
roundf(Config::screenWidth / 2.0f - float(m_title.getSize().x * Config::guiScale) / 2.0f),
roundf((float)topBorderSize / 2.0f - float(m_title.getSize().y * Config::guiScale) / 2.0f)
);
m_doneButton.setPosition(
roundf(Config::screenWidth / 2.0f - m_doneButton.getGlobalBounds().sizeX / 2.0f),
roundf(Config::screenHeight - bottomBorderSize / 2.0f - m_doneButton.getGlobalBounds().sizeY / 2.0f)
roundf(Config::screenHeight - (float)bottomBorderSize / 2.0f - m_doneButton.getGlobalBounds().sizeY / 2.0f)
);
m_menuWidget.setPosition(
roundf(Config::screenWidth / 2.0f - m_menuWidget.getGlobalBounds().sizeX / 2.0f),
roundf(topBorderSize + 5.0f * Config::guiScale)
roundf((float)topBorderSize + 5.0f * Config::guiScale)
);
}
@ -191,7 +198,7 @@ void SettingsMenuState::addGameplayButtons() {
addToggleButton("No Clip", Config::isNoClipEnabled, false);
m_menuWidget.addSlider("Max Block Reach: " + std::to_string(Config::maxBlockReach), [] (SliderWidget &slider, u32) {
Config::maxBlockReach = slider.getCurrentValue();
Config::maxBlockReach = (u16)slider.getCurrentValue();
slider.setText("Max Block Reach: " + std::to_string(Config::maxBlockReach));
}, 1, 15, Config::maxBlockReach);
@ -213,7 +220,7 @@ void SettingsMenuState::addGraphicsButtons() {
m_menuWidget.reset(2, 8);
m_menuWidget.addSlider("Render Distance: " + std::to_string(Config::renderDistance), [] (SliderWidget &slider, u32) {
Config::renderDistance = slider.getCurrentValue();
Config::renderDistance = (u16)slider.getCurrentValue();
slider.setText("Render Distance: " + std::to_string(Config::renderDistance));
World::isReloadRequested = true;
}, 4, 16, Config::renderDistance);
@ -234,7 +241,7 @@ void SettingsMenuState::addGraphicsButtons() {
};
m_menuWidget.addButton(std::string("Ambient Occlusion: ") + aoValueNames[Config::ambientOcclusion], [&, aoValueNames] (TextButton &button) {
Config::ambientOcclusion = (Config::ambientOcclusion + 1) % (Config::isSmoothLightingEnabled ? 3 : 2);
Config::ambientOcclusion = u8((Config::ambientOcclusion + 1) % (Config::isSmoothLightingEnabled ? 3 : 2));
button.setText(std::string("Ambient Occlusion: ") + aoValueNames[Config::ambientOcclusion]);
World::isReloadRequested = true;
@ -243,7 +250,7 @@ void SettingsMenuState::addGraphicsButtons() {
m_menuWidget.addSlider("GUI Scale: " + std::to_string(Config::guiScale), [this] (SliderWidget &slider, u32 eventType) {
slider.setText("GUI Scale: " + std::to_string(slider.getCurrentValue()));
if (eventType == SDL_MOUSEBUTTONUP) {
Config::guiScale = slider.getCurrentValue();
Config::guiScale = (u8)slider.getCurrentValue();
m_eventHandler->emplaceEvent<GuiScaleChangedEvent>(Config::guiScale);
}
}, 1, 3, Config::guiScale);
@ -280,35 +287,35 @@ void SettingsMenuState::addGraphicsButtons() {
addToggleButton("Use VSync", Config::isVerticalSyncEnabled, false);
m_menuWidget.addSlider("Mipmap Levels: " + std::to_string(Config::mipmapLevels), [] (SliderWidget &slider, u32) {
Config::mipmapLevels = slider.getCurrentValue();
Config::mipmapLevels = (u8)slider.getCurrentValue();
slider.setText("Mipmap Levels: " + std::to_string(Config::mipmapLevels));
}, 0, 4, Config::mipmapLevels);
addToggleButton("Star Rendering", Config::isStarRenderingEnabled, false);
m_menuWidget.addSlider("FOV: " + std::to_string((int)Config::cameraFOV), [] (SliderWidget &slider, u32) {
Config::cameraFOV = slider.getCurrentValue();
Config::cameraFOV = (float)slider.getCurrentValue();
slider.setText("FOV: " + std::to_string((int)Config::cameraFOV));
}, 45, 135, Config::cameraFOV);
}, 45, 135, (int)Config::cameraFOV);
updateWidgetPosition();
}
void SettingsMenuState::addInputButtons() {
KeyboardHandler *keyboardHandler = dynamic_cast<KeyboardHandler *>(gk::GamePad::getInputHandler());
m_menuWidget.reset(2, keyboardHandler->keyCount() / 2.f + 1.5f);
m_menuWidget.reset(2, u16((float)keyboardHandler->keyCount() / 2.f + 1.5f));
for (auto &it : keyboardHandler->keys()) {
m_menuWidget.addButton(it.second.name() + ": " + keyboardHandler->getKeyName(it.first), [this, it] (TextButton &button) {
button.setText(it.second.name() + ": ");
m_currentKey = it.first;
m_currentKey = (u16)it.first;
m_currentKeyButton = &button;
m_key = const_cast<Key *>(&it.second);
});
}
m_menuWidget.addSlider("Mouse Sensitivity: " + std::to_string(Config::mouseSensitivity), [] (SliderWidget &slider, u32) {
Config::mouseSensitivity = slider.getCurrentValue();
Config::mouseSensitivity = (u8)slider.getCurrentValue();
slider.setText("Mouse Sensitivity: " + std::to_string(Config::mouseSensitivity));
}, 4, 32, Config::mouseSensitivity);

View File

@ -40,8 +40,8 @@ namespace fs = ghc::filesystem;
TexturePackSelectionState::TexturePackSelectionState(gk::ApplicationState *parent) : InterfaceState(parent) {
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_filter1.setFillColor(gk::Color(0, 0, 0, 192));
m_filter2.setFillColor(gk::Color(0, 0, 0, 120));
m_filter1.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 192));
m_filter2.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 120));
m_title.setScale(Config::guiScale, Config::guiScale);
m_title.setString("Select Texture Pack");
@ -97,29 +97,36 @@ void TexturePackSelectionState::onEvent(const SDL_Event &event) {
}
void TexturePackSelectionState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_background.setClipRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_filter1.setSize(Config::screenWidth, Config::screenHeight);
const int topBorderSize = 25 * Config::guiScale;
const int bottomBorderSize = 25 * Config::guiScale;
m_filter2.setSize(Config::screenWidth, Config::screenHeight - topBorderSize - bottomBorderSize);
m_filter2.setPosition(0, topBorderSize);
m_filter2.setSize(Config::screenWidth, float(Config::screenHeight - topBorderSize - bottomBorderSize));
m_filter2.setPosition(0, (float)topBorderSize);
m_title.setPosition(
Config::screenWidth / 2.0f - m_title.getSize().x * Config::guiScale / 2.0f,
topBorderSize / 2.0f - m_title.getSize().y * Config::guiScale / 2.0f
Config::screenWidth / 2.0f - float(m_title.getSize().x * Config::guiScale) / 2.0f,
(float)topBorderSize / 2.0f - float(m_title.getSize().y * Config::guiScale) / 2.0f
);
m_texturePackList.setPosition(
Config::screenWidth / 2.0f - m_texturePackList.getGlobalBounds().sizeX / 2.0f,
topBorderSize + 2.0f * Config::guiScale
(float)topBorderSize + 2.0f * Config::guiScale
);
m_menuWidget.setPosition(
Config::screenWidth / 2.0f - m_menuWidget.getGlobalBounds().sizeX / 2.0f,
Config::screenHeight - bottomBorderSize / 2.0f - m_menuWidget.getGlobalBounds().sizeY / 2.0f
Config::screenHeight - (float)bottomBorderSize / 2.0f - m_menuWidget.getGlobalBounds().sizeY / 2.0f
);
}

View File

@ -168,17 +168,17 @@ void TitleScreenState::updateWidgetPosition() {
);
m_titleText.setPosition(
roundf(Config::screenWidth / 2.0f - m_titleText.getSize().x * m_titleText.getScale().x / 2.0f),
roundf(Config::screenWidth / 2.0f - (float)m_titleText.getSize().x * m_titleText.getScale().x / 2.0f),
roundf(0.04f * Config::screenHeight * Config::guiScale)
);
m_versionText.setPosition(Config::guiScale, Config::screenHeight - m_versionText.getSize().y * Config::guiScale);
m_versionText.setPosition(Config::guiScale, float(Config::screenHeight - m_versionText.getSize().y * Config::guiScale));
m_copyrightText.setPosition(
roundf(Config::screenWidth - m_copyrightText.getSize().x * Config::guiScale - Config::guiScale),
roundf(Config::screenHeight - m_copyrightText.getSize().y * Config::guiScale)
float(Config::screenWidth - m_copyrightText.getSize().x * Config::guiScale - Config::guiScale),
float(Config::screenHeight - m_copyrightText.getSize().y * Config::guiScale)
);
m_licenseText.setPosition(
roundf(Config::screenWidth - m_licenseText.getSize().x * Config::guiScale - Config::guiScale),
roundf(Config::screenHeight - (m_copyrightText.getSize().y + m_licenseText.getSize().y + 2) * Config::guiScale)
float(Config::screenWidth - m_licenseText.getSize().x * Config::guiScale - Config::guiScale),
float(Config::screenHeight - (m_copyrightText.getSize().y + m_licenseText.getSize().y + 2) * Config::guiScale)
);
}

View File

@ -47,7 +47,7 @@ WorldCreationState::WorldCreationState(TitleScreenState *titleScreen, const std:
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_filter.setFillColor(gk::Color(0, 0, 0, 192));
m_filter.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 192));
m_title.setScale(Config::guiScale, Config::guiScale);
m_title.setString(originalName.empty() ? "Create New World" : "Edit World");
@ -148,31 +148,38 @@ void WorldCreationState::update() {
}
void WorldCreationState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_background.setClipRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_filter.setSize(Config::screenWidth, Config::screenHeight);
m_title.setPosition(
Config::screenWidth / 2.0f - m_title.getSize().x * Config::guiScale / 2.0f,
12.5f * Config::guiScale - m_title.getSize().y * Config::guiScale / 2.0f
Config::screenWidth / 2.0f - float(m_title.getSize().x * Config::guiScale) / 2.0f,
12.5f * Config::guiScale - float(m_title.getSize().y * Config::guiScale) / 2.0f
);
if (!m_isEdition) {
m_nameInput.setPosition(
Config::screenWidth / 2.0f - m_nameInput.getBackgroundSize().x * Config::guiScale / 2.0f,
Config::screenHeight / 2.0f - m_nameInput.getBackgroundSize().y * Config::guiScale / 2.0f - 30 * Config::guiScale
Config::screenWidth / 2.0f - float(m_nameInput.getBackgroundSize().x * Config::guiScale) / 2.0f,
Config::screenHeight / 2.0f - float(m_nameInput.getBackgroundSize().y * Config::guiScale) / 2.0f - 30 * Config::guiScale
);
m_seedInput.setPosition(
Config::screenWidth / 2.0f - m_seedInput.getBackgroundSize().x * Config::guiScale / 2.0f,
Config::screenHeight / 2.0f - m_seedInput.getBackgroundSize().y * Config::guiScale / 2.0f
Config::screenWidth / 2.0f - float(m_seedInput.getBackgroundSize().x * Config::guiScale) / 2.0f,
Config::screenHeight / 2.0f - float(m_seedInput.getBackgroundSize().y * Config::guiScale) / 2.0f
);
}
else {
m_nameInput.setPosition(
Config::screenWidth / 2.0f - m_nameInput.getBackgroundSize().x * Config::guiScale / 2.0f,
Config::screenHeight / 2.0f - m_nameInput.getBackgroundSize().y * Config::guiScale / 2.0f
Config::screenWidth / 2.0f - float(m_nameInput.getBackgroundSize().x * Config::guiScale) / 2.0f,
Config::screenHeight / 2.0f - float(m_nameInput.getBackgroundSize().y * Config::guiScale) / 2.0f
);
}
@ -182,7 +189,7 @@ void WorldCreationState::updateWidgetPosition() {
);
m_errorText.setPosition(
Config::screenWidth / 2.0f - m_errorText.getSize().x * Config::guiScale / 2.0f,
Config::screenWidth / 2.0f - float(m_errorText.getSize().x * Config::guiScale) / 2.0f,
Config::screenHeight / 2.0f - 30 * Config::guiScale
);
}

View File

@ -38,7 +38,7 @@ namespace fs = ghc::filesystem;
WorldDeletionState::WorldDeletionState(const std::string &worldName, TitleScreenState *titleScreen) : InterfaceState(titleScreen) {
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_filter.setFillColor(gk::Color(0, 0, 0, 176));
m_filter.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 176));
m_text1.setString("Are you sure you want to delete this world?");
m_text1.updateVertexBuffer();
@ -76,20 +76,27 @@ void WorldDeletionState::onEvent(const SDL_Event &event) {
}
void WorldDeletionState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_background.setClipRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_filter.setSize(Config::screenWidth, Config::screenHeight);
m_text1.setPosition(Config::screenWidth / 2 - m_text1.getSize().x * Config::guiScale / 2,
Config::screenHeight / 2 - 30 * Config::guiScale);
m_text1.setPosition(Config::screenWidth / 2.f - float(m_text1.getSize().x * Config::guiScale) / 2.f,
Config::screenHeight / 2.f - 30.f * Config::guiScale);
m_text2.setPosition(Config::screenWidth / 2 - m_text2.getSize().x * Config::guiScale / 2,
Config::screenHeight / 2 - m_text2.getSize().y * Config::guiScale / 2);
m_text2.setPosition(Config::screenWidth / 2.f - float(m_text2.getSize().x * Config::guiScale) / 2.f,
Config::screenHeight / 2.f - float(m_text2.getSize().y * Config::guiScale) / 2.f);
m_menuWidget.setPosition(
Config::screenWidth / 2.0f - m_menuWidget.getGlobalBounds().sizeX / 2,
Config::screenHeight - 110 * Config::guiScale
Config::screenHeight - 110.f * Config::guiScale
);
}

View File

@ -38,7 +38,7 @@ WorldSavingState::WorldSavingState(Client &client, bool closeClient, gk::Applica
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_filter.setFillColor(gk::Color(0, 0, 0, 192));
m_filter.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 192));
m_text.setString("Saving world...");
m_text.setColor(gk::Color::White);
@ -69,13 +69,20 @@ void WorldSavingState::update() {
}
void WorldSavingState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_background.setClipRect(0, 0,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_filter.setSize(Config::screenWidth, Config::screenHeight);
m_text.setPosition(Config::screenWidth / 2 - m_text.getSize().x * Config::guiScale * 2 / 2,
Config::screenHeight / 2 - m_text.getSize().y * Config::guiScale * 2 / 2);
m_text.setPosition(Config::screenWidth / 2.f - float(m_text.getSize().x * Config::guiScale) * 2.f / 2.f,
Config::screenHeight / 2.f - float(m_text.getSize().y * Config::guiScale) * 2.f / 2.f);
}
void WorldSavingState::draw(gk::RenderTarget &target, gk::RenderStates states) const {

View File

@ -42,8 +42,8 @@ WorldSelectionState::WorldSelectionState(TitleScreenState *titleScreen)
{
m_background.setScale(Config::guiScale * 2, Config::guiScale * 2);
m_filter1.setFillColor(gk::Color(0, 0, 0, 192));
m_filter2.setFillColor(gk::Color(0, 0, 0, 120));
m_filter1.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 192));
m_filter2.setFillColor(gk::Color::fromRGBA32(0, 0, 0, 120));
m_title.setScale(Config::guiScale, Config::guiScale);
m_title.setString("Select World");
@ -116,39 +116,46 @@ void WorldSelectionState::onEvent(const SDL_Event &event) {
}
void WorldSelectionState::updateWidgetPosition() {
m_background.setPosRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setClipRect(0, 0, Config::screenWidth / m_background.getScale().x, Config::screenHeight / m_background.getScale().y);
m_background.setPosRect(0.f, 0.f,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_background.setClipRect(0.f, 0.f,
u16(Config::screenWidth / m_background.getScale().x),
u16(Config::screenHeight / m_background.getScale().y)
);
m_filter1.setSize(Config::screenWidth, Config::screenHeight);
const int topBorderSize = 25 * Config::guiScale;
const int bottomBorderSize = 50 * Config::guiScale;
m_filter2.setSize(Config::screenWidth, Config::screenHeight - topBorderSize - bottomBorderSize);
m_filter2.setPosition(0, topBorderSize);
m_filter2.setSize(Config::screenWidth, float(Config::screenHeight - topBorderSize - bottomBorderSize));
m_filter2.setPosition(0, (float)topBorderSize);
m_title.setPosition(
Config::screenWidth / 2.0f - m_title.getSize().x * Config::guiScale / 2.0f,
topBorderSize / 2.0f - m_title.getSize().y * Config::guiScale / 2.0f
Config::screenWidth / 2.0f - float(m_title.getSize().x * Config::guiScale) / 2.0f,
(float)topBorderSize / 2.0f - float(m_title.getSize().y * Config::guiScale) / 2.0f
);
m_worldList.setPosition(
Config::screenWidth / 2.0f - m_worldList.getGlobalBounds().sizeX / 2.0f,
topBorderSize + 2.0f * Config::guiScale
(float)topBorderSize + 2.0f * Config::guiScale
);
m_menuWidget1.setPosition(
Config::screenWidth / 2.0f - m_menuWidget1.getGlobalBounds().sizeX / 2.0f,
Config::screenHeight - bottomBorderSize / 2.0f - m_menuWidget1.getGlobalBounds().sizeY - 2.0f
Config::screenHeight - (float)bottomBorderSize / 2.0f - m_menuWidget1.getGlobalBounds().sizeY - 2.0f
);
m_menuWidget2.setPosition(
Config::screenWidth / 2.0f - m_menuWidget2.getGlobalBounds().sizeX - 4 * Config::guiScale,
Config::screenHeight - bottomBorderSize / 2.0f + 2 * Config::guiScale
Config::screenHeight - (float)bottomBorderSize / 2.0f + 2.0f * Config::guiScale
);
m_menuWidget3.setPosition(
Config::screenWidth / 2.0f + 4 * Config::guiScale,
Config::screenHeight - bottomBorderSize / 2.0f + 2 * Config::guiScale
Config::screenHeight - (float)bottomBorderSize / 2.0f + 2.0f * Config::guiScale
);
}
@ -169,7 +176,7 @@ void WorldSelectionState::loadSaveList() {
std::string filename = entry.path().filename();
if (filename.substr(filename.find_last_of('.')) == ".dat") {
std::string saveFile = filename.substr(0, filename.find_last_of('.'));
std::string filesize = std::to_string(entry.file_size() / 1000.f / 1000.f);
std::string filesize = std::to_string((float)entry.file_size() / 1000.f / 1000.f);
m_worldList.addElement(saveFile, filesize.substr(0, filesize.find_first_of('.') + 3) + " MB", "");
}
}

View File

@ -102,7 +102,7 @@ inline void ChunkMeshBuilder::addCube(s8f x, s8f y, s8f z, ChunkMeshBuildingJob
const gk::FloatBox &boundingBox = blockState.boundingBox();
u8f orientation = blockState.block().isRotatable()
? blockState.block().param().getParam(BlockParam::Rotation, blockParam) : 0;
? (u8f)blockState.block().param().getParam(BlockParam::Rotation, blockParam) : 0;
const glm::mat3 &orientMatrix = orientMatrices[orientation];
glm::vec3 vertexPos[nVertsPerCube]{
@ -120,9 +120,9 @@ inline void ChunkMeshBuilder::addCube(s8f x, s8f y, s8f z, ChunkMeshBuildingJob
if (blockState.drawType() == BlockDrawType::Cactus) {
// Ignore bounding box, initialize it to full node coordinates
for (u8f i = 0; i < nVertsPerCube; ++i) {
vertexPos[i].x = (i >> 0) & 1;
vertexPos[i].y = (i >> 1) & 1;
vertexPos[i].z = (i >> 2) & 1;
vertexPos[i].x = float((i >> 0) & 1);
vertexPos[i].y = float((i >> 1) & 1);
vertexPos[i].z = float((i >> 2) & 1);
}
}
@ -145,7 +145,7 @@ inline void ChunkMeshBuilder::addCube(s8f x, s8f y, s8f z, ChunkMeshBuildingJob
for (s8f f = 0; f < nFaces ; ++f) {
// Construct the normal vector to a face
const glm::vec3 glmNormal = orientMatrix * faceNormals[f];
const gk::Vector3i normal{int(glmNormal.x), int(glmNormal.y), int(glmNormal.z)};
const gk::Vector3<s8f> normal{s8f(glmNormal.x), s8f(glmNormal.y), s8f(glmNormal.z)};
// Construct an array with the 4 vertex positions of this face
glm::vec3 *faceVerts[nVertsPerFace]{
@ -155,12 +155,12 @@ inline void ChunkMeshBuilder::addCube(s8f x, s8f y, s8f z, ChunkMeshBuildingJob
// Construct an array with the 4 vertex neighbours of this face
// (as GameKit integer vectors)
const gk::Vector3i corner0{int(vNeighbour[cubeVerts[f][0]].x), int(vNeighbour[cubeVerts[f][0]].y), int(vNeighbour[cubeVerts[f][0]].z)};
const gk::Vector3i corner1{int(vNeighbour[cubeVerts[f][1]].x), int(vNeighbour[cubeVerts[f][1]].y), int(vNeighbour[cubeVerts[f][1]].z)};
const gk::Vector3i corner2{int(vNeighbour[cubeVerts[f][2]].x), int(vNeighbour[cubeVerts[f][2]].y), int(vNeighbour[cubeVerts[f][2]].z)};
const gk::Vector3i corner3{int(vNeighbour[cubeVerts[f][3]].x), int(vNeighbour[cubeVerts[f][3]].y), int(vNeighbour[cubeVerts[f][3]].z)};
const gk::Vector3<s8f> corner0{s8f(vNeighbour[cubeVerts[f][0]].x), s8f(vNeighbour[cubeVerts[f][0]].y), s8f(vNeighbour[cubeVerts[f][0]].z)};
const gk::Vector3<s8f> corner1{s8f(vNeighbour[cubeVerts[f][1]].x), s8f(vNeighbour[cubeVerts[f][1]].y), s8f(vNeighbour[cubeVerts[f][1]].z)};
const gk::Vector3<s8f> corner2{s8f(vNeighbour[cubeVerts[f][2]].x), s8f(vNeighbour[cubeVerts[f][2]].y), s8f(vNeighbour[cubeVerts[f][2]].z)};
const gk::Vector3<s8f> corner3{s8f(vNeighbour[cubeVerts[f][3]].x), s8f(vNeighbour[cubeVerts[f][3]].y), s8f(vNeighbour[cubeVerts[f][3]].z)};
const gk::Vector3i *vFaceNeighbours[nVertsPerFace]{&corner0, &corner1, &corner2, &corner3};
const gk::Vector3<s8f> *vFaceNeighbours[nVertsPerFace]{&corner0, &corner1, &corner2, &corner3};
addCubeFace(x, y, z, f, job, blockState, normal, faceVerts, vFaceNeighbours);
}
@ -168,9 +168,9 @@ inline void ChunkMeshBuilder::addCube(s8f x, s8f y, s8f z, ChunkMeshBuildingJob
inline void ChunkMeshBuilder::addCubeFace(s8f x, s8f y, s8f z, s8f f, ChunkMeshBuildingJob &job,
const BlockState &blockState,
const gk::Vector3i &normal,
const gk::Vector3<s8f> &normal,
const glm::vec3 *const vertexPos[nVertsPerFace],
const gk::Vector3i *const neighbourOfs[nVertsPerFace])
const gk::Vector3<s8f> *const neighbourOfs[nVertsPerFace])
{
// Get surrounding block for the face
s8f sx = x + normal.x;
@ -217,9 +217,9 @@ inline void ChunkMeshBuilder::addCubeFace(s8f x, s8f y, s8f z, s8f f, ChunkMeshB
Vertex vertices[nVertsPerFace];
for (s8f v = 0; v < nVertsPerFace; ++v) {
if (blockState.drawType() == BlockDrawType::Cactus) {
vertices[v].coord3d[0] = x + vertexPos[v]->x - boundingBox.x * normal.x;
vertices[v].coord3d[1] = y + vertexPos[v]->y - boundingBox.y * normal.y;
vertices[v].coord3d[2] = z + vertexPos[v]->z - boundingBox.z * normal.z;
vertices[v].coord3d[0] = x + vertexPos[v]->x - boundingBox.x * (float)normal.x;
vertices[v].coord3d[1] = y + vertexPos[v]->y - boundingBox.y * (float)normal.y;
vertices[v].coord3d[2] = z + vertexPos[v]->z - boundingBox.z * (float)normal.z;
}
else {
float blockHeight = vertexPos[v]->z;
@ -241,9 +241,9 @@ inline void ChunkMeshBuilder::addCubeFace(s8f x, s8f y, s8f z, s8f f, ChunkMeshB
vertices[v].coord3d[3] = f;
vertices[v].normal[0] = normal.x;
vertices[v].normal[1] = normal.y;
vertices[v].normal[2] = normal.z;
vertices[v].normal[0] = (float)normal.x;
vertices[v].normal[1] = (float)normal.y;
vertices[v].normal[2] = (float)normal.z;
const gk::Color colorMultiplier = blockState.colorMultiplier();
vertices[v].color[0] = colorMultiplier.r;
@ -253,8 +253,8 @@ inline void ChunkMeshBuilder::addCubeFace(s8f x, s8f y, s8f z, s8f f, ChunkMeshB
float U = (v == 0 || v == 3) ? U0 : U1;
float V = (v >= 2) ? V0 : V1;
vertices[v].texCoord[0] = gk::qlerp(blockTexCoords.x, blockTexCoords.x + blockTexCoords.sizeX, U);
vertices[v].texCoord[1] = gk::qlerp(blockTexCoords.y, blockTexCoords.y + blockTexCoords.sizeY, V);
vertices[v].texCoord[0] = gk::qlerpf(blockTexCoords.x, blockTexCoords.x + blockTexCoords.sizeX, U);
vertices[v].texCoord[1] = gk::qlerpf(blockTexCoords.y, blockTexCoords.y + blockTexCoords.sizeY, V);
if (Config::isSmoothLightingEnabled)
vertices[v].lightValue[0] = getLightForVertex(Light::Sun, x, y, z, *neighbourOfs[v], normal, job.chunkData);
@ -370,11 +370,11 @@ inline void ChunkMeshBuilder::addCross(s8f x, s8f y, s8f z, ChunkMeshBuildingJob
}
// Based on this article: https://0fps.net/2013/07/03/ambient-occlusion-for-minecraft-like-worlds/
inline u8 ChunkMeshBuilder::getAmbientOcclusion(s8f x, s8f y, s8f z, const gk::Vector3i &offset, const gk::Vector3i &normal, const ChunkData &chunk) {
gk::Vector3i minOffset{
(normal.x != 0) ? offset.x : 0,
(normal.y != 0) ? offset.y : 0,
(normal.z != 0) ? offset.z : 0
inline u8 ChunkMeshBuilder::getAmbientOcclusion(s8f x, s8f y, s8f z, const gk::Vector3<s8f> &offset, const gk::Vector3<s8f> &normal, const ChunkData &chunk) {
gk::Vector3<s8f> minOffset{
s8f((normal.x != 0) ? offset.x : 0),
s8f((normal.y != 0) ? offset.y : 0),
s8f((normal.z != 0) ? offset.z : 0)
};
const BlockState *blocks[4] = {
@ -395,24 +395,24 @@ inline u8 ChunkMeshBuilder::getAmbientOcclusion(s8f x, s8f y, s8f z, const gk::V
bool side2 = blockPresence[(minOffset.z != 0) ? 2 : 0];
bool corner = blockPresence[3];
return (side1 && side2) ? 0 : 3 - (side1 + side2 + corner);
return u8((side1 && side2) ? 0 : 3 - (side1 + side2 + corner));
}
inline u8 ChunkMeshBuilder::getLightForVertex(Light light, s8f x, s8f y, s8f z, const gk::Vector3i &offset, const gk::Vector3i &normal, const ChunkData &chunk) {
gk::Vector3i minOffset{
(normal.x != 0) ? offset.x : 0,
(normal.y != 0) ? offset.y : 0,
(normal.z != 0) ? offset.z : 0
inline u8 ChunkMeshBuilder::getLightForVertex(Light light, s8f x, s8f y, s8f z, const gk::Vector3<s8f> &offset, const gk::Vector3<s8f> &normal, const ChunkData &chunk) {
gk::Vector3<s8f> minOffset{
(normal.x != 0) ? offset.x : s8f(0),
(normal.y != 0) ? offset.y : s8f(0),
(normal.z != 0) ? offset.z : s8f(0)
};
gk::Vector3i surroundingBlocks[4]{
{x + minOffset.x, y + minOffset.y, z + offset.z},
{x + offset.x, y + minOffset.y, z + minOffset.z},
{x + minOffset.x, y + offset.y, z + minOffset.z},
{x + offset.x, y + offset.y, z + offset.z}
gk::Vector3<s8f> surroundingBlocks[4]{
{s8f(x + minOffset.x), s8f(y + minOffset.y), s8f(z + offset.z)},
{s8f(x + offset.x), s8f(y + minOffset.y), s8f(z + minOffset.z)},
{s8f(x + minOffset.x), s8f(y + offset.y), s8f(z + minOffset.z)},
{s8f(x + offset.x), s8f(y + offset.y), s8f(z + offset.z)}
};
auto getLight = [&](const ChunkData &chunk, s8 x, s8 y, s8 z) -> s8 {
auto getLight = [&](const ChunkData &chunk, s8f x, s8f y, s8f z) -> s8 {
return (light == Light::Sun) ? chunk.getSunlight(x, y, z) : chunk.getTorchlight(x, y, z);
};
@ -439,7 +439,7 @@ inline u8 ChunkMeshBuilder::getLightForVertex(Light light, s8f x, s8f y, s8f z,
}
if (count)
return total / count;
return u8(total / count);
else
return 0;
}

View File

@ -56,11 +56,11 @@ struct ChunkData {
}
u16 getBlockID(s8f x, s8f y, s8f z) const {
return data[z + 1][y + 1][x + 1] & 0xffff;
return u16(data[z + 1][y + 1][x + 1] & 0xffff);
}
u16 getBlockParam(s8f x, s8f y, s8f z) const {
return (data[z + 1][y + 1][x + 1] >> 16) & 0xffff;
return u16((data[z + 1][y + 1][x + 1] >> 16) & 0xffff);
}
s8 getTorchlight(s8f x, s8f y, s8f z) const {
@ -115,19 +115,19 @@ class ChunkMeshBuilder {
static void addCube(s8f x, s8f y, s8f z, ChunkMeshBuildingJob &job, const BlockState &blockState, u16 blockParam);
static void addCubeFace(s8f x, s8f y, s8f z, s8f f, ChunkMeshBuildingJob &job,
const BlockState &blockState,
const gk::Vector3i &normal, const glm::vec3 *const vertexPos[4],
const gk::Vector3i *const neighbourOfs[4]);
const gk::Vector3<s8f> &normal, const glm::vec3 *const vertexPos[4],
const gk::Vector3<s8f> *const neighbourOfs[4]);
enum class Light {
Sun,
Torch
};
static u8 getAmbientOcclusion(s8f x, s8f y, s8f z, const gk::Vector3i &offset,
const gk::Vector3i &normal, const ChunkData &chunk);
static u8 getAmbientOcclusion(s8f x, s8f y, s8f z, const gk::Vector3<s8f> &offset,
const gk::Vector3<s8f> &normal, const ChunkData &chunk);
static u8 getLightForVertex(Light light, s8f x, s8f y, s8f z, const gk::Vector3i &offset,
const gk::Vector3i &normal, const ChunkData &chunk);
static u8 getLightForVertex(Light light, s8f x, s8f y, s8f z, const gk::Vector3<s8f> &offset,
const gk::Vector3<s8f> &normal, const ChunkData &chunk);
ClientWorld &m_world;

View File

@ -88,7 +88,7 @@ void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u
glCheck(glEnable(GL_DEPTH_TEST));
if(Config::isWireframeModeEnabled) glCheck(glPolygonMode(GL_FRONT_AND_BACK, GL_LINE));
target.draw(m_vbo.at(layer), GL_TRIANGLES, 0, m_verticesCount.at(layer), states);
target.draw(m_vbo.at(layer), GL_TRIANGLES, 0, (GLsizei)m_verticesCount.at(layer), states);
if(Config::isWireframeModeEnabled) glCheck(glPolygonMode(GL_FRONT_AND_BACK, GL_FILL));
}

View File

@ -61,12 +61,12 @@ void ClientPlayer::turnViewV(float angle) {
}
void ClientPlayer::updateCamera() {
float ch = cosf(m_viewAngleH * RADIANS_PER_DEGREES);
float sh = sinf(m_viewAngleH * RADIANS_PER_DEGREES);
float cv = cosf(m_viewAngleV * RADIANS_PER_DEGREES);
float sv = sinf(m_viewAngleV * RADIANS_PER_DEGREES);
float cr = cosf(m_viewAngleRoll * RADIANS_PER_DEGREES);
float sr = sinf(m_viewAngleRoll * RADIANS_PER_DEGREES);
float ch = cosf(m_viewAngleH * gk::DEG_TO_RADf);
float sh = sinf(m_viewAngleH * gk::DEG_TO_RADf);
float cv = cosf(m_viewAngleV * gk::DEG_TO_RADf);
float sv = sinf(m_viewAngleV * gk::DEG_TO_RADf);
float cr = cosf(m_viewAngleRoll * gk::DEG_TO_RADf);
float sr = sinf(m_viewAngleRoll * gk::DEG_TO_RADf);
m_forwardDir = gk::Vector3f{ch * cv, sh * cv, sv};
m_camera.setDirection(m_forwardDir);
@ -76,8 +76,8 @@ void ClientPlayer::updateCamera() {
void ClientPlayer::move(float direction) {
direction += m_viewAngleH;
m_velocity.x = 0.04f * cosf(direction * RADIANS_PER_DEGREES);
m_velocity.y = 0.04f * sinf(direction * RADIANS_PER_DEGREES);
m_velocity.x = 0.04f * cosf(direction * gk::DEG_TO_RADf);
m_velocity.y = 0.04f * sinf(direction * gk::DEG_TO_RADf);
}
void ClientPlayer::processInputs() {
@ -87,11 +87,11 @@ void ClientPlayer::processInputs() {
}
if(gk::GamePad::isKeyPressed(GameKey::Fly)) {
m_velocity.z = 0.1;
m_velocity.z = 0.1f;
}
if(gk::GamePad::isKeyPressed(GameKey::Sneak)) {
m_velocity.z = -0.1;
m_velocity.z = -0.1f;
}
if(gk::GamePad::isKeyPressed(GameKey::Forward)) move(0.0f);
@ -112,7 +112,7 @@ void ClientPlayer::processInputs() {
}
void ClientPlayer::updatePosition(const ClientWorld &world) {
ClientChunk *chunk = (ClientChunk *)world.getChunkAtBlockPos(m_x, m_y, m_z);
ClientChunk *chunk = (ClientChunk *)world.getChunkAtBlockPos((int)m_x, (int)m_y, (int)m_z);
if (chunk && chunk->isInitialized()) {
if (!Config::isFlyModeEnabled) {
m_velocity.z -= chunk->dimension().gravity() * 0.001f;
@ -145,7 +145,7 @@ void ClientPlayer::updatePosition(const ClientWorld &world) {
m_velocity.z = 0.f;
// Checking to block at camera position to enable specific effects
const BlockState *blockState = world.getBlockState(m_camera.getDPosition().x, m_camera.getDPosition().y, m_camera.getDPosition().z);
const BlockState *blockState = world.getBlockState((int)m_camera.getDPosition().x, (int)m_camera.getDPosition().y, (int)m_camera.getDPosition().z);
if (blockState && blockState->fogDepth() != 0) {
GameConfig::currentScreenEffect = 1;
GameConfig::fogDepth = blockState->fogDepth();
@ -188,7 +188,7 @@ void ClientPlayer::checkCollisions(const ClientWorld &world) {
}
bool passable(const ClientWorld &world, double x, double y, double z) {
const BlockState *blockState = world.getBlockState(floor(x), floor(y), floor(z));
const BlockState *blockState = world.getBlockState((int)floor(x), (int)floor(y), (int)floor(z));
return !blockState || !blockState->block().id() || !blockState->isCollidable();
}

View File

@ -35,14 +35,6 @@
#include "Player.hpp"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef RADIANS_PER_DEGREES
#define RADIANS_PER_DEGREES (M_PI / 180.0f)
#endif
class ClientWorld;
class ClientPlayer : public Player {

View File

@ -93,9 +93,9 @@ void ClientWorld::requestChunkMeshing() {
}
void ClientWorld::checkPlayerChunk(double playerX, double playerY, double playerZ) {
int pcx = std::floor(playerX / CHUNK_WIDTH);
int pcy = std::floor(playerY / CHUNK_DEPTH);
int pcz = std::floor(playerZ / CHUNK_HEIGHT);
int pcx = (int)std::floor(playerX / CHUNK_WIDTH);
int pcy = (int)std::floor(playerY / CHUNK_DEPTH);
int pcz = (int)std::floor(playerZ / CHUNK_HEIGHT);
ClientChunk *chunk = (ClientChunk *)getChunk(pcx, pcy, pcz);
if (!chunk) {
@ -137,9 +137,9 @@ void ClientWorld::receiveChunkData(Network::Packet &packet) {
// Receive chunk data
// bool hasUpdatedChunk = false;
for (u16 z = 0 ; z < CHUNK_HEIGHT ; ++z) {
for (u16 y = 0 ; y < CHUNK_DEPTH ; ++y) {
for (u16 x = 0 ; x < CHUNK_WIDTH ; ++x) {
for (u8 z = 0 ; z < CHUNK_HEIGHT ; ++z) {
for (u8 y = 0 ; y < CHUNK_DEPTH ; ++y) {
for (u8 x = 0 ; x < CHUNK_WIDTH ; ++x) {
u32 block;
u8 light;
@ -300,8 +300,8 @@ void ClientWorld::draw(gk::RenderTarget &target, gk::RenderStates states) const
* glm::vec4(CHUNK_WIDTH / 2, CHUNK_DEPTH / 2, CHUNK_HEIGHT / 2, 1);
// Nope, too far, don't render it
if(glm::length(center) > (Config::renderDistance + 1) * CHUNK_WIDTH) {
if(floor(glm::length(center)) > (Config::renderDistance + 2) * CHUNK_WIDTH) {
if(glm::length(center) > (Config::renderDistance + 1.f) * CHUNK_WIDTH) {
if(floor(glm::length(center)) > (Config::renderDistance + 2.f) * CHUNK_WIDTH) {
it.second->setTooFar(true);
if (!it.second->isInitialized())

View File

@ -30,7 +30,7 @@
#include <gk/graphics/Color.hpp>
namespace Color {
const gk::Color Blue{32, 168, 248};
const gk::Color Blue = gk::Color::fromRGBA32(32, 168, 248);
}
#endif // COLOR_HPP_

View File

@ -64,9 +64,9 @@ void GameTime::updateTpsCounter() {
tpsStart = s_ticks;
u64 currentClockTicks = gk::GameClock::getInstance().getTicks(true);
u32 elapsed = currentClockTicks - tpsTimer;
u32 elapsed = u32(currentClockTicks - tpsTimer);
if (elapsed >= 1000) {
s_ticksPerSecond = ((s_ticks - tpsStart) * 1000 + elapsed / 2) / elapsed;
s_ticksPerSecond = u16(((s_ticks - tpsStart) * 1000 + elapsed / 2) / elapsed);
tpsTimer = currentClockTicks;
tpsStart = s_ticks;
}

View File

@ -49,15 +49,15 @@ class GameTime {
static u64 getTicks() { return s_ticks; }
static u32 getCurrentDay() {
return (s_ticks + dayStartOffset + 6000) / dayLength + 1;
return u32((s_ticks + dayStartOffset + 6000) / dayLength + 1);
}
static u8 getCurrentHour() {
return ((s_ticks + dayStartOffset + 6000) / 1000) % 24;
return u8(((s_ticks + dayStartOffset + 6000) / 1000) % 24);
}
static u8 getCurrentMinute() {
return ((s_ticks + dayStartOffset + 6000) % 1000) * 60 / 1000;
return u8(((s_ticks + dayStartOffset + 6000) % 1000) * 60 / 1000);
}
private:

View File

@ -85,7 +85,7 @@ Biome &Registry::registerSerializedBiome(sf::Packet &packet) {
}
Dimension &Registry::registerDimension(const std::string &stringID, const std::string &label) {
u16 id = m_dimensions.size();
size_t id = m_dimensions.size();
m_dimensionsID.emplace(stringID, id);
m_dimensions.emplace_back(id, stringID, label);
return m_dimensions.back();
@ -95,14 +95,14 @@ Dimension &Registry::registerSerializedDimension(sf::Packet &packet) {
m_dimensions.emplace_back();
m_dimensions.back().deserialize(packet);
u16 id = m_dimensions.size() - 1;
size_t id = m_dimensions.size() - 1;
m_dimensionsID.emplace(m_dimensions.back().stringID(), id);
return m_dimensions.back();
}
Key &Registry::registerKey(const std::string &stringID, const std::string &label) {
u16 id = GameKey::KeyCount + m_keys.size();
size_t id = GameKey::KeyCount + m_keys.size();
m_keysID.emplace(stringID, id);
m_keys.emplace_back(id, stringID, label);
return m_keys.back();
@ -112,7 +112,7 @@ Key &Registry::registerSerializedKey(sf::Packet &packet) {
m_keys.emplace_back();
m_keys.back().deserialize(packet);
u16 id = GameKey::KeyCount + m_keys.size() - 1;
size_t id = GameKey::KeyCount + m_keys.size() - 1;
m_keysID.emplace(m_biomes.back().stringID(), id);
return m_keys.back();

View File

@ -48,7 +48,7 @@ class Registry : public gk::ISerializable {
public:
template<typename T>
auto registerBlock(const std::string &stringID) -> typename std::enable_if<std::is_base_of<Block, T>::value, T&>::type {
u32 id = m_blocks.size();
size_t id = m_blocks.size();
m_blocksID.emplace(stringID, id);
m_blocks.emplace_back(std::make_unique<T>(id, stringID));
return *static_cast<T*>(m_blocks.back().get());
@ -59,7 +59,7 @@ class Registry : public gk::ISerializable {
m_blocks.emplace_back(std::make_unique<T>());
m_blocks.back()->deserialize(packet);
u32 id = m_blocks.size() - 1;
size_t id = m_blocks.size() - 1;
m_blocksID.emplace(m_blocks.back()->stringID(), id);
return *static_cast<T*>(m_blocks.back().get());
@ -67,7 +67,7 @@ class Registry : public gk::ISerializable {
template<typename T>
auto registerItem(const TilesDef &tiles, const std::string &stringID, const std::string &label) -> typename std::enable_if<std::is_base_of<Item, T>::value, T&>::type {
u32 id = m_items.size();
size_t id = m_items.size();
m_itemsID.emplace(stringID, id);
m_items.emplace_back(std::make_unique<T>(id, tiles, stringID, label));
return *static_cast<T*>(m_items.back().get());
@ -78,7 +78,7 @@ class Registry : public gk::ISerializable {
m_items.emplace_back(std::make_unique<T>());
m_items.back()->deserialize(packet);
u32 id = m_items.size() - 1;
size_t id = m_items.size() - 1;
m_itemsID.emplace(m_items.back()->stringID(), id);
return *static_cast<T*>(m_items.back().get());
@ -157,8 +157,8 @@ class Registry : public gk::ISerializable {
std::vector<Dimension> m_dimensions;
std::vector<Key> m_keys;
std::unordered_map<std::string, u32> m_blocksID;
std::unordered_map<std::string, u32> m_itemsID;
std::unordered_map<std::string, u16> m_blocksID;
std::unordered_map<std::string, u16> m_itemsID;
std::unordered_map<std::string, u16> m_skiesID;
std::unordered_map<std::string, u16> m_treesID;
std::unordered_map<std::string, u16> m_biomesID;

View File

@ -30,7 +30,7 @@
#include "TilesDef.hpp"
const std::string &TilesDef::getTextureForFace(u8 face) const {
u8 size = m_textureFilenames.size();
u8 size = (u8)m_textureFilenames.size();
if (size == 0)
throw EXCEPTION("For object '" + m_objectID + "' in state " + std::to_string(m_stateID) + ": Trying to get texture from empty tiles definition");

View File

@ -32,7 +32,7 @@
struct ServerOnlineEvent {
bool isOnline;
int port;
u16 port;
};
// Client-only events

View File

@ -93,7 +93,7 @@ bool CraftingRecipe::isMatching(const Inventory &inventory) const {
return false;
}
bool CraftingRecipe::checkMatch(const Inventory &inventory, int offsetX, int offsetY) const {
bool CraftingRecipe::checkMatch(const Inventory &inventory, u16 offsetX, u16 offsetY) const {
bool itemFound = false;
u16 y = 0;
for (y = 0 ; y < m_pattern.size() ; ++y) {
@ -120,7 +120,7 @@ bool CraftingRecipe::checkMatch(const Inventory &inventory, int offsetX, int off
return false;
}
for (int x = offsetX - 1 ; x >= 0 ; --x) {
for (u16 x = 0 ; x < offsetX ; ++x) {
if (inventory.getStack(x, offsetY + y).item().id())
return false;
}
@ -132,15 +132,15 @@ bool CraftingRecipe::checkMatch(const Inventory &inventory, int offsetX, int off
}
}
for (int y = offsetY - 1 ; y >= 0 ; --y) {
for (int x = 0 ; x < inventory.width() ; ++x) {
for (u16 y = 0 ; y < offsetY ; ++y) {
for (u16 x = 0 ; x < inventory.width() ; ++x) {
if (inventory.getStack(x, y).item().id())
return false;
}
}
while (offsetY + y < inventory.height()) {
for (int x = 0 ; x < inventory.width() ; ++x) {
for (u16 x = 0 ; x < inventory.width() ; ++x) {
if (inventory.getStack(x, offsetY + y).item().id())
return false;
}

View File

@ -43,7 +43,7 @@ class CraftingRecipe : public Recipe {
bool isMatching(const Inventory &inventory) const override;
private:
bool checkMatch(const Inventory &inventory, int offsetX, int offsetY) const;
bool checkMatch(const Inventory &inventory, u16 offsetX, u16 offsetY) const;
std::vector<std::string> m_pattern;
std::map<char, std::vector<std::string>> m_keys;

View File

@ -27,7 +27,7 @@
#include "Item.hpp"
#include "NetworkUtils.hpp"
Item::Item(u32 id, const TilesDef &tiles, const std::string &stringID, const std::string &label) {
Item::Item(u16 id, const TilesDef &tiles, const std::string &stringID, const std::string &label) {
m_id = id;
m_tiles = tiles;

View File

@ -38,7 +38,7 @@
class Item : public gk::ISerializable {
public:
Item() = default;
Item(u32 id, const TilesDef &tiles, const std::string &stringID, const std::string &label);
Item(u16 id, const TilesDef &tiles, const std::string &stringID, const std::string &label);
void serialize(sf::Packet &packet) const override;
void deserialize(sf::Packet &packet) override;
@ -48,7 +48,7 @@ class Item : public gk::ISerializable {
std::string modName() const { return m_stringID.substr(0, m_stringID.find_first_of(":")); }
u32 id() const { return m_id; }
u16 id() const { return m_id; }
const TilesDef &tiles() const { return m_tiles; }
bool isBlock() const { return m_isBlock; }
@ -87,7 +87,7 @@ class Item : public gk::ISerializable {
bool m_canBeActivated = false;
private:
u32 m_id = 0;
u16 m_id = 0;
TilesDef m_tiles;
std::string m_stringID;

View File

@ -77,7 +77,7 @@ void CompressedPacket::onReceive(const void* data, std::size_t size) {
// Extract the uncompressed data size from the first two
// bytes in the packet so we can use it for the buffer
sf::Uint16 uncompressedSize = srcData[1] << 8 | srcData[0];
sf::Uint16 uncompressedSize = sf::Uint16(srcData[1] << 8 | srcData[0]);
// Resize the vector to accomodate the uncompressed data
m_compressionBuffer.resize(uncompressedSize);

View File

@ -36,6 +36,8 @@
static bool areComponentsRegistered = false;
using namespace entt::literals;
Scene::Scene() {
if (!areComponentsRegistered) {
registerComponents();
@ -57,7 +59,7 @@ entt::entity Scene::createEntityFromModel(entt::registry &modelRegistry, entt::e
auto other = m_registry.create();
modelRegistry.visit(modelEntity, [&](const auto &component) {
const auto type = entt::resolve_type(component);
const auto type = entt::resolve(component);
const auto any = type.func("get"_hs).invoke({}, std::ref(modelRegistry), modelEntity);
type.func("set"_hs).invoke({}, std::ref(m_registry), other, any);
});

View File

@ -29,7 +29,7 @@
#include "Player.hpp"
#include "World.hpp"
Block::Block(u32 id, const std::string &stringID) {
Block::Block(u16 id, const std::string &stringID) {
m_id = id;
m_stringID = stringID;
@ -48,17 +48,15 @@ const TilesDef &Block::tiles(u16 stateID) const {
}
void Block::serialize(sf::Packet &packet) const {
packet << u32(m_id) << m_stringID << m_canUpdate << m_canBeActivated
packet << m_id << m_stringID << m_canUpdate << m_canBeActivated
<< m_isRotatable << m_groups << m_states << m_param << m_customParamBits
<< m_placementConstraints;
}
void Block::deserialize(sf::Packet &packet) {
u32 id;
packet >> id >> m_stringID >> m_canUpdate >> m_canBeActivated
packet >> m_id >> m_stringID >> m_canUpdate >> m_canBeActivated
>> m_isRotatable >> m_groups >> m_states >> m_param >> m_customParamBits
>> m_placementConstraints;
m_id = id;
for (auto &it : m_states) {
it.setBlock(this);

View File

@ -51,7 +51,7 @@ class World;
class Block : public gk::ISerializable {
public:
Block() = default;
Block(u32 id, const std::string &stringID);
Block(u16 id, const std::string &stringID);
virtual ~Block() = default;
void serialize(sf::Packet &packet) const override;

View File

@ -31,7 +31,7 @@
#include "Inventory.hpp"
struct BlockData {
BlockData(const gk::Vector3i &pos, int width, int height) : inventory(width, height) {
BlockData(const gk::Vector3i &pos, u16 width, u16 height) : inventory(width, height) {
inventory.setInBlock(true);
inventory.setBlockPos(pos);
}

View File

@ -68,7 +68,7 @@ u16 BlockParam::getParam(u8 type, u16 data) const {
return 0;
}
return (data >> it->second.offset) & ~(~0u << it->second.size);
return u16((data >> it->second.offset) & ~(~0u << it->second.size));
}
u16 BlockParam::setParam(u8 type, u16 data, u16 param) const {
@ -79,12 +79,12 @@ u16 BlockParam::setParam(u8 type, u16 data, u16 param) const {
return 0;
}
u16 mask = ~(~0u << it->second.size) << it->second.offset;
u16 mask = u16(~(~0u << it->second.size) << it->second.offset);
param <<= it->second.offset;
if ((param & ~mask) != 0)
gkWarning() << "Block param overflow for type" << getTypeName(type) << "in block" << m_block->stringID();
return (data & ~mask) | (param & mask);
return u16((data & ~mask) | (param & mask));
}
std::string BlockParam::getTypeName(u8 type) {

View File

@ -94,9 +94,9 @@ class BlockState : public gk::ISerializable {
float timeToBreak(u8 harvestCapability, float miningSpeed, bool isEffective) const {
if (isEffective || (harvestRequirements() & harvestCapability) || (harvestCapability == 0 && harvestRequirements() == 0))
return 1.5 * m_hardness / miningSpeed;
return 1.5f * m_hardness / miningSpeed;
else
return 5 * m_hardness;
return 5.f * m_hardness;
}
ItemStack getItemDrop() const { return {m_itemDrop, m_itemDropAmount}; }

View File

@ -68,7 +68,7 @@ u16 Chunk::getData(int x, int y, int z) const {
if(y >= Chunk::depth) return m_surroundingChunks[3] ? m_surroundingChunks[3]->getData(x, y - Chunk::depth, z) : 0;
if(z < 0) return m_surroundingChunks[4] ? m_surroundingChunks[4]->getData(x, y, z + Chunk::height) : 0;
if(z >= Chunk::height) return m_surroundingChunks[5] ? m_surroundingChunks[5]->getData(x, y, z - Chunk::height) : 0;
return (m_data[z][y][x] >> 16) & 0xffff;
return u16((m_data[z][y][x] >> 16) & 0xffff);
}
void Chunk::setBlock(int x, int y, int z, u16 type) {
@ -213,7 +213,7 @@ BlockData *Chunk::getBlockData(int x, int y, int z) const {
return it->second.get();
}
BlockData *Chunk::addBlockData(int x, int y, int z, int inventoryWidth, int inventoryHeight) {
BlockData *Chunk::addBlockData(int x, int y, int z, u16 inventoryWidth, u16 inventoryHeight) {
if(x < 0) return m_surroundingChunks[0] ? m_surroundingChunks[0]->addBlockData(x + CHUNK_WIDTH, y, z) : 0;
if(x >= CHUNK_WIDTH) return m_surroundingChunks[1] ? m_surroundingChunks[1]->addBlockData(x - CHUNK_WIDTH, y, z) : 0;
if(y < 0) return m_surroundingChunks[2] ? m_surroundingChunks[2]->addBlockData(x, y + CHUNK_DEPTH, z) : 0;

View File

@ -77,7 +77,7 @@ class Chunk : public gk::NonCopyable {
virtual void onBlockDestroyed(int, int, int, const Block &) {}
BlockData *getBlockData(int x, int y, int z) const;
BlockData *addBlockData(int x, int y, int z, int inventoryWidth = 0, int inventoryHeight = 0);
BlockData *addBlockData(int x, int y, int z, u16 inventoryWidth = 0, u16 inventoryHeight = 0);
s32 x() const { return m_x; }
s32 y() const { return m_y; }

View File

@ -37,7 +37,7 @@ ChunkLightmap::ChunkLightmap(Chunk *chunk) : m_chunk(chunk) {
std::memset(m_lightMap, 0, sizeof(m_lightMap));
}
bool ChunkLightmap::addTorchlight(int x, int y, int z, int val) {
bool ChunkLightmap::addTorchlight(int x, int y, int z, u8 val) {
if(x < 0) return m_chunk->getSurroundingChunk(0) ? m_chunk->getSurroundingChunk(0)->lightmap().addTorchlight(x + CHUNK_WIDTH, y, z, val) : false;
if(x >= CHUNK_WIDTH) return m_chunk->getSurroundingChunk(1) ? m_chunk->getSurroundingChunk(1)->lightmap().addTorchlight(x - CHUNK_WIDTH, y, z, val) : false;
if(y < 0) return m_chunk->getSurroundingChunk(2) ? m_chunk->getSurroundingChunk(2)->lightmap().addTorchlight(x, y + CHUNK_DEPTH, z, val) : false;
@ -51,7 +51,7 @@ bool ChunkLightmap::addTorchlight(int x, int y, int z, int val) {
return true;
}
bool ChunkLightmap::addSunlight(int x, int y, int z, int val) {
bool ChunkLightmap::addSunlight(int x, int y, int z, u8 val) {
if(x < 0) return m_chunk->getSurroundingChunk(0) ? m_chunk->getSurroundingChunk(0)->lightmap().addSunlight(x + CHUNK_WIDTH, y, z, val) : false;
if(x >= CHUNK_WIDTH) return m_chunk->getSurroundingChunk(1) ? m_chunk->getSurroundingChunk(1)->lightmap().addSunlight(x - CHUNK_WIDTH, y, z, val) : false;
if(y < 0) return m_chunk->getSurroundingChunk(2) ? m_chunk->getSurroundingChunk(2)->lightmap().addSunlight(x, y + CHUNK_DEPTH, z, val) : false;
@ -289,7 +289,7 @@ bool ChunkLightmap::setSunlight(int x, int y, int z, u8 val) {
if ((m_lightMap[z][y][x] & 0xf0) == ((val << 4) & 0xf0)) return false;
m_lightMap[z][y][x] = (m_lightMap[z][y][x] & 0xf) | ((val << 4) & 0xf0);
m_lightMap[z][y][x] = u8((m_lightMap[z][y][x] & 0xf) | ((val << 4) & 0xf0));
m_hasChanged = true;
m_chunk->world().addChunkToUpdate(m_chunk);

View File

@ -55,8 +55,8 @@ class ChunkLightmap {
public:
ChunkLightmap(Chunk *chunk);
bool addTorchlight(int x, int y, int z, int val);
bool addSunlight(int x, int y, int z, int val);
bool addTorchlight(int x, int y, int z, u8 val);
bool addSunlight(int x, int y, int z, u8 val);
bool removeTorchlight(int x, int y, int z);
bool removeSunlight(int x, int y, int z);

View File

@ -34,7 +34,7 @@ void HeightmapChunk::generate() {
double n2 = m_heightmap.noise2.GetNoise(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
double n3 = m_heightmap.noise3.GetNoise(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
double n4 = m_heightmap.noise4.GetNoise(x + m_x * CHUNK_WIDTH, y + m_y * CHUNK_DEPTH);
m_map[x + y * CHUNK_WIDTH] = (n1 + (n2 * n3 * (n4 * 2 - 1))) * 64 + 64;
m_map[x + y * CHUNK_WIDTH] = s32((n1 + (n2 * n3 * (n4 * 2 - 1))) * 64 + 64);
}
}
}
@ -89,8 +89,8 @@ int Heightmap::getHighestBlockAt(s32 blockX, s32 blockY) {
s32 chunkY = (blockY & -CHUNK_DEPTH) / CHUNK_DEPTH;
s32 blockZ = getOrCreateChunk(chunkX, chunkY).landHeightAt(
gk::pmod(blockX, CHUNK_WIDTH),
gk::pmod(blockY, CHUNK_DEPTH)
s8(gk::pmod(blockX, CHUNK_WIDTH)),
s8(gk::pmod(blockY, CHUNK_DEPTH))
);
return blockZ;

View File

@ -56,7 +56,7 @@ struct Ore : public gk::ISerializable {
u16 blockID;
double probability;
double size;
u16 size;
u8 genType;
void serialize(sf::Packet &packet) const override {

View File

@ -65,7 +65,7 @@ BlockData *World::getBlockData(int x, int y, int z) const {
return nullptr;
}
BlockData *World::addBlockData(int x, int y, int z, int inventoryWidth, int inventoryHeight) const {
BlockData *World::addBlockData(int x, int y, int z, u16 inventoryWidth, u16 inventoryHeight) const {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
if (chunk)
return chunk->addBlockData(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1), inventoryWidth, inventoryHeight);

View File

@ -42,7 +42,7 @@ class World {
Chunk *getChunkAtBlockPos(int x, int y, int z) const;
BlockData *getBlockData(int x, int y, int z) const;
BlockData *addBlockData(int x, int y, int z, int inventoryWidth = 0, int inventoryHeight = 0) const;
BlockData *addBlockData(int x, int y, int z, u16 inventoryWidth = 0, u16 inventoryHeight = 0) const;
const BlockState *getBlockState(int x, int y, int z) const;
void setBlockState(int x, int y, int z, u16 stateID);

View File

@ -62,7 +62,7 @@ ServerApplication::ServerApplication(gk::EventHandler &eventHandler) {
}
bool ServerApplication::init() {
std::srand(std::time(nullptr));
std::srand((unsigned int)std::time(nullptr));
gk::LoggerHandler::setInstance(m_loggerHandler);
m_loggerHandler.setName("server");
@ -93,7 +93,7 @@ bool ServerApplication::init() {
}
if (m_argumentParser.getArgument("port").isFound)
m_port = std::stoi(m_argumentParser.getArgument("port").parameter);
m_port = (u16)std::stoi(m_argumentParser.getArgument("port").parameter);
if (m_argumentParser.getArgument("world").isFound)
m_worldName = m_argumentParser.getArgument("world").parameter;
@ -155,7 +155,7 @@ int ServerApplication::run(bool isProtected) {
}
catch(const gk::Exception &e) {
if (m_eventHandler)
m_eventHandler->emplaceEvent<ServerOnlineEvent>(false, 0);
m_eventHandler->emplaceEvent<ServerOnlineEvent>(false, (u16)0);
gkError() << "Fatal error" << e.what();

View File

@ -101,7 +101,7 @@ bool ServerConfig::assignOption(const std::string &name, const std::string &valu
auto it = options.find(name);
if (it != options.end()) {
try {
sol::object object = lua.load("return " + value)();
sol::object object = lua.load("return " + value)().get<sol::object>();
if (object.valid()
&& (object.get_type() == sol::type::boolean
|| object.get_type() == sol::type::number

View File

@ -54,7 +54,7 @@ void CraftingWidgetDef::loadFromLuaTable(const sol::table &table) {
}
void CraftingWidgetDef::loadInventory(const sol::table &table) {
sol::object inventoryObject = table["inventory"];
sol::object inventoryObject = table["inventory"].get<sol::object>();
if (inventoryObject.valid() && inventoryObject.get_type() == sol::type::table) {
sol::table inventoryTable = inventoryObject.as<sol::table>();

Some files were not shown because too many files have changed in this diff Show More