Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Mar 5, 2021
1 parent a44555e commit 8999b4a
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 40 deletions.
31 changes: 16 additions & 15 deletions src/vpg/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <fstream>
#include <iostream>
#include <cstring>

using namespace vpg;

Expand All @@ -13,7 +14,7 @@ bool Config::load(int argc, char** argv) {

// Parse variables from command-line arguments
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "-c") == 0) {
if (strcmp(argv[i], "-c") == 0) {
if (i + 1 >= argc) {
std::cerr << "vpg::Config::load() failed:" << std::endl;
std::cerr << "Command-line arguments parsing failed:" << std::endl;
Expand Down Expand Up @@ -113,11 +114,11 @@ bool Config::load(int argc, char** argv) {
}
}

bool vpg::Config::get_boolean(const std::string& key, bool default) {
bool vpg::Config::get_boolean(const std::string& key, bool def) {
std::lock_guard guard(Config::mutex);

if (Config::variables.find(key) == Config::variables.end()) {
Config::variables[key] = std::to_string(default);
Config::variables[key] = std::to_string(def);
}

if (Config::variables[key] == "true") {
Expand All @@ -127,48 +128,48 @@ bool vpg::Config::get_boolean(const std::string& key, bool default) {
return false;
}
else {
Config::variables[key] = default ? "true" : "false";
return default;
Config::variables[key] = def ? "true" : "false";
return def;
}
}

int64_t Config::get_integer(const std::string& key, int64_t default) {
int64_t Config::get_integer(const std::string& key, int64_t def) {
std::lock_guard guard(Config::mutex);

if (Config::variables.find(key) == Config::variables.end()) {
Config::variables[key] = std::to_string(default);
Config::variables[key] = std::to_string(def);
}

try {
return std::stoll(Config::variables[key]);
}
catch (...) {
Config::variables[key] = std::to_string(default);
return default;
Config::variables[key] = std::to_string(def);
return def;
}
}

double Config::get_float(const std::string& key, double default) {
double Config::get_float(const std::string& key, double def) {
std::lock_guard guard(Config::mutex);

if (Config::variables.find(key) == Config::variables.end()) {
Config::variables[key] = std::to_string(default);
Config::variables[key] = std::to_string(def);
}

try {
return std::stod(Config::variables[key]);
}
catch (...) {
Config::variables[key] = std::to_string(default);
return default;
Config::variables[key] = std::to_string(def);
return def;
}
}

std::string Config::get_string(const std::string& key, const std::string& default) {
std::string Config::get_string(const std::string& key, const std::string& def) {
std::lock_guard guard(Config::mutex);

if (Config::variables.find(key) == Config::variables.end()) {
Config::variables[key] = default;
Config::variables[key] = def;
}

return Config::variables[key];
Expand Down
10 changes: 5 additions & 5 deletions src/vpg/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace vpg {

static bool load(int argc, char** argv);

static bool get_boolean(const std::string& key, bool default);
static int64_t get_integer(const std::string& key, int64_t default);
static double get_float(const std::string& key, double default);
static std::string get_string(const std::string& key, const std::string& default);
static bool get_boolean(const std::string& key, bool def);
static int64_t get_integer(const std::string& key, int64_t def);
static double get_float(const std::string& key, double def);
static std::string get_string(const std::string& key, const std::string& def);

static void set_boolean(const std::string& key, bool value);
static void set_integer(const std::string& key, int64_t value);
Expand All @@ -26,4 +26,4 @@ namespace vpg {
static std::mutex mutex;
static std::map<std::string, std::string> variables;
};
}
}
1 change: 1 addition & 0 deletions src/vpg/data/asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Asset::Asset(
this->is_dynamic = is_dynamic;
this->load_fn = load_fn;
this->unload_fn = unload_fn;
this->ref_count = 0;
this->data = nullptr;
}

Expand Down
10 changes: 5 additions & 5 deletions src/vpg/ecs/behaviour.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace vpg::ecs {
template<typename T>
inline void Behaviour::register_type() {
static_assert(std::is_base_of<IBehaviour, T>::value);
static_assert(std::is_base_of<IBehaviour::Info, T::Info>::value);
static_assert(std::is_base_of<IBehaviour::Info, typename T::Info>::value);

if (Behaviour::constructors.find(T::TypeName) != Behaviour::constructors.end()) {
std::cerr << "vpg::ecs::Behaviour::register_type() failed:\n"
Expand All @@ -81,11 +81,11 @@ namespace vpg::ecs {
}

Behaviour::info_constructors.emplace(T::TypeName, []() -> IBehaviour::Info* {
return new T::Info();
return new typename T::Info();
});

Behaviour::constructors.emplace(T::TypeName, [](Entity entity, const IBehaviour::Info* create_info) -> IBehaviour* {
return new T(entity, *((const T::Info*)create_info));
return new T(entity, *((const typename T::Info*)create_info));
});
}

Expand All @@ -97,10 +97,10 @@ namespace vpg::ecs {
};

template<typename T>
inline static Behaviour::Info Behaviour::Info::create(typename T::Info&& info) {
inline Behaviour::Info Behaviour::Info::create(typename T::Info&& info) {
Info ret;
ret.info = new typename T::Info(std::move(info));
ret.name = T::TypeName;
return std::move(ret);
}
}
}
4 changes: 2 additions & 2 deletions src/vpg/ecs/coordinator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace vpg::ecs {
}

template<typename T>
inline static T& Coordinator::add_component(Entity entity, const typename T::Info& create_info) {
inline T& Coordinator::add_component(Entity entity, const typename T::Info& create_info) {
auto& ret = Coordinator::component_manager->add_component<T>(entity, create_info);
auto signature = Coordinator::entity_manager->get_signature(entity);
signature.set(Coordinator::component_manager->get_component_type<T>(), true);
Expand Down Expand Up @@ -90,4 +90,4 @@ namespace vpg::ecs {
inline T* Coordinator::register_system(TArgs ... args) {
return Coordinator::system_manager->register_system<T>(args...);
}
}
}
1 change: 1 addition & 0 deletions src/vpg/ecs/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Transform::Transform(Entity entity, const Info& create_info) {
this->parent = NullEntity;
this->child = NullEntity;
this->next = NullEntity;
this->dirty = true;
this->set_parent(create_info.parent);
this->set_position(create_info.position);
this->set_scale(create_info.scale);
Expand Down
9 changes: 6 additions & 3 deletions src/vpg/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <vpg/physics/collider.hpp>

#include <glm/glm.hpp>
#include <gl/glew.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include <iostream>
Expand Down Expand Up @@ -82,7 +82,10 @@ void APIENTRY gl_debug_output(
int main(int argc, char** argv) {
Config::load(argc, argv);

input::Window::init();
if (!input::Window::init()) {
std::cerr << "vpg::input::Window::init() failed:\n";
return 0;
}

// Initialize GLEW
GLenum glew_status = glewInit();
Expand Down Expand Up @@ -182,4 +185,4 @@ int main(int argc, char** argv) {
input::Window::terminate();

return 0;
}
}
3 changes: 2 additions & 1 deletion src/vpg/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <functional>
#include <unordered_map>
#include <cstdint>

namespace vpg {
using Listener = uint32_t;
Expand Down Expand Up @@ -38,4 +39,4 @@ namespace vpg {
l.second(args...);
}
}
}
}
1 change: 1 addition & 0 deletions src/vpg/gl/index_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vpg/gl/usage.hpp>

#include <cstdint>
#include <cstddef>

namespace vpg::gl {
class IndexBuffer final {
Expand Down
2 changes: 1 addition & 1 deletion src/vpg/gl/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool vpg::gl::matrix_to_mesh(
dv[v] = h;

auto vi = vertices.size();
vertices.resize(vi + 4, { offset, back_face ? -q : q, unsigned char(mask[n] - 1) });
vertices.resize(vi + 4, { offset, back_face ? -q : q, (unsigned char)(mask[n] - 1) });
vertices[vi + 0].pos += glm::vec3(x);
vertices[vi + 1].pos += glm::vec3(x + du);
vertices[vi + 2].pos += glm::vec3(x + du + dv);
Expand Down
2 changes: 1 addition & 1 deletion src/vpg/gl/palette.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <vpg/gl/palette.hpp>

#include <gl/glew.h>
#include <GL/glew.h>
#include <cstring>

using namespace vpg::gl;
Expand Down
3 changes: 2 additions & 1 deletion src/vpg/gl/palette.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <glm/glm.hpp>
#include <initializer_list>

namespace vpg::gl {
// struct Material {
Expand Down Expand Up @@ -35,4 +36,4 @@ namespace vpg::gl {
Material* mats;
unsigned int ubo;
};
}
}
2 changes: 1 addition & 1 deletion src/vpg/gl/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <vpg/ecs/transform.hpp>
#include <vpg/gl/debug.hpp>

#include <gl/glew.h>
#include <GL/glew.h>
#include <random>

#define LIGHT_COUNT 64
Expand Down
4 changes: 1 addition & 3 deletions src/vpg/gl/vertex_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace vpg::gl {
~Attribute() = default;

private:
friend class VertexArray;
friend class VertexArray;

const VertexBuffer& buffer;
size_t stride;
Expand All @@ -54,8 +54,6 @@ namespace vpg::gl {
void bind() const;

private:
friend class VertexArray;

VertexArray(unsigned int vao);

unsigned int vao;
Expand Down
1 change: 1 addition & 0 deletions src/vpg/memory/pool.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <vpg/memory/pool.hpp>

#include <cstring>
#include <cstdlib>

using namespace vpg::memory;

Expand Down
3 changes: 2 additions & 1 deletion src/vpg/memory/std_stream_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vpg/memory/stream_buffer.hpp>

#include <cstdio>
#include <cstddef>

namespace vpg::memory {
class STDStreamBuffer : public StreamBuffer {
Expand All @@ -15,4 +16,4 @@ namespace vpg::memory {
private:
FILE* file;
};
}
}
4 changes: 3 additions & 1 deletion src/vpg/memory/stream_buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <cstddef>

namespace vpg::memory {
class StreamBuffer {
public:
Expand All @@ -11,4 +13,4 @@ namespace vpg::memory {
virtual size_t write(const void* data, size_t size) = 0;
virtual size_t read(void* data, size_t size) = 0;
};
}
}

0 comments on commit 8999b4a

Please sign in to comment.