├── .gitattributes ├── .github └── workflows │ └── cmake.yml ├── CMakeLists.txt ├── COPYING ├── Doxyfile ├── README.md ├── cmake ├── Findstormlib.cmake ├── GenerateRevision.cmake ├── add_compiler_flag_if_supported.cmake ├── deps │ ├── patch_dascript.cmake │ └── patch_fastnoise2.cmake ├── linux_postfind.cmake ├── revision.h.in └── win32_postfind.cmake ├── etc ├── random_changes_for_mop.diff ├── some_changes_for_cataclysm.diff ├── todo_1.4.md └── uid_fix_concept.md ├── include ├── utf8.h └── win │ ├── StackWalker.cpp │ └── StackWalker.h ├── media ├── noggit.icns ├── noggit.ico ├── noggit.png ├── noggit_icon.png └── res.rc ├── resources ├── fa-solid-900.ttf ├── noggit_font.ttf └── resources.qrc ├── scripts ├── clean.lua ├── docs │ ├── README.md │ └── api │ │ ├── classes │ │ ├── chunk.md │ │ ├── image.md │ │ ├── model.md │ │ ├── noisemap.md │ │ ├── procedures_class.md │ │ ├── random.md │ │ ├── script_brush.md │ │ ├── script_brush_event.md │ │ ├── selection.md │ │ ├── tag.md │ │ ├── tex.md │ │ ├── vector_3d.md │ │ └── vert.md │ │ └── modules.md ├── global.d.ts ├── height_noise.lua ├── image_brush.lua ├── prop_placer.lua ├── texture_brush.lua ├── texture_printer.lua └── tsconfig.json ├── sql └── Noggit.sql ├── src ├── external │ ├── qt-color-widgets.repo │ └── qt-color-widgets │ │ ├── CMakeLists.txt │ │ ├── COPYING │ │ ├── qt-color-widgets │ │ ├── abstract_widget_list.hpp │ │ ├── bound_color_selector.hpp │ │ ├── color_2d_slider.hpp │ │ ├── color_delegate.hpp │ │ ├── color_dialog.hpp │ │ ├── color_line_edit.hpp │ │ ├── color_list_widget.hpp │ │ ├── color_names.hpp │ │ ├── color_palette.hpp │ │ ├── color_palette_model.hpp │ │ ├── color_palette_widget.hpp │ │ ├── color_preview.hpp │ │ ├── color_selector.hpp │ │ ├── color_wheel.hpp │ │ ├── gradient_slider.hpp │ │ ├── hue_slider.hpp │ │ └── swatch.hpp │ │ └── src │ │ ├── abstract_widget_list.cpp │ │ ├── alphaback.png │ │ ├── bound_color_selector.cpp │ │ ├── color_2d_slider.cpp │ │ ├── color_delegate.cpp │ │ ├── color_dialog.cpp │ │ ├── color_dialog.ui │ │ ├── color_line_edit.cpp │ │ ├── color_list_widget.cpp │ │ ├── color_names.cpp │ │ ├── color_palette.cpp │ │ ├── color_palette_model.cpp │ │ ├── color_palette_widget.cpp │ │ ├── color_palette_widget.ui │ │ ├── color_preview.cpp │ │ ├── color_selector.cpp │ │ ├── color_utils.cpp │ │ ├── color_utils.hpp │ │ ├── color_wheel.cpp │ │ ├── color_widgets.qrc │ │ ├── gradient_slider.cpp │ │ ├── hue_slider.cpp │ │ └── swatch.cpp ├── glsl │ ├── cursor_frag.glsl │ ├── cursor_vert.glsl │ ├── gizmo_frag.glsl │ ├── gizmo_vert.glsl │ ├── horizon_frag.glsl │ ├── horizon_vert.glsl │ ├── liquid_frag.glsl │ ├── liquid_vert.glsl │ ├── m2_box_frag.glsl │ ├── m2_box_vert.glsl │ ├── m2_depth_frag.glsl │ ├── m2_depth_vert.glsl │ ├── m2_frag.glsl │ ├── m2_vert.glsl │ ├── mfbo_frag.glsl │ ├── mfbo_vert.glsl │ ├── particle_frag.glsl │ ├── particle_vert.glsl │ ├── ribbon_frag.glsl │ ├── ribbon_vert.glsl │ ├── shadow_frag.glsl │ ├── shadow_vert.glsl │ ├── terrain_frag.glsl │ ├── terrain_vert.glsl │ ├── wmo_depth_frag.glsl │ ├── wmo_depth_vert.glsl │ ├── wmo_frag.glsl │ └── wmo_vert.glsl ├── math │ ├── bounding_box.cpp │ ├── bounding_box.hpp │ ├── constants.hpp │ ├── frustum.cpp │ ├── frustum.hpp │ ├── interpolation.hpp │ ├── matrix_4x4.cpp │ ├── matrix_4x4.hpp │ ├── projection.hpp │ ├── quaternion.hpp │ ├── ray.cpp │ ├── ray.hpp │ ├── trig.hpp │ ├── vector_2d.cpp │ ├── vector_2d.hpp │ ├── vector_3d.hpp │ └── vector_4d.hpp ├── mysql │ ├── mysql.cpp │ └── mysql.h ├── noggit │ ├── Animated.h │ ├── AsyncLoader.cpp │ ├── AsyncLoader.h │ ├── AsyncObject.h │ ├── Brush.cpp │ ├── Brush.h │ ├── DBC.cpp │ ├── DBC.h │ ├── DBCFile.cpp │ ├── DBCFile.h │ ├── Log.cpp │ ├── Log.h │ ├── MPQ.cpp │ ├── MPQ.h │ ├── MapChunk.cpp │ ├── MapChunk.h │ ├── MapHeaders.h │ ├── MapTile.cpp │ ├── MapTile.h │ ├── MapView.cpp │ ├── MapView.h │ ├── Misc.cpp │ ├── Misc.h │ ├── Model.cpp │ ├── Model.h │ ├── ModelHeaders.h │ ├── ModelInstance.cpp │ ├── ModelInstance.h │ ├── ModelManager.cpp │ ├── ModelManager.h │ ├── Particle.cpp │ ├── Particle.h │ ├── Selection.h │ ├── Sky.cpp │ ├── Sky.h │ ├── TextureManager.cpp │ ├── TextureManager.h │ ├── WMO.cpp │ ├── WMO.h │ ├── WMOInstance.cpp │ ├── WMOInstance.h │ ├── World.cpp │ ├── World.h │ ├── alphamap.cpp │ ├── alphamap.hpp │ ├── application.cpp │ ├── bookmarks.cpp │ ├── bookmarks.hpp │ ├── bool_toggle_property.hpp │ ├── camera.cpp │ ├── camera.hpp │ ├── chunk_mover.cpp │ ├── chunk_mover.hpp │ ├── cursor_render.cpp │ ├── cursor_render.hpp │ ├── errorHandling.h │ ├── error_handling.cpp │ ├── float_property.hpp │ ├── gizmo.cpp │ ├── gizmo.hpp │ ├── liquid_chunk.cpp │ ├── liquid_chunk.hpp │ ├── liquid_layer.cpp │ ├── liquid_layer.hpp │ ├── liquid_render.cpp │ ├── liquid_render.hpp │ ├── liquid_tile.cpp │ ├── liquid_tile.hpp │ ├── map_chunk_headers.hpp │ ├── map_enums.hpp │ ├── map_horizon.cpp │ ├── map_horizon.h │ ├── map_index.cpp │ ├── map_index.hpp │ ├── moveable_object.cpp │ ├── moveable_object.hpp │ ├── moveable_object_group.cpp │ ├── moveable_object_group.hpp │ ├── multimap_with_normalized_key.hpp │ ├── scripting │ │ ├── script_brush.cpp │ │ ├── script_brush.hpp │ │ ├── script_chunk.cpp │ │ ├── script_chunk.hpp │ │ ├── script_context.cpp │ │ ├── script_context.hpp │ │ ├── script_exception.cpp │ │ ├── script_exception.hpp │ │ ├── script_filesystem.cpp │ │ ├── script_filesystem.hpp │ │ ├── script_global.cpp │ │ ├── script_global.hpp │ │ ├── script_image.cpp │ │ ├── script_image.hpp │ │ ├── script_math.cpp │ │ ├── script_math.hpp │ │ ├── script_model.cpp │ │ ├── script_model.hpp │ │ ├── script_noise.cpp │ │ ├── script_noise.hpp │ │ ├── script_object.cpp │ │ ├── script_object.hpp │ │ ├── script_procedures.cpp │ │ ├── script_procedures.hpp │ │ ├── script_profiles.cpp │ │ ├── script_profiles.hpp │ │ ├── script_random.cpp │ │ ├── script_random.hpp │ │ ├── script_registry.ipp │ │ ├── script_selection.cpp │ │ ├── script_selection.hpp │ │ ├── script_settings.cpp │ │ ├── script_settings.hpp │ │ ├── script_standard_brush.cpp │ │ ├── script_standard_brush.hpp │ │ ├── script_tex.cpp │ │ ├── script_tex.hpp │ │ ├── script_vert-script_texture_index.ipp │ │ ├── script_vert.cpp │ │ ├── script_vert.hpp │ │ ├── scripting_tool.cpp │ │ └── scripting_tool.hpp │ ├── settings.hpp │ ├── texture_array_handler.cpp │ ├── texture_array_handler.hpp │ ├── texture_set.cpp │ ├── texture_set.hpp │ ├── tile_index.hpp │ ├── tileset_array_handler.cpp │ ├── tileset_array_handler.hpp │ ├── tool_enums.hpp │ ├── ui │ │ ├── About.cpp │ │ ├── About.h │ │ ├── CurrentTexture.cpp │ │ ├── CurrentTexture.h │ │ ├── CursorSwitcher.cpp │ │ ├── CursorSwitcher.h │ │ ├── DetailInfos.cpp │ │ ├── DetailInfos.h │ │ ├── FlattenTool.cpp │ │ ├── FlattenTool.hpp │ │ ├── Help.cpp │ │ ├── Help.h │ │ ├── HelperModels.cpp │ │ ├── HelperModels.h │ │ ├── ModelImport.cpp │ │ ├── ModelImport.h │ │ ├── ObjectEditor.cpp │ │ ├── ObjectEditor.h │ │ ├── RotationEditor.cpp │ │ ├── RotationEditor.h │ │ ├── SettingsPanel.cpp │ │ ├── SettingsPanel.h │ │ ├── TextureList.cpp │ │ ├── TextureList.hpp │ │ ├── TexturePicker.cpp │ │ ├── TexturePicker.h │ │ ├── TexturingGUI.cpp │ │ ├── TexturingGUI.h │ │ ├── Toolbar.cpp │ │ ├── Toolbar.h │ │ ├── Water.cpp │ │ ├── Water.h │ │ ├── ZoneIDBrowser.cpp │ │ ├── ZoneIDBrowser.h │ │ ├── asset_browser.cpp │ │ ├── asset_browser.hpp │ │ ├── checkbox.hpp │ │ ├── chunk_mover.cpp │ │ ├── chunk_mover.hpp │ │ ├── clearing_tool.cpp │ │ ├── clearing_tool.hpp │ │ ├── clickable_label.cpp │ │ ├── clickable_label.hpp │ │ ├── collapsible_widget.cpp │ │ ├── collapsible_widget.hpp │ │ ├── double_spinbox.hpp │ │ ├── font_awesome.cpp │ │ ├── font_awesome.hpp │ │ ├── font_noggit.cpp │ │ ├── font_noggit.hpp │ │ ├── main_window.cpp │ │ ├── main_window.hpp │ │ ├── minimap_widget.cpp │ │ ├── minimap_widget.hpp │ │ ├── noggit_tool.cpp │ │ ├── noggit_tool.hpp │ │ ├── pushbutton.hpp │ │ ├── shader_tool.cpp │ │ ├── shader_tool.hpp │ │ ├── shadow_editor.cpp │ │ ├── shadow_editor.hpp │ │ ├── slider_spinbox.cpp │ │ ├── slider_spinbox.hpp │ │ ├── terrain_tool.cpp │ │ ├── terrain_tool.hpp │ │ ├── texture_palette_small.cpp │ │ ├── texture_palette_small.hpp │ │ ├── texture_swapper.cpp │ │ ├── texture_swapper.hpp │ │ ├── texturing_tool.cpp │ │ ├── texturing_tool.hpp │ │ ├── uid_fix_window.cpp │ │ ├── uid_fix_window.hpp │ │ └── widget.hpp │ ├── uid_storage.cpp │ ├── uid_storage.hpp │ ├── unsigned_int_property.hpp │ ├── wmo_headers.hpp │ ├── wmo_liquid.cpp │ ├── wmo_liquid.hpp │ ├── world_model_instances_storage.cpp │ ├── world_model_instances_storage.hpp │ ├── world_tile_update_queue.cpp │ └── world_tile_update_queue.hpp ├── opengl │ ├── arb_bindless_texture_ext.hpp │ ├── context.cpp │ ├── context.hpp │ ├── delayed.hpp │ ├── primitives.cpp │ ├── primitives.hpp │ ├── scoped.hpp │ ├── scoped.ipp │ ├── shader.cpp │ ├── shader.fwd.hpp │ ├── shader.hpp │ ├── texture.cpp │ ├── texture.hpp │ └── types.hpp └── util │ ├── exception_to_string.cpp │ ├── exception_to_string.hpp │ ├── qt │ └── overload.hpp │ ├── sExtendableArray.cpp │ ├── sExtendableArray.hpp │ └── sExtendableArray.ipp └── test └── math ├── matrix_4x4.cpp ├── trig.cpp └── vector_2d.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Sources 2 | *.c text diff=cpp eol=lf 3 | *.h text diff=cpp eol=lf 4 | *.cpp text diff=cpp eol=lf 5 | *.hpp text diff=cpp eol=lf 6 | *.ipp text diff=cpp eol=lf 7 | -------------------------------------------------------------------------------- /cmake/Findstormlib.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | # adds target stormlib::stormlib 4 | # hopes that users installed stormlib properly so that the CONFIG file gets used instead. 5 | 6 | find_path (STORM_INCLUDE_DIR StormLib.h StormPort.h) 7 | 8 | find_library (_storm_debug_lib NAMES StormLibDAD StormLibDAS StormLibDUD StormLibDUS) 9 | find_library (_storm_release_lib NAMES StormLibRAD StormLibRAS StormLibRUD StormLibRUS) 10 | find_library (_storm_any_lib NAMES storm stormlib StormLib) 11 | 12 | set (STORM_LIBRARIES) 13 | if (_storm_debug_lib AND _storm_release_lib) 14 | list (APPEND STORM_LIBRARIES debug ${_storm_debug_lib} optimized ${_storm_release_lib}) 15 | else() 16 | list (APPEND STORM_LIBRARIES ${_storm_any_lib}) 17 | endif() 18 | 19 | include (FindPackageHandleStandardArgs) 20 | find_package_handle_standard_args (stormlib DEFAULT_MSG STORM_LIBRARIES STORM_INCLUDE_DIR) 21 | 22 | mark_as_advanced (STORM_INCLUDE_DIR _storm_debug_lib _storm_release_lib _storm_any_lib STORM_LIBRARIES) 23 | 24 | add_library (StormLib INTERFACE) 25 | target_link_libraries (StormLib INTERFACE ${STORM_LIBRARIES}) 26 | set_property (TARGET StormLib APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${STORM_INCLUDE_DIR}) 27 | set_property (TARGET StormLib APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${STORM_INCLUDE_DIR}) 28 | 29 | 30 | if (NOT WIN32) 31 | find_package (ZLIB REQUIRED) 32 | find_package (BZip2 REQUIRED) 33 | target_link_libraries (StormLib INTERFACE ZLIB::ZLIB BZip2::BZip2) 34 | endif() 35 | 36 | target_compile_definitions (StormLib INTERFACE STORMLIB_NO_AUTO_LINK) 37 | 38 | add_library (stormlib::stormlib ALIAS StormLib) 39 | -------------------------------------------------------------------------------- /cmake/GenerateRevision.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | # assumes working directory in git repo 4 | # assumes var _noggit_revision_template_file 5 | # assumes var _noggit_revision_output_file 6 | # assumes var _noggit_revision_state_file 7 | # assumes var GIT_EXECUTABLE 8 | # generates file "${_noggit_revision_state_file}" 9 | # generates file "${_noggit_revision_output_file}" 10 | 11 | 12 | macro (execute _output_var) # , command... 13 | execute_process (COMMAND ${ARGN} 14 | OUTPUT_VARIABLE ${_output_var} OUTPUT_STRIP_TRAILING_WHITESPACE 15 | RESULT_VARIABLE _result) 16 | if (NOT _result EQUAL 0) 17 | message (FATAL_ERROR "'${ARGN}' failed.") 18 | endif() 19 | endmacro() 20 | 21 | execute (_status "${GIT_EXECUTABLE}" "status" "--porcelain") 22 | set (_dirty_marker "+") 23 | if (_status STREQUAL "") 24 | set (_dirty_marker "") 25 | endif() 26 | 27 | # \todo If head is tagged, use tag. 28 | # \todo Add deploy script that adds tags so that we have sane 29 | # revisions again, at all times. 30 | execute (_revision "${GIT_EXECUTABLE}" "rev-parse" "--short" "HEAD") 31 | execute (_commit_count "${GIT_EXECUTABLE}" "rev-list" "--count" "--all") 32 | 33 | file (READ "${_noggit_revision_template_file}" _template_blob) 34 | file (READ "${CMAKE_CURRENT_LIST_FILE}" _self_blob) 35 | string (SHA256 _state_hash "${_dirty_marker}${_revision}${_template_blob}${_self_blob}") 36 | 37 | if (EXISTS ${_noggit_revision_output_file}) 38 | file (READ "${_noggit_revision_state_file}" _old_state_hash) 39 | if (_state_hash STREQUAL _old_state_hash) 40 | return() 41 | endif() 42 | endif() 43 | 44 | file (WRITE "${_noggit_revision_state_file}" "${_state_hash}") 45 | 46 | message("Commit count: ${_commit_count}") 47 | 48 | set (NOGGIT_COMMIT_COUNT "${_commit_count}${_dirty_marker}") 49 | set (NOGGIT_GIT_VERSION_STRING "${_revision}") 50 | configure_file ("${_noggit_revision_template_file}" 51 | "${_noggit_revision_output_file}" @ONLY) 52 | -------------------------------------------------------------------------------- /cmake/deps/patch_dascript.cmake: -------------------------------------------------------------------------------- 1 | # please don't spam root source directory with test things 2 | file (READ "CMakeLists.txt" cmakelists_content) 3 | string (REPLACE "UNITIZE_BUILD(\"examples/test/unit_tests\" TEST_GENERATED_SRC)" "# noggit patch: examples removed" cmakelists_content "${cmakelists_content}") 4 | file (WRITE "CMakeLists.txt" "${cmakelists_content}") 5 | -------------------------------------------------------------------------------- /cmake/deps/patch_fastnoise2.cmake: -------------------------------------------------------------------------------- 1 | # set includes etc relative to fastnoise2 root directory, not noggit's 2 | file (GLOB_RECURSE cmakelists LIST_DIRECTORIES FALSE "CMakeLists.txt") 3 | foreach (cmakelist ${cmakelists}) 4 | file (READ "${cmakelist}" cmakelists_content) 5 | string (REPLACE "CMAKE_SOURCE_DIR" "PROJECT_SOURCE_DIR" cmakelists_content "${cmakelists_content}") 6 | file (WRITE "${cmakelist}" "${cmakelists_content}") 7 | endforeach() 8 | -------------------------------------------------------------------------------- /cmake/linux_postfind.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | # warnings? 4 | if( NOGGIT_ALL_WARNINGS ) 5 | MESSAGE( STATUS "Spilling out mass warnings." ) 6 | set(noggit_warning_flags "${noggit_warning_flags} -W -Wall -Wshadow") 7 | endif( NOGGIT_ALL_WARNINGS ) 8 | -------------------------------------------------------------------------------- /cmake/revision.h.in: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #define STRPRODUCTVER "3.@NOGGIT_COMMIT_COUNT@ [@NOGGIT_GIT_VERSION_STRING@]" 6 | -------------------------------------------------------------------------------- /cmake/win32_postfind.cmake: -------------------------------------------------------------------------------- 1 | # This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | LINK_DIRECTORIES(${STORMLIB_LIBRARY_DIR}) 4 | 5 | #maybe in wrong order now 6 | SET(IncludeDirectories ${IncludeDirectories} "${CMAKE_SOURCE_DIR}/include/win/") 7 | SET(SourceFiles ${SourceFiles} "${CMAKE_SOURCE_DIR}/include/win/StackWalker.cpp") 8 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /vmg /D NOMINMAX") 9 | 10 | # warnings? 11 | if( NOGGIT_ALL_WARNINGS ) 12 | MESSAGE( STATUS "Spilling out mass warnings." ) 13 | set(noggit_warning_flags "${noggit_warning_flags} /W4 /Wall /Wp64") 14 | endif( NOGGIT_ALL_WARNINGS ) 15 | 16 | # mark 32 bit executables large address aware so they can use > 2GB address space 17 | if(CMAKE_SIZEOF_VOID_P MATCHES 4) 18 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE") 19 | message(STATUS "- MSVC: Enabled large address awareness!") 20 | endif() 21 | 22 | set(ResFiles media/res.rc) 23 | -------------------------------------------------------------------------------- /etc/uid_fix_concept.md: -------------------------------------------------------------------------------- 1 | # MapIndex::fixUIDs() concept idea (Adspartan) 2 | 3 | ## Step 1: 4 | * read every tile 5 | * for each tile read all the modf and mddf entries 6 | * discard the entries not placed on the current tile (eg entry.pos isn't inside the tile) 7 | * discard duplicates 8 | * read the filenames 9 | * create the model/wmo instances and add them to a list 10 | 11 | -> [tile -> [(m*df, filename)]] where (m*df, filename) is unique by transformation, only entries with inside (tile, .pos) are stored 12 | 13 | ## Step 2: 14 | * create 2 lists for each tile, one for the wmo and one for the m2 15 | * assign a new uid for the instances (starting from 0) 16 | * add every model/wmo instances to the lists of every tiles they are on 17 | 18 | -> [[tile] -> [(uid, m*df, filename)] where uid is 0..n, all entries where intersect (tile, .extends) are stored 19 | 20 | ## Step 3: 21 | * load each tile without the models/wmos 22 | * save the tile with the model/wmo instances from step 2 23 | 24 | ## Step 4: 25 | * save the highest uid on the disc to not have to repeat the process ever again 26 | 27 | ## Claim 28 | * Every entity has a globally unique id in 2I, 1O 29 | * uniqueness of newly placed objects is guaranteed by storing highest uid on disk 30 | 31 | ## Shortcomings 32 | * does not work with parallel work by multiple editors on same map, or 33 | requires a central fix-pass every so often, which is undesirable 34 | -> requires one pass _after a fuckup_ which still can exist 35 | -> valid and good for single-person work 36 | -------------------------------------------------------------------------------- /include/win/StackWalker.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/include/win/StackWalker.cpp -------------------------------------------------------------------------------- /media/noggit.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/media/noggit.icns -------------------------------------------------------------------------------- /media/noggit.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/media/noggit.ico -------------------------------------------------------------------------------- /media/noggit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/media/noggit.png -------------------------------------------------------------------------------- /media/noggit_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/media/noggit_icon.png -------------------------------------------------------------------------------- /media/res.rc: -------------------------------------------------------------------------------- 1 | IDI_APP ICON "noggit.ico" -------------------------------------------------------------------------------- /resources/fa-solid-900.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/resources/fa-solid-900.ttf -------------------------------------------------------------------------------- /resources/noggit_font.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/resources/noggit_font.ttf -------------------------------------------------------------------------------- /resources/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | fa-solid-900.ttf 5 | 6 | 7 | noggit_font.ttf 8 | 9 | 10 | ../media/noggit_icon.png 11 | 12 | 13 | ../src/glsl/m2_vert.glsl 14 | ../src/glsl/m2_frag.glsl 15 | ../src/glsl/m2_box_vert.glsl 16 | ../src/glsl/m2_box_frag.glsl 17 | ../src/glsl/particle_vert.glsl 18 | ../src/glsl/particle_frag.glsl 19 | ../src/glsl/ribbon_vert.glsl 20 | ../src/glsl/ribbon_frag.glsl 21 | ../src/glsl/terrain_vert.glsl 22 | ../src/glsl/terrain_frag.glsl 23 | ../src/glsl/wmo_vert.glsl 24 | ../src/glsl/wmo_frag.glsl 25 | ../src/glsl/liquid_vert.glsl 26 | ../src/glsl/liquid_frag.glsl 27 | ../src/glsl/mfbo_vert.glsl 28 | ../src/glsl/mfbo_frag.glsl 29 | ../src/glsl/cursor_vert.glsl 30 | ../src/glsl/cursor_frag.glsl 31 | ../src/glsl/horizon_vert.glsl 32 | ../src/glsl/horizon_frag.glsl 33 | ../src/glsl/m2_depth_vert.glsl 34 | ../src/glsl/m2_depth_frag.glsl 35 | ../src/glsl/wmo_depth_vert.glsl 36 | ../src/glsl/wmo_depth_frag.glsl 37 | ../src/glsl/shadow_vert.glsl 38 | ../src/glsl/shadow_frag.glsl 39 | ../src/glsl/gizmo_vert.glsl 40 | ../src/glsl/gizmo_frag.glsl 41 | 42 | 43 | -------------------------------------------------------------------------------- /scripts/clean.lua: -------------------------------------------------------------------------------- 1 | -- This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | local clean = brush("Clean"); 3 | 4 | local def_height = clean:add_real_tag("Default height",-1000,1000,0) 5 | 6 | local tex_layer_1 = clean:add_string_tag("Texture layer 1","") 7 | local prop_layer_1 = clean:add_int_tag("Effect layer 1",-2,9999999999,-2) 8 | local tex_layer_2 = clean:add_string_tag("Texture layer 2","") 9 | local prop_layer_2 = clean:add_int_tag("Effect layer 2",-2,9999999999,-2) 10 | local tex_layer_3 = clean:add_string_tag("Texture layer 3","") 11 | local prop_layer_3 = clean:add_int_tag("Effect layer 3",-2,9999999999,-2) 12 | local tex_layer_4 = clean:add_string_tag("Texture layer 4","") 13 | local prop_layer_4 = clean:add_int_tag("Effect layer 4",-2,9999999999,-2) 14 | 15 | function clean:on_left_hold(evt) 16 | local sel = select_origin(evt:pos(), evt:outer_radius(), evt:outer_radius()) 17 | if(holding_shift()) then 18 | for i,chunk in pairs(sel:chunks()) do 19 | chunk:clear_textures() 20 | chunk:clear_colors() 21 | if tex_layer_1:get() ~= "" then chunk:add_texture(tex_layer_1:get(),prop_layer_1:get()) end 22 | if tex_layer_2:get() ~= "" then chunk:add_texture(tex_layer_2:get(),prop_layer_2:get()) end 23 | if tex_layer_3:get() ~= "" then chunk:add_texture(tex_layer_3:get(),prop_layer_3:get()) end 24 | if tex_layer_4:get() ~= "" then chunk:add_texture(tex_layer_4:get(),prop_layer_4:get()) end 25 | chunk:apply_all() 26 | end 27 | end 28 | 29 | if(holding_ctrl()) then 30 | for i,vert in pairs(sel:verts()) do 31 | vert:set_height(def_height:get()) 32 | end 33 | end 34 | 35 | if(holding_alt()) then 36 | for i,model in pairs(sel:models()) do 37 | model:remove() 38 | end 39 | end 40 | 41 | sel:apply() 42 | end -------------------------------------------------------------------------------- /scripts/docs/api/classes/noisemap.md: -------------------------------------------------------------------------------- 1 | # Class: noisemap 2 | 3 | Represents a map of floats values, typically use with a 4 | noise generator. 5 | 6 | ## Table of contents 7 | 8 | ### Constructors 9 | 10 | - [constructor](noisemap.md#constructor) 11 | 12 | ### Methods 13 | 14 | - [get](noisemap.md#get) 15 | - [height](noisemap.md#height) 16 | - [is\_highest](noisemap.md#is_highest) 17 | - [set](noisemap.md#set) 18 | - [width](noisemap.md#width) 19 | 20 | ## Constructors 21 | 22 | ### constructor 23 | 24 | \+ **new noisemap**(): [*noisemap*](noisemap.md) 25 | 26 | **Returns:** [*noisemap*](noisemap.md) 27 | 28 | ## Methods 29 | 30 | ### get 31 | 32 | ▸ **get**(`pos`: [*vector\_3d*](vector_3d.md)): *number* 33 | 34 | Returns the float value at a specific 3d position. 35 | 36 | **`note`** The 'y' value of pos is ignored by this operation. 37 | 38 | #### Parameters: 39 | 40 | Name | Type | 41 | :------ | :------ | 42 | `pos` | [*vector\_3d*](vector_3d.md) | 43 | 44 | **Returns:** *number* 45 | 46 | ___ 47 | 48 | ### height 49 | 50 | ▸ **height**(): *number* 51 | 52 | **Returns:** *number* 53 | 54 | ___ 55 | 56 | ### is\_highest 57 | 58 | ▸ **is_highest**(`pos`: [*vector\_3d*](vector_3d.md), `check_radius`: *number*): *boolean* 59 | 60 | Returns true if the float value at a 3d position 61 | is the highest position within a given range. 62 | 63 | This is typically used for object placement. 64 | 65 | #### Parameters: 66 | 67 | Name | Type | 68 | :------ | :------ | 69 | `pos` | [*vector\_3d*](vector_3d.md) | 70 | `check_radius` | *number* | 71 | 72 | **Returns:** *boolean* 73 | 74 | ___ 75 | 76 | ### set 77 | 78 | ▸ **set**(`x`: *number*, `y`: *number*, `value`: *number*): *void* 79 | 80 | #### Parameters: 81 | 82 | Name | Type | 83 | :------ | :------ | 84 | `x` | *number* | 85 | `y` | *number* | 86 | `value` | *number* | 87 | 88 | **Returns:** *void* 89 | 90 | ___ 91 | 92 | ### width 93 | 94 | ▸ **width**(): *number* 95 | 96 | **Returns:** *number* 97 | -------------------------------------------------------------------------------- /scripts/docs/api/classes/procedures_class.md: -------------------------------------------------------------------------------- 1 | # Class: procedures\_class 2 | 3 | Contains some general-purpose procedures that don't fit anywhere else. 4 | 5 | Access these functions through the global singleton "procedures". 6 | 7 | ## Table of contents 8 | 9 | ### Constructors 10 | 11 | - [constructor](procedures_class.md#constructor) 12 | 13 | ### Methods 14 | 15 | - [paint\_texture](procedures_class.md#paint_texture) 16 | 17 | ## Constructors 18 | 19 | ### constructor 20 | 21 | \+ **new procedures_class**(): [*procedures\_class*](procedures_class.md) 22 | 23 | **Returns:** [*procedures\_class*](procedures_class.md) 24 | 25 | ## Methods 26 | 27 | ### paint\_texture 28 | 29 | ▸ **paint_texture**(`sel`: [*selection*](selection.md), `img`: [*image*](image.md), `layer`: *number*, `pressure`: *number*, `angle`: *number*): *any* 30 | 31 | #### Parameters: 32 | 33 | Name | Type | 34 | :------ | :------ | 35 | `sel` | [*selection*](selection.md) | 36 | `img` | [*image*](image.md) | 37 | `layer` | *number* | 38 | `pressure` | *number* | 39 | `angle` | *number* | 40 | 41 | **Returns:** *any* 42 | -------------------------------------------------------------------------------- /scripts/docs/api/classes/random.md: -------------------------------------------------------------------------------- 1 | # Class: random 2 | 3 | Represents a random generator and its state. 4 | 5 | ## Table of contents 6 | 7 | ### Constructors 8 | 9 | - [constructor](random.md#constructor) 10 | 11 | ### Methods 12 | 13 | - [integer](random.md#integer) 14 | - [real](random.md#real) 15 | 16 | ## Constructors 17 | 18 | ### constructor 19 | 20 | \+ **new random**(): [*random*](random.md) 21 | 22 | **Returns:** [*random*](random.md) 23 | 24 | ## Methods 25 | 26 | ### integer 27 | 28 | ▸ **integer**(`low`: *number*, `high`: *number*): *number* 29 | 30 | #### Parameters: 31 | 32 | Name | Type | 33 | :------ | :------ | 34 | `low` | *number* | 35 | `high` | *number* | 36 | 37 | **Returns:** *number* 38 | 39 | ___ 40 | 41 | ### real 42 | 43 | ▸ **real**(`low`: *number*, `high`: *number*): *number* 44 | 45 | #### Parameters: 46 | 47 | Name | Type | 48 | :------ | :------ | 49 | `low` | *number* | 50 | `high` | *number* | 51 | 52 | **Returns:** *number* 53 | -------------------------------------------------------------------------------- /scripts/docs/api/classes/script_brush_event.md: -------------------------------------------------------------------------------- 1 | # Class: script\_brush\_event 2 | 3 | Represents the event context passed to brush click events. 4 | 5 | ## Table of contents 6 | 7 | ### Constructors 8 | 9 | - [constructor](script_brush_event.md#constructor) 10 | 11 | ### Methods 12 | 13 | - [dt](script_brush_event.md#dt) 14 | - [inner\_radius](script_brush_event.md#inner_radius) 15 | - [outer\_radius](script_brush_event.md#outer_radius) 16 | - [pos](script_brush_event.md#pos) 17 | - [set\_inner\_radius](script_brush_event.md#set_inner_radius) 18 | - [set\_outer\_radius](script_brush_event.md#set_outer_radius) 19 | 20 | ## Constructors 21 | 22 | ### constructor 23 | 24 | \+ **new script_brush_event**(): [*script\_brush\_event*](script_brush_event.md) 25 | 26 | **Returns:** [*script\_brush\_event*](script_brush_event.md) 27 | 28 | ## Methods 29 | 30 | ### dt 31 | 32 | ▸ **dt**(): *number* 33 | 34 | Returns the delta-time since the last update frame 35 | 36 | **Returns:** *number* 37 | 38 | ___ 39 | 40 | ### inner\_radius 41 | 42 | ▸ **inner_radius**(): *number* 43 | 44 | Returns the current inner radius configured in the settings panel 45 | 46 | **Returns:** *number* 47 | 48 | ___ 49 | 50 | ### outer\_radius 51 | 52 | ▸ **outer_radius**(): *number* 53 | 54 | Returns the current outer radius configured in the settings panel 55 | 56 | **Returns:** *number* 57 | 58 | ___ 59 | 60 | ### pos 61 | 62 | ▸ **pos**(): [*vector\_3d*](vector_3d.md) 63 | 64 | Returns world position of this click event. 65 | i.e. the world position where the user clicked, held or released a mouse button 66 | 67 | **Returns:** [*vector\_3d*](vector_3d.md) 68 | 69 | ___ 70 | 71 | ### set\_inner\_radius 72 | 73 | ▸ **set_inner_radius**(`value`: *number*): *any* 74 | 75 | Sets the outer radius in the settings panel for this brush 76 | 77 | #### Parameters: 78 | 79 | Name | Type | Description | 80 | :------ | :------ | :------ | 81 | `value` | *number* | should be between 0-1 | 82 | 83 | **Returns:** *any* 84 | 85 | ___ 86 | 87 | ### set\_outer\_radius 88 | 89 | ▸ **set_outer_radius**(`value`: *number*): *any* 90 | 91 | Sets the outer radius in the settings panel for this brush 92 | 93 | #### Parameters: 94 | 95 | Name | Type | 96 | :------ | :------ | 97 | `value` | *number* | 98 | 99 | **Returns:** *any* 100 | -------------------------------------------------------------------------------- /scripts/docs/api/classes/tag.md: -------------------------------------------------------------------------------- 1 | # Class: tag 2 | 3 | Represents a settings tag that can be accessed at any time by a script. 4 | 5 | ## Type parameters 6 | 7 | Name | 8 | :------ | 9 | `T` | 10 | 11 | ## Table of contents 12 | 13 | ### Constructors 14 | 15 | - [constructor](tag.md#constructor) 16 | 17 | ### Methods 18 | 19 | - [get](tag.md#get) 20 | 21 | ## Constructors 22 | 23 | ### constructor 24 | 25 | \+ **new tag**(): [*tag*](tag.md) 26 | 27 | #### Type parameters: 28 | 29 | Name | 30 | :------ | 31 | `T` | 32 | 33 | **Returns:** [*tag*](tag.md) 34 | 35 | ## Methods 36 | 37 | ### get 38 | 39 | ▸ **get**(): T 40 | 41 | Returns the current value of this tag in the settings panel. 42 | 43 | **Returns:** T 44 | -------------------------------------------------------------------------------- /scripts/docs/api/classes/tex.md: -------------------------------------------------------------------------------- 1 | # Class: tex 2 | 3 | Represents a single texture unit in the worlds texture layers. 4 | 5 | A texture unit represents the smallest area where it's possible to 6 | affect textures alpha layers. This is much smaller than the areas made 7 | up by heightmap vertices. 8 | 9 | ## Table of contents 10 | 11 | ### Constructors 12 | 13 | - [constructor](tex.md#constructor) 14 | 15 | ### Methods 16 | 17 | - [get\_alpha](tex.md#get_alpha) 18 | - [get\_pos\_2d](tex.md#get_pos_2d) 19 | - [set\_alpha](tex.md#set_alpha) 20 | 21 | ## Constructors 22 | 23 | ### constructor 24 | 25 | \+ **new tex**(): [*tex*](tex.md) 26 | 27 | **Returns:** [*tex*](tex.md) 28 | 29 | ## Methods 30 | 31 | ### get\_alpha 32 | 33 | ▸ **get_alpha**(`index`: *number*): *number* 34 | 35 | #### Parameters: 36 | 37 | Name | Type | 38 | :------ | :------ | 39 | `index` | *number* | 40 | 41 | **Returns:** *number* 42 | 43 | ___ 44 | 45 | ### get\_pos\_2d 46 | 47 | ▸ **get_pos_2d**(): [*vector\_3d*](vector_3d.md) 48 | 49 | **Returns:** [*vector\_3d*](vector_3d.md) 50 | 51 | ___ 52 | 53 | ### set\_alpha 54 | 55 | ▸ **set_alpha**(`index`: *number*, `alpha`: *number*): *void* 56 | 57 | #### Parameters: 58 | 59 | Name | Type | 60 | :------ | :------ | 61 | `index` | *number* | 62 | `alpha` | *number* | 63 | 64 | **Returns:** *void* 65 | -------------------------------------------------------------------------------- /scripts/docs/api/classes/vector_3d.md: -------------------------------------------------------------------------------- 1 | # Class: vector\_3d 2 | 3 | Represents a 3-dimensional vector. 4 | Most functions do not use the 'y' (height) value at all 5 | 6 | ## Table of contents 7 | 8 | ### Constructors 9 | 10 | - [constructor](vector_3d.md#constructor) 11 | 12 | ### Properties 13 | 14 | - [x](vector_3d.md#x) 15 | - [y](vector_3d.md#y) 16 | - [z](vector_3d.md#z) 17 | 18 | ## Constructors 19 | 20 | ### constructor 21 | 22 | \+ **new vector_3d**(): [*vector\_3d*](vector_3d.md) 23 | 24 | **Returns:** [*vector\_3d*](vector_3d.md) 25 | 26 | ## Properties 27 | 28 | ### x 29 | 30 | • **x**: *number* 31 | 32 | ___ 33 | 34 | ### y 35 | 36 | • **y**: *number* 37 | 38 | ___ 39 | 40 | ### z 41 | 42 | • **z**: *number* 43 | -------------------------------------------------------------------------------- /scripts/height_noise.lua: -------------------------------------------------------------------------------- 1 | -- This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | local noise_brush = brush("Height Noise") 3 | 4 | local algo = noise_brush:add_string_tag("Algorithm","HgANAAUAAAAAAABAEAAAAAA/CAAAAACAPwAAAAA/AAAAAAABEwBI4RpAGwANAAMAAAAAAABACAAAAAAAPwAAAAAAAI/C9Tw=") 5 | local seed = noise_brush:add_string_tag("Seed","noggit") 6 | local frequency = noise_brush:add_real_tag("Frequency",0.0005,1.0,0.001,5) 7 | local amplitude = noise_brush:add_real_tag("Amplitude",1.0,1000.0,410.0,2) 8 | 9 | function noise_brush:on_left_hold(evt) 10 | local sel = select_origin( 11 | evt:pos(), 12 | evt:outer_radius(), 13 | evt:outer_radius() 14 | ) 15 | local map = sel:make_noise( 16 | frequency:get(), 17 | algo:get(), 18 | seed:get() 19 | ) 20 | for i,vert in pairs(sel:verts()) do 21 | local height = map:get( 22 | vert:get_pos() 23 | ) * amplitude:get() 24 | vert:set_height(height) 25 | end 26 | sel:apply() 27 | end -------------------------------------------------------------------------------- /scripts/image_brush.lua: -------------------------------------------------------------------------------- 1 | -- This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | local painter_brush = brush("Image Painter") 3 | local image_path = painter_brush:add_string_tag("Filename", "") 4 | 5 | function painter_brush:on_left_click(evt) 6 | local img = load_png( 7 | image_path:get() 8 | ) 9 | local origin = evt:pos() 10 | local width = img:width() 11 | local height = img:height() 12 | local half_width = width / 2 13 | local half_height = height / 2 14 | local sel = select_origin(origin, width, height) 15 | 16 | for i,vert in pairs(sel:verts()) do 17 | local angle = cam_yaw() - 90 18 | local pos = rotate_2d( 19 | vert:get_pos(), 20 | origin, 21 | angle 22 | ) 23 | local local_x = round((pos.x - origin.x) + half_width) 24 | local local_z = round((pos.z - origin.z) + half_height) 25 | 26 | if local_x >= 0 27 | and local_x < width 28 | and local_z >= 0 29 | and local_z < height 30 | and img:get_alpha(local_x,local_z)>0.5 then 31 | local red = img:get_red(local_x, local_z) 32 | local green = img:get_green(local_x, local_z) 33 | local blue = img:get_blue(local_x, local_z) 34 | vert:set_color(red, green, blue) 35 | end 36 | end 37 | sel:apply() 38 | end -------------------------------------------------------------------------------- /scripts/texture_brush.lua: -------------------------------------------------------------------------------- 1 | local texture_brush = brush("Texture Brush") 2 | texture_brush:add_description("Description:") 3 | texture_brush:add_description("- Uses a black / white texture to paint alpha layers. ") 4 | texture_brush:add_description("- The painting is only additive at the moment,") 5 | texture_brush:add_description(" meaning it cannot paint layers from \"underneath\"") 6 | texture_brush:add_description(" another layer.") 7 | 8 | local texture = texture_brush:add_string_tag("Brush Texture", "") 9 | local pressure = texture_brush:add_real_tag("Pressure", 0, 1000, 1, 2) 10 | local index = texture_brush:add_int_tag("Texture Index", 1, 3, 1) 11 | 12 | texture_brush.on_left_hold = function(brush, evt) 13 | local image = load_png( 14 | texture:get() 15 | ) 16 | local sel = select_origin( 17 | evt:pos(), 18 | evt:outer_radius(), 19 | evt:outer_radius() 20 | ) 21 | procedures:paint_texture(sel,image,index:get(),pressure:get(),cam_yaw()-90) 22 | sel:apply() 23 | end -------------------------------------------------------------------------------- /scripts/texture_printer.lua: -------------------------------------------------------------------------------- 1 | local texture_printer = brush("Texture Printer"); 2 | 3 | texture_printer:add_description("Description:") 4 | texture_printer:add_description("Prints out texture paths and effect ids ") 5 | texture_printer:add_description("in the clicked chunk.") 6 | texture_printer:add_null_tag() 7 | 8 | function texture_printer:on_left_click(evt) 9 | local sel = select_origin(evt:pos(), 1, 1) 10 | 11 | for i,chunk in pairs(sel:chunks()) do 12 | if chunk:get_texture_count() == 0 then 13 | print("Chunk has no textures") 14 | end 15 | 16 | print("== Chunk Textures ==") 17 | for i=0,chunk:get_texture_count()-1 do 18 | local tex = chunk:get_texture(i) 19 | local eff = chunk:get_effect(i) 20 | print("Layer "..i..":") 21 | print(" Texture: "..tex) 22 | print(" Effect: "..eff) 23 | end 24 | print("") 25 | end 26 | end -------------------------------------------------------------------------------- /scripts/tsconfig.json: -------------------------------------------------------------------------------- 1 | /** 2 | * This file has a working configuration to write 3 | * script brushes with TypeScriptToLua 4 | * (https://github.com/TypeScriptToLua/TypeScriptToLua) 5 | */ 6 | { 7 | "compilerOptions": { 8 | "target": "es5", 9 | "module": "commonjs", 10 | "strict": true, 11 | "esModuleInterop": true, 12 | "skipLibCheck": true, 13 | "outDir": "./_tsbuild", 14 | "forceConsistentCasingInFileNames": true 15 | }, 16 | "tstl": { 17 | "luaTarget": "5.1", 18 | "luaPlugins": [], 19 | "noImplicitSelf": true, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sql/Noggit.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `UIDs` ( 2 | `MapId` int(11) NOT NULL, 3 | `UID` int(11) NOT NULL 4 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 5 | 6 | ALTER TABLE `UIDs` 7 | ADD PRIMARY KEY (`MapId`); 8 | -------------------------------------------------------------------------------- /src/external/qt-color-widgets.repo: -------------------------------------------------------------------------------- 1 | git@github.com:bloerwald/Qt-Color-Widgets.git 2 | -------------------------------------------------------------------------------- /src/external/qt-color-widgets/qt-color-widgets/bound_color_selector.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \author Mattia Basaglia 5 | * 6 | * \copyright Copyright (C) 2013-2017 Mattia Basaglia 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | #ifndef BOUND_COLOR_SELECTOR_HPP 23 | #define BOUND_COLOR_SELECTOR_HPP 24 | 25 | #include "qt-color-widgets/color_selector.hpp" 26 | 27 | namespace color_widgets { 28 | /** 29 | * \brief A color selector bound to a color reference 30 | * \todo Maybe this can be removed 31 | */ 32 | class Q_DECL_EXPORT BoundColorSelector : public ColorSelector 33 | { 34 | Q_OBJECT 35 | private: 36 | QColor* ref; 37 | public: 38 | explicit BoundColorSelector(QColor* reference, QWidget *parent = 0); 39 | 40 | private Q_SLOTS: 41 | void update_reference(QColor); 42 | }; 43 | } // namespace color_widgets 44 | #endif // BOUND_COLOR_SELECTOR_HPP 45 | -------------------------------------------------------------------------------- /src/external/qt-color-widgets/qt-color-widgets/color_delegate.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \author Mattia Basaglia 5 | * 6 | * \copyright Copyright (C) 2013-2017 Mattia Basaglia 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | #ifndef COLOR_DELEGATE_HPP 23 | #define COLOR_DELEGATE_HPP 24 | 25 | #include 26 | 27 | namespace color_widgets { 28 | 29 | /** 30 | Delegate to use a ColorSelector in a color list 31 | */ 32 | class Q_DECL_EXPORT ColorDelegate : public QAbstractItemDelegate 33 | { 34 | Q_OBJECT 35 | public: 36 | explicit ColorDelegate(QWidget *parent = 0); 37 | 38 | virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, 39 | const QModelIndex &index) const Q_DECL_OVERRIDE; 40 | 41 | bool editorEvent(QEvent* event, 42 | QAbstractItemModel* model, 43 | const QStyleOptionViewItem & option, 44 | const QModelIndex & index) override; 45 | 46 | virtual QSize sizeHint(const QStyleOptionViewItem &option, 47 | const QModelIndex &index) const Q_DECL_OVERRIDE; 48 | }; 49 | 50 | } // namespace color_widgets 51 | 52 | #endif // COLOR_DELEGATE_HPP 53 | -------------------------------------------------------------------------------- /src/external/qt-color-widgets/qt-color-widgets/color_list_widget.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \author Mattia Basaglia 5 | * 6 | * \copyright Copyright (C) 2013-2017 Mattia Basaglia 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | #ifndef COLOR_LIST_WIDGET_HPP 23 | #define COLOR_LIST_WIDGET_HPP 24 | 25 | #include "qt-color-widgets/abstract_widget_list.hpp" 26 | #include "qt-color-widgets/color_wheel.hpp" 27 | 28 | namespace color_widgets { 29 | 30 | class Q_DECL_EXPORT ColorListWidget : public AbstractWidgetList 31 | { 32 | Q_OBJECT 33 | 34 | Q_PROPERTY(QList colors READ colors WRITE setColors NOTIFY colorsChanged ) 35 | Q_PROPERTY(ColorWheel::DisplayFlags wheelFlags READ wheelFlags WRITE setWheelFlags NOTIFY wheelFlagsChanged) 36 | 37 | public: 38 | explicit ColorListWidget(QWidget *parent = 0); 39 | ~ColorListWidget(); 40 | 41 | QList colors() const; 42 | void setColors(const QList& colors); 43 | 44 | void swap(int a, int b); 45 | 46 | void append(); 47 | void setColorAt(int i, QColor const& color); 48 | 49 | 50 | ColorWheel::DisplayFlags wheelFlags() const; 51 | 52 | Q_SIGNALS: 53 | void color_added(); 54 | void colorsChanged(const QList&); 55 | void wheelFlagsChanged(ColorWheel::DisplayFlags flags); 56 | 57 | public Q_SLOTS: 58 | void setWheelFlags(ColorWheel::DisplayFlags flags); 59 | 60 | private Q_SLOTS: 61 | void emit_changed(); 62 | void handle_removed(int); 63 | void color_changed(int row); 64 | 65 | private: 66 | class Private; 67 | Private * const p; 68 | void append_widget(int col); 69 | }; 70 | 71 | } // namespace color_widgets 72 | 73 | #endif // COLOR_LIST_WIDGET_HPP 74 | -------------------------------------------------------------------------------- /src/external/qt-color-widgets/qt-color-widgets/color_names.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \author Mattia Basaglia 5 | * 6 | * \copyright Copyright (C) 2013-2017 Mattia Basaglia 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | #ifndef COLOR_WIDGETS_COLOR_NAMES_HPP 23 | #define COLOR_WIDGETS_COLOR_NAMES_HPP 24 | 25 | #include 26 | #include 27 | 28 | namespace color_widgets { 29 | 30 | /** 31 | * \brief Convert a string into a color 32 | * 33 | * Supported string formats: 34 | * * Short hex strings #f00 35 | * * Long hex strings #ff0000 36 | * * Color names red 37 | * * Function-like rgb(255,0,0) 38 | * 39 | * Additional string formats supported only when \p alpha is true: 40 | * * Long hex strings #ff0000ff 41 | * * Function like rgba(255,0,0,255) 42 | */ 43 | QColor colorFromString(const QString& string, bool alpha = true); 44 | 45 | /** 46 | * \brief Convert a color into a string 47 | * 48 | * Format: 49 | * * If the color has full alpha: #ff0000 50 | * * If alpha is true and the color has non-full alpha: #ff000088 51 | */ 52 | QString stringFromColor(const QColor& color, bool alpha = true); 53 | 54 | } // namespace color_widgets 55 | #endif // COLOR_WIDGETS_COLOR_NAMES_HPP 56 | -------------------------------------------------------------------------------- /src/external/qt-color-widgets/src/alphaback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/src/external/qt-color-widgets/src/alphaback.png -------------------------------------------------------------------------------- /src/external/qt-color-widgets/src/bound_color_selector.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \author Mattia Basaglia 5 | * 6 | * \copyright Copyright (C) 2013-2017 Mattia Basaglia 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | #include "qt-color-widgets/bound_color_selector.hpp" 23 | 24 | namespace color_widgets { 25 | 26 | BoundColorSelector::BoundColorSelector(QColor* reference, QWidget *parent) : 27 | ColorSelector(parent), ref(reference) 28 | { 29 | setColor(*reference); 30 | connect(this,&ColorPreview::colorChanged,this, &BoundColorSelector::update_reference); 31 | } 32 | 33 | void BoundColorSelector::update_reference(QColor c) 34 | { 35 | *ref = c; 36 | } 37 | 38 | } // namespace color_widgets 39 | -------------------------------------------------------------------------------- /src/external/qt-color-widgets/src/color_utils.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * 4 | * \author Mattia Basaglia 5 | * 6 | * \copyright Copyright (C) 2013-2017 Mattia Basaglia 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | #include 23 | #include 24 | 25 | namespace color_widgets { 26 | namespace detail { 27 | 28 | 29 | inline qreal color_chromaF(const QColor& c) 30 | { 31 | qreal max = qMax(c.redF(), qMax(c.greenF(), c.blueF())); 32 | qreal min = qMin(c.redF(), qMin(c.greenF(), c.blueF())); 33 | return max - min; 34 | } 35 | 36 | inline qreal color_lumaF(const QColor& c) 37 | { 38 | return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF(); 39 | } 40 | QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha = 1 ); 41 | 42 | inline QColor rainbow_lch(qreal hue) 43 | { 44 | return color_from_lch(hue,1,1); 45 | } 46 | 47 | inline QColor rainbow_hsv(qreal hue) 48 | { 49 | return QColor::fromHsvF(hue,1,1); 50 | } 51 | 52 | inline qreal color_lightnessF(const QColor& c) 53 | { 54 | return ( qMax(c.redF(),qMax(c.greenF(),c.blueF())) + 55 | qMin(c.redF(),qMin(c.greenF(),c.blueF())) ) / 2; 56 | } 57 | 58 | inline qreal color_HSL_saturationF(const QColor& col) 59 | { 60 | qreal c = color_chromaF(col); 61 | qreal l = color_lightnessF(col); 62 | if ( qFuzzyCompare(l+1,1) || qFuzzyCompare(l+1,2) ) 63 | return 0; 64 | return c / (1-qAbs(2*l-1)); 65 | } 66 | 67 | QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha = 1 ); 68 | 69 | } // namespace detail 70 | } // namespace color_widgets 71 | -------------------------------------------------------------------------------- /src/external/qt-color-widgets/src/color_widgets.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | alphaback.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/glsl/cursor_frag.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | uniform vec4 color; 5 | 6 | out vec4 out_color; 7 | 8 | void main() 9 | { 10 | out_color = color; 11 | } 12 | -------------------------------------------------------------------------------- /src/glsl/cursor_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | uniform mat4 model_view_projection; 5 | uniform vec3 cursor_pos; 6 | uniform float radius; 7 | 8 | in vec4 position; 9 | 10 | void main() 11 | { 12 | vec3 p = cursor_pos + position.xyz * radius; 13 | gl_Position = model_view_projection * vec4(p,1.); 14 | } 15 | -------------------------------------------------------------------------------- /src/glsl/gizmo_frag.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | in vec3 f_color; 5 | 6 | out vec4 out_color; 7 | 8 | uniform float alpha; 9 | 10 | void main() 11 | { 12 | out_color = vec4(f_color, alpha); 13 | } 14 | -------------------------------------------------------------------------------- /src/glsl/gizmo_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | in vec3 position; 5 | in vec3 color; 6 | 7 | out vec3 f_color; 8 | 9 | uniform mat4 view_projection; 10 | uniform mat4 model; 11 | 12 | void main() 13 | { 14 | gl_Position = view_projection * model * vec4(position, 1.); 15 | 16 | f_color = color; 17 | } 18 | -------------------------------------------------------------------------------- /src/glsl/horizon_frag.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | uniform vec3 color; 5 | 6 | out vec4 out_color; 7 | 8 | void main() 9 | { 10 | out_color = vec4(color, 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /src/glsl/horizon_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | in vec4 position; 5 | 6 | uniform mat4 model_view; 7 | uniform mat4 projection; 8 | 9 | void main() 10 | { 11 | gl_Position = projection * model_view * position; 12 | } 13 | -------------------------------------------------------------------------------- /src/glsl/liquid_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 410 core 3 | //todo: add fallback in case the extension isn't supported for the user 4 | #extension GL_ARB_shader_draw_parameters : require 5 | 6 | in vec4 position; 7 | in vec2 tex_coord; 8 | in float depth; 9 | 10 | uniform mat4 model_view; 11 | uniform mat4 projection; 12 | uniform mat4 transform; 13 | 14 | uniform int use_transform = int(0); 15 | 16 | out vec3 f_position; 17 | out float depth_; 18 | out vec2 tex_coord_; 19 | flat out int draw_id; 20 | 21 | void main() 22 | { 23 | f_position = position.xyz; 24 | depth_ = depth; 25 | tex_coord_ = tex_coord; 26 | 27 | if(use_transform == 1) 28 | { 29 | gl_Position = projection * model_view * transform * position; 30 | draw_id = 0; 31 | } 32 | else 33 | { 34 | gl_Position = projection * model_view * position; 35 | draw_id = gl_DrawIDARB; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/glsl/m2_box_frag.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | uniform vec4 color; 5 | 6 | out vec4 out_color; 7 | 8 | void main() 9 | { 10 | out_color = color; 11 | } 12 | -------------------------------------------------------------------------------- /src/glsl/m2_box_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | in mat4 transform; 5 | in vec4 position; 6 | 7 | uniform mat4 model_view; 8 | uniform mat4 projection; 9 | 10 | void main() 11 | { 12 | gl_Position = projection * model_view * transform * position; 13 | } 14 | -------------------------------------------------------------------------------- /src/glsl/m2_depth_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec3 position; 4 | in vec2 texcoord1; 5 | in vec2 texcoord2; 6 | in mat4 transform; 7 | 8 | out vec2 uv1; 9 | out vec2 uv2; 10 | 11 | uniform mat4 view_proj; 12 | 13 | struct m2_data 14 | { 15 | vec4 mesh_color; 16 | 17 | int fog_mode; 18 | int unfogged; 19 | int unlit; 20 | int pixel_shader; 21 | 22 | mat4 tex_matrix_1; 23 | mat4 tex_matrix_2; 24 | 25 | uvec2 texture_handle_1; 26 | uvec2 pad1; 27 | uvec2 texture_handle_2; 28 | uvec2 pad2; 29 | 30 | int index_1; 31 | int index_2; 32 | ivec2 padding; 33 | 34 | float alpha_test; 35 | int tex_unit_lookup_1; 36 | int tex_unit_lookup_2; 37 | int tex_count; 38 | }; 39 | 40 | uniform int index; 41 | 42 | layout (std140) uniform render_data 43 | { 44 | m2_data data[192]; 45 | }; 46 | 47 | void main() 48 | { 49 | gl_Position = view_proj * transform * vec4(position, 1.f); 50 | 51 | uv1 = texcoord1; 52 | uv2 = texcoord2; 53 | } -------------------------------------------------------------------------------- /src/glsl/m2_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 410 core 3 | 4 | in vec4 pos; 5 | in vec3 normal; 6 | in vec2 texcoord1; 7 | in vec2 texcoord2; 8 | 9 | #ifdef instanced 10 | in mat4 transform; 11 | #else 12 | uniform mat4 transform; 13 | #endif 14 | 15 | out vec2 uv1; 16 | out vec2 uv2; 17 | out float camera_dist; 18 | out vec3 norm; 19 | 20 | uniform mat4 model_view; 21 | uniform mat4 projection; 22 | 23 | struct m2_data 24 | { 25 | vec4 mesh_color; 26 | 27 | int fog_mode; 28 | int unfogged; 29 | int unlit; 30 | int pixel_shader; 31 | 32 | mat4 tex_matrix_1; 33 | mat4 tex_matrix_2; 34 | 35 | uvec2 texture_handle_1; 36 | uvec2 pad1; 37 | uvec2 texture_handle_2; 38 | uvec2 pad2; 39 | 40 | int index_1; 41 | int index_2; 42 | ivec2 padding; 43 | 44 | float alpha_test; 45 | int tex_unit_lookup_1; 46 | int tex_unit_lookup_2; 47 | int tex_count; 48 | }; 49 | 50 | uniform int index; 51 | 52 | layout (std140) uniform render_data 53 | { 54 | m2_data data[192]; 55 | }; 56 | 57 | 58 | // code from https://wowdev.wiki/M2/.skin#Environment_mapping 59 | vec2 sphere_map(vec3 vert, vec3 norm) 60 | { 61 | vec3 normPos = -(normalize(vert)); 62 | vec3 temp = (normPos - (norm * (2.0 * dot(normPos, norm)))); 63 | temp = vec3(temp.x, temp.y, temp.z + 1.0); 64 | 65 | return ((normalize(temp).xy * 0.5) + vec2(0.5)); 66 | } 67 | 68 | vec2 get_texture_uv(int tex_unit_lookup, vec3 vert, vec3 norm) 69 | { 70 | if(tex_unit_lookup == 0) 71 | { 72 | return sphere_map(vert, norm); 73 | } 74 | else if(tex_unit_lookup == 1) 75 | { 76 | return (transpose(data[index].tex_matrix_1) * vec4(texcoord1, 0.0, 1.0)).xy; 77 | } 78 | else if(tex_unit_lookup == 2) 79 | { 80 | return (transpose(data[index].tex_matrix_2) * vec4(texcoord2, 0.0, 1.0)).xy; 81 | } 82 | else 83 | { 84 | return vec2(0.0); 85 | } 86 | } 87 | 88 | void main() 89 | { 90 | vec4 vertex = model_view * transform * pos; 91 | 92 | // important to normalize because of the scaling !! 93 | norm = normalize(mat3(transform) * normal); 94 | 95 | uv1 = get_texture_uv(data[index].tex_unit_lookup_1, vertex.xyz, norm); 96 | uv2 = get_texture_uv(data[index].tex_unit_lookup_2, vertex.xyz, norm); 97 | 98 | camera_dist = -vertex.z; 99 | gl_Position = projection * vertex; 100 | } 101 | -------------------------------------------------------------------------------- /src/glsl/mfbo_frag.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | uniform vec4 color; 5 | 6 | out vec4 out_color; 7 | 8 | void main() 9 | { 10 | out_color = color; 11 | } 12 | -------------------------------------------------------------------------------- /src/glsl/mfbo_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | in vec4 position; 5 | 6 | uniform mat4 model_view_projection; 7 | 8 | void main() 9 | { 10 | gl_Position = model_view_projection * position; 11 | } 12 | -------------------------------------------------------------------------------- /src/glsl/particle_frag.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 410 core 3 | #ifdef use_bindless 4 | #extension GL_ARB_bindless_texture : require 5 | 6 | uniform uvec2 tex_array; 7 | #else 8 | uniform sampler2DArray tex_array; 9 | #endif 10 | 11 | in vec2 f_uv; 12 | in vec4 f_color; 13 | 14 | out vec4 out_color; 15 | 16 | 17 | uniform int index_in_array; 18 | 19 | uniform float alpha_test; 20 | 21 | void main() 22 | { 23 | #ifdef use_bindless 24 | vec4 t = texture(sampler2DArray(tex_array), vec3(f_uv, index_in_array)); 25 | #else 26 | vec4 t = texture(tex_array, vec3(f_uv, index_in_array)); 27 | #endif 28 | 29 | if(t.a < alpha_test) 30 | { 31 | discard; 32 | } 33 | 34 | out_color = vec4(f_color.rgb * t.rgb, t.a); 35 | } 36 | -------------------------------------------------------------------------------- /src/glsl/particle_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | in mat4 transform; 5 | in vec4 position; 6 | in vec3 offset; 7 | in vec2 uv; 8 | in vec4 color; 9 | 10 | out vec2 f_uv; 11 | out vec4 f_color; 12 | 13 | uniform mat4 model_view_projection; 14 | uniform int billboard; 15 | 16 | void main() 17 | { 18 | f_uv = uv; 19 | f_color = color; 20 | if(billboard == 1) 21 | { 22 | vec4 pos = transform*position; 23 | pos.xyz += offset; 24 | gl_Position = model_view_projection * pos; 25 | } 26 | else 27 | { 28 | gl_Position = model_view_projection * transform * position; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/glsl/ribbon_frag.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 410 core 3 | #ifdef use_bindless 4 | #extension GL_ARB_bindless_texture : require 5 | 6 | uniform uvec2 tex_array; 7 | #else 8 | uniform sampler2DArray tex_array; 9 | #endif 10 | 11 | in vec2 f_uv; 12 | 13 | out vec4 out_color; 14 | 15 | uniform int index_in_array; 16 | uniform vec4 color; 17 | 18 | void main() 19 | { 20 | #ifdef use_bindless 21 | vec4 t = texture(sampler2DArray(tex_array), vec3(f_uv, index_in_array)); 22 | #else 23 | vec4 t = texture(tex_array, vec3(f_uv, index_in_array)); 24 | #endif 25 | 26 | out_color = vec4(color.rgb * t.rgb, color.a); 27 | } 28 | -------------------------------------------------------------------------------- /src/glsl/ribbon_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | in mat4 transform; 5 | in vec4 position; 6 | in vec2 uv; 7 | 8 | out vec2 f_uv; 9 | 10 | uniform mat4 model_view_projection; 11 | 12 | void main() 13 | { 14 | f_uv = uv; 15 | gl_Position = model_view_projection * transform * position; 16 | } 17 | -------------------------------------------------------------------------------- /src/glsl/shadow_frag.glsl: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec3 f_position; 4 | in vec4 f_light_position; 5 | in vec3 f_normal; 6 | 7 | uniform sampler2DShadow depth_texture; 8 | uniform vec3 light_dir; 9 | 10 | out vec4 shadow; 11 | 12 | void main() 13 | { 14 | vec3 proj_coords = (f_light_position.xyz / f_light_position.w) * 0.5 + 0.5; 15 | float shadow_bias = 0.0001; 16 | float bias = max(shadow_bias * (1.0 - dot(f_normal, light_dir)), shadow_bias); 17 | 18 | proj_coords.z -= bias; 19 | 20 | // shadow outside the light's frustrum 21 | if (proj_coords.z > 1.0) 22 | { 23 | shadow = vec4(0., 0., 0., 1.); 24 | } 25 | else 26 | { 27 | float closest_depth = texture(depth_texture, proj_coords.xyz); 28 | shadow = vec4(1. - closest_depth, 0., 0., 1.); 29 | } 30 | } -------------------------------------------------------------------------------- /src/glsl/shadow_vert.glsl: -------------------------------------------------------------------------------- 1 | #version 410 core 2 | 3 | in vec3 position; 4 | in vec3 normal; 5 | 6 | out vec3 f_position; 7 | out vec4 f_light_position; 8 | out vec3 f_normal; 9 | 10 | uniform mat4 view_proj; 11 | uniform mat4 light_view_proj; 12 | 13 | void main() 14 | { 15 | gl_Position = view_proj * vec4(position, 1.f); 16 | 17 | f_position = position; 18 | f_light_position = light_view_proj * vec4(position, 1.); 19 | f_normal = normal; 20 | } -------------------------------------------------------------------------------- /src/glsl/terrain_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 410 core 3 | 4 | in vec3 position; 5 | in vec3 normal; 6 | in vec3 mccv; 7 | in vec2 texcoord; 8 | 9 | uniform mat4 mvp; 10 | 11 | out vec3 vary_position; 12 | out vec2 vary_texcoord; 13 | out vec3 vary_normal; 14 | out vec3 vary_mccv; 15 | 16 | 17 | flat out int chunk_id; 18 | 19 | void main() 20 | { 21 | gl_Position = mvp * vec4(position, 1.0); 22 | vary_normal = normal; 23 | vary_position = position; 24 | vary_texcoord = texcoord; 25 | vary_mccv = mccv; 26 | 27 | chunk_id = gl_VertexID / 145; 28 | } 29 | -------------------------------------------------------------------------------- /src/glsl/wmo_depth_frag.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 410 core 3 | 4 | #ifdef use_bindless 5 | #extension GL_ARB_bindless_texture : require 6 | #else 7 | uniform sampler2DArray array_0; 8 | #endif 9 | 10 | 11 | 12 | 13 | struct batch_uniforms 14 | { 15 | uvec2 texture_1; 16 | uvec2 padding_1; 17 | uvec2 texture_2; 18 | uvec2 padding_2; 19 | 20 | int texture_index_1; 21 | int texture_index_2; 22 | int use_vertex_color; 23 | int exterior_lit; 24 | 25 | int shader_id; 26 | int unfogged; 27 | int unlit; 28 | float alpha_test; 29 | }; 30 | 31 | 32 | flat in int index; 33 | 34 | layout (std140) uniform render_data 35 | { 36 | batch_uniforms data[96]; 37 | }; 38 | 39 | in vec2 f_texcoord; 40 | 41 | void main() 42 | { 43 | vec4 out_color; 44 | 45 | #ifdef use_bindless 46 | vec4 tex = texture(sampler2DArray(data[index].texture_1), vec3(f_texcoord, data[index].texture_index_1)); 47 | #else 48 | vec4 tex = texture(array_0, vec3(f_texcoord, data[index].texture_index_1)); 49 | #endif 50 | 51 | int shader = data[index].shader_id; 52 | 53 | // only those shaders use the texture for alpha testing 54 | if((shader == 1 || shader == 2) && (tex.a < data[index].alpha_test)) 55 | { 56 | discard; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/glsl/wmo_depth_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 410 core 3 | 4 | in vec4 position; 5 | in vec2 uv1; 6 | in int id; 7 | 8 | in mat4 transform; 9 | 10 | out vec2 f_texcoord; 11 | 12 | flat out int index; 13 | 14 | uniform mat4 view_proj; 15 | 16 | struct batch_uniforms 17 | { 18 | uvec2 texture_1; 19 | uvec2 padding_1; 20 | uvec2 texture_2; 21 | uvec2 padding_2; 22 | 23 | int texture_index_1; 24 | int texture_index_2; 25 | int use_vertex_color; 26 | int exterior_lit; 27 | 28 | int shader_id; 29 | int unfogged; 30 | int unlit; 31 | float alpha_test; 32 | }; 33 | 34 | 35 | layout (std140) uniform render_data 36 | { 37 | batch_uniforms data[96]; 38 | }; 39 | 40 | void main() 41 | { 42 | index = id; 43 | f_texcoord = uv1; 44 | 45 | gl_Position = view_proj * transform * position; 46 | } 47 | -------------------------------------------------------------------------------- /src/glsl/wmo_vert.glsl: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #version 330 core 3 | 4 | in vec4 position; 5 | in vec3 normal; 6 | in vec4 color; 7 | in vec2 uv1; 8 | in vec2 uv2; 9 | in int id; 10 | 11 | in mat4 transform; 12 | 13 | out vec3 f_position; 14 | out vec3 f_normal; 15 | out vec2 f_texcoord; 16 | out vec2 f_texcoord_2; 17 | out vec4 f_vertex_color; 18 | flat out int index; 19 | 20 | uniform mat4 model_view; 21 | uniform mat4 projection; 22 | 23 | struct batch_uniforms 24 | { 25 | uvec2 texture_1; 26 | uvec2 padding_1; 27 | uvec2 texture_2; 28 | uvec2 padding_2; 29 | 30 | int texture_index_1; 31 | int texture_index_2; 32 | int use_vertex_color; 33 | int exterior_lit; 34 | 35 | int shader_id; 36 | int unfogged; 37 | int unlit; 38 | float alpha_test; 39 | }; 40 | 41 | 42 | layout (std140) uniform render_data 43 | { 44 | batch_uniforms data[96]; 45 | }; 46 | 47 | void main() 48 | { 49 | index = id; 50 | vec4 pos = transform * position; 51 | vec4 view_space_pos = model_view * pos; 52 | gl_Position = projection * view_space_pos; 53 | 54 | f_position = pos.xyz; 55 | f_normal = mat3(transform) * normal; 56 | 57 | // Env and EnvMetal 58 | if(data[index].shader_id == 3 || data[index].shader_id == 5) 59 | { 60 | f_texcoord = uv1; 61 | f_texcoord_2 = reflect(normalize(view_space_pos.xyz), f_normal).xy; 62 | } 63 | else 64 | { 65 | f_texcoord = uv1; 66 | f_texcoord_2 = uv2; 67 | } 68 | 69 | f_vertex_color = color; 70 | } 71 | -------------------------------------------------------------------------------- /src/math/bounding_box.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | namespace 6 | { 7 | math::vector_3d min_per_dimension(std::vector const& points) 8 | { 9 | auto min(math::vector_3d::max()); 10 | for (auto const& point : points) 11 | { 12 | min = math::min(min, point); 13 | } 14 | return min; 15 | } 16 | math::vector_3d max_per_dimension(std::vector const& points) 17 | { 18 | auto max(math::vector_3d::min()); 19 | for (auto const& point : points) 20 | { 21 | max = math::max(max, point); 22 | } 23 | return max; 24 | } 25 | } 26 | 27 | namespace math 28 | { 29 | aabb::aabb(math::vector_3d const& min_, math::vector_3d const& max_) 30 | : min(min_) 31 | , max(max_) 32 | { 33 | } 34 | 35 | aabb::aabb(std::vector points) 36 | : aabb(min_per_dimension(points), max_per_dimension(points)) 37 | { 38 | } 39 | 40 | //! \todo Optimize: iterate lazily. 41 | std::vector aabb::all_corners() const 42 | { 43 | return box_points(min, max); 44 | } 45 | 46 | 47 | std::vector box_points(math::vector_3d const& box_min, math::vector_3d const& box_max) 48 | { 49 | std::vector points; 50 | 51 | points.emplace_back(box_max.x, box_max.y, box_max.z); 52 | points.emplace_back(box_max.x, box_max.y, box_min.z); 53 | points.emplace_back(box_max.x, box_min.y, box_max.z); 54 | points.emplace_back(box_max.x, box_min.y, box_min.z); 55 | points.emplace_back(box_min.x, box_max.y, box_max.z); 56 | points.emplace_back(box_min.x, box_max.y, box_min.z); 57 | points.emplace_back(box_min.x, box_min.y, box_max.z); 58 | points.emplace_back(box_min.x, box_min.y, box_min.z); 59 | 60 | return points; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/math/bounding_box.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace math 10 | { 11 | struct aabb 12 | { 13 | aabb(math::vector_3d const& min_, math::vector_3d const& max_); 14 | aabb(std::vector points); 15 | 16 | std::vector all_corners() const; 17 | 18 | math::vector_3d min; 19 | math::vector_3d max; 20 | }; 21 | 22 | std::vector box_points(math::vector_3d const& box_min, math::vector_3d const& box_max); 23 | } 24 | -------------------------------------------------------------------------------- /src/math/constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace math 4 | { 5 | namespace constants 6 | { 7 | constexpr float const pi = 3.141592653f; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/math/frustum.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace math 13 | { 14 | class frustum 15 | { 16 | enum SIDES 17 | { 18 | RIGHT, 19 | LEFT, 20 | BOTTOM, 21 | TOP, 22 | BACK, 23 | FRONT, 24 | SIDES_MAX, 25 | }; 26 | 27 | class plane 28 | { 29 | public: 30 | plane() = default; 31 | plane (vector_4d const& vec) 32 | : _normal (vec.xyz()) 33 | , _distance (vec.w) 34 | { 35 | normalize(); 36 | } 37 | 38 | void normalize() 39 | { 40 | const float recip (1.0f / _normal.length()); 41 | _normal *= recip; 42 | _distance *= recip; 43 | } 44 | 45 | const float& distance() const 46 | { 47 | return _distance; 48 | } 49 | 50 | const vector_3d& normal() const 51 | { 52 | return _normal; 53 | } 54 | 55 | private: 56 | vector_3d _normal; 57 | float _distance; 58 | }; 59 | std::array _planes; 60 | 61 | public: 62 | frustum (matrix_4x4 const& matrix); 63 | 64 | bool contains (const vector_3d& point) const; 65 | bool intersects (const std::vector& intersect_points) const; 66 | bool intersects ( const vector_3d& v1 67 | , const vector_3d& v2 68 | ) const; 69 | bool intersectsSphere ( const vector_3d& position 70 | , const float& radius 71 | ) const; 72 | }; 73 | } 74 | -------------------------------------------------------------------------------- /src/math/interpolation.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace math 8 | { 9 | namespace interpolation 10 | { 11 | template 12 | static T linear (const float& percentage, const T& start, const T& end) 13 | { 14 | return T (start * (1.0f - percentage) + end * percentage); 15 | } 16 | 17 | template 18 | static T slerp (const float& percentage, const T& start, const T& end) 19 | { 20 | const float dot (start * end); 21 | 22 | if (std::abs (dot) > 0.9995f) 23 | { 24 | //! \note Don't call linear here, as this will recurse with quaternions. 25 | return T (start * (1.0f - percentage) + end * percentage); 26 | } 27 | 28 | radians const a (acos (dot)._ * percentage); 29 | 30 | return T (start * cos (a) + T (end - start * dot).normalize() * sin (a)); 31 | } 32 | 33 | template 34 | static T hermite ( const float& percentage 35 | , const T& start 36 | , const T& end 37 | , const T& in 38 | , const T& out 39 | ) 40 | { 41 | const float percentage_2 (percentage * percentage); 42 | const float percentage_3 (percentage_2 * percentage); 43 | const float _2_percentage_3 (2.0f * percentage_3); 44 | const float _3_percentage_2 (3.0f * percentage_2); 45 | 46 | const float h1 (_2_percentage_3 - _3_percentage_2 + 1.0f); 47 | const float h2 (_3_percentage_2 - _2_percentage_3); 48 | const float h3 (percentage_3 - 2.0f * percentage_2 + percentage); 49 | const float h4 (percentage_3 - percentage_2); 50 | 51 | return T (start * h1 + end * h2 + in * h3 + out * h4); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/math/ray.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace math 8 | { 9 | std::optional ray::intersect_bounds 10 | (vector_3d const& min, vector_3d const& max) const 11 | { 12 | float tmin (std::numeric_limits::lowest()); 13 | float tmax (std::numeric_limits::max()); 14 | 15 | if (_direction.x != 0.0f) 16 | { 17 | float const tx1 ((min.x - _origin.x) / _direction.x); 18 | float const tx2 ((max.x - _origin.x) / _direction.x); 19 | 20 | tmin = std::max (tmin, std::min (tx1, tx2)); 21 | tmax = std::min (tmax, std::max (tx1, tx2)); 22 | } 23 | 24 | if (_direction.y != 0.0f) 25 | { 26 | float const ty1 ((min.y - _origin.y) / _direction.y); 27 | float const ty2 ((max.y - _origin.y) / _direction.y); 28 | 29 | tmin = std::max (tmin, std::min (ty1, ty2)); 30 | tmax = std::min (tmax, std::max (ty1, ty2)); 31 | } 32 | 33 | if (_direction.z != 0.0f) 34 | { 35 | float const tz1 ((min.z - _origin.z) / _direction.z); 36 | float const tz2 ((max.z - _origin.z) / _direction.z); 37 | 38 | tmin = std::max (tmin, std::min (tz1, tz2)); 39 | tmax = std::min (tmax, std::max (tz1, tz2)); 40 | } 41 | 42 | if (tmax >= tmin) 43 | { 44 | return tmin; 45 | } 46 | 47 | return std::nullopt; 48 | } 49 | 50 | std::optional ray::intersect_triangle 51 | (vector_3d const& v0, vector_3d const& v1, vector_3d const& v2) const 52 | { 53 | vector_3d const e1 (v1 - v0); 54 | vector_3d const e2 (v2 - v0); 55 | 56 | vector_3d const P (_direction % e2); 57 | 58 | float const det (e1 * P); 59 | 60 | if (det == 0.0f) 61 | { 62 | return std::nullopt; 63 | } 64 | 65 | vector_3d const T (_origin - v0); 66 | float const u ((T * P) / det); 67 | 68 | if (u < 0.0f || u > 1.0f) 69 | { 70 | return std::nullopt; 71 | } 72 | 73 | vector_3d const Q (T % e1); 74 | float const v ((_direction * Q) / det); 75 | 76 | if (v < 0.0f || u + v > 1.0f) 77 | { 78 | return std::nullopt; 79 | } 80 | 81 | float const t ((e2 * Q) / det); 82 | 83 | if (t > std::numeric_limits::min()) 84 | { 85 | return t; 86 | } 87 | 88 | return std::nullopt; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/math/ray.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace math 11 | { 12 | struct ray 13 | { 14 | ray (vector_3d origin, vector_3d const& direction) 15 | : _origin (std::move (origin)) 16 | , _direction (direction.normalized()) 17 | {} 18 | 19 | ray (matrix_4x4 const& transform, ray const& other) 20 | : ray ( (transform * math::vector_4d (other._origin, 1.0)).xyz() 21 | , (transform * math::vector_4d (other._direction, 0.0)).xyz() 22 | ) 23 | {} 24 | 25 | std::optional intersect_bounds 26 | (vector_3d const& _min, vector_3d const& _max) const; 27 | std::optional intersect_triangle 28 | (vector_3d const& _v0, vector_3d const& _v1, vector_3d const& _v2) const; 29 | 30 | vector_3d position (float distance) const 31 | { 32 | return _origin + _direction * distance; 33 | } 34 | 35 | private: 36 | vector_3d _origin; 37 | vector_3d _direction; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /src/math/vector_2d.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | 6 | namespace math 7 | { 8 | void rotate (float x0, float y0, float* x, float* y, radians angle) 9 | { 10 | const float xa (*x - x0); 11 | const float ya (*y - y0); 12 | *x = xa * cos (angle) - ya * sin (angle) + x0; 13 | *y = xa * sin (angle) + ya * cos (angle) + y0; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/mysql/mysql.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace 12 | { 13 | std::unique_ptr connect() 14 | { 15 | QSettings settings; 16 | std::unique_ptr Con 17 | (get_driver_instance()->connect 18 | ( settings.value("project/mysql/server").toString().toStdString() 19 | , settings.value("project/mysql/user").toString().toStdString() 20 | , settings.value("project/mysql/pwd").toString().toStdString() 21 | ) 22 | ); 23 | Con->setSchema(settings.value("project/mysql/db").toString().toStdString()); 24 | 25 | return Con; 26 | } 27 | } 28 | 29 | namespace mysql 30 | { 31 | bool hasMaxUIDStoredDB(std::size_t mapID) 32 | { 33 | auto Con(connect()); 34 | std::unique_ptr pstmt(Con->prepareStatement("SELECT * FROM UIDs WHERE MapId=(?)")); 35 | pstmt->setInt(1, mapID); 36 | std::unique_ptr res(pstmt->executeQuery()); 37 | return res->rowsCount(); 38 | } 39 | 40 | std::uint32_t getGUIDFromDB(std::size_t mapID) 41 | { 42 | auto Con(connect()); 43 | std::unique_ptr pstmt(Con->prepareStatement("SELECT UID FROM UIDs WHERE MapId=(?)")); 44 | pstmt->setInt(1, mapID); 45 | std::unique_ptr res(pstmt->executeQuery()); 46 | 47 | std::uint32_t highGUID(0); 48 | if (res->rowsCount() == 0) 49 | { 50 | return 0; 51 | } 52 | while (res->next()) 53 | { 54 | highGUID = res->getInt(1); 55 | } 56 | 57 | return highGUID; 58 | } 59 | 60 | void insertUIDinDB(std::size_t mapID, std::uint32_t NewUID) 61 | { 62 | auto Con(connect()); 63 | std::unique_ptr pstmt(Con->prepareStatement("INSERT INTO UIDs SET MapId=(?), UID=(?)")); 64 | pstmt->setInt(1, mapID); 65 | pstmt->setInt(2, NewUID); 66 | pstmt->executeUpdate(); 67 | } 68 | 69 | void updateUIDinDB (std::size_t mapID, std::uint32_t NewUID) 70 | { 71 | auto Con(connect()); 72 | std::unique_ptr pstmt(Con->prepareStatement("UPDATE UIDs SET UID=(?) WHERE MapId=(?)")); 73 | pstmt->setInt(1, NewUID); 74 | pstmt->setInt(2, mapID); 75 | pstmt->executeUpdate(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/mysql/mysql.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace mysql 9 | { 10 | bool hasMaxUIDStoredDB(std::size_t mapID); 11 | std::uint32_t getGUIDFromDB(std::size_t mapID); 12 | void insertUIDinDB(std::size_t mapID, std::uint32_t NewUID); 13 | void updateUIDinDB (std::size_t mapID, std::uint32_t NewUID); 14 | }; 15 | -------------------------------------------------------------------------------- /src/noggit/AsyncLoader.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class AsyncLoader 15 | { 16 | public: 17 | // use regular pointer because unique_ptr was causing 18 | // a significant performance hit 19 | static AsyncLoader* instance; 20 | 21 | static void setup(int threads); 22 | 23 | //! Ownership is _not_ transferred. Call ensure_deletable to ensure 24 | //! that a previously enqueued object can be destroyed. 25 | void queue_for_load (AsyncObject*); 26 | 27 | void ensure_deletable (AsyncObject*); 28 | 29 | // wait until everything is loaded 30 | void wait_queue_empty(); 31 | 32 | AsyncLoader(int numThreads); 33 | ~AsyncLoader(); 34 | 35 | bool important_object_failed_loading() const { return _important_object_failed_loading; } 36 | void reset_object_fail() { _important_object_failed_loading = false; } 37 | 38 | private: 39 | void process(); 40 | 41 | std::mutex _guard; 42 | std::condition_variable _state_changed; 43 | std::atomic _stop; 44 | std::atomic _object_queued_count = { 0 }; 45 | std::array, (size_t)async_priority::count> _to_load; 46 | std::list _currently_loading; 47 | std::list _threads; 48 | bool _important_object_failed_loading = false; 49 | }; 50 | -------------------------------------------------------------------------------- /src/noggit/AsyncObject.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | enum class async_priority : int 13 | { 14 | high, 15 | medium, 16 | low, 17 | count 18 | }; 19 | 20 | class AsyncObject 21 | { 22 | private: 23 | bool _loading_failed = false; 24 | protected: 25 | std::atomic finished = {false}; 26 | std::mutex _mutex; 27 | std::condition_variable _state_changed; 28 | 29 | AsyncObject(std::string filename_) : filename(filename_) {} 30 | 31 | public: 32 | std::string const filename; 33 | 34 | AsyncObject() = delete; 35 | virtual ~AsyncObject() = default; 36 | 37 | virtual bool finishedLoading() const 38 | { 39 | return finished.load(); 40 | } 41 | 42 | bool loading_failed() const 43 | { 44 | return _loading_failed; 45 | } 46 | 47 | void wait_until_loaded() 48 | { 49 | if (finished.load()) 50 | { 51 | return; 52 | } 53 | 54 | std::unique_lock lock (_mutex); 55 | 56 | _state_changed.wait 57 | ( lock 58 | , [&] 59 | { 60 | return finished.load(); 61 | } 62 | ); 63 | } 64 | 65 | void error_on_loading() 66 | { 67 | LogError << filename << " could not be loaded" << std::endl; 68 | _loading_failed = true; 69 | finished = true; 70 | _state_changed.notify_all(); 71 | } 72 | 73 | virtual bool is_required_when_saving() const 74 | { 75 | return false; 76 | } 77 | 78 | virtual async_priority loading_priority() const 79 | { 80 | return async_priority::medium; 81 | } 82 | 83 | virtual void finishLoading() = 0; 84 | }; 85 | -------------------------------------------------------------------------------- /src/noggit/Brush.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | Brush::Brush(float radius, float inner_ratio) 6 | : _radius(radius) 7 | , _inner_ratio(inner_ratio) 8 | { 9 | update_values(); 10 | } 11 | 12 | void Brush::set_inner_ratio(float ratio) 13 | { 14 | _inner_ratio = ratio; 15 | update_values(); 16 | } 17 | void Brush::set_radius(float radius) 18 | { 19 | _radius = radius; 20 | update_values(); 21 | } 22 | 23 | float Brush::value_at_dist(float dist) const 24 | { 25 | if (dist > _radius) 26 | { 27 | return 0.0f; 28 | } 29 | if (dist < _inner_size) 30 | { 31 | return 1.0f; 32 | } 33 | 34 | // lerp from the start of the inner part to the radius 35 | return 1.0f - ((dist - _inner_size) / _outer_size); 36 | } 37 | 38 | void Brush::update_values() 39 | { 40 | _inner_size = _inner_ratio * _radius; 41 | _outer_size = _radius - _inner_size; 42 | } 43 | -------------------------------------------------------------------------------- /src/noggit/Brush.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | class Brush 6 | { 7 | public: 8 | Brush(float radius = 15.f, float inner_radius_ratio = 0.5f); 9 | 10 | void set_inner_ratio(float ratio); 11 | void set_radius(float radius); 12 | float get_inner_ratio() const { return _inner_ratio; } 13 | float get_radius() const { return _radius; } 14 | float get_inner_radius() const { return _inner_size; } 15 | 16 | float value_at_dist(float dist) const; 17 | 18 | private: 19 | void update_values(); 20 | 21 | float _radius; 22 | float _inner_ratio; 23 | float _inner_size; 24 | float _outer_size; 25 | }; 26 | -------------------------------------------------------------------------------- /src/noggit/DBCFile.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | DBCFile::DBCFile(const std::string& _filename) 10 | : filename(_filename) 11 | {} 12 | 13 | void DBCFile::open() 14 | { 15 | MPQFile f (filename); 16 | 17 | if (f.isEof()) 18 | { 19 | LogError << "The DBC file \"" << filename << "\" could not be opened. This application may crash soon as the file is most likely needed." << std::endl; 20 | return; 21 | } 22 | LogDebug << "Opening DBC \"" << filename << "\"" << std::endl; 23 | 24 | char header[4]; 25 | 26 | f.read(header, 4); // Number of records 27 | assert(header[0] == 'W' && header[1] == 'D' && header[2] == 'B' && header[3] == 'C'); 28 | f.read(&recordCount, 4); 29 | f.read(&fieldCount, 4); 30 | f.read(&recordSize, 4); 31 | f.read(&stringSize, 4); 32 | 33 | if (fieldCount * 4 != recordSize) 34 | { 35 | throw std::logic_error ("non four-byte-columns not supported"); 36 | } 37 | 38 | data.resize (recordSize * recordCount); 39 | f.read (data.data(), data.size()); 40 | 41 | stringTable.resize (stringSize); 42 | f.read (stringTable.data(), stringTable.size()); 43 | 44 | f.close(); 45 | } 46 | -------------------------------------------------------------------------------- /src/noggit/Log.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | std::ostream& _LogError(const char * pFile, int pLine) 10 | { 11 | return std::cerr << clock() * 1000 / CLOCKS_PER_SEC << " - (" << ((strrchr(pFile, '/') ? strrchr(pFile, '/') : (strrchr(pFile, '\\') ? strrchr(pFile, '\\') : pFile - 1)) + 1) << ":" << pLine << "): [Error] "; 12 | } 13 | std::ostream& _LogDebug(const char * pFile, int pLine) 14 | { 15 | return std::clog << clock() * 1000 / CLOCKS_PER_SEC << " - (" << ((strrchr(pFile, '/') ? strrchr(pFile, '/') : (strrchr(pFile, '\\') ? strrchr(pFile, '\\') : pFile - 1)) + 1) << ":" << pLine << "): [Debug] "; 16 | } 17 | std::ostream& _Log(const char * pFile, int pLine) 18 | { 19 | return std::cout << clock() * 1000 / CLOCKS_PER_SEC << " - (" << ((strrchr(pFile, '/') ? strrchr(pFile, '/') : (strrchr(pFile, '\\') ? strrchr(pFile, '\\') : pFile - 1)) + 1) << ":" << pLine << "): "; 20 | } 21 | 22 | #if DEBUG__LOGGINGTOCONSOLE 23 | void InitLogging() 24 | { 25 | LogDebug << "Logging to console window." << std::endl; 26 | } 27 | #else 28 | namespace 29 | { 30 | std::ofstream gLogStream; 31 | } 32 | void InitLogging() 33 | { 34 | // Set up log. 35 | gLogStream.open("log.txt", std::ios_base::out | std::ios_base::trunc); 36 | if (gLogStream) 37 | { 38 | std::cout.rdbuf(gLogStream.rdbuf()); 39 | std::clog.rdbuf(gLogStream.rdbuf()); 40 | std::cerr.rdbuf(gLogStream.rdbuf()); 41 | } 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /src/noggit/Log.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | std::ostream& _LogError(const char * pFile, int pLine); 8 | std::ostream& _LogDebug(const char * pFile, int pLine); 9 | std::ostream& _Log(const char * pFile, int pLine); 10 | 11 | #define LogError _LogError( __FILE__, __LINE__ ) 12 | #define LogDebug _LogDebug( __FILE__, __LINE__ ) 13 | #define NOGGIT_LOG _Log( __FILE__, __LINE__ ) 14 | 15 | void InitLogging(); 16 | -------------------------------------------------------------------------------- /src/noggit/ModelManager.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include // AsyncLoader 4 | #include // LogDebug 5 | #include // Model 6 | #include // ModelManager 7 | 8 | #include 9 | 10 | namespace 11 | { 12 | std::string normalized_filename (std::string filename) 13 | { 14 | filename = noggit::mpq::normalized_filename (filename); 15 | 16 | std::size_t found; 17 | if ((found = filename.rfind (".mdx")) != std::string::npos) 18 | { 19 | filename.replace(found, 4, ".m2"); 20 | } 21 | else if ((found = filename.rfind (".mdl")) != std::string::npos) 22 | { 23 | filename.replace(found, 4, ".m2"); 24 | } 25 | 26 | return filename; 27 | } 28 | } 29 | 30 | decltype (ModelManager::_) ModelManager::_ {normalized_filename}; 31 | 32 | void ModelManager::report() 33 | { 34 | std::string output = "Still in the Model manager:\n"; 35 | _.apply ( [&] (std::string const& key, Model const&) 36 | { 37 | output += " - " + key + "\n"; 38 | } 39 | ); 40 | LogDebug << output; 41 | } 42 | 43 | void ModelManager::resetAnim() 44 | { 45 | _.apply ( [&] (std::string const&, Model& model) 46 | { 47 | model.animcalc = false; 48 | } 49 | ); 50 | } 51 | 52 | void ModelManager::updateEmitters(float dt) 53 | { 54 | _.apply ( [&] (std::string const&, Model& model) 55 | { 56 | model.updateEmitters (dt); 57 | } 58 | ); 59 | } 60 | 61 | void ModelManager::clear_hidden_models() 62 | { 63 | _.apply ( [&] (std::string const&, Model& model) 64 | { 65 | model.show(); 66 | } 67 | ); 68 | } 69 | -------------------------------------------------------------------------------- /src/noggit/ModelManager.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class Model; 13 | 14 | class ModelManager 15 | { 16 | public: 17 | static void resetAnim(); 18 | static void updateEmitters(float dt); 19 | static void clear_hidden_models(); 20 | 21 | static void report(); 22 | 23 | private: 24 | friend struct scoped_model_reference; 25 | static noggit::async_object_multimap_with_normalized_key _; 26 | }; 27 | 28 | struct scoped_model_reference 29 | { 30 | scoped_model_reference (std::string const& filename) 31 | : _valid (true) 32 | , _filename (filename) 33 | , _model (ModelManager::_.emplace (_filename)) 34 | {} 35 | 36 | scoped_model_reference (scoped_model_reference const& other) 37 | : _valid (other._valid) 38 | , _filename (other._filename) 39 | , _model (ModelManager::_.emplace (_filename)) 40 | {} 41 | scoped_model_reference& operator= (scoped_model_reference const& other) 42 | { 43 | _valid = other._valid; 44 | _filename = other._filename; 45 | _model = ModelManager::_.emplace (_filename); 46 | return *this; 47 | } 48 | 49 | scoped_model_reference (scoped_model_reference&& other) 50 | : _valid (other._valid) 51 | , _filename (other._filename) 52 | , _model (other._model) 53 | { 54 | other._valid = false; 55 | } 56 | scoped_model_reference& operator= (scoped_model_reference&& other) 57 | { 58 | std::swap (_valid, other._valid); 59 | std::swap (_filename, other._filename); 60 | std::swap (_model, other._model); 61 | other._valid = false; 62 | return *this; 63 | } 64 | 65 | ~scoped_model_reference() 66 | { 67 | if (_valid) 68 | { 69 | ModelManager::_.erase (_filename); 70 | } 71 | } 72 | 73 | Model* operator->() const 74 | { 75 | return _model; 76 | } 77 | Model* get() const 78 | { 79 | return _model; 80 | } 81 | 82 | private: 83 | bool _valid; 84 | std::string _filename; 85 | Model* _model; 86 | }; 87 | -------------------------------------------------------------------------------- /src/noggit/Selection.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class ModelInstance; 12 | class WMOInstance; 13 | class MapChunk; 14 | class liquid_layer; 15 | 16 | struct selected_chunk_type 17 | { 18 | selected_chunk_type(MapChunk* _chunk, std::tuple _triangle, math::vector_3d _position) 19 | : chunk(_chunk) 20 | , triangle(_triangle) 21 | , position(_position) 22 | {} 23 | 24 | MapChunk* chunk; 25 | std::tuple triangle; // mVertices[i] points of the hit triangle 26 | math::vector_3d position; 27 | 28 | bool operator== (selected_chunk_type const& other) const 29 | { 30 | return chunk == other.chunk; 31 | } 32 | }; 33 | 34 | struct selected_liquid_layer_type 35 | { 36 | selected_liquid_layer_type(liquid_layer* layer, std::tuple triangle, math::vector_3d position, int liquid_id) 37 | : layer(layer) 38 | , triangle(triangle) 39 | , position(position) 40 | , liquid_id(liquid_id) 41 | { 42 | 43 | } 44 | 45 | bool operator== (selected_liquid_layer_type const& other) const 46 | { 47 | return layer == other.layer; 48 | } 49 | 50 | liquid_layer* layer; 51 | std::tuple triangle; 52 | math::vector_3d position; 53 | int liquid_id; 54 | }; 55 | 56 | using selected_model_type = ModelInstance*; 57 | using selected_wmo_type = WMOInstance*; 58 | using selection_type = std::variant < selected_model_type 59 | , selected_wmo_type 60 | , selected_chunk_type 61 | , selected_liquid_layer_type 62 | >; 63 | //! \note Keep in same order as variant! 64 | enum eSelectionEntryTypes 65 | { 66 | eEntry_Model, 67 | eEntry_WMO, 68 | eEntry_MapChunk, 69 | eEntry_LiquidLayer 70 | }; 71 | 72 | using selection_entry = std::pair; 73 | using selection_result = std::vector; 74 | -------------------------------------------------------------------------------- /src/noggit/alphamap.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | class Alphamap 12 | { 13 | public: 14 | Alphamap(); 15 | Alphamap(MPQFile* f, unsigned int flags, bool use_big_alphamaps, bool do_not_fix_alpha_map); 16 | 17 | void setAlpha(size_t offset, std::uint8_t value); 18 | void setAlpha(const std::uint8_t *pAmap); 19 | 20 | std::uint8_t getAlpha(size_t offset) const; 21 | const std::uint8_t *getAlpha(); 22 | 23 | std::vector compress() const; 24 | 25 | private: 26 | void readCompressed(MPQFile *f); 27 | void readBigAlpha(MPQFile *f); 28 | void readNotCompressed(MPQFile *f, bool do_not_fix_alpha_map); 29 | 30 | void reset(); 31 | 32 | std::array amap; 33 | }; 34 | -------------------------------------------------------------------------------- /src/noggit/bookmarks.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace noggit 13 | { 14 | void bookmark_manager::reload() 15 | { 16 | _bookmarks.clear(); 17 | 18 | std::ifstream f("bookmarks.txt"); 19 | if (!f.is_open()) 20 | { 21 | LogDebug << "No bookmarks file." << std::endl; 22 | return; 23 | } 24 | 25 | bookmark b; 26 | 27 | while (f >> b.map_id >> b.pos.x >> b.pos.y >> b.pos.z >> b.camera_yaw >> b.camera_pitch >> b.area_id) 28 | { 29 | if (b.map_id == -1) 30 | { 31 | continue; 32 | } 33 | 34 | std::stringstream name; 35 | name << MapDB::getMapName(b.map_id) << ": " << AreaDB::getAreaName(b.area_id); 36 | b.name = name.str(); 37 | 38 | _bookmarks.push_back(b); 39 | } 40 | 41 | f.close(); 42 | } 43 | 44 | bookmark const& bookmark_manager::add(math::vector_3d const& pos, math::degrees yaw, math::degrees pitch, std::uint32_t map, std::uint32_t area) 45 | { 46 | bookmark b; 47 | 48 | b.map_id = map; 49 | b.area_id = area; 50 | b.pos = pos; 51 | b.camera_yaw = yaw._; 52 | b.camera_pitch = pitch._; 53 | 54 | std::stringstream name; 55 | name << MapDB::getMapName(b.map_id) << ": " << AreaDB::getAreaName(b.area_id); 56 | b.name = name.str(); 57 | 58 | _bookmarks.push_back(b); 59 | 60 | std::ofstream f ("bookmarks.txt", std::ios_base::app); 61 | f << map << " " 62 | << pos.x << " " 63 | << pos.y << " " 64 | << pos.z << " " 65 | << yaw._ << " " 66 | << pitch._ << " " 67 | << area << std::endl; 68 | 69 | return *_bookmarks.rbegin(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/noggit/bookmarks.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace noggit 13 | { 14 | struct bookmark 15 | { 16 | std::uint32_t map_id; 17 | std::uint32_t area_id; 18 | std::string name; 19 | math::vector_3d pos; 20 | float camera_yaw; 21 | float camera_pitch; 22 | }; 23 | 24 | class bookmark_manager 25 | { 26 | public: 27 | void reload(); 28 | bookmark const& add(math::vector_3d const& pos, math::degrees yaw, math::degrees pitch, std::uint32_t map, std::uint32_t area); 29 | std::vector const& bookmarks() const { return _bookmarks; } 30 | 31 | static bookmark_manager& instance() 32 | { 33 | static bookmark_manager inst; 34 | return inst; 35 | } 36 | private: 37 | bookmark_manager() {} 38 | 39 | std::vector _bookmarks; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /src/noggit/bool_toggle_property.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | struct bool_toggle_property : QObject 10 | { 11 | private: 12 | Q_OBJECT 13 | 14 | bool _value; 15 | 16 | signals: 17 | void changed (bool); 18 | 19 | public slots: 20 | void set (bool v) 21 | { 22 | if (_value != v) 23 | { 24 | _value = v; 25 | emit changed (v); 26 | } 27 | } 28 | bool get() const 29 | { 30 | return _value; 31 | } 32 | void toggle() 33 | { 34 | set(!_value); 35 | } 36 | public: 37 | bool_toggle_property (bool value) 38 | : _value (value) 39 | {} 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /src/noggit/camera.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | //! \todo there should be a seperate class for tile mode 10 | class camera 11 | { 12 | public: 13 | camera ( math::vector_3d const& position 14 | , math::degrees yaw_ 15 | , math::degrees pitch_ 16 | ); 17 | 18 | math::degrees yaw() const; 19 | math::degrees yaw (math::degrees); 20 | void add_to_yaw (math::degrees); 21 | 22 | math::degrees pitch() const; 23 | math::degrees pitch (math::degrees); 24 | void add_to_pitch (math::degrees); 25 | 26 | math::degrees roll() const; 27 | math::degrees roll(math::degrees); 28 | void add_to_roll(math::degrees); 29 | 30 | math::radians fov() const; 31 | 32 | math::vector_3d look_at() const; 33 | math::vector_3d direction() const; 34 | math::vector_3d up() const; 35 | math::vector_3d right() const; 36 | 37 | math::matrix_4x4 look_at_matrix() const; 38 | 39 | void move_forward (float sign, float dt); 40 | void move_horizontal (float sign, float dt); 41 | void move_vertical (float sign, float dt, bool local_space); 42 | 43 | math::vector_3d position; 44 | float move_speed; 45 | 46 | private: 47 | math::degrees _roll; // this is not used currently 48 | math::degrees _yaw; 49 | math::degrees _pitch; 50 | math::radians _fov; 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /src/noggit/chunk_mover.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wowdev/noggit3/28c1a0405ec12fd2a7b563c08b6a418bfc2fab23/src/noggit/chunk_mover.cpp -------------------------------------------------------------------------------- /src/noggit/cursor_render.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace noggit 13 | { 14 | class cursor_render 15 | { 16 | public: 17 | enum class mode : int 18 | { 19 | circle, 20 | sphere, 21 | square, 22 | cube, 23 | mode_count 24 | }; 25 | 26 | void draw(mode cursor_mode, math::matrix_4x4 const& mvp, math::vector_4d color, math::vector_3d const& pos, float radius, float inner_radius_ratio = 0.f); 27 | 28 | private: 29 | bool _uploaded = false; 30 | 31 | void upload(); 32 | void create_circle_buffer(opengl::scoped::use_program& shader); 33 | void create_sphere_buffer(opengl::scoped::use_program& shader); 34 | void create_square_buffer(opengl::scoped::use_program& shader); 35 | void create_cube_buffer(opengl::scoped::use_program& shader); 36 | 37 | opengl::scoped::deferred_upload_vertex_arrays<(int)mode::mode_count> _vaos; 38 | opengl::scoped::deferred_upload_buffers<(int)mode::mode_count * 2> _vbos; 39 | 40 | std::map _indices_count; 41 | 42 | std::unique_ptr _cursor_program; 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /src/noggit/errorHandling.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | namespace noggit 6 | { 7 | void RegisterErrorHandlers(); 8 | void printStacktrace(); 9 | } 10 | -------------------------------------------------------------------------------- /src/noggit/float_property.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | struct float_property : QObject 10 | { 11 | private: 12 | Q_OBJECT 13 | 14 | float _value; 15 | 16 | signals: 17 | void changed (float); 18 | 19 | public slots: 20 | void set (float v) 21 | { 22 | if (_value != v) 23 | { 24 | _value = v; 25 | emit changed (v); 26 | } 27 | } 28 | void change(float v) 29 | { 30 | _value += v; 31 | emit changed(_value); 32 | } 33 | float get() const 34 | { 35 | return _value; 36 | } 37 | 38 | public: 39 | float_property (float value) 40 | : _value (value) 41 | {} 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /src/noggit/liquid_render.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | struct liquid_layer_ubo_data 19 | { 20 | int liquid_type; 21 | int array_id; 22 | int id_start_in_array; 23 | int texture_count; 24 | math::vector_4d param; // only x,y are used, rest is padding 25 | }; 26 | 27 | class liquid_render 28 | { 29 | public: 30 | liquid_render() = default; 31 | 32 | opengl::program const& shader_program() const 33 | { 34 | return program; 35 | } 36 | 37 | liquid_layer_ubo_data ubo_data(int liquid_id); 38 | void bind_arrays(); 39 | int array_count() const { return _texture_arrays.size(); } 40 | private: 41 | 42 | opengl::program program 43 | { { GL_VERTEX_SHADER, opengl::shader::src_from_qrc("liquid_vs") } 44 | , { GL_FRAGMENT_SHADER, opengl::shader::src_from_qrc("liquid_fs") } 45 | }; 46 | 47 | std::map _liquid_id_types; 48 | std::map _float_param_by_liquid_id; 49 | 50 | std::map _liquids_ubo_data; 51 | // todo: make sure it doesn't go over the shader's array size 52 | std::vector _texture_arrays; 53 | std::vector _arrays_format; 54 | std::map _textures_used_per_array; 55 | 56 | // most liquids have 30 textures 57 | static constexpr int textures_per_array = 60; 58 | }; 59 | -------------------------------------------------------------------------------- /src/noggit/map_enums.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | enum class tile_mode 6 | { 7 | // regular mode 8 | edit, 9 | // uid fix mode, ignore/change loading and saving to 10 | // reduce the uid fix all time 11 | uid_fix_all 12 | }; 13 | 14 | enum class model_update 15 | { 16 | add, 17 | remove, 18 | // only model update that doesn't require to update the bounding boxes 19 | doodadset 20 | }; 21 | -------------------------------------------------------------------------------- /src/noggit/map_horizon.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | 17 | class MapIndex; 18 | 19 | namespace noggit 20 | { 21 | 22 | struct map_horizon_tile 23 | { 24 | int16_t height_17[17][17]; 25 | int16_t height_16[16][16]; 26 | }; 27 | 28 | struct map_horizon_batch 29 | { 30 | map_horizon_batch () 31 | : vertex_start (0) 32 | , vertex_count (0) 33 | {} 34 | 35 | map_horizon_batch (uint32_t _vertex_start, uint32_t _vertex_count) 36 | : vertex_start(_vertex_start) 37 | , vertex_count(_vertex_count) 38 | {} 39 | 40 | uint32_t vertex_start; 41 | uint32_t vertex_count; 42 | }; 43 | 44 | class map_horizon 45 | { 46 | public: 47 | struct render 48 | { 49 | render(const map_horizon& horizon); 50 | 51 | void draw( math::matrix_4x4 const& model_view 52 | , math::matrix_4x4 const& projection 53 | , MapIndex *index 54 | , const math::vector_3d& color 55 | , const float& cull_distance 56 | , const math::frustum& frustum 57 | , const math::vector_3d& camera 58 | , display_mode display 59 | ); 60 | 61 | map_horizon_batch _batches[64][64]; 62 | 63 | opengl::scoped::deferred_upload_vertex_arrays<1> _vaos; 64 | GLuint const& _vao = _vaos[0]; 65 | opengl::scoped::buffers<2> _buffers; 66 | GLuint const& _index_buffer = _buffers[0]; 67 | GLuint const& _vertex_buffer = _buffers[1]; 68 | std::unique_ptr _map_horizon_program; 69 | }; 70 | 71 | class minimap : public opengl::texture 72 | { 73 | public: 74 | minimap(const map_horizon& horizon); 75 | }; 76 | 77 | map_horizon(const std::string& basename, const MapIndex * const index); 78 | 79 | QImage _qt_minimap; 80 | 81 | private: 82 | std::string _filename; 83 | 84 | std::unique_ptr _tiles[64][64]; 85 | }; 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/noggit/moveable_object_group.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace noggit 14 | { 15 | class moveable_object_group : public moveable_object 16 | { 17 | public: 18 | moveable_object_group() : moveable_object(math::vector_3d(), math::degrees::vec3()) {} 19 | 20 | using moveable_object::move; 21 | 22 | virtual void move(math::vector_3d const& pos_dt, World* world) override; 23 | virtual void rotate(math::degrees::vec3 const& rotation, World* world, bool local) override; 24 | 25 | bool add_object(moveable_object* object); 26 | bool remove_object(moveable_object* object); 27 | bool object_is_grouped(moveable_object* object); 28 | 29 | void reset_xz_rotation(World* world); 30 | 31 | void update_center(); 32 | void reset(); 33 | 34 | math::vector_3d local_forward() const; 35 | math::vector_3d local_up() const; 36 | math::vector_3d local_right() const; 37 | 38 | int object_count() const { return _objects.size(); } 39 | std::optional pivot() const; 40 | 41 | private: 42 | std::vector _objects; 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_chunk.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace noggit 10 | { 11 | namespace scripting 12 | { 13 | class script_context; 14 | class selection; 15 | class tex; 16 | class vert; 17 | class chunk: public script_object 18 | { 19 | public: 20 | chunk(script_context * ctx, MapChunk* chunk); 21 | void remove_texture(int index); 22 | std::string get_texture(int index); 23 | int get_effect(int index); 24 | void set_effect(int index, int effectID); 25 | int add_texture(std::string const& texture, int effectID /* = -2*/); 26 | int add_texture_1(std::string const& texture) 27 | { return add_texture(texture,-2);} 28 | int get_texture_count(); 29 | void clear_textures(); 30 | void set_hole(bool hole); 31 | void clear_colors(); 32 | void apply_textures(); 33 | void apply_heightmap(); 34 | void apply_vertex_color(); 35 | void apply_all(); 36 | 37 | void set_deep_flag(std::uint32_t low, std::uint32_t high); 38 | void set_deep_flag_1(std::uint32_t low); 39 | std::uint32_t get_deep_flag(); 40 | std::uint32_t get_deep_flag_high(); 41 | 42 | void set_fishable_flag(std::uint32_t low, std::uint32_t high); 43 | void set_fishable_flag_1(std::uint32_t low); 44 | std::uint32_t get_fishable_flag(); 45 | std::uint32_t get_fishable_flag_high(); 46 | bool has_render_flags(); 47 | 48 | void set_impassable(bool add); 49 | int get_area_id(); 50 | void set_area_id(int value); 51 | tex get_tex(int index); 52 | vert get_vert(int index); 53 | std::shared_ptr to_selection(); 54 | private: 55 | MH2O_Attributes getRenderOrDefault(); 56 | MH2O_Attributes& getOrCreateRender(); 57 | MapChunk* _chunk; 58 | friend class selection; 59 | }; 60 | 61 | void register_chunk(script_context * state); 62 | } // namespace scripting 63 | } // namespace noggit -------------------------------------------------------------------------------- /src/noggit/scripting/script_context.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class World; 13 | 14 | namespace noggit 15 | { 16 | class camera; 17 | namespace scripting 18 | { 19 | class scripting_tool; 20 | 21 | class script_context: public sol::state 22 | { 23 | public: 24 | script_context(scripting_tool * tool); 25 | void select_script(int index); 26 | int get_selection(); 27 | World * world(); 28 | scripting_tool * tool(); 29 | std::string get_selected_name(); 30 | std::vector> &get_scripts(); 31 | sol::table require(std::string const& path); 32 | void execute_file(std::string const& filename); 33 | std::string file_to_module(std::string const& file); 34 | std::string module_to_file(std::string const& module); 35 | private: 36 | scripting_tool * _tool; 37 | std::vector> _scripts; 38 | std::map _modules; 39 | std::vector _file_stack; 40 | int _selected = -1; 41 | }; 42 | 43 | template 44 | class script_scoped_function 45 | { 46 | public: 47 | script_scoped_function( script_context *lua 48 | , std::string const &name 49 | , std::function fun 50 | ) 51 | : _lua(lua) 52 | , _name(name) 53 | { 54 | lua->set_function(name, fun); 55 | } 56 | 57 | script_scoped_function() 58 | { 59 | _lua->set_function(_name, nullptr); 60 | } 61 | private: 62 | script_context* _lua; 63 | std::string _name; 64 | }; 65 | } // namespace scripting 66 | } // namespace noggit -------------------------------------------------------------------------------- /src/noggit/scripting/script_exception.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace scripting 10 | { 11 | script_exception::script_exception(std::string const& funcName, std::string const& msg) 12 | : std::runtime_error(msg+" (in function "+funcName+")") 13 | { 14 | // TEMP: remove when exceptions are working 15 | if(msg.find("C++ exception") != 0) 16 | { 17 | set_cur_exception(std::string(what())); 18 | } 19 | } 20 | } // namespace scripting 21 | } // namespace noggit 22 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_exception.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace scripting 10 | { 11 | class script_exception : public std::runtime_error 12 | { 13 | public: 14 | script_exception(std::string const& funcName, std::string const& msg); 15 | }; 16 | } // namespace scripting 17 | } // namespace noggit 18 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_filesystem.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace scripting 10 | { 11 | class script_context; 12 | class scripting_tool; 13 | namespace fs = std::filesystem; 14 | std::filesystem::path get_writable_path(std::string const& caller, script_context * state, std::string const& path); 15 | void write_file(script_context * ctx, std::string const& path, std::string const& content); 16 | void append_file(script_context * ctx, std::string const& path, std::string const& content); 17 | std::string read_file(std::string const& path); 18 | bool path_exists(std::string const& path); 19 | void register_filesystem(script_context * state); 20 | void mkdirs(std::string const& path); 21 | } // namespace scripting 22 | } // namespace noggit 23 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_global.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | namespace noggit { 7 | namespace scripting { 8 | class scripting_tool; 9 | class script_context; 10 | void register_global(script_context * state); 11 | } 12 | } -------------------------------------------------------------------------------- /src/noggit/scripting/script_image.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace noggit 11 | { 12 | namespace scripting 13 | { 14 | class scripting_tool; 15 | class script_context; 16 | class image: public script_object 17 | { 18 | public: 19 | image(script_context * ctx, std::string const& path); 20 | image(script_context * ctx, int width, int height); 21 | std::vector _image; 22 | int get_index(int x, int y) const; 23 | unsigned get_pixel(int x, int y) const; 24 | float gradient_scale(float rel) const; 25 | void set_pixel(int x, int y, unsigned value); 26 | void set_pixel_floats(int x, int y, float r, float g, float b, float a /*= 1.0*/); 27 | void set_pixel_floats_1(int x, int y, float r, float g, float b) 28 | { 29 | set_pixel_floats(x,y,r,g,b,1.0); 30 | } 31 | void save(std::string const& filename); 32 | int width() const; 33 | int height() const; 34 | float get_blue(int x, int y) const; 35 | float get_green(int x, int y) const; 36 | float get_red(int x, int y) const; 37 | float get_alpha(int x, int y) const; 38 | private: 39 | void resize(int width, int height); 40 | unsigned char const * get_image() const {return _image.data();} 41 | unsigned char * get_image_w() {return _image.data();} 42 | unsigned _width = 0; 43 | unsigned _height = 0; 44 | unsigned _size = 0; 45 | }; 46 | 47 | void register_image(script_context * state); 48 | } // namespace scripting 49 | } // namespace noggit 50 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_math.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace noggit 10 | { 11 | namespace scripting 12 | { 13 | class scripting_tool; 14 | class script_context; 15 | int round(float a1); 16 | float pow(float a1, float a2); 17 | float log10(float arg); 18 | float log(float arg); 19 | int ceil(float arg); 20 | int floor(float arg); 21 | float exp(float arg); 22 | float cbrt(float arg); 23 | float acosh(float arg); 24 | float asinh(float arg); 25 | float atanh(float arg); 26 | float cosh(float arg); 27 | float sinh(float arg); 28 | float tanh(float arg); 29 | float acos(float arg); 30 | float asin(float arg); 31 | float atan(float arg); 32 | float cos(float arg); 33 | float sin(float arg); 34 | float tan(float arg); 35 | float sqrt(float arg); 36 | float abs(float arg); 37 | float lerp(float from, float to, float amount); 38 | float dist_2d(math::vector_3d const& from, math::vector_3d const& to); 39 | int dist_2d_compare(math::vector_3d const& from, math::vector_3d const& to, float dist); 40 | math::vector_3d rotate_2d(math::vector_3d const& point, math::vector_3d const& origin, float angleDeg); 41 | 42 | void register_math(script_context * state); 43 | } // namespace scripting 44 | } // namespace noggit 45 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_model.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | class World; 11 | 12 | class ModelInstance; 13 | class WMOInstance; 14 | 15 | namespace noggit 16 | { 17 | namespace scripting 18 | { 19 | class scripting_tool; 20 | class script_context; 21 | class model : public script_object 22 | { 23 | public: 24 | model(script_context * ctx, ModelInstance* model); 25 | model(script_context * ctx, WMOInstance* model); 26 | 27 | math::vector_3d get_pos(); 28 | void set_pos(math::vector_3d& pos); 29 | 30 | math::vector_3d get_rot(); 31 | void set_rot(math::vector_3d& rot); 32 | 33 | float get_scale(); 34 | void set_scale(float scale); 35 | 36 | bool has_filename(std::string const& name); 37 | 38 | unsigned get_uid(); 39 | 40 | void remove(); 41 | 42 | std::string get_filename(); 43 | void replace(std::string const& filename); 44 | 45 | private: 46 | std::variant _impl; 47 | }; 48 | 49 | void collect_models( 50 | script_context * ctx 51 | , World * world 52 | , math::vector_3d const& min 53 | , math::vector_3d const& max 54 | , std::vector& vec 55 | ); 56 | 57 | void register_model(script_context * state); 58 | } // namespace scripting 59 | } // namespace noggit 60 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_noise.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace noggit 15 | { 16 | namespace scripting 17 | { 18 | class script_context; 19 | class noisemap: public script_object 20 | { 21 | public: 22 | noisemap(script_context * ctx 23 | , unsigned start_x 24 | , unsigned start_y 25 | , unsigned width 26 | , unsigned height 27 | , float frequency 28 | , std::string const& algorithm 29 | , std::string const& seed); 30 | 31 | float get(math::vector_3d &pos); 32 | bool is_highest(math::vector_3d &pos, int check_radius); 33 | void set(int x, int y, float value); 34 | math::vector_3d start(); 35 | unsigned width(); 36 | unsigned height(); 37 | 38 | private: 39 | std::vector _noise; 40 | float get_index(std::string const& caller, int x, int y); 41 | float *get_map() { return _noise.data(); }; 42 | unsigned _width; 43 | unsigned _height; 44 | unsigned _start_x; 45 | unsigned _start_y; 46 | unsigned _size; 47 | }; 48 | 49 | std::shared_ptr make_noise( 50 | script_context * ctx 51 | , int start_x 52 | , int start_y 53 | , int width 54 | , int height 55 | , float frequency 56 | , std::string const& algorithm 57 | , std::string const& seed); 58 | 59 | void register_noise(script_context * state); 60 | } // namespace scripting 61 | } // namespace noggit 62 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_object.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace noggit { 9 | namespace scripting { 10 | script_object::script_object(script_context * state) 11 | : _state(state) 12 | {} 13 | 14 | sol::object script_object::set(const std::string& key, sol::stack_object obj) 15 | { 16 | initialize_table(); 17 | _table[key] = obj; 18 | return obj; 19 | } 20 | 21 | bool script_object::has_table() 22 | { 23 | return _initialized; 24 | } 25 | 26 | World * script_object::world() 27 | { 28 | return _state->world(); 29 | } 30 | 31 | void script_object::initialize_table() 32 | { 33 | if(!_initialized) 34 | { 35 | _table = _state->create_table(); 36 | _initialized = true; 37 | } 38 | } 39 | 40 | sol::object script_object::get(const std::string& key) 41 | { 42 | initialize_table(); 43 | return _table[key]; 44 | } 45 | 46 | sol::table script_object::table() 47 | { 48 | initialize_table(); 49 | return _table; 50 | } 51 | 52 | script_context * script_object::state() 53 | { 54 | return _state; 55 | } 56 | 57 | scripting_tool * script_object::tool() 58 | { 59 | return _state->tool(); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /src/noggit/scripting/script_object.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | 8 | class World; 9 | 10 | namespace noggit { 11 | namespace scripting { 12 | class script_context; 13 | class scripting_tool; 14 | 15 | class script_object { 16 | public: 17 | // TODO: We can probably get this in a more intelligent way 18 | script_object(script_context * state); 19 | virtual sol::object set(const std::string& key, sol::stack_object obj); 20 | virtual sol::object get(const std::string& key); 21 | 22 | script_context * state(); 23 | scripting_tool * tool(); 24 | World * world(); 25 | sol::table table(); 26 | bool has_table(); 27 | protected: 28 | sol::table _table; 29 | void initialize_table(); 30 | private: 31 | bool _initialized = false; 32 | script_context * _state; 33 | }; 34 | 35 | template 36 | class lua_function { 37 | public: 38 | lua_function(O * obj, std::string const& func) 39 | : _obj(obj) 40 | , _func(func) 41 | {} 42 | 43 | bool exists() 44 | { 45 | if (!_obj->has_table()) 46 | { 47 | return false; 48 | } 49 | 50 | auto fn = _obj->table()[_func]; 51 | if (!fn.valid()) 52 | { 53 | return false; 54 | } 55 | 56 | if (fn.get_type() == sol::type::function) 57 | { 58 | return true; 59 | } 60 | return false; 61 | } 62 | 63 | void call_if_exists(std::string caller, Ts...args) 64 | { 65 | if (exists()) call(caller, args...); 66 | } 67 | 68 | void call(std::string caller, Ts...args) 69 | { 70 | if(!exists()) 71 | { 72 | throw script_exception(caller,"calling null function"); 73 | } 74 | sol::protected_function fn = _obj->table()[_func]; 75 | auto ret = fn(_obj, args...); 76 | if (!ret.valid()) 77 | { 78 | sol::error err = ret; 79 | throw script_exception(caller, err.what()); 80 | } 81 | } 82 | private: 83 | O * _obj; 84 | std::string _func; 85 | }; 86 | 87 | #define LUA_MEMBER_FUNC(selftype, type,name) lua_function name = lua_function(this,#name); 88 | } 89 | } -------------------------------------------------------------------------------- /src/noggit/scripting/script_procedures.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace noggit { 11 | namespace scripting { 12 | void procedures::paint_texture( 13 | selection & sel 14 | , image const& img 15 | , int layer 16 | , float pressure 17 | , float angle 18 | ) 19 | { 20 | auto center = math::vector_3d(sel.min().x + (sel.max().x - sel.min().x) / 2, 0, sel.min().z + (sel.max().z - sel.min().z) / 2); 21 | auto outer_radius = (sel.max().x - sel.min().x) / 2; 22 | int width = img.width(); 23 | int height = img.height(); 24 | float half_width = float(width) / 2; 25 | float half_height = float(height) / 2; 26 | for (auto & tex : sel.textures_raw()) 27 | { 28 | auto global_pos = tex.get_pos_2d(); 29 | auto dist = dist_2d(global_pos, center) / outer_radius; 30 | global_pos = rotate_2d(global_pos, center, angle); 31 | 32 | auto rel_x = (global_pos.x - center.x) / outer_radius; 33 | auto rel_z = (global_pos.z - center.z) / outer_radius; 34 | 35 | if (!(rel_x < -1 || rel_x > 1 || rel_z < -1 || rel_z > 1)) 36 | { 37 | auto img_x = round(half_width + half_width * rel_x); 38 | auto img_z = round(half_height + half_height * rel_z); 39 | if (img_x >= 0 && img_x < width && img_z >= 0 && img_z < height) { 40 | auto old = tex.get_alpha(layer); 41 | tex.set_alpha(layer, old + (img.get_red(img_x, img_z) * pressure * (1 - dist))); 42 | } 43 | } 44 | } 45 | } 46 | 47 | void register_procedures(script_context* state) 48 | { 49 | state->new_usertype("procedures_class" 50 | , "paint_texture", &procedures::paint_texture 51 | ); 52 | state->set("procedures", procedures()); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/noggit/scripting/script_procedures.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | namespace noggit { 7 | namespace scripting { 8 | class selection; 9 | class image; 10 | class script_context; 11 | class procedures { 12 | public: 13 | void paint_texture( 14 | selection & sel 15 | , image const& image 16 | , int layer 17 | , float pressure 18 | , float angle 19 | ); 20 | }; 21 | 22 | void register_procedures(script_context * state); 23 | } 24 | } -------------------------------------------------------------------------------- /src/noggit/scripting/script_profiles.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace noggit { 12 | namespace scripting { 13 | class scripting_tool; 14 | class script_settings; 15 | 16 | class script_profiles : public QGroupBox { 17 | public: 18 | script_profiles(noggit::scripting::scripting_tool * tool); 19 | void select_profile(int profile); 20 | std::string get_cur_profile(); 21 | void clear(); 22 | void add_profile(std::string const& profile); 23 | int profile_count(); 24 | std::string get_profile(int index); 25 | private: 26 | noggit::scripting::scripting_tool* _tool; 27 | QGridLayout* _select_column; 28 | QComboBox* _selection; 29 | QLineEdit* _name_entry; 30 | QPushButton* _remove_button; 31 | QPushButton* _create_button; 32 | std::string _cur_profile; 33 | void on_change_script(int selection); 34 | void select_profile_gui(int profile); 35 | }; 36 | } 37 | } -------------------------------------------------------------------------------- /src/noggit/scripting/script_random.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | namespace noggit 10 | { 11 | namespace scripting 12 | { 13 | class scripting_tool; 14 | class script_context; 15 | class random: public script_object 16 | { 17 | public: 18 | random(script_context * state, unsigned seed); 19 | random(script_context * state, std::string const& seed); 20 | random(script_context * state); 21 | long integer(long low, long high); 22 | double real(double low, double high); 23 | private: 24 | std::minstd_rand _state; 25 | }; 26 | 27 | std::shared_ptr random_from_seed(script_context * state, std::string const& seed); 28 | std::shared_ptr random_from_time(script_context * state); 29 | 30 | void register_random(script_context * state); 31 | } // namespace scripting 32 | } // namespace noggit 33 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_registry.ipp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | namespace noggit { 24 | namespace scripting { 25 | namespace { 26 | void register_functions(script_context * lua) 27 | { 28 | // Register your functions / add registry functions here! 29 | register_script_brush(lua); 30 | register_model(lua); 31 | register_global(lua); 32 | register_vert(lua); 33 | register_tex(lua); 34 | register_chunk(lua); 35 | register_selection(lua); 36 | register_random(lua); 37 | register_noise(lua); 38 | register_math(lua); 39 | register_image(lua); 40 | register_filesystem(lua); 41 | register_standard_brush(lua); 42 | register_procedures(lua); 43 | register_settings(lua); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_selection.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | class MapChunk; 15 | class World; 16 | 17 | namespace noggit 18 | { 19 | namespace scripting 20 | { 21 | class script_context; 22 | class model_iterator; 23 | class vert_iterator; 24 | class tex_iterator; 25 | class noisemap; 26 | 27 | class selection: public script_object 28 | { 29 | public: 30 | selection( script_context * ctx 31 | , std::string const& caller 32 | , math::vector_3d const& point1 33 | , math::vector_3d const& point2 34 | ); 35 | 36 | std::shared_ptr make_noise( 37 | float frequency 38 | , std::string const& algorithm 39 | , std::string const& seed 40 | ); 41 | 42 | math::vector_3d center(); 43 | math::vector_3d min(); 44 | math::vector_3d max(); 45 | math::vector_3d size(); 46 | 47 | std::vector chunks_raw(); 48 | std::vector verts_raw(); 49 | std::vector textures_raw(); 50 | std::vector models_raw(); 51 | 52 | sol::as_table_t> chunks(); 53 | sol::as_table_t> verts(); 54 | sol::as_table_t> textures(); 55 | sol::as_table_t> models(); 56 | 57 | void apply(); 58 | 59 | private: 60 | World* _world; 61 | math::vector_3d _center; 62 | math::vector_3d _min; 63 | math::vector_3d _max; 64 | math::vector_3d _size; 65 | }; 66 | 67 | void register_selection(script_context * state); 68 | } // namespace scripting 69 | } // namespace noggit 70 | -------------------------------------------------------------------------------- /src/noggit/scripting/script_tex.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | class MapChunk; 10 | 11 | namespace noggit { 12 | namespace scripting { 13 | class scripting_tool; 14 | class script_context; 15 | 16 | class tex: public script_object 17 | { 18 | public: 19 | tex(script_context * ctx, MapChunk* chunk, int index); 20 | void set_alpha(int index, float alpha); 21 | float get_alpha(int index); 22 | math::vector_3d get_pos_2d(); 23 | 24 | private: 25 | MapChunk* _chunk; 26 | int _index; 27 | }; 28 | 29 | void collect_textures( 30 | script_context* ctx 31 | , MapChunk* chnk 32 | , std::vector& vec 33 | , math::vector_3d const& min 34 | , math::vector_3d const& max 35 | ); 36 | 37 | class tex_iterator : public script_object { 38 | public: 39 | tex_iterator( script_context * ctx 40 | , std::shared_ptr> chunks 41 | , math::vector_3d const& min 42 | , math::vector_3d const& max 43 | ); 44 | bool next(); 45 | tex get(); 46 | 47 | void paint_image(image & img, int layer, float pressure, float angle); 48 | 49 | private: 50 | int _tex_iter = -1; 51 | std::shared_ptr> _chunks; 52 | std::vector::iterator _chunk_iter; 53 | math::vector_3d const& _min; 54 | math::vector_3d const& _max; 55 | }; 56 | 57 | void register_tex(script_context * state); 58 | } 59 | } -------------------------------------------------------------------------------- /src/noggit/scripting/script_vert.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace noggit 11 | { 12 | namespace scripting 13 | { 14 | class scripting_tool; 15 | class script_context; 16 | 17 | class vert: public script_object 18 | { 19 | public: 20 | vert(script_context * ctx, MapChunk* chunk, int index); 21 | math::vector_3d get_pos(); 22 | void set_height(float y); 23 | void add_height(float y); 24 | void sub_height(float y); 25 | 26 | math::vector_3d get_color(); 27 | void set_color(float r, float g, float b); 28 | void set_water(int type, float height); 29 | void set_hole(bool add); 30 | void set_alpha(int index, float alpha); 31 | float get_alpha(int index); 32 | sol::as_table_t> textures(); 33 | bool is_water_aligned(); 34 | 35 | private: 36 | MapChunk* _chunk; 37 | int _index; 38 | }; 39 | 40 | void register_vert(script_context * state); 41 | } // namespace scripting 42 | } // namespace noggit 43 | -------------------------------------------------------------------------------- /src/noggit/settings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | class settings 10 | { 11 | public: 12 | settings() 13 | { 14 | values = std::make_unique("settings.ini", QSettings::Format::IniFormat); 15 | 16 | QString project_folder = values->value("project/path", "./").toString(); 17 | if (!(project_folder.endsWith('\\') || project_folder.endsWith('/'))) 18 | { 19 | project_folder += "/"; 20 | } 21 | 22 | values->setValue("project/path", project_folder); 23 | 24 | uids = std::make_unique(project_folder + "uid.ini", QSettings::Format::IniFormat); 25 | } 26 | 27 | QVariant value(const QString& key, const QVariant& default_value = QVariant()) const 28 | { 29 | return values->value(key, default_value); 30 | } 31 | 32 | void set_value(const QString& key, const QVariant& value) 33 | { 34 | values->setValue(key, value); 35 | } 36 | 37 | std::string project_path() 38 | { 39 | return values->value("project/path", "./").toString().toStdString(); 40 | } 41 | 42 | void sync() 43 | { 44 | values->sync(); 45 | } 46 | 47 | std::unique_ptr values; 48 | std::unique_ptr uids; 49 | 50 | static settings& instance() 51 | { 52 | static settings inst; 53 | return inst; 54 | } 55 | }; 56 | } 57 | 58 | #define NoggitSettings noggit::settings::instance() 59 | -------------------------------------------------------------------------------- /src/noggit/texture_array_handler.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace noggit 13 | { 14 | struct texture_infos 15 | { 16 | texture_infos(std::string const& filename) : tex(filename) {} 17 | 18 | scoped_blp_texture_reference tex; 19 | 20 | // array index, index inside array 21 | std::optional> pos_in_array; 22 | std::optional array_handle; 23 | 24 | bool ready() const { return pos_in_array.has_value(); } 25 | }; 26 | 27 | class texture_array_handler 28 | { 29 | public: 30 | texture_array_handler(int base_texture_unit) : _base_texture_unit(base_texture_unit) {} 31 | 32 | ~texture_array_handler(); 33 | 34 | void bind(); 35 | void bind_layer(int array_index, int texture_unit = 0); 36 | 37 | texture_infos const* get_texture_info(std::string const& normalized_filename); 38 | 39 | int array_count() const { return _texture_arrays.size(); } 40 | 41 | // todo: grab that info beforehand to have it on creation 42 | void set_max_array_size(int max_layer_count) { _max_layer_count = max_layer_count; } 43 | 44 | void upload_ready_textures(); 45 | private: 46 | std::optional> find_next_available_spot(int width, int height, GLuint format); 47 | 48 | 49 | // return the array's handle 50 | GLuint64 create_next_array(int width, int height, GLuint format); 51 | 52 | int _max_layer_count = 256; 53 | int _base_texture_unit; 54 | 55 | std::vector _texture_arrays; 56 | std::vector> _texture_size_for_array; 57 | std::vector _texture_count_in_array; 58 | std::vector _array_capacity; 59 | std::vector _array_format; 60 | 61 | std::map _textures_infos; 62 | 63 | std::vector _textures_to_upload; 64 | 65 | // todo: make that variable depending on size, and add the option to reupload an array 66 | // if there isn't enough space and 67 | // how many textures are stored per opengl::texture_array 68 | static constexpr int textures_per_array = 24; 69 | }; 70 | } 71 | -------------------------------------------------------------------------------- /src/noggit/tile_index.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | struct tile_index 9 | { 10 | tile_index(const math::vector_3d& pos) : tile_index(std::floor(pos.x / TILESIZE), std::floor(pos.z / TILESIZE)) { } 11 | tile_index(std::size_t tileX = 0, std::size_t tileZ = 0) : x(tileX), z(tileZ) { } 12 | 13 | friend bool operator== (tile_index const& lhs, tile_index const& rhs) 14 | { 15 | return std::tie (lhs.x, lhs.z) == std::tie (rhs.x, rhs.z); 16 | } 17 | 18 | bool is_valid() const 19 | { 20 | // x and z are unsigned so negative signed int value are positive and > 63 21 | return x < 64 && z < 64; 22 | } 23 | 24 | float dist(tile_index const& other) const 25 | { 26 | return (math::vector_3d(x, 0.f, z) - math::vector_3d(other.x, 0.f, other.z)).length(); 27 | } 28 | 29 | std::size_t x; 30 | std::size_t z; 31 | }; 32 | -------------------------------------------------------------------------------- /src/noggit/tileset_array_handler.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace noggit 12 | { 13 | class tileset_array_handler 14 | { 15 | public: 16 | tileset_array_handler(int base_texture_unit) : _base_texture_unit(base_texture_unit) {} 17 | ~tileset_array_handler(); 18 | 19 | void bind(); 20 | std::pair get_texture_position(std::string const& normalized_filename); 21 | std::pair get_texture_position_normalize_filename(std::string const& tileset_filename); 22 | 23 | int array_count() const { return _texture_arrays.size(); } 24 | private: 25 | std::optional> find_next_available_spot(int width, int height, GLint format) const; 26 | 27 | void bind_layer(int array_index); 28 | void create_next_array(int width, int height, GLint format); 29 | 30 | int _base_texture_unit; 31 | int _texture_count = 0; 32 | 33 | std::vector _texture_arrays; 34 | std::vector> _texture_size_for_array; 35 | std::vector _texture_count_in_array; 36 | std::vector _texture_format; 37 | std::map> _texture_positions; 38 | 39 | // how many textures are stored per opengl::texture_array 40 | static constexpr int textures_per_array = 64; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /src/noggit/tool_enums.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | enum eTerrainType 6 | { 7 | eTerrainType_Flat, 8 | eTerrainType_Linear, 9 | eTerrainType_Smooth, 10 | eTerrainType_Polynom, 11 | eTerrainType_Trigo, 12 | eTerrainType_Quadra, 13 | eTerrainType_Gaussian, 14 | eTerrainType_Vertex, 15 | eTerrainType_Count, 16 | }; 17 | 18 | enum class terrain_edit_mode 19 | { 20 | normal, 21 | only_above_cursor, 22 | only_below_cursor 23 | }; 24 | 25 | enum eVertexMode 26 | { 27 | eVertexMode_Mouse, 28 | eVertexMode_Center, 29 | eVertexMode_Count 30 | }; 31 | 32 | enum eTabletControl 33 | { 34 | eTabletControl_Off, 35 | eTabletControl_On 36 | }; 37 | 38 | enum eTerrainTabletActiveGroup 39 | { 40 | eTerrainTabletActiveGroup_Radius, 41 | eTerrainTabletActiveGroup_Speed, 42 | }; 43 | 44 | enum eFlattenType 45 | { 46 | eFlattenType_Flat, 47 | eFlattenType_Linear, 48 | eFlattenType_Smooth, 49 | eFlattenType_Origin, 50 | eFlattenType_Smooth_Inner, 51 | eFlattenType_Count, 52 | }; 53 | 54 | struct flatten_mode 55 | { 56 | flatten_mode(bool a, bool b) : raise(a), lower(b) {} 57 | 58 | bool raise : 1; 59 | bool lower : 1; 60 | 61 | flatten_mode next() 62 | { 63 | lower = lower == raise; 64 | raise = !raise; 65 | 66 | return *this; 67 | } 68 | }; 69 | 70 | enum class editing_mode 71 | { 72 | ground, 73 | flatten_blur, 74 | paint, 75 | holes, 76 | areaid, 77 | flags, 78 | water, 79 | mccv, 80 | object, 81 | #ifdef NOGGIT_HAS_SCRIPTING 82 | scripting, 83 | #endif 84 | clearing, 85 | chunk_mover, 86 | shadows, 87 | }; 88 | 89 | enum class water_opacity : int 90 | { 91 | auto_opacity, 92 | river_opacity, 93 | ocean_opacity, 94 | custom_opacity, 95 | }; 96 | 97 | enum class cursor_mode : unsigned int 98 | { 99 | none, 100 | disk, 101 | sphere, 102 | unused, // left it there to avoid issues 103 | terrain, 104 | mode_count 105 | }; 106 | 107 | enum display_mode 108 | { 109 | in_2D, 110 | in_3D 111 | }; 112 | -------------------------------------------------------------------------------- /src/noggit/ui/About.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | 6 | #include "revision.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace noggit 13 | { 14 | namespace ui 15 | { 16 | about::about(QWidget* parent) 17 | : QDialog(parent) 18 | { 19 | setWindowIcon(QIcon(":/icon")); 20 | setWindowTitle("About"); 21 | 22 | //! \todo make nice looking again, I don't care currently 23 | new QVBoxLayout (this); 24 | 25 | auto icon (new QLabel (this)); 26 | icon->setPixmap (render_blp_to_pixmap ("interface/icons/inv_potion_83.blp")); 27 | layout()->addWidget (icon); 28 | //! \todo was Skurri32 29 | layout()->addWidget (new QLabel ("Noggit Studio", this)); 30 | layout()->addWidget (new QLabel ("a wow map editor for 3.3.5a", this)); 31 | layout()->addWidget ( new QLabel ( "Ufoz [...], Cryect, Beket, Schlumpf, " 32 | "Tigurius, Steff, Garthog, Glararan, Cromon, " 33 | "Hanfer, Skarn, AxelSheva, Valium, Kaev, " 34 | "Adspartan", this 35 | ) 36 | ); 37 | layout()->addWidget (new QLabel ("World of Warcraft is (C) Blizzard Entertainment", this)); 38 | layout()->addWidget (new QLabel (STRPRODUCTVER, this)); 39 | layout()->addWidget (new QLabel (__DATE__ ", " __TIME__, this)); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/noggit/ui/About.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace ui 10 | { 11 | class about : public QDialog 12 | { 13 | public: 14 | about(QWidget* parent = nullptr); 15 | }; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/noggit/ui/CurrentTexture.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | 14 | class QMouseEvent; 15 | class QDropEvent; 16 | class QDragEnterEvent; 17 | 18 | namespace noggit 19 | { 20 | namespace ui 21 | { 22 | class texture_swapper; 23 | 24 | class current_texture : public clickable_label 25 | { 26 | Q_OBJECT 27 | private: 28 | std::string _filename; 29 | bool _need_update; 30 | 31 | virtual void resizeEvent (QResizeEvent*) override 32 | { 33 | update_texture_if_needed(); 34 | } 35 | void update_texture_if_needed(); 36 | 37 | virtual int heightForWidth (int) const override; 38 | 39 | QSize sizeHint() const override; 40 | 41 | QPoint _start_pos; 42 | 43 | signals: 44 | void texture_dropped(std::string const& filename); 45 | public: 46 | current_texture(bool accept_drop, QWidget* parent = nullptr); 47 | void set_texture (std::string const& texture); 48 | 49 | void mouseMoveEvent(QMouseEvent* event) override; 50 | void mousePressEvent(QMouseEvent* event) override; 51 | 52 | void dragEnterEvent(QDragEnterEvent* event) override; 53 | void dropEvent(QDropEvent* event) override; 54 | }; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/noggit/ui/CursorSwitcher.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace noggit 11 | { 12 | namespace ui 13 | { 14 | class cursor_switcher : public widget 15 | { 16 | public: 17 | cursor_switcher(QWidget* parent, math::vector_4d& color, noggit::unsigned_int_property& cursor_type); 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/noggit/ui/DetailInfos.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace ui 10 | { 11 | detail_infos::detail_infos(QWidget* parent) 12 | : widget (parent) 13 | { 14 | setWindowFlags (Qt::Tool); 15 | auto layout (new QFormLayout (this)); 16 | 17 | layout->addRow (_info_text = new QLabel (this)); 18 | } 19 | 20 | void detail_infos::setText (const std::string& t) 21 | { 22 | _info_text->setText (t.c_str ()); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/noggit/ui/DetailInfos.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace noggit 12 | { 13 | namespace ui 14 | { 15 | class detail_infos : public widget 16 | { 17 | private: 18 | QLabel* _info_text; 19 | 20 | public: 21 | detail_infos(QWidget* parent); 22 | void setText (const std::string& t); 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/noggit/ui/Help.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | class QFormLayout; 9 | 10 | namespace noggit 11 | { 12 | namespace ui 13 | { 14 | class help : public widget 15 | { 16 | public: 17 | help(QWidget* parent = nullptr); 18 | 19 | private: 20 | inline void generate_hotkey_row(std::initializer_list&& hotkeys, const char* description, QFormLayout* layout); 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/noggit/ui/HelperModels.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace ui 10 | { 11 | class object_editor; 12 | 13 | class helper_models : public QWidget 14 | { 15 | public: 16 | helper_models (object_editor* object_editor); 17 | }; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/noggit/ui/ModelImport.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class MapView; 10 | 11 | namespace noggit 12 | { 13 | namespace ui 14 | { 15 | class object_editor; 16 | 17 | class model_import : public QWidget 18 | { 19 | private: 20 | QListWidget* _list; 21 | QLineEdit* _textBox; 22 | 23 | public: 24 | model_import (noggit::ui::object_editor* object_editor); 25 | void buildModelList(); 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/noggit/ui/RotationEditor.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class World; 13 | 14 | namespace noggit 15 | { 16 | namespace ui 17 | { 18 | class rotation_editor : public QWidget 19 | { 20 | public: 21 | rotation_editor(QWidget* parent, World* world, noggit::bool_toggle_property* use_median_pivot_point); 22 | 23 | void updateValues(World* world); 24 | private: 25 | noggit::bool_toggle_property* _use_median_pivot_point; 26 | 27 | // for single selection 28 | void set_model_rotation(World* world); 29 | // for multi selection 30 | void change_models_rotation(World* world); 31 | 32 | QDoubleSpinBox* _rotation_x; 33 | QDoubleSpinBox* _rotation_z; 34 | QDoubleSpinBox* _rotation_y; 35 | QDoubleSpinBox* _position_x; 36 | QDoubleSpinBox* _position_z; 37 | QDoubleSpinBox* _position_y; 38 | QDoubleSpinBox* _scale; 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/noggit/ui/SettingsPanel.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace util 17 | { 18 | struct file_line_edit : public QWidget 19 | { 20 | enum mode 21 | { 22 | files, 23 | directories, 24 | }; 25 | 26 | file_line_edit (mode, QString browse_title, QWidget* parent); 27 | 28 | QLineEdit* actual; 29 | }; 30 | } 31 | 32 | namespace noggit 33 | { 34 | namespace ui 35 | { 36 | class settings : public QDialog 37 | { 38 | private: 39 | util::file_line_edit* gamePathField; 40 | util::file_line_edit* projectPathField; 41 | util::file_line_edit* importPathField; 42 | util::file_line_edit* wmvLogPathField; 43 | util::file_line_edit* mclq_liquids_export_path; 44 | QDoubleSpinBox* _fov; 45 | QDoubleSpinBox* _view_distance; 46 | QSpinBox* _adt_unload_dist; 47 | QSpinBox* _adt_unload_check_interval; 48 | QSpinBox* _adt_loading_radius; 49 | QSpinBox* _async_loader_thread_count; 50 | QCheckBox* _uid_cb; 51 | 52 | QCheckBox* tabletModeCheck; 53 | QCheckBox* _undock_tool_properties; 54 | QCheckBox* _undock_small_texture_palette; 55 | QCheckBox* _vsync_cb; 56 | 57 | QCheckBox* _additional_file_loading_log; 58 | 59 | QCheckBox* _use_mclq_liquids_export; 60 | QCheckBox* _only_one_model_box; 61 | 62 | #ifdef NOGGIT_HAS_SCRIPTING 63 | QCheckBox* _allow_scripts_write_any_file; 64 | #endif 65 | 66 | QGroupBox* _mysql_box; 67 | #ifdef USE_MYSQL_UID_STORAGE 68 | QLineEdit* _mysql_server_field; 69 | QLineEdit* _mysql_user_field; 70 | QLineEdit* _mysql_pwd_field; 71 | QLineEdit* _mysql_db_field; 72 | #endif 73 | 74 | QButtonGroup* _wireframe_type_group; 75 | QDoubleSpinBox* _wireframe_radius; 76 | QDoubleSpinBox* _wireframe_width; 77 | color_widgets::ColorSelector* _wireframe_color; 78 | QCheckBox* _anti_aliasing_cb; 79 | QCheckBox* _fullscreen_cb; 80 | 81 | public: 82 | settings(QWidget* parent = nullptr); 83 | void discard_changes(); 84 | void save_changes(); 85 | }; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/noggit/ui/TextureList.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | namespace noggit 15 | { 16 | namespace ui 17 | { 18 | TextureList::TextureList(QWidget* parent) 19 | : QListView(parent) 20 | { 21 | setDragEnabled(true); 22 | } 23 | 24 | void TextureList::mousePressEvent(QMouseEvent* event) 25 | { 26 | if (event->button() == Qt::LeftButton) 27 | _start_pos = event->pos(); 28 | 29 | QListView::mousePressEvent(event); 30 | } 31 | 32 | void TextureList::mouseMoveEvent(QMouseEvent* event) 33 | { 34 | QListView::mouseMoveEvent(event); 35 | 36 | if (event->buttons() & Qt::LeftButton) { 37 | int distance = (event->pos() - _start_pos).manhattanLength(); 38 | if (distance >= QApplication::startDragDistance()) 39 | { 40 | QModelIndex index = currentIndex(); 41 | const std::string filename = index.data(Qt::DisplayRole).toString().prepend("tileset/").toStdString(); 42 | 43 | QMimeData* mimeData = new QMimeData; 44 | mimeData->setText(QString(filename.c_str())); 45 | 46 | 47 | QDrag* drag = new QDrag(this); 48 | drag->setMimeData(mimeData); 49 | drag->setPixmap(index.data(Qt::DecorationRole).value().pixmap(128, 128)); 50 | drag->exec(); 51 | } 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/noggit/ui/TextureList.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | 6 | class QMouseEvent; 7 | 8 | namespace noggit 9 | { 10 | namespace ui 11 | { 12 | class TextureList : public QListView 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | TextureList(QWidget* parent = nullptr); 18 | 19 | void mouseMoveEvent(QMouseEvent* event) override; 20 | void mousePressEvent(QMouseEvent* event) override; 21 | 22 | private: 23 | QPoint _start_pos; 24 | 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/noggit/ui/TexturePicker.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | class QGridLayout; 12 | 13 | namespace noggit 14 | { 15 | namespace ui 16 | { 17 | class current_texture; 18 | 19 | class texture_picker : public widget 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | texture_picker (current_texture*, QWidget* parent = nullptr); 25 | 26 | void getTextures(MapChunk* chunk); 27 | void setTexture(size_t id, current_texture*); 28 | void shiftSelectedTextureLeft(); 29 | void shiftSelectedTextureRight(); 30 | 31 | private: 32 | void update(bool set_changed = true); 33 | 34 | QGridLayout* layout; 35 | 36 | std::vector _labels; 37 | std::vector _textures; 38 | MapChunk* _chunk; 39 | 40 | signals: 41 | void set_texture(scoped_blp_texture_reference texture); 42 | void shift_left(); 43 | void shift_right(); 44 | }; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/noggit/ui/TexturingGUI.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | 11 | class QMouseEvent; 12 | class QListView; 13 | 14 | namespace noggit 15 | { 16 | namespace ui 17 | { 18 | class current_texture; 19 | 20 | struct tileset_chooser : public widget 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | tileset_chooser (QWidget* parent = nullptr); 26 | 27 | signals: 28 | void selected (std::string); 29 | 30 | }; 31 | 32 | class selected_texture 33 | { 34 | public: 35 | static void set(scoped_blp_texture_reference t); 36 | static std::optional get(); 37 | static std::optional texture; 38 | }; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/noggit/ui/Toolbar.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | namespace noggit 6 | { 7 | namespace ui 8 | { 9 | toolbar::toolbar(std::function set_editing_mode) 10 | : _set_editing_mode (set_editing_mode) 11 | , _tool_group(this) 12 | { 13 | add_tool_icon (editing_mode::ground, tr("Raise / Lower"), font_awesome::chartarea); 14 | add_tool_icon (editing_mode::flatten_blur, tr("Flatten / Blur"), font_awesome::bacon); 15 | add_tool_icon (editing_mode::paint, tr("3D Paint"), font_awesome::paintbrush); 16 | add_tool_icon (editing_mode::holes, tr("Holes"), font_awesome::cut); 17 | add_tool_icon (editing_mode::areaid, tr("AreaID Paint"), font_awesome::objectgroup); 18 | add_tool_icon (editing_mode::flags, tr("Impassible Flag"), font_awesome::ban); 19 | add_tool_icon (editing_mode::water, tr("Water edit"), font_awesome::water); 20 | add_tool_icon (editing_mode::mccv, tr("Shader editor"), font_awesome::eyedropper); 21 | add_tool_icon (editing_mode::object, tr("Object editor"), font_awesome::cube); 22 | #ifdef NOGGIT_HAS_SCRIPTING 23 | add_tool_icon (editing_mode::scripting, tr("Script Editor"), font_awesome::book); 24 | #endif 25 | add_tool_icon(editing_mode::clearing, tr("Clearing Tool"), font_awesome::eraser); 26 | add_tool_icon(editing_mode::chunk_mover, tr("Chunk Mover"), font_awesome::arrowsalt); 27 | add_tool_icon(editing_mode::shadows, tr("Shadows Editor"), font_awesome::cloudsun); 28 | } 29 | 30 | void toolbar::add_tool_icon(editing_mode mode, const QString& name, const font_awesome::icons& icon) 31 | { 32 | auto action = addAction(font_awesome_icon(icon), name); 33 | connect (action, &QAction::triggered, [this, mode] () { 34 | _set_editing_mode (mode); 35 | }); 36 | action->setActionGroup(&_tool_group); 37 | action->setCheckable(true); 38 | } 39 | 40 | void toolbar::check_tool(editing_mode mode) 41 | { 42 | _tool_group.actions()[static_cast (mode)]->setChecked(true); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/noggit/ui/Toolbar.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace noggit 14 | { 15 | namespace ui 16 | { 17 | class toolbar: public QToolBar 18 | { 19 | public: 20 | toolbar(std::function set_editing_mode); 21 | 22 | void check_tool(editing_mode); 23 | 24 | private: 25 | std::function _set_editing_mode; 26 | QActionGroup _tool_group; 27 | 28 | void add_tool_icon(editing_mode mode, const QString& name, const font_awesome::icons& icon); 29 | }; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/noggit/ui/ZoneIDBrowser.h: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace noggit 15 | { 16 | namespace ui 17 | { 18 | class zone_id_browser : public noggit_tool 19 | { 20 | public: 21 | zone_id_browser(QWidget* parent = nullptr); 22 | void set_map_id(int id); 23 | void set_area_id(int id); 24 | std::optional area_id() const { return _area_id; } 25 | 26 | virtual void tick(float dt, math::vector_3d const& cursor_pos, bool cursor_under_map, World* world) override; 27 | 28 | private: 29 | QTreeWidget* _area_tree; 30 | std::map _items; 31 | int mapID; 32 | 33 | std::optional _area_id; 34 | 35 | void build_area_list(); 36 | QTreeWidgetItem* create_or_get_tree_widget_item(int area_id); 37 | QTreeWidgetItem* add_area(int area_id); 38 | }; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/noggit/ui/asset_browser.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace noggit::ui 11 | { 12 | class object_editor; 13 | 14 | class asset_browser : public QWidget 15 | { 16 | Q_OBJECT 17 | public: 18 | asset_browser(QWidget* parent = nullptr, noggit::ui::object_editor* object_editor = nullptr); 19 | 20 | private: 21 | void create_tree(QString filter = QString{}); 22 | 23 | struct asset_tree_node; 24 | void add_children(asset_tree_node const& data_node, QTreeWidgetItem* parent); 25 | 26 | bool _expanded = false; 27 | 28 | QLineEdit* _search_bar; 29 | QTreeWidget* _asset_tree; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /src/noggit/ui/checkbox.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace noggit 10 | { 11 | namespace ui 12 | { 13 | class checkbox : public QCheckBox 14 | { 15 | public: 16 | checkbox ( QString label 17 | , bool_toggle_property* prop 18 | , QWidget* parent = nullptr 19 | ) 20 | : QCheckBox (label, parent) 21 | { 22 | connect ( this, &QCheckBox::toggled 23 | , prop, &bool_toggle_property::set 24 | ); 25 | connect ( prop, &bool_toggle_property::changed 26 | , this, &QCheckBox::setChecked 27 | ); 28 | setChecked (prop->get()); 29 | } 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/noggit/ui/chunk_mover.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace noggit::ui 14 | { 15 | class chunk_mover_ui : public noggit_tool 16 | { 17 | public: 18 | chunk_mover_ui(noggit::chunk_mover* chunk_mover, QWidget* parent = nullptr); 19 | 20 | virtual void tick(float dt, math::vector_3d const& cursor_pos, bool cursor_under_map, World* world) override; 21 | virtual void mouse_move_event(QLineF const& relative_movement) override; 22 | virtual void wheel_event(QWheelEvent* event) override; 23 | 24 | void change_height_offset(float change); 25 | void paste_selection(); 26 | 27 | chunk_override_params override_params() const; 28 | 29 | float radius() const { return _radius.get(); } 30 | bool use_square_brush() const { return _square_brush.get(); } 31 | 32 | void change_radius(float v) { _radius.change(v); } 33 | 34 | void toggle_preview(); 35 | private: 36 | noggit::chunk_mover* _chunk_mover; 37 | 38 | bool_toggle_property _override_height; 39 | bool_toggle_property _override_textures; 40 | bool_toggle_property _override_alphamaps; 41 | bool_toggle_property _override_vertex_colors; 42 | bool_toggle_property _override_liquids; 43 | bool_toggle_property _override_shadows; 44 | bool_toggle_property _override_area_id; 45 | bool_toggle_property _override_holes; 46 | bool_toggle_property _override_models; 47 | 48 | chunk_override_params::height_mode _height_mode = chunk_override_params::height_mode::normal; 49 | 50 | float_property _radius; 51 | bool_toggle_property _square_brush; 52 | bool_toggle_property _fix_gaps; 53 | bool_toggle_property _clear_shadows; 54 | bool_toggle_property _clear_models; 55 | 56 | bool_toggle_property _preview_enabled; 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /src/noggit/ui/clearing_tool.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace noggit 11 | { 12 | namespace ui 13 | { 14 | class clearing_tool : public noggit_tool 15 | { 16 | public: 17 | clearing_tool(QWidget* parent = nullptr); 18 | 19 | virtual void tick(float dt, math::vector_3d const& cursor_pos, bool cursor_under_map, World* world) override; 20 | virtual void mouse_move_event(QLineF const& relative_movement) override; 21 | 22 | void change_radius(float change) { _radius.change(change); } 23 | float radius() const { return _radius.get(); } 24 | 25 | QSize sizeHint() const override; 26 | 27 | private: 28 | int _mode = 0; 29 | 30 | float_property _radius; 31 | float_property _texture_threshold; 32 | 33 | bool_toggle_property _clear_height; 34 | bool_toggle_property _clear_textures; 35 | bool_toggle_property _clear_duplicate_textures; 36 | bool_toggle_property _clear_textures_under_threshold; 37 | bool_toggle_property _clear_texture_flags; 38 | bool_toggle_property _clear_liquids; 39 | bool_toggle_property _clear_m2s; 40 | bool_toggle_property _clear_wmos; 41 | bool_toggle_property _clear_shadows; 42 | bool_toggle_property _clear_mccv; 43 | bool_toggle_property _clear_impassible_flag; 44 | bool_toggle_property _clear_holes; 45 | }; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/noggit/ui/clickable_label.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | namespace noggit 6 | { 7 | namespace ui 8 | { 9 | clickable_label::clickable_label(QWidget* parent) : QLabel(parent){} 10 | 11 | void clickable_label::mouseReleaseEvent (QMouseEvent*) 12 | { 13 | emit clicked(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/noggit/ui/clickable_label.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace ui 10 | { 11 | class clickable_label : public QLabel 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | clickable_label(QWidget* parent=nullptr); 17 | 18 | signals: 19 | void clicked(); 20 | 21 | protected: 22 | virtual void mouseReleaseEvent (QMouseEvent* event) override; 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/noggit/ui/collapsible_widget.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace noggit::ui 10 | { 11 | collapsible_widget::collapsible_widget(std::string const& header, bool collasped, QWidget* parent) 12 | : QGroupBox(parent) 13 | , _collasped(collasped) 14 | { 15 | QGridLayout* layout = new QGridLayout(this); 16 | 17 | layout->setSpacing(1); 18 | layout->setContentsMargins(1, 1, 1, 1); 19 | 20 | _toggle_btn = new QPushButton(collasped ? ">" : "-", this); 21 | _toggle_btn->setFixedWidth(20); 22 | _toggle_btn->setFixedHeight(20); 23 | _toggle_btn->setStyleSheet("text-align:center; background-color:transparent; border-color:transparent;"); 24 | 25 | clickable_label* header_label = new clickable_label(this); 26 | header_label->setText(QString::fromStdString(header)); 27 | 28 | layout->addWidget(_toggle_btn, 0, 0); 29 | layout->addWidget(header_label, 0, 1); 30 | 31 | _widget = new QWidget(this); 32 | _layout = new QVBoxLayout(_widget); 33 | 34 | layout->addWidget(_widget, 1, 0, 1, 2); 35 | 36 | if (_collasped) 37 | { 38 | _toggle_btn->setText(">"); 39 | _widget->setVisible(false); 40 | } 41 | 42 | connect( _toggle_btn, &QPushButton::clicked 43 | , [=]() 44 | { 45 | toggle(); 46 | } 47 | ); 48 | connect( header_label, &clickable_label::clicked 49 | , [=] 50 | { 51 | toggle(); 52 | } 53 | ); 54 | } 55 | 56 | void collapsible_widget::add_layout(QLayout* layout) 57 | { 58 | _layout->addLayout(layout); 59 | } 60 | void collapsible_widget::add_widget(QWidget* widget) 61 | { 62 | _layout->addWidget(widget); 63 | } 64 | 65 | void collapsible_widget::toggle() 66 | { 67 | _toggle_btn->setText(_collasped ? "-" : ">"); 68 | _widget->setVisible(_collasped); 69 | _collasped = !_collasped; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/noggit/ui/collapsible_widget.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace noggit::ui 10 | { 11 | class collapsible_widget : public QGroupBox 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | collapsible_widget(std::string const& header, bool collapsed, QWidget* parent = nullptr); 17 | 18 | void add_layout(QLayout* layout); 19 | void add_widget(QWidget* widget); 20 | 21 | // to avoid using the groupbox's title/checkbox as it's only 22 | // used to get the border, the title is inside the widget 23 | void setTitle(const QString&) { } 24 | void setCheckable(bool) { } 25 | 26 | private: 27 | void toggle(); 28 | 29 | QWidget* _widget; 30 | QVBoxLayout* _layout; 31 | QPushButton* _toggle_btn; 32 | 33 | bool _collasped = false; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /src/noggit/ui/double_spinbox.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace noggit 11 | { 12 | namespace ui 13 | { 14 | class double_spinbox : public QDoubleSpinBox 15 | { 16 | public: 17 | double_spinbox( float_property* prop 18 | , QWidget* parent = nullptr 19 | ) 20 | : QDoubleSpinBox(parent) 21 | { 22 | connect ( this, qOverload(&QDoubleSpinBox::valueChanged) 23 | , prop, &float_property::set 24 | ); 25 | connect ( prop, &float_property::changed 26 | , this, &QDoubleSpinBox::setValue 27 | ); 28 | 29 | setValue(prop->get()); 30 | } 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/noggit/ui/font_noggit.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace noggit 14 | { 15 | namespace ui 16 | { 17 | 18 | font_noggit_icon_engine::font_noggit_icon_engine(const QString& text) 19 | : font_awesome_icon_engine(text) 20 | , _text(text) 21 | {} 22 | 23 | font_noggit_icon_engine* font_noggit_icon_engine::clone() const 24 | { 25 | return new font_noggit_icon_engine(_text); 26 | } 27 | 28 | void font_noggit_icon_engine::paint(QPainter* painter 29 | , QRect const& rect 30 | , QIcon::Mode mode 31 | , QIcon::State state 32 | ) 33 | { 34 | painter->save(); 35 | { 36 | painter->setPen((state == QIcon::On || mode == QIcon::Active) 37 | ? QColor(0, 0, 0) 38 | : QColor(0, 0, 0) 39 | ); 40 | 41 | if (!_fonts.count(rect.height())) 42 | { 43 | auto id(QFontDatabase::addApplicationFont(":/fonts/noggit_font.ttf")); 44 | 45 | if (id == -1) 46 | { 47 | throw std::runtime_error("Unable to load Noggit font."); 48 | } 49 | 50 | QFont font(QFontDatabase::applicationFontFamilies(id).at(0)); 51 | font.setPixelSize(rect.height()); 52 | 53 | _fonts[rect.height()] = font; 54 | } 55 | 56 | painter->setFont(_fonts.at(rect.height())); 57 | 58 | painter->drawText 59 | (rect, _text, QTextOption(Qt::AlignCenter | Qt::AlignVCenter)); 60 | } 61 | painter->restore(); 62 | } 63 | 64 | std::map font_noggit_icon_engine::_fonts = {}; 65 | 66 | font_noggit_icon::font_noggit_icon(font_noggit::icons const& icon) 67 | : QIcon(new font_noggit_icon_engine(QString(QChar(icon)))) 68 | {} 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/noggit/ui/font_noggit.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | 10 | namespace noggit 11 | { 12 | namespace ui 13 | { 14 | struct font_noggit 15 | { 16 | enum icons 17 | { 18 | rmb = 0xf868, 19 | lmb = 0xf864, 20 | mmb = 0xf866, 21 | rmb_drag = 0xf869, 22 | lmb_drag = 0xf865, 23 | mmb_drag = 0xf867, 24 | drag = 0xf86A, 25 | alt = 0xf86B, 26 | ctrl = 0xf86C, 27 | shift = 0xf86D, 28 | a = 0xf86E, 29 | b = 0xf86F, 30 | c = 0xf870, 31 | d = 0xf871, 32 | e = 0xf872, 33 | f = 0xf873, 34 | g = 0xf874, 35 | h = 0xf875, 36 | i = 0xf876, 37 | j = 0xf877, 38 | k = 0xf878, 39 | l = 0xf879, 40 | m = 0xf87A, 41 | n = 0xf87B, 42 | o = 0xf87C, 43 | p = 0xf87D, 44 | q = 0xf87E, 45 | r = 0xf87F, 46 | s = 0xf880, 47 | t = 0xf881, 48 | u = 0xf882, 49 | v = 0xf883, 50 | w = 0xf884, 51 | x = 0xf885, 52 | y = 0xf886, 53 | z = 0xf887, 54 | space = 0xf888, 55 | page_up = 0xf889, 56 | page_down = 0xf88A, 57 | home = 0xf88B, 58 | num = 0xf88C, 59 | tab = 0xf88D, 60 | plus = 0xf88E, 61 | minus = 0xf88F, 62 | f1 = 0xf890, 63 | f2 = 0xf891, 64 | f3 = 0xf892, 65 | f4 = 0xf893, 66 | f5 = 0xf894, 67 | f6 = 0xf895, 68 | f7 = 0xf896, 69 | f8 = 0xf897, 70 | f9 = 0xf898, 71 | f10 = 0xf899, 72 | f11 = 0xf89A, 73 | f12 = 0xf89B 74 | }; 75 | }; 76 | 77 | class font_noggit_icon : public QIcon 78 | { 79 | public: 80 | font_noggit_icon(font_noggit::icons const&); 81 | }; 82 | 83 | class font_noggit_icon_engine : public font_awesome_icon_engine 84 | { 85 | public: 86 | font_noggit_icon_engine(const QString& text); 87 | 88 | virtual font_noggit_icon_engine* clone() const override; 89 | 90 | virtual void paint(QPainter* painter, QRect const& rect, QIcon::Mode mode, QIcon::State state) override; 91 | 92 | 93 | private: 94 | const QString _text; 95 | 96 | static std::map _fonts; 97 | 98 | }; 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/noggit/ui/main_window.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | namespace noggit 14 | { 15 | namespace ui 16 | { 17 | class minimap_widget; 18 | class settings; 19 | class about; 20 | 21 | struct main_window : QMainWindow 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | main_window(); 27 | 28 | void prompt_exit(QCloseEvent* event); 29 | void prompt_uid_fix_failure(); 30 | 31 | std::unordered_set displayed_widgets; 32 | 33 | signals: 34 | void exit_prompt_opened(); 35 | 36 | private: 37 | void loadMap (int mapID); 38 | 39 | void check_uid_then_enter_map ( math::vector_3d pos 40 | , math::degrees camera_pitch 41 | , math::degrees camera_yaw 42 | , bool from_bookmark = false 43 | ); 44 | 45 | void enterMapAt ( math::vector_3d pos 46 | , math::degrees camera_pitch 47 | , math::degrees camera_yaw 48 | , uid_fix_mode uid_fix = uid_fix_mode::none 49 | , bool from_bookmark = false 50 | ); 51 | 52 | void build_menu(); 53 | void rebuild_menu(); 54 | 55 | struct MapEntry 56 | { 57 | int mapID; 58 | std::string name; 59 | int areaType; 60 | }; 61 | 62 | 63 | std::vector mMaps; 64 | 65 | minimap_widget* _minimap; 66 | settings* _settings; 67 | about* _about; 68 | QWidget* _null_widget; 69 | 70 | std::unique_ptr _world; 71 | 72 | bool map_loaded = false; 73 | 74 | virtual void closeEvent (QCloseEvent*) override; 75 | }; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/noggit/ui/minimap_widget.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace math 8 | { 9 | struct vector_3d; 10 | } 11 | class World; 12 | 13 | //! \todo add adt coordinates/name on mouseover 14 | namespace noggit 15 | { 16 | class camera; 17 | 18 | namespace ui 19 | { 20 | //! \todo Make this a fixed square somehow. 21 | class minimap_widget : public QWidget 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | minimap_widget (QWidget* parent = nullptr); 27 | 28 | virtual QSize sizeHint() const override; 29 | 30 | inline const World* world (World* const world_) 31 | { _world = world_; update(); return _world; } 32 | inline const World* world() const { return _world; } 33 | 34 | inline const bool& draw_skies (const bool& draw_skies_) 35 | { _draw_skies = draw_skies_; update(); return _draw_skies; } 36 | inline const bool& draw_skies() const { return _draw_skies; } 37 | 38 | inline const bool& draw_boundaries (const bool& draw_boundaries_) 39 | { _draw_boundaries = draw_boundaries_; update(); return _draw_boundaries; } 40 | inline const bool& draw_boundaries() const { return _draw_boundaries; } 41 | 42 | inline void camera (noggit::camera* camera) { _camera = camera; } 43 | 44 | protected: 45 | virtual void paintEvent (QPaintEvent*) override; 46 | virtual void mouseDoubleClickEvent (QMouseEvent*) override; 47 | virtual void mouseMoveEvent(QMouseEvent*) override; 48 | 49 | signals: 50 | void map_clicked (const ::math::vector_3d&); 51 | void tile_clicked (const QPoint&); 52 | 53 | private: 54 | World const* _world; 55 | noggit::camera* _camera; 56 | bool _draw_skies; 57 | bool _draw_camera; 58 | bool _draw_boundaries; 59 | }; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/noggit/ui/noggit_tool.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace noggit::ui 8 | { 9 | void noggit_tool::mouse_press_event(QMouseEvent* event) 10 | { 11 | switch (event->button()) 12 | { 13 | case Qt::LeftButton: _left_mouse_button = true; break; 14 | case Qt::MiddleButton: _middle_mouse_button = true; break; 15 | case Qt::RightButton: _right_mouse_button = true; break; 16 | } 17 | } 18 | void noggit_tool::mouse_release_event(QMouseEvent* event) 19 | { 20 | switch (event->button()) 21 | { 22 | case Qt::LeftButton: _left_mouse_button = false; break; 23 | case Qt::MiddleButton: _middle_mouse_button = false; break; 24 | case Qt::RightButton: _right_mouse_button = false; break; 25 | } 26 | } 27 | 28 | void noggit_tool::key_release_event(QKeyEvent* event) 29 | { 30 | auto key = event->key(); 31 | 32 | switch (key) 33 | { 34 | case Qt::Key_Alt: _mod_alt_down = false; break; 35 | case Qt::Key_Control: _mod_ctrl_down = false; break; 36 | case Qt::Key_Shift: _mod_shift_down = false; break; 37 | case Qt::Key_Space: _mod_space_down = false; break; 38 | } 39 | } 40 | void noggit_tool::key_press_event(QKeyEvent* event) 41 | { 42 | auto key = event->key(); 43 | 44 | switch (key) 45 | { 46 | case Qt::Key_Alt: _mod_alt_down = true; break; 47 | case Qt::Key_Control: _mod_ctrl_down = true; break; 48 | case Qt::Key_Shift: _mod_shift_down = true; break; 49 | case Qt::Key_Space: _mod_space_down = true; break; 50 | } 51 | } 52 | 53 | void noggit_tool::reset_input_states() 54 | { 55 | _mod_alt_down = false; 56 | _mod_ctrl_down = false; 57 | _mod_shift_down = false; 58 | _mod_space_down = false; 59 | 60 | _left_mouse_button = false; 61 | _middle_mouse_button = false; 62 | _right_mouse_button = false; 63 | 64 | reset_extra_states(); 65 | } 66 | 67 | float noggit_tool::scroll_wheel_delta_for_range(QWheelEvent* event, float range) const 68 | { 69 | return ( _mod_ctrl_down ? 0.01f : 0.1f) 70 | * range 71 | // alt = horizontal delta 72 | * (_mod_alt_down ? event->angleDelta().x() : event->angleDelta().y()) 73 | / 320.f 74 | ; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/noggit/ui/noggit_tool.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | class World; 10 | 11 | namespace noggit 12 | { 13 | namespace ui 14 | { 15 | class noggit_tool : public QWidget 16 | { 17 | public: 18 | noggit_tool(QWidget* parent = nullptr) : QWidget(parent) {} 19 | 20 | virtual void tick([[maybe_unused]] float dt, 21 | [[maybe_unused]] math::vector_3d const& cursor_pos, 22 | [[maybe_unused]] bool cursor_under_map, 23 | World*) {} 24 | 25 | virtual void mouse_move_event([[maybe_unused]] QLineF const& relative_movement) {} 26 | virtual void mouse_press_event(QMouseEvent*); 27 | virtual void mouse_release_event(QMouseEvent*); 28 | virtual void wheel_event(QWheelEvent*) {} 29 | virtual void key_release_event(QKeyEvent*); 30 | virtual void key_press_event(QKeyEvent*); 31 | 32 | void reset_input_states(); 33 | // for tool specific states 34 | // called by reset_input_states 35 | virtual void reset_extra_states() {} 36 | 37 | static constexpr float mouse_sensibility = 15.f; 38 | 39 | void set_window_size(int width, int height) { _window_width = width; _window_height = height; } 40 | float aspect_ratio() const { return static_cast(_window_width) / static_cast(_window_height); } 41 | 42 | protected: 43 | int _window_width = 1; 44 | int _window_height = 1; 45 | 46 | //! \note 8.f for degrees, 40.f for smoothness 47 | float scroll_wheel_delta_for_range(QWheelEvent* event, float range) const; 48 | 49 | bool _mod_alt_down = false; 50 | bool _mod_ctrl_down = false; 51 | bool _mod_shift_down = false; 52 | bool _mod_space_down = false; 53 | 54 | bool _left_mouse_button = false; 55 | bool _middle_mouse_button = false; 56 | bool _right_mouse_button = false; 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/noggit/ui/pushbutton.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace ui 10 | { 11 | class pushbutton : public QPushButton 12 | { 13 | public: 14 | template 15 | pushbutton ( QString label 16 | , Func&& function 17 | , QWidget* parent = nullptr 18 | ) 19 | : QPushButton (label, parent) 20 | { 21 | connect (this, &QPushButton::clicked, function); 22 | } 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/noggit/ui/shader_tool.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | 21 | namespace noggit 22 | { 23 | namespace ui 24 | { 25 | class shader_tool : public noggit_tool 26 | { 27 | public: 28 | shader_tool(math::vector_4d& color, QWidget* parent = nullptr); 29 | 30 | void changeShader (World*, math::vector_3d const& pos, float dt, bool add); 31 | void pickColor(World* world, math::vector_3d const& pos); 32 | void addColorToPalette(); 33 | 34 | void change_radius(float change) { _radius_property.change(change); } 35 | void changeSpeed(float change) { _speed_property.change(change); } 36 | 37 | float brushRadius() const { return _radius_property.get(); } 38 | 39 | QSize sizeHint() const override; 40 | 41 | virtual void tick(float dt, math::vector_3d const& cursor_pos, bool cursor_under_map, World* world) override; 42 | virtual void mouse_move_event(QLineF const& relative_movement) override; 43 | virtual void key_press_event(QKeyEvent* event) override; 44 | private: 45 | float_property _radius_property; 46 | float_property _speed_property; 47 | math::vector_4d& _color; 48 | 49 | slider_spinbox* _radius_widget; 50 | QSpinBox* _spin_hue; 51 | QSpinBox* _spin_saturation; 52 | QSpinBox* _spin_value; 53 | 54 | color_widgets::ColorSelector* color_picker; 55 | color_widgets::ColorWheel* color_wheel; 56 | color_widgets::HueSlider* _slide_hue; 57 | color_widgets::GradientSlider* _slide_saturation; 58 | color_widgets::GradientSlider* _slide_value; 59 | color_widgets::ColorListWidget* _color_palette; 60 | 61 | public Q_SLOTS: 62 | void set_hsv(); 63 | void update_color_widgets(); 64 | 65 | }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/noggit/ui/shadow_editor.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | namespace noggit::ui 14 | { 15 | shadow_editor::shadow_editor(QWidget* parent) 16 | : noggit_tool(parent) 17 | , _radius_property(10.f) 18 | , _pitch_property(47.f) 19 | , _threshold_property(128.f) 20 | { 21 | auto layout(new QFormLayout(this)); 22 | 23 | QGroupBox* brush_group = new QGroupBox("Brush", this); 24 | auto brush_layout(new QFormLayout(brush_group)); 25 | brush_layout->addWidget(new slider_spinbox("Radius", &_radius_property, 0.f, 100.f, 2, this)); 26 | 27 | QGroupBox* generation_group = new QGroupBox("Auto Generation", this); 28 | auto generation_layout(new QFormLayout(generation_group)); 29 | generation_layout->addWidget(new slider_spinbox("Sun Pitch", &_pitch_property, 1.f, 90.f, 0, this)); 30 | generation_layout->addWidget(new slider_spinbox("Shadow Threshold", &_threshold_property, 0.f, 256.f, 0, this)); 31 | 32 | layout->addRow(brush_group); 33 | layout->addRow(generation_group); 34 | } 35 | 36 | 37 | void shadow_editor::tick(float /* dt */, math::vector_3d const& cursor_pos, bool cursor_under_map, World* world) 38 | { 39 | if (!cursor_under_map && _left_mouse_button) 40 | { 41 | if (_mod_shift_down) 42 | { 43 | world->set_shadow(cursor_pos, _radius_property.get(), true); 44 | } 45 | if (_mod_ctrl_down) 46 | { 47 | world->set_shadow(cursor_pos, _radius_property.get(), false); 48 | } 49 | } 50 | 51 | if (!cursor_under_map && _middle_mouse_button) 52 | { 53 | world->update_legacy_shadow_for_tile_at(cursor_pos, _pitch_property.get(), static_cast(std::round(_threshold_property.get()))); 54 | } 55 | } 56 | 57 | void shadow_editor::mouse_move_event(QLineF const& relative_movement) 58 | { 59 | if (_left_mouse_button && _mod_alt_down) 60 | { 61 | change_radius(relative_movement.dx() / mouse_sensibility); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/noggit/ui/shadow_editor.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | namespace noggit::ui 11 | { 12 | class shadow_editor : public noggit_tool 13 | { 14 | public: 15 | shadow_editor(QWidget* parent = nullptr); 16 | 17 | void change_radius(float change) { _radius_property.change(change); } 18 | float radius() const { return _radius_property.get(); } 19 | 20 | virtual void tick(float dt, math::vector_3d const& cursor_pos, bool cursor_under_map, World* world) override; 21 | virtual void mouse_move_event(QLineF const& relative_movement) override; 22 | 23 | private: 24 | float_property _radius_property; 25 | float_property _pitch_property; 26 | float_property _threshold_property; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /src/noggit/ui/slider_spinbox.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace noggit::ui 12 | { 13 | class slider_spinbox : public widget 14 | { 15 | public: 16 | slider_spinbox(QString label, float_property* prop, float min, float max, int decimal_count, QWidget* parent = nullptr); 17 | 18 | private: 19 | float _min; 20 | float _max; 21 | int _slider_shift; 22 | 23 | float_property* _prop; 24 | QDoubleSpinBox* _spin; 25 | QSlider* _slider; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /src/noggit/ui/texture_palette_small.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | 12 | class QGridLayout; 13 | class QPushButton; 14 | class QDropEvent; 15 | class QDragEnterEvent; 16 | class QMouseEvent; 17 | class QListWidget; 18 | class QPoint; 19 | 20 | 21 | namespace noggit 22 | { 23 | namespace ui 24 | { 25 | class current_texture; 26 | 27 | class PaletteList : public QListWidget 28 | { 29 | public: 30 | PaletteList(QWidget* parent); 31 | 32 | void mouseMoveEvent(QMouseEvent* event) override; 33 | void mousePressEvent(QMouseEvent* event) override; 34 | 35 | private: 36 | QPoint _start_pos; 37 | 38 | }; 39 | 40 | class texture_palette_small : public widget 41 | { 42 | Q_OBJECT 43 | 44 | public: 45 | texture_palette_small (QWidget* parent); 46 | 47 | void addTexture(); 48 | void addTextureByFilename(const std::string& filename); 49 | 50 | void removeTexture(QString filename); 51 | 52 | void removeSelectedTexture(); 53 | 54 | void updateWidget(); 55 | 56 | void dragEnterEvent(QDragEnterEvent* event) override; 57 | void dropEvent(QDropEvent* event) override; 58 | 59 | 60 | signals: 61 | void selected(std::string); 62 | 63 | private: 64 | 65 | QGridLayout* layout; 66 | 67 | QListWidget* _texture_list; 68 | QPushButton* _add_button; 69 | QPushButton* _remove_button; 70 | std::unordered_set _texture_paths; 71 | 72 | }; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/noggit/ui/texture_swapper.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | class World; 19 | 20 | namespace noggit 21 | { 22 | namespace ui 23 | { 24 | class texture_swapper : public QWidget 25 | { 26 | public: 27 | texture_swapper ( QWidget* parent 28 | , const math::vector_3d* camera_pos 29 | , World* 30 | ); 31 | 32 | std::optional const& texture_to_swap() const 33 | { 34 | return _texture_to_swap; 35 | } 36 | 37 | float radius() const { return _radius.get(); } 38 | float hardness() const { return _hardness.get(); } 39 | float pressure() const { return _pressure.get(); } 40 | 41 | void change_radius(float change) { _radius.change(change); } 42 | void change_hardness(float change) { _hardness.change(change); } 43 | void change_pressure(float change) { _pressure.change(change); } 44 | 45 | bool brush_mode() const 46 | { 47 | return _brush_mode_group->isChecked(); 48 | } 49 | 50 | Brush brush() const { return Brush(radius(), hardness()); } 51 | 52 | void toggle_brush_mode() 53 | { 54 | _brush_mode_group->setChecked(!_brush_mode_group->isChecked()); 55 | } 56 | 57 | void set_texture(std::string const& filename); 58 | 59 | current_texture* const texture_display() { return _texture_to_swap_display; } 60 | 61 | private: 62 | std::optional _texture_to_swap; 63 | float_property _radius; 64 | float_property _hardness; 65 | float_property _pressure; 66 | 67 | private: 68 | current_texture* _texture_to_swap_display; 69 | 70 | QGroupBox* _brush_mode_group; 71 | }; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/noggit/ui/uid_fix_window.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | enum class uid_fix_mode 8 | { 9 | none, 10 | max_uid, 11 | fix_all_fail_on_model_loading_error, 12 | fix_all_fuckporting_edition 13 | }; 14 | 15 | namespace noggit 16 | { 17 | namespace ui 18 | { 19 | class uid_fix_window : public QDialog 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | uid_fix_window(); 25 | 26 | signals: 27 | void fix_uid (uid_fix_mode uid_fix); 28 | }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/noggit/ui/widget.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | namespace ui 10 | { 11 | class widget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | using QWidget::QWidget; 17 | 18 | virtual void showEvent (QShowEvent* event) override 19 | { 20 | emit visibilityChanged (true); 21 | return QWidget::showEvent (event); 22 | } 23 | virtual void hideEvent (QHideEvent* event) override 24 | { 25 | emit visibilityChanged (false); 26 | return QWidget::hideEvent (event); 27 | } 28 | 29 | signals: 30 | void visibilityChanged (bool); 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/noggit/uid_storage.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | 6 | bool uid_storage::hasMaxUIDStored(uint32_t mapID) 7 | { 8 | return NoggitSettings.uids->value(QString::number(mapID), -1).toUInt() != -1; 9 | } 10 | 11 | uint32_t uid_storage::getMaxUID(uint32_t mapID) 12 | { 13 | return NoggitSettings.uids->value(QString::number(mapID), 0).toUInt(); 14 | } 15 | 16 | void uid_storage::saveMaxUID(uint32_t mapID, uint32_t uid) 17 | { 18 | NoggitSettings.uids->setValue(QString::number(mapID), uid); 19 | } 20 | 21 | void uid_storage::remove_uid_for_map(uint32_t map_id) 22 | { 23 | NoggitSettings.uids->remove(QString::number(map_id)); 24 | } 25 | -------------------------------------------------------------------------------- /src/noggit/uid_storage.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | class uid_storage 8 | { 9 | public: 10 | static bool hasMaxUIDStored(uint32_t mapID); 11 | static uint32_t getMaxUID (uint32_t mapID); 12 | static void saveMaxUID(uint32_t mapID, uint32_t uid); 13 | static void remove_uid_for_map(uint32_t map_id); 14 | }; 15 | -------------------------------------------------------------------------------- /src/noggit/unsigned_int_property.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace noggit 8 | { 9 | struct unsigned_int_property : QObject 10 | { 11 | private: 12 | Q_OBJECT 13 | 14 | unsigned int _value; 15 | 16 | signals: 17 | void changed (unsigned int); 18 | 19 | public slots: 20 | void set (unsigned int v) 21 | { 22 | if (_value != v) 23 | { 24 | _value = v; 25 | emit changed (v); 26 | } 27 | } 28 | unsigned int get() const 29 | { 30 | return _value; 31 | } 32 | 33 | public: 34 | unsigned_int_property (unsigned int value) 35 | : _value (value) 36 | {} 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /src/noggit/wmo_liquid.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | // #define USEBLSFILES 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | 18 | 19 | class wmo_liquid 20 | { 21 | public: 22 | wmo_liquid(MPQFile* f, WMOLiquidHeader const& header, WMOMaterial const& mat, int group_liquid, bool use_dbc_type, bool is_ocean); 23 | wmo_liquid(wmo_liquid const& other); 24 | 25 | void draw ( math::matrix_4x4 const& transform 26 | , liquid_render& render 27 | ); 28 | 29 | void upload(opengl::scoped::use_program& water_shader, liquid_render& render); 30 | 31 | private: 32 | int initGeometry(MPQFile* f); 33 | 34 | math::vector_3d pos; 35 | bool mTransparency; 36 | int xtiles, ytiles; 37 | int _liquid_id; 38 | 39 | std::vector _vertices; 40 | 41 | std::vector indices; 42 | 43 | int _indices_count; 44 | 45 | bool _uploaded = false; 46 | 47 | opengl::scoped::deferred_upload_buffers<3> _buffer; 48 | GLuint const& _indices_buffer = _buffer[0]; 49 | GLuint const& _vertices_buffer = _buffer[1]; 50 | GLuint const& _liquid_ubo = _buffer[2]; 51 | 52 | opengl::scoped::deferred_upload_vertex_arrays<1> _vertex_array; 53 | GLuint const& _vao = _vertex_array[0]; 54 | }; 55 | -------------------------------------------------------------------------------- /src/noggit/world_tile_update_queue.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class ModelInstance; 15 | class WMOInstance; 16 | class World; 17 | 18 | namespace noggit 19 | { 20 | struct instance_update; 21 | 22 | class world_tile_update_queue 23 | { 24 | public: 25 | world_tile_update_queue(World* world); 26 | ~world_tile_update_queue(); 27 | 28 | world_tile_update_queue() = delete; 29 | world_tile_update_queue(world_tile_update_queue const&) = delete; 30 | world_tile_update_queue(world_tile_update_queue&&) = delete; 31 | world_tile_update_queue& operator= (world_tile_update_queue const&) = delete; 32 | world_tile_update_queue& operator= (world_tile_update_queue&&) = delete; 33 | 34 | void wait_for_all_update(); 35 | 36 | void queue_update(ModelInstance* instance, model_update type); 37 | void queue_update(WMOInstance* instance, model_update type); 38 | 39 | private: 40 | void process_queue(); 41 | private: 42 | World* _world; 43 | 44 | std::atomic _stop = {false}; 45 | std::mutex _mutex; 46 | std::condition_variable _state_changed; 47 | 48 | // only use one thread 49 | std::unique_ptr _thread; 50 | 51 | std::queue> _update_queue; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /src/opengl/delayed.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace opengl 6 | { 7 | namespace delayed 8 | { 9 | // all objects being delayed inherit from this class 10 | class object 11 | { 12 | public: 13 | object() 14 | : _finished_upload(false) 15 | {} 16 | 17 | virtual void upload() = 0; 18 | 19 | inline bool finished_upload() const { 20 | return _finished_upload; 21 | } 22 | 23 | protected: 24 | bool _finished_upload; 25 | }; 26 | 27 | // this is used to collect all objects _local_ to the draw entry point function (eg World::draw) 28 | // it is passed in to the draw function of a delayed::object 29 | // said object then check via uploader::can_draw if it can continue drawing 30 | // after all objects were drawn delayed::upload is called to upload a limited number of objects 31 | // im aware that it is not optimal for all objects to check if they can draw or not, 32 | // but i feel like it is the path of least resistance 33 | class uploader 34 | { 35 | public: 36 | inline bool can_draw(object* obj) { 37 | if(obj->finished_upload()) 38 | return true; 39 | 40 | _delayed_objects.insert(obj); 41 | return false; 42 | } 43 | 44 | void upload(size_t count) { 45 | size_t counter (std::min(count, _delayed_objects.size())); 46 | 47 | for(auto obj : _delayed_objects) { 48 | if(!counter) 49 | return; 50 | 51 | obj->upload(); 52 | 53 | counter--; 54 | } 55 | } 56 | 57 | private: 58 | std::unordered_set _delayed_objects; 59 | }; 60 | } 61 | } -------------------------------------------------------------------------------- /src/opengl/shader.fwd.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | namespace opengl 6 | { 7 | struct shader; 8 | struct program; 9 | 10 | namespace scoped 11 | { 12 | struct use_program; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/opengl/texture.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace opengl 9 | { 10 | texture::texture() 11 | : _id (0) 12 | { 13 | 14 | } 15 | 16 | texture::~texture() 17 | { 18 | if (_id > 0 && _id != -1) 19 | { 20 | gl.deleteTextures (1, &_id); 21 | } 22 | } 23 | 24 | texture::texture (texture&& other) 25 | : _id (other._id) 26 | { 27 | other._id = -1; 28 | } 29 | 30 | texture& texture::operator= (texture&& other) 31 | { 32 | std::swap (_id, other._id); 33 | return *this; 34 | } 35 | 36 | void texture::bind() 37 | { 38 | if (_id == 0) 39 | { 40 | gl.genTextures (1, &_id); 41 | } 42 | gl.bindTexture (GL_TEXTURE_2D, _id); 43 | } 44 | 45 | void texture::attach_to_framebuffer(GLenum attachment, int level) 46 | { 47 | if (_id == 0) 48 | { 49 | gl.genTextures(1, &_id); 50 | } 51 | 52 | gl.framebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, _id, level); 53 | } 54 | 55 | size_t texture::current_active_texture = -1; 56 | 57 | void texture::set_active_texture (size_t num) 58 | { 59 | if (num != current_active_texture) 60 | { 61 | gl.activeTexture(GL_TEXTURE0 + num); 62 | current_active_texture = num; 63 | } 64 | } 65 | 66 | void texture_array::bind() 67 | { 68 | if (_id == 0) 69 | { 70 | gl.genTextures(1, &_id); 71 | } 72 | gl.bindTexture(GL_TEXTURE_2D_ARRAY, _id); 73 | } 74 | 75 | #ifdef USE_BINDLESS_TEXTURES 76 | GLuint64 texture_array::get_resident_handle() 77 | { 78 | if (!_handle) 79 | { 80 | bind(); 81 | _handle = gl.getTextureHandleARB(_id); 82 | gl.makeTextureHandleResidentARB(_handle.value()); 83 | gl.bindTexture(GL_TEXTURE_2D_ARRAY, 0); 84 | } 85 | 86 | return _handle.value(); 87 | } 88 | #endif 89 | } 90 | -------------------------------------------------------------------------------- /src/opengl/texture.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace opengl 10 | { 11 | class texture 12 | { 13 | public: 14 | texture(); 15 | ~texture(); 16 | 17 | texture (texture const&) = delete; 18 | texture (texture&&); 19 | texture& operator= (texture const&) = delete; 20 | texture& operator= (texture&&); 21 | 22 | virtual void bind(); 23 | 24 | void attach_to_framebuffer(GLenum attachment, int level); 25 | 26 | static void set_active_texture (size_t num = 0); 27 | static size_t current_active_texture; 28 | 29 | protected: 30 | typedef GLuint internal_type; 31 | 32 | internal_type _id; 33 | }; 34 | 35 | class texture_array : texture 36 | { 37 | public: 38 | virtual void bind() override; 39 | 40 | #ifdef USE_BINDLESS_TEXTURES 41 | GLuint64 get_resident_handle(); 42 | #endif 43 | private: 44 | std::optional _handle; 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /src/opengl/types.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace opengl 8 | { 9 | typedef GLuint light; 10 | } 11 | -------------------------------------------------------------------------------- /src/util/exception_to_string.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | #include 5 | 6 | namespace util 7 | { 8 | namespace 9 | { 10 | std::string exception_to_string_impl 11 | (std::exception_ptr const& ep, std::size_t indentation, bool is_first) 12 | { 13 | auto const prefix {(is_first ? "" : "\n") + std::string (indentation, ' ')}; 14 | 15 | try 16 | { 17 | std::rethrow_exception (ep); 18 | } 19 | catch (std::exception const& e) 20 | { 21 | std::string res {prefix + e.what()}; 22 | 23 | try 24 | { 25 | std::rethrow_if_nested (e); 26 | } 27 | catch (...) 28 | { 29 | res += exception_to_string_impl 30 | (std::current_exception(), indentation + 1, false); 31 | } 32 | 33 | return res; 34 | } 35 | catch (...) 36 | { 37 | return prefix + ""; 38 | } 39 | 40 | return prefix + ""; 41 | } 42 | } 43 | 44 | std::string exception_to_string (std::exception_ptr ptr) 45 | { 46 | noggit::printStacktrace(); 47 | return exception_to_string_impl (ptr, 0, true); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/util/exception_to_string.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace util 9 | { 10 | std::string exception_to_string (std::exception_ptr); 11 | } 12 | -------------------------------------------------------------------------------- /src/util/qt/overload.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | //! \note Qt 5.7 finally adds a nice qOverload, but we don't require 8 | //! that. So, we just copy it here. 9 | #if QT_VERSION < QT_VERSION_CHECK (5, 7, 0) 10 | 11 | QT_BEGIN_NAMESPACE 12 | 13 | template 14 | struct QNonConstOverload 15 | { 16 | template 17 | Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr) 18 | { 19 | return ptr; 20 | } 21 | 22 | template 23 | static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr) 24 | { 25 | return ptr; 26 | } 27 | }; 28 | 29 | template 30 | struct QConstOverload 31 | { 32 | template 33 | Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr) 34 | { 35 | return ptr; 36 | } 37 | 38 | template 39 | static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr) 40 | { 41 | return ptr; 42 | } 43 | }; 44 | 45 | template 46 | struct QOverload : QConstOverload, QNonConstOverload 47 | { 48 | using QConstOverload::of; 49 | using QConstOverload::operator(); 50 | using QNonConstOverload::of; 51 | using QNonConstOverload::operator(); 52 | 53 | template 54 | Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr) 55 | { 56 | return ptr; 57 | } 58 | 59 | template 60 | static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr) 61 | { 62 | return ptr; 63 | } 64 | }; 65 | 66 | #if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14 67 | template 68 | Q_DECL_CONSTEXPR QOverload qOverload Q_DECL_UNUSED = {}; 69 | template 70 | Q_DECL_CONSTEXPR QConstOverload qConstOverload Q_DECL_UNUSED = {}; 71 | template 72 | Q_DECL_CONSTEXPR QNonConstOverload qNonConstOverload Q_DECL_UNUSED = {}; 73 | #endif 74 | 75 | QT_END_NAMESPACE 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/util/sExtendableArray.cpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #include 4 | 5 | namespace util 6 | { 7 | void sExtendableArray::Extend (long pAddition) 8 | { 9 | data.resize (data.size() + pAddition); 10 | } 11 | 12 | void sExtendableArray::Insert (unsigned long pPosition, unsigned long pAddition) 13 | { 14 | std::vector tmp (pAddition); 15 | data.insert (data.begin() + pPosition, tmp.begin(), tmp.end()); 16 | } 17 | 18 | void sExtendableArray::Insert (unsigned long pPosition, unsigned long pAddition, const char * pAdditionalData) 19 | { 20 | data.insert (data.begin() + pPosition, pAdditionalData, pAdditionalData + pAddition); 21 | } 22 | 23 | std::vector sExtendableArray::all_data() const 24 | { 25 | return data_up_to (data.size()); 26 | } 27 | std::vector sExtendableArray::data_up_to (std::size_t position) const 28 | { 29 | return std::vector (data.begin(), data.begin() + position); 30 | } 31 | 32 | sExtendableArray::sExtendableArray(unsigned long pSize, const char *pData) 33 | : data (pData, pData + pSize) 34 | {} 35 | } 36 | -------------------------------------------------------------------------------- /src/util/sExtendableArray.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace util 8 | { 9 | //! \todo This name is horrible. The API is mediocre. 10 | class sExtendableArray 11 | { 12 | std::vector data; 13 | 14 | public: 15 | //! Equivalent to `Allocate ($size + pAddition)`. 16 | void Extend (long pAddition); 17 | 18 | //! At \a pPosition, insert \a pAddition bytes that are all '\0', 19 | //! moving existing data further back. 20 | void Insert (unsigned long pPosition, unsigned long pAddition); 21 | 22 | //! At \a pPosition, insert \a pAddition bytes with the data at \a 23 | //! pAdditionalData, moving existing data further back. 24 | void Insert (unsigned long pPosition, unsigned long pAddition, const char * pAdditionalData); 25 | 26 | template 27 | struct LazyPointer 28 | { 29 | LazyPointer (std::vector& data, std::size_t position); 30 | T* get() const; 31 | T& operator*() const; 32 | T* operator->() const; 33 | T& operator[] (std::size_t) const; 34 | LazyPointer& operator+= (std::size_t); 35 | 36 | private: 37 | std::vector& _data; 38 | std::size_t _position; 39 | }; 40 | 41 | template 42 | LazyPointer GetPointer(unsigned long pPosition = 0); 43 | 44 | std::vector all_data() const; 45 | std::vector data_up_to (std::size_t position) const; 46 | 47 | sExtendableArray() = default; 48 | sExtendableArray(unsigned long pSize, const char *pData); 49 | }; 50 | } 51 | 52 | #include 53 | -------------------------------------------------------------------------------- /src/util/sExtendableArray.ipp: -------------------------------------------------------------------------------- 1 | // This file is part of Noggit3, licensed under GNU General Public License (version 3). 2 | 3 | namespace util 4 | { 5 | template 6 | sExtendableArray::LazyPointer sExtendableArray::GetPointer 7 | (unsigned long pPosition) 8 | { 9 | return {data, pPosition}; 10 | } 11 | 12 | template 13 | sExtendableArray::LazyPointer::LazyPointer 14 | (std::vector& data, std::size_t position) 15 | : _data (data) 16 | , _position (position) 17 | {} 18 | 19 | template 20 | T* sExtendableArray::LazyPointer::get() const 21 | { 22 | return reinterpret_cast (_data.data() + _position); 23 | } 24 | template 25 | T& sExtendableArray::LazyPointer::operator*() const 26 | { 27 | return *get(); 28 | } 29 | template 30 | T* sExtendableArray::LazyPointer::operator->() const 31 | { 32 | return get(); 33 | } 34 | template 35 | T& sExtendableArray::LazyPointer::operator[] (std::size_t i) const 36 | { 37 | return *(get() + i); 38 | } 39 | 40 | template 41 | sExtendableArray::LazyPointer& 42 | sExtendableArray::LazyPointer::operator+= (std::size_t num) 43 | { 44 | _position += num * sizeof (T); 45 | return *this; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/math/matrix_4x4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace math 6 | { 7 | BOOST_AUTO_TEST_CASE (translation) 8 | { 9 | vector_3d const trans (10.0f, 20.0f, -2.0f); 10 | 11 | BOOST_REQUIRE_EQUAL (matrix_4x4 (matrix_4x4::translation, trans) * vector_3d(), trans); 12 | BOOST_REQUIRE_EQUAL (matrix_4x4 (matrix_4x4::translation, trans) * trans, 2 * trans); 13 | } 14 | 15 | BOOST_AUTO_TEST_CASE (scale) 16 | { 17 | vector_3d const scal (10.0f, 20.0f, -2.0f); 18 | 19 | BOOST_REQUIRE_EQUAL (matrix_4x4 (matrix_4x4::scale, scal) * vector_3d(), vector_3d()); 20 | BOOST_REQUIRE_EQUAL (matrix_4x4 (matrix_4x4::scale, scal) * vector_3d (1.0f, 1.0f, 1.0f), scal); 21 | } 22 | 23 | //! \todo CHECK_CLOSE to not fail 24 | BOOST_AUTO_TEST_CASE (rotation) 25 | { 26 | BOOST_CHECK_EQUAL (matrix_4x4 (matrix_4x4::rotation, {0.f, 0.f, 0.f, 1.f}) * vector_3d(), vector_3d()); 27 | BOOST_CHECK_EQUAL (matrix_4x4 (matrix_4x4::rotation, {0.f, 0.f, 0.f, 1.f}) * vector_3d (1.f, 0.f, 0.f), vector_3d (1.f, 0.f, 0.f)); 28 | BOOST_CHECK_EQUAL (matrix_4x4 (matrix_4x4::rotation_xyz, {degrees (90.f), degrees (0.f), degrees (0.f)}) * vector_3d (1.f, 0.f, 0.f), vector_3d (1.f, 0.f, 0.f)); 29 | BOOST_CHECK_EQUAL (matrix_4x4 (matrix_4x4::rotation_xyz, {degrees (0.f), degrees (90.f), degrees (0.f)}) * vector_3d (1.f, 0.f, 0.f), vector_3d (0.f, 0.f, -1.f)); 30 | BOOST_CHECK_EQUAL (matrix_4x4 (matrix_4x4::rotation_xyz, {degrees (0.f), degrees (0.f), degrees (90.f)}) * vector_3d (1.f, 0.f, 0.f), vector_3d (0.f, -1.f, 0.f)); 31 | } 32 | } 33 | --------------------------------------------------------------------------------