Squash improve-ide-compat into main

Fixes GH-5

- cppcheck replaced with clang-tidy
- clang-tidy lint warnings fixed
- Reworked build tools from scratch to make IDE setup easier
- Added 1.5 IDE setup guides
This commit is contained in:
2023-11-10 21:30:55 +01:00
parent 189d19fd4a
commit ae4e265a90
66 changed files with 2017 additions and 1498 deletions

View File

@ -1,6 +1,6 @@
#pragma once
#include "boost/core/noncopyable.hpp"
#include "../util.h"
#include <vector>
#define GLM_FORCE_RADIANS
@ -12,8 +12,7 @@
#include "image.h"
namespace progressia {
namespace main {
namespace progressia::main {
struct Vertex {
@ -25,31 +24,27 @@ struct Vertex {
glm::vec2 texCoord;
};
class Texture : private boost::noncopyable {
public:
using Backend = void *;
class Texture : private progressia::main::NonCopyable {
private:
Backend backend;
struct Backend;
std::unique_ptr<Backend> backend;
friend class GraphicsInterface;
friend class Primitive;
public:
Texture(Backend);
Texture(std::unique_ptr<Backend>);
~Texture();
};
class Primitive : private boost::noncopyable {
public:
using Backend = void *;
class Primitive : private progressia::main::NonCopyable {
private:
Backend backend;
struct Backend;
std::unique_ptr<Backend> backend;
friend class GraphicsInterface;
public:
Primitive(Backend);
Primitive(std::unique_ptr<Backend>);
~Primitive();
void draw();
@ -57,30 +52,28 @@ class Primitive : private boost::noncopyable {
const Texture *getTexture() const;
};
class View : private boost::noncopyable {
public:
using Backend = void *;
class View : private progressia::main::NonCopyable {
private:
Backend backend;
struct Backend;
std::unique_ptr<Backend> backend;
friend class GraphicsInterface;
public:
View(Backend);
View(std::unique_ptr<Backend>);
~View();
void configure(const glm::mat4 &proj, const glm::mat4 &view);
void use();
};
class Light : private boost::noncopyable {
public:
using Backend = void *;
class Light : private progressia::main::NonCopyable {
private:
Backend backend;
struct Backend;
std::unique_ptr<Backend> backend;
friend class GraphicsInterface;
public:
Light(Backend);
Light(std::unique_ptr<Backend>);
~Light();
void configure(const glm::vec3 &color, const glm::vec3 &from,
@ -88,7 +81,7 @@ class Light : private boost::noncopyable {
void use();
};
class GraphicsInterface : private boost::noncopyable {
class GraphicsInterface : private progressia::main::NonCopyable {
public:
using Backend = void *;
@ -99,18 +92,18 @@ class GraphicsInterface : private boost::noncopyable {
GraphicsInterface(Backend);
~GraphicsInterface();
Texture *newTexture(const Image &);
std::unique_ptr<Texture> newTexture(const Image &);
Primitive *newPrimitive(const std::vector<Vertex> &,
const std::vector<Vertex::Index> &,
Texture *texture);
std::unique_ptr<Primitive> newPrimitive(const std::vector<Vertex> &,
const std::vector<Vertex::Index> &,
Texture *texture);
glm::vec2 getViewport() const;
void setModelTransform(const glm::mat4 &);
View *newView();
Light *newLight();
std::unique_ptr<View> newView();
std::unique_ptr<Light> newLight();
void flush();
void startNextLayer();
@ -119,5 +112,4 @@ class GraphicsInterface : private boost::noncopyable {
uint64_t getLastStartedFrame();
};
} // namespace main
} // namespace progressia
} // namespace progressia::main

View File

@ -4,15 +4,17 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <limits>
#include <vector>
#include "stb/stb_image.h"
#include <embedded_resources.h>
#include "../logging.h"
using namespace progressia::main::logging;
namespace progressia {
namespace main {
namespace progressia::main {
std::size_t Image::getSize() const { return data.size(); }
@ -20,33 +22,36 @@ const Image::Byte *Image::getData() const { return data.data(); }
Image::Byte *Image::getData() { return data.data(); }
Image loadImage(const std::filesystem::path &path) {
Image loadImage(const std::string &path) {
std::ifstream file(path, std::ios::ate | std::ios::binary);
auto resource = __embedded_resources::getEmbeddedResource(path);
if (!file.is_open()) {
fatal() << "Could not access a PNG image in file " << path;
if (resource.data == nullptr) {
// REPORT_ERROR
progressia::main::logging::fatal()
<< "Could not find resource \"" << path << "\"";
exit(1);
}
std::size_t fileSize = static_cast<std::size_t>(file.tellg());
std::vector<Image::Byte> png(fileSize);
std::vector<Image::Byte> png(resource.data,
resource.data + resource.length);
file.seekg(0);
file.read(reinterpret_cast<char *>(png.data()), fileSize);
if (png.size() > std::numeric_limits<int>::max()) {
// REPORT_ERROR
progressia::main::logging::fatal()
<< "Could not load \"" << path << "\": image file too large";
exit(1);
}
file.close();
int dataSize = static_cast<int>(png.size());
int width = 0;
int height = 0;
int channelsInFile = 0;
int width;
int height;
int channelsInFile;
Image::Byte *stbAllocatedData = stbi_load_from_memory(
png.data(), dataSize, &width, &height, &channelsInFile, STBI_rgb_alpha);
Image::Byte *stbAllocatedData =
stbi_load_from_memory(png.data(), png.size(), &width, &height,
&channelsInFile, STBI_rgb_alpha);
if (stbAllocatedData == NULL) {
if (stbAllocatedData == nullptr) {
fatal() << "Could not decode a PNG image from file " << path;
// REPORT_ERROR
exit(1);
@ -61,5 +66,4 @@ Image loadImage(const std::filesystem::path &path) {
data};
}
} // namespace main
} // namespace progressia
} // namespace progressia::main

View File

@ -3,8 +3,7 @@
#include <filesystem>
#include <vector>
namespace progressia {
namespace main {
namespace progressia::main {
class Image {
public:
@ -19,7 +18,6 @@ class Image {
Byte *getData();
};
Image loadImage(const std::filesystem::path &);
Image loadImage(const std::string &);
} // namespace main
} // namespace progressia
} // namespace progressia::main