fix: optimization: PVS-Studio warning V813

Passing large objects by const reference avoids unnecessary copying and enhances efficiency.

Reported by: PVS-Studio
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov
2024-08-02 05:35:55 +03:00
committed by Pugemon
parent 5b325ac2bc
commit 2c1103307f
42 changed files with 173 additions and 144 deletions
+2 -1
View File
@@ -40,7 +40,8 @@ namespace AL {
/// @param field enum value /// @param field enum value
/// @param def default value will be returned in case of error /// @param def default value will be returned in case of error
/// @return field value or default /// @return field value or default
inline glm::vec3 getSource3f(uint source, ALenum field, glm::vec3 def={}) { inline glm::vec3 getSource3f(uint source, ALenum field, const glm::vec3& def= {}
) {
glm::vec3 value = def; glm::vec3 value = def;
if (source == 0) if (source == 0)
return def; return def;
+5 -5
View File
@@ -210,10 +210,10 @@ std::unique_ptr<Stream> audio::open_stream(std::shared_ptr<PCMStream> stream, bo
void audio::set_listener( void audio::set_listener(
glm::vec3 position, const glm::vec3& position,
glm::vec3 velocity, const glm::vec3& velocity,
glm::vec3 lookAt, const glm::vec3& lookAt,
glm::vec3 up const glm::vec3& up
) { ) {
backend->setListener(position, velocity, lookAt, up); backend->setListener(position, velocity, lookAt, up);
} }
@@ -310,7 +310,7 @@ speakerid_t audio::play(
speakerid_t audio::play_stream( speakerid_t audio::play_stream(
const fs::path& file, const fs::path& file,
glm::vec3 position, const glm::vec3& position,
bool relative, bool relative,
float volume, float volume,
float pitch, float pitch,
+5 -5
View File
@@ -399,10 +399,10 @@ namespace audio {
/// @param lookAt point the listener look at /// @param lookAt point the listener look at
/// @param up camera up vector /// @param up camera up vector
void set_listener( void set_listener(
glm::vec3 position, const glm::vec3& position,
glm::vec3 velocity, const glm::vec3& velocity,
glm::vec3 lookAt, const glm::vec3& lookAt,
glm::vec3 up const glm::vec3& up
); );
/// @brief Play 3D sound in the world /// @brief Play 3D sound in the world
@@ -457,7 +457,7 @@ namespace audio {
/// @return speaker id or 0 /// @return speaker id or 0
speakerid_t play_stream( speakerid_t play_stream(
const fs::path& file, const fs::path& file,
glm::vec3 position, const glm::vec3& position,
bool relative, bool relative,
float volume, float volume,
float pitch, float pitch,
+1 -1
View File
@@ -119,7 +119,7 @@ public:
static constexpr size_t MISSING = SIZE_MAX; static constexpr size_t MISSING = SIZE_MAX;
void add(std::string name, dynamic::Map_sptr map) { void add(const std::string& name, dynamic::Map_sptr map) {
indices[name] = names.size(); indices[name] = names.size();
names.push_back(name); names.push_back(name);
savedData->push_back(map); savedData->push_back(map);
+10 -10
View File
@@ -118,34 +118,34 @@ namespace dynamic {
List_sptr list(const std::string& key) const; List_sptr list(const std::string& key) const;
void flag(const std::string& key, bool& dst) const; void flag(const std::string& key, bool& dst) const;
Map& put(std::string key, std::unique_ptr<Map> value) { Map& put(const std::string& key, std::unique_ptr<Map> value) {
return put(key, Map_sptr(value.release())); return put(key, Map_sptr(value.release()));
} }
Map& put(std::string key, std::unique_ptr<List> value) { Map& put(const std::string& key, std::unique_ptr<List> value) {
return put(key, List_sptr(value.release())); return put(key, List_sptr(value.release()));
} }
Map& put(std::string key, int value) { Map& put(const std::string& key, int value) {
return put(key, Value(static_cast<integer_t>(value))); return put(key, Value(static_cast<integer_t>(value)));
} }
Map& put(std::string key, unsigned int value) { Map& put(const std::string& key, unsigned int value) {
return put(key, Value(static_cast<integer_t>(value))); return put(key, Value(static_cast<integer_t>(value)));
} }
Map& put(std::string key, int64_t value) { Map& put(const std::string& key, int64_t value) {
return put(key, Value(static_cast<integer_t>(value))); return put(key, Value(static_cast<integer_t>(value)));
} }
Map& put(std::string key, uint64_t value) { Map& put(const std::string& key, uint64_t value) {
return put(key, Value(static_cast<integer_t>(value))); return put(key, Value(static_cast<integer_t>(value)));
} }
Map& put(std::string key, float value) { Map& put(const std::string& key, float value) {
return put(key, Value(static_cast<number_t>(value))); return put(key, Value(static_cast<number_t>(value)));
} }
Map& put(std::string key, double value) { Map& put(const std::string& key, double value) {
return put(key, Value(static_cast<number_t>(value))); return put(key, Value(static_cast<number_t>(value)));
} }
Map& put(std::string key, bool value) { Map& put(const std::string& key, bool value) {
return put(key, Value(static_cast<bool>(value))); return put(key, Value(static_cast<bool>(value)));
} }
Map& put(std::string key, const char* value) { Map& put(const std::string& key, const char* value) {
return put(key, Value(value)); return put(key, Value(value));
} }
Map& put(const std::string& key, const Value& value); Map& put(const std::string& key, const Value& value);
+1 -1
View File
@@ -55,7 +55,7 @@ static void add_world_generators() {
WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat"); WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat");
} }
static void create_channel(Engine* engine, std::string name, NumberSetting& setting) { static void create_channel(Engine* engine, const std::string& name, NumberSetting& setting) {
if (name != "master") { if (name != "master") {
audio::create_channel(name); audio::create_channel(name);
} }
+4 -4
View File
@@ -196,7 +196,7 @@ ubyte* WorldRegions::getData(int x, int z, int layer, uint32_t& size) {
return nullptr; return nullptr;
} }
regfile_ptr WorldRegions::useRegFile(glm::ivec3 coord) { regfile_ptr WorldRegions::useRegFile(const glm::ivec3& coord) {
auto* file = openRegFiles[coord].get(); auto* file = openRegFiles[coord].get();
file->inUse = true; file->inUse = true;
return regfile_ptr(file, &regFilesCv); return regfile_ptr(file, &regFilesCv);
@@ -208,7 +208,7 @@ void WorldRegions::closeRegFile(glm::ivec3 coord) {
} }
// Marks regfile as used and unmarks when shared_ptr dies // Marks regfile as used and unmarks when shared_ptr dies
regfile_ptr WorldRegions::getRegFile(glm::ivec3 coord, bool create) { regfile_ptr WorldRegions::getRegFile(const glm::ivec3& coord, bool create) {
{ {
std::lock_guard lock(regFilesMutex); std::lock_guard lock(regFilesMutex);
const auto found = openRegFiles.find(coord); const auto found = openRegFiles.find(coord);
@@ -225,7 +225,7 @@ regfile_ptr WorldRegions::getRegFile(glm::ivec3 coord, bool create) {
return nullptr; return nullptr;
} }
regfile_ptr WorldRegions::createRegFile(glm::ivec3 coord) { regfile_ptr WorldRegions::createRegFile(const glm::ivec3& coord) {
fs::path file = layers[coord[2]].folder/getRegionFilename(coord[0], coord[1]); fs::path file = layers[coord[2]].folder/getRegionFilename(coord[0], coord[1]);
if (!fs::exists(file)) { if (!fs::exists(file)) {
return nullptr; return nullptr;
@@ -352,7 +352,7 @@ static std::unique_ptr<ubyte[]> write_inventories(Chunk* chunk, uint& datasize)
} }
/// @brief Store chunk data (voxels and lights) in region (existing or new) /// @brief Store chunk data (voxels and lights) in region (existing or new)
void WorldRegions::put(Chunk* chunk, std::vector<ubyte> entitiesData){ void WorldRegions::put(Chunk* chunk, const std::vector<ubyte>& entitiesData){
assert(chunk != nullptr); assert(chunk != nullptr);
if (!chunk->flags.lighted) { if (!chunk->flags.lighted) {
return; return;
+4 -4
View File
@@ -149,10 +149,10 @@ class WorldRegions {
ubyte* getData(int x, int z, int layer, uint32_t& size); ubyte* getData(int x, int z, int layer, uint32_t& size);
regfile_ptr getRegFile(glm::ivec3 coord, bool create=true); regfile_ptr getRegFile(const glm::ivec3& coord, bool create=true);
void closeRegFile(glm::ivec3 coord); void closeRegFile(glm::ivec3 coord);
regfile_ptr useRegFile(glm::ivec3 coord); regfile_ptr useRegFile(const glm::ivec3& coord);
regfile_ptr createRegFile(glm::ivec3 coord); regfile_ptr createRegFile(const glm::ivec3& coord);
fs::path getRegionFilename(int x, int y) const; fs::path getRegionFilename(int x, int y) const;
@@ -172,7 +172,7 @@ public:
~WorldRegions(); ~WorldRegions();
/// @brief Put all chunk data to regions /// @brief Put all chunk data to regions
void put(Chunk* chunk, std::vector<ubyte> entitiesData); void put(Chunk* chunk, const std::vector<ubyte>& entitiesData);
/// @brief Store data in specified region /// @brief Store data in specified region
/// @param x chunk.x /// @param x chunk.x
+1 -1
View File
@@ -314,7 +314,7 @@ void Hud::openInventory() {
} }
void Hud::openInventory( void Hud::openInventory(
glm::ivec3 block, const glm::ivec3& block,
UiDocument* doc, UiDocument* doc,
std::shared_ptr<Inventory> blockinv, std::shared_ptr<Inventory> blockinv,
bool playerInventory bool playerInventory
+3 -3
View File
@@ -140,12 +140,12 @@ public:
/// @brief Show block inventory in inventory-mode /// @brief Show block inventory in inventory-mode
/// @param block block position /// @param block block position
/// @param doc block ui layout /// @param doc block ui layout
/// @param blockInv block inventory /// @param blockinv block inventory
/// @param playerInventory show player inventory too /// @param playerInventory show player inventory too
void openInventory( void openInventory(
glm::ivec3 block, const glm::ivec3& block,
UiDocument* doc, UiDocument* doc,
std::shared_ptr<Inventory> blockInv, std::shared_ptr<Inventory> blockinv,
bool playerInventory bool playerInventory
); );
+7 -5
View File
@@ -59,8 +59,8 @@ void Batch2D::vertex(
buffer[index++] = a; buffer[index++] = a;
} }
void Batch2D::vertex( void Batch2D::vertex(
glm::vec2 point, const glm::vec2& point,
glm::vec2 uvpoint, const glm::vec2& uvpoint,
float r, float g, float b, float a float r, float g, float b, float a
) { ) {
buffer[index++] = point.x; buffer[index++] = point.x;
@@ -138,7 +138,7 @@ void Batch2D::rect(
UVRegion region, UVRegion region,
bool flippedX, bool flippedX,
bool flippedY, bool flippedY,
glm::vec4 tint const glm::vec4& tint
) { ) {
if (index + 6*B2D_VERTEX_SIZE >= capacity) { if (index + 6*B2D_VERTEX_SIZE >= capacity) {
flush(); flush();
@@ -322,11 +322,13 @@ void Batch2D::rect(
vertex(v1, glm::vec2(0, 0), r2,g2,b2,1.0f); vertex(v1, glm::vec2(0, 0), r2,g2,b2,1.0f);
} }
void Batch2D::sprite(float x, float y, float w, float h, const UVRegion& region, glm::vec4 tint){ void Batch2D::sprite(float x, float y, float w, float h, const UVRegion& region,
const glm::vec4& tint){
rect(x, y, w, h, region.u1, region.v1, region.u2-region.u1, region.v2-region.v1, tint.r, tint.g, tint.b, tint.a); rect(x, y, w, h, region.u1, region.v1, region.u2-region.u1, region.v2-region.v1, tint.r, tint.g, tint.b, tint.a);
} }
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index, glm::vec4 tint){ void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index,
const glm::vec4& tint){
float scale = 1.0f / (float)atlasRes; float scale = 1.0f / (float)atlasRes;
float u = (index % atlasRes) * scale; float u = (index % atlasRes) * scale;
float v = 1.0f - ((index / atlasRes) * scale) - scale; float v = 1.0f - ((index / atlasRes) * scale) - scale;
+8 -6
View File
@@ -31,8 +31,8 @@ class Batch2D : public Flushable {
); );
void vertex( void vertex(
glm::vec2 point, const glm::vec2& point,
glm::vec2 uvpoint, const glm::vec2& uvpoint,
float r, float g, float b, float a float r, float g, float b, float a
); );
@@ -44,11 +44,13 @@ public:
void texture(Texture* texture); void texture(Texture* texture);
void untexture(); void untexture();
void setRegion(UVRegion region); void setRegion(UVRegion region);
void sprite(float x, float y, float w, float h, const UVRegion& region, glm::vec4 tint); void sprite(float x, float y, float w, float h, const UVRegion& region,
void sprite(float x, float y, float w, float h, int atlasRes, int index, glm::vec4 tint); const glm::vec4& tint);
void sprite(float x, float y, float w, float h, int atlasRes, int index,
const glm::vec4& tint);
void point(float x, float y, float r, float g, float b, float a); void point(float x, float y, float r, float g, float b, float a);
inline void setColor(glm::vec4 color) { inline void setColor(const glm::vec4& color) {
this->color = color; this->color = color;
} }
inline glm::vec4 getColor() const { inline glm::vec4 getColor() const {
@@ -69,7 +71,7 @@ public:
float ox, float oy, float ox, float oy,
float angle, UVRegion region, float angle, UVRegion region,
bool flippedX, bool flippedY, bool flippedX, bool flippedY,
glm::vec4 tint const glm::vec4& tint
); );
void rect(float x, float y, float w, float h); void rect(float x, float y, float w, float h);
+9 -9
View File
@@ -51,7 +51,7 @@ void Batch3D::vertex(
buffer[index++] = a; buffer[index++] = a;
} }
void Batch3D::vertex( void Batch3D::vertex(
glm::vec3 coord, float u, float v, const glm::vec3& coord, float u, float v,
float r, float g, float b, float a float r, float g, float b, float a
) { ) {
buffer[index++] = coord.x; buffer[index++] = coord.x;
@@ -65,8 +65,8 @@ void Batch3D::vertex(
buffer[index++] = a; buffer[index++] = a;
} }
void Batch3D::vertex( void Batch3D::vertex(
glm::vec3 point, const glm::vec3& point,
glm::vec2 uvpoint, const glm::vec2& uvpoint,
float r, float g, float b, float a float r, float g, float b, float a
) { ) {
buffer[index++] = point.x; buffer[index++] = point.x;
@@ -118,12 +118,12 @@ void Batch3D::texture(Texture* new_texture){
} }
void Batch3D::sprite( void Batch3D::sprite(
glm::vec3 pos, const glm::vec3& pos,
glm::vec3 up, const glm::vec3& up,
glm::vec3 right, const glm::vec3& right,
float w, float h, float w, float h,
const UVRegion& uv, const UVRegion& uv,
glm::vec4 color const glm::vec4& color
){ ){
const float r = color.r; const float r = color.r;
const float g = color.g; const float g = color.g;
@@ -245,11 +245,11 @@ void Batch3D::blockCube(
cube((1.0f - size) * -0.5f, size, texfaces, tint, shading); cube((1.0f - size) * -0.5f, size, texfaces, tint, shading);
} }
void Batch3D::point(glm::vec3 coord, glm::vec2 uv, glm::vec4 tint) { void Batch3D::point(const glm::vec3& coord, const glm::vec2& uv, const glm::vec4& tint) {
vertex(coord, uv, tint.r, tint.g, tint.b, tint.a); vertex(coord, uv, tint.r, tint.g, tint.b, tint.a);
} }
void Batch3D::point(glm::vec3 coord, glm::vec4 tint) { void Batch3D::point(const glm::vec3& coord, const glm::vec4& tint) {
point(coord, glm::vec2(), tint); point(coord, glm::vec2(), tint);
} }
+12 -5
View File
@@ -27,12 +27,13 @@ class Batch3D : public Flushable {
float r, float g, float b, float a float r, float g, float b, float a
); );
void vertex( void vertex(
glm::vec3 coord, const glm::vec3& coord,
float u, float v, float u, float v,
float r, float g, float b, float a float r, float g, float b, float a
); );
void vertex( void vertex(
glm::vec3 point, glm::vec2 uvpoint, const glm::vec3& point,
const glm::vec2& uvpoint,
float r, float g, float b, float a float r, float g, float b, float a
); );
void face( void face(
@@ -49,12 +50,18 @@ public:
void begin(); void begin();
void texture(Texture* texture); void texture(Texture* texture);
void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h, const UVRegion& uv, glm::vec4 tint); void sprite(
const glm::vec3& pos,
const glm::vec3& up,
const glm::vec3& right, float w, float h, const UVRegion& uv,
const glm::vec4& color
);
void xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading=true); void xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading=true);
void cube(const glm::vec3 coords, const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true); void cube(const glm::vec3 coords, const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
void blockCube(const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true); void blockCube(const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
void point(glm::vec3 pos, glm::vec2 uv, glm::vec4 tint); void point(
void point(glm::vec3 pos, glm::vec4 tint); const glm::vec3& coord, const glm::vec2& uv, const glm::vec4& tint);
void point(const glm::vec3& coord, const glm::vec4& tint);
void flush() override; void flush() override;
void flushPoints(); void flushPoints();
}; };
+1 -1
View File
@@ -148,7 +148,7 @@ void DrawContext::setBlendMode(BlendMode mode) {
set_blend_mode(mode); set_blend_mode(mode);
} }
void DrawContext::setScissors(glm::vec4 area) { void DrawContext::setScissors(const glm::vec4& area) {
Window::pushScissor(area); Window::pushScissor(area);
scissorsCount++; scissorsCount++;
} }
+1 -1
View File
@@ -35,7 +35,7 @@ public:
void setDepthTest(bool flag); void setDepthTest(bool flag);
void setCullFace(bool flag); void setCullFace(bool flag);
void setBlendMode(BlendMode mode); void setBlendMode(BlendMode mode);
void setScissors(glm::vec4 area); void setScissors(const glm::vec4& area);
void setLineWidth(float width); void setLineWidth(float width);
}; };
+2 -2
View File
@@ -18,7 +18,7 @@ public:
LineBatch(size_t capacity=4096); LineBatch(size_t capacity=4096);
~LineBatch(); ~LineBatch();
inline void line(const glm::vec3 a, const glm::vec3 b, const glm::vec4 color) { inline void line(const glm::vec3 &a, const glm::vec3 &b, const glm::vec4 &color) {
line(a.x, a.y, a.z, b.x, b.y, b.z, color.r, color.g, color.b, color.a); line(a.x, a.y, a.z, b.x, b.y, b.z, color.r, color.g, color.b, color.a);
} }
void line(float x1, float y1, float z1, float x2, float y2, float z2, void line(float x1, float y1, float z1, float x2, float y2, float z2,
@@ -26,7 +26,7 @@ public:
void box(float x, float y, float z, float w, float h, float d, void box(float x, float y, float z, float w, float h, float d,
float r, float g, float b, float a); float r, float g, float b, float a);
inline void box(glm::vec3 xyz, glm::vec3 whd, glm::vec4 rgba) { inline void box(const glm::vec3 &xyz, const glm::vec3 &whd, const glm::vec4 &rgba) {
box(xyz.x, xyz.y, xyz.z, whd.x, whd.y, whd.z, box(xyz.x, xyz.y, xyz.z, whd.x, whd.y, whd.z,
rgba.r, rgba.g, rgba.b, rgba.a); rgba.r, rgba.g, rgba.b, rgba.a);
} }
+6 -2
View File
@@ -8,7 +8,11 @@ inline constexpr glm::vec3 X(1, 0, 0);
inline constexpr glm::vec3 Y(0, 1, 0); inline constexpr glm::vec3 Y(0, 1, 0);
inline constexpr glm::vec3 Z(0, 0, 1); inline constexpr glm::vec3 Z(0, 0, 1);
void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm) { void Mesh::addPlane(
const glm::vec3 &pos,
const glm::vec3 &right,
const glm::vec3 &up,
const glm::vec3 &norm) {
vertices.push_back({pos-right-up, {0,0}, norm}); vertices.push_back({pos-right-up, {0,0}, norm});
vertices.push_back({pos+right-up, {1,0}, norm}); vertices.push_back({pos+right-up, {1,0}, norm});
vertices.push_back({pos+right+up, {1,1}, norm}); vertices.push_back({pos+right+up, {1,1}, norm});
@@ -18,7 +22,7 @@ void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm
vertices.push_back({pos-right+up, {0,1}, norm}); vertices.push_back({pos-right+up, {0,1}, norm});
} }
void Mesh::addBox(glm::vec3 pos, glm::vec3 size) { void Mesh::addBox(const glm::vec3 &pos, const glm::vec3 &size) {
addPlane(pos+Z*size, X*size, Y*size, Z); addPlane(pos+Z*size, X*size, Y*size, Z);
addPlane(pos-Z*size, -X*size, Y*size, -Z); addPlane(pos-Z*size, -X*size, Y*size, -Z);
+6 -2
View File
@@ -16,8 +16,12 @@ namespace model {
std::string texture; std::string texture;
std::vector<Vertex> vertices; std::vector<Vertex> vertices;
void addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm); void addPlane(
void addBox(glm::vec3 pos, glm::vec3 size); const glm::vec3& pos,
const glm::vec3& right,
const glm::vec3& up,
const glm::vec3& norm);
void addBox(const glm::vec3& pos, const glm::vec3& size);
}; };
struct Model { struct Model {
+3 -3
View File
@@ -54,11 +54,11 @@ void Shader::uniform2f(const std::string& name, float x, float y){
glUniform2f(getUniformLocation(name), x, y); glUniform2f(getUniformLocation(name), x, y);
} }
void Shader::uniform2f(const std::string& name, glm::vec2 xy){ void Shader::uniform2f(const std::string& name, const glm::vec2& xy){
glUniform2f(getUniformLocation(name), xy.x, xy.y); glUniform2f(getUniformLocation(name), xy.x, xy.y);
} }
void Shader::uniform2i(const std::string& name, glm::ivec2 xy){ void Shader::uniform2i(const std::string& name, const glm::ivec2& xy){
glUniform2i(getUniformLocation(name), xy.x, xy.y); glUniform2i(getUniformLocation(name), xy.x, xy.y);
} }
@@ -66,7 +66,7 @@ void Shader::uniform3f(const std::string& name, float x, float y, float z){
glUniform3f(getUniformLocation(name), x,y,z); glUniform3f(getUniformLocation(name), x,y,z);
} }
void Shader::uniform3f(const std::string& name, glm::vec3 xyz){ void Shader::uniform3f(const std::string& name, const glm::vec3& xyz){
glUniform3f(getUniformLocation(name), xyz.x, xyz.y, xyz.z); glUniform3f(getUniformLocation(name), xyz.x, xyz.y, xyz.z);
} }
+3 -3
View File
@@ -26,10 +26,10 @@ public:
void uniform1i(const std::string& name, int x); void uniform1i(const std::string& name, int x);
void uniform1f(const std::string& name, float x); void uniform1f(const std::string& name, float x);
void uniform2f(const std::string& name, float x, float y); void uniform2f(const std::string& name, float x, float y);
void uniform2f(const std::string& name, glm::vec2 xy); void uniform2f(const std::string& name, const glm::vec2& xy);
void uniform2i(const std::string& name, glm::ivec2 xy); void uniform2i(const std::string& name, const glm::ivec2& xy);
void uniform3f(const std::string& name, float x, float y, float z); void uniform3f(const std::string& name, float x, float y, float z);
void uniform3f(const std::string& name, glm::vec3 xyz); void uniform3f(const std::string& name, const glm::vec3& xyz);
/// @brief Create shader program using vertex and fragment shaders source. /// @brief Create shader program using vertex and fragment shaders source.
/// @param vertexFile vertex shader file name /// @param vertexFile vertex shader file name
+8 -5
View File
@@ -35,7 +35,7 @@ struct DecomposedMat4 {
glm::vec4 perspective; glm::vec4 perspective;
}; };
static glm::mat4 extract_rotation(glm::mat4 matrix) { static glm::mat4 extract_rotation(const glm::mat4& matrix) {
DecomposedMat4 decomposed = {}; DecomposedMat4 decomposed = {};
glm::quat rotation; glm::quat rotation;
glm::decompose( glm::decompose(
@@ -66,8 +66,10 @@ ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
ModelBatch::~ModelBatch() = default; ModelBatch::~ModelBatch() = default;
void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix, void ModelBatch::draw(const model::Mesh& mesh,
const glm::mat3& rotation, glm::vec3 tint, const glm::mat4& matrix,
const glm::mat3& rotation,
const glm::vec3& tint,
const texture_names_map* varTextures) { const texture_names_map* varTextures) {
glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
light_t light = chunks->getLight(floor(gpos.x), floor(gpos.y), floor(gpos.z)); light_t light = chunks->getLight(floor(gpos.x), floor(gpos.y), floor(gpos.z));
@@ -94,8 +96,9 @@ void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
} }
} }
void ModelBatch::draw(glm::mat4 matrix, void ModelBatch::draw(
glm::vec3 tint, const glm::mat4& matrix,
const glm::vec3& tint,
const model::Model* model, const model::Model* model,
const texture_names_map* varTextures) { const texture_names_map* varTextures) {
for (const auto& mesh : model->meshes) { for (const auto& mesh : model->meshes) {
+8 -4
View File
@@ -37,7 +37,10 @@ class ModelBatch {
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f}; static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
inline void vertex( inline void vertex(
glm::vec3 pos, glm::vec2 uv, glm::vec4 light, glm::vec3 tint const glm::vec3& pos,
const glm::vec2& uv,
const glm::vec4& light,
const glm::vec3& tint
) { ) {
float* buffer = this->buffer.get(); float* buffer = this->buffer.get();
buffer[index++] = pos.x; buffer[index++] = pos.x;
@@ -65,7 +68,7 @@ class ModelBatch {
void draw(const model::Mesh& mesh, void draw(const model::Mesh& mesh,
const glm::mat4& matrix, const glm::mat4& matrix,
const glm::mat3& rotation, const glm::mat3& rotation,
glm::vec3 tint, const glm::vec3& tint,
const texture_names_map* varTextures); const texture_names_map* varTextures);
void setTexture(const std::string& name, void setTexture(const std::string& name,
const texture_names_map* varTextures); const texture_names_map* varTextures);
@@ -84,8 +87,9 @@ public:
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks); ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
~ModelBatch(); ~ModelBatch();
void draw(glm::mat4 matrix, void draw(
glm::vec3 tint, const glm::mat4& matrix,
const glm::vec3& tint,
const model::Model* model, const model::Model* model,
const texture_names_map* varTextures); const texture_names_map* varTextures);
void render(); void render();
+5 -3
View File
@@ -230,10 +230,12 @@ void WorldRenderer::renderBlockSelection() {
: block->hitboxes; : block->hitboxes;
lineBatch->lineWidth(2.0f); lineBatch->lineWidth(2.0f);
constexpr auto boxOffset = glm::vec3(0.02);
constexpr auto boxColor = glm::vec4(0.f, 0.f, 0.f, 0.5f);
for (auto& hitbox: hitboxes) { for (auto& hitbox: hitboxes) {
const glm::vec3 center = glm::vec3(pos) + hitbox.center(); const glm::vec3 center = glm::vec3(pos) + hitbox.center();
const glm::vec3 size = hitbox.size(); const glm::vec3 size = hitbox.size();
lineBatch->box(center, size + glm::vec3(0.02), glm::vec4(0.f, 0.f, 0.f, 0.5f)); lineBatch->box(center, size + boxOffset, boxColor);
if (player->debug) { if (player->debug) {
lineBatch->line(point, point+norm*0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f)); lineBatch->line(point, point+norm*0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f));
} }
@@ -340,12 +342,12 @@ void WorldRenderer::draw(
ctx.setDepthTest(true); ctx.setDepthTest(true);
ctx.setCullFace(true); ctx.setCullFace(true);
renderLevel(ctx, camera, settings, delta, pause); renderLevel(ctx, camera, settings, delta, pause);
// Debug lines
if (hudVisible){ if (hudVisible){
renderLines(camera, linesShader, ctx); renderLines(camera, linesShader, ctx);
} }
} }
// Debug lines
if (hudVisible && player->debug) { if (hudVisible && player->debug) {
renderDebugLines(wctx, camera, linesShader); renderDebugLines(wctx, camera, linesShader);
} }
+2 -2
View File
@@ -52,7 +52,7 @@ InventoryBuilder::InventoryBuilder() {
void InventoryBuilder::addGrid( void InventoryBuilder::addGrid(
int cols, int count, int cols, int count,
glm::vec2 pos, const glm::vec2 &pos,
int padding, int padding,
bool addpanel, bool addpanel,
const SlotLayout& slotLayout const SlotLayout& slotLayout
@@ -381,7 +381,7 @@ void InventoryView::setPos(glm::vec2 pos) {
Container::setPos(pos - origin); Container::setPos(pos - origin);
} }
void InventoryView::setOrigin(glm::vec2 origin) { void InventoryView::setOrigin(const glm::vec2 &origin) {
this->origin = origin; this->origin = origin;
} }
+2 -2
View File
@@ -93,7 +93,7 @@ namespace gui {
virtual void setPos(glm::vec2 pos) override; virtual void setPos(glm::vec2 pos) override;
void setOrigin(glm::vec2 origin); void setOrigin(const glm::vec2 &origin);
glm::vec2 getOrigin() const; glm::vec2 getOrigin() const;
void setSelected(int index); void setSelected(int index);
@@ -130,7 +130,7 @@ namespace gui {
/// @param slotLayout slot settings (index and position are ignored) /// @param slotLayout slot settings (index and position are ignored)
void addGrid( void addGrid(
int cols, int count, int cols, int count,
glm::vec2 pos, const glm::vec2 &pos,
int padding, int padding,
bool addpanel, bool addpanel,
const SlotLayout& slotLayout const SlotLayout& slotLayout
+1 -1
View File
@@ -256,7 +256,7 @@ public:
dynamic::Value applyRelative( dynamic::Value applyRelative(
Argument* arg, Argument* arg,
dynamic::Value value, const dynamic::Value& value,
const dynamic::Value& origin const dynamic::Value& origin
) { ) {
if (origin.index() == 0) { if (origin.index() == 0) {
+8 -8
View File
@@ -151,20 +151,20 @@ namespace lua {
return 3; return 3;
} }
inline int pushivec3_stack(lua::State* L, glm::ivec3 vec) { inline int pushivec3_stack(lua::State* L, const glm::ivec3 &vec) {
pushinteger(L, vec.x); pushinteger(L, vec.x);
pushinteger(L, vec.y); pushinteger(L, vec.y);
pushinteger(L, vec.z); pushinteger(L, vec.z);
return 3; return 3;
} }
inline int pushvec3_stack(lua::State* L, glm::vec3 vec) { inline int pushvec3_stack(lua::State* L, const glm::vec3 &vec) {
pushnumber(L, vec.x); pushnumber(L, vec.x);
pushnumber(L, vec.y); pushnumber(L, vec.y);
pushnumber(L, vec.z); pushnumber(L, vec.z);
return 3; return 3;
} }
inline int pushvec4_stack(lua::State* L, glm::vec4 vec) { inline int pushvec4_stack(lua::State* L, const glm::vec4 &vec) {
pushnumber(L, vec.x); pushnumber(L, vec.x);
pushnumber(L, vec.y); pushnumber(L, vec.y);
pushnumber(L, vec.z); pushnumber(L, vec.z);
@@ -179,15 +179,15 @@ namespace lua {
lua_pushvalue(L, idx); lua_pushvalue(L, idx);
return 1; return 1;
} }
inline int pushvec2(lua::State* L, glm::vec2 vec) { inline int pushvec2(lua::State* L, const glm::vec2 &vec) {
return pushvec(L, vec); return pushvec(L, vec);
} }
inline int pushvec3(lua::State* L, glm::vec3 vec) { inline int pushvec3(lua::State* L, const glm::vec3 &vec) {
return pushvec(L, vec); return pushvec(L, vec);
} }
inline int pushvec4(lua::State* L, glm::vec4 vec) { inline int pushvec4(lua::State* L, const glm::vec4 &vec) {
return pushvec(L, vec); return pushvec(L, vec);
} }
inline int pushcolor(lua::State* L, glm::vec4 vec) { inline int pushcolor(lua::State* L, glm::vec4 vec) {
@@ -210,7 +210,7 @@ namespace lua {
} }
return 1; return 1;
} }
inline int pushmat4(lua::State* L, glm::mat4 matrix) { inline int pushmat4(lua::State* L, const glm::mat4 &matrix) {
createtable(L, 16, 0); createtable(L, 16, 0);
for (uint y = 0; y < 4; y++) { for (uint y = 0; y < 4; y++) {
for (uint x = 0; x < 4; x++) { for (uint x = 0; x < 4; x++) {
@@ -222,7 +222,7 @@ namespace lua {
return 1; return 1;
} }
/// @brief pushes matrix table to the stack and updates it with glm matrix /// @brief pushes matrix table to the stack and updates it with glm matrix
inline int setmat4(lua::State* L, int idx, glm::mat4 matrix) { inline int setmat4(lua::State* L, int idx, const glm::mat4 &matrix) {
pushvalue(L, idx); pushvalue(L, idx);
for (uint y = 0; y < 4; y++) { for (uint y = 0; y < 4; y++) {
for (uint x = 0; x < 4; x++) { for (uint x = 0; x < 4; x++) {
+1 -1
View File
@@ -70,7 +70,7 @@ struct AABB {
b = end; b = end;
} }
inline void addPoint(glm::vec3 p) { inline void addPoint(const glm::vec3& p) {
a = glm::min(a, p); a = glm::min(a, p);
b = glm::max(b, p); b = glm::max(b, p);
} }
+4 -4
View File
@@ -186,7 +186,7 @@ void Entities::loadEntity(const dynamic::Map_sptr& map) {
spawn(def, {}, nullptr, map, uid); spawn(def, {}, nullptr, map, uid);
} }
void Entities::loadEntity(const dynamic::Map_sptr& map, Entity entity) { void Entities::loadEntity(const dynamic::Map_sptr& map, const Entity &entity) {
auto& transform = entity.getTransform(); auto& transform = entity.getTransform();
auto& body = entity.getRigidbody(); auto& body = entity.getRigidbody();
auto& skeleton = entity.getSkeleton(); auto& skeleton = entity.getSkeleton();
@@ -228,7 +228,7 @@ void Entities::loadEntity(const dynamic::Map_sptr& map, Entity entity) {
} }
std::optional<Entities::RaycastResult> Entities::rayCast( std::optional<Entities::RaycastResult> Entities::rayCast(
glm::vec3 start, glm::vec3 dir, float maxDistance, entityid_t ignore const glm::vec3 &start, const glm::vec3 &dir, float maxDistance, entityid_t ignore
) { ) {
Ray ray(start, dir); Ray ray(start, dir);
auto view = registry.view<EntityId, Transform, Rigidbody>(); auto view = registry.view<EntityId, Transform, Rigidbody>();
@@ -547,7 +547,7 @@ bool Entities::hasBlockingInside(AABB aabb) {
return false; return false;
} }
std::vector<Entity> Entities::getAllInside(AABB aabb) { std::vector<Entity> Entities::getAllInside(const AABB &aabb) {
std::vector<Entity> collected; std::vector<Entity> collected;
auto view = registry.view<Transform>(); auto view = registry.view<Transform>();
for (auto [entity, transform] : view.each()) { for (auto [entity, transform] : view.each()) {
@@ -564,7 +564,7 @@ std::vector<Entity> Entities::getAllInside(AABB aabb) {
return collected; return collected;
} }
std::vector<Entity> Entities::getAllInRadius(glm::vec3 center, float radius) { std::vector<Entity> Entities::getAllInRadius(const glm::vec3 &center, float radius) {
std::vector<Entity> collected; std::vector<Entity> collected;
auto view = registry.view<Transform>(); auto view = registry.view<Transform>();
for (auto [entity, transform] : view.each()) { for (auto [entity, transform] : view.each()) {
+7 -7
View File
@@ -49,19 +49,19 @@ struct Transform {
void refresh(); void refresh();
inline void setRot(glm::mat3 m) { inline void setRot(const glm::mat3 &m) {
rot = m; rot = m;
dirty = true; dirty = true;
} }
inline void setSize(glm::vec3 v) { inline void setSize(const glm::vec3 &v) {
if (glm::distance2(displaySize, v) >= 0.00001f) { if (glm::distance2(displaySize, v) >= 0.00001f) {
dirty = true; dirty = true;
} }
size = v; size = v;
} }
inline void setPos(glm::vec3 v) { inline void setPos(const glm::vec3 &v) {
if (glm::distance2(displayPos, v) >= 0.0001f) { if (glm::distance2(displayPos, v) >= 0.0001f) {
dirty = true; dirty = true;
} }
@@ -212,15 +212,15 @@ public:
/// @param ignore Ignored entity ID /// @param ignore Ignored entity ID
/// @return An optional structure containing entity, normal and distance /// @return An optional structure containing entity, normal and distance
std::optional<RaycastResult> rayCast( std::optional<RaycastResult> rayCast(
glm::vec3 start, glm::vec3 dir, float maxDistance, entityid_t ignore=-1); const glm::vec3 &start, const glm::vec3 &dir, float maxDistance, entityid_t ignore=-1);
void loadEntities(dynamic::Map_sptr map); void loadEntities(dynamic::Map_sptr map);
void loadEntity(const dynamic::Map_sptr& map); void loadEntity(const dynamic::Map_sptr& map);
void loadEntity(const dynamic::Map_sptr& map, Entity entity); void loadEntity(const dynamic::Map_sptr& map, const Entity &entity);
void onSave(const Entity& entity); void onSave(const Entity& entity);
bool hasBlockingInside(AABB aabb); bool hasBlockingInside(AABB aabb);
std::vector<Entity> getAllInside(AABB aabb); std::vector<Entity> getAllInside(const AABB &aabb);
std::vector<Entity> getAllInRadius(glm::vec3 center, float radius); std::vector<Entity> getAllInRadius(const glm::vec3 &center, float radius);
void despawn(entityid_t id); void despawn(entityid_t id);
dynamic::Value serialize(const Entity& entity); dynamic::Value serialize(const Entity& entity);
+2 -2
View File
@@ -169,7 +169,7 @@ void Player::postUpdate() {
glm::mat4(1.0f), glm::radians(cam.y), glm::vec3(1, 0, 0)); glm::mat4(1.0f), glm::radians(cam.y), glm::vec3(1, 0, 0));
} }
void Player::teleport(glm::vec3 position) { void Player::teleport(const glm::vec3 &position) {
this->position = position; this->position = position;
if (auto hitbox = getHitbox()) { if (auto hitbox = getHitbox()) {
hitbox->position = position; hitbox->position = position;
@@ -239,7 +239,7 @@ std::shared_ptr<Inventory> Player::getInventory() const {
return inventory; return inventory;
} }
void Player::setSpawnPoint(glm::vec3 spawnpoint) { void Player::setSpawnPoint(const glm::vec3 &spawnpoint) {
this->spawnpoint = spawnpoint; this->spawnpoint = spawnpoint;
} }
+2 -2
View File
@@ -64,7 +64,7 @@ public:
std::shared_ptr<Inventory> inv, entityid_t eid); std::shared_ptr<Inventory> inv, entityid_t eid);
~Player(); ~Player();
void teleport(glm::vec3 position); void teleport(const glm::vec3 &position);
void updateEntity(); void updateEntity();
void updateInput(PlayerInput& input, float delta); void updateInput(PlayerInput& input, float delta);
void updateSelectedEntity(); void updateSelectedEntity();
@@ -96,7 +96,7 @@ public:
Hitbox* getHitbox(); Hitbox* getHitbox();
void setSpawnPoint(glm::vec3 point); void setSpawnPoint(const glm::vec3 &spawnpoint);
glm::vec3 getSpawnPoint() const; glm::vec3 getSpawnPoint() const;
std::unique_ptr<dynamic::Map> serialize() const override; std::unique_ptr<dynamic::Map> serialize() const override;
+2 -2
View File
@@ -69,7 +69,7 @@ size_t SkeletonConfig::update(
size_t index, size_t index,
Skeleton& skeleton, Skeleton& skeleton,
Bone* node, Bone* node,
glm::mat4 matrix) const const glm::mat4& matrix) const
{ {
auto boneMatrix = skeleton.pose.matrices[index]; auto boneMatrix = skeleton.pose.matrices[index];
auto boneOffset = node->getOffset(); auto boneOffset = node->getOffset();
@@ -85,7 +85,7 @@ size_t SkeletonConfig::update(
return count; return count;
} }
void SkeletonConfig::update(Skeleton& skeleton, glm::mat4 matrix) const { void SkeletonConfig::update(Skeleton& skeleton, const glm::mat4& matrix) const {
update(0, skeleton, root.get(), matrix); update(0, skeleton, root.get(), matrix);
} }
+2 -2
View File
@@ -103,12 +103,12 @@ namespace rigging {
size_t index, size_t index,
Skeleton& skeleton, Skeleton& skeleton,
Bone* node, Bone* node,
glm::mat4 matrix) const; const glm::mat4& matrix) const;
public: public:
SkeletonConfig(const std::string& name, std::unique_ptr<Bone> root, SkeletonConfig(const std::string& name, std::unique_ptr<Bone> root,
size_t nodesCount); size_t nodesCount);
void update(Skeleton& skeleton, glm::mat4 matrix) const; void update(Skeleton& skeleton, const glm::mat4& matrix) const;
void render( void render(
Assets* assets, Assets* assets,
ModelBatch& batch, ModelBatch& batch,
+2 -2
View File
@@ -37,7 +37,7 @@ std::string util::quote(const std::string& s) {
return escape(s); return escape(s);
} }
std::wstring util::lfill(std::wstring s, uint length, wchar_t c) { std::wstring util::lfill(const std::wstring& s, uint length, wchar_t c) {
if (s.length() >= length) { if (s.length() >= length) {
return s; return s;
} }
@@ -49,7 +49,7 @@ std::wstring util::lfill(std::wstring s, uint length, wchar_t c) {
return ss.str(); return ss.str();
} }
std::wstring util::rfill(std::wstring s, uint length, wchar_t c) { std::wstring util::rfill(const std::wstring& s, uint length, wchar_t c) {
if (s.length() >= length) { if (s.length() >= length) {
return s; return s;
} }
+2 -2
View File
@@ -13,8 +13,8 @@ namespace util {
/// @brief Function used for error messages /// @brief Function used for error messages
std::string quote(const std::string& s); std::string quote(const std::string& s);
std::wstring lfill(std::wstring s, uint length, wchar_t c); std::wstring lfill(const std::wstring& s, uint length, wchar_t c);
std::wstring rfill(std::wstring s, uint length, wchar_t c); std::wstring rfill(const std::wstring& s, uint length, wchar_t c);
uint encode_utf8(uint32_t c, ubyte* bytes); uint encode_utf8(uint32_t c, ubyte* bytes);
uint32_t decode_utf8(uint& size, const char* bytes); uint32_t decode_utf8(uint& size, const char* bytes);
+1 -1
View File
@@ -48,7 +48,7 @@ struct CoordSystem {
void transform(AABB& aabb) const; void transform(AABB& aabb) const;
inline bool isVectorHasNegatives(glm::ivec3 vec) { inline bool isVectorHasNegatives(const glm::ivec3& vec) {
return (vec.x < 0 || vec.y < 0 || vec.z < 0); return (vec.x < 0 || vec.y < 0 || vec.z < 0);
} }
}; };
+6 -6
View File
@@ -232,13 +232,13 @@ void Chunks::repairSegments(const Block* def, blockstate state, int x, int y, in
} }
} }
bool Chunks::checkReplaceability(const Block* def, blockstate state, glm::ivec3 origin, blockid_t ignore) { bool Chunks::checkReplaceability(const Block* def, blockstate state, const glm::ivec3 &coord, blockid_t ignore) {
const auto& rotation = def->rotations.variants[state.rotation]; const auto& rotation = def->rotations.variants[state.rotation];
const auto size = def->size; const auto size = def->size;
for (int sy = 0; sy < size.y; sy++) { for (int sy = 0; sy < size.y; sy++) {
for (int sz = 0; sz < size.z; sz++) { for (int sz = 0; sz < size.z; sz++) {
for (int sx = 0; sx < size.x; sx++) { for (int sx = 0; sx < size.x; sx++) {
auto pos = origin; auto pos = coord;
pos += rotation.axisX * sx; pos += rotation.axisX * sx;
pos += rotation.axisY * sy; pos += rotation.axisY * sy;
pos += rotation.axisZ * sz; pos += rotation.axisZ * sz;
@@ -257,7 +257,7 @@ bool Chunks::checkReplaceability(const Block* def, blockstate state, glm::ivec3
} }
void Chunks::setRotationExtended( void Chunks::setRotationExtended(
Block* def, blockstate state, glm::ivec3 origin, uint8_t index Block* def, blockstate state, const glm::ivec3 &origin, uint8_t index
) { ) {
auto newstate = state; auto newstate = state;
newstate.rotation = index; newstate.rotation = index;
@@ -387,8 +387,8 @@ void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, blockstate state)
} }
voxel* Chunks::rayCast( voxel* Chunks::rayCast(
glm::vec3 start, const glm::vec3 &start,
glm::vec3 dir, const glm::vec3 &dir,
float maxDist, float maxDist,
glm::vec3& end, glm::vec3& end,
glm::ivec3& norm, glm::ivec3& norm,
@@ -520,7 +520,7 @@ voxel* Chunks::rayCast(
return nullptr; return nullptr;
} }
glm::vec3 Chunks::rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist) { glm::vec3 Chunks::rayCastToObstacle(const glm::vec3 &start, const glm::vec3 &dir, float maxDist) {
const float px = start.x; const float px = start.x;
const float py = start.y; const float py = start.y;
const float pz = start.z; const float pz = start.z;
+6 -6
View File
@@ -27,7 +27,7 @@ class Chunks {
void eraseSegments(const Block* def, blockstate state, int x, int y, int z); void eraseSegments(const Block* def, blockstate state, int x, int y, int z);
void repairSegments(const Block* def, blockstate state, int x, int y, int z); void repairSegments(const Block* def, blockstate state, int x, int y, int z);
void setRotationExtended(Block* def, blockstate state, glm::ivec3 origin, uint8_t rotation); void setRotationExtended(Block* def, blockstate state, const glm::ivec3 &origin, uint8_t rotation);
public: public:
std::vector<std::shared_ptr<Chunk>> chunks; std::vector<std::shared_ptr<Chunk>> chunks;
std::vector<std::shared_ptr<Chunk>> chunksSecond; std::vector<std::shared_ptr<Chunk>> chunksSecond;
@@ -48,7 +48,7 @@ public:
Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z); Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z);
voxel* get(int32_t x, int32_t y, int32_t z) const; voxel* get(int32_t x, int32_t y, int32_t z) const;
inline voxel* get(glm::ivec3 pos) { inline voxel* get(const glm::ivec3 &pos) {
return get(pos.x, pos.y, pos.z); return get(pos.x, pos.y, pos.z);
} }
@@ -68,20 +68,20 @@ public:
/// @param state the block state /// @param state the block state
/// @param coord position of the zone start /// @param coord position of the zone start
/// @param ignore ignored block id (will be counted as replaceable) /// @param ignore ignored block id (will be counted as replaceable)
bool checkReplaceability(const Block* def, blockstate state, glm::ivec3 coord, blockid_t ignore=0); bool checkReplaceability(const Block* def, blockstate state, const glm::ivec3 &coord, blockid_t ignore=0);
void setRotation(int32_t x, int32_t y, int32_t z, uint8_t rotation); void setRotation(int32_t x, int32_t y, int32_t z, uint8_t rotation);
voxel* rayCast( voxel* rayCast(
glm::vec3 start, const glm::vec3 &start,
glm::vec3 dir, const glm::vec3 &dir,
float maxLength, float maxLength,
glm::vec3& end, glm::vec3& end,
glm::ivec3& norm, glm::ivec3& norm,
glm::ivec3& iend glm::ivec3& iend
); );
glm::vec3 rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist); glm::vec3 rayCastToObstacle(const glm::vec3 &start, const glm::vec3 &dir, float maxDist);
const AABB* isObstacleAt(float x, float y, float z); const AABB* isObstacleAt(float x, float y, float z);
bool isSolidBlock(int32_t x, int32_t y, int32_t z); bool isSolidBlock(int32_t x, int32_t y, int32_t z);
+2 -2
View File
@@ -205,11 +205,11 @@ void Window::clearDepth() {
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
} }
void Window::setBgColor(glm::vec3 color) { void Window::setBgColor(const glm::vec3 &color) {
glClearColor(color.r, color.g, color.b, 1.0f); glClearColor(color.r, color.g, color.b, 1.0f);
} }
void Window::setBgColor(glm::vec4 color) { void Window::setBgColor(const glm::vec4 &color) {
glClearColor(color.r, color.g, color.b, color.a); glClearColor(color.r, color.g, color.b, color.a);
} }
+2 -2
View File
@@ -49,8 +49,8 @@ public:
static void clear(); static void clear();
static void clearDepth(); static void clearDepth();
static void setBgColor(glm::vec3 color); static void setBgColor(const glm::vec3 &color);
static void setBgColor(glm::vec4 color); static void setBgColor(const glm::vec4 &color);
static double time(); static double time();
static const char* getClipboardText(); static const char* getClipboardText();
static void setClipboardText(const char* text); static void setClipboardText(const char* text);