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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/client/Typer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct TypingCharacter {

class Typer {
private:
float scale = 0.3;
float scale = 1.0f;
Shader shader;
std::map<GLchar, TypingCharacter> Characters;
unsigned int VAO, VBO;
Expand Down
1 change: 0 additions & 1 deletion include/client/menus/Menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Menu {
int menuWidth = 0;
int menuHeight = 0;
float menuScale = 0;
float textScale = 1.0f;

Typer textRenderer;
Typer titleRenderer;
Expand Down
2 changes: 1 addition & 1 deletion src/client/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void App::init(const std::string& serverIp) {
audio.reset();
}

glfwSetFramebufferSizeCallback(window, [](GLFWwindow* w, const int width, const int height) {
glfwSetFramebufferSizeCallback(window, [](GLFWwindow* w, int width, int height) {
App* app = static_cast<App*>(glfwGetWindowUserPointer(w));
// Skip resize if window is minimized (0x0)
if (width == 0 || height == 0)
Expand Down
20 changes: 12 additions & 8 deletions src/client/menus/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

Chat::Chat(float width, float height) : Menu(width, height)
{
DESIGN_WIDTH = 3840;
DESIGN_HEIGHT = 2160;
build();
chatColor = glm::vec4(0,0,0,0.6f);

resize(width, height);
}

Chat::~Chat()
Expand Down Expand Up @@ -45,12 +49,12 @@ void Chat::goThroughChatLog(const int key)
void Chat::onRender()
{
drawSimpleQuad(x, y, w, h, chatColor);
float offset = 10.0f * menuScale;
float charHeight = (48+10)*textScale*menuScale; //48 cause font is 48 and 10 is height offset
float offset = 10.0f * textRenderer.getScale();
float charHeight = 48 * textRenderer.getScale();

textRenderer.renderText(currMsg, x + offset, y + offset, glm::vec3(0.5, 0.8f, 0.2f));

int currHeight = offset + charHeight;
float currHeight = offset + charHeight;
for (auto it = chatLog.rbegin(); it != chatLog.rend() && currHeight < (h - charHeight); ++it)
{
textRenderer.renderText(it->message.c_str(), x+offset, y+currHeight, glm::vec3(1.0f));
Expand All @@ -64,9 +68,9 @@ void Chat::renderRecentMessages()
auto nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(timepoint.time_since_epoch()).count();
auto nowS = std::chrono::duration_cast<std::chrono::seconds>(timepoint.time_since_epoch()).count();

float offset = 10.0f * menuScale;
float charHeight = (48+10)*textScale; //48 cause font is 48 and 10 is height offset
int currHeight = offset + charHeight;
float offset = 10.0f * textRenderer.getScale();
float charHeight = 48 * textRenderer.getScale();
float currHeight = offset + charHeight;

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Expand All @@ -82,12 +86,12 @@ void Chat::renderRecentMessages()
std::clamp(1.0 - age / (MESSAGE_LIFETIME * 1000), 0.0, 1.0)
);

drawSimpleQuad(x + offset, y + (currHeight - 4) * menuScale, textRenderer.getPixelSizeOfString(msg->message) + 2, charHeight, glm::vec4(0,0,0,alpha/2.0f));
drawSimpleQuad(x + offset, y + currHeight - offset / 2.0f - 4, textRenderer.getPixelSizeOfString(msg->message) + 2, charHeight, glm::vec4(0,0,0,alpha/2.0f));

textRenderer.renderText(
msg->message.c_str(),
x + offset,
y + currHeight * menuScale,
y + currHeight,
glm::vec3(1.0f),
alpha
);
Expand Down
15 changes: 10 additions & 5 deletions src/client/menus/DebugHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
DebugHUD::DebugHUD(float width, float height)
: Menu(width, height)
{
DESIGN_WIDTH = 3840;
DESIGN_HEIGHT = 2160;
build();

resize(width, height);
}

void DebugHUD::update(const DebugStats& stats)
Expand All @@ -19,20 +23,21 @@ void DebugHUD::build()

void DebugHUD::onRender()
{
const float pad = 8.0f * menuScale;
const float lineH = 18.0f * menuScale * textScale * 3;
const float bgPadX = 2.0f * menuScale; // horizontal inset inside each bg
float scale = textRenderer.getScale() * 2.5f;
const float pad = 8.0f * scale;
const float lineH = 18.0f * scale;
const float bgPadX = 2.0f * scale; // horizontal inset inside each bg
const glm::vec4 bgColor{ 0.0f, 0.0f, 0.0f, 0.0f };
const glm::vec3 white{ 1.0f, 1.0f, 1.0f };

const float textX = pad;
float textY = static_cast<float>(fullscreenHeight) - pad - 4.0f * menuScale * textScale * 5;
float textY = static_cast<float>(fullscreenHeight) - pad - 8.0f * scale;

char buf[64];

auto drawLine = [&](const char* text) {
float w = static_cast<float>(textRenderer.getPixelSizeOfString(text));
drawSimpleQuad(textX - bgPadX, textY - 3.0f * menuScale, w + bgPadX * 2.0f, lineH - 2.0f * menuScale, bgColor);
drawSimpleQuad(textX - bgPadX, textY - 3.0f * scale, w + bgPadX * 2.0f, lineH - 2.0f * scale, bgColor);
textRenderer.renderText(text, textX, textY, white);
textY -= lineH;
};
Expand Down
3 changes: 1 addition & 2 deletions src/client/menus/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,10 @@ void Menu::resize(float width, float height)
float scale = std::min(scaleX, scaleY);

menuScale = scale;

this->menuWidth = DESIGN_WIDTH * scale;
this->menuHeight = DESIGN_HEIGHT * scale;

textRenderer.setScale(textScale * scale);
textRenderer.setScale(scale);

build();
}
Expand Down
13 changes: 9 additions & 4 deletions src/client/menus/PlayerListHUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ glm::vec3 PlayerListHUD::idToColor(uint32_t id)
PlayerListHUD::PlayerListHUD(float width, float height)
: Menu(width, height)
{
DESIGN_WIDTH = 3840;
DESIGN_HEIGHT = 2160;
build();

resize(width, height);
}

void PlayerListHUD::update(const std::vector<PlayerEntry>& players)
Expand All @@ -44,11 +48,12 @@ void PlayerListHUD::onRender()
{
if (m_players.empty()) return;

const float s = menuScale;
const float panelW = 300.0f * s * textScale * 3;
float scale = textRenderer.getScale() * 2.5f;
const float s = scale;
const float panelW = 300.0f * s;
const float padX = 10.0f * s;
const float padY = 8.0f * s * textScale * 3;
const float lineH = 20.0f * s * textScale * 3;
const float padY = 8.0f * s;
const float lineH = 20.0f * s;
const float iconSize = 12.0f * s;
const float topGap = 10.0f * s;

Expand Down
11 changes: 8 additions & 3 deletions src/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,14 @@
std::istringstream iss(pkt.message.substr(strlen("tp ")));
float x, y, z;
if (iss >> x >> y >> z) {
player->movement->setPosition(glm::vec3(x, y, z));
player->movement->setVelocity(glm::vec3(0.0f));
player->movement->accumulatedFallDistance = 0.0f;
if (abs(x) < 100000000 && abs(y) < 100000000 && abs(z) < 2000)

Check failure on line 773 in src/server/Server.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=ldominiq_ft_minecraft&issues=AZ6NncuEaGUIhYcu-udV&open=AZ6NncuEaGUIhYcu-udV&pullRequest=110
{
player->movement->setPosition(glm::vec3(x, y, z));
player->movement->setVelocity(glm::vec3(0.0f));
player->movement->accumulatedFallDistance = 0.0f;
}
else
player->targetedMessages.push_back("You can't tp that far!");

Check warning on line 780 in src/server/Server.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this use of "push_back" with "emplace_back".

See more on https://sonarcloud.io/project/issues?id=ldominiq_ft_minecraft&issues=AZ6NncuEaGUIhYcu-udW&open=AZ6NncuEaGUIhYcu-udW&pullRequest=110
} else {
player->targetedMessages.push_back("[server] Usage: /tp <x> <y> <z>");
}
Expand Down
Loading