Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
uis246 committed Nov 27, 2020
1 parent edfefd1 commit 2fafbef
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 28 deletions.
4 changes: 1 addition & 3 deletions src/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ Component RecurParseComponent(json j) {
}

Chat::Chat(const std::string &json) {
static const size_t s = sizeof(Component);
nlohmann::json j = nlohmann::json::parse(json);
volatile size_t f = s + 1;
component = RecurParseComponent(j);
}

Expand All @@ -105,7 +103,7 @@ void RecurPlainTextAppend(const Component& component, std::string& str) {
str += "<";
RecurPlainTextAppend(component.with[0], str);
str += "> ";
for (int i = 1; i < component.with.size(); i++)
for (size_t i = 1; i < component.with.size(); i++)
RecurPlainTextAppend(component.with[i], str);
} else {
str += component.translate;
Expand Down
4 changes: 2 additions & 2 deletions src/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct Entity {
double pitch = 0;
double width = 1.0;
double height = 1.0;
glm::vec3 renderColor;
glm::vec3 renderColor = glm::vec3(0, 0, 1);
int entityType=0;
EntityType type;
bool isSolid = true;
Expand All @@ -154,4 +154,4 @@ struct Entity {

Entity CreateObject(ObjectType type);

Entity CreateMob(MobType type);
Entity CreateMob(MobType type);
12 changes: 6 additions & 6 deletions src/Event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ class Event {
std::shared_ptr<EventDataBase> data;

public:
const size_t id;
mutable size_t id;

template<typename T>
Event(size_t eventId, const T &value) :
id(eventId),
data(std::make_shared<EventData<T>>(value)) {}
data(std::make_shared<EventData<T>>(value)),
id(eventId) {}

~Event() = default;

Event(const Event &other) = default;

Event &operator=(const Event &) = default;
Event& operator=(const Event &) = default;

Event(Event &&) = delete;

Event &operator=(Event &&) = delete;
Event& operator=(Event &&) = delete;

template<typename T>
const T& get() const {
Expand Down Expand Up @@ -124,4 +124,4 @@ class EventSystem {

#define PUSH_EVENT(eventName, data) EventSystem::PushEvent(StrHash(eventName),data) //; LOG(INFO)<<"PUSH_EVENT "<<eventName;

#define DIRECT_EVENT_CALL(eventName,data) EventSystem::DirectEventCall(StrHash(eventName),data) //; LOG(INFO)<<"DIRECT_CALL "<<eventName;
#define DIRECT_EVENT_CALL(eventName,data) EventSystem::DirectEventCall(StrHash(eventName),data) //; LOG(INFO)<<"DIRECT_CALL "<<eventName;
2 changes: 2 additions & 0 deletions src/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ void GameState::UpdatePacket(std::shared_ptr<PacketCB> ptr) {
case JoinGame: {
auto packet = std::static_pointer_cast<PacketJoinGame>(ptr);
Entity entity;
//FIXME: player should be handled separately
entity.type = EntityType::Mob;
entity.entityId = packet->EntityId;
entity.width = 0.6;
entity.height = 1.8;
Expand Down
9 changes: 4 additions & 5 deletions src/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <imgui.h>
#include <easylogging++.h>
#include <optick.h>

#include "imgui_impl_sdl_gl3.h"
#include "Shader.hpp"
Expand Down Expand Up @@ -88,8 +87,8 @@ Render::~Render() {
void Render::InitSdl(unsigned int WinWidth, unsigned int WinHeight, std::string WinTitle) {
LOG(INFO) << "Creating window: " << WinWidth << "x" << WinHeight << " \"" << WinTitle << "\"";

if (SDL_Init(SDL_INIT_VIDEO) < 0)
throw std::runtime_error("SDL initalization failed: " + std::string(SDL_GetError()));
if (SDL_Init(SDL_INIT_VIDEO) < 0)
throw std::runtime_error("SDL initalization failed: " + std::string(SDL_GetError()));

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
Expand Down Expand Up @@ -437,8 +436,8 @@ void Render::RenderGui() {
"Player health: %.1f/%.1f",
GetGameState()->GetPlayerStatus().health, 20.0f);

ImGui::Text(
"Selected block: %d %d %d : %.1f",
ImGui::Text(//NOTE: shold be selected block uint64?
"Selected block: %lld %lld %lld : %.1f",
selectionStatus.selectedBlock.x,
selectionStatus.selectedBlock.y,
selectionStatus.selectedBlock.z,
Expand Down
11 changes: 4 additions & 7 deletions src/RendererWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <optick.h>

#include "DebugInfo.hpp"
#include "Frustum.hpp"
Expand Down Expand Up @@ -315,7 +314,7 @@ RendererWorld::~RendererWorld() {
}
LOG(INFO) << "Total faces to render: " << faces;
isRunning = false;
for (int i = 0; i < numOfWorkers; i++)
for (size_t i = 0; i < numOfWorkers; i++)
workers[i].join();
DebugInfo::renderSections = 0;
DebugInfo::readyRenderer = 0;
Expand Down Expand Up @@ -359,7 +358,7 @@ void RendererWorld::Render(RenderState & renderState) {
entityShader->Activate();
entityShader->SetUniform("projection", projection);
entityShader->SetUniform("view", view);
glCheckError();
glCheckError();

renderState.SetActiveVao(RendererEntity::GetVao());
for (auto& it : entities) {
Expand All @@ -378,9 +377,9 @@ void RendererWorld::Render(RenderState & renderState) {
model = glm::scale(model,glm::vec3(1.01f,1.01f,1.01f));
entityShader->SetUniform("model", model);
entityShader->SetUniform("color", glm::vec3(0, 0, 0));
glCheckError();
glDrawArrays(GL_LINES, 0, 24);
}
glCheckError();
}

//Render raycast hit
Expand All @@ -397,13 +396,12 @@ void RendererWorld::Render(RenderState & renderState) {
entityShader->SetUniform("color", glm::vec3(0.7f, 0, 0));
else
entityShader->SetUniform("color", glm::vec3(0, 0, 0.7f));
glCheckError();
glDrawArrays(GL_LINE_STRIP, 0, 36);
}
glCheckError();
}

glLineWidth(1.0);
glCheckError();

//Render sky
renderState.TimeOfDay = GetGameState()->GetTimeStatus().timeOfDay;
Expand Down Expand Up @@ -491,7 +489,6 @@ void RendererWorld::Render(RenderState & renderState) {
section.second.Render();
renderedFaces += section.second.numOfFaces;
}
glCheckError();
glBindVertexArray(0);
this->culledSections = culledSections;
DebugInfo::renderFaces.store(renderedFaces, std::memory_order_relaxed);
Expand Down
2 changes: 1 addition & 1 deletion src/TextureAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TextureAtlas::TextureAtlas(std::vector<TextureData> &textures) {
int invY = textureCoords[i].pixelH - y - 1;
unsigned char *src = textures[i].data.data() + y * bytesPerLine;
unsigned char *dst = textures[i].data.data() + invY * bytesPerLine;
for (int j = 0; j < bytesPerLine; j++) {
for (size_t j = 0; j < bytesPerLine; j++) {
std::swap(*(src + j), *(dst + j));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Utility.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "Utility.hpp"
#include "Platform.hpp"

#include <thread>

#include <optick.h>
#include <easylogging++.h>

//NOTE: use glCheckError only in debugging
GLenum glCheckError_(const char *file, int line) {
OPTICK_EVENT();
GLenum errorCode;
Expand Down Expand Up @@ -32,8 +33,7 @@ GLenum glCheckError_(const char *file, int line) {
case GL_INVALID_FRAMEBUFFER_OPERATION:
error = "INVALID_FRAMEBUFFER_OPERATION";
break;
}
static int t = 0;
}
LOG(ERROR) << "OpenGL error: " << error << " at " << file << ":" << line;
}
return errorCode;
Expand Down
1 change: 0 additions & 1 deletion src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <bitset>
#include <glm/glm.hpp>
#include <optick.h>

#include "Event.hpp"
#include "DebugInfo.hpp"
Expand Down

0 comments on commit 2fafbef

Please sign in to comment.