From bd79036d13732c2995359b9f3146ddb9150fa3e3 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 10 Dec 2020 08:40:08 +0100 Subject: [PATCH] Replaced all "long long" types with int64_t Replaced all "unsigned long long" types with uint64_t. These "new" types better communicate their meaning and they are guaranteed to behave the same on all platforms & compilers. --- src/libslic3r/GCode/GCodeProcessor.hpp | 3 +- src/libslic3r/SLAPrint.hpp | 3 +- src/slic3r/GUI/GCodeViewer.cpp | 22 +++++++------- src/slic3r/GUI/GCodeViewer.hpp | 37 ++++++++++++------------ src/slic3r/GUI/GLCanvas3D.cpp | 2 +- src/slic3r/GUI/GLCanvas3D.hpp | 11 +++---- src/slic3r/GUI/InstanceCheck.cpp | 9 +++--- tests/libnest2d/libnest2d_tests_main.cpp | 5 ++-- tests/sla_print/sla_print_tests.cpp | 5 ++-- 9 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 6367215cf..db221a360 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -7,6 +7,7 @@ #include "libslic3r/PrintConfig.hpp" #include "libslic3r/CustomGCode.hpp" +#include #include #include #include @@ -298,7 +299,7 @@ namespace Slic3r { PrintEstimatedTimeStatistics time_statistics; #if ENABLE_GCODE_VIEWER_STATISTICS - long long time{ 0 }; + int64_t time{ 0 }; void reset() { time = 0; diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 15292273f..f69ed7b8e 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_SLAPrint_hpp_ #define slic3r_SLAPrint_hpp_ +#include #include #include "PrintBase.hpp" #include "SLA/RasterBase.hpp" @@ -37,7 +38,7 @@ using _SLAPrintObjectBase = // Layers according to quantized height levels. This will be consumed by // the printer (rasterizer) in the SLAPrint class. -// using coord_t = long long; +// using coord_t = int64_t; enum SliceOrigin { soSupport, soModel }; diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 1c3b556a7..4e2c1c585 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1011,11 +1011,11 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) m_max_bounding_box.merge(m_paths_bounding_box.max + m_sequential_view.marker.get_bounding_box().size()[2] * Vec3d::UnitZ()); auto log_memory_usage = [this](const std::string& label, const std::vector>& vertices, const std::vector& indices) { - long long vertices_size = 0; + int64_t vertices_size = 0; for (size_t i = 0; i < vertices.size(); ++i) { vertices_size += SLIC3R_STDVEC_MEMSIZE(vertices[i], float); } - long long indices_size = 0; + int64_t indices_size = 0; for (size_t i = 0; i < indices.size(); ++i) { for (size_t j = 0; j < indices[i].size(); ++j) { indices_size += SLIC3R_STDVEC_MEMSIZE(indices[i][j], unsigned int); @@ -1432,7 +1432,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) buffer.vertices.count = buffer_vertices.size() / buffer.vertices.vertex_size_floats(); #if ENABLE_GCODE_VIEWER_STATISTICS m_statistics.vertices_gpu_size += buffer_vertices.size() * sizeof(float); - m_statistics.max_vertices_in_vertex_buffer = std::max(m_statistics.max_vertices_in_vertex_buffer, static_cast(buffer.vertices.count)); + m_statistics.max_vertices_in_vertex_buffer = std::max(m_statistics.max_vertices_in_vertex_buffer, static_cast(buffer.vertices.count)); #endif // ENABLE_GCODE_VIEWER_STATISTICS glsafe(::glGenBuffers(1, &buffer.vertices.id)); @@ -1538,7 +1538,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) ibuffer.count = buffer_indices.size(); #if ENABLE_GCODE_VIEWER_STATISTICS m_statistics.indices_gpu_size += ibuffer.count * sizeof(unsigned int); - m_statistics.max_indices_in_index_buffer = std::max(m_statistics.max_indices_in_index_buffer, static_cast(ibuffer.count)); + m_statistics.max_indices_in_index_buffer = std::max(m_statistics.max_indices_in_index_buffer, static_cast(ibuffer.count)); #endif // ENABLE_GCODE_VIEWER_STATISTICS if (ibuffer.count > 0) { @@ -2803,7 +2803,7 @@ void GCodeViewer::render_statistics() const ImGuiWrapper& imgui = *wxGetApp().imgui(); - auto add_time = [this, &imgui](const std::string& label, long long time) { + auto add_time = [this, &imgui](const std::string& label, int64_t time) { char buf[1024]; sprintf(buf, "%lld ms (%s)", time, get_time_dhms(static_cast(time) * 0.001f).c_str()); imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); @@ -2811,7 +2811,7 @@ void GCodeViewer::render_statistics() const imgui.text(buf); }; - auto add_memory = [this, &imgui](const std::string& label, long long memory) { + auto add_memory = [this, &imgui](const std::string& label, int64_t memory) { static const float mb = 1024.0f * 1024.0f; static const float inv_mb = 1.0f / mb; static const float gb = 1024.0f * mb; @@ -2826,7 +2826,7 @@ void GCodeViewer::render_statistics() const imgui.text(buf); }; - auto add_counter = [this, &imgui](const std::string& label, long long counter) { + auto add_counter = [this, &imgui](const std::string& label, int64_t counter) { char buf[1024]; sprintf(buf, "%lld", counter); imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); @@ -2890,11 +2890,11 @@ void GCodeViewer::render_statistics() const } #endif // ENABLE_GCODE_VIEWER_STATISTICS -void GCodeViewer::log_memory_used(const std::string& label, long long additional) const +void GCodeViewer::log_memory_used(const std::string& label, int64_t additional) const { if (Slic3r::get_logging_level() >= 5) { - long long paths_size = 0; - long long render_paths_size = 0; + int64_t paths_size = 0; + int64_t render_paths_size = 0; for (const TBuffer& buffer : m_buffers) { paths_size += SLIC3R_STDVEC_MEMSIZE(buffer.paths, Path); render_paths_size += SLIC3R_STDVEC_MEMSIZE(buffer.render_paths, RenderPath); @@ -2903,7 +2903,7 @@ void GCodeViewer::log_memory_used(const std::string& label, long long additional render_paths_size += SLIC3R_STDVEC_MEMSIZE(path.offsets, size_t); } } - long long layers_size = SLIC3R_STDVEC_MEMSIZE(m_layers.get_zs(), double); + int64_t layers_size = SLIC3R_STDVEC_MEMSIZE(m_layers.get_zs(), double); layers_size += SLIC3R_STDVEC_MEMSIZE(m_layers.get_endpoints(), Layers::Endpoints); BOOST_LOG_TRIVIAL(trace) << label << format_memsize_MB(additional + paths_size + render_paths_size + layers_size) diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 64a368efa..ac19f24ef 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -5,6 +5,7 @@ #include "libslic3r/GCode/GCodeProcessor.hpp" #include "GLModel.hpp" +#include #include namespace Slic3r { @@ -311,26 +312,26 @@ class GCodeViewer struct Statistics { // time - long long results_time{ 0 }; - long long load_time{ 0 }; - long long refresh_time{ 0 }; - long long refresh_paths_time{ 0 }; + int64_t results_time{ 0 }; + int64_t load_time{ 0 }; + int64_t refresh_time{ 0 }; + int64_t refresh_paths_time{ 0 }; // opengl calls - long long gl_multi_points_calls_count{ 0 }; - long long gl_multi_lines_calls_count{ 0 }; - long long gl_multi_triangles_calls_count{ 0 }; + int64_t gl_multi_points_calls_count{ 0 }; + int64_t gl_multi_lines_calls_count{ 0 }; + int64_t gl_multi_triangles_calls_count{ 0 }; // memory - long long results_size{ 0 }; - long long vertices_gpu_size{ 0 }; - long long indices_gpu_size{ 0 }; - long long paths_size{ 0 }; - long long render_paths_size{ 0 }; + int64_t results_size{ 0 }; + int64_t vertices_gpu_size{ 0 }; + int64_t indices_gpu_size{ 0 }; + int64_t paths_size{ 0 }; + int64_t render_paths_size{ 0 }; // other - long long travel_segments_count{ 0 }; - long long wipe_segments_count{ 0 }; - long long extrude_segments_count{ 0 }; - long long max_vertices_in_vertex_buffer{ 0 }; - long long max_indices_in_index_buffer{ 0 }; + int64_t travel_segments_count{ 0 }; + int64_t wipe_segments_count{ 0 }; + int64_t extrude_segments_count{ 0 }; + int64_t max_vertices_in_vertex_buffer{ 0 }; + int64_t max_indices_in_index_buffer{ 0 }; void reset_all() { reset_times(); @@ -509,7 +510,7 @@ private: return role < erCount && (m_extrusions.role_visibility_flags & (1 << role)) != 0; } bool is_visible(const Path& path) const { return is_visible(path.role); } - void log_memory_used(const std::string& label, long long additional = 0) const; + void log_memory_used(const std::string& label, int64_t additional = 0) const; }; } // namespace GUI diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index e5aaad822..368405b46 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1681,7 +1681,7 @@ void GLCanvas3D::render() imgui.begin(std::string("Render statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); imgui.text("Last frame:"); ImGui::SameLine(); - long long average = m_render_stats.get_average(); + int64_t average = m_render_stats.get_average(); imgui.text(std::to_string(average)); ImGui::SameLine(); imgui.text("ms"); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 6ebf72dd1..e45ea1188 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "GLToolbar.hpp" #include "Event.hpp" @@ -322,12 +323,12 @@ class GLCanvas3D #if ENABLE_RENDER_STATISTICS class RenderStats { - std::queue> m_frames; - long long m_curr_total{ 0 }; + std::queue> m_frames; + int64_t m_curr_total{ 0 }; public: - void add_frame(long long frame) { - long long now = wxGetLocalTimeMillis().GetValue(); + void add_frame(int64_t frame) { + int64_t now = wxGetLocalTimeMillis().GetValue(); if (!m_frames.empty() && now - m_frames.front().first > 1000) { m_curr_total -= m_frames.front().second; m_frames.pop(); @@ -335,7 +336,7 @@ class GLCanvas3D m_curr_total += frame; m_frames.push({ now, frame }); } - long long get_average() const { return m_frames.empty() ? 0 : m_curr_total / m_frames.size(); } + int64_t get_average() const { return m_frames.empty() ? 0 : m_curr_total / m_frames.size(); } }; #endif // ENABLE_RENDER_STATISTICS diff --git a/src/slic3r/GUI/InstanceCheck.cpp b/src/slic3r/GUI/InstanceCheck.cpp index d4dfa1f35..100fd5c53 100644 --- a/src/slic3r/GUI/InstanceCheck.cpp +++ b/src/slic3r/GUI/InstanceCheck.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -82,10 +83,10 @@ namespace instance_check_internal if (wndTextString.find(L"PrusaSlicer") != std::wstring::npos && classNameString == L"wxWindowNR") { //check if other instances has same instance hash //if not it is not same version(binary) as this version - HANDLE handle = GetProp(hwnd, L"Instance_Hash_Minor"); - unsigned long long other_instance_hash = PtrToUint(handle); - unsigned long long other_instance_hash_major; - unsigned long long my_instance_hash = GUI::wxGetApp().get_instance_hash_int(); + HANDLE handle = GetProp(hwnd, L"Instance_Hash_Minor"); + uint64_t other_instance_hash = PtrToUint(handle); + uint64_t other_instance_hash_major; + uint64_t my_instance_hash = GUI::wxGetApp().get_instance_hash_int(); handle = GetProp(hwnd, L"Instance_Hash_Major"); other_instance_hash_major = PtrToUint(handle); other_instance_hash_major = other_instance_hash_major << 32; diff --git a/tests/libnest2d/libnest2d_tests_main.cpp b/tests/libnest2d/libnest2d_tests_main.cpp index e0692f4e7..a0f192460 100644 --- a/tests/libnest2d/libnest2d_tests_main.cpp +++ b/tests/libnest2d/libnest2d_tests_main.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include "printer_parts.hpp" @@ -472,7 +473,7 @@ TEST_CASE("ArrangeRectanglesLoose", "[Nesting]") namespace { using namespace libnest2d; -template +template void exportSVG(const char *loc, It from, It to) { static const char* svg_header = @@ -512,7 +513,7 @@ R"raw( // } } -template +template void exportSVG(std::vector>& result, int idx = 0) { exportSVG((std::string("out") + std::to_string(idx) + ".svg").c_str(), result.begin(), result.end()); diff --git a/tests/sla_print/sla_print_tests.cpp b/tests/sla_print/sla_print_tests.cpp index c1941c8d9..bdd5731dc 100644 --- a/tests/sla_print/sla_print_tests.cpp +++ b/tests/sla_print/sla_print_tests.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "sla_test_utils.hpp" @@ -63,7 +64,7 @@ TEST_CASE("Support point generator should be deterministic if seeded", point_gen.execute(slices, slicegrid); auto get_chksum = [](const std::vector &pts){ - long long chksum = 0; + int64_t chksum = 0; for (auto &pt : pts) { auto p = scaled(pt.pos); chksum += p.x() + p.y() + p.z(); @@ -72,7 +73,7 @@ TEST_CASE("Support point generator should be deterministic if seeded", return chksum; }; - long long checksum = get_chksum(point_gen.output()); + int64_t checksum = get_chksum(point_gen.output()); size_t ptnum = point_gen.output().size(); REQUIRE(point_gen.output().size() > 0);