From 40f6b554b53dbc069cb97626787b125bcca19601 Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 22 Nov 2026 17:27:24 -0500 Subject: [PATCH] Initialize with = instead of braces, and drop const from local autos Scalars get = 0, = false or = nullptr. Standard containers and strings rely on their constructors. Other types get = {} or = value, and lists keep = {...}. glm types are left alone until they're replaced. --- src/asset_store.h | 4 +- src/audio.cpp | 8 +- src/audio_data.cpp | 2 +- src/audio_data.h | 4 +- src/audio_stream.h | 12 +- src/canvas.cpp | 8 +- src/canvas.h | 20 +- src/cli.cpp | 40 ++-- src/dialog.cpp | 2 +- src/dialog.h | 10 +- src/document.cpp | 118 +++++----- src/document.h | 98 ++++----- src/edit/animations.cpp | 58 ++--- src/edit/content.cpp | 28 +-- src/edit/edit.h | 44 ++-- src/edit/flatten.cpp | 18 +- src/edit/frames.cpp | 44 ++-- src/edit/isaac.cpp | 10 +- src/edit/spritesheets.cpp | 14 +- src/edit/tracks.cpp | 10 +- src/file.cpp | 4 +- src/file.h | 2 +- src/font.h | 2 +- src/framebuffer.h | 8 +- src/friends.h | 6 +- src/icon.h | 2 +- src/image.cpp | 22 +- src/image.h | 12 +- src/loader.cpp | 8 +- src/loader.h | 14 +- src/localization.h | 2 +- src/log.cpp | 30 +-- src/log.h | 18 +- src/main.cpp | 8 +- src/manager.cpp | 28 +-- src/manager.h | 62 +++--- src/math_util.cpp | 4 +- src/model/common.h | 50 ++--- src/model/draw.cpp | 24 +-- src/model/draw.h | 38 ++-- src/model/frames.cpp | 22 +- src/model/json.cpp | 90 ++++---- src/model/model.cpp | 60 +++--- src/model/model.h | 276 ++++++++++++------------ src/model/xml.cpp | 208 +++++++++--------- src/model/xml.h | 22 +- src/pack.cpp | 18 +- src/path.cpp | 12 +- src/playback.h | 8 +- src/render.cpp | 46 ++-- src/render.h | 48 ++--- src/resources.h | 4 +- src/selection.cpp | 8 +- src/selection.h | 6 +- src/settings.cpp | 10 +- src/settings.h | 2 +- src/shader.cpp | 52 ++--- src/shader.h | 50 ++--- src/snapshots.cpp | 4 +- src/snapshots.h | 14 +- src/socket.cpp | 10 +- src/socket.h | 8 +- src/state.cpp | 8 +- src/state.h | 16 +- src/subprocess.cpp | 2 +- src/subprocess.h | 2 +- src/texture.cpp | 6 +- src/tool.h | 14 +- src/ui/about.cpp | 8 +- src/ui/about.h | 48 ++--- src/ui/actions.cpp | 2 +- src/ui/actions.h | 18 +- src/ui/animation_preview.cpp | 20 +- src/ui/animation_preview.h | 16 +- src/ui/animations.cpp | 58 ++--- src/ui/autosave_restore.h | 6 +- src/ui/canvas_view.cpp | 4 +- src/ui/canvas_view.h | 38 ++-- src/ui/change_all_frame_properties.cpp | 20 +- src/ui/change_all_frame_properties.h | 2 +- src/ui/configure.cpp | 4 +- src/ui/configure.h | 6 +- src/ui/dockspace.h | 26 +-- src/ui/documents.cpp | 14 +- src/ui/documents.h | 8 +- src/ui/draw.cpp | 4 +- src/ui/frame_properties.cpp | 6 +- src/ui/generate_animation_from_grid.cpp | 2 +- src/ui/generate_animation_from_grid.h | 4 +- src/ui/input.cpp | 12 +- src/ui/item_properties.cpp | 4 +- src/ui/item_properties.h | 4 +- src/ui/items.cpp | 10 +- src/ui/layout.h | 4 +- src/ui/libraries.cpp | 2 +- src/ui/multiselect.h | 6 +- src/ui/panel.cpp | 22 +- src/ui/panel.h | 88 ++++---- src/ui/popup.h | 16 +- src/ui/regions.cpp | 18 +- src/ui/render_animation.cpp | 6 +- src/ui/render_animation.h | 2 +- src/ui/selectable.cpp | 6 +- src/ui/shaders.cpp | 8 +- src/ui/shaders.h | 10 +- src/ui/shortcut.cpp | 2 +- src/ui/sounds.cpp | 2 +- src/ui/spritesheet_editor.cpp | 2 +- src/ui/spritesheet_editor.h | 2 +- src/ui/spritesheets.cpp | 2 +- src/ui/taskbar.cpp | 4 +- src/ui/taskbar.h | 44 ++-- src/ui/theme.cpp | 26 +-- src/ui/timeline.h | 124 +++++------ src/ui/timeline_children.cpp | 8 +- src/ui/timeline_context.h | 54 ++--- src/ui/timeline_edit.cpp | 32 +-- src/ui/timeline_frames.cpp | 36 ++-- src/ui/timeline_menus.cpp | 12 +- src/ui/timeline_selection.cpp | 12 +- src/ui/timeline_tracks.cpp | 8 +- src/ui/toast.h | 6 +- src/ui/tree.cpp | 2 +- src/ui/tree.h | 10 +- src/uid.h | 2 +- src/vector.h | 2 +- src/working_directory.cpp | 4 +- src/working_directory.h | 2 +- tests/assets.cpp | 12 +- tests/common.h | 10 +- tests/corpus_local.cpp | 8 +- tests/draw.cpp | 22 +- tests/invariants.cpp | 14 +- tests/operations.cpp | 34 +-- tests/render/render.cpp | 18 +- tests/roundtrip.cpp | 4 +- tests/selection.cpp | 18 +- tests/undo.cpp | 8 +- 138 files changed, 1500 insertions(+), 1500 deletions(-) diff --git a/src/asset_store.h b/src/asset_store.h index 955906b..5f06b7c 100644 --- a/src/asset_store.h +++ b/src/asset_store.h @@ -10,8 +10,8 @@ // entries live until the document closes so any step can be restored. class AssetStore { - std::unordered_map images{}; - std::unordered_map audio{}; + std::unordered_map images; + std::unordered_map audio; public: std::uint64_t image_add(Image); diff --git a/src/audio.cpp b/src/audio.cpp index 9926967..f0cca6c 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -8,10 +8,10 @@ struct AudioEntry { - MIX_Audio* audio{}; - std::vector tracks{}; // one per overlapping play, reused once finished + MIX_Audio* audio = nullptr; + std::vector tracks; // one per overlapping play, reused once finished std::atomic squares[2]{}; - std::atomic sampleCount{}; + std::atomic sampleCount = {}; }; // Sums the squares of the left/right samples the track plays, for its levels. @@ -28,7 +28,7 @@ entry->sampleCount += samples / channels; } - static std::unordered_map entries{}; + static std::unordered_map entries; static MIX_Mixer* audio_mixer_get() { diff --git a/src/audio_data.cpp b/src/audio_data.cpp index 551390b..726695d 100644 --- a/src/audio_data.cpp +++ b/src/audio_data.cpp @@ -15,7 +15,7 @@ AudioData::AudioData(const std::filesystem::path& path) { std::ifstream file(path, std::ios::binary); - std::vector data{std::istreambuf_iterator(file), {}}; + std::vector data = {std::istreambuf_iterator(file), {}}; *this = AudioData(data.data(), data.size()); } diff --git a/src/audio_data.h b/src/audio_data.h index 266b8c1..b0916a5 100644 --- a/src/audio_data.h +++ b/src/audio_data.h @@ -8,8 +8,8 @@ // Encoded audio file bytes. uid identifies the bytes so playback state can be cached by it. struct AudioData { - std::vector bytes{}; - std::uint64_t uid{}; + std::vector bytes; + std::uint64_t uid = 0; AudioData() = default; AudioData(const unsigned char*, size_t); diff --git a/src/audio_stream.h b/src/audio_stream.h index a589712..d7a830d 100644 --- a/src/audio_stream.h +++ b/src/audio_stream.h @@ -8,12 +8,12 @@ static void callback(void*, MIX_Mixer*, const SDL_AudioSpec*, float*, int); public: - std::vector stream{}; - SDL_AudioSpec spec{}; - int callbackSamples{}; - Uint64 captureStartCounter{}; - Uint64 firstCallbackCounter{}; - bool isFirstCallbackCaptured{}; + std::vector stream; + SDL_AudioSpec spec = {}; + int callbackSamples = 0; + Uint64 captureStartCounter = 0; + Uint64 firstCallbackCounter = 0; + bool isFirstCallbackCaptured = false; AudioStream(MIX_Mixer*); }; diff --git a/src/canvas.cpp b/src/canvas.cpp index 60b6ed8..bed40bc 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -165,7 +165,7 @@ using namespace glm; return; } - for (const auto& uniform : shader.uniforms) + for (auto& uniform : shader.uniforms) { if (uniform.location == -1) continue; @@ -279,7 +279,7 @@ using namespace glm; { auto blurred = draw; auto& frame = blurred.frame; - TextureBlur blur{.region = vec4(frame.crop, frame.crop + frame.size) / vec4(textureSize, textureSize)}; + TextureBlur blur = {.region = vec4(frame.crop, frame.crop + frame.size) / vec4(textureSize, textureSize)}; if (frame.blur > 0.0f && frame.size.x > 0.0f && frame.size.y > 0.0f) { auto canvasArea = std::abs(glm::determinant(glm::mat2(draw.parent * draw_quad_model_get(draw)))); @@ -300,7 +300,7 @@ using namespace glm; const std::function& image_get, const std::function& shader_get) const { - for (const auto& draw : animation_draws_get(model, animation, options)) + for (auto& draw : animation_draws_get(model, animation, options)) { if (draw.type != DrawType::LAYER) continue; auto& frame = draw.frame; @@ -342,7 +342,7 @@ using namespace glm; if (zoom > ZOOM_LEVELS.back()) return ZOOM_LEVELS.back(); auto levelCount = (int)ZOOM_LEVELS.size(); - int levelIndex{}; + int levelIndex = 0; if (levelDelta > 0) { auto it = std::upper_bound(ZOOM_LEVELS.begin(), ZOOM_LEVELS.end(), zoom); diff --git a/src/canvas.h b/src/canvas.h index 63c3dad..0f6fa04 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -16,7 +16,7 @@ // A box blur `radius` texels wide each way over the texture's `region` (UV min, max); outside it is clear. struct TextureBlur { - float radius{}; + float radius = 0; glm::vec4 region{}; }; @@ -53,15 +53,15 @@ static constexpr auto BORDER_DASH_OFFSET = 0.0f; static constexpr auto PIVOT_COLOR = COLOR_PINK; - GLuint axisVAO{}; - GLuint axisVBO{}; - GLuint rectVAO{}; - GLuint rectVBO{}; - GLuint gridVAO{}; - GLuint gridVBO{}; - GLuint textureVAO{}; - GLuint textureVBO{}; - GLuint textureEBO{}; + GLuint axisVAO = 0; + GLuint axisVBO = 0; + GLuint rectVAO = 0; + GLuint rectVBO = 0; + GLuint gridVAO = 0; + GLuint gridVBO = 0; + GLuint textureVAO = 0; + GLuint textureVBO = 0; + GLuint textureEBO = 0; Canvas(); Canvas(glm::vec2); diff --git a/src/cli.cpp b/src/cli.cpp index ea81321..a51a892 100644 --- a/src/cli.cpp +++ b/src/cli.cpp @@ -49,9 +49,9 @@ options: struct Arguments { - std::string command{}; - std::filesystem::path file{}; - std::map options{}; + std::string command; + std::filesystem::path file; + std::map options; std::optional get(const std::string& name) const { @@ -78,7 +78,7 @@ options: { if (argc < 3) return {}; // Absolute, so a bare file name still has a folder for the paths in it. - Arguments arguments{.command = argv[1], .file = std::filesystem::absolute(path_from_utf8(argv[2]))}; + Arguments arguments = {.command = argv[1], .file = std::filesystem::absolute(path_from_utf8(argv[2]))}; for (int i = 3; i < argc; ++i) { std::string name = argv[i]; @@ -95,7 +95,7 @@ options: { auto text = arguments.get("background").value_or("transparent"); if (text.starts_with('#')) text.erase(0, 1); - unsigned value{}; + unsigned value = 0; if (text.size() != HEX_RGB_LENGTH || std::from_chars(text.data(), text.data() + text.size(), value, HEX_BASE).ec != std::errc{}) return {}; @@ -118,7 +118,7 @@ options: { auto animations = model.animations_get(); auto name = arguments.get("animation").value_or(model.animations.defaultAnimation); - int index{-1}; + int index = -1; if (std::from_chars(name.data(), name.data() + name.size(), index).ec == std::errc{} && index >= 0 && index < (int)animations.size()) return animations[index]; @@ -130,8 +130,8 @@ options: static int info_print(const Arguments& arguments) { - Model model{}; - std::string error{}; + Model model = {}; + std::string error; if (!model_load(model, arguments.file, &error)) { std::println(stderr, "could not load {}: {}", path_to_utf8(arguments.file), error); @@ -154,26 +154,26 @@ options: WorkingDirectory workingDirectory(arguments.file.parent_path()); std::println("spritesheets:"); - for (const auto& spritesheet : content.spritesheets) + for (auto& spritesheet : content.spritesheets) { auto image = Image(path_case_insensitive_find(spritesheet.path)); auto status = image.is_valid() ? std::format("{}x{}", image.size.x, image.size.y) : std::string("missing"); std::println(" #{} {} ({}), {} regions", spritesheet.id, path_to_utf8(spritesheet.path), status, spritesheet.regions.size()); } - for (const auto& library : content.libraries) + for (auto& library : content.libraries) std::println("library #{} {}", library.id, path_to_utf8(library.path)); - for (const auto& layer : content.layers) + for (auto& layer : content.layers) if (layer.is_animation()) std::println("layer #{} {} (animation {}, library #{})", layer.id, layer.name, layer.animation, layer.libraryId); else std::println("layer #{} {} (spritesheet #{})", layer.id, layer.name, layer.spritesheetId); - for (const auto& null : content.nulls) + for (auto& null : content.nulls) std::println("null #{} {}", null.id, null.name); - for (const auto& event : content.events) + for (auto& event : content.events) std::println("event #{} {}", event.id, event.name); - for (const auto& sound : content.sounds) + for (auto& sound : content.sounds) std::println("sound #{} {}", sound.id, path_to_utf8(sound.path)); auto issues = isaac_issues_get(model); @@ -195,14 +195,14 @@ options: return 2; } - HeadlessGL gl{}; + HeadlessGL gl = {}; if (!gl.is_valid()) { std::println(stderr, "could not create an OpenGL 3.3 context"); return 1; } - std::string error{}; + std::string error; Document document(arguments.file, false, &error); if (!document.is_valid()) { @@ -229,7 +229,7 @@ options: isRootTransform); }; auto outPath = path_from_utf8(*out); - std::error_code ec{}; + std::error_code ec; std::filesystem::create_directories(type_is_folder(arguments) ? outPath : outPath.parent_path(), ec); if (arguments.command == "frame") @@ -296,9 +296,9 @@ options: return 2; } // The game's copy bakes what it can't draw with OpenGL (and the document's shaders compile only with it). - std::optional gl{}; + std::optional gl; if (format == "xml") gl.emplace(); - std::string error{}; + std::string error; Document document(arguments.file, false, &error); auto fileUtf8 = path_to_utf8(arguments.file); if (!document.is_valid()) @@ -308,7 +308,7 @@ options: } if (!error.empty()) std::println(stderr, "{}:\n{}", fileUtf8, error); auto out = std::filesystem::absolute(arguments.get("out").transform(path_from_utf8).value_or(arguments.file)); - Options options{}; + Options options = {}; options.isJson = format == "json"; if (document.save(out, &error, options)) return 0; std::println(stderr, "could not write {}: {}", path_to_utf8(out), error); diff --git a/src/dialog.cpp b/src/dialog.cpp index ca7e9d2..8d8612c 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -101,7 +101,7 @@ void Dialog::file_explorer_open(const std::filesystem::path& path) { if (path.empty()) return; - std::error_code ec{}; + std::error_code ec; auto absolutePath = std::filesystem::absolute(path, ec); auto isFile = std::filesystem::is_regular_file(absolutePath, ec); #ifdef _WIN32 diff --git a/src/dialog.h b/src/dialog.h index c45449f..a210fb7 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -79,11 +79,11 @@ #undef DIALOG_LIST - SDL_Window* window{}; - std::filesystem::path path{}; - std::vector paths{}; - Type type{NONE}; - int selectedFilter{-1}; + SDL_Window* window = nullptr; + std::filesystem::path path; + std::vector paths; + Type type = NONE; + int selectedFilter = -1; Dialog() = default; Dialog(SDL_Window*); diff --git a/src/document.cpp b/src/document.cpp index b78e919..4b832ff 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -40,7 +40,7 @@ using namespace glm; static std::filesystem::path absolute_path_get(const std::filesystem::path& directory, const std::filesystem::path& path) { WorkingDirectory workingDirectory(directory); - std::error_code ec{}; + std::error_code ec; auto absolutePath = std::filesystem::weakly_canonical(directory / path_case_insensitive_find(path), ec); return ec ? directory / path : absolutePath; } @@ -48,22 +48,22 @@ using namespace glm; static void library_load(const std::filesystem::path& path, LibraryData& library) { library = {}; - std::string errorString{}; + std::string errorString; model_load(library.model, path, &errorString); // Why it couldn't load, or what a JSON library couldn't read. if (!errorString.empty()) toast_log(Level::WARNING, TOAST_LIBRARY_ISSUES, path_to_utf8(path), errorString); - std::error_code ec{}; + std::error_code ec; library.writeTime = std::filesystem::last_write_time(path, ec); WorkingDirectory workingDirectory(path.parent_path()); - for (const auto& spritesheet : library.model.content.spritesheets) + for (auto& spritesheet : library.model.content.spritesheets) library.images.emplace(spritesheet.id, Image(path_case_insensitive_find(spritesheet.path))); - for (const auto& sound : library.model.content.sounds) + for (auto& sound : library.model.content.sounds) library.sounds.emplace(sound.id, AudioData(path_case_insensitive_find(sound.path))); } static uint64_t document_tab_id_next() { - static uint64_t next{1}; + static uint64_t next = 1; return next++; } @@ -91,8 +91,8 @@ using namespace glm; static std::string shader_source_lines_get(std::string_view label, std::string_view source) { std::string output = std::format("\n{}:\n", label); - int lineNumber{1}; - std::size_t position{}; + int lineNumber = 1; + std::size_t position = 0; while (position <= source.size()) { auto end = source.find('\n', position); @@ -142,7 +142,7 @@ using namespace glm; void resources_sync(Document& document, const Items& items, std::map& keys, std::unordered_map& paths, Load&& load) { - std::set validIds{}; + std::set validIds; WorkingDirectory workingDirectory(document.directory_get()); for (auto& element : items) { @@ -228,7 +228,7 @@ using namespace glm; { return [this](const Model& source, const std::filesystem::path& spritesheetPath) { - for (const auto& [libraryPath, library] : libraries) + for (auto& [libraryPath, library] : libraries) if (&library.model == &source) return path_backslash_replace( path_make_relative(absolute_path_get(libraryPath.parent_path(), spritesheetPath), @@ -241,7 +241,7 @@ using namespace glm; // can't show worked around. bool Document::file_write(const std::filesystem::path& path, std::string* errorString, Options options) { - std::optional game{}; + std::optional game; if (!options.isJson) { game = animation_layers_flatten(model, library_resolver_get(), spritesheet_path_resolver_get()); @@ -340,8 +340,8 @@ using namespace glm; return shader_erase(); } - std::string vertexSource{}; - std::string fragmentSource{}; + std::string vertexSource; + std::string fragmentSource; auto isVertexLoaded = shader_source_load(*this, shaderElement->vertex, vertexSource, LABEL_VERTEX, status, TEXTURE_COMPATIBILITY_VERTEX); auto isFragmentLoaded = @@ -359,7 +359,7 @@ using namespace glm; } if (!result.isLinked || !result.id) return shader_erase(); - ShaderProgram runtime{}; + ShaderProgram runtime = {}; runtime.id = result.id; runtime.uniforms = std::move(result.uniforms); if (uniform_configs_trim(*shaderElement, runtime.uniforms)) hash_set(); @@ -380,7 +380,7 @@ using namespace glm; [&](int id, const std::filesystem::path& path) { sound_set(id, AudioData(path)); }); - std::set validShaderIds{}; + std::set validShaderIds; WorkingDirectory workingDirectory(directory_get()); for (auto& shaderElement : model.content.shaders) { @@ -407,11 +407,11 @@ using namespace glm; std::erase_if(shaderFragmentPaths, is_invalid); // Vector images drawn from spritesheet images no longer in use are dropped. - std::set imageUids{}; - for (const auto& spritesheet : model.content.spritesheets) + std::set imageUids; + for (auto& spritesheet : model.content.spritesheets) if (auto image = texture_get(spritesheet.id)) imageUids.insert(image->uid); - for (const auto& [path, library] : libraries) - for (const auto& [id, image] : library.images) + for (auto& [path, library] : libraries) + for (auto& [id, image] : library.images) imageUids.insert(image.uid); std::erase_if(vectorImages, [&](const auto& pair) { return !imageUids.contains(pair.first.first); }); } @@ -454,7 +454,7 @@ using namespace glm; { auto library = libraryId == -1 ? nullptr : library_get(model, libraryId); auto source = libraryId == -1 ? &model : library ? &library->model : nullptr; - std::vector names{}; + std::vector names; if (source) for (auto [index, animation] : source->animations_get()) names.push_back(animation->name); @@ -464,9 +464,9 @@ using namespace glm; // A layer draw's spritesheet image, at `scale` (see vector_image_get). const Image* Document::draw_image_get(const Draw& draw, float scale) const { - const Image* image{}; + const Image* image = nullptr; if (!draw.source || draw.source == &model) image = texture_get(draw.spritesheetId); - for (const auto& [path, library] : libraries) + for (auto& [path, library] : libraries) if (&library.model == draw.source) if (auto found = library.images.find(draw.spritesheetId); found != library.images.end()) image = &found->second; return vector_image_get(image, scale); @@ -490,14 +490,14 @@ using namespace glm; void Document::libraries_sync() { libraryLinks.clear(); - std::set reached{}; + std::set reached; std::vector> pending{ {&model, std::filesystem::absolute(directory_get())}}; while (!pending.empty()) { auto [from, directory] = pending.back(); pending.pop_back(); - for (const auto& library : from->content.libraries) + for (auto& library : from->content.libraries) { auto path = absolute_path_get(directory, library.path); auto [it, isNew] = libraries.try_emplace(path); @@ -516,10 +516,10 @@ using namespace glm; // Reloads the libraries whose file changed on disk; true when any did. bool Document::libraries_reload() { - bool isReloaded{}; + bool isReloaded = false; for (auto& [path, library] : libraries) { - std::error_code ec{}; + std::error_code ec; auto time = std::filesystem::last_write_time(path, ec); if (ec || time == library.writeTime) continue; library_load(path, library); @@ -566,11 +566,11 @@ using namespace glm; // Every sound that may be playing: this document's and its libraries'. std::vector Document::sounds_get() const { - std::vector result{}; - for (const auto& [id, key] : sounds) + std::vector result; + for (auto& [id, key] : sounds) if (auto sound = sound_get(id)) result.push_back(sound); - for (const auto& [path, library] : libraries) - for (const auto& [id, sound] : library.sounds) + for (auto& [path, library] : libraries) + for (auto& [id, sound] : library.sounds) result.push_back(&sound); return result; } @@ -580,8 +580,8 @@ using namespace glm; std::vector Document::trigger_sounds_get(const Animation& animation, int time, int index) const { - std::vector result{}; - for (const auto& [source, trigger, layerId] : + std::vector result; + for (auto& [source, trigger, layerId] : animation_triggers_get(model, animation, time, library_resolver_get())) { if (trigger.soundIds.empty()) continue; @@ -589,9 +589,9 @@ using namespace glm; auto soundIndex = std::min( index >= 0 ? (std::size_t)index % count : (std::size_t)random_in_range(0.0f, (float)count), count - 1); auto soundId = trigger.soundIds[soundIndex]; - const AudioData* sound{}; + const AudioData* sound = nullptr; if (source == &model) sound = sound_get(soundId); - for (const auto& [path, library] : libraries) + for (auto& [path, library] : libraries) if (&library.model == source) if (auto found = library.sounds.find(soundId); found != library.sounds.end()) sound = &found->second; if (sound) result.push_back(sound); @@ -652,7 +652,7 @@ using namespace glm; void Document::spritesheet_hashes_sync() { - std::set validIds{}; + std::set validIds; for (auto& spritesheet : model.content.spritesheets) { validIds.insert(spritesheet.id); @@ -693,7 +693,7 @@ using namespace glm; std::vector Document::references_get(const Uids& uids) const { UidIndex index(model); - std::vector references{}; + std::vector references; for (auto uid : uids) if (auto reference = index.reference_get(uid)) references.push_back(*reference); return references; @@ -713,8 +713,8 @@ using namespace glm; // Spritesheets with unsaved pixel edits that their autosave copy doesn't have yet. std::set Document::spritesheets_autosave_dirty_get() { - std::set ids{}; - for (const auto& spritesheet : model.content.spritesheets) + std::set ids; + for (auto& spritesheet : model.content.spritesheets) { auto id = spritesheet.id; auto autosaveHash = spritesheetAutosaveHashes.find(id); @@ -728,7 +728,7 @@ using namespace glm; // After a crash, autosaved spritesheets come back as unsaved edits; their files are left as they are. void Document::spritesheets_autosave_restore() { - for (const auto& spritesheet : model.content.spritesheets) + for (auto& spritesheet : model.content.spritesheets) { auto path = spritesheet_autosave_path_get(spritesheet); if (!is_path_exist(path)) continue; @@ -738,8 +738,8 @@ using namespace glm; void Document::spritesheets_autosave_clear() { - std::error_code ec{}; - for (const auto& spritesheet : model.content.spritesheets) + std::error_code ec; + for (auto& spritesheet : model.content.spritesheets) std::filesystem::remove(spritesheet_autosave_path_get(spritesheet), ec); spritesheetAutosaveHashes.clear(); } @@ -761,7 +761,7 @@ using namespace glm; spritesheets_changed_get(); if (auto spritesheet = item_get(model.content.spritesheets, id)) { - std::error_code ec{}; + std::error_code ec; std::filesystem::remove(spritesheet_autosave_path_get(*spritesheet), ec); } spritesheetAutosaveHashes.erase(id); @@ -770,11 +770,11 @@ using namespace glm; // Spritesheets whose file changed on disk since it was last loaded or saved; ones with unsaved edits are left alone. std::set Document::spritesheets_changed_get() { - std::set ids{}; + std::set ids; WorkingDirectory workingDirectory(directory_get()); - for (const auto& spritesheet : model.content.spritesheets) + for (auto& spritesheet : model.content.spritesheets) { - std::error_code ec{}; + std::error_code ec; auto time = std::filesystem::last_write_time(path_case_insensitive_find(spritesheet.path), ec); if (ec) continue; auto [it, isNew] = textureWriteTimes.try_emplace(spritesheet.id, time); @@ -803,7 +803,7 @@ using namespace glm; // Rasterizes SVG spritesheets: each is written as a PNG beside it (as drawn now), and points at the PNG. void Document::spritesheets_vector_convert(const std::set& ids) { - std::set converted{}; + std::set converted; edit_apply(EDIT_CONVERT_SVG_SPRITESHEETS, [&](Model& model) { @@ -890,7 +890,7 @@ using namespace glm; // Combo entries for a content kind (regions are those of layer `layerId`'s spritesheet); all but spritesheets start with None. Choices Document::choices_get(SelectionKind kind, int layerId) const { - Choices choices{}; + Choices choices = {}; if (kind != SelectionKind::SPRITESHEETS) { choices.ids.push_back(-1); @@ -898,7 +898,7 @@ using namespace glm; } auto add = [&](const auto& items, auto&& label_get) { - for (const auto& item : items) + for (auto& item : items) { choices.ids.push_back(item.id); choices.labels.push_back(label_get(item)); @@ -1014,7 +1014,7 @@ using namespace glm; std::set Document::animations_selected_get() const { - std::set indices{}; + std::set indices; for (auto reference : selected_get(SelectionKind::ANIMATIONS)) indices.insert(reference.animationIndex); return indices; @@ -1022,7 +1022,7 @@ using namespace glm; void Document::animations_selected_set(const std::set& indices) { - std::set references{}; + std::set references; for (auto index : indices) references.insert({index}); selected_set(SelectionKind::ANIMATIONS, references); @@ -1030,7 +1030,7 @@ using namespace glm; std::set Document::item_frame_references_get(Reference itemReference) const { - std::set result{}; + std::set result; itemReference.frameIndex = -1; auto item = itemReference.itemType == NONE ? nullptr : model.track_get(itemReference); for (int frameIndex = 0; item && frameIndex < (int)item->frames.size(); ++frameIndex) @@ -1047,7 +1047,7 @@ using namespace glm; if (auto reference = reference_get(); selectedItems.empty() && reference.itemType != NONE) selectedItems.insert(item_reference_get(reference)); - std::set result{}; + std::set result; for (auto itemReference : selectedItems) result.merge(item_frame_references_get(itemReference)); return result; @@ -1066,7 +1066,7 @@ using namespace glm; void Document::frame_references_set(std::set frameReferences) { std::erase_if(frameReferences, [&](const Reference& frame) { return !model.frame_get(frame); }); - std::set tracks{}; + std::set tracks; for (auto frame : frameReferences) tracks.insert(item_reference_get(frame)); selected_set(SelectionKind::FRAMES, frameReferences); @@ -1088,7 +1088,7 @@ using namespace glm; if (selectedReferences.empty() && reference.itemType != NONE) selectedReferences.insert(item_reference_get(reference)); - std::vector result{}; + std::vector result; for (auto itemReference : selectedReferences) { if (itemReference.itemType != LAYER) return {}; @@ -1102,11 +1102,11 @@ using namespace glm; auto& items = model.content.spritesheets; auto directory = directory_get(); - std::vector> loaded{}; + std::vector> loaded; for (auto& path : paths) { auto storagePath = path_backslash_handle(path); - std::optional workingDirectory{}; + std::optional workingDirectory; if (!storagePath.is_absolute()) workingDirectory.emplace(directory); auto texture = Image(path_case_insensitive_find(storagePath)); if (!texture.is_valid()) @@ -1120,7 +1120,7 @@ using namespace glm; edit_begin(EDIT_ADD_SPRITESHEET); - std::set added{}; + std::set added; for (auto& [relativePath, texture] : loaded) { auto& element = @@ -1143,7 +1143,7 @@ using namespace glm; edit_begin(EDIT_ADD_SOUND); - std::set added{}; + std::set added; for (auto& path : paths) { if (path.empty()) continue; @@ -1163,7 +1163,7 @@ using namespace glm; void Document::libraries_add(const std::vector& paths) { - std::set added{}; + std::set added; edit_apply( EDIT_ADD_LIBRARY, [&](Model& model) diff --git a/src/document.h b/src/document.h index 70ff7ee..8ad9019 100644 --- a/src/document.h +++ b/src/document.h @@ -26,76 +26,76 @@ // Ids and labels for a combo box of content items. struct Choices { - std::vector ids{}; - std::vector labels{}; + std::vector ids; + std::vector labels; }; // A linked .anm2, loaded read-only: its document, its spritesheets' images and its sounds. struct LibraryData { - Model model{}; - std::map images{}; - std::map sounds{}; - std::filesystem::file_time_type writeTime{}; + Model model = {}; + std::map images; + std::map sounds; + std::filesystem::file_time_type writeTime; }; // A step into an animation layer's child: the parent's tab, animation, time and layer track it was taken from, // and the animation it led to (in this tab, or a library's). struct ChildStep { - std::uint64_t tabId{}; - int animationIndex{-1}; - float frameTime{}; - Reference layer{}; - std::string animationName{}; - std::string layerName{}; - int childAnimationIndex{-1}; + std::uint64_t tabId = 0; + int animationIndex = -1; + float frameTime = 0; + Reference layer = {}; + std::string animationName; + std::string layerName; + int childAnimationIndex = -1; }; struct DocumentData { - std::filesystem::path path{}; - uint64_t tabId{}; - Snapshots snapshots{}; - AssetStore assets{}; - std::map textureDrafts{}; - int changeAllFramePropertiesRegionId{-1}; - int changeAllFramePropertiesShaderId{-1}; + std::filesystem::path path; + uint64_t tabId = 0; + Snapshots snapshots = {}; + AssetStore assets = {}; + std::map textureDrafts; + int changeAllFramePropertiesRegionId = -1; + int changeAllFramePropertiesShaderId = -1; - float previewZoom{200}; + float previewZoom = 200; glm::vec2 previewPan{}; glm::vec2 editorPan{}; - float editorZoom{200}; - int overlayIndex{-1}; - uint64_t overlayDocumentId{}; + float editorZoom = 200; + int overlayIndex = -1; + uint64_t overlayDocumentId = 0; - uint64_t hash{}; - uint64_t saveHash{}; - uint64_t autosaveHash{}; - double lastAutosaveTime{}; - bool isValid{true}; - bool isOpen{true}; - bool isForceDirty{false}; - bool isVectorKept{}; + uint64_t hash = 0; + uint64_t saveHash = 0; + uint64_t autosaveHash = 0; + double lastAutosaveTime = 0; + bool isValid = true; + bool isOpen = true; + bool isForceDirty = false; + bool isVectorKept = false; std::vector childSteps{}; // the steps that led to the animation being edited (the breadcrumb) // asked this session to keep SVG spritesheets in a Rebirth document - std::unordered_map spritesheetHashes{}; - std::unordered_map spritesheetSaveHashes{}; - std::unordered_map spritesheetAutosaveHashes{}; - std::unordered_map texturePaths{}; - std::unordered_map textureWriteTimes{}; - std::unordered_map soundPaths{}; - std::map shaderVertexPaths{}; - std::map shaderFragmentPaths{}; - std::map shaders{}; + std::unordered_map spritesheetHashes; + std::unordered_map spritesheetSaveHashes; + std::unordered_map spritesheetAutosaveHashes; + std::unordered_map texturePaths; + std::unordered_map textureWriteTimes; + std::unordered_map soundPaths; + std::map shaderVertexPaths; + std::map shaderFragmentPaths; + std::map shaders; // Libraries by absolute path, and what each (document, library id) points at (nullptr is this document). - std::map libraries{}; - std::map, const LibraryData*> libraryLinks{}; - std::uint64_t librariesRevision{}; // counts library loads, for anything drawn from them + std::map libraries; + std::map, const LibraryData*> libraryLinks; + std::uint64_t librariesRevision = 0; // counts library loads, for anything drawn from them // Vector spritesheets drawn again for zooms past 100%, by (image uid, power-of-two level). - mutable std::map, Image> vectorImages{}; - bool isAnimationPreviewSet{false}; - bool isSpritesheetEditorSet{false}; + mutable std::map, Image> vectorImages; + bool isAnimationPreviewSet = false; + bool isSpritesheetEditorSet = false; }; class Document : public DocumentData @@ -120,8 +120,8 @@ SNAPSHOT_STEP_STATE_FIELDS #undef X std::string& message = current.message; - EditTarget editTarget{EditTarget::NONE}; - UidIndex index{}; + EditTarget editTarget = EditTarget::NONE; + UidIndex index = {}; Document(const std::filesystem::path&, bool = false, std::string* = nullptr); Document(const Document&) = delete; diff --git a/src/edit/animations.cpp b/src/edit/animations.cpp index 41da0f0..5681e5f 100644 --- a/src/edit/animations.cpp +++ b/src/edit/animations.cpp @@ -8,15 +8,15 @@ std::set animation_group_ids_get(const Model& model) { - std::set ids{}; - for (const auto& entry : model.animations.entries) + std::set ids; + for (auto& entry : model.animations.entries) if (auto group = std::get_if(&entry)) ids.insert(group->id); return ids; } std::set animation_group_indices_get(const Model& model, int groupId) { - std::set indices{}; + std::set indices; for (int i = 0; i < model.animations_count_get(); ++i) if (model.animation_group_id_get(i) == groupId) indices.insert(i); return indices; @@ -25,14 +25,14 @@ // Animations and whole groups taken out of the list, remembering the order they had. struct AnimationsTaken { - std::vector animations{}; - std::vector groups{}; + std::vector animations; + std::vector groups; }; static AnimationsTaken animations_take(Model& model, const std::set& indices, const std::set& groupIds) { - AnimationsTaken taken{}; - int index{}; + AnimationsTaken taken = {}; + int index = 0; std::erase_if(model.animations.entries, [&](AnimationEntry& entry) { @@ -64,9 +64,9 @@ // Where an animation with this uid sits: its top-level entry, and its group (or nullptr) and position there. struct AnimationPlace { - int entry{-1}; - AnimationGroup* group{}; - int position{-1}; + int entry = -1; + AnimationGroup* group = nullptr; + int position = -1; }; static AnimationPlace animation_place_get(Model& model, std::uint64_t uid) @@ -133,18 +133,18 @@ // An empty copy of a track list: same tracks and groups, no frames. static std::vector track_entries_shell_get(const std::vector& entries) { - std::vector shell{}; + std::vector shell; auto track_shell_get = [](const Track& track) { return Track{.type = track.type, .id = track.id, .isVisible = track.isVisible}; }; - for (const auto& entry : entries) + for (auto& entry : entries) if (auto track = std::get_if(&entry)) shell.emplace_back(track_shell_get(*track)); else { - const auto& group = std::get(entry); + auto& group = std::get(entry); TrackGroup copy{ .id = group.id, .name = group.name, .isExpanded = group.isExpanded, .isVisible = group.isVisible}; - for (const auto& groupTrack : group.tracks) + for (auto& groupTrack : group.tracks) copy.tracks.push_back(track_shell_get(groupTrack)); shell.emplace_back(std::move(copy)); } @@ -154,7 +154,7 @@ // Adds an animation with the same (empty) tracks as the template animation. Uids animation_add(Model& model, int index, int groupId, int templateIndex, const std::string& name) { - Animation animation{.name = name}; + Animation animation = {.name = name}; if (auto source = model.animation_get(templateIndex)) { animation.layers = track_entries_shell_get(source->layers); @@ -187,8 +187,8 @@ auto taken = animations_take(model, indices, groupIds); if (taken.animations.empty() && taken.groups.empty()) return {}; - Uids uids{}; - for (const auto& animation : taken.animations) + Uids uids = {}; + for (auto& animation : taken.animations) uids.push_back(animation->uid); auto& entries = model.animations.entries; @@ -250,9 +250,9 @@ auto existingGroupIds = animation_group_ids_get(model); auto nextGroupId = existingGroupIds.empty() ? 0 : *existingGroupIds.rbegin() + 1; - Uids uids{}; - std::vector loose{}; - std::vector placed{}; + Uids uids = {}; + std::vector loose; + std::vector placed; for (auto& entry : entries) if (auto animation = std::get_if(&entry)) { @@ -265,7 +265,7 @@ auto& group = std::get(entry); group.id = nextGroupId++; groupIds.insert(group.id); - for (const auto& animation : group.animations) + for (auto& animation : group.animations) uids.push_back(animation->uid); placed.push_back(std::move(entry)); } @@ -285,8 +285,8 @@ static void track_merge(Track& destination, const Track& source, Merge type) { - std::vector frames{}; - for (const auto& frame : source.frames) + std::vector frames; + for (auto& frame : source.frames) frames.push_back(frame_clone(frame)); switch (type) { @@ -310,15 +310,15 @@ static void track_entries_merge(std::vector& destination, const std::vector& source, Merge type) { - std::map groupRemap{}; - std::set matchedGroupIds{}; - int nextGroupId{}; + std::map groupRemap; + std::set matchedGroupIds; + int nextGroupId = 0; groups_each(destination, [&](const TrackGroup& group) { nextGroupId = std::max(nextGroupId, group.id + 1); }); groups_each(source, [&](const TrackGroup& sourceGroup) { - TrackGroup* matched{}; + TrackGroup* matched = nullptr; groups_each(destination, [&](TrackGroup& group) { @@ -345,14 +345,14 @@ tracks_each(source, [&](const Track& sourceTrack, const TrackGroup* sourceGroup) { - TrackGroup* group{}; + TrackGroup* group = nullptr; if (sourceGroup) groups_each(destination, [&](TrackGroup& candidate) { if (candidate.id == groupRemap[sourceGroup->id]) group = &candidate; }); - Track* existing{}; + Track* existing = nullptr; if (group) { for (auto& track : group->tracks) diff --git a/src/edit/content.cpp b/src/edit/content.cpp index 093c686..a4b2085 100644 --- a/src/edit/content.cpp +++ b/src/edit/content.cpp @@ -29,7 +29,7 @@ { auto animation = model.animation_get(animationIndex); if (!animation) return; - std::vector> tracks{}; + std::vector> tracks; tracks_each(animation->layers, [&](const Track& track, const TrackGroup* group) { @@ -48,7 +48,7 @@ Uids regions_generate(Model& model, const std::set& animationIndices, const std::set& frames, const std::string& format, RegionFrameMapping mapping) { - std::unordered_map regionNumbers{}; + std::unordered_map regionNumbers; auto frame_apply = [&](Frame& frame, int spritesheetId) { auto& regions = item_get(model.content.spritesheets, spritesheetId)->regions; @@ -86,7 +86,7 @@ [&](Frame& frame, int spritesheetId) { if (frame.regionId != -1) return; - for (const auto& region : item_get(model.content.spritesheets, spritesheetId)->regions) + for (auto& region : item_get(model.content.spritesheets, spritesheetId)->regions) if (is_region_matched(region, frame)) { frame.regionId = region.id; @@ -131,8 +131,8 @@ { std::erase_if(items, [&](const auto& item) { return ids.contains(item.id); }); }; auto layer_ids_get = [&](auto&& is_removed) { - std::set layerIds{}; - for (const auto& layer : content.layers) + std::set layerIds; + for (auto& layer : content.layers) if (is_removed(layer)) layerIds.insert(layer.id); return layerIds; }; @@ -239,7 +239,7 @@ // Appends grid frames to each layer track (optionally making a region per frame) and fits the animation length. Uids animation_grid_generate(Model& model, const std::vector& tracks, const GridOptions& options) { - Uids uids{}; + Uids uids = {}; for (auto reference : tracks) { if (!model.track_get(reference)) continue; @@ -273,8 +273,8 @@ // given animations. Uids frames_change_apply(Model& model, const ChangeTargets& targets, FrameChange change, ChangeType type) { - std::map> frames{}; - std::set wholeTracks{}; + std::map> frames; + std::set wholeTracks; for (auto reference : targets.references) { auto index = std::exchange(reference.frameIndex, -1); @@ -288,7 +288,7 @@ }; auto whole_apply = [&](Track& track) { - std::set indices{}; + std::set indices; for (int i = 0; i < (int)track.frames.size(); ++i) indices.insert(i); frames_change(track, change, track.type, type, indices, is_animation_layer(track)); @@ -315,17 +315,17 @@ bool file_merge(Model& model, const std::filesystem::path& path, const std::filesystem::path& directory, FileMergePreset preset) { - Model source{}; + Model source = {}; if (!model_load(source, path) || !source.isValid) return false; auto isAppendAsNew = preset == FILE_MERGE_PRESET_APPEND_AS_NEW; - std::map> remaps{}; + std::map> remaps; auto& content = model.content; auto path_remap = [&](const std::filesystem::path& original) { if (directory.empty() || original.empty()) return original; - std::error_code ec{}; + std::error_code ec; auto absolute = original.is_absolute() ? original : std::filesystem::weakly_canonical(path.parent_path() / original, ec); if (ec) absolute = path.parent_path() / original; @@ -429,7 +429,7 @@ auto entries_remap = [&](std::vector& entries, ElementType type) { - std::vector result{}; + std::vector result; auto track_keep = [&](Track& track) { track.id = id_remap(type, track.id); @@ -469,7 +469,7 @@ return -1; }; - std::string defaultAnimationName{}; + std::string defaultAnimationName; for (auto [index, incoming] : source.animations_get()) { auto processed = animation_build(*incoming); diff --git a/src/edit/edit.h b/src/edit/edit.h index 382248e..805b97d 100644 --- a/src/edit/edit.h +++ b/src/edit/edit.h @@ -19,18 +19,18 @@ struct RowTarget { - bool isGroup{}; - int type{NONE}; - int id{-1}; - int groupId{-1}; + bool isGroup = false; + int type = NONE; + int id = -1; + int groupId = -1; }; struct RootBakeOptions { - bool isRoundScale{}; - bool isRoundRotation{}; - bool isMatchRootInterpolation{}; - bool isUseRootPivot{}; + bool isRoundScale = false; + bool isRoundRotation = false; + bool isMatchRootInterpolation = false; + bool isUseRootPivot = false; }; struct GridOptions @@ -38,28 +38,28 @@ glm::ivec2 start{}; glm::ivec2 size{}; glm::vec2 pivot{}; - int columns{}; - int count{}; - int delay{}; - bool isMakeRegions{}; - std::string regionNameFormat{}; + int columns = 0; + int count = 0; + int delay = 0; + bool isMakeRegions = false; + std::string regionNameFormat; }; struct ChangeTargets { - std::set references{}; - std::set animations{}; - bool isRoot{}; - bool isLayers{}; - bool isNulls{}; + std::set references; + std::set animations; + bool isRoot = false; + bool isLayers = false; + bool isNulls = false; }; struct AnimationTarget { - int animationIndex{-1}; - int groupId{-1}; - bool isAfter{}; - bool isInto{}; + int animationIndex = -1; + int groupId = -1; + bool isAfter = false; + bool isInto = false; }; // Frame properties that can be copied on their own. diff --git a/src/edit/flatten.cpp b/src/edit/flatten.cpp index 96dd67b..6578c2f 100644 --- a/src/edit/flatten.cpp +++ b/src/edit/flatten.cpp @@ -48,7 +48,7 @@ { return layer.is_animation() && (layerIds.empty() || layerIds.contains(layer.id)); }; if (std::ranges::none_of(content.layers, is_flattened)) return model; - std::map, int> spritesheetIds{}; + std::map, int> spritesheetIds; auto spritesheet_id_get = [&](const Model* source, int id) { if (source == &model) return id; @@ -62,7 +62,7 @@ }; // (animation layer, source, source layer) -> the plain layer standing in for it. - std::map, int> plainIds{}; + std::map, int> plainIds; auto layer_id_get = [&](const Draw& draw) { auto [it, isNew] = plainIds.try_emplace({draw.id, draw.source, draw.sourceId}); @@ -84,10 +84,10 @@ { auto layer = item_get(content.layers, track.id); if (!layer || !is_flattened(*layer)) return std::vector{track}; - std::map> frames{}; - std::vector order{}; + std::map> frames; + std::vector order; for (int time = 0; time < source.frameNum; ++time) - for (const auto& draw : animation_draws_get(model, source, {.time = (float)time, .library_get = library_get})) + for (auto& draw : animation_draws_get(model, source, {.time = (float)time, .library_get = library_get})) { if (draw.type != DrawType::LAYER || draw.id != track.id || draw.frame.size == glm::vec2()) continue; auto id = layer_id_get(draw); @@ -95,7 +95,7 @@ if (isNew) order.push_back(id); it->second[time] = draw_frame_bake(draw); } - std::vector tracks{}; + std::vector tracks; for (auto id : order) { auto& baked = tracks.emplace_back(Track{.type = ItemType::LAYER, .id = id, .isVisible = track.isVisible}); @@ -108,7 +108,7 @@ return tracks; }; - std::vector entries{}; + std::vector entries; for (auto& entry : source.layers) if (auto track = std::get_if(&entry)) for (auto& flat : tracks_flatten(*track)) @@ -127,8 +127,8 @@ auto triggers = source.triggers; for (int time = 0; time < source.frameNum; ++time) { - std::vector eventIds{}; - for (const auto& fire : animation_triggers_get(model, source, time, library_get)) + std::vector eventIds; + for (auto& fire : animation_triggers_get(model, source, time, library_get)) { auto layer = item_get(content.layers, fire.layerId); if (!layer || !is_flattened(*layer)) continue; diff --git a/src/edit/frames.cpp b/src/edit/frames.cpp index e68158b..81546b0 100644 --- a/src/edit/frames.cpp +++ b/src/edit/frames.cpp @@ -9,7 +9,7 @@ std::map> frames_by_track_get(const std::set& frames) { - std::map> result{}; + std::map> result; for (auto frame : frames) { auto index = std::exchange(frame.frameIndex, -1); @@ -20,7 +20,7 @@ static Uids frames_uids_get(const Track& track, int start, int count) { - Uids uids{}; + Uids uids = {}; for (int i = std::max(start, 0); i < std::min(start + count, (int)track.frames.size()); ++i) uids.push_back(track.frames[i].uid); return uids; @@ -34,7 +34,7 @@ if (track->type == ItemType::TRIGGER) { if (std::ranges::any_of(track->frames, [&](const Frame& trigger) { return trigger.atFrame == time; })) return {}; - Frame trigger{}; + Frame trigger = {}; trigger.atFrame = time; track->frames.push_back(trigger); frames_sort_by_at_frame(*track); @@ -62,15 +62,15 @@ Uids frames_duplicate(Model& model, const std::set& frames, Reference focus) { - Uids uids{}; - std::uint64_t focusUid{}; + Uids uids = {}; + std::uint64_t focusUid = 0; for (auto& [trackReference, indices] : frames_by_track_get(frames)) { auto track = model.track_edit(trackReference); if (!track) continue; - std::vector copies{}; - int lastIndex{-1}; + std::vector copies; + int lastIndex = -1; for (auto index : indices) { if (index < 0 || index >= (int)track->frames.size()) continue; @@ -82,7 +82,7 @@ } if (copies.empty()) continue; - for (const auto& copy : copies) + for (auto& copy : copies) uids.push_back(copy.uid); track->frames.insert(track->frames.begin() + lastIndex + 1, copies.begin(), copies.end()); } @@ -100,7 +100,7 @@ auto track = model.track_edit(trackReference); if (!track || indices.size() < 2) continue; - std::vector reversed{}; + std::vector reversed; for (auto it = indices.rbegin(); it != indices.rend(); ++it) if (*it >= 0 && *it < (int)track->frames.size()) { @@ -116,13 +116,13 @@ Uids frames_bake(Model& model, const std::set& frames, int interval, bool isRoundScale, bool isRoundRotation) { - Uids uids{}; + Uids uids = {}; for (auto& [trackReference, indices] : frames_by_track_get(frames)) { auto track = model.track_edit(trackReference); if (!track) continue; - int inserted{}; + int inserted = 0; for (auto originalIndex : indices) { auto index = originalIndex + inserted; @@ -163,7 +163,7 @@ // Splits each of the frames that spans the time (last first, so earlier references stay valid). Uids frames_split(Model& model, const std::set& references, int time) { - Uids uids{}; + Uids uids = {}; for (auto it = references.rbegin(); it != references.rend(); ++it) std::ranges::copy(frame_split(model, *it, time), std::back_inserter(uids)); return uids; @@ -178,12 +178,12 @@ auto targetUid = targetTrack->uid; insertIndex = std::clamp(insertIndex, 0, (int)targetTrack->frames.size()); - std::vector moved{}; + std::vector moved; for (auto& [trackReference, indices] : frames_by_track_get(frames)) { auto track = model.track_edit(trackReference); if (!track) continue; - std::vector trackMoved{}; + std::vector trackMoved; for (auto it = indices.rbegin(); it != indices.rend(); ++it) { if (*it < 0 || *it >= (int)track->frames.size()) continue; @@ -290,7 +290,7 @@ Uids frames_property_set(Model& model, const std::set& references, FrameProperty property, const Frame& source) { - Uids uids{}; + Uids uids = {}; for (auto reference : references) if (is_frame_property_valid(property, (ItemType)reference.itemType)) if (auto frame = model.frame_edit(reference)) @@ -315,7 +315,7 @@ auto trigger = model.frame_edit(reference); if (!trigger) return {}; trigger->atFrame = atFrame; - for (const auto& other : model.track_get(reference)->frames) + for (auto& other : model.track_get(reference)->frames) if (&other != trigger && other.atFrame == trigger->atFrame) trigger->atFrame--; return {}; } @@ -351,7 +351,7 @@ frame.regionId = -1; auto& track = *model.track_edit(reference); - Uids uids{}; + Uids uids = {}; if (track.type != ItemType::TRIGGER) { track.frames.insert(track.frames.begin() + insertIndex, frames.begin(), frames.end()); @@ -383,7 +383,7 @@ if (!rootTrack) return {}; auto root = *rootTrack; - std::vector> spans{}; + std::vector> spans; for (auto index : rootIndices) if (index >= 0 && index < (int)root.frames.size()) { @@ -413,13 +413,13 @@ } } - Uids uids{}; - std::vector rewritten{}; - int defaultDuration{}; + Uids uids = {}; + std::vector rewritten; + int defaultDuration = 0; auto default_push = [&]() { if (defaultDuration <= 0) return; - Frame frame{}; + Frame frame = {}; frame.duration = std::max(defaultDuration, FRAME_DURATION_MIN); uids.push_back(frame.uid); rewritten.push_back(frame); diff --git a/src/edit/isaac.cpp b/src/edit/isaac.cpp index 2910f80..a52b554 100644 --- a/src/edit/isaac.cpp +++ b/src/edit/isaac.cpp @@ -36,7 +36,7 @@ static void depths_bridge(Model& model) { auto& content = model.content; - std::map, int> copyIds{}; + std::map, int> copyIds; auto copy_id_get = [&](int layerId, int depth) { auto [it, isNew] = copyIds.try_emplace({layerId, depth}); @@ -57,7 +57,7 @@ if (!isUsed) continue; auto& animation = *model.animation_edit(i); - std::vector tracks{}; + std::vector tracks; for (auto& entry : animation.layers) if (auto track = std::get_if(&entry)) tracks.push_back(std::move(*track)); @@ -73,7 +73,7 @@ } // Each track's place in drawing order: (its position + depth, depth), kept in position order when equal. - std::vector, Track>> placed{}; + std::vector, Track>> placed; auto shown_set = [](Track& track, int depth) { for (auto& frame : track.frames) @@ -85,8 +85,8 @@ for (int position = 0; position < (int)tracks.size(); ++position) { auto& track = tracks[position]; - std::set depths{}; - for (const auto& frame : track.frames) + std::set depths; + for (auto& frame : track.frames) if (frame.depth != 0) depths.insert(frame.depth); for (auto depth : depths) { diff --git a/src/edit/spritesheets.cpp b/src/edit/spritesheets.cpp index ee0e34a..629668e 100644 --- a/src/edit/spritesheets.cpp +++ b/src/edit/spritesheets.cpp @@ -15,7 +15,7 @@ auto spritesheet = item_get(model.content.spritesheets, spritesheetId); if (!spritesheet || !source.is_valid() || source.pixels.empty()) return false; - bool isChanged{}; + bool isChanged = false; for (auto id : ids) { auto region = item_get(spritesheet->regions, id); @@ -63,7 +63,7 @@ { struct PackItem { - int regionId{-1}; + int regionId = -1; glm::ivec2 source{}; glm::ivec2 size{}; }; @@ -72,7 +72,7 @@ if (!spritesheet || !sheet.is_valid() || sheet.pixels.empty()) return {}; padding = std::max(0, padding); - std::vector items{}; + std::vector items; for (auto& region : spritesheet->regions) { auto minPoint = glm::ivec2(glm::min(region.crop, region.crop + region.size)); @@ -96,7 +96,7 @@ std::vector positions{}; if (!rects_pack(sizes, packedSize, positions) || packedSize.x <= 0 || packedSize.y <= 0) return {}; - std::vector parts{}; + std::vector parts; for (int i = 0; i < (int)items.size(); ++i) parts.push_back({&sheet, items[i].source, items[i].size, positions[i] + padding}); for (auto& region : spritesheet->regions) @@ -119,12 +119,12 @@ auto base = item_get(model.content.spritesheets, baseId); auto mergedSize = image_get(baseId)->size; std::vector parts{{image_get(baseId), {}, mergedSize, {}}}; - std::unordered_map> regionIdMap{}; + std::unordered_map> regionIdMap; auto location_region_add = [&](int sourceId, glm::ivec2 crop, glm::ivec2 size) { auto source = item_get(model.content.spritesheets, sourceId); - Region region{}; + Region region = {}; region.id = item_next_id_get(base->regions); auto stem = path_to_utf8(source->path.stem()); region.name = stem.empty() ? std::format("#{}", sourceId) : stem; @@ -158,7 +158,7 @@ } } - std::unordered_map layerSpritesheetBefore{}; + std::unordered_map layerSpritesheetBefore; for (auto& layer : model.content.layers) if (ids.contains(layer.spritesheetId)) { diff --git a/src/edit/tracks.cpp b/src/edit/tracks.cpp index 6176911..c16b6ef 100644 --- a/src/edit/tracks.cpp +++ b/src/edit/tracks.cpp @@ -38,9 +38,9 @@ auto entries = track_entries_edit(model, animationIndex, type); if (!entries) return {}; - int nextId{}; + int nextId = 0; groups_each(*entries, [&](const TrackGroup& group) { nextId = std::max(nextId, group.id + 1); }); - TrackGroup group{.id = nextId, .name = name}; + TrackGroup group = {.id = nextId, .name = name}; auto insertIndex = -1; for (int i = 0; i < (int)entries->size(); ++i) @@ -68,8 +68,8 @@ auto entries = track_entries_edit(model, animationIndex, type); if (!entries) return {}; - std::vector movedTracks{}; - std::vector movedGroups{}; + std::vector movedTracks; + std::vector movedGroups; std::erase_if(*entries, [&](TrackEntry& entry) { @@ -138,7 +138,7 @@ movedTracks.clear(); } - std::vector topMoved{}; + std::vector topMoved; for (auto& track : movedTracks) topMoved.emplace_back(std::move(track)); topMoved.insert(topMoved.end(), std::make_move_iterator(movedGroups.begin()), diff --git a/src/file.cpp b/src/file.cpp index f65bf41..68a5ca9 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -11,7 +11,7 @@ close(); #ifdef _WIN32 - std::wstring wideMode{}; + std::wstring wideMode = {}; if (mode) for (auto character = mode; *character; ++character) wideMode.push_back((wchar_t)*character); @@ -48,7 +48,7 @@ if (!file) return false; output->clear(); - std::array buffer{}; + std::array buffer = {}; while (true) { auto read = std::fread(buffer.data(), 1, buffer.size(), file.get()); diff --git a/src/file.h b/src/file.h index e1ddd5e..cfbf408 100644 --- a/src/file.h +++ b/src/file.h @@ -17,7 +17,7 @@ explicit operator bool() const; private: - FILE* handle{}; + FILE* handle = nullptr; }; bool file_text_load(const std::filesystem::path&, std::string*, const char* mode = "rb"); diff --git a/src/font.h b/src/font.h index 3e15cfc..2c6355f 100644 --- a/src/font.h +++ b/src/font.h @@ -19,7 +19,7 @@ class Font { - ImFont* pointer{}; + ImFont* pointer = nullptr; public: Font(); diff --git a/src/framebuffer.h b/src/framebuffer.h index 22c7110..363b0f6 100644 --- a/src/framebuffer.h +++ b/src/framebuffer.h @@ -13,12 +13,12 @@ OVERLAY, }; - GLuint fbo{}; - GLuint rbo{}; - GLuint texture{}; + GLuint fbo = 0; + GLuint rbo = 0; + GLuint texture = 0; glm::vec2 size{}; glm::vec2 previousSize{}; - GLint filter{GL_LINEAR}; // how the texture is sampled when drawn scaled; takes effect on the next resize + GLint filter = GL_LINEAR; // how the texture is sampled when drawn scaled; takes effect on the next resize Framebuffer(); ~Framebuffer(); diff --git a/src/friends.h b/src/friends.h index 16dbdce..f937009 100644 --- a/src/friends.h +++ b/src/friends.h @@ -4,9 +4,9 @@ struct FriendInfo { - const char* name{}; - const Embed* png{}; - const Embed* anm2{}; + const char* name = nullptr; + const Embed* png = nullptr; + const Embed* anm2 = nullptr; }; #define FRIENDS_LIST \ diff --git a/src/icon.h b/src/icon.h index ca1919c..2157f49 100644 --- a/src/icon.h +++ b/src/icon.h @@ -65,7 +65,7 @@ struct IconInfo { - const Embed* svg{}; + const Embed* svg = nullptr; glm::ivec2 size{}; }; diff --git a/src/image.cpp b/src/image.cpp index 0f8ae94..3ce887a 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -199,7 +199,7 @@ using namespace glm; // A copy of a block of the image (transparent where it falls outside). Image Image::region_get(glm::ivec2 min, glm::ivec2 regionSize) const { - Image region{}; + Image region = {}; region.size = regionSize; region.pixels.assign((std::size_t)regionSize.x * regionSize.y * IMAGE_CHANNELS, 0); pixels_copy(*this, min, region, {}, regionSize); @@ -209,11 +209,11 @@ using namespace glm; // Base64 of bytes, for an image embedded in an SVG. static std::string base64_get(const std::vector& bytes) { - std::string text{}; + std::string text; for (std::size_t i = 0; i < bytes.size(); i += BASE64_GROUP_BYTES) { auto count = std::min(BASE64_GROUP_BYTES, bytes.size() - i); - std::uint32_t value{}; + std::uint32_t value = 0; for (std::size_t j = 0; j < BASE64_GROUP_BYTES; ++j) value = value << BYTE_BITS | (j < count ? bytes[i + j] : 0u); for (std::size_t j = 0; j <= BASE64_GROUP_BYTES; ++j) @@ -238,7 +238,7 @@ using namespace glm; { if (!image.is_vector()) { - std::vector png{}; + std::vector png; stbi_write_png_to_func( [](void* context, void* data, int count) { @@ -254,13 +254,13 @@ using namespace glm; return; } - pugi::xml_document source{}; + pugi::xml_document source; source.load_string(image.svg->c_str()); auto sourceRoot = source.document_element(); if (!sourceRoot) return; // Every id in the drawing gets the prefix, and so does every reference to one (href="#id", url(#id)). - std::set ids{}; + std::set ids; auto elements_each = [](pugi::xml_node element, auto&& callback, auto&& self) -> void { callback(element); @@ -332,12 +332,12 @@ using namespace glm; { std::vector pixels((std::size_t)size.x * size.y * IMAGE_CHANNELS, 0); Image composed(pixels.data(), size); - for (const auto& part : parts) + for (auto& part : parts) composed.paste(part.image->region_get(part.source, part.size), part.destination); return composed; } - pugi::xml_document document{}; + pugi::xml_document document; auto root = document.append_child("svg"); root.append_attribute("xmlns") = SVG_NAMESPACE; root.append_attribute("xmlns:xlink") = XLINK_NAMESPACE; @@ -346,8 +346,8 @@ using namespace glm; root.append_attribute("viewBox") = std::format("0 0 {} {}", size.x, size.y).c_str(); auto defs = root.append_child("defs"); - std::vector sources{}; - for (const auto& part : parts) + std::vector sources; + for (auto& part : parts) { auto source = std::ranges::find(sources, part.image); if (source == sources.end()) @@ -369,7 +369,7 @@ using namespace glm; use.append_attribute("height") = unitSize.y; } - std::ostringstream text{}; + std::ostringstream text; document.save(text, SVG_INDENT, pugi::format_indent | pugi::format_no_declaration); return svg_render(std::make_shared(text.str()), 1.0f); } diff --git a/src/image.h b/src/image.h index d93fc8f..32f5848 100644 --- a/src/image.h +++ b/src/image.h @@ -18,7 +18,7 @@ // A block of an image placed at `destination`, for composing images. struct ImagePart { - const Image* image{}; + const Image* image = nullptr; glm::ivec2 source{}; glm::ivec2 size{}; glm::ivec2 destination{}; @@ -30,11 +30,11 @@ { public: glm::ivec2 size{}; - std::vector pixels{}; - bool isLinear{}; - std::uint64_t uid{}; - std::shared_ptr svg{}; - float scale{1.0f}; + std::vector pixels; + bool isLinear = false; + std::uint64_t uid = 0; + std::shared_ptr svg; + float scale = 1.0f; Image() = default; Image(const uint8_t*, glm::ivec2, bool = false); diff --git a/src/loader.cpp b/src/loader.cpp index 33414f8..af5fd24 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -44,7 +44,7 @@ uint32_t count = htonl(static_cast(paths.size())); if (!socket.send(&count, sizeof(count))) return false; - for (const auto& path : paths) + for (auto& path : paths) { uint32_t length = htonl(static_cast(path.size())); if (!socket.send(&length, sizeof(length))) return false; @@ -56,7 +56,7 @@ static std::vector socket_paths_receive(Socket& socket) { - uint32_t count{}; + uint32_t count = 0; if (!socket.receive(&count, sizeof(count))) return {}; count = ntohl(count); if (count > SOCKET_MAX_PATHS) return {}; @@ -66,7 +66,7 @@ for (uint32_t i = 0; i < count; ++i) { - uint32_t length{}; + uint32_t length = 0; if (!socket.receive(&length, sizeof(length))) return {}; length = ntohl(length); if (length > SOCKET_MAX_PATH_LENGTH) return {}; @@ -272,7 +272,7 @@ for (auto& path : paths) { if (path.empty()) continue; - SDL_Event event{}; + SDL_Event event = {}; event.type = SDL_EVENT_USER; event.user.code = 0; event.user.data1 = SDL_strdup(path.c_str()); diff --git a/src/loader.h b/src/loader.h index 9dc5564..bdb01ee 100644 --- a/src/loader.h +++ b/src/loader.h @@ -15,15 +15,15 @@ std::filesystem::path settings_path(); public: - Socket socket{}; - std::thread socketThread{}; - std::atomic_bool isSocketRunning{}; - SDL_Window* window{}; - SDL_GLContext glContext{}; + Socket socket = {}; + std::thread socketThread; + std::atomic_bool isSocketRunning = {}; + SDL_Window* window = nullptr; + SDL_GLContext glContext = {}; Settings settings; std::vector arguments; - bool isError{}; - bool isSocketThread{}; + bool isError = false; + bool isSocketThread = false; Loader(int, const char**); ~Loader(); diff --git a/src/localization.h b/src/localization.h index ef53b92..93b80c8 100644 --- a/src/localization.h +++ b/src/localization.h @@ -903,7 +903,7 @@ class Localizer { public: - Language language{ENGLISH}; + Language language = ENGLISH; inline const char* get(StringType type, Language setLanguage = (Language)-1) const { diff --git a/src/log.cpp b/src/log.cpp index 3ec120d..8f5ff0a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -27,9 +27,9 @@ struct SessionFile { - std::filesystem::path path{}; - std::filesystem::file_time_type time{}; - std::uintmax_t size{}; + std::filesystem::path path; + std::filesystem::file_time_type time; + std::uintmax_t size = 0; }; static std::uint32_t process_id_get() @@ -50,15 +50,15 @@ static std::vector session_files_get(const std::filesystem::path& directory, const std::filesystem::path& currentPath) { - std::vector files{}; - std::error_code ec{}; + std::vector files; + std::error_code ec; if (!std::filesystem::is_directory(directory, ec)) return files; for (std::filesystem::directory_iterator it(directory, ec), end{}; !ec && it != end; it.increment(ec)) { auto path = it->path(); if (path == currentPath || path.extension() != ".log") continue; - std::error_code fileEc{}; + std::error_code fileEc; if (!std::filesystem::is_regular_file(path, fileEc)) continue; auto size = std::filesystem::file_size(path, fileEc); @@ -78,7 +78,7 @@ static void session_file_remove(const SessionFile& file, std::uintmax_t& totalSize) { - std::error_code ec{}; + std::error_code ec; std::filesystem::remove(file.path, ec); if (!ec && totalSize >= file.size) totalSize -= file.size; } @@ -89,8 +89,8 @@ std::sort(files.begin(), files.end(), [](const SessionFile& left, const SessionFile& right) { return left.time > right.time; }); - std::uintmax_t totalSize{}; - for (const auto& file : files) + std::uintmax_t totalSize = 0; + for (auto& file : files) totalSize += file.size; while (files.size() >= SESSION_LIMIT) @@ -114,7 +114,7 @@ auto legacyPath = directory / "log.txt"; if (legacyPath == currentPath) return; - std::error_code ec{}; + std::error_code ec; std::filesystem::remove(legacyPath, ec); } @@ -168,11 +168,11 @@ void Logger::stderr_pump() { - std::string pending{}; - std::array buffer{}; + std::string pending; + std::array buffer = {}; while (isStderrRedirecting) { - int readBytes{}; + int readBytes = 0; #if _WIN32 readBytes = _read(stderrPipeReadFd, buffer.data(), (unsigned int)buffer.size()); #else @@ -182,7 +182,7 @@ pending.append(buffer.data(), (std::size_t)readBytes); - std::size_t lineEnd{}; + std::size_t lineEnd = 0; while ((lineEnd = pending.find('\n')) != std::string::npos) { auto line = pending.substr(0, lineEnd); @@ -266,7 +266,7 @@ isLogLimitReached = false; if (!logPath.empty()) { - std::error_code ec{}; + std::error_code ec; auto directory = logPath.parent_path(); if (!directory.empty()) std::filesystem::create_directories(directory, ec); legacy_log_remove(logPath); diff --git a/src/log.h b/src/log.h index 3b745f1..1f936aa 100644 --- a/src/log.h +++ b/src/log.h @@ -44,15 +44,15 @@ class Logger { - std::filesystem::path logPath{}; - std::uintmax_t logSize{}; - std::mutex mutex{}; - std::thread stderrThread{}; - bool isStderrRedirecting{}; - bool isLogLimitReached{}; - int stderrPipeReadFd{-1}; - int stderrPipeWriteFd{-1}; - int stderrOriginalFd{-1}; + std::filesystem::path logPath; + std::uintmax_t logSize = 0; + std::mutex mutex; + std::thread stderrThread; + bool isStderrRedirecting = false; + bool isLogLimitReached = false; + int stderrPipeReadFd = -1; + int stderrPipeWriteFd = -1; + int stderrOriginalFd = -1; void stderr_redirect_start(); void stderr_redirect_stop(); diff --git a/src/main.cpp b/src/main.cpp index 2aa5720..6fa54c5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,8 +17,8 @@ #ifdef _WIN32 struct CommandLineArguments { - std::vector strings{}; - std::vector pointers{}; + std::vector strings; + std::vector pointers; }; std::string wstring_utf8_get(std::wstring_view value) @@ -34,7 +34,7 @@ CommandLineArguments command_line_arguments_get() { - int count{}; + int count = 0; auto wideArguments = CommandLineToArgvW(GetCommandLineW(), &count); if (!wideArguments) return {}; if (count <= 0) @@ -43,7 +43,7 @@ return {}; } - CommandLineArguments arguments{}; + CommandLineArguments arguments = {}; arguments.strings.reserve((std::size_t)count); for (int i = 0; i < count; ++i) arguments.strings.push_back(wstring_utf8_get(wideArguments[i])); diff --git a/src/manager.cpp b/src/manager.cpp index 2079ef0..12343d5 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -22,7 +22,7 @@ { auto parent = path.parent_path(); if (parent.empty()) return; - std::error_code ec{}; + std::error_code ec; std::filesystem::create_directories(parent, ec); if (ec) logger.warning(std::format("Could not create directory for {}: {}", path_to_utf8(path), ec.message())); } @@ -31,14 +31,14 @@ { if (path.empty()) return; - std::error_code ec{}; + std::error_code ec; std::filesystem::remove(path, ec); if (ec) logger.warning(std::format("Could not remove autosave file {}: {}", path_to_utf8(path), ec.message())); } static std::vector path_list_load(const std::filesystem::path& path, std::string_view name) { - std::string fileData{}; + std::string fileData; if (!file_text_load(path, &fileData, "rb")) { logger.warning(std::format("Could not load {} from: {}. Skipping...", name, path_to_utf8(path))); @@ -46,7 +46,7 @@ } logger.info(std::format("Loading {} from: {}", name, path_to_utf8(path))); - std::vector result{}; + std::vector result; std::istringstream file(fileData); for (std::string line{}; std::getline(file, line);) { @@ -61,7 +61,7 @@ std::string_view name) { ensure_parent_directory_exists(path); - std::ostringstream file{}; + std::ostringstream file; for (auto& entry : entries) file << path_to_utf8(entry) << '\n'; if (!file_text_save(path, file.str(), "wb")) @@ -130,7 +130,7 @@ Document* Manager::open(const std::filesystem::path& path, bool isNew, bool isRecent) { - std::string errorString{}; + std::string errorString; documents.emplace_back(path, isNew, &errorString); auto pathString = path_to_utf8(path); @@ -160,15 +160,15 @@ { if (auto document = get(index); document) { - std::string errorString{}; - const auto previousAutosavePath = document->autosave_path_get(); + std::string errorString; + auto previousAutosavePath = document->autosave_path_get(); auto savePath = !path.empty() ? path : document->path; savePath.replace_extension(".anm2"); ensure_parent_directory_exists(savePath); if (!document->save(savePath, &errorString, saveOptions)) return false; - const auto autosavePath = document->autosave_path_get(); + auto autosavePath = document->autosave_path_get(); autosaveFiles.erase(std::remove(autosaveFiles.begin(), autosaveFiles.end(), previousAutosavePath), autosaveFiles.end()); if (autosavePath != previousAutosavePath) @@ -187,7 +187,7 @@ void Manager::autosave(Document& document) { - std::string errorString{}; + std::string errorString; auto autosavePath = document.autosave_path_get(); if (!document.autosave(&errorString, saveOptions)) return; @@ -265,7 +265,7 @@ { for (int i = 0; i < (int)documents.size(); ++i) { - std::error_code ec{}; + std::error_code ec; if (std::filesystem::equivalent(documents[i].path, path, ec)) return i; } return -1; @@ -382,7 +382,7 @@ std::vector ordered; ordered.reserve(orderedEntries.size()); - for (const auto& [pathString, _] : orderedEntries) + for (auto& [pathString, _] : orderedEntries) ordered.emplace_back(path_from_utf8(pathString)); return ordered; } @@ -390,7 +390,7 @@ void Manager::recent_file_add(const std::filesystem::path& path) { if (path.empty()) return; - std::error_code ec{}; + std::error_code ec; if (!std::filesystem::exists(path, ec)) { logger.warning(std::format("Skipping missing recent file: {}", path_to_utf8(path))); @@ -409,7 +409,7 @@ auto loaded = path_list_load(recent_files_path_get(), "recent files"); for (auto it = loaded.rbegin(); it != loaded.rend(); ++it) { - std::error_code ec{}; + std::error_code ec; if (std::filesystem::exists(*it, ec)) recentFiles[path_to_utf8(*it)] = ++recentFilesCounter; else diff --git a/src/manager.h b/src/manager.h index 07a9f34..6b87b51 100644 --- a/src/manager.h +++ b/src/manager.h @@ -19,7 +19,7 @@ struct Command { - int documentIndex{-1}; + int documentIndex = -1; std::function run{}; std::function runManager{}; }; @@ -33,58 +33,58 @@ void recent_files_trim(); public: - std::vector documents{}; - std::vector commands{}; - std::map> recentFiles{}; - std::size_t recentFilesCounter{}; - std::vector autosaveFiles{}; + std::vector documents; + std::vector commands; + std::map> recentFiles; + std::size_t recentFilesCounter = 0; + std::vector autosaveFiles; - int selected{-1}; - int pendingSelected{-1}; + int selected = -1; + int pendingSelected = -1; - bool isRecording{}; - bool isRecordingStart{}; - int recordingStart{}; - int recordingEnd{}; - bool isRecordingRange{}; - bool isAbleToRecord{}; + bool isRecording = false; + bool isRecordingStart = false; + int recordingStart = 0; + int recordingEnd = 0; + bool isRecordingRange = false; + bool isAbleToRecord = false; ImGuiKeyChord chords[SHORTCUT_COUNT]{}; - Options saveOptions{}; + Options saveOptions = {}; - std::vector anm2DragDropPaths{}; - bool isAnm2DragDrop{}; - int anm2DragDropMergePreset{FILE_MERGE_PRESET_MERGE_BY_NAME}; + std::vector anm2DragDropPaths; + bool isAnm2DragDrop = false; + int anm2DragDropMergePreset = FILE_MERGE_PRESET_MERGE_BY_NAME; PopupHelper anm2DragDropPopup{ PopupHelper(LABEL_MANAGER_ANM2_DRAG_DROP, POPUP_NORMAL, POPUP_BY_CURSOR)}; PopupHelper anm2DragDropMergePopup{ PopupHelper(LABEL_DOCUMENTS_MERGE_INTO_CURRENT, POPUP_SMALL_NO_HEIGHT)}; - std::filesystem::path spritesheetDragDropPath{}; - bool isSpritesheetDragDrop{}; + std::filesystem::path spritesheetDragDropPath; + bool isSpritesheetDragDrop = false; struct ItemEdit { - int id{-1}; - std::string name{}; - int spritesheetId{}; - bool isShowRect{}; - bool isAnimation{}; - int libraryId{-1}; - std::string animation{}; + int id = -1; + std::string name; + int spritesheetId = 0; + bool isShowRect = false; + bool isAnimation = false; + int libraryId = -1; + std::string animation; } itemEdit{}; PopupHelper itemPropertiesPopups[2]{ PopupHelper(LABEL_MANAGER_LAYER_PROPERTIES, POPUP_SMALL_NO_HEIGHT), PopupHelper(LABEL_MANAGER_NULL_PROPERTIES, POPUP_SMALL_NO_HEIGHT)}; - Region makeRegion{}; - int makeRegionSpritesheetId{-1}; - bool isMakeRegionRequested{}; + Region makeRegion = {}; + int makeRegionSpritesheetId = -1; + bool isMakeRegionRequested = false; PopupHelper progressPopup{ PopupHelper(LABEL_MANAGER_RENDERING_PROGRESS, POPUP_SMALL_NO_HEIGHT)}; - std::vector selectionHistory{}; + std::vector selectionHistory; Manager(); ~Manager(); diff --git a/src/math_util.cpp b/src/math_util.cpp index 7c0ae86..5d4c378 100644 --- a/src/math_util.cpp +++ b/src/math_util.cpp @@ -23,7 +23,7 @@ using namespace glm; const char* float_format_get(float value) { - static std::string formatString{}; + static std::string formatString; int decimalCount = float_decimals_needed(value); formatString = (decimalCount == 0) ? "%.0f" : ("%." + std::to_string(decimalCount) + "f"); return formatString.c_str(); @@ -31,7 +31,7 @@ using namespace glm; const char* vec2_format_get(const vec2& value) { - static std::string formatString{}; + static std::string formatString; int decimalCountX = float_decimals_needed(value.x); int decimalCountY = float_decimals_needed(value.y); int decimalCount = (decimalCountX > decimalCountY) ? decimalCountX : decimalCountY; diff --git a/src/model/common.h b/src/model/common.h index 23a4741..54c6ffe 100644 --- a/src/model/common.h +++ b/src/model/common.h @@ -169,9 +169,9 @@ // game's copy when it differs from the document (animation layers flattened). struct Options { - bool isJson{}; // the editor's own JSON document instead - bool isPixelBaked{true}; // what the game can't draw is baked into a spritesheet beside the file - const Model* gameModel{}; + bool isJson = false; // the editor's own JSON document instead + bool isPixelBaked = true; // what the game can't draw is baked into a spritesheet beside the file + const Model* gameModel = nullptr; }; #define FRAME_CHANGE_SCALARS \ @@ -200,33 +200,33 @@ struct FrameChange { - std::optional regionId{}; + std::optional regionId; #define X(name, member, isLayerOnly, isColor, isEnabled, value) std::optional name{}; FRAME_CHANGE_SCALARS #undef X - std::optional duration{}; - std::optional depth{}; - std::optional shaderId{}; - std::optional isVisible{}; - std::optional interpolation{}; - std::optional isFlipX{}; - std::optional isFlipY{}; + std::optional duration; + std::optional depth; + std::optional shaderId; + std::optional isVisible; + std::optional interpolation; + std::optional isFlipX; + std::optional isFlipY; // An animation layer's child; a spritesheet layer's frames keep theirs. - std::optional childAnimation{}; - std::optional childMode{}; - std::optional childStart{}; - std::optional isChildStartRandom{}; - std::optional isChildRestart{}; + std::optional childAnimation; + std::optional childMode; + std::optional childStart; + std::optional isChildStartRandom; + std::optional isChildRestart; }; struct Reference { - int animationIndex{-1}; - int itemType{(int)ItemType::NONE}; - int itemID{-1}; - int frameIndex{-1}; - int groupType{(int)ItemType::NONE}; - int groupId{-1}; + int animationIndex = -1; + int itemType = (int)ItemType::NONE; + int itemID = -1; + int frameIndex = -1; + int groupType = (int)ItemType::NONE; + int groupId = -1; auto operator<=>(const Reference&) const = default; }; @@ -234,9 +234,9 @@ // A Reference expressed by runtime uids, so it survives inserts, deletes and moves. struct Handle { - std::uint64_t animation{}; - std::uint64_t item{}; - std::uint64_t frame{}; + std::uint64_t animation = 0; + std::uint64_t item = 0; + std::uint64_t frame = 0; auto operator<=>(const Handle&) const = default; }; diff --git a/src/model/draw.cpp b/src/model/draw.cpp index e62f3aa..a1b0d3e 100644 --- a/src/model/draw.cpp +++ b/src/model/draw.cpp @@ -35,7 +35,7 @@ static std::vector> draw_times_get(const Animation& animation, const Track& track, const DrawOptions& options) { - std::vector> times{}; + std::vector> times; for (int i = 0; i < (int)options.samples.size(); ++i) { auto& sample = options.samples[i]; @@ -67,9 +67,9 @@ // playing then loops the child, stops it at its end, or holds its own start frame. float child_time_get(const Track& track, float time, int length, int seed) { - float start{}; - float clockStart{}; - float clockOffset{}; + float start = 0; + float clockStart = 0; + float clockOffset = 0; for (int i = 0; i < (int)track.frames.size(); ++i) { auto& frame = track.frames[i]; @@ -138,7 +138,7 @@ std::vector animation_triggers_get(const Model& model, const Animation& animation, int time, const LibraryGet& library_get) { - std::vector fires{}; + std::vector fires; std::vector playing{&animation}; animation_triggers_add(fires, model, animation, time, library_get, playing); return fires; @@ -168,11 +168,11 @@ static std::vector animation_draws_get(const Model& model, const Animation& animation, const DrawOptions& options, std::vector& playing) { - std::vector draws{}; + std::vector draws; // Each layer draw's place in the drawing order: its track's position among the layers plus its frame's depth; a // moved layer lands past the one already at that place (below it when moved down, above it when moved up). - std::vector> layerOrders{}; - int layerOrder{}; + std::vector> layerOrders; + int layerOrder = 0; auto parent_get = [&](float time, const TrackGroup* group) { glm::mat4 parent(1.0f); @@ -249,7 +249,7 @@ if (track.isVisible && isFound) track_draws_add(track, drawType, track.id, NONE, group); if (type == LAYER) ++layerOrder; }; - for (const auto& entry : *entries) + for (auto& entry : *entries) { if (auto track = std::get_if(&entry)) { @@ -259,18 +259,18 @@ auto& group = std::get(entry); if (!group.isVisible) continue; if (group.root.isVisible) track_draws_add(group.root, DrawType::GROUP_ROOT, group.id, type, &group); - for (const auto& groupTrack : group.tracks) + for (auto& groupTrack : group.tracks) track_add(groupTrack, &group); } } // Layers draw one after another, so reordering them by depth only moves them among each other. - std::vector layerIndices{}; + std::vector layerIndices; for (std::size_t i = 0; i < draws.size(); ++i) if (draws[i].type == DrawType::LAYER) layerIndices.push_back(i); auto sorted = layerIndices; std::ranges::stable_sort(sorted, {}, [&](std::size_t i) { return layerOrders[i]; }); - std::vector layerDraws{}; + std::vector layerDraws; for (auto i : sorted) layerDraws.push_back(draws[i]); for (std::size_t i = 0; i < layerIndices.size(); ++i) diff --git a/src/model/draw.h b/src/model/draw.h index a34028f..779ebc5 100644 --- a/src/model/draw.h +++ b/src/model/draw.h @@ -18,8 +18,8 @@ // An onion-skin sample: a time offset, or (when sampling by index) an offset in each track's frames. struct DrawSample { - float timeOffset{}; - int indexOffset{}; + float timeOffset = 0; + int indexOffset = 0; }; // The document a library id of a document (the one drawn, or a library) points at; nullptr when not loaded. @@ -27,11 +27,11 @@ struct DrawOptions { - float time{}; - bool isRootTransform{}; - bool isIndexSampled{}; - std::vector samples{}; - LibraryGet library_get{}; + float time = 0; + bool isRootTransform = false; + bool isIndexSampled = false; + std::vector samples; + LibraryGet library_get = {}; }; // An item's frame at a time; `parent` is the transform of its root and group root when root transforms are shown @@ -40,24 +40,24 @@ // layers' draws, with the animation layer's id and transform. struct Draw { - DrawType type{}; - int id{-1}; - int groupType{NONE}; - int sample{-1}; - float time{}; - Frame frame{}; + DrawType type = {}; + int id = -1; + int groupType = NONE; + int sample = -1; + float time = 0; + Frame frame = {}; glm::mat4 parent{1.0f}; - const Model* source{}; - int spritesheetId{-1}; - int sourceId{-1}; // the layer of `source` drawn (a child's, for an animation layer's draws) + const Model* source = nullptr; + int spritesheetId = -1; + int sourceId = -1; // the layer of `source` drawn (a child's, for an animation layer's draws) }; // A trigger that fires, from the animation played or a child animation (whose ids belong to `source`). struct TriggerFire { - const Model* source{}; - Frame trigger{}; - int layerId{-1}; // the animation's layer whose child fired it; -1 for the animation's own + const Model* source = nullptr; + Frame trigger = {}; + int layerId = -1; // the animation's layer whose child fired it; -1 for the animation's own }; glm::mat4 draw_quad_model_get(const Draw&); diff --git a/src/model/frames.cpp b/src/model/frames.cpp index 41e6f76..d348090 100644 --- a/src/model/frames.cpp +++ b/src/model/frames.cpp @@ -23,7 +23,7 @@ { auto total = std::max(original.duration, FRAME_DURATION_MIN); interval = std::max(interval, FRAME_DURATION_MIN); - std::vector frames{}; + std::vector frames; for (int duration = 0; duration < total; duration += interval) { auto& baked = frames.emplace_back(duration == 0 ? original : frame_clone(original)); @@ -68,7 +68,7 @@ auto trackLength = track_length_get(track); if (trackLength <= 0) return; auto length = std::max({trackLength, track_length_get(root), frameNum, FRAME_DURATION_MIN}); - std::vector frames{}; + std::vector frames; for (int time = 0; time < length; ++time) { auto& frame = frames.emplace_back(frame_generate(track, (float)time)); @@ -83,21 +83,21 @@ // returned only on its exact frame; otherwise the result is invisible. Frame frame_generate(const Track& track, float time) { - Frame frame{}; + Frame frame = {}; frame.isVisible = false; if (track.frames.empty()) return frame; time = std::max(time, 0.0f); if (track.type == ItemType::TRIGGER) { - for (const auto& trigger : track.frames) + for (auto& trigger : track.frames) if ((int)time == trigger.atFrame) return trigger; return frame; } - const Frame* next{}; - int durationCurrent{}; - int durationNext{}; + const Frame* next = nullptr; + int durationCurrent = 0; + int durationNext = 0; for (int i = 0; i < (int)track.frames.size(); ++i) { frame = track.frames[i]; @@ -129,7 +129,7 @@ if (track.frames.empty()) return -1; if (time <= 0.0f) return 0; - float duration{}; + float duration = 0; for (int i = 0; i < (int)track.frames.size(); ++i) { duration += track.frames[i].duration; @@ -142,7 +142,7 @@ { if (index < 0 || index >= (int)track.frames.size()) return 0.0f; if (track.type == ItemType::TRIGGER) return (float)track.frames[index].atFrame; - float time{}; + float time = 0; for (int i = 0; i < index; ++i) time += track.frames[i].duration; return time; @@ -237,10 +237,10 @@ constexpr glm::ivec2 CORNERS[4] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; glm::vec2 min{std::numeric_limits::infinity()}; glm::vec2 max{-std::numeric_limits::infinity()}; - bool isAny{}; + bool isAny = false; for (float time = 0.0f; time < (float)animation.frameNum; time += 1.0f) - for (const auto& draw : animation_draws_get( + for (auto& draw : animation_draws_get( model, animation, {.time = time, .isRootTransform = isRootTransform, .library_get = library_get})) { if (draw.type != DrawType::LAYER || draw.frame.size == glm::vec2()) continue; diff --git a/src/model/json.cpp b/src/model/json.cpp index fde811a..fc83ee5 100644 --- a/src/model/json.cpp +++ b/src/model/json.cpp @@ -27,7 +27,7 @@ using namespace simdjson; constexpr int HOURS_HALF_DAY = 12; constexpr int DATE_FIELDS = 6; constexpr int DATE_MERIDIEM_SIZE = 3; - const std::vector REGIONS_NONE{}; + const std::vector REGIONS_NONE; bool is_json(std::string_view text) { @@ -91,15 +91,15 @@ using namespace simdjson; struct Scope { - bool isInline{}; - bool isJoinable{true}; - std::size_t start{}; - bool isEmpty{true}; + bool isInline = false; + bool isJoinable = true; + std::size_t start = 0; + bool isEmpty = true; }; const Model& model; - std::string text{}; - std::vector scopes{}; + std::string text; + std::vector scopes; void separate() { @@ -119,7 +119,7 @@ using namespace simdjson; // Line breaks become nothing, or a space after a comma. void join(const Scope& scope) { - std::string joined{}; + std::string joined; for (auto i = scope.start; i < text.size(); ++i) if (text[i] != '\n') joined += text[i]; @@ -217,7 +217,7 @@ using namespace simdjson; template void references(std::string_view name, const std::vector& ids, const Items& items) { - std::vector indices{}; + std::vector indices; for (auto id : ids) if (auto index = index_get(items, id); index != -1) indices.push_back(index); field(name, indices, {}); @@ -249,7 +249,7 @@ using namespace simdjson; if (items.empty()) return; key(name); open('[', false, isJoinable); - for (const auto& item : items) + for (auto& item : items) { separate(); open('{', isInline); @@ -264,7 +264,7 @@ using namespace simdjson; if (items.empty()) return; key(name); open('[', false, false); - for (const auto& item : items) + for (auto& item : items) { separate(); value(get(item)); @@ -276,7 +276,7 @@ using namespace simdjson; // Each returns what it expected when the value is the wrong kind (and leaves the value as it was). static std::string_view value_read(dom::element element, bool& value) { - bool read{}; + bool read = false; if (element.get(read)) return "true or false"; value = read; return {}; @@ -286,7 +286,7 @@ using namespace simdjson; requires std::is_same_v || std::is_same_v std::string_view value_read(dom::element element, T& value) { - double read{}; + double read = 0; if (element.get(read)) return "a number"; value = (T)read; return {}; @@ -294,7 +294,7 @@ using namespace simdjson; static std::string_view value_read(dom::element element, std::string& value) { - std::string_view read{}; + std::string_view read; if (element.get(read)) return "a string"; value = read; return {}; @@ -302,7 +302,7 @@ using namespace simdjson; static std::string_view value_read(dom::element element, std::filesystem::path& value) { - std::string read{}; + std::string read; auto expected = value_read(element, read); if (expected.empty()) value = path_from_utf8(read); return expected; @@ -312,10 +312,10 @@ using namespace simdjson; std::string_view value_read(dom::element element, glm::vec& value) { static const auto EXPECTED = std::format("an array of {} numbers", L); - dom::array array{}; + dom::array array; if (element.get(array) || array.size() != L) return EXPECTED; auto read = value; - int i{}; + int i = 0; for (auto item : array) if (!value_read(item, read[i++]).empty()) return EXPECTED; value = read; @@ -324,9 +324,9 @@ using namespace simdjson; template static std::string_view value_read(dom::element element, std::vector& value) { - dom::array array{}; + dom::array array; if (element.get(array)) return "an array"; - std::vector read{}; + std::vector read; for (auto item : array) if (auto expected = value_read(item, read.emplace_back()); !expected.empty()) return expected; value = std::move(read); @@ -340,11 +340,11 @@ using namespace simdjson; static constexpr bool IS_READING = true; const Model& model; - std::vector* issues{}; - std::string path{}; - dom::object fields{}; - std::set used{}; - bool isKeyed{}; // its keys are names rather than fields + std::vector* issues = nullptr; + std::string path; + dom::object fields; + std::set used; + bool isKeyed = false; // its keys are names rather than fields void issue_add(std::string_view name, std::string_view message) { @@ -359,13 +359,13 @@ using namespace simdjson; bool has(std::string_view name) { - dom::element element{}; + dom::element element; return element_get(name, element); } template bool field(std::string_view name, T& value, const std::type_identity_t& = {}) { - dom::element element{}; + dom::element element; if (!element_get(name, element)) return false; if (auto expected = value_read(element, value); !expected.empty()) issue_add(name, std::format("expected {}", expected)); @@ -399,7 +399,7 @@ using namespace simdjson; template void choice(std::string_view name, E& value, const std::string_view (&names)[N], E) { - std::string read{}; + std::string read; if (!field(name, read)) return; auto it = std::ranges::find(names, read); if (read.empty() || it == std::end(names)) @@ -418,7 +418,7 @@ using namespace simdjson; // Reads `element` as an object at `childPath` (ending in '.'), then notes the keys it never asked for. template void object_each(dom::element element, std::string childPath, Fn&& fn) { - JsonReader reader{model, issues, std::move(childPath)}; + JsonReader reader = {model, issues, std::move(childPath)}; if (element.get(reader.fields)) { issues->push_back(std::format("{}: expected an object", reader.path.substr(0, reader.path.size() - 1))); @@ -430,13 +430,13 @@ using namespace simdjson; template void object(std::string_view name, Fn&& fn, bool, bool = false) { - dom::element element{}; + dom::element element; if (element_get(name, element)) object_each(element, std::format("{}{}.", path, name), fn); } bool array_get(std::string_view name, dom::array& array) { - dom::element element{}; + dom::element element; if (!element_get(name, element)) return false; if (!element.get(array)) return true; issue_add(name, "expected an array"); @@ -445,7 +445,7 @@ using namespace simdjson; template void list(std::string_view name, std::vector& items, Fn&& fn, bool, bool = true) { - dom::array array{}; + dom::array array; if (!array_get(name, array)) return; items.clear(); for (auto element : array) @@ -460,7 +460,7 @@ using namespace simdjson; template void values(std::string_view name, std::vector& items, Get&& get) { - dom::array array{}; + dom::array array; if (!array_get(name, array)) return; items.clear(); for (auto element : array) @@ -477,7 +477,7 @@ using namespace simdjson; template static void frame_io(Io& io, F& frame, ItemType type, const std::vector& regions) { - static const Frame FRAME_DEFAULT{}; + static const Frame FRAME_DEFAULT = {}; auto& content = io.model.content; if (type == ItemType::TRIGGER) { @@ -573,7 +573,7 @@ using namespace simdjson; false); if constexpr (Io::IS_READING) { - int id{}; + int id = 0; groups_each(entries, [&](TrackGroup& group) { group.id = id++; }); } } @@ -595,8 +595,8 @@ using namespace simdjson; // Animation names are unique document-wide (default names one); a group's only among the top-level keys. static void animations_write(JsonWriter& io, const Model& model) { - std::set animationNames{}; - std::set keys{}; + std::set animationNames; + std::set keys; auto name_unique_get = [](const std::string& name, std::initializer_list*> sets) { auto candidate = name; @@ -617,7 +617,7 @@ using namespace simdjson; "animations", [&](JsonWriter&) { - for (const auto& entry : model.animations.entries) + for (auto& entry : model.animations.entries) { if (auto animation = std::get_if>(&entry)) { @@ -635,7 +635,7 @@ using namespace simdjson; "animations", [&](JsonWriter&) { - for (const auto& animation : group.animations) + for (auto& animation : group.animations) animation_write(*animation, false); }, false); @@ -650,11 +650,11 @@ using namespace simdjson; { auto animation_read = [&](std::string_view name, JsonReader& animationIo) { - Animation animation{.name = std::string(name), .root = {.type = ItemType::ROOT}}; + Animation animation = {.name = std::string(name), .root = {.type = ItemType::ROOT}}; animation_io(animationIo, animation); return std::make_shared(std::move(animation)); }; - int groupId{}; + int groupId = 0; io.object( "animations", [&](JsonReader& animationsIo) @@ -669,7 +669,7 @@ using namespace simdjson; model.animations.entries.emplace_back(animation_read(name, entryIo)); return; } - AnimationGroup group{.id = groupId++, .name = std::string(name)}; + AnimationGroup group = {.id = groupId++, .name = std::string(name)}; entryIo.field("expanded", group.isExpanded); entryIo.field("visible", group.isVisible); entryIo.object( @@ -792,11 +792,11 @@ using namespace simdjson; // Fails only when the text isn't a JSON object; anything it couldn't read is listed in `errorString`. bool model_from_json(Model& model, std::string_view text, std::string* errorString) { - dom::parser parser{}; + dom::parser parser; padded_string json(text); - dom::element root{}; - std::vector issues{}; - JsonReader io{model, &issues}; + dom::element root; + std::vector issues; + JsonReader io = {model, &issues}; auto error = parser.parse(json).get(root); if (!error) error = root.get(io.fields); if (error) diff --git a/src/model/model.cpp b/src/model/model.cpp index d012779..cc909ec 100644 --- a/src/model/model.cpp +++ b/src/model/model.cpp @@ -26,8 +26,8 @@ int Model::animations_count_get() const { - int count{}; - for (const auto& entry : animations.entries) + int count = 0; + for (auto& entry : animations.entries) count += std::holds_alternative(entry) ? (int)std::get(entry).animations.size() : 1; return count; @@ -57,7 +57,7 @@ std::vector> Model::animations_get() const { - std::vector> result{}; + std::vector> result; for (int i = 0; i < animations_count_get(); ++i) result.emplace_back(i, animation_get(i)); return result; @@ -66,7 +66,7 @@ template static auto animation_group_find(Self& self, int index) { using Group = std::conditional_t, const AnimationGroup, AnimationGroup>; - Group* result{}; + Group* result = nullptr; if (index < 0) return result; for (auto& entry : self.animations.entries) { @@ -94,7 +94,7 @@ template static auto animation_track_group_find(A& animation, int groupType, int groupId) { using Group = std::conditional_t, const TrackGroup, TrackGroup>; - Group* result{}; + Group* result = nullptr; if (groupId < 0 || (groupType != LAYER && groupType != NULL_)) return result; groups_each(animation_entries_get(animation, groupType), [&](auto& group) @@ -119,7 +119,7 @@ template static auto animation_track_find(A& animation, int itemType, int id, int groupType, int groupId) { using T = std::conditional_t, const Track, Track>; - T* result{}; + T* result = nullptr; auto isGrouped = groupType != NONE && groupId != -1; if (itemType == ROOT) { @@ -212,8 +212,8 @@ template static std::set unused_ids_get(const Items& items, const std::set& used) { - std::set unused{}; - for (const auto& item : items) + std::set unused; + for (auto& item : items) if (!used.contains(item.id)) unused.insert(item.id); return unused; } @@ -230,7 +230,7 @@ if (type == ElementType::SPRITESHEET || type == ElementType::LIBRARY) { // An animation layer's spritesheet isn't drawn. - for (const auto& layer : content.layers) + for (auto& layer : content.layers) if (type == ElementType::LIBRARY) callback(layer.libraryId); else if (!layer.is_animation()) @@ -243,14 +243,14 @@ tracks_each(type == ElementType::LAYER_ELEMENT ? animation.layers : animation.nulls, [&](const Track& track, auto*) { callback(track.id); }); if (type == ElementType::EVENT_ELEMENT || type == ElementType::SOUND_ELEMENT) - for (const auto& trigger : animation.triggers.frames) + for (auto& trigger : animation.triggers.frames) for (auto id : type == ElementType::EVENT_ELEMENT ? trigger.eventIds : trigger.soundIds) callback(id); if (type == ElementType::SHADER) animation_tracks_each(animation, [&](const Track& track) { - for (const auto& frame : track.frames) + for (auto& frame : track.frames) callback(frame.shaderId); }); if (type == ElementType::REGION) @@ -259,7 +259,7 @@ { auto layer = item_get(content.layers, track.id); if (!layer || layer->spritesheetId != spritesheetId) return; - for (const auto& frame : track.frames) + for (auto& frame : track.frames) callback(frame.regionId); }); }; @@ -270,7 +270,7 @@ std::set Model::unused_get(ElementType type, const Animation* only) const { - std::set used{}; + std::set used; references_each(*this, type, -1, only, [&](int id) { used.insert(id); }); switch (type) { @@ -296,14 +296,14 @@ // How many references there are to the items `ids` (see references_each). int Model::uses_count(ElementType type, const std::set& ids, int spritesheetId, const Animation* only) const { - int count{}; + int count = 0; references_each(*this, type, spritesheetId, only, [&](int id) { count += ids.contains(id); }); return count; } Handle Model::handle_get(Reference reference, bool isGroup) const { - Handle handle{}; + Handle handle = {}; auto animation = animation_get(reference.animationIndex); if (!animation) return handle; handle.animation = animation->uid; @@ -347,7 +347,7 @@ // Gives any element that shares a uid with an earlier one a fresh uid (copies made without cloning). void Model::uids_repair() { - std::unordered_set seen{}; + std::unordered_set seen; auto repair = [&](std::uint64_t& uid) { if (!uid || !seen.insert(uid).second) uid = uid_next(); @@ -356,7 +356,7 @@ for (int i = 0; i < animations_count_get(); ++i) { auto seenBefore = seen; - bool isDuplicate{}; + bool isDuplicate = false; animation_uids_each(const_cast(*animation_get(i)), [&](std::uint64_t& uid) { isDuplicate |= !uid || !seen.insert(uid).second; }); if (!isDuplicate) continue; @@ -388,8 +388,8 @@ // SVG spritesheets that layers show. std::set spritesheets_vector_used_get(const Model& model) { - std::set ids{}; - for (const auto& layer : model.content.layers) + std::set ids; + for (auto& layer : model.content.layers) if (auto spritesheet = item_get(model.content.spritesheets, layer.spritesheetId); spritesheet && !layer.is_animation() && is_path_extension(spritesheet->path, SVG_EXTENSION)) ids.insert(spritesheet->id); @@ -400,8 +400,8 @@ int track_length_get(const Track& track) { - int length{}; - for (const auto& frame : track.frames) + int length = 0; + for (auto& frame : track.frames) length = track.type == ItemType::TRIGGER ? std::max(length, frame.atFrame) : length + frame.duration; return length; } @@ -417,7 +417,7 @@ int animation_length_get(const Animation& animation) { - int length{}; + int length = 0; animation_tracks_each(animation, [&](const Track& track) { length = std::max(length, track_length_get(track)); }); return std::max(length, FRAME_DURATION_MIN); } @@ -449,7 +449,7 @@ ElementType::LAYER_ANIMATION, ElementType::NULL_ANIMATION, ElementType::TRIGGERS}; locations[track.uid] = {reference, TRACK_TYPES[(int)track.type]}; - for (const auto& frame : track.frames) + for (auto& frame : track.frames) { ++reference.frameIndex; locations[frame.uid] = {reference, track.type == ItemType::TRIGGER ? ElementType::TRIGGER : ElementType::FRAME}; @@ -464,15 +464,15 @@ track_locations_add(locations, animation->root, {index, ROOT}); track_locations_add(locations, animation->triggers, {index, TRIGGER}); for (auto type : {LAYER, NULL_}) - for (const auto& entry : animation_entries_get(*animation, type)) + for (auto& entry : animation_entries_get(*animation, type)) if (auto track = std::get_if(&entry)) track_locations_add(locations, *track, {index, type, track->id}); else { - const auto& group = std::get(entry); + auto& group = std::get(entry); locations[group.uid] = {{index, type, group.id}, ElementType::GROUP}; track_locations_add(locations, group.root, {index, ROOT, -1, -1, type, group.id}); - for (const auto& groupTrack : group.tracks) + for (auto& groupTrack : group.tracks) track_locations_add(locations, groupTrack, {index, type, groupTrack.id, -1, type, group.id}); } } @@ -506,16 +506,16 @@ { return a == b || (a && b && *a == *b); }; for (std::size_t i = 0; i < left.animations.entries.size(); ++i) { - const auto& a = left.animations.entries[i]; - const auto& b = right.animations.entries[i]; + auto& a = left.animations.entries[i]; + auto& b = right.animations.entries[i]; if (a.index() != b.index()) return false; if (auto animation = std::get_if>(&a)) { if (!is_animation_equal(*animation, std::get>(b))) return false; continue; } - const auto& groupA = std::get(a); - const auto& groupB = std::get(b); + auto& groupA = std::get(a); + auto& groupB = std::get(b); if (groupA.uid != groupB.uid || groupA.id != groupB.id || groupA.name != groupB.name || groupA.isExpanded != groupB.isExpanded || groupA.isVisible != groupB.isVisible || groupA.extras != groupB.extras || groupA.animations.size() != groupB.animations.size()) diff --git a/src/model/model.h b/src/model/model.h index 41c2034..6de4700 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -18,10 +18,10 @@ // An XML element the editor does not understand, kept verbatim so it survives a save. struct XmlNode { - std::string tag{}; - std::vector> attributes{}; - std::string text{}; - std::vector children{}; + std::string tag; + std::vector> attributes; + std::string text; + std::vector children; bool operator==(const XmlNode&) const = default; }; @@ -29,9 +29,9 @@ // Unknown XML attached to a known node: attributes, text, and unknown children with the child index they had. struct Extras { - std::vector> attributes{}; - std::string text{}; - std::vector> children{}; + std::vector> attributes; + std::string text; + std::vector> children; bool operator==(const Extras&) const = default; }; @@ -39,59 +39,59 @@ // A keyframe; on a triggers track the same struct is a trigger (atFrame, eventIds, soundIds). struct Frame { - std::uint64_t uid{uid_next()}; + std::uint64_t uid = uid_next(); glm::vec2 crop{}; glm::vec2 size{}; glm::vec2 pivot{}; glm::vec2 position{}; glm::vec2 scale{100.0f, 100.0f}; glm::vec2 skew{}; - float rotation{}; + float rotation = 0; glm::vec4 tint{COLOR_WHITE}; glm::vec4 colorOffset{}; - int duration{1}; - bool isVisible{true}; - Interpolation interpolation{Interpolation::NONE}; - int regionId{-1}; - int shaderId{-1}; - int depth{}; // a layer frame draws this many layers above (or below) its place in the timeline; editor-only - float blur{}; // Flash's BlurFilter at quality 1: one box blur this many canvas pixels wide; editor-only + int duration = 1; + bool isVisible = true; + Interpolation interpolation = Interpolation::NONE; + int regionId = -1; + int shaderId = -1; + int depth = 0; // a layer frame draws this many layers above (or below) its place in the timeline; editor-only + float blur = 0; // Flash's BlurFilter at quality 1: one box blur this many canvas pixels wide; editor-only // On an animation layer: the child animation (empty for the layer's own) and how it plays; editor-only. - std::string childAnimation{}; - ChildMode childMode{ChildMode::LOOP}; - int childStart{}; - bool isChildStartRandom{}; - bool isChildRestart{}; - int atFrame{-1}; - std::vector eventIds{}; - std::vector soundIds{}; - Extras extras{}; + std::string childAnimation; + ChildMode childMode = ChildMode::LOOP; + int childStart = 0; + bool isChildStartRandom = false; + bool isChildRestart = false; + int atFrame = -1; + std::vector eventIds; + std::vector soundIds; + Extras extras = {}; bool operator==(const Frame&) const = default; }; struct Track { - std::uint64_t uid{uid_next()}; - ItemType type{ItemType::LAYER}; - int id{-1}; - bool isVisible{true}; - std::vector frames{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + ItemType type = ItemType::LAYER; + int id = -1; + bool isVisible = true; + std::vector frames; + Extras extras = {}; bool operator==(const Track&) const = default; }; struct TrackGroup { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::string name{}; - bool isExpanded{true}; - bool isVisible{true}; - Track root{.type = ItemType::ROOT, .frames = {Frame{}}}; - std::vector tracks{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::string name; + bool isExpanded = true; + bool isVisible = true; + Track root = {.type = ItemType::ROOT, .frames = {Frame{}}}; + std::vector tracks; + Extras extras = {}; bool operator==(const TrackGroup&) const = default; }; @@ -100,35 +100,35 @@ struct Animation { - std::uint64_t uid{uid_next()}; - std::string name{}; - int frameNum{1}; - bool isLoop{true}; + std::uint64_t uid = uid_next(); + std::string name; + int frameNum = 1; + bool isLoop = true; // Playback stays between these frames (inclusive) when set; -1 for none. Saved only in the editor's copy. - int startMarker{-1}; - int endMarker{-1}; - Track root{.type = ItemType::ROOT, .frames = {Frame{}}}; - std::vector layers{}; - std::vector nulls{}; - Track triggers{.type = ItemType::TRIGGER}; + int startMarker = -1; + int endMarker = -1; + Track root = {.type = ItemType::ROOT, .frames = {Frame{}}}; + std::vector layers; + std::vector nulls; + Track triggers = {.type = ItemType::TRIGGER}; std::vector layout{ElementType::ROOT_ANIMATION, ElementType::LAYER_ANIMATIONS, ElementType::NULL_ANIMATIONS, ElementType::TRIGGERS}; - Extras extras{}; - Extras layersExtras{}; - Extras nullsExtras{}; + Extras extras = {}; + Extras layersExtras = {}; + Extras nullsExtras = {}; bool operator==(const Animation&) const = default; }; struct AnimationGroup { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::string name{}; - bool isExpanded{true}; - bool isVisible{true}; - std::vector> animations{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::string name; + bool isExpanded = true; + bool isVisible = true; + std::vector> animations; + Extras extras = {}; bool operator==(const AnimationGroup&) const = default; }; @@ -137,74 +137,74 @@ struct Region { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::string name{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::string name; glm::vec2 crop{}; glm::vec2 size{}; glm::vec2 pivot{}; - Origin origin{Origin::CUSTOM}; - Extras extras{}; + Origin origin = Origin::CUSTOM; + Extras extras = {}; bool operator==(const Region&) const = default; }; struct Spritesheet { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::filesystem::path path{}; - std::vector regions{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::filesystem::path path; + std::vector regions; + Extras extras = {}; bool operator==(const Spritesheet&) const = default; }; struct Component { - int index{-1}; - std::string binding{}; - std::string value{}; - Extras extras{}; + int index = -1; + std::string binding; + std::string value; + Extras extras = {}; bool operator==(const Component&) const = default; }; struct Uniform { - std::string name{}; - std::string binding{}; - std::string value{}; - std::vector components{}; - Extras extras{}; + std::string name; + std::string binding; + std::string value; + std::vector components; + Extras extras = {}; bool operator==(const Uniform&) const = default; }; struct Shader { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::string name{}; - std::filesystem::path vertex{}; - std::filesystem::path fragment{}; - std::vector uniforms{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::string name; + std::filesystem::path vertex; + std::filesystem::path fragment; + std::vector uniforms; + Extras extras = {}; bool operator==(const Shader&) const = default; }; struct Layer { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::string name{}; - int spritesheetId{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::string name; + int spritesheetId = 0; // An animation layer plays `animation` (from library `libraryId`, or this file at -1) instead of showing its // spritesheet. - int libraryId{-1}; - std::string animation{}; - Extras extras{}; + int libraryId = -1; + std::string animation; + Extras extras = {}; bool is_animation() const { return !animation.empty(); } bool operator==(const Layer&) const = default; @@ -213,79 +213,79 @@ // Another .anm2 whose animations this one's layers can play. struct Library { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::filesystem::path path{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::filesystem::path path; + Extras extras = {}; bool operator==(const Library&) const = default; }; struct Null { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::string name{}; - bool isShowRect{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::string name; + bool isShowRect = false; + Extras extras = {}; bool operator==(const Null&) const = default; }; struct Event { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::string name{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::string name; + Extras extras = {}; bool operator==(const Event&) const = default; }; struct Sound { - std::uint64_t uid{uid_next()}; - int id{-1}; - std::filesystem::path path{}; - Extras extras{}; + std::uint64_t uid = uid_next(); + int id = -1; + std::filesystem::path path; + Extras extras = {}; bool operator==(const Sound&) const = default; }; struct Info { - std::string createdBy{"robot"}; - std::string createdOn{}; - int fps{30}; - int version{}; - bool isIsaacIgnored{}; // last saved with Ignore and Save: nothing the game can't show worked around; editor-only - Extras extras{}; + std::string createdBy = "robot"; + std::string createdOn; + int fps = 30; + int version = 0; + bool isIsaacIgnored = false; // last saved with Ignore and Save: nothing the game can't show worked around; editor-only + Extras extras = {}; bool operator==(const Info&) const = default; }; struct Content { - std::vector spritesheets{}; - std::vector shaders{}; - std::vector layers{}; - std::vector nulls{}; - std::vector events{}; - std::vector sounds{}; - std::vector libraries{}; + std::vector spritesheets; + std::vector shaders; + std::vector layers; + std::vector nulls; + std::vector events; + std::vector sounds; + std::vector libraries; std::vector layout{ElementType::SPRITESHEETS, ElementType::SHADERS, ElementType::LAYERS, ElementType::NULLS, ElementType::EVENTS}; - Extras extras{}; - std::vector> containerExtras{}; + Extras extras = {}; + std::vector> containerExtras; bool operator==(const Content&) const = default; }; struct Animations { - std::string defaultAnimation{}; - std::vector entries{}; - Extras extras{}; + std::string defaultAnimation; + std::vector entries; + Extras extras = {}; bool operator==(const Animations&) const = default; }; @@ -300,8 +300,8 @@ template int item_next_id_get(const Items& items) { - int id{-1}; - for (const auto& item : items) + int id = -1; + for (auto& item : items) id = std::max(id, item.id); return id + 1; } @@ -352,12 +352,12 @@ class Model { public: - Info info{}; - Content content{}; - Animations animations{}; - std::vector layout{ElementType::INFO, ElementType::CONTENT, ElementType::ANIMATIONS}; - Extras extras{}; - bool isValid{true}; + Info info = {}; + Content content = {}; + Animations animations = {}; + std::vector layout = {ElementType::INFO, ElementType::CONTENT, ElementType::ANIMATIONS}; + Extras extras = {}; + bool isValid = true; int animations_count_get() const; const Animation* animation_get(int) const; @@ -390,12 +390,12 @@ public: struct Location { - Reference reference{}; - ElementType type{}; + Reference reference = {}; + ElementType type = {}; }; private: - std::unordered_map locations{}; + std::unordered_map locations; public: UidIndex() = default; diff --git a/src/model/xml.cpp b/src/model/xml.cpp index bcb9337..b52fc9c 100644 --- a/src/model/xml.cpp +++ b/src/model/xml.cpp @@ -193,7 +193,7 @@ // Child elements with their position, skipping legacy Overlay, nested SourceDocument copies and misplaced shaders. template static void children_each(pugi::xml_node parent, Callback&& callback) { - int position{}; + int position = 0; for (auto child : parent.children()) if (child.type() == pugi::node_element && is_child_kept(parent, child)) callback(child, type_get(child), position++); @@ -212,7 +212,7 @@ static XmlNode node_read(pugi::xml_node element) { - XmlNode node{.tag = element.name()}; + XmlNode node = {.tag = element.name()}; for (auto attribute : element.attributes()) attribute_read(node.attributes, attribute); if (auto text = text_get(element)) node.text = text; @@ -222,7 +222,7 @@ static Extras extras_read(pugi::xml_node element) { - Extras extras{}; + Extras extras = {}; for (auto attribute : element.attributes()) if (!std::ranges::contains(KNOWN_ATTRIBUTES, std::string_view(attribute.name()))) attribute_read(extras.attributes, attribute); @@ -237,7 +237,7 @@ static Frame frame_read(pugi::xml_node element) { - Frame frame{}; + Frame frame = {}; frame.crop = {float_get(element, "XCrop"), float_get(element, "YCrop")}; frame.size = {float_get(element, "Width"), float_get(element, "Height")}; frame.pivot = {float_get(element, "XPivot"), float_get(element, "YPivot")}; @@ -290,7 +290,7 @@ static Track track_read(pugi::xml_node element, ItemType type) { - Track track{.type = type, .isVisible = bool_get(element, "Visible", true), .extras = extras_read(element)}; + Track track = {.type = type, .isVisible = bool_get(element, "Visible", true), .extras = extras_read(element)}; if (type == ItemType::LAYER) track.id = int_get(element, "LayerId"); if (type == ItemType::NULL_) track.id = int_get(element, "NullId"); auto frameType = type == ItemType::TRIGGER ? ElementType::TRIGGER : ElementType::FRAME; @@ -321,16 +321,16 @@ { using Group = GroupType; - std::optional child{}; - std::optional group{}; - std::optional node{}; - int groupId{-1}; - int index{-1}; - std::vector children{}; - std::optional root{}; - std::optional backupRoot{}; - std::vector backupTracks{}; - bool isBackup{}; + std::optional child; + std::optional group; + std::optional node; + int groupId = -1; + int index = -1; + std::vector children; + std::optional root; + std::optional backupRoot; + std::vector backupTracks; + bool isBackup = false; }; using TrackItem = ContainerItem; @@ -343,11 +343,11 @@ // group seen before it. Unknown XML becomes extras at its position. template static std::vector entries_build(std::vector items, Extras& extras) { - int nextGroupId{}; - for (const auto& item : items) + int nextGroupId = 0; + for (auto& item : items) if (item.group) nextGroupId = std::max(nextGroupId, item.group->id + 1); - std::vector flat{}; + std::vector flat; for (auto& item : items) { if (!item.group) @@ -363,8 +363,8 @@ flat.push_back({.child = std::move(child), .groupId = groupId}); } - std::vector entries{}; - std::map groupEntries{}; + std::vector entries; + std::map groupEntries; for (int i = 0; i < (int)flat.size(); ++i) { auto& item = flat[i]; @@ -417,7 +417,7 @@ static std::vector track_items_read(pugi::xml_node container, ItemType type) { - std::vector items{}; + std::vector items; children_each(container, [&](pugi::xml_node child, ElementType childType, int) { @@ -438,8 +438,8 @@ { if (!legacyGroups.empty()) { - std::set legacyIds{}; - for (const auto& item : legacyGroups) + std::set legacyIds; + for (auto& item : legacyGroups) if (item.group->id >= 0) legacyIds.insert(item.group->id); std::erase_if(items, [&](const TrackItem& item) { return item.group && legacyIds.contains(item.group->id); }); std::ranges::stable_sort(legacyGroups, @@ -457,7 +457,7 @@ } } - std::set restoredIds{}; + std::set restoredIds; for (auto& item : items) if (item.group && item.group->id >= 0 && item.isBackup && (item.backupRoot || !item.backupTracks.empty())) { @@ -482,10 +482,10 @@ .root = {.type = ItemType::ROOT}, .layout = {}, .extras = extras_read(element)}; - std::map> items{}; - std::map> legacyGroups{}; - std::set legacyRead{}; - int skipped{}; + std::map> items; + std::map> legacyGroups; + std::set legacyRead; + int skipped = 0; children_each(element, [&](pugi::xml_node child, ElementType type, int position) { @@ -539,7 +539,7 @@ static std::vector animation_entries_read(pugi::xml_node parent, Extras& extras) { - std::vector items{}; + std::vector items; children_each(parent, [&](pugi::xml_node child, ElementType type, int) { @@ -674,7 +674,7 @@ template static std::vector items_read(pugi::xml_node container, Content& content, ElementType type) { - std::vector items{}; + std::vector items; auto extras = extras_read(container); children_each(container, [&](pugi::xml_node child, ElementType childType, int position) @@ -690,7 +690,7 @@ static Content content_read(pugi::xml_node element) { - Content content{.layout = {}, .extras = extras_read(element)}; + Content content = {.layout = {}, .extras = extras_read(element)}; children_each(element, [&](pugi::xml_node child, ElementType type, int position) { @@ -717,11 +717,11 @@ // Gives every item a unique, non-negative id; the first holder of a duplicated id keeps it. template static void ids_repair(Items& items) { - std::set usedIds{}; - for (const auto& item : items) + std::set usedIds; + for (auto& item : items) if (item.id >= 0) usedIds.insert(item.id); - std::set keptIds{}; - int nextId{}; + std::set keptIds; + int nextId = 0; for (auto& item : items) { if (item.id >= 0 && keptIds.insert(item.id).second) continue; @@ -797,7 +797,7 @@ static Model model_read(pugi::xml_node element) { - Model model{.layout = {}, .extras = extras_read(element)}; + Model model = {.layout = {}, .extras = extras_read(element)}; children_each(element, [&](pugi::xml_node child, ElementType type, int position) { @@ -833,11 +833,11 @@ struct Writer { - Flags flags{}; - const Model* model{}; - std::map shaderIds{}; - std::map layerIds{}; - std::map> regionIds{}; + Flags flags = {}; + const Model* model = nullptr; + std::map shaderIds; + std::map layerIds; + std::map> regionIds; // With a model, a whole document is written: shader, layer and region ids are renumbered by position. Writer(Flags flags, const Model* model = nullptr) : flags(flags), model(model) @@ -848,8 +848,8 @@ shaderIds[content.shaders[i].id] = i; for (int i = 0; i < (int)content.layers.size(); ++i) layerIds[content.layers[i].id] = i; - std::set spritesheetIds{}; - for (const auto& spritesheet : content.spritesheets) + std::set spritesheetIds; + for (auto& spritesheet : content.spritesheets) if (spritesheetIds.insert(spritesheet.id).second && !spritesheet.regions.empty()) for (int i = 0; i < (int)spritesheet.regions.size(); ++i) regionIds[spritesheet.id][spritesheet.regions[i].id] = i; @@ -882,18 +882,18 @@ struct Open { - std::string_view tag{}; - bool isEmpty{true}; - bool isTextDone{}; + std::string_view tag; + bool isEmpty = true; + bool isTextDone = false; }; - Mode mode{TEXT}; - std::string text{}; - std::uint64_t hash{HASH_OFFSET}; - XmlNode root{}; - std::vector stack{}; - std::vector nodes{}; - int textDepth{-1}; + Mode mode = TEXT; + std::string text; + std::uint64_t hash = HASH_OFFSET; + XmlNode root = {}; + std::vector stack; + std::vector nodes; + int textDepth = -1; void hash_add(char marker, std::string_view value) { @@ -1046,10 +1046,10 @@ void node(const XmlNode& node) { open(node.tag); - for (const auto& [name, value] : node.attributes) + for (auto& [name, value] : node.attributes) attribute_text(name, value); text_add(node.text); - for (const auto& child : node.children) + for (auto& child : node.children) this->node(child); close(); } @@ -1059,7 +1059,7 @@ // children at their recorded positions among the known ones. static void extras_attributes_write(Sink& sink, const Extras& extras) { - for (const auto& [name, value] : extras.attributes) + for (auto& [name, value] : extras.attributes) sink.attribute_text(name, value); } @@ -1074,8 +1074,8 @@ { Sink& sink; const Extras& extras; - std::size_t next{}; - int position{}; + std::size_t next = 0; + int position = 0; void add() { @@ -1149,8 +1149,8 @@ // A frame baked into single steps for the game records, on its first step, how to read them back as one. struct FrameBake { - Interpolation interpolation{}; - int delay{}; + Interpolation interpolation = {}; + int delay = 0; }; static void frame_write(Sink& sink, const Writer& writer, const Frame& frame, ItemType type, FrameBake bake = {}) @@ -1161,7 +1161,7 @@ if (!frame.eventIds.empty()) sink.attribute("EventId", frame.eventIds.front()); sink.attribute("AtFrame", frame.atFrame); extras_write(sink, frame.extras); - Children children{sink, frame.extras}; + Children children = {sink, frame.extras}; if (writer.is(SERIALIZE_EXTENSIONS)) for (auto eventId : frame.eventIds | std::views::drop(1)) { @@ -1257,7 +1257,7 @@ } extras_write(sink, track.extras); - Children children{sink, track.extras}; + Children children = {sink, track.extras}; auto layerTrack = track.type == ItemType::LAYER && !isBackup ? &track : nullptr; for (int i = 0; i < (int)track.frames.size(); ++i) { @@ -1295,7 +1295,7 @@ sink.attribute("Visible", group.isVisible); if (index) sink.attribute("Index", *index); extras_write(sink, group.extras); - Children children{sink, group.extras}; + Children children = {sink, group.extras}; if constexpr (requires { group.root; }) { children.add(); @@ -1309,8 +1309,8 @@ struct ContainerChild { std::function, const std::function&)> write{}; - int groupId{-1}; - std::optional ownGroupId{}; + int groupId = -1; + std::optional ownGroupId; }; template static ContainerChild group_child_make(Sink& sink, const Writer& writer, const Group& group) @@ -1326,26 +1326,26 @@ ElementType groupsType = ElementType::UNKNOWN) { extras_write(sink, extras); - for (const auto& [index, node] : extras.children) + for (auto& [index, node] : extras.children) flat.insert(flat.begin() + std::min(index, (int)flat.size()), ContainerChild{.write = [&sink, &node](std::optional, const std::function&) { sink.node(node); }}); auto isGroups = writer.is(SERIALIZE_GROUPS); - std::map> grouped{}; + std::map> grouped; if (isGroups && writer.is(SERIALIZE_NESTED_GROUPS)) { - std::set groupIds{}; - for (const auto& child : flat) + std::set groupIds; + for (auto& child : flat) if (child.ownGroupId && *child.ownGroupId >= 0) groupIds.insert(*child.ownGroupId); - for (const auto& child : flat) + for (auto& child : flat) if (!child.ownGroupId && groupIds.contains(child.groupId)) grouped[child.groupId].push_back(child); std::erase_if(flat, [&](const ContainerChild& child) { return !child.ownGroupId && groupIds.contains(child.groupId); }); } auto isExtracted = groupsType != ElementType::UNKNOWN && isGroups && !writer.is(SERIALIZE_NESTED_GROUPS); - std::vector extracted{}; + std::vector extracted; for (int i = 0; i < (int)flat.size(); ++i) { auto& child = flat[i]; @@ -1376,21 +1376,21 @@ static void track_entries_write(Sink& sink, const Writer& writer, const std::vector& entries, ElementType type, const Extras& extras) { - std::vector flat{}; + std::vector flat; auto track_child_make = [&](const Track& track, int groupId) { return ContainerChild{.write = [&, groupId](std::optional, const std::function&) { track_write(sink, writer, track, groupId); }, .groupId = groupId}; }; - for (const auto& entry : entries) + for (auto& entry : entries) if (auto track = std::get_if(&entry)) flat.push_back(track_child_make(*track, -1)); else { auto& group = std::get(entry); flat.push_back(group_child_make(sink, writer, group)); - for (const auto& groupTrack : group.tracks) + for (auto& groupTrack : group.tracks) flat.push_back(track_child_make(groupTrack, group.id)); } sink.open(tag_get(type)); @@ -1401,14 +1401,14 @@ static bool is_frame_transform_default(const Frame& frame) { - Frame base{}; + Frame base = {}; return frame.position == base.position && frame.scale == base.scale && frame.rotation == base.rotation && frame.skew == base.skew && frame.tint == base.tint && frame.colorOffset == base.colorOffset; } IsaacIssues isaac_issues_get(const Model& model) { - IsaacIssues issues{}; + IsaacIssues issues = {}; issues.animationLayers = (int)std::ranges::count_if(model.content.layers, &Layer::is_animation); issues.vectorSpritesheets = (int)spritesheets_vector_used_get(model).size(); for (auto [index, animation] : model.animations_get()) @@ -1420,7 +1420,7 @@ *animation, [&](const Track& track) { - for (const auto& frame : track.frames) + for (auto& frame : track.frames) { issues.easedFrames += track.type != ItemType::TRIGGER && is_special_interpolation(frame.interpolation); issues.skewFrames += frame.skew != glm::vec2(); @@ -1447,7 +1447,7 @@ [&](TrackGroup& group) { if (std::ranges::all_of(group.root.frames, is_frame_transform_default)) return; - Sink backup{.mode = Sink::TREE}; + Sink backup = {.mode = Sink::TREE}; backup.open(FRAME_RESTORE_TAG); track_write(backup, writer, group.root); for (auto& track : group.tracks) @@ -1489,7 +1489,7 @@ auto isBaked = writer.model && (writer.is(SERIALIZE_BAKE_GROUP_FRAMES) || writer.is(SERIALIZE_FLATTEN_SPECIAL_INTERPOLATED_FRAMES)); auto baked = isBaked ? std::optional(animation_bake(writer, source)) : std::nullopt; - const auto& animation = baked ? *baked : source; + auto& animation = baked ? *baked : source; sink.open(tag_get(ElementType::ANIMATION)); sink.attribute("Name", animation.name); @@ -1501,7 +1501,7 @@ if (groupId != -1 && is_group_id_written(writer)) sink.attribute("GroupId", groupId); extras_write(sink, animation.extras); - Children children{sink, animation.extras}; + Children children = {sink, animation.extras}; for (auto type : layout_get(animation.layout, {{ElementType::ROOT_ANIMATION, !animation.root.frames.empty()}, {ElementType::LAYER_ANIMATIONS, !animation.layers.empty()}, {ElementType::NULL_ANIMATIONS, !animation.nulls.empty()}, @@ -1520,21 +1520,21 @@ static void animations_write(Sink& sink, const Writer& writer, const Animations& animations) { - std::vector flat{}; + std::vector flat; auto animation_child_make = [&](const Animation& animation, int groupId) { return ContainerChild{.write = [&, groupId](std::optional, const std::function&) { animation_write(sink, writer, animation, groupId); }, .groupId = groupId}; }; - for (const auto& entry : animations.entries) + for (auto& entry : animations.entries) if (auto animation = std::get_if>(&entry)) flat.push_back(animation_child_make(**animation, -1)); else { auto& group = std::get(entry); flat.push_back(group_child_make(sink, writer, group)); - for (const auto& groupAnimation : group.animations) + for (auto& groupAnimation : group.animations) flat.push_back(animation_child_make(*groupAnimation, group.id)); } sink.open(tag_get(ElementType::ANIMATIONS)); @@ -1568,7 +1568,7 @@ sink.attribute("Id", id); path_add(sink, "Path", spritesheet.path); extras_write(sink, spritesheet.extras); - Children children{sink, spritesheet.extras}; + Children children = {sink, spritesheet.extras}; if (writer.is(SERIALIZE_REGIONS)) for (int i = 0; i < (int)spritesheet.regions.size(); ++i) { @@ -1592,16 +1592,16 @@ path_add(sink, "Vertex", shader.vertex); path_add(sink, "Fragment", shader.fragment); extras_write(sink, shader.extras); - Children children{sink, shader.extras}; - for (const auto& uniform : shader.uniforms) + Children children = {sink, shader.extras}; + for (auto& uniform : shader.uniforms) { children.add(); sink.open(tag_get(ElementType::UNIFORM)); sink.attribute("Name", uniform.name); binding_value_add(sink, uniform.binding, uniform.value); extras_write(sink, uniform.extras); - Children components{sink, uniform.extras}; - for (const auto& component : uniform.components) + Children components = {sink, uniform.extras}; + for (auto& component : uniform.components) { components.add(); sink.open(tag_get(ElementType::COMPONENT)); @@ -1672,8 +1672,8 @@ // A content container's unknown XML (a file may repeat a container; its parts are merged in order). static Extras container_extras_get(const Content& content, ElementType type) { - Extras merged{}; - for (const auto& [extrasType, extras] : content.containerExtras) + Extras merged = {}; + for (auto& [extrasType, extras] : content.containerExtras) { if (extrasType != type) continue; merged.attributes.insert(merged.attributes.end(), extras.attributes.begin(), extras.attributes.end()); @@ -1689,7 +1689,7 @@ { sink.open(tag_get(type)); extras_write(sink, extras); - Children children{sink, extras}; + Children children = {sink, extras}; auto isRenumbered = writer.model && (type == ElementType::LAYERS || type == ElementType::SHADERS); for (int i = 0; i < (int)items.size(); ++i) { @@ -1703,7 +1703,7 @@ { sink.open(tag_get(ElementType::CONTENT)); extras_write(sink, content.extras); - Children children{sink, content.extras}; + Children children = {sink, content.extras}; for (auto type : layout_get(content.layout, {{ElementType::SPRITESHEETS, !content.spritesheets.empty()}, {ElementType::SHADERS, !content.shaders.empty()}, {ElementType::LAYERS, !content.layers.empty()}, @@ -1740,7 +1740,7 @@ Writer writer(flags, &model); sink.open(tag.empty() ? tag_get(ElementType::ANIMATED_ACTOR) : tag); extras_write(sink, model.extras); - Children children{sink, model.extras}; + Children children = {sink, model.extras}; auto isIgnored = writer.is(SERIALIZE_EXTENSIONS) && model.info.isIsaacIgnored; auto isInfo = model.info.fps != Info{}.fps || model.info.createdBy != Info{}.createdBy || isIgnored; for (auto type : layout_get(model.layout, {{ElementType::INFO, isInfo}, @@ -1780,7 +1780,7 @@ // The text of whatever `write` sends to a sink. template static std::string text_get(Write&& write) { - Sink sink{}; + Sink sink = {}; write(sink); return std::move(sink.text); } @@ -1805,7 +1805,7 @@ static bool document_load(Model& model, std::string_view text, std::string* errorString) { - pugi::xml_document document{}; + pugi::xml_document document; if (!document_parse(document, text, errorString)) return model_invalid_set(model); auto root = document.document_element(); if (!root) @@ -1821,14 +1821,14 @@ Model model_make() { - Model model{}; + Model model = {}; model.info.createdOn = timestamp_get(CREATED_ON_FORMAT); return model; } bool model_load(Model& model, const std::filesystem::path& path, std::string* errorString) { - std::string text{}; + std::string text; if (file_text_load(path, &text)) return model_load_string(model, text, errorString); if (errorString) *errorString = "File not found."; return model_invalid_set(model); @@ -1868,7 +1868,7 @@ // The hash of what the editor would save, so it changes exactly when a save would. std::uint64_t model_hash(const Model& model) { - Sink sink{.mode = Sink::HASH}; + Sink sink = {.mode = Sink::HASH}; model_write(sink, model, SERIALIZE_ANM2ED_DEFAULT); return sink.hash; } @@ -1890,10 +1890,10 @@ std::vector frames_from_string(const std::string& text, ItemType type, std::string* errorString) { - pugi::xml_document document{}; + pugi::xml_document document; if (!document_parse(document, text, errorString)) return {}; auto tag = tag_get(type == ItemType::TRIGGER ? ElementType::TRIGGER : ElementType::FRAME); - std::vector frames{}; + std::vector frames; for (auto element : document.children(tag)) frames.push_back(frame_read(element)); if (frames.empty() && errorString) *errorString = std::format("No valid {}(s).", tag); @@ -1902,9 +1902,9 @@ std::vector animations_from_string(const std::string& text, std::string* errorString) { - pugi::xml_document document{}; + pugi::xml_document document; if (!document_parse(document, text, errorString)) return {}; - Extras extras{}; + Extras extras = {}; auto entries = animation_entries_read(document, extras); if (entries.empty() && errorString) *errorString = "No valid animation(s)."; return entries; @@ -1917,10 +1917,10 @@ template static std::vector items_from_string(const std::string& text, std::string* errorString) { - pugi::xml_document document{}; + pugi::xml_document document; if (!document_parse(document, text, errorString)) return {}; auto tag = tag_get(ITEM_TYPE); - std::vector items{}; + std::vector items; for (auto element : document.children(tag)) { auto item = item_read(element); diff --git a/src/model/xml.h b/src/model/xml.h index c9408ab..82dd9d8 100644 --- a/src/model/xml.h +++ b/src/model/xml.h @@ -9,17 +9,17 @@ // What the game's copy of a save can't keep as it is: how many of each. struct IsaacIssues { - int easedFrames{}; - int groupTransforms{}; - int skewFrames{}; - int shaderFrames{}; - int depthFrames{}; - int alphaOffsetFrames{}; - int blurFrames{}; - int triggerSounds{}; - int extraEvents{}; - int animationLayers{}; - int vectorSpritesheets{}; + int easedFrames = 0; + int groupTransforms = 0; + int skewFrames = 0; + int shaderFrames = 0; + int depthFrames = 0; + int alphaOffsetFrames = 0; + int blurFrames = 0; + int triggerSounds = 0; + int extraEvents = 0; + int animationLayers = 0; + int vectorSpritesheets = 0; bool operator==(const IsaacIssues&) const = default; }; diff --git a/src/pack.cpp b/src/pack.cpp index cf3f9be..f69c130 100644 --- a/src/pack.cpp +++ b/src/pack.cpp @@ -9,10 +9,10 @@ struct Rect { - int x{}; - int y{}; - int w{}; - int h{}; + int x = 0; + int y = 0; + int w = 0; + int h = 0; }; static bool is_rect_intersecting(const Rect& a, const Rect& b) @@ -27,7 +27,7 @@ static void free_rects_split(std::vector& freeRects, const Rect& used) { - std::vector next{}; + std::vector next; next.reserve(freeRects.size() * 2); for (auto& free : freeRects) { @@ -74,7 +74,7 @@ { int bestShort = std::numeric_limits::max(); int bestLong = std::numeric_limits::max(); - bool isFound{}; + bool isFound = false; for (auto& free : freeRects) { if (size.x > free.w || size.y > free.h) continue; @@ -98,7 +98,7 @@ glm::ivec2 maxSize{}; glm::ivec2 sumSize{}; - std::int64_t totalArea{}; + std::int64_t totalArea = 0; for (auto& size : sizes) { maxSize = glm::max(maxSize, size); @@ -116,7 +116,7 @@ { std::vector candidate(sizes.size()); glm::ivec2 used{}; - bool isValid{}; + bool isValid = false; for (int height = std::max(maxSize.y, (int)std::ceil((double)totalArea / width)); height <= sumSize.y && !isValid; ++height) { @@ -125,7 +125,7 @@ isValid = true; for (int i = 0; i < (int)sizes.size() && isValid; ++i) { - Rect rect{}; + Rect rect = {}; isValid = rect_insert(freeRects, sizes[i], rect); candidate[i] = {rect.x, rect.y}; used = glm::max(used, glm::ivec2(rect.x + rect.w, rect.y + rect.h)); diff --git a/src/path.cpp b/src/path.cpp index 93f2d52..2a8153f 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -96,7 +96,7 @@ if (path.empty()) return path; if (!path.is_absolute()) return path; - std::error_code ec{}; + std::error_code ec; auto relative = std::filesystem::relative(path, ec); if (!ec) return relative; return path; @@ -107,7 +107,7 @@ if (path.empty()) return path; if (base.empty() || !path.is_absolute()) return path; - std::error_code ec{}; + std::error_code ec; auto relative = std::filesystem::relative(path, base, ec); if (!ec) return relative; return path; @@ -128,7 +128,7 @@ if (is_path_exist(handledPath)) return handledPath; auto resolvedPath = handledPath.root_path(); - for (const auto& part : handledPath.relative_path()) + for (auto& part : handledPath.relative_path()) { auto candidate = resolvedPath / part; if (is_path_exist(candidate)) @@ -138,13 +138,13 @@ } auto parent = resolvedPath.empty() ? std::filesystem::path(".") : resolvedPath; - std::error_code ec{}; - bool isFound{}; + std::error_code ec; + bool isFound = false; if (std::filesystem::is_directory(parent, ec)) { auto partLower = path_to_lower(part); std::filesystem::directory_iterator it(parent, ec); - std::filesystem::directory_iterator end{}; + std::filesystem::directory_iterator end = {}; for (; !ec && it != end; it.increment(ec)) if (path_to_lower(it->path().filename()) == partLower) { diff --git a/src/playback.h b/src/playback.h index 8b309a0..30e9c15 100644 --- a/src/playback.h +++ b/src/playback.h @@ -3,9 +3,9 @@ class Playback { public: - float time{}; - bool isPlaying{}; - bool isFinished{}; + float time = 0; + bool isPlaying = false; + bool isFinished = false; void toggle(); void timing_reset(); @@ -15,5 +15,5 @@ void increment(int); private: - float tickAccumulator{}; + float tickAccumulator = 0; }; diff --git a/src/render.cpp b/src/render.cpp index 82d0462..d852efd 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -46,10 +46,10 @@ std::filesystem::remove(ffmpegTempPath, ffmpegTempError); #endif - std::filesystem::path audioPath{}; - std::string audioInputArguments{}; - std::string audioOutputArguments{"-an"}; - std::string command{}; + std::filesystem::path audioPath; + std::string audioInputArguments; + std::string audioOutputArguments = "-an"; + std::string command; auto temporaryDirectory = framePaths.front().parent_path(); if (temporaryDirectory.empty()) temporaryDirectory = std::filesystem::temp_directory_path(); @@ -202,7 +202,7 @@ // PNG sequences go straight to their folder; other outputs collect frames in a temporary folder beside the output. static std::filesystem::path frames_directory_create(const RecorderOptions& options) { - std::error_code ec{}; + std::error_code ec; if (options.type == RENDER_PNGS) { std::filesystem::create_directories(options.path, ec); @@ -258,9 +258,9 @@ auto channels = std::max(mixSpec.channels, 1); auto framesPerStep = (double)std::max(mixSpec.freq, 1) / (double)fps; auto accumulator = 0.0; - std::vector buffer{}; + std::vector buffer; auto isGenerated = true; - for (const auto& sounds : frameSounds) + for (auto& sounds : frameSounds) { for (auto sound : sounds) audio_play(*sound, false, mixer); @@ -315,7 +315,7 @@ float scale, glm::vec4 background, bool isRootTransform) { canvas.size_set(glm::vec2(glm::max(glm::ivec2(glm::ceil(glm::vec2(bounds.z, bounds.w) * scale)), glm::ivec2(1)))); - float zoom{}; + float zoom = 0; glm::vec2 pan{}; canvas.set_to_rect(zoom, pan, bounds); canvas.bind(); @@ -380,7 +380,7 @@ toast_log(Level::ERROR, TOAST_SPRITESHEET_EMPTY); else { - Image sheet{}; + Image sheet = {}; sheet.size = first.size * glm::ivec2(layout.columns, layout.rows); sheet.pixels.resize((std::size_t)sheet.size.x * sheet.size.y * IMAGE_CHANNELS); for (int i = 0; i < (int)frames.size() && i < layout.rows * layout.columns; ++i) @@ -410,7 +410,7 @@ // Stops; the temporary frame folder is removed (a PNG sequence's own folder is kept). void Recorder::cancel() { - std::error_code ec{}; + std::error_code ec; if (options.type != RENDER_PNGS && !directory.empty()) std::filesystem::remove_all(directory, ec); directory.clear(); frames.clear(); @@ -424,7 +424,7 @@ { auto options = recorderOptions; options.isIsolated = options.isBounded = true; - Recorder recorder{}; + Recorder recorder = {}; if (!recorder.start(options)) return false; while (!recorder.is_done()) { @@ -464,7 +464,7 @@ auto size = glm::ivec2(high - low); canvas.size_set(glm::vec2(size)); - float zoom{}; + float zoom = 0; glm::vec2 pan{}; canvas.set_to_rect(zoom, pan, glm::vec4(low, glm::vec2(size))); canvas.bind(); @@ -492,7 +492,7 @@ auto is_skewed = [](const Track& root) { return std::ranges::any_of(root.frames, [](const Frame& frame) { return frame.skew != glm::vec2(); }); }; - std::vector indices{}; + std::vector indices; for (int i = 0; i < game.animations_count_get(); ++i) { auto& animation = *game.animation_get(i); @@ -512,8 +512,8 @@ auto& content = game.content; auto spritesheetId = item_next_id_get(content.spritesheets); - std::vector images{}; - std::map> imageHashes{}; + std::vector images; + std::map> imageHashes; auto image_index_get = [&](Image image) { auto hash = @@ -524,7 +524,7 @@ images.push_back(std::move(image)); return (int)images.size() - 1; }; - std::map bakedLayerIds{}; + std::map bakedLayerIds; auto baked_layer_id_get = [&](int layerId) { auto [it, isNew] = bakedLayerIds.try_emplace(layerId); @@ -561,9 +561,9 @@ auto isForced = isRootFolded || groupRoot; auto layer = item_get(content.layers, track.id); if (!layer || (!isForced && std::ranges::none_of(track.frames, is_baked))) return {}; - Track plain{track}; + Track plain = track; plain.frames.clear(); - Track baked{.type = ItemType::LAYER, .id = -1, .isVisible = track.isVisible}; + Track baked = {.type = ItemType::LAYER, .id = -1, .isVisible = track.isVisible}; auto isBaked = false; auto length = std::max(track_length_get(track), animation.frameNum); for (int time = 0; time < length; ++time) @@ -622,7 +622,7 @@ return baked; }; - std::vector entries{}; + std::vector entries; for (auto& entry : animation.layers) if (auto track = std::get_if(&entry)) { @@ -634,7 +634,7 @@ { auto group = std::get(entry); auto isGroupFolded = is_skewed(group.root); - std::vector tracks{}; + std::vector tracks; for (auto& groupTrack : group.tracks) { auto baked = track_bake(groupTrack, isGroupFolded ? &group.root : nullptr); @@ -667,12 +667,12 @@ if (images.empty()) return; std::vector sizes{}; - for (const auto& image : images) + for (auto& image : images) sizes.push_back(image.size); glm::ivec2 packedSize{}; std::vector positions{}; rects_pack(sizes, packedSize, positions); - std::vector parts{}; + std::vector parts; for (int i = 0; i < (int)images.size(); ++i) parts.push_back({.image = &images[i], .size = images[i].size, .destination = positions[i]}); if (!Image::compose(parts, packedSize, false).write_png(path)) @@ -681,7 +681,7 @@ toast_log(Level::WARNING, TOAST_BAKE_LARGE, pathUtf8, packedSize.x, packedSize.y, BAKED_SIZE_MAX); content.spritesheets.push_back({.id = spritesheetId, .path = path.filename()}); - std::set bakedIds{}; + std::set bakedIds; for (auto [layerId, bakedId] : bakedLayerIds) bakedIds.insert(bakedId); for (auto index : indices) diff --git a/src/render.h b/src/render.h index 2613ae0..a838ed1 100644 --- a/src/render.h +++ b/src/render.h @@ -57,8 +57,8 @@ struct SDL_GLContextState; struct SpritesheetLayout { - int rows{}; - int columns{}; + int rows = 0; + int columns = 0; }; inline int frame_count_get(int start, int end) { return std::max(end - start + 1, 1); } @@ -119,8 +119,8 @@ struct SDL_GLContextState; // An OpenGL context with no visible window, for drawing animations outside the editor (the CLI, render tests). class HeadlessGL { - SDL_Window* window{}; - SDL_GLContextState* context{}; + SDL_Window* window = nullptr; + SDL_GLContextState* context = nullptr; public: HeadlessGL(); @@ -138,19 +138,19 @@ struct SDL_GLContextState; struct RecorderOptions { - RenderType type{}; - std::filesystem::path path{}; - std::filesystem::path format{}; - std::filesystem::path ffmpegPath{}; - int start{}; - int end{}; - int animationFps{1}; - int fps{1}; - int rows{}; - int columns{}; - bool isSound{}; - bool isIsolated{}; - bool isBounded{}; + RenderType type = {}; + std::filesystem::path path; + std::filesystem::path format; + std::filesystem::path ffmpegPath; + int start = 0; + int end = 0; + int animationFps = 1; + int fps = 1; + int rows = 0; + int columns = 0; + bool isSound = false; + bool isIsolated = false; + bool isBounded = false; }; // A render in progress: which animation times to capture, the frames captured so far (written to disk) and the @@ -158,9 +158,9 @@ struct SDL_GLContextState; class Recorder { public: - RecorderOptions options{}; - int index{}; - int count{}; + RecorderOptions options = {}; + int index = 0; + int count = 0; bool start(const RecorderOptions&); bool is_done() const; @@ -171,10 +171,10 @@ struct SDL_GLContextState; void cancel(); private: - std::filesystem::path directory{}; - std::vector frames{}; - std::vector> sounds{}; - int soundTime{-1}; + std::filesystem::path directory; + std::vector frames; + std::vector> sounds; + int soundTime = -1; }; // Records a whole animation with these options (bounded and isolated), each frame drawn as animation_frame_render diff --git a/src/resources.h b/src/resources.h index ec73d7a..e37d58f 100644 --- a/src/resources.h +++ b/src/resources.h @@ -14,7 +14,7 @@ Font fonts[FONT_COUNT]{}; Image icons[ICON_COUNT]{}; ShaderProgram shaders[SHADER_COUNT]{}; - AudioData music{}; + AudioData music = {}; Resources(); GLuint icon_id_get(int); @@ -22,5 +22,5 @@ AudioData* music_track_if_loaded(); private: - bool isMusicLoaded{false}; + bool isMusicLoaded = false; }; diff --git a/src/selection.cpp b/src/selection.cpp index be16804..0dd560c 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -3,7 +3,7 @@ std::set selection_references_get(const Selection& selection, const UidIndex& index, SelectionKind kind) { - std::set references{}; + std::set references; if (auto uids = selection.uids.find(kind); uids != selection.uids.end()) for (auto uid : uids->second) if (auto reference = index.reference_get(uid)) references.insert(*reference); @@ -41,10 +41,10 @@ static std::vector> content_keys_get(const Selection& selection, const Model& model, SelectionKind kind) { - std::vector> keys{}; + std::vector> keys; auto add = [&](const auto& items) { - for (const auto& item : items) + for (auto& item : items) keys.emplace_back(item.id, item.uid); }; auto& content = model.content; @@ -64,7 +64,7 @@ std::set selection_ids_get(const Selection& selection, const Model& model, SelectionKind kind) { - std::set ids{}; + std::set ids; auto uids = selection.uids.find(kind); if (uids == selection.uids.end()) return ids; for (auto [id, uid] : content_keys_get(selection, model, kind)) diff --git a/src/selection.h b/src/selection.h index 06df020..7a74a3a 100644 --- a/src/selection.h +++ b/src/selection.h @@ -26,9 +26,9 @@ // so nothing here is repaired by index; the UI reads it as References through a UidIndex. struct Selection { - std::map> uids{}; - Handle focus{}; - std::map focuses{}; + std::map> uids; + Handle focus = {}; + std::map focuses; bool operator==(const Selection&) const = default; }; diff --git a/src/settings.cpp b/src/settings.cpp index 9d2d4bd..c576b4f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -193,7 +193,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991 isDefault = true; } - std::string fileData{}; + std::string fileData; if (!file_text_load(path, &fileData, "rb")) { logger.error(std::format("Failed to open settings file: {}", pathUtf8)); @@ -201,7 +201,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991 } std::istringstream file(fileData); - std::string line{}; + std::string line; auto stream_assign = [](auto& dest, std::istringstream& ss) { ss >> dest; }; @@ -283,7 +283,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991 std::string Settings::imgui_data_load(const std::filesystem::path& path) { auto pathUtf8 = path_to_utf8(path); - std::string fileData{}; + std::string fileData; if (!file_text_load(path, &fileData, "rb")) { logger.error( @@ -292,7 +292,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991 } std::istringstream file(fileData); - std::string line{}; + std::string line; std::ostringstream dataStream; bool isImGuiSection = false; bool isContent = false; @@ -330,7 +330,7 @@ DockSpace ID=0x123F8F08 Window=0x6D581B32 Pos=8,62 Size=1902,991 { auto pathUtf8 = path_to_utf8(path); logger.info(std::format("Saving settings to: {}", pathUtf8)); - std::ostringstream file{}; + std::ostringstream file; file << "[Settings]\n"; diff --git a/src/settings.h b/src/settings.h index fc394c2..a25640e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -321,7 +321,7 @@ SETTINGS_MEMBERS SETTINGS_SHORTCUTS SETTINGS_WINDOWS #undef X - bool isDefault{}; + bool isDefault = false; Settings() = default; diff --git a/src/shader.cpp b/src/shader.cpp index 7208807..8f93c44 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -15,8 +15,8 @@ struct UniformAlias { - UniformBinding binding{}; - const char* name{}; + UniformBinding binding = {}; + const char* name = nullptr; }; #define RESOURCE_SHADER_UNIFORM_ALIASES \ @@ -52,7 +52,7 @@ static std::string shader_text_replace(std::string string, std::string_view from, std::string_view to) { if (from.empty()) return string; - std::size_t position{}; + std::size_t position = 0; while ((position = string.find(from, position)) != std::string::npos) { string.replace(position, from.size(), to.data(), to.size()); @@ -65,7 +65,7 @@ { if (from.empty()) return string; - std::size_t position{}; + std::size_t position = 0; while ((position = string.find(from, position)) != std::string::npos) { auto after = position + from.size(); @@ -84,8 +84,8 @@ static std::string shader_space_collapse(std::string_view string) { - std::string out{}; - bool isSpace{}; + std::string out; + bool isSpace = false; for (auto character : string) { if (std::isspace((unsigned char)character)) @@ -103,7 +103,7 @@ static std::string shader_trim_get(std::string_view line) { - std::size_t begin{}; + std::size_t begin = 0; while (begin < line.size() && std::isspace((unsigned char)line[begin])) ++begin; @@ -116,7 +116,7 @@ static bool is_shader_word_present(std::string_view string, std::string_view word) { - std::size_t position{}; + std::size_t position = 0; while ((position = string.find(word, position)) != std::string_view::npos) { auto after = position + word.size(); @@ -177,7 +177,7 @@ UniformBinding uniform_binding_auto_get(std::string_view name, UniformValueType type) { - for (const auto& alias : UNIFORM_ALIASES) + for (auto& alias : UNIFORM_ALIASES) if (name == alias.name && is_uniform_binding_valid(alias.binding, type)) return alias.binding; if (type == UNIFORM_VALUE_SAMPLER2D) return UNIFORM_BINDING_MAIN_TEXTURE; if (is_uniform_value_editable(type)) return UNIFORM_BINDING_MANUAL; @@ -186,21 +186,21 @@ UniformBinding uniform_binding_get(std::string_view value) { - for (const auto& info : UNIFORM_BINDING_INFOS) + for (auto& info : UNIFORM_BINDING_INFOS) if (value == info.value) return info.binding; return UNIFORM_BINDING_IGNORE; } std::string_view uniform_binding_value_get(UniformBinding binding) { - for (const auto& info : UNIFORM_BINDING_INFOS) + for (auto& info : UNIFORM_BINDING_INFOS) if (binding == info.binding) return info.value; return UNIFORM_BINDING_INFOS[0].value; } std::string_view uniform_binding_label_get(UniformBinding binding) { - for (const auto& info : UNIFORM_BINDING_INFOS) + for (auto& info : UNIFORM_BINDING_INFOS) if (binding == info.binding) return info.label; return UNIFORM_BINDING_INFOS[0].label; } @@ -391,26 +391,26 @@ static std::vector uniforms_get(GLuint id) { - GLint count{}; - GLint maxLength{}; + GLint count = 0; + GLint maxLength = 0; glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &count); glGetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxLength); - std::vector uniforms{}; + std::vector uniforms; if (count <= 0 || maxLength <= 0) return uniforms; std::string name((std::size_t)maxLength, '\0'); for (GLint index = 0; index < count; ++index) { - GLsizei length{}; - GLint size{}; - GLenum type{}; + GLsizei length = 0; + GLint size = 0; + GLenum type = 0; glGetActiveUniform(id, (GLuint)index, maxLength, &length, &size, &type, name.data()); auto uniformName = uniform_name_clean_get(std::string(name.data(), (std::size_t)length)); auto valueType = uniform_value_type_get(type); - ShaderUniform uniform{}; + ShaderUniform uniform = {}; uniform.name = uniformName; uniform.location = glGetUniformLocation(id, uniformName.c_str()); uniform.glType = type; @@ -432,8 +432,8 @@ auto normalized = shader_text_replace(std::string(source), "\r\n", "\n"); normalized = shader_text_replace(std::move(normalized), "\r", "\n"); - std::string body{}; - std::size_t position{}; + std::string body; + std::size_t position = 0; while (position <= normalized.size()) { auto end = normalized.find('\n', position); @@ -454,19 +454,19 @@ ShaderCompileResult shader_compile(const char* vertex, const char* fragment) { - ShaderCompileResult result{}; + ShaderCompileResult result = {}; result.id = glCreateProgram(); auto compile = [&](const GLuint& id, const char* text, const char* label) { - int isCompile{}; + int isCompile = 0; glShaderSource(id, 1, &text, nullptr); glCompileShader(id); glGetShaderiv(id, GL_COMPILE_STATUS, &isCompile); if (!isCompile) { - GLint length{}; + GLint length = 0; glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length); if (length <= 0) length = 1; std::string compileLog((std::size_t)length, '\0'); @@ -488,7 +488,7 @@ glAttachShader(result.id, vertexHandle); glAttachShader(result.id, fragmentHandle); - for (const auto& alias : ATTRIBUTE_ALIASES) + for (auto& alias : ATTRIBUTE_ALIASES) glBindAttribLocation(result.id, alias.index, alias.name); glLinkProgram(result.id); @@ -498,7 +498,7 @@ result.isLinked = isLinked == GL_TRUE; if (!result.isLinked) { - GLint length{}; + GLint length = 0; glGetProgramiv(result.id, GL_INFO_LOG_LENGTH, &length); if (length <= 0) length = 1; std::string linkLog((std::size_t)length, '\0'); diff --git a/src/shader.h b/src/shader.h index b1ac233..a8f9cc4 100644 --- a/src/shader.h +++ b/src/shader.h @@ -277,8 +277,8 @@ struct AttributeAlias { - GLuint index{}; - const char* name{}; + GLuint index = 0; + const char* name = nullptr; }; inline constexpr AttributeAlias ATTRIBUTE_ALIASES[] = { @@ -308,9 +308,9 @@ struct UniformBindingInfo { - UniformBinding binding{}; - const char* value{}; - const char* label{}; + UniformBinding binding = {}; + const char* value = nullptr; + const char* label = nullptr; }; inline constexpr UniformBindingInfo UNIFORM_BINDING_INFOS[] = { @@ -339,9 +339,9 @@ struct UniformValueTypeInfo { - UniformValueType type{}; - const char* label{}; - int componentCount{}; + UniformValueType type = {}; + const char* label = nullptr; + int componentCount = 0; }; inline constexpr UniformValueTypeInfo UNIFORM_VALUE_TYPE_INFOS[] = { @@ -354,19 +354,19 @@ { struct Component { - UniformBinding binding{UNIFORM_BINDING_MANUAL}; - float value{}; + UniformBinding binding = UNIFORM_BINDING_MANUAL; + float value = 0; }; - std::string name{}; - GLint location{-1}; - GLenum glType{}; - GLint size{}; - UniformValueType valueType{UNIFORM_VALUE_UNKNOWN}; - UniformBinding binding{UNIFORM_BINDING_IGNORE}; + std::string name; + GLint location = -1; + GLenum glType = 0; + GLint size = 0; + UniformValueType valueType = UNIFORM_VALUE_UNKNOWN; + UniformBinding binding = UNIFORM_BINDING_IGNORE; glm::vec4 value{}; - int intValue{}; - std::array components{}; + int intValue = 0; + std::array components = {}; }; enum ShaderStage @@ -411,11 +411,11 @@ struct ShaderCompileResult { - GLuint id{}; - std::string output{}; - std::vector uniforms{}; - bool isCompiled{}; - bool isLinked{}; + GLuint id = 0; + std::string output; + std::vector uniforms; + bool isCompiled = false; + bool isLinked = false; }; ShaderCompileResult shader_compile(const char*, const char*); @@ -423,8 +423,8 @@ class ShaderProgram { public: - GLuint id{}; - std::vector uniforms{}; + GLuint id = 0; + std::vector uniforms; ShaderProgram(); ShaderProgram(const char*, const char*); diff --git a/src/snapshots.cpp b/src/snapshots.cpp index 94e0e3c..89e22b8 100644 --- a/src/snapshots.cpp +++ b/src/snapshots.cpp @@ -25,7 +25,7 @@ static void step_apply(Snapshot& current, const SnapshotStep& step, bool isUndo) { - const auto& target = isUndo ? step.before : step.after; + auto& target = isUndo ? step.before : step.after; #define X(type, name) \ if (!is_value_equal(step.before.name, step.after.name)) current.name = target.name; SNAPSHOT_STEP_STATE_FIELDS @@ -86,7 +86,7 @@ { if (pendingFocus) selection_follow(current, *std::exchange(pendingFocus, std::nullopt)); if (!pending) return; - SnapshotStep step{std::move(*std::exchange(pending, std::nullopt)), current}; + SnapshotStep step = {std::move(*std::exchange(pending, std::nullopt)), current}; if (is_step_empty(step)) return; undoStack.push(std::move(step)); redoStack.clear(); diff --git a/src/snapshots.h b/src/snapshots.h index 5fb3c46..14e2c29 100644 --- a/src/snapshots.h +++ b/src/snapshots.h @@ -34,8 +34,8 @@ // One undoable edit: the state before and after it; undo/redo restore only the fields the edit changed. struct SnapshotStep { - Snapshot before{}; - Snapshot after{}; + Snapshot before = {}; + Snapshot after = {}; }; class SnapshotStack @@ -58,11 +58,11 @@ class Snapshots { public: - SnapshotStack undoStack{}; - SnapshotStack redoStack{}; - Snapshot current{}; - std::optional pending{}; - std::optional pendingFocus{}; + SnapshotStack undoStack = {}; + SnapshotStack redoStack = {}; + Snapshot current = {}; + std::optional pending; + std::optional pendingFocus; void push(const std::string&); void commit(); diff --git a/src/socket.cpp b/src/socket.cpp index bbe8b95..b285212 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -8,13 +8,13 @@ { WSAInitializer() { - WSADATA data{}; + WSADATA data = {}; WSAStartup(MAKEWORD(2, 2), &data); } ~WSAInitializer() { WSACleanup(); } }; - WSAInitializer initializer{}; + WSAInitializer initializer = {}; #endif static int socket_last_error() @@ -97,7 +97,7 @@ return false; } - sockaddr_in addr{}; + sockaddr_in addr = {}; addr.sin_family = AF_INET; addr.sin_port = htons(address.port); @@ -141,7 +141,7 @@ Socket Socket::accept() { - Socket client{}; + Socket client = {}; if (!is_valid()) return client; auto accepted = ::accept(handle, nullptr, nullptr); @@ -166,7 +166,7 @@ return false; } - sockaddr_in addr{}; + sockaddr_in addr = {}; addr.sin_family = AF_INET; addr.sin_port = htons(address.port); diff --git a/src/socket.h b/src/socket.h index 43c788b..1531a43 100644 --- a/src/socket.h +++ b/src/socket.h @@ -25,16 +25,16 @@ constexpr socket_handle SOCKET_INVALID = -1; struct SocketAddress { - std::string host{}; - unsigned short port{}; + std::string host; + unsigned short port = {}; }; class Socket { private: socket_handle handle; - SocketRole role{}; - int lastError{}; + SocketRole role = {}; + int lastError = 0; public: Socket(); diff --git a/src/state.cpp b/src/state.cpp index 645258c..1d79ceb 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -22,7 +22,7 @@ { dialog = Dialog(window); - for (const auto& argument : arguments) + for (auto& argument : arguments) manager.open(path_from_utf8(argument)); manager.settings_apply(settings); @@ -40,7 +40,7 @@ SDL_GetWindowSize(window, &settings.windowSize.x, &settings.windowSize.y); SDL_GetWindowPosition(window, &settings.windowPosition.x, &settings.windowPosition.y); - SDL_Event event{}; + SDL_Event event = {}; while (SDL_PollEvent(&event)) { @@ -56,7 +56,7 @@ dockspace.update(taskbar, documents, manager, settings, resources, dialog, clipboard); */ - SDL_Event event{}; + SDL_Event event = {}; while (SDL_PollEvent(&event)) { @@ -181,7 +181,7 @@ if (!dockspace.is_canvas_focused_get()) { - float uiScaleDelta{}; + float uiScaleDelta = 0; if (shortcut(manager.chords[SHORTCUT_ZOOM_IN], SCOPE_GLOBAL)) uiScaleDelta += UI_SCALE_STEP; if (shortcut(manager.chords[SHORTCUT_ZOOM_OUT], SCOPE_GLOBAL)) uiScaleDelta -= UI_SCALE_STEP; if (uiScaleDelta != 0.0f) diff --git a/src/state.h b/src/state.h index bcd4d19..2cd3951 100644 --- a/src/state.h +++ b/src/state.h @@ -14,8 +14,8 @@ void render(SDL_Window*&, Settings&); public: - bool isQuit{}; - bool isQuitting{}; + bool isQuit = false; + bool isQuitting = false; Manager manager; Resources resources; Dialog dialog; @@ -25,12 +25,12 @@ Documents documents; Dockspace dockspace; - uint64_t previousTick{}; - uint64_t previousUpdate{}; - double tickAccumulatorMs{}; - bool wasRecording{}; - std::vector spritesheetDropPaths{}; - std::vector soundDropPaths{}; + uint64_t previousTick = 0; + uint64_t previousUpdate = 0; + double tickAccumulatorMs = 0; + bool wasRecording = false; + std::vector spritesheetDropPaths; + std::vector soundDropPaths; State(SDL_Window*&, Settings& settings, std::vector&); diff --git a/src/subprocess.cpp b/src/subprocess.cpp index a3d33a6..7cacaba 100644 --- a/src/subprocess.cpp +++ b/src/subprocess.cpp @@ -54,7 +54,7 @@ std::string Process::output_get_and_close() { - std::string output{}; + std::string output; if (!pipe) return {}; char buffer[256]; diff --git a/src/subprocess.h b/src/subprocess.h index 4461796..eb59c56 100644 --- a/src/subprocess.h +++ b/src/subprocess.h @@ -17,5 +17,5 @@ std::string output_get_and_close(); private: - FILE* pipe{}; + FILE* pipe = nullptr; }; diff --git a/src/texture.cpp b/src/texture.cpp index af5c070..3b15e54 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -7,11 +7,11 @@ struct TextureEntry { - GLuint id{}; - bool isUsed{}; + GLuint id = 0; + bool isUsed = false; }; - static std::unordered_map entries{}; + static std::unordered_map entries; GLuint texture_id_get(const Image& image) { diff --git a/src/tool.h b/src/tool.h index 77060d0..ffbc28a 100644 --- a/src/tool.h +++ b/src/tool.h @@ -32,14 +32,14 @@ struct ToolInfo { - ImGuiMouseCursor cursor{ImGuiMouseCursor_None}; - Icon icon{}; - ShortcutType shortcut{}; + ImGuiMouseCursor cursor = ImGuiMouseCursor_None; + Icon icon = {}; + ShortcutType shortcut = {}; ToolArea areaType; - const char* label{}; - StringType tooltip{}; - bool isFrameRequired{}; - bool isSpritesheetRequired{}; + const char* label = nullptr; + StringType tooltip = {}; + bool isFrameRequired = false; + bool isSpritesheetRequired = false; }; constexpr ToolInfo TOOLS[] = { diff --git a/src/ui/about.cpp b/src/ui/about.cpp index 0a77ea1..15ff7d9 100644 --- a/src/ui/about.cpp +++ b/src/ui/about.cpp @@ -180,7 +180,7 @@ using namespace glm; state.fps = 30.0f; state.isLoaded = false; - std::string errorString{}; + std::string errorString; if (!model_load_string(state.model, std::string_view((const char*)info.anm2->data, info.anm2->size), &errorString)) { logger.error(std::format("Unable to load friend animation {}: {}", info.name, errorString)); @@ -391,7 +391,7 @@ using namespace glm; auto left = side == 0 ? min.x : max.x - width; auto covered = 0.0f; auto weight = 1.0f; - for (const auto& frame : history) + for (auto& frame : history) { if (weight < ROLL_WEIGHT_MIN) break; auto height = frame.levels[side]; @@ -431,9 +431,9 @@ using namespace glm; drawList->AddRectFilled(min, max, ROLL_BACKGROUND); // Each tick faded what came before it by its trail alpha; the copies still visible are drawn oldest first. - std::vector> copies{}; + std::vector> copies; auto weight = 1.0f; - for (const auto& frame : roll.history) + for (auto& frame : roll.history) { if (weight < ROLL_WEIGHT_MIN) break; copies.emplace_back(&frame, weight); diff --git a/src/ui/about.h b/src/ui/about.h index cff88c7..6db7220 100644 --- a/src/ui/about.h +++ b/src/ui/about.h @@ -18,50 +18,50 @@ public: struct Credit { - const char* string{}; - FontStyle font{FONT_REGULAR}; + const char* string = nullptr; + FontStyle font = FONT_REGULAR; }; // One 30 Hz tick of the credits roll, after the original editor's About box. Lengths are in its pixels (for // 14 px text); `trailAlpha` is how much of what was drawn before this tick it faded out (255 clears it). struct RollFrame { - float scroll{}; - float offsetX{}; - float stretch{1.0f}; - int effect{}; - int trailAlpha{255}; + float scroll = 0; + float offsetX = 0; + float stretch = 1.0f; + int effect = 0; + int trailAlpha = 255; glm::vec2 levels{}; - float gradientHeight{}; - ImU32 gradientColor{}; + float gradientHeight = 0; + ImU32 gradientColor = 0; }; // The credits scroll up through a box, one of four effects per pass (none, sway, stretch to the music, wave), // between volume bars; recent ticks are kept to draw the trails they leave. struct RollState { - std::deque history{}; - float scroll{}; - float tickTime{}; - int tick{}; - int pass{}; - float levelPeak{}; - ImU32 titleColor{}; + std::deque history; + float scroll = 0; + float tickTime = 0; + int tick = 0; + int pass = 0; + float levelPeak = 0; + ImU32 titleColor = 0; }; struct FriendState { - Model model{}; - std::unique_ptr canvas{}; - std::unordered_map textures{}; + Model model = {}; + std::unique_ptr canvas; + std::unordered_map textures; glm::vec4 rect{-1.0f}; - float time{}; - float fps{30.0f}; - bool isLoaded{}; + float time = 0; + float fps = 30.0f; + bool isLoaded = false; }; - RollState roll{}; - std::array friendStates{}; + RollState roll = {}; + std::array friendStates = {}; void reset(Resources& resources); void update(Resources& resources); diff --git a/src/ui/actions.cpp b/src/ui/actions.cpp index e7ec3a1..f0fec62 100644 --- a/src/ui/actions.cpp +++ b/src/ui/actions.cpp @@ -55,7 +55,7 @@ static void action_items_menu_draw(std::vector& items, Settings& settings) { - bool isPreviousSeparator{}; + bool isPreviousSeparator = false; for (auto& action : items) { if (action.isSeparator) diff --git a/src/ui/actions.h b/src/ui/actions.h index 63f2a4e..c6b61cd 100644 --- a/src/ui/actions.h +++ b/src/ui/actions.h @@ -49,8 +49,8 @@ struct ActionInfo { - StringType label{}; - int shortcut{-1}; + StringType label = {}; + int shortcut = -1; }; constexpr ActionInfo ACTION_INFOS[] = { @@ -61,19 +61,19 @@ struct Action { - ActionType type{}; - StringType label{STRING_UNDEFINED}; - StringType tooltip{STRING_UNDEFINED}; - int shortcut{-1}; - bool isSeparator{}; + ActionType type = {}; + StringType label = STRING_UNDEFINED; + StringType tooltip = STRING_UNDEFINED; + int shortcut = -1; + bool isSeparator = false; std::function isEnabled{}; std::function run{}; - std::vector children{}; // a submenu, in menus + std::vector children; // a submenu, in menus }; struct Actions { - std::vector items{}; + std::vector items; void add(Action); void add(ActionType, std::function, std::function, StringType = STRING_UNDEFINED, diff --git a/src/ui/animation_preview.cpp b/src/ui/animation_preview.cpp index 4db10d3..9304287 100644 --- a/src/ui/animation_preview.cpp +++ b/src/ui/animation_preview.cpp @@ -41,9 +41,9 @@ using namespace glm; constexpr auto TRIGGER_TEXT_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 0.5f); struct OverlayAnimationOption { - uint64_t documentId{}; - int animationIndex{-1}; - std::string label{}; + uint64_t documentId = 0; + int animationIndex = -1; + std::string label; }; static std::vector overlay_animation_options_get(Manager& manager) @@ -65,7 +65,7 @@ using namespace glm; static std::vector overlay_animation_option_labels_get(std::vector& options) { - std::vector labels{}; + std::vector labels; labels.reserve(options.size()); for (auto& option : options) labels.push_back(option.label.c_str()); @@ -606,7 +606,7 @@ using namespace glm; .isRootTransform = isRootTransform, .isIndexSampled = settings.onionskinMode == (int)OnionskinMode::INDEX}; std::vector sampleColors{}; - std::vector sampleAlphas{}; + std::vector sampleAlphas; auto samples_add = [&](int count, int direction, vec3 color) { for (int i = 1; i <= count; ++i) @@ -664,7 +664,7 @@ using namespace glm; auto targetIcon = resources.icon_id_get(isAltIcons && !isIsolated ? ICON_TARGET_ALT : ICON_TARGET); auto sampleOptions = options; sampleOptions.library_get = sampleDocument.library_resolver_get(); - for (const auto& draw : animation_draws_get(sampleModel, sampleAnimation, sampleOptions)) + for (auto& draw : animation_draws_get(sampleModel, sampleAnimation, sampleOptions)) { if (isParent && (draw.type != DrawType::LAYER || draw.id == skipLayerId)) continue; auto isOnion = draw.sample != -1; @@ -774,7 +774,7 @@ using namespace glm; pivotPathsKey = key; pivotPaths.clear(); for (int time = 0; time < animation->frameNum; ++time) - for (const auto& draw : animation_draws_get(model, *animation, + for (auto& draw : animation_draws_get(model, *animation, {.time = (float)time, .isRootTransform = isRootTransform, .library_get = document.library_resolver_get()})) @@ -791,7 +791,7 @@ using namespace glm; } auto pointIcon = resources.icon_id_get(ICON_POINT); - for (const auto& path : pivotPaths) + for (auto& path : pivotPaths) { if (isOnlySelected && !is_draw_selected(path.item)) continue; for (std::size_t i = 0; i < path.points.size(); ++i) @@ -828,9 +828,9 @@ using namespace glm; image_premultiplied_draw(texture, to_imvec2(size)); // The events triggers (the animation's and its children's) fire on this frame. - std::string names{}; + std::string names; if (animation && !isOnlyShowLayers && !manager.isRecording) - for (const auto& [source, trigger, layerId] : + for (auto& [source, trigger, layerId] : animation_triggers_get(model, *animation, (int)frameTime, document.library_resolver_get())) for (auto eventId : trigger.eventIds) if (auto event = item_get(source->content.events, eventId)) diff --git a/src/ui/animation_preview.h b/src/ui/animation_preview.h index ed7fe23..6fd7b1b 100644 --- a/src/ui/animation_preview.h +++ b/src/ui/animation_preview.h @@ -15,24 +15,24 @@ { MIX_Mixer* mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr); AudioStream audioStream = AudioStream(mixer); - bool wasPlaybackPlaying{}; - int soundFrame{-1}; - bool isMoveDragging{}; + bool wasPlaybackPlaying = false; + int soundFrame = -1; + bool isMoveDragging = false; glm::vec2 moveOffset{}; glm::vec2 nullRectScaleAnchor{}; - Recorder recorder{}; + Recorder recorder = {}; glm::vec2 recordSize{}; glm::vec2 recordPan{}; - float recordZoom{}; + float recordZoom = 0; // Where each item's pivot is at every frame of the animation, kept until the document or view changes. struct PivotPath { - Draw item{}; + Draw item = {}; std::vector points{}; }; - std::vector pivotPaths{}; - std::tuple pivotPathsKey{}; + std::vector pivotPaths; + std::tuple pivotPathsKey; void recording_start(Manager&, Settings&, Document&, const Animation*); void recording_stop(Manager&, Document&); diff --git a/src/ui/animations.cpp b/src/ui/animations.cpp index 4f0904a..0386b15 100644 --- a/src/ui/animations.cpp +++ b/src/ui/animations.cpp @@ -30,25 +30,25 @@ struct AnimationDragDropItem { - bool isGroup{}; - int id{-1}; + bool isGroup = false; + int id = -1; bool operator==(const AnimationDragDropItem&) const = default; }; struct AnimationMergeOptions { - std::set selection{}; - int reference{-1}; - Merge type{}; - bool isDeleteAnimationsAfter{}; + std::set selection; + int reference = -1; + Merge type = {}; + bool isDeleteAnimationsAfter = false; }; // Calls back for each top-level entry: (animation index, animation) for loose animations, (index, group) for groups. template static void animation_entries_each(const Model& model, Callback&& callback) { - int index{}; - for (const auto& entry : model.animations.entries) + int index = 0; + for (auto& entry : model.animations.entries) if (auto animation = std::get_if>(&entry)) callback(index++, animation->get(), (const AnimationGroup*)nullptr); else @@ -62,7 +62,7 @@ // The flat index of a group's first animation. static int animation_group_first_index_get(const Model& model, int groupId) { - int first{-1}; + int first = -1; animation_entries_each(model, [&](int index, auto*, const AnimationGroup* group) { @@ -73,10 +73,10 @@ static std::set animation_groups_selected_get(const Document& document) { - std::set groupIds{}; + std::set groupIds; auto uids = document.selection.uids.find(SelectionKind::ANIMATION_GROUPS); if (uids == document.selection.uids.end()) return groupIds; - for (const auto& entry : document.model.animations.entries) + for (auto& entry : document.model.animations.entries) if (auto group = std::get_if(&entry); group && uids->second.contains(group->uid)) groupIds.insert(group->id); return groupIds; @@ -87,7 +87,7 @@ document.animations_selected_set(indices); auto& groupUids = document.selection.uids[SelectionKind::ANIMATION_GROUPS]; groupUids.clear(); - for (const auto& entry : document.model.animations.entries) + for (auto& entry : document.model.animations.entries) if (auto group = std::get_if(&entry); group && groupIds.contains(group->id)) groupUids.insert(group->uid); } @@ -103,7 +103,7 @@ static std::vector animation_groupable_indices_get(const Document& document) { - std::vector result{}; + std::vector result; for (auto index : document.animations_selected_get()) { if (!document.model.animation_get(index) || document.model.animation_group_id_get(index) != -1) return {}; @@ -114,7 +114,7 @@ static std::set animation_merge_indices_get(const Document& document, const std::set& keys, int reference) { - std::set result{}; + std::set result; for (auto key : keys) if (!is_group_key(key)) result.insert(key); @@ -146,7 +146,7 @@ static std::set animation_indices_get(Document& document, const Uids& uids) { - std::set indices{}; + std::set indices; for (auto reference : document.references_get(uids)) indices.insert(reference.animationIndex); return indices; @@ -154,11 +154,11 @@ static std::string animation_clipboard_text_get(const Document& document) { - std::string clipboardText{}; + std::string clipboardText; auto& model = document.model; auto groupIds = animation_groups_selected_get(document); auto selection = document.animations_selected_get(); - for (const auto& entry : model.animations.entries) + for (auto& entry : model.animations.entries) if (auto group = std::get_if(&entry); group && groupIds.contains(group->id)) clipboardText += animation_group_to_string(*group); for (int i = 0; i < model.animations_count_get(); ++i) @@ -173,8 +173,8 @@ static void animations_insert(PanelState& state, Document& document, const std::string& text, int start, int targetGroupId, StringType edit) { - std::set groupIds{}; - std::string errorString{}; + std::set groupIds; + std::string errorString; document.edit_apply(edit, [&](Model& model) { @@ -216,7 +216,7 @@ else if (sources.empty()) return -1; - int merged{-1}; + int merged = -1; document.edit_apply(EDIT_MERGE_ANIMATIONS, [&](Model& model) { @@ -248,8 +248,8 @@ command_push(panel, [items, target](Document& document) { - std::set indices{}; - std::set groupIds{}; + std::set indices; + std::set groupIds; for (auto item : items) (item.isGroup ? groupIds : indices).insert(item.id); document.edit_apply(EDIT_MOVE_ANIMATIONS, @@ -267,7 +267,7 @@ { if (!ImGui::BeginDragDropSource(DRAG_DROP_SOURCE_FLAGS)) return; - static std::vector items{}; + static std::vector items; items.clear(); auto groupIds = animation_groups_selected_get(document); auto selection = document.animations_selected_get(); @@ -442,10 +442,10 @@ struct AnimationMergeCandidate { - int key{}; - std::string label{}; + int key = 0; + std::string label; }; - std::vector candidates{}; + std::vector candidates; auto candidate_animation_push = [&](const Animation& animation, int animationIndex, bool isGrouped) { if (animationIndex != mergeReference) @@ -474,7 +474,7 @@ if (ImGui::BeginChild(localize.get(LABEL_ANIMATIONS_CHILD), animationsSize, ImGuiChildFlags_Borders)) { animations.mergeKeys.clear(); - for (const auto& candidate : candidates) + for (auto& candidate : candidates) animations.mergeKeys.push_back(candidate.key); mergeSelection.set_index_map(&animations.mergeKeys); mergeSelection.start(candidates.size()); @@ -555,7 +555,7 @@ return indices.empty() ? count : std::min(*indices.rbegin() + 1, count); }; - Actions actions{}; + Actions actions = {}; actions.add( ACTION_RENAME, [&]() { return selection.size() == 1 || (selection.empty() && groupSelection.size() == 1); }, [&]() { state.newId = selection.size() == 1 ? *selection.begin() : group_key_get(*groupSelection.begin()); }); @@ -749,7 +749,7 @@ panel, actions, {{ACTION_ADD, ACTION_DUPLICATE, ACTION_MERGE, ACTION_REMOVE, ACTION_DEFAULT}}, [&]() { - std::vector visibleKeys{}; + std::vector visibleKeys; state.keys.clear(); for (int i = 0; i < count; ++i) state.keys.push_back(i); diff --git a/src/ui/autosave_restore.h b/src/ui/autosave_restore.h index b6d0d1f..c024af7 100644 --- a/src/ui/autosave_restore.h +++ b/src/ui/autosave_restore.h @@ -5,9 +5,9 @@ class AutosaveRestore { - PopupHelper popup{PopupHelper(LABEL_WELCOME_RESTORE_POPUP, POPUP_SMALL_NO_HEIGHT)}; - bool isInitialized{}; - bool isRestoreAvailable{}; + PopupHelper popup = PopupHelper(LABEL_WELCOME_RESTORE_POPUP, POPUP_SMALL_NO_HEIGHT); + bool isInitialized = false; + bool isRestoreAvailable = false; public: void update(Manager&); diff --git a/src/ui/canvas_view.cpp b/src/ui/canvas_view.cpp index 0789552..82b09f7 100644 --- a/src/ui/canvas_view.cpp +++ b/src/ui/canvas_view.cpp @@ -82,7 +82,7 @@ using namespace glm; void tooltip_lines_draw(std::initializer_list lines) { if (!ImGui::BeginTooltip()) return; - for (const auto& line : lines) + for (auto& line : lines) ImGui::TextUnformatted(line.c_str()); ImGui::EndTooltip(); } @@ -184,7 +184,7 @@ using namespace glm; auto zoom_center_step = [&](int levelDelta) { zoom_step(zoom, pan, position_translate(zoom, pan, size * 0.5f), levelDelta); }; - Actions actions{}; + Actions actions = {}; actions_undo_redo_add(actions, manager, document); actions.separator(); actions.add(ACTION_CENTER_VIEW, []() { return true; }, center); diff --git a/src/ui/canvas_view.h b/src/ui/canvas_view.h index e73c583..c50ee2b 100644 --- a/src/ui/canvas_view.h +++ b/src/ui/canvas_view.h @@ -18,21 +18,21 @@ { glm::vec2 arrow{}; glm::vec2 mouseDelta{}; - float wheel{}; - float step{}; - bool isArrowBegin{}; - bool isArrowDown{}; - bool isArrowEnd{}; - bool isLeftClicked{}; - bool isLeftDown{}; - bool isLeftReleased{}; - bool isRightClicked{}; - bool isRightDown{}; - bool isRightReleased{}; - bool isMiddleDown{}; - bool isZoomIn{}; - bool isZoomOut{}; - bool isMod{}; + float wheel = 0; + float step = 0; + bool isArrowBegin = false; + bool isArrowDown = false; + bool isArrowEnd = false; + bool isLeftClicked = false; + bool isLeftDown = false; + bool isLeftReleased = false; + bool isRightClicked = false; + bool isRightDown = false; + bool isRightReleased = false; + bool isMiddleDown = false; + bool isZoomIn = false; + bool isZoomOut = false; + bool isMod = false; }; CanvasInput canvas_input_get(Manager&, bool); @@ -50,10 +50,10 @@ glm::vec2 mousePos{}; glm::vec2 checkerPan{}; glm::vec2 checkerSyncPan{}; - float checkerSyncZoom{}; - bool isCheckerPanInitialized{}; - bool hasPendingZoomPanAdjust{}; - bool isFocused{}; + float checkerSyncZoom = 0; + bool isCheckerPanInitialized = false; + bool hasPendingZoomPanAdjust = false; + bool isFocused = false; void checker_pan_reset(float, glm::vec2); void checker_pan_sync(float, glm::vec2); diff --git a/src/ui/change_all_frame_properties.cpp b/src/ui/change_all_frame_properties.cpp index 99a0321..b036aff 100644 --- a/src/ui/change_all_frame_properties.cpp +++ b/src/ui/change_all_frame_properties.cpp @@ -86,7 +86,7 @@ using namespace glm; ImGui::PopItemWidth(); if (!isColor) return; - ImVec4 buttonColor{0.0f, 0.0f, 0.0f, 1.0f}; + ImVec4 buttonColor = {0.0f, 0.0f, 0.0f, 1.0f}; for (int i = 0; i < count; ++i) if (*row.isEnabled[i]) (&buttonColor.x)[i] = glm::clamp(row.values[i], 0.0f, 1.0f); ImGui::SameLine(); @@ -141,8 +141,8 @@ using namespace glm; auto layer = is_layer(reference) ? item_get(document.model.content.layers, reference.itemID) : nullptr; return layer && layer->is_animation() ? layer : nullptr; }; - std::set childAnimations{}; - bool isChildPropertyAvailable{}; + std::set childAnimations; + bool isChildPropertyAvailable = false; auto child_layer_add = [&](const Layer* layer) { if (!layer || !layer->is_animation()) return; @@ -151,10 +151,10 @@ using namespace glm; childAnimations.insert(name); }; if (isFramesDestination || isItemsDestination) - for (const auto& reference : isFramesDestination ? selectedFrameReferences : selectedItemReferences) + for (auto& reference : isFramesDestination ? selectedFrameReferences : selectedItemReferences) child_layer_add(animation_layer_get(reference)); else if (settings.changeIsLayers) - for (const auto& layer : document.model.content.layers) + for (auto& layer : document.model.content.layers) child_layer_add(&layer); ComponentRow componentRows[] = { @@ -212,8 +212,8 @@ using namespace glm; ImGui::PopID(); }; - std::vector interpolationIds{}; - std::vector interpolationLabels{}; + std::vector interpolationIds; + std::vector interpolationLabels; for (int i = 0; i < (int)std::size(INTERPOLATION_LABELS); ++i) { interpolationIds.push_back(i); @@ -270,8 +270,8 @@ using namespace glm; ImGui::EndDisabled(); ImGui::PopID(); - std::vector modeIds{}; - std::vector modeLabels{}; + std::vector modeIds; + std::vector modeLabels; for (int i = 0; i < (int)std::size(CHILD_MODE_LABELS); ++i) { modeIds.push_back(i); @@ -324,7 +324,7 @@ using namespace glm; [=, queuedAnimations = std::set(animations.begin(), animations.end()), isRoot = settings.changeIsRoot, isLayers = settings.changeIsLayers, isNulls = settings.changeIsNulls](Manager&, Document& document) { - ChangeTargets targets{.isRoot = isRoot, .isLayers = isLayers, .isNulls = isNulls}; + ChangeTargets targets = {.isRoot = isRoot, .isLayers = isLayers, .isNulls = isNulls}; if (isFramesDestination) targets.references = {selectedFrameReferences.begin(), selectedFrameReferences.end()}; else if (isItemsDestination) diff --git a/src/ui/change_all_frame_properties.h b/src/ui/change_all_frame_properties.h index 0fcd3ac..ec2faf0 100644 --- a/src/ui/change_all_frame_properties.h +++ b/src/ui/change_all_frame_properties.h @@ -11,7 +11,7 @@ class ChangeAllFrameProperties { public: - bool isChanged{}; + bool isChanged = false; void update(Manager&, Document&, Settings&, bool = false); }; diff --git a/src/ui/configure.cpp b/src/ui/configure.cpp index 4a1acfe..5b8cc60 100644 --- a/src/ui/configure.cpp +++ b/src/ui/configure.cpp @@ -148,14 +148,14 @@ if (isSelected) { - ImGuiKeyChord chord{ImGuiKey_None}; + ImGuiKeyChord chord = ImGuiKey_None; if (ImGui::IsKeyDown(ImGuiMod_Ctrl)) chord |= ImGuiMod_Ctrl; if (ImGui::IsKeyDown(ImGuiMod_Shift)) chord |= ImGuiMod_Shift; if (ImGui::IsKeyDown(ImGuiMod_Alt)) chord |= ImGuiMod_Alt; if (ImGui::IsKeyDown(ImGuiMod_Super)) chord |= ImGuiMod_Super; - for (const auto& entry : KEY_MAP) + for (auto& entry : KEY_MAP) { auto key = entry.second; if (ImGui::IsKeyPressed(key)) diff --git a/src/ui/configure.h b/src/ui/configure.h index 3479880..d30a06e 100644 --- a/src/ui/configure.h +++ b/src/ui/configure.h @@ -4,11 +4,11 @@ class Configure { - Settings temporary{}; - int selectedShortcut{-1}; + Settings temporary = {}; + int selectedShortcut = -1; public: - bool isSet{}; + bool isSet = false; void reset(Settings&); void update(Manager&, Settings&); diff --git a/src/ui/dockspace.h b/src/ui/dockspace.h index 14283c1..809494a 100644 --- a/src/ui/dockspace.h +++ b/src/ui/dockspace.h @@ -12,21 +12,21 @@ class Dockspace { AnimationPreview animationPreview; - bool isCanvasFocused{}; - float reloadTime{}; - AnimationsPanel animations{}; - RegionsPanel regions{}; - PanelState events{}; - FramePropertiesPanel frameProperties{}; - PanelState layers{}; - PanelState nulls{}; - ShadersPanel shaders{}; + bool isCanvasFocused = false; + float reloadTime = 0; + AnimationsPanel animations = {}; + RegionsPanel regions = {}; + PanelState events = {}; + FramePropertiesPanel frameProperties = {}; + PanelState layers = {}; + PanelState nulls = {}; + ShadersPanel shaders = {}; SpritesheetEditor spritesheetEditor; - SpritesheetsPanel spritesheets{}; - PanelState sounds{}; - PanelState libraries{}; + SpritesheetsPanel spritesheets = {}; + PanelState sounds = {}; + PanelState libraries = {}; Timeline timeline; - PopupHelper toolsColorEditPopup{PopupHelper(LABEL_TOOLS_COLOR_EDIT_POPUP, POPUP_TO_CONTENT, POPUP_BY_ITEM)}; + PopupHelper toolsColorEditPopup = PopupHelper(LABEL_TOOLS_COLOR_EDIT_POPUP, POPUP_TO_CONTENT, POPUP_BY_ITEM); AutosaveRestore autosaveRestore; public: diff --git a/src/ui/documents.cpp b/src/ui/documents.cpp index 61f2a0d..7db15c6 100644 --- a/src/ui/documents.cpp +++ b/src/ui/documents.cpp @@ -17,8 +17,8 @@ struct DocumentTab { - ImGuiID imguiId{}; - uint64_t documentId{}; + ImGuiID imguiId = 0; + uint64_t documentId = 0; }; #define ANM2_DRAG_DROP_MERGE_PRESETS \ @@ -62,7 +62,7 @@ return; } - std::vector order{}; + std::vector order; order.reserve(manager.documents.size()); for (auto documentId : pendingDocumentTabIds) { @@ -91,7 +91,7 @@ } std::vector remap(manager.documents.size(), -1); - std::vector documents{}; + std::vector documents; documents.reserve(manager.documents.size()); for (auto [i, index] : std::views::enumerate(order)) { @@ -168,9 +168,9 @@ int closeShortcutIndex = isCloseShortcut && manager.selected >= 0 && manager.selected < documentsCount ? manager.selected : -1; - std::vector closeIndices{}; + std::vector closeIndices; closeIndices.reserve(documentsCount); - std::vector documentTabs{}; + std::vector documentTabs; documentTabs.reserve(documentsCount); for (int i = 0; i < documentsCount; ++i) @@ -232,7 +232,7 @@ if (auto tabBar = ImGui::GetCurrentTabBar(); tabBar && documentTabs.size() == manager.documents.size()) { - std::vector documentTabIds{}; + std::vector documentTabIds; documentTabIds.reserve(manager.documents.size()); for (auto& tab : tabBar->Tabs) { diff --git a/src/ui/documents.h b/src/ui/documents.h index 06397c3..c9ef81c 100644 --- a/src/ui/documents.h +++ b/src/ui/documents.h @@ -11,12 +11,12 @@ class Documents { - int closeDocumentIndex{-1}; - std::vector pendingDocumentTabIds{}; - PopupHelper closePopup{PopupHelper(LABEL_DOCUMENT_CLOSE, POPUP_TO_CONTENT)}; + int closeDocumentIndex = -1; + std::vector pendingDocumentTabIds; + PopupHelper closePopup = PopupHelper(LABEL_DOCUMENT_CLOSE, POPUP_TO_CONTENT); public: - float height{}; + float height = 0; void pending_document_order_apply(Manager&); void update(Taskbar&, Manager&, Settings&, Resources&, bool&); diff --git a/src/ui/draw.cpp b/src/ui/draw.cpp index cc6ce14..92291d1 100644 --- a/src/ui/draw.cpp +++ b/src/ui/draw.cpp @@ -9,8 +9,8 @@ struct CheckerStart { - float position{}; - long long index{}; + float position = 0; + long long index = {}; }; static CheckerStart checker_start(float minCoord, float offset, float step) diff --git a/src/ui/frame_properties.cpp b/src/ui/frame_properties.cpp index f6132ff..8439a11 100644 --- a/src/ui/frame_properties.cpp +++ b/src/ui/frame_properties.cpp @@ -82,7 +82,7 @@ using namespace glm; auto events = document.choices_get(SelectionKind::EVENTS); auto sounds = document.choices_get(SelectionKind::SOUNDS); auto shaders = document.choices_get(SelectionKind::SHADERS); - std::vector interpolationLabels{}; + std::vector interpolationLabels; for (auto label : INTERPOLATION_LABELS) interpolationLabels.push_back(localize.get(label)); @@ -201,7 +201,7 @@ using namespace glm; displayFrame.size == frame->size && displayFrame.pivot == frame->pivot; for (auto& field : VEC2_FIELDS) { - const auto& source = field.isRegionField ? displayFrame : useFrame; + auto& source = field.isRegionField ? displayFrame : useFrame; auto value = frame ? source.*field.member : vec2(); // An animation layer's pivot is where its child's origin goes; it has no crop or size. ImGui::BeginDisabled(field.isRegionField && (type == ROOT || type == NULL_ || isRegionSet || @@ -352,7 +352,7 @@ using namespace glm; combo_string_mapped(localize.get(LABEL_ANIMATION), &useFrame.childAnimation, values, labels); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHILD_ANIMATION)); - std::vector modeLabels{}; + std::vector modeLabels; for (auto label : CHILD_MODE_LABELS) modeLabels.push_back(localize.get(label)); auto mode = (int)useFrame.childMode; diff --git a/src/ui/generate_animation_from_grid.cpp b/src/ui/generate_animation_from_grid.cpp index e9fd792..fd1268b 100644 --- a/src/ui/generate_animation_from_grid.cpp +++ b/src/ui/generate_animation_from_grid.cpp @@ -89,7 +89,7 @@ using namespace glm; auto sourceTexture = layer ? document.texture_get(layer->spritesheetId) : nullptr; if (sourceTexture && sourceTexture->is_valid()) { - Track previewTrack{}; + Track previewTrack = {}; frames_generate_from_grid(previewTrack, startPosition, size, pivot, columns, count, delay); auto length = std::max(track_length_get(previewTrack), FRAME_DURATION_MIN); diff --git a/src/ui/generate_animation_from_grid.h b/src/ui/generate_animation_from_grid.h index c241443..e3fc728 100644 --- a/src/ui/generate_animation_from_grid.h +++ b/src/ui/generate_animation_from_grid.h @@ -8,10 +8,10 @@ class GenerateAnimationFromGrid : public Canvas { - float time{}; + float time = 0; public: - bool isEnd{}; + bool isEnd = false; GenerateAnimationFromGrid(); void update(Manager&, Document&, Resources&, Settings&); diff --git a/src/ui/input.cpp b/src/ui/input.cpp index 367b80d..3cdbdb6 100644 --- a/src/ui/input.cpp +++ b/src/ui/input.cpp @@ -54,8 +54,8 @@ using namespace glm; bool combo_id_mapped(const std::string& label, int* id, const std::vector& ids, const std::vector& labelStrings) { - std::vector labels{}; - for (const auto& labelString : labelStrings) + std::vector labels; + for (auto& labelString : labelStrings) labels.push_back(labelString.c_str()); if (!id) return false; @@ -81,8 +81,8 @@ using namespace glm; EditState drag_float_persistent(const char* label, float* value, float speed, float min, float max, const char* format, ImGuiSliderFlags flags) { - static bool isEditing{}; - static float start{NAN}; + static bool isEditing = false; + static float start = NAN; auto persistent = value ? *value : 0; ImGui::DragFloat(label, &persistent, speed, min, max, format, flags); @@ -112,7 +112,7 @@ using namespace glm; EditState drag_float2_persistent(const char* label, vec2* value, float speed, float min, float max, const char* format, ImGuiSliderFlags flags) { - static bool isEditing{}; + static bool isEditing = false; static vec2 start{NAN}; auto persistent = value ? *value : vec2(); @@ -142,7 +142,7 @@ using namespace glm; EditState color_edit4_persistent(const char* label, vec4* value, ImGuiColorEditFlags flags) { - static bool isEditing{}; + static bool isEditing = false; static vec4 start{NAN}; auto persistent = value ? *value : vec4(); diff --git a/src/ui/item_properties.cpp b/src/ui/item_properties.cpp index c5e2105..849b481 100644 --- a/src/ui/item_properties.cpp +++ b/src/ui/item_properties.cpp @@ -19,7 +19,7 @@ bool ItemProperties::update(Manager& manager, Settings& settings, Document& document, Reference& reference) { - bool isAdded{}; + bool isAdded = false; auto& model = document.model; auto animation = model.animation_get(reference.animationIndex); auto unused_items_get = [&](int type) @@ -177,7 +177,7 @@ manager.command_push({manager.selected, [=](Manager&, Document& document) { - int addId{-1}; + int addId = -1; document.edit_apply(EDIT_ADD_ITEM, [&](Model& model) { diff --git a/src/ui/item_properties.h b/src/ui/item_properties.h index 2c4c6fb..a20eda0 100644 --- a/src/ui/item_properties.h +++ b/src/ui/item_properties.h @@ -9,8 +9,8 @@ class ItemProperties { - PopupHelper popup{PopupHelper(LABEL_TIMELINE_PROPERTIES_POPUP, POPUP_SMALL_NO_HEIGHT)}; - Manager::ItemEdit edit{}; + PopupHelper popup = PopupHelper(LABEL_TIMELINE_PROPERTIES_POPUP, POPUP_SMALL_NO_HEIGHT); + Manager::ItemEdit edit = {}; void reset(); diff --git a/src/ui/items.cpp b/src/ui/items.cpp index bc01d3e..b3a178b 100644 --- a/src/ui/items.cpp +++ b/src/ui/items.cpp @@ -114,7 +114,7 @@ auto result = popup_buttons_draw(manager, localize.get(edit.id == -1 ? BASIC_ADD : BASIC_CONFIRM)); if (result == PopupButton::CONFIRM) { - Item item{}; + Item item = {}; if constexpr (std::is_same_v) item = item_edit_layer_get(edit); else @@ -174,7 +174,7 @@ auto& layers = document.model.content.layers; if (ImGui::Begin(localize.get(LABEL_LAYERS_WINDOW), &settings.windowIsLayers)) { - Actions actions{}; + Actions actions = {}; track_items_actions_add(actions, panel, SelectionKind::LAYERS, ElementType::LAYER_ELEMENT, TOOLTIP_ADD_LAYER, EDIT_PASTE_LAYERS, TOAST_DESERIALIZE_LAYERS_FAILED, layers_get); @@ -209,7 +209,7 @@ auto& nulls = document.model.content.nulls; if (ImGui::Begin(localize.get(LABEL_NULLS_WINDOW), &settings.windowIsNulls)) { - Actions actions{}; + Actions actions = {}; track_items_actions_add(actions, panel, SelectionKind::NULLS, ElementType::NULL_ELEMENT, TOOLTIP_ADD_NULL, EDIT_PASTE_NULLS, TOAST_DESERIALIZE_NULLS_FAILED, nulls_get); @@ -243,7 +243,7 @@ if (ImGui::Begin(localize.get(LABEL_EVENTS_WINDOW), &settings.windowIsEvents)) { auto selection = document.selected_ids_get(SelectionKind::EVENTS); - Actions actions{}; + Actions actions = {}; actions.add( ACTION_RENAME, [selection]() { return selection.size() == 1; }, [&state, selection]() { state.newId = *selection.begin(); }); @@ -255,7 +255,7 @@ command_push(panel, [&state](Document& document) { - int id{}; + int id = 0; document.edit_apply(EDIT_ADD_EVENT, [&](Model& model) { diff --git a/src/ui/layout.h b/src/ui/layout.h index a7936eb..47b8822 100644 --- a/src/ui/layout.h +++ b/src/ui/layout.h @@ -13,13 +13,13 @@ template constexpr T& dummy_value() { - static T value{}; + static T value = {}; return value; } template constexpr T& dummy_value_negative() { - static T value{-1}; + static T value = -1; return value; } diff --git a/src/ui/libraries.cpp b/src/ui/libraries.cpp index 5ac853c..0450e85 100644 --- a/src/ui/libraries.cpp +++ b/src/ui/libraries.cpp @@ -40,7 +40,7 @@ }}); }; - Actions actions{}; + Actions actions = {}; actions.add(ACTION_OPEN, isOne, [&]() { open(*selection.begin()); }, TOOLTIP_LIBRARY_OPEN); actions.add(ACTION_OPEN_DIRECTORY, isOne, [&]() { directory_open(dialog, document, item_get(libraries, *selection.begin())->path); }); diff --git a/src/ui/multiselect.h b/src/ui/multiselect.h index 17daddf..bc5fa9e 100644 --- a/src/ui/multiselect.h +++ b/src/ui/multiselect.h @@ -8,9 +8,9 @@ class MultiSelectStorage : public std::set { public: - ImGuiSelectionExternalStorage internal{}; - ImGuiMultiSelectIO* io{}; - std::vector* indexMap{}; + ImGuiSelectionExternalStorage internal = {}; + ImGuiMultiSelectIO* io = nullptr; + std::vector* indexMap = nullptr; using std::set::set; using std::set::operator=; diff --git a/src/ui/panel.cpp b/src/ui/panel.cpp index e9c92c8..e946965 100644 --- a/src/ui/panel.cpp +++ b/src/ui/panel.cpp @@ -125,7 +125,7 @@ using namespace glm; if (isInvalid) ImGui::PushStyleColor(ImGuiCol_Text, CARD_TINT_INVALID); if (arrowKey == key) ImGui::SetKeyboardFocusHere(); - bool isActivated{}; + bool isActivated = false; if (rows.rename) { if (state.newId == key) @@ -247,7 +247,7 @@ using namespace glm; auto arrowKey = list_select_begin(panel, selection, focus, rows, keys); for (int i = 0; i < (int)keys.size(); ++i) { - bool isBreak{}; + bool isBreak = false; if (isCards) card_draw(panel, selection, focus, rows, keys[i], i, arrowKey, isBreak); else @@ -274,7 +274,7 @@ using namespace glm; int spritesheetId) { auto& content = model.content; - std::vector lines{}; + std::vector lines; auto names_add = [&](const auto& items, auto&& name_get) { for (auto id : ids) @@ -288,8 +288,8 @@ using namespace glm; }; auto layers_add = [&](StringType format, auto&& is_removed) { - std::set layerIds{}; - for (const auto& layer : content.layers) + std::set layerIds; + for (auto& layer : content.layers) if (is_removed(layer)) { layerIds.insert(layer.id); @@ -319,9 +319,9 @@ using namespace glm; names_add(content.sounds, path_get); count_add(FORMAT_REMOVE_TRIGGER_USES, uses); // Triggers whose every event and sound goes. - int emptied{}; + int emptied = 0; for (auto [index, animation] : model.animations_get()) - for (const auto& trigger : animation->triggers.frames) + for (auto& trigger : animation->triggers.frames) { auto& own = isEvent ? trigger.eventIds : trigger.soundIds; auto& other = isEvent ? trigger.soundIds : trigger.eventIds; @@ -432,17 +432,17 @@ using namespace glm; if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlappedByWindow) && ImGui::IsMouseReleased(ImGuiMouseButton_Right)) ImGui::OpenPopup(CONTEXT_MENU_LABEL); - Actions menu{}; + Actions menu = {}; actions_undo_redo_add(menu, manager, document); menu.separator(); menu.items.insert(menu.items.end(), actions.items.begin(), actions.items.end()); actions_popup_draw(CONTEXT_MENU_LABEL, menu, settings); auto& buttons = footerActions ? *footerActions : actions; - for (const auto& row : footer) + for (auto& row : footer) { auto widgetSize = widget_size_with_row_get((int)row.size()); - bool isSameLine{}; + bool isSameLine = false; for (auto type : row) if (auto action = std::ranges::find(buttons.items, type, &Action::type); action != buttons.items.end()) action_button_draw(*action, manager, settings, widgetSize, isSameLine); @@ -488,7 +488,7 @@ using namespace glm; void directory_open(Dialog& dialog, Document& document, const std::filesystem::path& path) { if (path.empty()) return; - std::error_code ec{}; + std::error_code ec; auto absolutePath = std::filesystem::weakly_canonical(document.directory_get() / path, ec); if (ec) absolutePath = document.directory_get() / path; auto target = std::filesystem::is_regular_file(absolutePath, ec) || std::filesystem::is_directory(absolutePath, ec) diff --git a/src/ui/panel.h b/src/ui/panel.h index 244bf69..5253b60 100644 --- a/src/ui/panel.h +++ b/src/ui/panel.h @@ -28,35 +28,35 @@ struct CardImage { - const Image* texture{}; + const Image* texture = nullptr; glm::vec2 size{}; glm::vec2 uvMin{}; glm::vec2 uvMax{1.0f}; - bool isValid{}; + bool isValid = false; }; // What a list panel remembers between frames. struct PanelState { - int newId{-1}; - int scrollId{-1}; - int renameId{-1}; - std::string renameText{}; - RenameState renameState{RENAME_SELECTABLE}; - std::vector keys{}; - std::vector dragIds{}; - MultiSelectStorage selection{}; - ImVec2 tooltipPadding{}; - ImVec2 tooltipSpacing{}; - PopupHelper removePopup{PopupHelper(LABEL_REMOVE_IN_USE, POPUP_SMALL_NO_HEIGHT)}; + int newId = -1; + int scrollId = -1; + int renameId = -1; + std::string renameText; + RenameState renameState = RENAME_SELECTABLE; + std::vector keys; + std::vector dragIds; + MultiSelectStorage selection = {}; + ImVec2 tooltipPadding; + ImVec2 tooltipSpacing; + PopupHelper removePopup = PopupHelper(LABEL_REMOVE_IN_USE, POPUP_SMALL_NO_HEIGHT); // A removal waiting on its confirmation, since what it removes is in use. struct Removal { - ElementType type{}; - SelectionKind kind{}; - std::set ids{}; - int spritesheetId{-1}; - std::vector lines{}; + ElementType type = {}; + SelectionKind kind = {}; + std::set ids; + int spritesheetId = -1; + std::vector lines; } removal{}; }; @@ -86,8 +86,8 @@ std::function select{}; std::function activate{}; std::function drag_drop_update{}; - int cardLines{}; - bool isFocusItalic{}; + int cardLines = 0; + bool isFocusItalic = false; }; enum class PopupButton @@ -116,38 +116,38 @@ struct SpritesheetsPanel { - PanelState state{}; - PopupHelper mergePopup{PopupHelper(LABEL_SPRITESHEETS_MERGE_POPUP, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper packPopup{PopupHelper(LABEL_SPRITESHEETS_PACK_POPUP, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper overwritePopup{PopupHelper(LABEL_TASKBAR_OVERWRITE_FILE, POPUP_SMALL_NO_HEIGHT)}; - std::set mergeIds{}; - std::set saveIds{}; - int packId{-1}; + PanelState state = {}; + PopupHelper mergePopup = PopupHelper(LABEL_SPRITESHEETS_MERGE_POPUP, POPUP_SMALL_NO_HEIGHT); + PopupHelper packPopup = PopupHelper(LABEL_SPRITESHEETS_PACK_POPUP, POPUP_SMALL_NO_HEIGHT); + PopupHelper overwritePopup = PopupHelper(LABEL_TASKBAR_OVERWRITE_FILE, POPUP_SMALL_NO_HEIGHT); + std::set mergeIds; + std::set saveIds; + int packId = -1; }; struct RegionsPanel { - PanelState state{}; - PopupHelper propertiesPopup{PopupHelper(LABEL_REGION_PROPERTIES, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper exportPopup{PopupHelper(LABEL_EXPORT_REGION, POPUP_SMALL_NO_HEIGHT)}; - Region editRegion{}; - int editId{-1}; - int exportId{-1}; + PanelState state = {}; + PopupHelper propertiesPopup = PopupHelper(LABEL_REGION_PROPERTIES, POPUP_SMALL_NO_HEIGHT); + PopupHelper exportPopup = PopupHelper(LABEL_EXPORT_REGION, POPUP_SMALL_NO_HEIGHT); + Region editRegion = {}; + int editId = -1; + int exportId = -1; }; struct AnimationsPanel { - PanelState state{}; - PopupHelper mergePopup{PopupHelper(LABEL_ANIMATIONS_MERGE_POPUP)}; - MultiSelectStorage mergeSelection{}; - std::vector mergeKeys{}; - int mergeReference{-1}; + PanelState state = {}; + PopupHelper mergePopup = PopupHelper(LABEL_ANIMATIONS_MERGE_POPUP); + MultiSelectStorage mergeSelection = {}; + std::vector mergeKeys; + int mergeReference = -1; }; struct FramePropertiesPanel { - ChangeAllFrameProperties changeAllFrameProperties{}; - bool isBatchMode{}; + ChangeAllFrameProperties changeAllFrameProperties = {}; + bool isBatchMode = false; }; class Taskbar; @@ -174,15 +174,15 @@ template std::vector item_ids_get(const Items& items) { - std::vector ids{}; - for (const auto& item : items) + std::vector ids; + for (auto& item : items) ids.push_back(item.id); return ids; } template void items_copy(Clipboard& clipboard, const Items& items, const std::set& ids) { - std::string text{}; + std::string text; for (auto id : ids) if (auto item = item_get(items, id)) text += item_to_string(*item); if (!text.empty()) clipboard.set(text); @@ -197,7 +197,7 @@ command_push(panel, [&state, kind, edit, failToast, text, items_get](Document& document) { - std::string errorString{}; + std::string errorString; auto pasted = items_from_string(text, &errorString); if (pasted.empty()) return toast_log(Level::ERROR, failToast, errorString); document.edit_apply(edit, diff --git a/src/ui/popup.h b/src/ui/popup.h index 2b55490..923e04a 100644 --- a/src/ui/popup.h +++ b/src/ui/popup.h @@ -28,14 +28,14 @@ class PopupHelper { public: - StringType labelId{}; - PopupType type{}; - PopupPosition position{}; - int id{}; - bool isOpen{}; - bool isTriggered{}; - bool isJustOpened{}; - mutable std::string labelText{}; + StringType labelId = {}; + PopupType type = {}; + PopupPosition position = {}; + int id = 0; + bool isOpen = false; + bool isTriggered = false; + bool isJustOpened = false; + mutable std::string labelText; static int nextId; PopupHelper(StringType, PopupType = POPUP_NORMAL, PopupPosition = POPUP_CENTER); diff --git a/src/ui/regions.cpp b/src/ui/regions.cpp index a89e146..1058092 100644 --- a/src/ui/regions.cpp +++ b/src/ui/regions.cpp @@ -28,11 +28,11 @@ using namespace glm; struct RegionExportOptions { - int spritesheetId{-1}; - int regionId{-1}; - std::filesystem::path path{}; - bool isMakeSpritesheet{}; - bool isRemoveCurrent{}; + int spritesheetId = -1; + int regionId = -1; + std::filesystem::path path; + bool isMakeSpritesheet = false; + bool isRemoveCurrent = false; }; static void region_pivot_apply(Region& region) @@ -133,7 +133,7 @@ using namespace glm; if (options.isMakeSpritesheet) { auto& spritesheets = document.model.content.spritesheets; - Spritesheet exported{.id = item_next_id_get(spritesheets), .path = outputPath}; + Spritesheet exported = {.id = item_next_id_get(spritesheets), .path = outputPath}; auto exportedRegion = sourceRegion; exportedRegion.uid = uid_next(); @@ -184,7 +184,7 @@ using namespace glm; auto isAfter = is_drop_after(cardMin, cardMax); drop_line_draw(ImGui::GetForegroundDrawList(), cardMin, cardMax, isAfter); - std::vector indices{}; + std::vector indices; auto payloadIds = (const int*)payload->Data; for (int i = 0; i < payload->DataSize / (int)sizeof(int); i++) if (auto keyIndex = vector_index_find(state.keys, payloadIds[i]); keyIndex != -1) indices.push_back(keyIndex); @@ -406,7 +406,7 @@ using namespace glm; auto selection = document.selected_ids_get(SelectionKind::REGIONS); auto isOne = [selection]() { return selection.size() == 1; }; - Actions actions{}; + Actions actions = {}; actions.add(ACTION_PROPERTIES, isOne, [&]() { region_properties_open(regions, document, *selection.begin()); }); actions.add(ACTION_ADD, {}, [&]() { region_properties_open(regions, document, -1); }, TOOLTIP_ADD_REGION); content_remove_action_add(actions, panel, ElementType::REGION, SelectionKind::REGIONS, spritesheetId); @@ -453,7 +453,7 @@ using namespace glm; }; if (!spritesheet_regions_get()) return; auto nextId = item_next_id_get(*spritesheet_regions_get()); - std::string errorString{}; + std::string errorString; document.edit_apply( EDIT_PASTE_REGIONS, [&](Model& model) { return regions_paste(model, spritesheetId, text, insertIndex, &errorString); }); diff --git a/src/ui/render_animation.cpp b/src/ui/render_animation.cpp index e870b13..8a14658 100644 --- a/src/ui/render_animation.cpp +++ b/src/ui/render_animation.cpp @@ -39,8 +39,8 @@ { if (auto item = document.model.track_get(reference)) { - int duration{}; - int frameIndex{}; + int duration = 0; + int frameIndex = 0; for (auto& frame : item->frames) { if (frameIndex == frameReferences.begin()->frameIndex) manager.recordingStart = duration; @@ -99,7 +99,7 @@ auto widgetSize = widget_size_with_row_get(2); - Dialog::Type dialogType{Dialog::NONE}; + Dialog::Type dialogType = Dialog::NONE; switch (type) { case RENDER_PNGS: diff --git a/src/ui/render_animation.h b/src/ui/render_animation.h index c2345a6..7fcde96 100644 --- a/src/ui/render_animation.h +++ b/src/ui/render_animation.h @@ -8,7 +8,7 @@ { public: - bool isEnd{}; + bool isEnd = false; void range_to_frames_set(Manager&, Document&); void range_to_animation_set(Manager&, Document&); diff --git a/src/ui/selectable.cpp b/src/ui/selectable.cpp index f360be8..b290cae 100644 --- a/src/ui/selectable.cpp +++ b/src/ui/selectable.cpp @@ -8,13 +8,13 @@ std::string& selectable_input_text_id() { - static std::string editID{}; + static std::string editID; return editID; } bool input_text_rename_update(std::string& text, RenameState& state, float width) { - bool isActivated{}; + bool isActivated = false; auto finish = [&]() { @@ -43,7 +43,7 @@ { auto& editID = selectable_input_text_id(); auto isRename = editID == id; - bool isActivated{}; + bool isActivated = false; if (isRename) isActivated = input_text_rename_update(text, state); diff --git a/src/ui/shaders.cpp b/src/ui/shaders.cpp index f5f7447..4704f04 100644 --- a/src/ui/shaders.cpp +++ b/src/ui/shaders.cpp @@ -158,7 +158,7 @@ ImGui::SetNextItemWidth(ImGui::GetFrameHeight() * 5.0f); if (!ImGui::BeginCombo("##Component Binding", bindingLabel.data())) return false; - bool isChanged{}; + bool isChanged = false; constexpr UniformBinding bindings[] = {UNIFORM_BINDING_MANUAL, UNIFORM_BINDING_PLAYBACK_TIME}; for (auto binding : bindings) @@ -178,7 +178,7 @@ static bool shader_uniform_components_update(ShaderUniform& uniform) { - bool isChanged{}; + bool isChanged = false; constexpr const char* labels[] = {"X", "Y", "Z", "W"}; auto componentCount = UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount; @@ -297,7 +297,7 @@ propertiesPopup.open(); }; - Actions actions{}; + Actions actions = {}; actions.add( ACTION_ADD, {}, [&]() @@ -305,7 +305,7 @@ command_push(panel, [&state](Document& document) { - int id{}; + int id = 0; document.edit_apply(EDIT_ADD_SHADER, [&](Model& model) { diff --git a/src/ui/shaders.h b/src/ui/shaders.h index 3b19c9c..029d542 100644 --- a/src/ui/shaders.h +++ b/src/ui/shaders.h @@ -4,11 +4,11 @@ struct ShadersPanel { - PanelState state{}; - std::string status{}; - int dialogShaderId{-1}; - int popupShaderId{-1}; - PopupHelper propertiesPopup{PopupHelper(LABEL_SHADER_PROPERTIES, POPUP_NORMAL)}; + PanelState state = {}; + std::string status; + int dialogShaderId = -1; + int popupShaderId = -1; + PopupHelper propertiesPopup = PopupHelper(LABEL_SHADER_PROPERTIES, POPUP_NORMAL); }; void shaders_update(Panel&, ShadersPanel&); diff --git a/src/ui/shortcut.cpp b/src/ui/shortcut.cpp index aa32e99..63d9abf 100644 --- a/src/ui/shortcut.cpp +++ b/src/ui/shortcut.cpp @@ -102,7 +102,7 @@ static const char* shortcut_canonical_key_name(ImGuiKey key) { - for (const auto& [mappedKey, name] : CANONICAL_KEY_NAMES) + for (auto& [mappedKey, name] : CANONICAL_KEY_NAMES) if (mappedKey == key) return name; return nullptr; } diff --git a/src/ui/sounds.cpp b/src/ui/sounds.cpp index 9250b2d..4e944a9 100644 --- a/src/ui/sounds.cpp +++ b/src/ui/sounds.cpp @@ -57,7 +57,7 @@ if (auto sound = item_get(sounds, id)) directory_open(dialog, document, sound->path); }; - Actions actions{}; + Actions actions = {}; actions.add(ACTION_PLAY, isOne, [&]() { play(*selection.begin()); }, STRING_UNDEFINED, -1); actions.add(ACTION_OPEN_DIRECTORY, isOne, [&]() { open(*selection.begin()); }); actions.add(ACTION_ADD, {}, [&]() { dialog.file_open(Dialog::SOUND_OPEN, true); }, TOOLTIP_SOUND_ADD); diff --git a/src/ui/spritesheet_editor.cpp b/src/ui/spritesheet_editor.cpp index 5f5d32c..f6b8312 100644 --- a/src/ui/spritesheet_editor.cpp +++ b/src/ui/spritesheet_editor.cpp @@ -388,7 +388,7 @@ using namespace glm; ImGui::PopFont(); auto originLabel = localize.get(region->origin == Origin::TOP_LEFT ? LABEL_REGION_ORIGIN_TOP_LEFT : LABEL_REGION_ORIGIN_CENTER); - for (const auto& line : + for (auto& line : {localize_format(FORMAT_ID, hoveredRegionId), localize_format(FORMAT_CROP, region->crop.x, region->crop.y), localize_format(FORMAT_SIZE, region->size.x, region->size.y), diff --git a/src/ui/spritesheet_editor.h b/src/ui/spritesheet_editor.h index f3cf2be..0ff47cf 100644 --- a/src/ui/spritesheet_editor.h +++ b/src/ui/spritesheet_editor.h @@ -9,7 +9,7 @@ { glm::vec2 previousMousePos{}; glm::vec2 cropAnchor{}; - int hoveredRegionId{-1}; + int hoveredRegionId = -1; public: void update(Manager&, Settings&, Resources&); diff --git a/src/ui/spritesheets.cpp b/src/ui/spritesheets.cpp index 96cb9ef..4466893 100644 --- a/src/ui/spritesheets.cpp +++ b/src/ui/spritesheets.cpp @@ -231,7 +231,7 @@ if (auto spritesheet = spritesheet_get(document, id)) directory_open(dialog, document, spritesheet->path); }; - Actions actions{}; + Actions actions = {}; actions.add(ACTION_OPEN_DIRECTORY, isOne, [&]() { open(*selection.begin()); }); actions.add(ACTION_SET_FILE_PATH, isOne, [&]() { dialog.file_save(Dialog::SPRITESHEET_PATH_SET); }); actions.add(ACTION_ADD, {}, [&]() { dialog.file_open(Dialog::SPRITESHEET_OPEN, true); }, TOOLTIP_ADD_SPRITESHEET); diff --git a/src/ui/taskbar.cpp b/src/ui/taskbar.cpp index 604571a..83d3ee4 100644 --- a/src/ui/taskbar.cpp +++ b/src/ui/taskbar.cpp @@ -42,7 +42,7 @@ using namespace glm; auto* document = manager.get(index); if (!document) return false; - PendingSave request{.index = index, .path = path}; + PendingSave request = {.index = index, .path = path}; if (isQueued) { // Rebirth can't load SVG spritesheets: offer to convert them (the request waits in isaacSave either way). @@ -261,7 +261,7 @@ using namespace glm; auto widgetSize = widget_size_with_row_get(2); if (ImGui::Button(localize.get(LABEL_GENERATE), widgetSize)) { - std::set animationIndices{}; + std::set animationIndices; if (generateRegionsTarget == GENERATE_REGIONS_TARGET_ALL) { for (int i = 0; i < document->model.animations_count_get(); ++i) diff --git a/src/ui/taskbar.h b/src/ui/taskbar.h index dc8844f..f00264e 100644 --- a/src/ui/taskbar.h +++ b/src/ui/taskbar.h @@ -20,40 +20,40 @@ { struct PendingSave { - int index{-1}; - std::filesystem::path path{}; - bool isQueued{}; + int index = -1; + std::filesystem::path path; + bool isQueued = false; }; - ChangeAllFrameProperties changeAllFrameProperties{}; - About about{}; - Configure configure{}; - GenerateAnimationFromGrid generateAnimationFromGrid{}; - RenderAnimation renderAnimation{}; + ChangeAllFrameProperties changeAllFrameProperties = {}; + About about = {}; + Configure configure = {}; + GenerateAnimationFromGrid generateAnimationFromGrid = {}; + RenderAnimation renderAnimation = {}; Canvas generate; - PopupHelper generatePopup{PopupHelper(LABEL_TASKBAR_GENERATE_ANIMATION_FROM_GRID)}; + PopupHelper generatePopup = PopupHelper(LABEL_TASKBAR_GENERATE_ANIMATION_FROM_GRID); PopupHelper generateRegionsPopup{ PopupHelper(LABEL_TASKBAR_GENERATE_REGIONS_FROM_ANIMATIONS, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper changePopup{PopupHelper(LABEL_CHANGE_ALL_FRAME_PROPERTIES, POPUP_NORMAL_NO_HEIGHT)}; - PopupHelper overwritePopup{PopupHelper(LABEL_TASKBAR_OVERWRITE_FILE, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper isaacPopup{PopupHelper(LABEL_ISAAC_COMPATIBILITY_WARNING, POPUP_SMALL_NO_HEIGHT)}; - PendingSave isaacSave{}; - PopupHelper vectorPopup{PopupHelper(LABEL_CONVERT_SVG_POPUP, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper renderPopup{PopupHelper(LABEL_TASKBAR_RENDER_ANIMATION, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper configurePopup{PopupHelper(LABEL_TASKBAR_CONFIGURE)}; - PopupHelper aboutPopup{PopupHelper(LABEL_TASKBAR_ABOUT)}; - Settings editSettings{}; - int generateRegionsTarget{}; - bool isGenerateRegionsMapFrames{true}; - bool isQuittingMode{}; + PopupHelper changePopup = PopupHelper(LABEL_CHANGE_ALL_FRAME_PROPERTIES, POPUP_NORMAL_NO_HEIGHT); + PopupHelper overwritePopup = PopupHelper(LABEL_TASKBAR_OVERWRITE_FILE, POPUP_SMALL_NO_HEIGHT); + PopupHelper isaacPopup = PopupHelper(LABEL_ISAAC_COMPATIBILITY_WARNING, POPUP_SMALL_NO_HEIGHT); + PendingSave isaacSave = {}; + PopupHelper vectorPopup = PopupHelper(LABEL_CONVERT_SVG_POPUP, POPUP_SMALL_NO_HEIGHT); + PopupHelper renderPopup = PopupHelper(LABEL_TASKBAR_RENDER_ANIMATION, POPUP_SMALL_NO_HEIGHT); + PopupHelper configurePopup = PopupHelper(LABEL_TASKBAR_CONFIGURE); + PopupHelper aboutPopup = PopupHelper(LABEL_TASKBAR_ABOUT); + Settings editSettings = {}; + int generateRegionsTarget = 0; + bool isGenerateRegionsMapFrames = true; + bool isQuittingMode = false; bool save_execute(Manager&, const PendingSave&); void save_enqueue(Manager&, const PendingSave&); bool save_request(Manager&, Settings&, int = -1, const std::filesystem::path& = {}, bool = false); public: - float height{}; + float height = 0; void update(Manager&, Settings&, Resources&, Dialog&, bool&); bool save_manual(Manager&, Settings&, int = -1, const std::filesystem::path& = {}); diff --git a/src/ui/theme.cpp b/src/ui/theme.cpp index 526c34e..fafc2f4 100644 --- a/src/ui/theme.cpp +++ b/src/ui/theme.cpp @@ -2,19 +2,19 @@ #include - constexpr ImVec4 COLOR_LIGHT_BUTTON{0.98f, 0.98f, 0.98f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TITLE_BG{0.78f, 0.78f, 0.78f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TITLE_BG_ACTIVE{0.64f, 0.64f, 0.64f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TITLE_BG_COLLAPSED{0.74f, 0.74f, 0.74f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TABLE_HEADER{0.78f, 0.78f, 0.78f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TAB{0.74f, 0.74f, 0.74f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TAB_HOVERED{0.82f, 0.82f, 0.82f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TAB_SELECTED{0.92f, 0.92f, 0.92f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TAB_DIMMED{0.70f, 0.70f, 0.70f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TAB_DIMMED_SELECTED{0.86f, 0.86f, 0.86f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TAB_OVERLINE{0.55f, 0.55f, 0.55f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_TAB_DIMMED_OVERLINE{0.50f, 0.50f, 0.50f, 1.0f}; - constexpr ImVec4 COLOR_LIGHT_CHECK_MARK{0.0f, 0.0f, 0.0f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_BUTTON = {0.98f, 0.98f, 0.98f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TITLE_BG = {0.78f, 0.78f, 0.78f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TITLE_BG_ACTIVE = {0.64f, 0.64f, 0.64f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TITLE_BG_COLLAPSED = {0.74f, 0.74f, 0.74f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TABLE_HEADER = {0.78f, 0.78f, 0.78f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TAB = {0.74f, 0.74f, 0.74f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TAB_HOVERED = {0.82f, 0.82f, 0.82f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TAB_SELECTED = {0.92f, 0.92f, 0.92f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TAB_DIMMED = {0.70f, 0.70f, 0.70f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TAB_DIMMED_SELECTED = {0.86f, 0.86f, 0.86f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TAB_OVERLINE = {0.55f, 0.55f, 0.55f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_TAB_DIMMED_OVERLINE = {0.50f, 0.50f, 0.50f, 1.0f}; + constexpr ImVec4 COLOR_LIGHT_CHECK_MARK = {0.0f, 0.0f, 0.0f, 1.0f}; constexpr auto FRAME_BORDER_SIZE = 1.0f; void theme_set(Theme theme) diff --git a/src/ui/timeline.h b/src/ui/timeline.h index f85983f..030bcad 100644 --- a/src/ui/timeline.h +++ b/src/ui/timeline.h @@ -74,39 +74,39 @@ // track or group root belongs to. struct TimelineRow { - int documentIndex{-1}; - int animationIndex{-1}; - int type{NONE}; - int id{-1}; - int index{-1}; - int groupType{NONE}; - int groupId{-1}; - int depth{}; - bool isGroup{}; + int documentIndex = -1; + int animationIndex = -1; + int type = NONE; + int id = -1; + int index = -1; + int groupType = NONE; + int groupId = -1; + int depth = 0; + bool isGroup = false; auto operator<=>(const TimelineRow&) const = default; }; struct FrameMoveDrag { - int animationIndex{-1}; - int duration{1}; - std::vector references{}; - bool isActive{}; + int animationIndex = -1; + int duration = 1; + std::vector references; + bool isActive = false; }; // What the timeline last put on the clipboard: frames of a type, or one property of a frame. struct FrameClipboard { - std::string text{}; - int itemType{NONE}; - int property{-1}; + std::string text; + int itemType = NONE; + int property = -1; }; struct FrameDurationDrag { - Reference reference{}; - int duration{1}; + Reference reference = {}; + int duration = 1; }; enum class BakeIntoOtherFramesTarget @@ -117,57 +117,57 @@ struct TimelineState { - bool isDragging{}; - bool isRulerHovered{}; - FrameClipboard frameClipboard{}; - int markerTime{}; - bool isWindowHovered{}; - bool isHorizontalScroll{}; - ItemProperties itemProperties{}; - PopupHelper bakePopup{PopupHelper(LABEL_TIMELINE_BAKE_POPUP, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper bakeIntoOtherFramesPopup{PopupHelper(LABEL_BAKE_INTO_OTHER_FRAMES, POPUP_SMALL_NO_HEIGHT)}; - PopupHelper makeManyRegionsPopup{PopupHelper(LABEL_MAKE_MANY_REGIONS, POPUP_SMALL_NO_HEIGHT)}; - BakeIntoOtherFramesTarget bakeIntoOtherFramesTarget{BakeIntoOtherFramesTarget::CURRENT_SELECTION}; - bool isBakeIntoOtherFramesLayers{true}; - bool isBakeIntoOtherFramesNulls{true}; - bool isMakeManyRegionsMapFrames{true}; - std::set makeManyRegionReferences{}; - int hoveredTime{}; - bool isFrameBoxPending{}; - bool isFrameBoxSelecting{}; - bool isFrameBoxAdditive{}; - ImVec2 frameBoxStart{}; - ImVec2 frameBoxEnd{}; - std::set frameBoxSelection{}; - std::optional rowSelectionAnchor{}; - PopupHelper groupPropertiesPopup{PopupHelper(LABEL_GROUP_PROPERTIES, POPUP_SMALL_NO_HEIGHT)}; - std::string groupName{}; - int groupAnimationIndex{-1}; - int groupType{NONE}; - int groupId{-1}; - Reference draggedFrameReference{}; - bool isDraggedFrameActive{}; - int draggedFrameType{}; - int draggedFrameStart{-1}; - int draggedFrameStartDuration{-1}; - std::vector draggedFrameStartDurations{}; - float draggedFrameStartMouseX{}; - float draggedFrameWidth{}; - bool isDraggedFrameSnapshot{}; - FrameMoveDrag frameMoveDrag{}; + bool isDragging = false; + bool isRulerHovered = false; + FrameClipboard frameClipboard = {}; + int markerTime = 0; + bool isWindowHovered = false; + bool isHorizontalScroll = false; + ItemProperties itemProperties = {}; + PopupHelper bakePopup = PopupHelper(LABEL_TIMELINE_BAKE_POPUP, POPUP_SMALL_NO_HEIGHT); + PopupHelper bakeIntoOtherFramesPopup = PopupHelper(LABEL_BAKE_INTO_OTHER_FRAMES, POPUP_SMALL_NO_HEIGHT); + PopupHelper makeManyRegionsPopup = PopupHelper(LABEL_MAKE_MANY_REGIONS, POPUP_SMALL_NO_HEIGHT); + BakeIntoOtherFramesTarget bakeIntoOtherFramesTarget = BakeIntoOtherFramesTarget::CURRENT_SELECTION; + bool isBakeIntoOtherFramesLayers = true; + bool isBakeIntoOtherFramesNulls = true; + bool isMakeManyRegionsMapFrames = true; + std::set makeManyRegionReferences; + int hoveredTime = 0; + bool isFrameBoxPending = false; + bool isFrameBoxSelecting = false; + bool isFrameBoxAdditive = false; + ImVec2 frameBoxStart; + ImVec2 frameBoxEnd; + std::set frameBoxSelection; + std::optional rowSelectionAnchor; + PopupHelper groupPropertiesPopup = PopupHelper(LABEL_GROUP_PROPERTIES, POPUP_SMALL_NO_HEIGHT); + std::string groupName; + int groupAnimationIndex = -1; + int groupType = NONE; + int groupId = -1; + Reference draggedFrameReference = {}; + bool isDraggedFrameActive = false; + int draggedFrameType = 0; + int draggedFrameStart = -1; + int draggedFrameStartDuration = -1; + std::vector draggedFrameStartDurations; + float draggedFrameStartMouseX = 0; + float draggedFrameWidth = 0; + bool isDraggedFrameSnapshot = false; + FrameMoveDrag frameMoveDrag = {}; // The tab a held shorten/extend chord is editing (0 when released), so a held chord starts one undo entry per document. std::uint64_t resizeChordTabIds[2]{}; - std::optional frameSelectionAnchor{}; - int animationLengthEditIndex{-1}; - std::vector rowDragReferences{}; - std::set expandedLayerTracks{}; // animation layer tracks (by uid) showing their child's tracks + std::optional frameSelectionAnchor; + int animationLengthEditIndex = -1; + std::vector rowDragReferences; + std::set expandedLayerTracks; // animation layer tracks (by uid) showing their child's tracks glm::vec2 scroll{}; - ImGuiStyle style{}; + ImGuiStyle style = {}; }; class Timeline { - std::unique_ptr context{}; + std::unique_ptr context; public: Timeline(); diff --git a/src/ui/timeline_children.cpp b/src/ui/timeline_children.cpp index 17d0e60..ddb507d 100644 --- a/src/ui/timeline_children.cpp +++ b/src/ui/timeline_children.cpp @@ -7,7 +7,7 @@ // The child animation's tracks (root, layers top-down, nulls, triggers) when an animation layer row is expanded. std::vector TimelineContext::peek_rows_get(const TimelineRow& row) { - std::vector rows{}; + std::vector rows; if (row.isGroup || row.type != LAYER) return rows; auto track = item_get(LAYER, row.id, row.groupType, row.groupId); auto layer = ::item_get(model.content.layers, row.id); @@ -20,7 +20,7 @@ if (settings.timelineIsShowUnused || !childTrack.frames.empty()) rows.push_back({source, child, &childTrack}); }; row_add(child->root); - std::vector layers{}; + std::vector layers; tracks_each(child->layers, [&](const Track& childTrack, auto*) { layers.push_back(&childTrack); }); for (auto it = layers.rbegin(); it != layers.rend(); ++it) row_add(**it); @@ -107,8 +107,8 @@ ImGui::GetColorU32(iconTintDefault)); }; - int runStart{}; - int runKey{-1}; + int runStart = 0; + int runKey = -1; for (int time = 0; time <= animation->frameNum; ++time) { auto key = time < animation->frameNum && track && layer ? key_get(time) : -1; diff --git a/src/ui/timeline_context.h b/src/ui/timeline_context.h index b39b929..cd7e8ed 100644 --- a/src/ui/timeline_context.h +++ b/src/ui/timeline_context.h @@ -134,9 +134,9 @@ using namespace glm; // A read-only row under an expanded animation layer: one track of the child animation it plays. struct PeekRow { - const Model* source{}; - const Animation* child{}; - const Track* track{}; + const Model* source = nullptr; + const Animation* child = nullptr; + const Track* track = nullptr; }; Reference row_item_reference_get(const TimelineRow&); @@ -152,32 +152,32 @@ using namespace glm; Model& model; Playback& playback; Reference reference; - const Animation* animation{}; - float rowFrameChildHeight{}; - bool isLightTheme{}; - bool isTextPushed{}; + const Animation* animation = nullptr; + float rowFrameChildHeight = 0; + bool isLightTheme = false; + bool isTextPushed = false; - ImVec4 iconTintDefault{}; - ImVec4 itemIconTint{}; - ImVec4 frameBorderColor{}; - ImVec4 frameBorderColorReferenced{}; - ImVec4 frameMultipleOverlayColor{}; - ImVec4 textMultipleColor{}; - ImVec4 playheadLineColor{}; - ImVec4 playheadIconTint{}; - ImVec4 timelineBackgroundColor{}; - ImVec4 timelinePlayheadRectColor{}; - ImVec4 timelineTickColor{}; - ImVec4 itemTextColor{}; - std::optional frameSplitTimeAtCursor{}; + ImVec4 iconTintDefault; + ImVec4 itemIconTint; + ImVec4 frameBorderColor; + ImVec4 frameBorderColorReferenced; + ImVec4 frameMultipleOverlayColor; + ImVec4 textMultipleColor; + ImVec4 playheadLineColor; + ImVec4 playheadIconTint; + ImVec4 timelineBackgroundColor; + ImVec4 timelinePlayheadRectColor; + ImVec4 timelineTickColor; + ImVec4 itemTextColor; + std::optional frameSplitTimeAtCursor; - std::optional frameMoveDropTarget{}; - float playheadLineCenterX{}; - float playheadLineTopY{}; - bool isPlayheadLineSet{}; - ImVec2 frameBoxClipMin{}; - ImVec2 frameBoxClipMax{}; - bool isFrameBoxClipSet{}; + std::optional frameMoveDropTarget; + float playheadLineCenterX = 0; + float playheadLineTopY = 0; + bool isPlayheadLineSet = false; + ImVec2 frameBoxClipMin; + ImVec2 frameBoxClipMax; + bool isFrameBoxClipSet = false; const Track* item_get(int type, int id = -1, int groupType = NONE, int groupId = -1); const Frame* frame_get(); diff --git a/src/ui/timeline_edit.cpp b/src/ui/timeline_edit.cpp index 625071d..838020f 100644 --- a/src/ui/timeline_edit.cpp +++ b/src/ui/timeline_edit.cpp @@ -28,7 +28,7 @@ bool TimelineContext::is_frames_reverse_available(std::set selectedFrames) { - std::map counts{}; + std::map counts; std::erase_if(selectedFrames, is_trigger_reference); for (auto frameReference : selectedFrames) { @@ -67,7 +67,7 @@ const Document& targetDocument, const Animation& targetAnimation, BakeIntoOtherFramesTarget target, bool isLayers, bool isNulls) { - std::set result{}; + std::set result; auto animationIndex = targetDocument.reference_get().animationIndex; if (target == BakeIntoOtherFramesTarget::CURRENT_SELECTION) { @@ -121,8 +121,8 @@ void TimelineContext::item_remove() { - std::map> ids{}; - std::map> groupIds{}; + std::map> ids; + std::map> groupIds; for (auto row : selected_row_references_get()) if (row.type == LAYER || row.type == NULL_) (row.isGroup ? groupIds : ids)[row.type].insert(row.id); if (!animation || (ids.empty() && groupIds.empty())) return; @@ -144,11 +144,11 @@ { return itemReference.itemType != LAYER && itemReference.itemType != NULL_; }); if (selectedItems.empty()) return std::vector{}; auto itemType = selectedItems.begin()->itemType; - for (const auto& itemReference : selectedItems) + for (auto& itemReference : selectedItems) if (itemReference.itemType != itemType) return std::vector{}; - std::vector result{}; - for (const auto& row : timeline_item_rows_get()) + std::vector result; + for (auto& row : timeline_item_rows_get()) { if (row.isGroup || row.type != itemType) continue; auto itemReference = item_reference_get(row.type, row.id, NONE, -1); @@ -163,7 +163,7 @@ { auto targetReferences = item_references_groupable_get(); if (targetReferences.empty()) return; - std::set ids{}; + std::set ids; for (auto itemReference : targetReferences) ids.insert(itemReference.itemID); edit_push( @@ -192,18 +192,18 @@ targetRow.type != TRIGGER) return; - std::set ids{}; - std::set groupIds{}; - for (const auto& row : draggedRows) + std::set ids; + std::set groupIds; + for (auto& row : draggedRows) (row.isGroup ? groupIds : ids).insert(row.id); RowTarget target{targetRow.isGroup, targetRow.type, targetRow.id, targetRow.type == ROOT ? -1 : targetRow.groupId}; auto animationIndex = reference.animationIndex; - std::set tracks{}; - std::set groups{}; - for (const auto& row : draggedRows) + std::set tracks; + std::set groups; + for (auto& row : draggedRows) (row.isGroup ? groups : tracks).insert(row_selection_reference_get(row)); - Selection moved{}; + Selection moved = {}; selection_references_set(moved, model, SelectionKind::TRACKS, tracks); selection_references_set(moved, model, SelectionKind::GROUPS, groups); if (!tracks.empty()) selection_focus_set(moved, model, *tracks.begin()); @@ -238,7 +238,7 @@ { if (!animation || selectedFrames.empty()) return; - std::string clipboardString{}; + std::string clipboardString; for (auto frameReference : selectedFrames) { auto frame = model.frame_get(frameReference); diff --git a/src/ui/timeline_frames.cpp b/src/ui/timeline_frames.cpp index 2980fe0..e25979c 100644 --- a/src/ui/timeline_frames.cpp +++ b/src/ui/timeline_frames.cpp @@ -135,9 +135,9 @@ auto boxMax = ImVec2(std::max(frameBoxStart.x, frameBoxEnd.x), std::max(frameBoxStart.y, frameBoxEnd.y)); auto rowMinY = cursorScreenPos.y + scroll.y - frameBoxClipMin.y; auto rowMaxY = rowMinY + childSize.y; - float selectionFrameTime{}; - int frameIndex{}; - for (const auto& frame : item->frames) + float selectionFrameTime = 0; + int frameIndex = 0; + for (auto& frame : item->frames) { auto frameReference = row_reference_make(frameIndex); auto frameStart = type == TRIGGER ? frame.atFrame : selectionFrameTime; @@ -246,7 +246,7 @@ isRulerHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup); if (isRulerHovered && ImGui::IsMouseReleased(ImGuiMouseButton_Right)) markerTime = hoveredTime; - Actions markerActions{}; + Actions markerActions = {}; auto isAnimation = [&]() { return animation != nullptr; }; markerActions.add({.label = LABEL_ADD_START_MARKER, .shortcut = SHORTCUT_START_MARKER, @@ -281,7 +281,7 @@ } else if (animation) { - float frameTime{}; + float frameTime = 0; for (int i = frameMin; i < frameMax; i++) { @@ -306,11 +306,11 @@ } bool isFrameMovePreview = false; - ImVec2 frameMovePreviewMin{}; - ImVec2 frameMovePreviewMax{}; + ImVec2 frameMovePreviewMin; + ImVec2 frameMovePreviewMax; bool isFrameMoveHoveredFrame = false; - ImVec2 frameMoveHoveredFrameMin{}; - ImVec2 frameMoveHoveredFrameMax{}; + ImVec2 frameMoveHoveredFrameMin; + ImVec2 frameMoveHoveredFrameMax; if (frameMoveDrag.isActive && type != TRIGGER) { @@ -322,11 +322,11 @@ auto mouseX = mousePos.x - cursorScreenPos.x; auto targetTime = glm::max(0.0f, mouseX / frameSize.x); int dropIndex = (int)item->frames.size(); - float dropFrameTime{}; - float frameTime{}; - int frameIndex{}; + float dropFrameTime = 0; + float frameTime = 0; + int frameIndex = 0; - for (const auto& frame : item->frames) + for (auto& frame : item->frames) { auto frameStart = frameTime; auto frameEnd = frameStart + frame.duration; @@ -569,7 +569,7 @@ } else { - std::map durations{}; + std::map durations; if (draggedFrameStartDurations.empty()) durations[targetReference] = draggedFrameStartDuration + durationDelta; for (auto frameDuration : draggedFrameStartDurations) durations[frameDuration.reference] = frameDuration.duration + durationDelta; @@ -615,7 +615,7 @@ auto animationsLength = [&]() { - int length{}; + int length = 0; for (auto [index, item] : model.animations_get()) length = std::max(length, animation_length_get(*item)); return length; @@ -711,7 +711,7 @@ } } - int index{}; + int index = 0; ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("##Frames"); @@ -729,10 +729,10 @@ { ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f); - for (const auto& row : timeline_item_rows_get()) + for (auto& row : timeline_item_rows_get()) { frames_child_row(row); - for (const auto& peek : peek_rows_get(row)) + for (auto& peek : peek_rows_get(row)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); diff --git a/src/ui/timeline_menus.cpp b/src/ui/timeline_menus.cpp index 13c26ba..4908bb8 100644 --- a/src/ui/timeline_menus.cpp +++ b/src/ui/timeline_menus.cpp @@ -76,7 +76,7 @@ auto spritesheetID = layer->spritesheetId; if (!::item_get(document.model.content.spritesheets, spritesheetID)) return; - Region region{.crop = frame->crop, .size = frame->size, .pivot = frame->pivot}; + Region region = {.crop = frame->crop, .size = frame->size, .pivot = frame->pivot}; document.focused_id_set(SelectionKind::SPRITESHEETS, spritesheetID); settingsPtr->windowIsRegions = true; @@ -106,7 +106,7 @@ bool isMakeManyRegions = selectedRegionFrames.size() > 1; auto selectedRootFrames = selected_root_frame_references_get(); bool isMakeRegion = is_region_makeable(reference); - Actions actions{}; + Actions actions = {}; actions_undo_redo_add(actions, manager, document); actions.separator(); actions.add({.label = playback.isPlaying ? LABEL_PAUSE : LABEL_PLAY, @@ -162,7 +162,7 @@ auto properties_get = [&](int itemType, std::function is_property_enabled, std::function property_run) { - Action properties{.label = LABEL_PROPERTY}; + Action properties = {.label = LABEL_PROPERTY}; for (int i = 0; i < (int)FrameProperty::COUNT; ++i) { auto property = (FrameProperty)i; @@ -273,8 +273,8 @@ auto selectedRows = selected_row_references_get(); auto selectedGroupableItems = item_references_groupable_get(); auto copyFrames = copy_frame_references_get(); - TimelineRow selectedGroupRow{}; - const TrackGroup* selectedGroup{}; + TimelineRow selectedGroupRow = {}; + const TrackGroup* selectedGroup = nullptr; if (selectedRows.size() == 1 && selectedRows.front().isGroup) { auto row = selectedRows.front(); @@ -294,7 +294,7 @@ ImGui::IsMouseClicked(ImGuiMouseButton_Right)) ImGui::OpenPopup("##Items Context Menu"); - Actions actions{}; + Actions actions = {}; actions_undo_redo_add(actions, manager, document); actions.separator(); actions.add( diff --git a/src/ui/timeline_selection.cpp b/src/ui/timeline_selection.cpp index bb73599..4695805 100644 --- a/src/ui/timeline_selection.cpp +++ b/src/ui/timeline_selection.cpp @@ -90,7 +90,7 @@ if (selectedItems.empty() && reference.itemType != NONE && reference.frameIndex < 0) selectedItems.insert(item_reference_from_frame_get(reference)); - std::set result{}; + std::set result; for (auto itemReference : selectedItems) { itemReference.frameIndex = -1; @@ -109,7 +109,7 @@ std::vector TimelineContext::timeline_item_rows_get() { - std::vector rows{}; + std::vector rows; if (!animation) return rows; auto is_track_shown = [&](const Track& track) @@ -266,8 +266,8 @@ void TimelineContext::reference_set_adjacent_item(int direction) { - std::vector itemReferences{}; - for (const auto& row : timeline_item_rows_get()) + std::vector itemReferences; + for (auto& row : timeline_item_rows_get()) if (!row.isGroup) itemReferences.push_back(row_item_reference_get(row)); if (itemReferences.empty()) return; @@ -285,8 +285,8 @@ std::vector TimelineContext::selected_row_references_get() { - std::vector result{}; - for (const auto& row : timeline_item_rows_get()) + std::vector result; + for (auto& row : timeline_item_rows_get()) if (is_row_selected(row)) result.push_back(row); return result; } diff --git a/src/ui/timeline_tracks.cpp b/src/ui/timeline_tracks.cpp index 6dc3b69..7ea0d89 100644 --- a/src/ui/timeline_tracks.cpp +++ b/src/ui/timeline_tracks.cpp @@ -56,7 +56,7 @@ { return mouse.x >= min.x && mouse.x < max.x && mouse.y >= min.y && mouse.y < max.y; }; auto isGroupHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) && is_mouse_in_rect(mousePos, groupButtonMin, groupButtonMax); - bool isGroupTooltipDelayed{}; + bool isGroupTooltipDelayed = false; if (isGroupHovered) { auto& imguiStyle = ImGui::GetStyle(); @@ -556,13 +556,13 @@ item_child(row, index); }; - int index{}; + int index = 0; item_child_row({.type = NONE}, index++); if (animation) - for (const auto& row : timeline_item_rows_get()) + for (auto& row : timeline_item_rows_get()) { item_child_row(row, index++); - for (const auto& peek : peek_rows_get(row)) + for (auto& peek : peek_rows_get(row)) { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); diff --git a/src/ui/toast.h b/src/ui/toast.h index cd614aa..b73abe8 100644 --- a/src/ui/toast.h +++ b/src/ui/toast.h @@ -10,8 +10,8 @@ class Toast { public: - std::string message{}; - float lifetime{}; + std::string message; + float lifetime = 0; Toast(const std::string&); }; @@ -19,7 +19,7 @@ class Toasts { public: - std::vector toasts{}; + std::vector toasts; void update(); void push(const std::string&); diff --git a/src/ui/tree.cpp b/src/ui/tree.cpp index 0b01170..8de2ab1 100644 --- a/src/ui/tree.cpp +++ b/src/ui/tree.cpp @@ -3,7 +3,7 @@ TreeNodeInputTextResult tree_node_input_text(const std::string& label, const std::string& id, std::string& text, bool isSelected, ImGuiTreeNodeFlags flags, RenameState& state) { - TreeNodeInputTextResult result{}; + TreeNodeInputTextResult result = {}; auto& editID = selectable_input_text_id(); auto isRename = editID == id; auto treeFlags = flags | ImGuiTreeNodeFlags_FramePadding | (isSelected ? ImGuiTreeNodeFlags_Selected : 0); diff --git a/src/ui/tree.h b/src/ui/tree.h index 45d2771..bd5893d 100644 --- a/src/ui/tree.h +++ b/src/ui/tree.h @@ -8,11 +8,11 @@ struct TreeNodeInputTextResult { - bool isOpen{}; - bool isActivated{}; - bool isClicked{}; - bool isRenameStarted{}; - bool isRenameFinished{}; + bool isOpen = false; + bool isActivated = false; + bool isClicked = false; + bool isRenameStarted = false; + bool isRenameFinished = false; }; TreeNodeInputTextResult tree_node_input_text(const std::string&, const std::string&, std::string&, bool, diff --git a/src/uid.h b/src/uid.h index 863bfe2..7631ef4 100644 --- a/src/uid.h +++ b/src/uid.h @@ -6,6 +6,6 @@ // Process-unique, never reused; 0 means "none". inline std::uint64_t uid_next() { - static std::atomic next{1}; + static std::atomic next = 1; return next++; } diff --git a/src/vector.h b/src/vector.h index 25a3ff4..ab3abcf 100644 --- a/src/vector.h +++ b/src/vector.h @@ -46,7 +46,7 @@ v.insert(v.begin() + insertPos, std::make_move_iterator(moveItems.begin()), std::make_move_iterator(moveItems.end())); - std::set moveIndices{}; + std::set moveIndices; for (int i = 0; i < (int)moveItems.size(); i++) moveIndices.insert(insertPos + i); diff --git a/src/working_directory.cpp b/src/working_directory.cpp index f11da8b..7a86c8a 100644 --- a/src/working_directory.cpp +++ b/src/working_directory.cpp @@ -7,7 +7,7 @@ WorkingDirectory::WorkingDirectory(const std::filesystem::path& path, Type type) { - std::error_code ec{}; + std::error_code ec; previous = std::filesystem::current_path(ec); if (ec) { @@ -37,7 +37,7 @@ { if (previous.empty()) return; - std::error_code ec{}; + std::error_code ec; std::filesystem::current_path(previous, ec); if (ec) logger.warning( diff --git a/src/working_directory.h b/src/working_directory.h index e99e5d1..13e18cf 100644 --- a/src/working_directory.h +++ b/src/working_directory.h @@ -11,7 +11,7 @@ DIRECTORY }; - std::filesystem::path previous{}; + std::filesystem::path previous; WorkingDirectory(const std::filesystem::path&, Type type = DIRECTORY); ~WorkingDirectory(); diff --git a/tests/assets.cpp b/tests/assets.cpp index 802d9e2..0bbba05 100644 --- a/tests/assets.cpp +++ b/tests/assets.cpp @@ -10,7 +10,7 @@ TEST_CASE("Image png round trip and uid tracking") { - const std::vector pixels{255, 0, 0, 255, 0, 255, 0, 128, 0, 0, 255, 0, 10, 20, 30, 40}; + const std::vector pixels = {255, 0, 0, 255, 0, 255, 0, 128, 0, 0, 255, 0, 10, 20, 30, 40}; Image image(pixels.data(), {2, 2}); REQUIRE(image.is_valid()); @@ -45,8 +45,8 @@ TEST_CASE("AudioData holds file bytes") TEST_CASE("AssetStore keys assets by content") { - AssetStore store{}; - const std::vector pixels{1, 2, 3, 4}; + AssetStore store = {}; + const std::vector pixels = {1, 2, 3, 4}; auto key = store.image_add(Image(pixels.data(), {1, 1})); CHECK(key != 0); CHECK(store.image_add(Image(pixels.data(), {1, 1})) == key); @@ -91,7 +91,7 @@ TEST_CASE("SVG spritesheets compose into SVGs that draw the same") CHECK(swapped.pixel_read({1.0f, 1.0f}) == glm::vec4()); // A PNG part is embedded as an image, pixel for pixel; composing the result again still works. - const std::vector pixels{255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255}; + const std::vector pixels = {255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255}; Image raster(pixels.data(), {2, 2}); auto mixed = Image::compose({{&swapped, {}, swapped.size, {}}, {&raster, {}, raster.size, {32, 0}}}, {34, 16}, true); REQUIRE(mixed.is_vector()); @@ -123,8 +123,8 @@ TEST_CASE("Embedded resources load") for (auto& info : FRIENDS) { INFO("friend: ", info.name); - Model model{}; - std::string errorString{}; + Model model = {}; + std::string errorString; CHECK(model_load_string(model, std::string_view((const char*)info.anm2->data, info.anm2->size), &errorString)); CHECK(model.animations_count_get() > 0); CHECK(Image(info.png->data, info.png->size).is_valid()); diff --git a/tests/common.h b/tests/common.h index 63e800a..63b6ac8 100644 --- a/tests/common.h +++ b/tests/common.h @@ -43,8 +43,8 @@ inline std::vector fixtures_get() { - std::vector fixtures{}; - for (const auto& entry : std::filesystem::directory_iterator(CORPUS_DIR)) + std::vector fixtures; + for (auto& entry : std::filesystem::directory_iterator(CORPUS_DIR)) if (entry.path().extension() == ".anm2") fixtures.push_back(entry.path()); std::ranges::sort(fixtures); return fixtures; @@ -52,7 +52,7 @@ inline Model model_load(const std::string& text) { - Model model{}; + Model model = {}; REQUIRE(model_load_string(model, text)); return model; } @@ -60,14 +60,14 @@ // Every serialization and merge the editor can produce for a document; goldens lock each one down. inline std::vector variants_get(const Model& model) { - std::vector variants{}; + std::vector variants; for (auto [name, flags] : PRESETS) variants.emplace_back(name, model_serialize(model, flags)); variants.emplace_back("save", model_to_string(model)); for (auto [name, type] : MERGES) { auto merged = model; - std::set sources{0, 1, 2}; + std::set sources = {0, 1, 2}; animations_merge(merged, 0, sources, type, type == MERGE_PREPEND || type == MERGE_REPLACE, {}); variants.emplace_back(name, model_serialize(merged, SERIALIZE_ANM2ED_DEFAULT)); diff --git a/tests/corpus_local.cpp b/tests/corpus_local.cpp index 0e58218..5d88afe 100644 --- a/tests/corpus_local.cpp +++ b/tests/corpus_local.cpp @@ -8,20 +8,20 @@ TEST_CASE("local corpus matches baselines" * doctest::skip(!is_env_set("ANM2ED_C ? std::filesystem::path(std::getenv("ANM2ED_CORPUS_BASELINE")) : std::filesystem::path(std::getenv("HOME")) / ".cache/anm2ed/corpus"; std::istringstream list(file_load(std::getenv("ANM2ED_CORPUS"))); - std::string line{}; + std::string line; while (std::getline(list, line)) { if (line.empty()) continue; INFO("file: ", line); auto key = std::format("{:016x}", std::hash{}(line)); - Model anm2{}; - std::string error{}; + Model anm2 = {}; + std::string error; if (!model_load(anm2, line, &error)) { golden_check(baseline / (key + ".error.txt"), error, true); continue; } - for (const auto& [name, text] : variants_get(anm2)) + for (auto& [name, text] : variants_get(anm2)) golden_check(baseline / std::format("{}.{}.xml", key, name), text, true); invariants_check(anm2); } diff --git a/tests/draw.cpp b/tests/draw.cpp index b28f724..6a1ac1d 100644 --- a/tests/draw.cpp +++ b/tests/draw.cpp @@ -28,7 +28,7 @@ TEST_CASE("root transforms fold into layer draws") auto plain = animation_draws_get(anm2, animation, {}); auto rooted = animation_draws_get(anm2, animation, {.isRootTransform = true}); REQUIRE(plain.size() == rooted.size()); - bool isAnyMoved{}; + bool isAnyMoved = false; for (int i = 0; i < (int)plain.size(); ++i) isAnyMoved |= plain[i].type == DrawType::LAYER && plain[i].parent != rooted[i].parent; CHECK(isAnyMoved); @@ -39,8 +39,8 @@ TEST_CASE("a layer frame's depth moves it among the layers for that frame only") auto anm2 = model_load(file_load(TEST_DIR / "render" / "spin.anm2")); auto layer_ids_get = [&](float time) { - std::vector ids{}; - for (const auto& draw : animation_draws_get(anm2, *anm2.animation_get(0), {.time = time})) + std::vector ids; + for (auto& draw : animation_draws_get(anm2, *anm2.animation_get(0), {.time = time})) if (draw.type == DrawType::LAYER) ids.push_back(draw.id); return ids; }; @@ -60,8 +60,8 @@ TEST_CASE("a layer frame's blur reaches its child's draws and stays out of the g { auto anm2 = model_load(file_load(TEST_DIR / "render" / "nested.anm2")); anm2.frame_edit({0, LAYER, 1, 0})->blur = 6.0f; - bool isAnyChild{}; - for (const auto& draw : animation_draws_get(anm2, *anm2.animation_get(0), {})) + bool isAnyChild = false; + for (auto& draw : animation_draws_get(anm2, *anm2.animation_get(0), {})) if (draw.type == DrawType::LAYER && draw.id == 1) { isAnyChild = true; @@ -79,11 +79,11 @@ TEST_CASE("an animation layer draws its child animation, from this file or a lib { auto anm2 = model_load(file_load(TEST_DIR / "render" / "nested.anm2")); auto spin = model_load(file_load(TEST_DIR / "render" / "spin.anm2")); - DrawOptions options{.library_get = [&](const Model&, int id) { return id == 0 ? &spin : nullptr; }}; + DrawOptions options = {.library_get = [&](const Model&, int id) { return id == 0 ? &spin : nullptr; }}; auto red_position_get = [&](int layerId) { std::optional position{}; - for (const auto& draw : animation_draws_get(anm2, *anm2.animation_get(0), options)) + for (auto& draw : animation_draws_get(anm2, *anm2.animation_get(0), options)) if (draw.type == DrawType::LAYER && draw.id == layerId && draw.frame.crop == glm::vec2()) position = glm::vec2(draw.parent * glm::vec4(draw.frame.position, 0.0f, 1.0f)); return position; @@ -143,8 +143,8 @@ TEST_CASE("child animations fire their triggers as they reach them") auto library_get = [&](const Model&, int id) { return id == 0 ? &spin : nullptr; }; auto sources_get = [&](int time) { - std::vector sources{}; - for (const auto& fire : animation_triggers_get(anm2, *anm2.animation_get(0), time, library_get)) + std::vector sources; + for (auto& fire : animation_triggers_get(anm2, *anm2.animation_get(0), time, library_get)) sources.push_back(fire.source); return sources; }; @@ -171,7 +171,7 @@ TEST_CASE("flattening animation layers bakes their children into plain layers th auto points_get = [&](const Model& model, const LibraryGet& get, float time) { std::vector points{}; - for (const auto& draw : + for (auto& draw : animation_draws_get(model, *model.animation_get(0), {.time = time, .library_get = get})) if (draw.type == DrawType::LAYER) points.push_back(glm::round(glm::vec2(draw.parent * draw_quad_model_get(draw) * glm::vec4(1, 1, 0, 1)))); @@ -223,7 +223,7 @@ TEST_CASE("the game's copy stands in for depth and alpha offsets") auto draws_get = [](const Model& model, float time) { std::vector> draws{}; - for (const auto& draw : animation_draws_get(model, *model.animation_get(0), {.time = time})) + for (auto& draw : animation_draws_get(model, *model.animation_get(0), {.time = time})) if (draw.type == DrawType::LAYER && draw.frame.isVisible) draws.emplace_back(draw.frame.crop, draw.frame.position); return draws; diff --git a/tests/invariants.cpp b/tests/invariants.cpp index e94c04f..7d2a04e 100644 --- a/tests/invariants.cpp +++ b/tests/invariants.cpp @@ -2,7 +2,7 @@ TEST_CASE("per-fixture invariants") { - for (const auto& fixture : fixtures_get()) + for (auto& fixture : fixtures_get()) { INFO("fixture: ", fixture.filename().string()); invariants_check(model_load(file_load(fixture))); @@ -28,7 +28,7 @@ TEST_CASE("saved text escapes what it holds, and reads back the same") TEST_CASE("saves leave out default colors, which read back the same") { - for (const auto& fixture : fixtures_get()) + for (auto& fixture : fixtures_get()) { INFO("fixture: ", fixture.string()); auto model = model_load(file_load(fixture)); @@ -41,7 +41,7 @@ TEST_CASE("saves leave out default colors, which read back the same") TEST_CASE("JSON documents read back as the editor's copy") { - for (const auto& fixture : fixtures_get()) + for (auto& fixture : fixtures_get()) { INFO("fixture: ", fixture.string()); auto model = model_load(file_load(fixture)); @@ -113,8 +113,8 @@ TEST_CASE("JSON that can't be read is reported by where it is, and the rest stil auto text = R"({ "colour": 1, "info": { "fps": "fast" }, "layers": [ { "name": "a", "sheet": 4 } ], "animations": { "Idle": { "length": 3, "root": [ { "pos": [1], "ease": "bouncy", "delay": 3 } ] } } })"; - Model model{}; - std::string issues{}; + Model model = {}; + std::string issues; REQUIRE(model_load_string(model, text, &issues)); CHECK(model.animation_get(0)->frameNum == 3); CHECK(model.animation_get(0)->root.frames[0].duration == 3); @@ -130,8 +130,8 @@ TEST_CASE("JSON layers can name a library listed after them in the file") { auto text = R"({ "layers": [ { "name": "shadow", "library": 0, "animation": "Small" } ], "libraries": [ "shared/shadows.anm2" ] })"; - Model model{}; - std::string issues{}; + Model model = {}; + std::string issues; REQUIRE(model_load_string(model, text, &issues)); CHECK(issues.empty()); CHECK(model.content.layers[0].libraryId == 0); diff --git a/tests/operations.cpp b/tests/operations.cpp index d214417..ac333f8 100644 --- a/tests/operations.cpp +++ b/tests/operations.cpp @@ -21,7 +21,7 @@ static Track& layer_track_get(Model& model, int animationIndex, int layerId) static int groups_named_count(const Animation& animation, std::string_view name) { - int count{}; + int count = 0; for (const auto* entries : {&animation.layers, &animation.nulls}) groups_each(*entries, [&](const TrackGroup& group) { count += group.name == name; }); return count; @@ -85,7 +85,7 @@ TEST_CASE("frames_change") for (auto [name, type] : CHANGES) { auto model = fixture_load("02_items.anm2"); - FrameChange change{.cropX = 2.0f, .positionY = 4.0f, .scaleX = 50.0f, .rotation = 90.0f, .tintR = 0.5f}; + FrameChange change = {.cropX = 2.0f, .positionY = 4.0f, .scaleX = 50.0f, .rotation = 90.0f, .tintR = 0.5f}; change.duration = 3; change.interpolation = Interpolation::EASE_IN; change.isFlipX = true; @@ -101,8 +101,8 @@ TEST_CASE("frame_bake and frame_mix") frame_bake(layer_track_get(model, 0, 0), 3, 1, false, true); operation_check("frame_bake", model); - Frame from{}; - Frame to{}; + Frame from = {}; + Frame to = {}; to.position = {10.0f, -20.0f}; to.skew = {30.0f, 0.0f}; to.rotation = 90.0f; @@ -145,7 +145,7 @@ TEST_CASE("edit layer operations") std::size_t uidCount; }; - const Reference head{0, LAYER, 0}; + const Reference head = {0, LAYER, 0}; const Case CASES[] = { {"frame_insert", "02_items.anm2", [&](Model& anm2) { return frame_insert(anm2, {0, LAYER, 0, 0}, 0); }, 1}, @@ -195,7 +195,7 @@ TEST_CASE("edit layer operations") {"animations_paste", "02_items.anm2", [&](Model& anm2) { - std::set groupIds{}; + std::set groupIds; auto text = animation_to_string(*anm2.animation_get(1)); return animations_paste(anm2, text, 0, -1, groupIds, nullptr); }, @@ -217,7 +217,7 @@ TEST_CASE("edit layer operations") {"frames_change_apply", "02_items.anm2", [&](Model& anm2) { - FrameChange change{.positionX = 3.0f, .rotation = 10.0f}; + FrameChange change = {.positionX = 3.0f, .rotation = 10.0f}; return frames_change_apply( anm2, {.references = {{0, LAYER, 0, 1}, {0, NULL_, 0}}, .animations = {1}, .isRoot = true}, change, ChangeType::ADD); @@ -227,7 +227,7 @@ TEST_CASE("edit layer operations") [&](Model& anm2) { return animations_merge(anm2, 0, {1}, MERGE_APPEND, true, {0}); }, 1}, }; - for (const auto& entry : CASES) + for (auto& entry : CASES) { INFO("operation: ", std::string(entry.name)); auto anm2 = fixture_load(entry.fixture); @@ -303,7 +303,7 @@ TEST_CASE("markers stay in the editor's copy and bound playback") CHECK(reloaded.animation_get(0)->startMarker == 2); CHECK(reloaded.animation_get(0)->endMarker == 5); - Playback playback{}; + Playback playback = {}; playback.isPlaying = true; playback.tick(10, 2, 6, true, 0.1f); CHECK(playback.time == doctest::Approx(3.0f)); @@ -325,9 +325,9 @@ TEST_CASE("isaac_issues_get counts what the game's copy changes") TEST_CASE("frames_property_set copies one property to the frames that have it") { auto model = fixture_load("02_items.anm2"); - Frame source{.crop = {7, 8}, .position = {3, 4}}; - Reference layer{0, LAYER, 0, 0}; - Reference null{0, NULL_, 0, 0}; + Frame source = {.crop = {7, 8}, .position = {3, 4}}; + Reference layer = {0, LAYER, 0, 0}; + Reference null = {0, NULL_, 0, 0}; REQUIRE(model.frame_get(layer)); REQUIRE(model.frame_get(null)); auto nullCrop = model.frame_get(null)->crop; @@ -367,8 +367,8 @@ TEST_CASE("frames_split splits every selected frame that spans the time") TEST_CASE("change all frame properties changes layer depth only") { auto model = fixture_load("02_items.anm2"); - Reference layer{0, LAYER, 0, 0}; - Reference null{0, NULL_, 0, 0}; + Reference layer = {0, LAYER, 0, 0}; + Reference null = {0, NULL_, 0, 0}; frames_change_apply(model, {.references = {layer, null}}, {.depth = 2}, ChangeType::ADD); frames_change_apply(model, {.references = {layer, null}}, {.depth = 1}, ChangeType::SUBTRACT); CHECK(model.frame_get(layer)->depth == 1); @@ -378,8 +378,8 @@ TEST_CASE("change all frame properties changes layer depth only") TEST_CASE("change all frame properties blurs layers and changes only animation layers' children") { auto model = model_load(file_load(TEST_DIR / "render" / "nested.anm2")); - Reference animationLayer{0, LAYER, 1, 0}; - Reference spritesheetLayer{1, LAYER, 2, 0}; + Reference animationLayer = {0, LAYER, 1, 0}; + Reference spritesheetLayer = {1, LAYER, 2, 0}; REQUIRE(model.frame_get(spritesheetLayer)); frames_change_apply(model, {.references = {animationLayer, spritesheetLayer}}, {.blur = 8.0f, .childAnimation = "Spin", .childMode = ChildMode::ONCE, .childStart = 3}, @@ -489,7 +489,7 @@ TEST_CASE("content_remove takes what refers to an item with it") { content_remove(model, type, ids, spritesheetId, library_get, path_keep); }; auto tracks_count = [](const Model& model, int layerId) { - int count{}; + int count = 0; for (auto [index, animation] : model.animations_get()) tracks_each(animation->layers, [&](const Track& track, auto*) { count += track.id == layerId; }); return count; diff --git a/tests/render/render.cpp b/tests/render/render.cpp index b38026d..9ab3982 100644 --- a/tests/render/render.cpp +++ b/tests/render/render.cpp @@ -36,7 +36,7 @@ static void golden_image_check(const std::string& name) Image golden(goldenPath); REQUIRE(golden.is_valid()); REQUIRE(actual.size == golden.size); - int mismatches{}; + int mismatches = 0; for (std::size_t i = 0; i < actual.pixels.size(); ++i) mismatches += std::abs((int)actual.pixels[i] - (int)golden.pixels[i]) > CHANNEL_TOLERANCE; CHECK((double)mismatches / (double)actual.pixels.size() <= MISMATCH_RATIO_MAX); @@ -44,11 +44,11 @@ static void golden_image_check(const std::string& name) struct RenderFixture { - HeadlessGL gl{}; - std::optional document{}; - std::optional shader{}; - std::optional canvas{}; - const Animation* animation{}; + HeadlessGL gl = {}; + std::optional document; + std::optional shader; + std::optional canvas; + const Animation* animation = nullptr; glm::vec4 bounds{}; explicit RenderFixture(const char* file) @@ -255,7 +255,7 @@ TEST_CASE("a Rebirth save flattens animation layers for the game") // The game's copy draws what the editor does: skew, blur and a skewed root baked into a spritesheet beside the save. TEST_CASE("the game's copy bakes skew and blur into a spritesheet that draws the same") { - HeadlessGL gl{}; + HeadlessGL gl = {}; if (!gl.is_valid()) return; auto directory = std::filesystem::temp_directory_path() / "anm2ed_bake"; std::filesystem::remove_all(directory); @@ -278,7 +278,7 @@ TEST_CASE("the game's copy bakes skew and blur into a spritesheet that draws the REQUIRE(document.is_valid()); REQUIRE(document.save(directory / "saved.anm2")); CHECK(std::filesystem::exists(directory / "saved.baked.png")); - std::string saved{}; + std::string saved; { std::ifstream file(directory / "saved.anm2"); saved.assign(std::istreambuf_iterator(file), {}); @@ -310,7 +310,7 @@ TEST_CASE("the game's copy bakes skew and blur into a spritesheet that draws the 1.0f, glm::vec4(0.0f), true); REQUIRE(actual.size() == expected.size()); CHECK(std::ranges::any_of(expected, [](uint8_t channel) { return channel != 0; })); - int mismatches{}; + int mismatches = 0; for (std::size_t i = 0; i < actual.size(); ++i) mismatches += std::abs((int)actual[i] - (int)expected[i]) > CHANNEL_TOLERANCE; CHECK((double)mismatches / (double)actual.size() <= MISMATCH_RATIO_MAX); diff --git a/tests/roundtrip.cpp b/tests/roundtrip.cpp index 0c83284..85dd834 100644 --- a/tests/roundtrip.cpp +++ b/tests/roundtrip.cpp @@ -4,10 +4,10 @@ TEST_CASE("fixtures match goldens") { auto fixtures = fixtures_get(); REQUIRE(!fixtures.empty()); - for (const auto& fixture : fixtures) + for (auto& fixture : fixtures) { auto anm2 = model_load(file_load(fixture)); - for (const auto& [name, text] : variants_get(anm2)) + for (auto& [name, text] : variants_get(anm2)) golden_check(GOLDEN_DIR / std::format("{}.{}.xml", fixture.stem().string(), name), text); } } diff --git a/tests/selection.cpp b/tests/selection.cpp index 43b1477..75cc404 100644 --- a/tests/selection.cpp +++ b/tests/selection.cpp @@ -16,17 +16,17 @@ void selection_edit(Model& anm2, Selection& selection, auto&& edit) TEST_CASE("uids are unique and non-zero after load") { - for (const auto& fixture : fixtures_get()) + for (auto& fixture : fixtures_get()) { auto anm2 = model_load(file_load(fixture)); - std::set uids{}; - bool isUnique{true}; + std::set uids; + bool isUnique = true; for (auto [index, animation] : anm2.animations_get()) animation_tracks_each(*animation, [&](const Track& track) { isUnique &= uids.insert(track.uid).second; - for (const auto& frame : track.frames) + for (auto& frame : track.frames) isUnique &= uids.insert(frame.uid).second; }); INFO("fixture: ", fixture.filename().string()); @@ -37,7 +37,7 @@ TEST_CASE("uids are unique and non-zero after load") TEST_CASE("selected frames and focus follow inserts and moves") { auto anm2 = fixture_load_with_uids("02_items.anm2"); - Selection selection{}; + Selection selection = {}; selection_references_set(selection, anm2, SelectionKind::FRAMES, {{0, LAYER, 0, 1}, {0, LAYER, 1, 0}}); selection_focus_set(selection, anm2, {0, LAYER, 0, 1}); @@ -53,7 +53,7 @@ TEST_CASE("selected frames and focus follow inserts and moves") TEST_CASE("a removed focus falls back to its nearest survivor") { auto anm2 = fixture_load_with_uids("02_items.anm2"); - Selection selection{}; + Selection selection = {}; selection_focus_set(selection, anm2, {0, LAYER, 0, 1}); selection_references_set(selection, anm2, SelectionKind::FRAMES, {{0, LAYER, 0, 1}}); @@ -72,11 +72,11 @@ TEST_CASE("a removed focus falls back to its nearest survivor") TEST_CASE("track and group selection follow regrouping") { auto anm2 = fixture_load_with_uids("03a_groups_nested.anm2"); - const TrackGroup* group{}; + const TrackGroup* group = nullptr; groups_each(anm2.animation_get(0)->layers, [&](const TrackGroup& candidate) { group = &candidate; }); REQUIRE(group); auto groupId = group->id; - Selection selection{}; + Selection selection = {}; selection_references_set(selection, anm2, SelectionKind::TRACKS, {{0, LAYER, 0, -1, LAYER, groupId}}); selection_references_set(selection, anm2, SelectionKind::GROUPS, {{0, LAYER, groupId}}); @@ -91,7 +91,7 @@ TEST_CASE("track and group selection follow regrouping") TEST_CASE("content selection follows items, and regions follow the focused spritesheet") { auto anm2 = fixture_load_with_uids("05_regions.anm2"); - Selection selection{}; + Selection selection = {}; auto& regions = item_get(anm2.content.spritesheets, 0)->regions; REQUIRE(regions.size() > 1); auto regionId = regions[1].id; diff --git a/tests/undo.cpp b/tests/undo.cpp index 5336970..14381c8 100644 --- a/tests/undo.cpp +++ b/tests/undo.cpp @@ -12,7 +12,7 @@ constexpr int UNDO_LIMIT = 1000; static std::vector references_all_get(const Model& anm2, bool isFrames) { UidIndex index(anm2); - std::vector result{}; + std::vector result; auto add = [&](std::uint64_t uid) { auto reference = index.reference_get(uid); @@ -24,7 +24,7 @@ static std::vector references_all_get(const Model& anm2, bool isFrame [&](const Track& track) { add(track.uid); - for (const auto& frame : track.frames) + for (auto& frame : track.frames) add(frame.uid); }); return result; @@ -81,7 +81,7 @@ TEST_CASE("undo and redo restore every state of a random edit walk") {"02_items.anm2", "03a_groups_nested.anm2", "04_group_root_transform.anm2", "07_special_interpolation.anm2"}) { INFO("fixture: ", name); - Snapshots snapshots{}; + Snapshots snapshots = {}; snapshots.current.model = model_load(file_load(CORPUS_DIR / name)); std::mt19937 random(WALK_SEED); @@ -113,7 +113,7 @@ TEST_CASE("undo and redo restore every state of a random edit walk") TEST_CASE("selection follows its frame through an edit and its undo") { - Snapshots snapshots{}; + Snapshots snapshots = {}; auto& current = snapshots.current; current.model = model_load(file_load(CORPUS_DIR / "02_items.anm2")); selection_focus_set(current.selection, current.model, {0, LAYER, 0, 1});