mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 12:29:18 +02:00
reformat: parameters can be made const
This commit is contained in:
@@ -28,7 +28,7 @@ fs::path settings_path()
|
||||
return p.empty() ? fs::path("eu07_editor.ini") : p;
|
||||
}
|
||||
|
||||
const char *scheme_to_string(editorSettings::movement_scheme scheme)
|
||||
const char *scheme_to_string(const editorSettings::movement_scheme scheme)
|
||||
{
|
||||
return scheme == editorSettings::movement_scheme::legacy ? "legacy" : "wsad";
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
bool save();
|
||||
|
||||
movement_scheme movement() const { return m_movement; }
|
||||
void movement(movement_scheme scheme) { m_movement = scheme; }
|
||||
void movement(const movement_scheme scheme) { m_movement = scheme; }
|
||||
|
||||
private:
|
||||
movement_scheme m_movement{movement_scheme::wsad};
|
||||
|
||||
@@ -84,7 +84,7 @@ bool editor_terrain::create(glm::dvec3 const &Center, int Cells, float CellSize,
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dvec3 editor_terrain::vertex_position(int Ix, int Iz) const
|
||||
glm::dvec3 editor_terrain::vertex_position(const int Ix, const int Iz) const
|
||||
{
|
||||
return glm::dvec3(
|
||||
m_x0 + static_cast<double>(Ix) * m_cellsize,
|
||||
@@ -105,7 +105,7 @@ glm::vec3 editor_terrain::vertex_normal(int Ix, int Iz) const
|
||||
return glm::normalize(n);
|
||||
}
|
||||
|
||||
world_vertex editor_terrain::make_vertex(int Ix, int Iz) const
|
||||
world_vertex editor_terrain::make_vertex(const int Ix, const int Iz) const
|
||||
{
|
||||
world_vertex v;
|
||||
v.position = vertex_position(Ix, Iz);
|
||||
@@ -115,7 +115,7 @@ world_vertex editor_terrain::make_vertex(int Ix, int Iz) const
|
||||
}
|
||||
|
||||
// emits one quad (two upward-facing triangles) spanning grid corners (X0,Z0)..(X1,Z1)
|
||||
void editor_terrain::emit_quad(int X0, int Z0, int X1, int Z1, std::vector<world_vertex> &Out) const
|
||||
void editor_terrain::emit_quad(const int X0, const int Z0, const int X1, const int Z1, std::vector<world_vertex> &Out) const
|
||||
{
|
||||
world_vertex const v00 = make_vertex(X0, Z0);
|
||||
world_vertex const v10 = make_vertex(X1, Z0);
|
||||
@@ -132,7 +132,7 @@ void editor_terrain::emit_quad(int X0, int Z0, int X1, int Z1, std::vector<world
|
||||
}
|
||||
|
||||
// true if every grid vertex inside the block stays within Error of the bilinear plane of its corners
|
||||
bool editor_terrain::block_flat(int X0, int Z0, int X1, int Z1, float Error) const
|
||||
bool editor_terrain::block_flat(const int X0, const int Z0, const int X1, const int Z1, const float Error) const
|
||||
{
|
||||
float const h00 = m_heights[index(X0, Z0)];
|
||||
float const h10 = m_heights[index(X1, Z0)];
|
||||
@@ -155,7 +155,7 @@ bool editor_terrain::block_flat(int X0, int Z0, int X1, int Z1, float Error) con
|
||||
}
|
||||
|
||||
// adaptive quadtree: collapse flat blocks into a single quad, otherwise split into four
|
||||
void editor_terrain::emit_block(int X0, int Z0, int X1, int Z1, float Error, std::vector<world_vertex> &Out) const
|
||||
void editor_terrain::emit_block(const int X0, const int Z0, const int X1, const int Z1, const float Error, std::vector<world_vertex> &Out) const
|
||||
{
|
||||
bool const splitx = (X1 - X0) > 1;
|
||||
bool const splitz = (Z1 - Z0) > 1;
|
||||
@@ -178,7 +178,7 @@ void editor_terrain::emit_block(int X0, int Z0, int X1, int Z1, float Error, std
|
||||
emit_block(xm, zm, X1, Z1, Error, Out);
|
||||
}
|
||||
|
||||
void editor_terrain::build_vertices(std::vector<world_vertex> &Out, bool Simplify) const
|
||||
void editor_terrain::build_vertices(std::vector<world_vertex> &Out, const bool Simplify) const
|
||||
{
|
||||
Out.clear();
|
||||
Out.reserve(static_cast<std::size_t>(m_cells) * m_cells * 6);
|
||||
@@ -194,7 +194,7 @@ void editor_terrain::build_vertices(std::vector<world_vertex> &Out, bool Simplif
|
||||
emit_quad(ix, iz, ix + 1, iz + 1, Out);
|
||||
}
|
||||
|
||||
void editor_terrain::regenerate(bool Simplify)
|
||||
void editor_terrain::regenerate(const bool Simplify)
|
||||
{
|
||||
if (!valid())
|
||||
return;
|
||||
@@ -233,7 +233,7 @@ void editor_terrain::regenerate(bool Simplify)
|
||||
m_vertexcount = gpuverts.size();
|
||||
}
|
||||
|
||||
void editor_terrain::optimize(float ErrorMetres)
|
||||
void editor_terrain::optimize(const float ErrorMetres)
|
||||
{
|
||||
m_simplify = true;
|
||||
m_simplify_error = (ErrorMetres > 0.0f ? ErrorMetres : 0.01f);
|
||||
@@ -269,14 +269,14 @@ void editor_terrain::destroy()
|
||||
m_heights.clear();
|
||||
}
|
||||
|
||||
bool editor_terrain::contains(double X, double Z) const
|
||||
bool editor_terrain::contains(const double X, const double Z) const
|
||||
{
|
||||
double const x1 = m_x0 + static_cast<double>(m_cells) * m_cellsize;
|
||||
double const z1 = m_z0 + static_cast<double>(m_cells) * m_cellsize;
|
||||
return (X >= m_x0 && X <= x1 && Z >= m_z0 && Z <= z1);
|
||||
}
|
||||
|
||||
double editor_terrain::height_at(double X, double Z) const
|
||||
double editor_terrain::height_at(const double X, const double Z) const
|
||||
{
|
||||
double const fx = (X - m_x0) / m_cellsize;
|
||||
double const fz = (Z - m_z0) / m_cellsize;
|
||||
@@ -298,7 +298,7 @@ double editor_terrain::height_at(double X, double Z) const
|
||||
return h11 + (1.0 - tx) * (h01 - h11) + (1.0 - tz) * (h10 - h11);
|
||||
}
|
||||
|
||||
bool editor_terrain::sculpt(double X, double Z, double Radius, double Strength)
|
||||
bool editor_terrain::sculpt(const double X, const double Z, const double Radius, const double Strength)
|
||||
{
|
||||
if (!valid() || Radius <= 0.0)
|
||||
return false;
|
||||
|
||||
@@ -80,7 +80,7 @@ class editor_terrain
|
||||
std::size_t full_triangles() const { return static_cast<std::size_t>(m_cells) * m_cells * 2; }
|
||||
|
||||
private:
|
||||
int index(int Ix, int Iz) const { return Iz * (m_cells + 1) + Ix; }
|
||||
int index(const int Ix, const int Iz) const { return Iz * (m_cells + 1) + Ix; }
|
||||
glm::dvec3 vertex_position(int Ix, int Iz) const;
|
||||
glm::vec3 vertex_normal(int Ix, int Iz) const;
|
||||
world_vertex make_vertex(int Ix, int Iz) const;
|
||||
|
||||
@@ -20,7 +20,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
// simulation-level streamer instance (see header)
|
||||
terrain_streamer EditorTerrain;
|
||||
|
||||
void terrain_streamer::configure(int Cells, float CellSize, int Radius, float BaseHeight, std::string const &Texture)
|
||||
void terrain_streamer::configure(const int Cells, const float CellSize, const int Radius, const float BaseHeight, std::string const &Texture)
|
||||
{
|
||||
m_cells = std::max(1, Cells);
|
||||
m_cellsize = std::max(0.1f, CellSize);
|
||||
@@ -29,19 +29,19 @@ void terrain_streamer::configure(int Cells, float CellSize, int Radius, float Ba
|
||||
m_texture = Texture;
|
||||
}
|
||||
|
||||
terrain_streamer::chunk_key terrain_streamer::key_at(double X, double Z) const
|
||||
terrain_streamer::chunk_key terrain_streamer::key_at(const double X, const double Z) const
|
||||
{
|
||||
double const size = chunk_world_size();
|
||||
return {static_cast<int>(std::floor(X / size)), static_cast<int>(std::floor(Z / size))};
|
||||
}
|
||||
|
||||
glm::dvec3 terrain_streamer::chunk_centre(int Cx, int Cz) const
|
||||
glm::dvec3 terrain_streamer::chunk_centre(const int Cx, const int Cz) const
|
||||
{
|
||||
double const size = chunk_world_size();
|
||||
return glm::dvec3((Cx + 0.5) * size, static_cast<double>(m_baseheight), (Cz + 0.5) * size);
|
||||
}
|
||||
|
||||
std::string terrain_streamer::chunk_path(int Cx, int Cz) const
|
||||
std::string terrain_streamer::chunk_path(const int Cx, const int Cz) const
|
||||
{
|
||||
return m_dir + "/chunk_" + std::to_string(Cx) + "_" + std::to_string(Cz) + ".etc";
|
||||
}
|
||||
@@ -60,7 +60,7 @@ bool terrain_streamer::chunk_on_disk(chunk_key const &Key)
|
||||
|
||||
// 16-bit chunk file: 'ETC1' | uint16 cells | float baseY | float step | (cells+1)^2 * uint16
|
||||
// where worldY = baseY + raw * step (per-chunk auto-scaled to fit the height range losslessly-ish)
|
||||
bool terrain_streamer::load_heights(int Cx, int Cz, std::vector<float> &Out) const
|
||||
bool terrain_streamer::load_heights(const int Cx, const int Cz, std::vector<float> &Out) const
|
||||
{
|
||||
std::ifstream f(chunk_path(Cx, Cz), std::ios::binary);
|
||||
if (!f)
|
||||
@@ -92,7 +92,7 @@ bool terrain_streamer::load_heights(int Cx, int Cz, std::vector<float> &Out) con
|
||||
return true;
|
||||
}
|
||||
|
||||
void terrain_streamer::save_heights(int Cx, int Cz, editor_terrain const &Terrain)
|
||||
void terrain_streamer::save_heights(const int Cx, const int Cz, editor_terrain const &Terrain)
|
||||
{
|
||||
auto const &h = Terrain.heights();
|
||||
if (h.empty())
|
||||
@@ -154,7 +154,7 @@ void terrain_streamer::update(glm::dvec3 const &CameraPos)
|
||||
int const cells = m_cells;
|
||||
float const cs = m_cellsize;
|
||||
editor_terrain::height_sampler sampler =
|
||||
[&loaded, x0, z0, cells, cs](double X, double Z, double &OutY) -> bool {
|
||||
[&loaded, x0, z0, cells, cs](const double X, const double Z, double &OutY) -> bool {
|
||||
int ix = static_cast<int>(std::lround((X - x0) / cs));
|
||||
int iz = static_cast<int>(std::lround((Z - z0) / cs));
|
||||
ix = std::clamp(ix, 0, cells);
|
||||
@@ -219,7 +219,7 @@ void terrain_streamer::collect(std::vector<editor_terrain *> &Out) const
|
||||
Out.push_back(entry.second.get());
|
||||
}
|
||||
|
||||
editor_terrain *terrain_streamer::terrain_at(double X, double Z) const
|
||||
editor_terrain *terrain_streamer::terrain_at(const double X, const double Z) const
|
||||
{
|
||||
auto const it = m_chunks.find(key_at(X, Z));
|
||||
if (it != m_chunks.end() && it->second && it->second->contains(X, Z))
|
||||
|
||||
@@ -30,16 +30,16 @@ class terrain_streamer
|
||||
|
||||
terrain_streamer() = default;
|
||||
|
||||
void active(bool State) { m_active = State; }
|
||||
void active(const bool State) { m_active = State; }
|
||||
bool active() const { return m_active; }
|
||||
|
||||
// per-chunk configuration (applied to chunks built from now on)
|
||||
void configure(int Cells, float CellSize, int Radius, float BaseHeight, std::string const &Texture);
|
||||
void simplify(bool Auto, float Error) { m_auto_optimize = Auto; m_simplify_error = Error; }
|
||||
void simplify(const bool Auto, const float Error) { m_auto_optimize = Auto; m_simplify_error = Error; }
|
||||
// safe to change while resident (only affects how far chunks load/unload)
|
||||
void radius(int Radius) { m_radius = Radius < 0 ? 0 : Radius; }
|
||||
void radius(const int Radius) { m_radius = Radius < 0 ? 0 : Radius; }
|
||||
// persist edited chunks to disk on unload, and load them back instead of regenerating
|
||||
void persist(bool Enable) { m_persist = Enable; }
|
||||
void persist(const bool Enable) { m_persist = Enable; }
|
||||
void directory(std::string const &Dir)
|
||||
{
|
||||
if (!Dir.empty() && Dir != m_dir)
|
||||
@@ -70,7 +70,7 @@ class terrain_streamer
|
||||
// persist an externally-authored chunk (e.g. a manual grid chunk being handed over to streaming)
|
||||
void save_chunk(int Cx, int Cz, editor_terrain const &Terrain);
|
||||
// chunk coordinate covering (X,Z)
|
||||
chunk_key key_for(double X, double Z) const { return key_at(X, Z); }
|
||||
chunk_key key_for(const double X, const double Z) const { return key_at(X, Z); }
|
||||
|
||||
std::size_t resident() const { return m_chunks.size(); }
|
||||
float chunk_world_size() const { return m_cells * m_cellsize; }
|
||||
|
||||
Reference in New Issue
Block a user