├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake └── Modules │ ├── FindAssimp.cmake │ ├── FindOGRE.cmake │ ├── FindOIS.cmake │ ├── FindPkgMacros.cmake │ ├── MacroLogFeature.cmake │ ├── OgreAddTargets.cmake │ ├── OgreConfigTargets.cmake │ ├── OgreFindFrameworks.cmake │ ├── OgreGetVersion.cmake │ ├── PrecompiledHeader.cmake │ └── PreprocessorUtils.cmake ├── docs ├── Doxyfile ├── img │ ├── voxel_crack.png │ ├── voxel_crack_wire.png │ ├── voxel_customVoxelInformation.png │ ├── voxel_lod_wire.png │ ├── voxel_mesh.png │ ├── voxel_mesh_wire.png │ ├── voxel_multimaterial.png │ ├── voxel_noise.png │ ├── voxel_primitive.png │ └── voxel_primitive_wire.png └── manual │ └── voxel.dox ├── examples ├── CMakeLists.txt └── voxelterrain │ ├── CMakeLists.txt │ └── source │ ├── Handler.hpp │ ├── OgreTile.hpp │ ├── customVertexInformation.cpp │ ├── mesh.cpp │ ├── noise.cpp │ └── primitives.cpp └── modules ├── CMakeLists.txt ├── async ├── CMakeLists.txt └── source │ └── blub │ └── async │ ├── deadlineTimer.cpp │ ├── deadlineTimer.hpp │ ├── dispatcher.cpp │ ├── dispatcher.hpp │ ├── log │ ├── global.cpp │ └── global.hpp │ ├── mutex.hpp │ ├── mutexLocker.hpp │ ├── mutexReadWrite.hpp │ ├── predecl.hpp │ ├── strand.cpp │ ├── strand.hpp │ ├── updater.cpp │ └── updater.hpp ├── core ├── CMakeLists.txt └── source │ └── blub │ └── core │ ├── array.hpp │ ├── bind.hpp │ ├── byteArray.cpp │ ├── byteArray.hpp │ ├── classVersion.hpp │ ├── dateTime.cpp │ ├── dateTime.hpp │ ├── deque.hpp │ ├── enableSharedFromThis.hpp │ ├── geometry.hpp │ ├── globals.hpp.in │ ├── hashList.hpp │ ├── hashMap.hpp │ ├── hashMapMulti.hpp │ ├── idCreator.hpp │ ├── list.hpp │ ├── map.hpp │ ├── move.hpp │ ├── noncopyable.hpp │ ├── optional.hpp │ ├── pair.hpp │ ├── predecl.hpp │ ├── scopedPtr.hpp │ ├── sharedPointer.hpp │ ├── signal.hpp │ ├── state.hpp │ ├── string.cpp │ ├── string.hpp │ ├── stringList.hpp │ ├── timer.cpp │ ├── timer.hpp │ ├── vector.hpp │ └── weakPointer.hpp ├── log ├── CMakeLists.txt └── source │ └── blub │ └── log │ ├── global.cpp │ ├── global.hpp │ ├── globalLogger.hpp │ ├── logger.cpp │ ├── logger.hpp │ ├── predecl.hpp │ ├── system.cpp │ └── system.hpp ├── math ├── CMakeLists.txt └── source │ └── blub │ └── math │ ├── axisAlignedBox.cpp │ ├── axisAlignedBox.hpp │ ├── axisAlignedBoxInt32.hpp │ ├── axisAlignedBoxTemplate.hpp │ ├── colour.cpp │ ├── colour.hpp │ ├── intersection.cpp │ ├── intersection.hpp │ ├── log │ ├── global.cpp │ └── global.hpp │ ├── math.cpp │ ├── math.hpp │ ├── octree │ ├── container.hpp │ └── search.hpp │ ├── plane.cpp │ ├── plane.hpp │ ├── predecl.hpp │ ├── quaternion.cpp │ ├── quaternion.hpp │ ├── ray.cpp │ ├── ray.hpp │ ├── rectangle.cpp │ ├── rectangle.hpp │ ├── sphere.cpp │ ├── sphere.hpp │ ├── transform.cpp │ ├── transform.hpp │ ├── triangle.hpp │ ├── triangleVector3.cpp │ ├── triangleVector3.hpp │ ├── vector2.cpp │ ├── vector2.hpp │ ├── vector2int.hpp │ ├── vector3.cpp │ ├── vector3.hpp │ ├── vector3int.hpp │ └── vector3int32map.hpp ├── procedural ├── CMakeLists.txt └── source │ └── blub │ └── procedural │ ├── log │ ├── global.cpp │ └── global.hpp │ ├── predecl.hpp │ └── voxel │ ├── config.hpp │ ├── data.hpp │ ├── edit │ ├── axisAlignedBox.hpp │ ├── base.hpp │ ├── box.hpp │ ├── mesh.hpp │ ├── noise.hpp │ └── sphere.hpp │ ├── simple │ ├── accessor.hpp │ ├── base.hpp │ ├── container │ │ ├── base.cpp │ │ ├── base.hpp │ │ ├── database.hpp │ │ ├── inMemory.cpp │ │ ├── inMemory.hpp │ │ └── utils │ │ │ └── tile.hpp │ ├── renderer.hpp │ └── surface.hpp │ ├── terrain │ ├── accessor.hpp │ ├── base.hpp │ ├── renderer.hpp │ └── surface.hpp │ ├── tile │ ├── accessor.hpp │ ├── base.hpp │ ├── container.hpp │ ├── internal │ │ └── transvoxelTables.hpp │ ├── renderer.hpp │ └── surface.hpp │ └── vertex.hpp ├── serialization ├── CMakeLists.txt └── source │ └── blub │ └── serialization │ ├── access.hpp │ ├── callBaseObject.hpp │ ├── format │ ├── text │ │ ├── input.hpp │ │ └── output.hpp │ └── xml │ │ ├── input.hpp │ │ └── output.hpp │ ├── log │ ├── global.cpp │ └── global.hpp │ ├── nameValuePair.hpp │ ├── predecl.hpp │ └── saveLoad.hpp └── sync ├── CMakeLists.txt └── source └── blub └── sync ├── identifier.hpp ├── log ├── global.cpp └── global.hpp ├── predecl.hpp ├── receiver.cpp ├── receiver.hpp ├── sender.hpp └── voxel ├── accessor ├── multipleTiles │ ├── base.hpp │ ├── receiver.hpp │ └── sender.hpp └── terrain │ ├── receiver.hpp │ └── sender.hpp └── container └── multipleTiles ├── base.hpp ├── receiver.hpp └── sender.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeLists.txt.user 2 | docs/gen/ 3 | *.kdev4* 4 | *.tmp 5 | *.cfg 6 | *.dat 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Markus Lanner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VoxelTerrain 2 | All information about this library is available at [voxelTerrain.com](http://voxelterrain.com) 3 | 4 | ## Some images 5 | ![Primitives](/docs/img/voxel_primitive.png) 6 | ![Level of detail](/docs/img/voxel_lod_wire.png) 7 | 8 | 9 | -------------------------------------------------------------------------------- /cmake/Modules/FindAssimp.cmake: -------------------------------------------------------------------------------- 1 | # ASSIMP_FOUND - system has Assimp 2 | # ASSIMP_INCLUDE_DIRS - the Assimp include directories 3 | # ASSIMP_LIBRARIES - link these to use Assimp 4 | 5 | include(FindPkgMacros) 6 | findpkg_begin(ASSIMP) 7 | 8 | # Get path, convert backslashes as ${ENV_${var}} 9 | getenv_path(ASSIMP_HOME) 10 | 11 | # construct search paths 12 | set(ASSIMP_PREFIX_PATH ${ASSIMP_HOME} ${ENV_ASSIMP_HOME} /usr/local /usr/local/include /usr/local/lib /usr/include /usr/lib /usr/local/include/assimp /usr/include/assimp /usr/lib/assimp /usr/local/lib/assimp) 13 | create_search_paths(ASSIMP) 14 | # redo search if prefix path changed 15 | clear_if_changed(ASSIMP_PREFIX_PATH 16 | ASSIMP_LIBRARY_REL 17 | ASSIMP_LIBRARY_DBG 18 | ASSIMP_INCLUDE_DIR 19 | ) 20 | 21 | set(ASSIMP_LIBRARY_NAMES assimp) 22 | get_debug_names(ASSIMP_LIBRARY_NAMES) 23 | 24 | #use_pkgconfig(ASSIMP_PKGC ASSIMP) 25 | use_pkgconfig(ASSIMP assimp) 26 | 27 | findpkg_framework(ASSIMP) 28 | 29 | find_path(ASSIMP_INCLUDE_DIR NAMES config.h HINTS ${ASSIMP_INC_SEARCH_PATH} ${ASSIMP_PKGC_INCLUDE_DIRS} PATH_SUFFIXES assimp) 30 | find_library(ASSIMP_LIBRARY_REL NAMES ${ASSIMP_LIBRARY_NAMES} HINTS ${ASSIMP_LIB_SEARCH_PATH} ${ASSIMP_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" release relwithdebinfo minsizerel) 31 | find_library(ASSIMP_LIBRARY_DBG NAMES ${ASSIMP_LIBRARY_NAMES_DBG} HINTS ${ASSIMP_LIB_SEARCH_PATH} ${ASSIMP_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" debug) 32 | make_library_set(ASSIMP_LIBRARY) 33 | 34 | findpkg_finish(ASSIMP) 35 | add_parent_dir(ASSIMP_INCLUDE_DIRS ASSIMP_INCLUDE_DIR) 36 | 37 | -------------------------------------------------------------------------------- /cmake/Modules/FindOIS.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file is part of the CMake build system for OGRE 3 | # (Object-oriented Graphics Rendering Engine) 4 | # For the latest info, see http://www.ogre3d.org/ 5 | # 6 | # The contents of this file are placed in the public domain. Feel 7 | # free to make use of it in any way you like. 8 | #------------------------------------------------------------------- 9 | 10 | # - Try to find OIS 11 | # Once done, this will define 12 | # 13 | # OIS_FOUND - system has OIS 14 | # OIS_INCLUDE_DIRS - the OIS include directories 15 | # OIS_LIBRARIES - link these to use OIS 16 | # OIS_BINARY_REL / OIS_BINARY_DBG - DLL names (windows only) 17 | 18 | include(FindPkgMacros) 19 | findpkg_begin(OIS) 20 | 21 | # Get path, convert backslashes as ${ENV_${var}} 22 | getenv_path(OIS_HOME) 23 | getenv_path(OGRE_SDK) 24 | getenv_path(OGRE_HOME) 25 | getenv_path(OGRE_SOURCE) 26 | getenv_path(OGRE_DEPENDENCIES_DIR) 27 | 28 | # construct search paths 29 | set(OIS_PREFIX_PATH ${OIS_HOME} ${ENV_OIS_HOME} 30 | ${OGRE_DEPENDENCIES_DIR} ${ENV_OGRE_DEPENDENCIES_DIR} 31 | ${OGRE_SOURCE}/iOSDependencies ${ENV_OGRE_SOURCE}/iOSDependencies 32 | ${OGRE_SOURCE}/Dependencies ${ENV_OGRE_SOURCE}/Dependencies 33 | ${OGRE_SDK} ${ENV_OGRE_SDK} 34 | ${OGRE_HOME} ${ENV_OGRE_HOME}) 35 | create_search_paths(OIS) 36 | # redo search if prefix path changed 37 | clear_if_changed(OIS_PREFIX_PATH 38 | OIS_LIBRARY_FWK 39 | OIS_LIBRARY_REL 40 | OIS_LIBRARY_DBG 41 | OIS_INCLUDE_DIR 42 | ) 43 | 44 | set(OIS_LIBRARY_NAMES OIS) 45 | get_debug_names(OIS_LIBRARY_NAMES) 46 | 47 | use_pkgconfig(OIS_PKGC OIS) 48 | 49 | # For OIS, prefer static library over framework (important when referencing OIS source build) 50 | set(CMAKE_FIND_FRAMEWORK "LAST") 51 | 52 | findpkg_framework(OIS) 53 | if (OIS_HOME) 54 | # OIS uses the 'includes' path for its headers in the source release, not 'include' 55 | set(OIS_INC_SEARCH_PATH ${OIS_INC_SEARCH_PATH} ${OIS_HOME}/includes) 56 | endif() 57 | if (APPLE AND OIS_HOME) 58 | # OIS source build on Mac stores libs in a different location 59 | # Also this is for static build 60 | set(OIS_LIB_SEARCH_PATH ${OIS_LIB_SEARCH_PATH} ${OIS_HOME}/Mac/XCode-2.2/build) 61 | endif() 62 | find_path(OIS_INCLUDE_DIR NAMES OIS.h HINTS ${OIS_INC_SEARCH_PATH} ${OIS_PKGC_INCLUDE_DIRS} PATH_SUFFIXES OIS) 63 | find_library(OIS_LIBRARY_REL NAMES ${OIS_LIBRARY_NAMES} HINTS ${OIS_LIB_SEARCH_PATH} ${OIS_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" Release RelWithDebInfo MinSizeRel) 64 | find_library(OIS_LIBRARY_DBG NAMES ${OIS_LIBRARY_NAMES_DBG} HINTS ${OIS_LIB_SEARCH_PATH} ${OIS_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" Debug) 65 | 66 | make_library_set(OIS_LIBRARY) 67 | 68 | if (WIN32) 69 | set(OIS_BIN_SEARCH_PATH ${OGRE_DEPENDENCIES_DIR}/bin ${CMAKE_SOURCE_DIR}/Dependencies/bin ${OIS_HOME}/dll 70 | ${ENV_OIS_HOME}/dll ${ENV_OGRE_DEPENDENCIES_DIR}/bin 71 | ${OGRE_SOURCE}/Dependencies/bin ${ENV_OGRE_SOURCE}/Dependencies/bin 72 | ${OGRE_SDK}/bin ${ENV_OGRE_SDK}/bin 73 | ${OGRE_HOME}/bin ${ENV_OGRE_HOME}/bin) 74 | find_file(OIS_BINARY_REL NAMES "OIS.dll" HINTS ${OIS_BIN_SEARCH_PATH} 75 | PATH_SUFFIXES "" Release RelWithDebInfo MinSizeRel) 76 | find_file(OIS_BINARY_DBG NAMES "OIS_d.dll" HINTS ${OIS_BIN_SEARCH_PATH} 77 | PATH_SUFFIXES "" Debug ) 78 | endif() 79 | mark_as_advanced(OIS_BINARY_REL OIS_BINARY_DBG) 80 | 81 | 82 | findpkg_finish(OIS) 83 | 84 | # add parent of OIS folder to support OIS/OIS.h 85 | add_parent_dir(OIS_INCLUDE_DIRS OIS_INCLUDE_DIR) 86 | 87 | # Reset framework finding 88 | set(CMAKE_FIND_FRAMEWORK "FIRST") 89 | -------------------------------------------------------------------------------- /cmake/Modules/OgreAddTargets.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file is part of the CMake build system for OGRE 3 | # (Object-oriented Graphics Rendering Engine) 4 | # For the latest info, see http://www.ogre3d.org/ 5 | # 6 | # The contents of this file are placed in the public domain. Feel 7 | # free to make use of it in any way you like. 8 | #------------------------------------------------------------------- 9 | 10 | # check the contents of a given source file. If they differ from the 11 | # expected content, or the file does not exist, rewrite it with the 12 | # provided content. 13 | # This function is used in order to update Unity build files only when 14 | # necessary. If we rewrote them unconditionally, it might trigger an 15 | # unnecessary rebuild of the file. 16 | function(check_and_update_file FILENAME CONTENT) 17 | # read current file contents 18 | if (EXISTS ${FILENAME}) 19 | file(READ ${FILENAME} _CUR) 20 | else () 21 | # create empty file 22 | file(WRITE ${FILENAME} "") 23 | set(_CUR "") 24 | endif () 25 | if (NOT _CUR STREQUAL CONTENT) 26 | # rewrite file with new contents 27 | message(STATUS " Updating ${FILENAME}...") 28 | file(WRITE ${FILENAME} ${CONTENT}) 29 | else () 30 | message(STATUS " ${FILENAME} is up to date.") 31 | endif () 32 | endfunction() 33 | 34 | 35 | # generate unity build files for the given target. 36 | # If in the list of source files the key word SEPARATE is specified, then 37 | # any source file after that will be compiled separately. 38 | macro(create_unity_build_files TARGETNAME) 39 | # first step: build the primary and separate lists 40 | set(_PRIMARY "") 41 | set(_EXCLUDES "") 42 | set(_SEP FALSE) 43 | foreach(_FILE ${ARGN}) 44 | if (_FILE STREQUAL "SEPARATE") 45 | set(_SEP TRUE) 46 | else () 47 | if (_SEP) 48 | list(APPEND _EXCLUDES ${_FILE}) 49 | else () 50 | list(APPEND _PRIMARY ${_FILE}) 51 | endif () 52 | endif() 53 | endforeach() 54 | set(_SOURCES ${_PRIMARY} ${_EXCLUDES}) 55 | list(REMOVE_DUPLICATES _SOURCES) 56 | 57 | if (OGRE_UNITY_BUILD) 58 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 59 | # create Unity compilation units 60 | # all source files given will be put into a certain number of 61 | # compilation units. 62 | # if certain source files should be excluded from the unity build 63 | # and built separately, they need to also be named in the SEPARATE 64 | # list. 65 | set(_FILE_NUM 0) 66 | set(_FILE_CNT 0) 67 | set(_FILE_CONTENTS "") 68 | message(STATUS "Creating Unity build files for target ${TARGETNAME}") 69 | foreach(_FILE ${_PRIMARY}) 70 | # test if file is more than just a header 71 | get_filename_component(_EXT ${_FILE} EXT) 72 | list(FIND _EXCLUDES ${_FILE} _EXCLUDED) 73 | if ((_EXT STREQUAL ".cpp") AND (_EXCLUDED EQUAL "-1")) 74 | set(_FILE_CONTENTS "${_FILE_CONTENTS}\#include \"${_FILE}\"\n") 75 | math(EXPR _FILE_CNT "${_FILE_CNT}+1") 76 | if(_FILE_CNT EQUAL OGRE_UNITY_FILES_PER_UNIT) 77 | set(_FILENAME "${OGRE_BINARY_DIR}/${TARGETNAME}/compile_${TARGETNAME}_${_FILE_NUM}.cpp") 78 | check_and_update_file(${_FILENAME} ${_FILE_CONTENTS}) 79 | math(EXPR _FILE_NUM "${_FILE_NUM}+1") 80 | set(_FILE_CNT 0) 81 | set (_FILE_CONTENTS "") 82 | list(APPEND _SOURCES ${_FILENAME}) 83 | endif() 84 | # exclude the original source file from the compilation 85 | set_source_files_properties(${_FILE} PROPERTIES LANGUAGE "" HEADER_FILE_ONLY TRUE) 86 | endif() 87 | endforeach() 88 | # don't forget the last set of files 89 | set(_FILENAME "${OGRE_BINARY_DIR}/${TARGETNAME}/compile_${TARGETNAME}_${_FILE_NUM}.cpp") 90 | check_and_update_file(${_FILENAME} ${_FILE_CONTENTS}) 91 | list(APPEND _SOURCES ${_FILENAME}) 92 | endif () 93 | endmacro() 94 | 95 | 96 | # add a new library target 97 | # usage: ogre_add_library(TARGETNAME LIBTYPE SOURCE_FILES [SEPARATE SOURCE_FILES]) 98 | function(ogre_add_library TARGETNAME LIBTYPE) 99 | create_unity_build_files(${TARGETNAME} ${ARGN}) 100 | add_library(${TARGETNAME} ${LIBTYPE} ${_SOURCES}) 101 | endfunction(ogre_add_library) 102 | 103 | 104 | # add a new executable target 105 | # usage: ogre_add_executable(TARGETNAME [WIN32] [MACOSX_BUNDLE] SOURCE_FILES [SEPARATE SOURCE_FILES]) 106 | function(ogre_add_executable TARGETNAME) 107 | # test if WIN32 or MACOSX_BUNDLE options were provided 108 | set(_WIN32 "") 109 | set(_OSX "") 110 | list(FIND ARGN "WIN32" _W32_IDX) 111 | if (_W32_IDX GREATER "-1") 112 | set(_WIN32 "WIN32") 113 | list(REMOVE_AT ARGN ${_W32_IDX}) 114 | endif () 115 | list(FIND ARGN "MACOSX_BUNDLE" _OSX_IDX) 116 | if (_OSX_IDX GREATER "-1") 117 | set(_OSX "MACOSX_BUNDLE") 118 | list(REMOVE_AT ARGN ${_OSX_IDX}) 119 | endif () 120 | create_unity_build_files(${TARGETNAME} ${ARGN}) 121 | add_executable(${TARGETNAME} ${_WIN32} ${_OSX} ${_SOURCES}) 122 | endfunction() 123 | -------------------------------------------------------------------------------- /cmake/Modules/OgreFindFrameworks.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file is part of the CMake build system for OGRE 3 | # (Object-oriented Graphics Rendering Engine) 4 | # For the latest info, see http://www.ogre3d.org/ 5 | # 6 | # The contents of this file are placed in the public domain. Feel 7 | # free to make use of it in any way you like. 8 | #------------------------------------------------------------------- 9 | 10 | # - helper module to find OSX frameworks 11 | # Adapted from standard CMake version, but added dependencies 12 | # Standard finder does not look in any variable locations such as 13 | # CMAKE_FRAMEWORK_PATH (not sure why not) 14 | 15 | IF(NOT OGRE_FIND_FRAMEWORKS_INCLUDED) 16 | SET(OGRE_FIND_FRAMEWORKS_INCLUDED 1) 17 | MACRO(OGRE_FIND_FRAMEWORKS fwk) 18 | IF(APPLE) 19 | SET(${fwk}_FRAMEWORKS) 20 | SET(OGRE_FRAMEWORK_PATH 21 | ${OGRE_DEPENDENCIES_DIR} 22 | ~/Library/Frameworks 23 | /Library/Frameworks 24 | /System/Library/Frameworks 25 | /Network/Library/Frameworks 26 | ) 27 | FOREACH(dir ${OGRE_FRAMEWORK_PATH}) 28 | SET(fwkpath ${dir}/${fwk}.framework) 29 | IF(EXISTS ${fwkpath}) 30 | SET(${fwk}_FRAMEWORKS ${${fwk}_FRAMEWORKS} ${fwkpath}) 31 | ENDIF(EXISTS ${fwkpath}) 32 | ENDFOREACH(dir) 33 | ENDIF(APPLE) 34 | ENDMACRO(OGRE_FIND_FRAMEWORKS) 35 | ENDIF(NOT OGRE_FIND_FRAMEWORKS_INCLUDED) 36 | -------------------------------------------------------------------------------- /cmake/Modules/OgreGetVersion.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file is part of the CMake build system for OGRE 3 | # (Object-oriented Graphics Rendering Engine) 4 | # For the latest info, see http://www.ogre3d.org/ 5 | # 6 | # The contents of this file are placed in the public domain. Feel 7 | # free to make use of it in any way you like. 8 | #------------------------------------------------------------------- 9 | 10 | include(PreprocessorUtils) 11 | 12 | macro(ogre_get_version HEADER) 13 | file(READ ${HEADER} TEMP_VAR_CONTENTS) 14 | get_preprocessor_entry(TEMP_VAR_CONTENTS OGRE_VERSION_MAJOR OGRE_VERSION_MAJOR) 15 | get_preprocessor_entry(TEMP_VAR_CONTENTS OGRE_VERSION_MINOR OGRE_VERSION_MINOR) 16 | get_preprocessor_entry(TEMP_VAR_CONTENTS OGRE_VERSION_PATCH OGRE_VERSION_PATCH) 17 | get_preprocessor_entry(TEMP_VAR_CONTENTS OGRE_VERSION_NAME OGRE_VERSION_NAME) 18 | get_preprocessor_entry(TEMP_VAR_CONTENTS OGRE_VERSION_SUFFIX OGRE_VERSION_SUFFIX) 19 | set(OGRE_VERSION "${OGRE_VERSION_MAJOR}.${OGRE_VERSION_MINOR}.${OGRE_VERSION_PATCH}${OGRE_VERSION_SUFFIX}") 20 | set(OGRE_SOVERSION "${OGRE_VERSION_MAJOR}.${OGRE_VERSION_MINOR}.${OGRE_VERSION_PATCH}") 21 | set(OGRE_VERSION_DASH_SEPARATED "${OGRE_VERSION_MAJOR}-${OGRE_VERSION_MINOR}-${OGRE_VERSION_PATCH}${OGRE_VERSION_SUFFIX}") 22 | 23 | endmacro() 24 | -------------------------------------------------------------------------------- /cmake/Modules/PrecompiledHeader.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file is part of the CMake build system for OGRE 3 | # (Object-oriented Graphics Rendering Engine) 4 | # For the latest info, see http://www.ogre3d.org/ 5 | # 6 | # The contents of this file are placed in the public domain. Feel 7 | # free to make use of it in any way you like. 8 | #------------------------------------------------------------------- 9 | 10 | ################################################################## 11 | # Support macro to use a precompiled header 12 | # Usage: 13 | # use_precompiled_header(TARGET HEADER_FILE SRC_FILE) 14 | ################################################################## 15 | 16 | macro(use_precompiled_header TARGET HEADER_FILE SRC_FILE) 17 | get_filename_component(HEADER ${HEADER_FILE} NAME) 18 | 19 | # Use MSVC_IDE to exclude NMake from using PCHs 20 | if (MSVC AND NOT NMAKE AND NOT OGRE_UNITY_BUILD AND NOT ${CMAKE_GENERATOR} MATCHES Ninja) 21 | add_definitions(/Yu"${HEADER}") 22 | set_source_files_properties(${SRC_FILE} 23 | PPROPERTIES COMPILE_FLAGS /Yc"${HEADER}" 24 | ) 25 | 26 | elseif (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) 27 | # disabled because it seems to increase compile time 28 | ## this is some serious hack... we definitely need native 29 | ## support in CMake for this! 30 | ## we will generate the precompiled header via a workaround 31 | ## first give the header a new name with the proper extension 32 | #set(PRECOMP_HEADER ${CMAKE_CURRENT_BINARY_DIR}/hacked/${HEADER}.gch) 33 | #configure_file(${HEADER_FILE} ${PRECOMP_HEADER} COPYONLY) 34 | ## retrieve some info about the target's build settings 35 | #get_target_property(${TARGET} PRECOMP_TYPE TYPE) 36 | #if (PRECOMP_TYPE STREQUAL "SHARED_LIBRARY") 37 | # set(PRECOMP_LIBTYPE "SHARED") 38 | #else () 39 | # set(PRECOMP_LIBTYPE "STATIC") 40 | #endif () 41 | #get_target_property(${TARGET} PRECOMP_DEFINITIONS COMPILE_DEFINITIONS) 42 | #get_target_property(${TARGET} PRECOMP_FLAGS COMPILE_FLAGS) 43 | # 44 | ## add a new target which compiles the header 45 | #add_library(__precomp_header ${PRECOMP_LIBTYPE} ${PRECOMP_HEADER}) 46 | #add_dependencies(${TARGET} __precomp_header) 47 | #set_target_properties(__precomp_header PROPERTIES 48 | # COMPILE_DEFINITIONS ${PRECOMP_DEFINITIONS} 49 | # COMPILE_FLAGS ${PRECOMP_FLAGS} 50 | # HAS_CXX TRUE 51 | #) 52 | #set_source_files_properties(${PRECOMP_HEADER} PROPERTIES 53 | # HEADER_FILE_ONLY FALSE 54 | # KEEP_EXTENSION TRUE 55 | # COMPILE_FLAGS "-x c++-header" 56 | # LANGUAGE CXX 57 | #) 58 | # 59 | ## finally, we need to ensure that gcc can find the precompiled header 60 | ## this is another dirty hack 61 | #include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/__precomp_header.dir/hacked") 62 | 63 | endif () 64 | endmacro(use_precompiled_header) 65 | -------------------------------------------------------------------------------- /cmake/Modules/PreprocessorUtils.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file is part of the CMake build system for OGRE 3 | # (Object-oriented Graphics Rendering Engine) 4 | # For the latest info, see http://www.ogre3d.org/ 5 | # 6 | # The contents of this file are placed in the public domain. Feel 7 | # free to make use of it in any way you like. 8 | #------------------------------------------------------------------- 9 | 10 | macro(get_preprocessor_entry CONTENTS KEYWORD VARIABLE) 11 | string(REGEX MATCH 12 | "# *define +${KEYWORD} +((\"([^\n]*)\")|([^ \n]*))" 13 | PREPROC_TEMP_VAR 14 | ${${CONTENTS}} 15 | ) 16 | if (CMAKE_MATCH_3) 17 | set(${VARIABLE} ${CMAKE_MATCH_3}) 18 | else () 19 | set(${VARIABLE} ${CMAKE_MATCH_4}) 20 | endif () 21 | endmacro() 22 | 23 | macro(has_preprocessor_entry CONTENTS KEYWORD VARIABLE) 24 | string(REGEX MATCH 25 | "\n *# *define +(${KEYWORD})" 26 | PREPROC_TEMP_VAR 27 | ${${CONTENTS}} 28 | ) 29 | if (CMAKE_MATCH_1) 30 | set(${VARIABLE} TRUE) 31 | else () 32 | set(${VARIABLE} FALSE) 33 | endif () 34 | endmacro() 35 | 36 | macro(replace_preprocessor_entry VARIABLE KEYWORD NEW_VALUE) 37 | string(REGEX REPLACE 38 | "(// *)?# *define +${KEYWORD} +[^ \n]*" 39 | "#define ${KEYWORD} ${NEW_VALUE}" 40 | ${VARIABLE}_TEMP 41 | ${${VARIABLE}} 42 | ) 43 | set(${VARIABLE} ${${VARIABLE}_TEMP}) 44 | endmacro() 45 | 46 | macro(set_preprocessor_entry VARIABLE KEYWORD ENABLE) 47 | if (${ENABLE}) 48 | set(TMP_REPLACE_STR "#define ${KEYWORD}") 49 | else () 50 | set(TMP_REPLACE_STR "// #define ${KEYWORD}") 51 | endif () 52 | string(REGEX REPLACE 53 | "(// *)?# *define +${KEYWORD} *\n" 54 | ${TMP_REPLACE_STR} 55 | ${VARIABLE}_TEMP 56 | ${${VARIABLE}} 57 | ) 58 | set(${VARIABLE} ${${VARIABLE}_TEMP}) 59 | endmacro() 60 | 61 | -------------------------------------------------------------------------------- /docs/img/voxel_crack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_crack.png -------------------------------------------------------------------------------- /docs/img/voxel_crack_wire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_crack_wire.png -------------------------------------------------------------------------------- /docs/img/voxel_customVoxelInformation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_customVoxelInformation.png -------------------------------------------------------------------------------- /docs/img/voxel_lod_wire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_lod_wire.png -------------------------------------------------------------------------------- /docs/img/voxel_mesh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_mesh.png -------------------------------------------------------------------------------- /docs/img/voxel_mesh_wire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_mesh_wire.png -------------------------------------------------------------------------------- /docs/img/voxel_multimaterial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_multimaterial.png -------------------------------------------------------------------------------- /docs/img/voxel_noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_noise.png -------------------------------------------------------------------------------- /docs/img/voxel_primitive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_primitive.png -------------------------------------------------------------------------------- /docs/img/voxel_primitive_wire.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/docs/img/voxel_primitive_wire.png -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # example macro 2 | macro (add_example example_name) 3 | message( STATUS "Creating example ${example_name}" ) 4 | set (INCLUDES ${INCLUDES} 5 | source 6 | ) 7 | prefix_list( 8 | "source/" 9 | sources 10 | sources_with_prefix 11 | ) 12 | prefix_list( 13 | "source/" 14 | headers 15 | headers_with_prefix 16 | ) 17 | include_directories(${INCLUDES}) 18 | 19 | # one example consists of one cpp. All other helper classes are header only. 20 | # Makes it easier to read the example, than rather jumping between several implementation files. 21 | # so every cpp has to have a main will become an executeable. 22 | foreach(MAIN_TO_BUILD ${sources_with_prefix}) 23 | GET_FILENAME_COMPONENT(MAIN_TO_BUILD_NAME ${MAIN_TO_BUILD} NAME_WE) 24 | set(MAIN_TO_BUILD_RESULT_NAME "example-${example_name}-${MAIN_TO_BUILD_NAME}") 25 | add_executable(${MAIN_TO_BUILD_RESULT_NAME} ${MAIN_TO_BUILD} ${headers_with_prefix}) 26 | target_link_libraries(${MAIN_TO_BUILD_RESULT_NAME} ${BLUB_LIBRARIES_TO_BUILD} ${LIBS}) 27 | set_property(TARGET ${MAIN_TO_BUILD_RESULT_NAME} PROPERTY DEBUG_POSTFIX _d) 28 | if (BLUB_INSTALL_EXAMPLES) 29 | install (TARGETS ${MAIN_TO_BUILD_RESULT_NAME} 30 | DESTINATION bin) 31 | endif(BLUB_INSTALL_EXAMPLES) 32 | endforeach(MAIN_TO_BUILD) 33 | endmacro (add_example) 34 | 35 | option (BLUB_INSTALL_EXAMPLES "install examples" ON) 36 | 37 | set(EXAMPLES_TO_BUILD ${EXAMPLES_TO_BUILD} 38 | voxelterrain 39 | ) 40 | 41 | if (BLUB_BUILD_GRAPHIC) 42 | set(EXAMPLES_TO_BUILD ${EXAMPLES_TO_BUILD} graphic) 43 | endif (BLUB_BUILD_GRAPHIC) 44 | if (BLUB_BUILD_PHYSIC) 45 | set(EXAMPLES_TO_BUILD ${EXAMPLES_TO_BUILD} physic) 46 | endif (BLUB_BUILD_PHYSIC) 47 | if (BLUB_BUILD_WEB) 48 | set(EXAMPLES_TO_BUILD ${EXAMPLES_TO_BUILD} web) 49 | endif (BLUB_BUILD_WEB) 50 | 51 | foreach(EXAMPLE_TO_BUILD ${EXAMPLES_TO_BUILD}) 52 | add_subdirectory(${EXAMPLE_TO_BUILD}) 53 | endforeach(EXAMPLE_TO_BUILD) 54 | 55 | 56 | -------------------------------------------------------------------------------- /examples/voxelterrain/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(sources 3 | customVertexInformation.cpp 4 | noise.cpp 5 | primitives.cpp 6 | ) 7 | 8 | if (BLUB_USE_ASSIMP) 9 | set(sources ${sources} mesh.cpp) 10 | endif(BLUB_USE_ASSIMP) 11 | 12 | set(headers 13 | Handler.hpp 14 | OgreTile.hpp 15 | ) 16 | 17 | add_example(voxelterrain) 18 | 19 | -------------------------------------------------------------------------------- /examples/voxelterrain/source/mesh.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/log/global.hpp" 2 | #include "blub/log/system.hpp" 3 | #include "blub/math/math.hpp" 4 | #include "blub/math/quaternion.hpp" 5 | #include "blub/math/sphere.hpp" 6 | #include "blub/math/transform.hpp" 7 | #include "blub/sync/identifier.hpp" 8 | #include "blub/procedural/voxel/edit/mesh.hpp" 9 | #include "blub/procedural/voxel/edit/sphere.hpp" 10 | #include "blub/procedural/voxel/simple/container/inMemory.hpp" 11 | #include "blub/procedural/voxel/terrain/accessor.hpp" 12 | #include "blub/procedural/voxel/terrain/surface.hpp" 13 | #include "blub/procedural/voxel/terrain/renderer.hpp" 14 | #include "blub/procedural/voxel/tile/container.hpp" 15 | 16 | #include "OgreTile.hpp" 17 | #include "Handler.hpp" 18 | 19 | 20 | 21 | /** @example mesh.cpp 22 | * This is an example that converts a mesh, loaded by collada, to voxels and renders them. 23 | * @image html voxel_mesh_wire.png 24 | */ 25 | 26 | 27 | using namespace blub::procedural; 28 | using namespace blub; 29 | 30 | 31 | typedef sharedPointer t_cameraIdentifier; 32 | typedef voxel::data t_voxel; 33 | typedef voxel::simple::container::inMemory t_voxelContainer; 34 | typedef voxel::terrain::accessor t_voxelAccessor; 35 | typedef voxel::terrain::renderer t_voxelRenderer; 36 | typedef voxel::terrain::surface t_voxelSurface; 37 | typedef voxel::edit::base t_voxelEdit; 38 | typedef OgreTile t_renderTile; 39 | 40 | 41 | void createSphere(t_voxelContainer *container, const vector3 &position, const bool &cut); 42 | 43 | 44 | int main(int /*argc*/, char* /*argv*/[]) 45 | { 46 | blub::log::system::addConsole(); 47 | blub::log::system::addFile("voxelterrain.log"); 48 | 49 | Handler handler; 50 | if (!handler.initialiseOgre()) 51 | { 52 | return EXIT_FAILURE; 53 | } 54 | if (!handler.initialiseOIS()) 55 | { 56 | return EXIT_FAILURE; 57 | } 58 | 59 | // initialise terrain 60 | 61 | scopedPointer voxelContainer; 62 | scopedPointer voxelAccessor; 63 | scopedPointer voxelSurface; 64 | scopedPointer voxelRenderer; 65 | 66 | async::dispatcher terrainDispatcher(4, false, "terrain"); 67 | 68 | t_cameraIdentifier cameraIdentifier; 69 | { 70 | const int32 numLod(3); // no lod for mesh to voxel presentation 71 | 72 | // voxel themself 73 | voxelContainer.reset(new t_voxelContainer(terrainDispatcher)); 74 | 75 | // accessor 76 | voxelAccessor.reset(new t_voxelAccessor(terrainDispatcher, *voxelContainer, numLod)); 77 | 78 | // surface 79 | voxelSurface.reset(new t_voxelSurface(terrainDispatcher, *voxelAccessor)); 80 | 81 | // ogre3d render wrapper 82 | const t_voxelRenderer::t_createTileCallback callbackCreate = boost::bind(t_renderTile::create, handler.renderScene, "none", &handler.graphicDispatcher); 83 | 84 | // renderer 85 | t_voxelRenderer::t_syncRadiusList lodRadien(numLod); 86 | lodRadien[0] = voxel::tile::container::voxelLength*2.0; 87 | lodRadien[1] = voxel::tile::container::voxelLength*4.0; 88 | lodRadien[2] = voxel::tile::container::voxelLength*6.0; 89 | voxelRenderer.reset(new t_voxelRenderer(terrainDispatcher, *voxelSurface, lodRadien)); 90 | voxelRenderer->setCreateTileCallback(callbackCreate); 91 | cameraIdentifier = sync::identifier::create(); 92 | voxelRenderer->addCamera(cameraIdentifier, handler.camera->getPosition()); 93 | handler.signalFrame()->connect( 94 | [&] (real) 95 | { 96 | voxelRenderer->updateCamera(cameraIdentifier, handler.camera->getPosition()); 97 | } 98 | ); 99 | 100 | // add/cut sphere when mouse-button gets pressed 101 | handler.signalMouseGotPressed()->connect( 102 | [&] (bool &left) 103 | { 104 | createSphere(voxelContainer.get(), handler.camera->getPosition()+handler.camera->getDirection()*10., !left); 105 | } 106 | ); 107 | } 108 | 109 | // create voxel 110 | { 111 | voxel::edit::mesh::pointer mesh(voxel::edit::mesh::create()); 112 | mesh->load("/home/mlanner/Desktop/test.dae", transform(vector3(), quaternion(), 10.0)); 113 | voxelContainer->editVoxel(mesh); 114 | } 115 | 116 | 117 | // start rendering and begin terrain worker. 118 | { 119 | terrainDispatcher.start(); 120 | handler.renderSystem->startRendering(); // ends when render-window closes 121 | terrainDispatcher.stop(); 122 | } 123 | 124 | return EXIT_SUCCESS; 125 | } 126 | 127 | 128 | void createSphere(t_voxelContainer *container, const vector3 &position, const bool &cut) 129 | { 130 | BLUB_LOG_OUT() << "createSphere"; 131 | 132 | voxel::edit::sphere::pointer sphereEdit(voxel::edit::sphere::create(sphere(position, 5.))); 133 | sphereEdit->setCut(cut); 134 | container->editVoxel(sphereEdit); 135 | } 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /examples/voxelterrain/source/noise.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/log/global.hpp" 2 | #include "blub/log/system.hpp" 3 | #include "blub/math/math.hpp" 4 | #include "blub/math/quaternion.hpp" 5 | #include "blub/math/sphere.hpp" 6 | #include "blub/math/transform.hpp" 7 | #include "blub/sync/identifier.hpp" 8 | #include "blub/procedural/voxel/config.hpp" 9 | #include "blub/procedural/voxel/edit/noise.hpp" 10 | #include "blub/procedural/voxel/edit/sphere.hpp" 11 | #include "blub/procedural/voxel/simple/accessor.hpp" 12 | #include "blub/procedural/voxel/simple/container/inMemory.hpp" 13 | #include "blub/procedural/voxel/simple/renderer.hpp" 14 | #include "blub/procedural/voxel/simple/surface.hpp" 15 | #include "blub/procedural/voxel/terrain/accessor.hpp" 16 | #include "blub/procedural/voxel/terrain/surface.hpp" 17 | #include "blub/procedural/voxel/terrain/renderer.hpp" 18 | #include "blub/procedural/voxel/tile/container.hpp" 19 | #include "blub/procedural/voxel/tile/renderer.hpp" 20 | #include "blub/procedural/voxel/tile/surface.hpp" 21 | 22 | #include "OgreTile.hpp" 23 | #include "Handler.hpp" 24 | 25 | 26 | /** @example noise.cpp 27 | * This is an example creates a randomized figure by using simplex noise. 28 | * @image html voxel_noise.png 29 | */ 30 | 31 | 32 | using namespace blub::procedural; 33 | using namespace blub; 34 | 35 | 36 | struct config : public voxel::config 37 | { 38 | typedef container t_container; 39 | typedef accessor t_accessor; 40 | typedef surface t_surface; 41 | template 42 | struct renderer : public voxel::config::renderer 43 | { 44 | typedef OgreTile t_tile; 45 | }; 46 | typedef renderer t_renderer; 47 | }; 48 | 49 | typedef sharedPointer t_cameraIdentifier; 50 | typedef config t_config; 51 | typedef voxel::simple::container::inMemory t_voxelContainer; 52 | typedef voxel::terrain::accessor t_voxelAccessor; 53 | typedef voxel::terrain::renderer t_voxelRenderer; 54 | typedef voxel::terrain::surface t_voxelSurface; 55 | typedef voxel::edit::noise t_editNoise; 56 | typedef voxel::edit::sphere t_editSphere; 57 | typedef OgreTile t_renderTile; 58 | 59 | 60 | void createSphere(t_voxelContainer *container, const vector3 &position, const bool &cut); 61 | 62 | 63 | int main(int /*argc*/, char* /*argv*/[]) 64 | { 65 | blub::log::system::addConsole(); 66 | blub::log::system::addFile("voxelterrain.log"); 67 | 68 | Handler handler; 69 | if (!handler.initialiseOgre()) 70 | { 71 | return EXIT_FAILURE; 72 | } 73 | if (!handler.initialiseOIS()) 74 | { 75 | return EXIT_FAILURE; 76 | } 77 | 78 | // initialise terrain 79 | 80 | scopedPointer voxelContainer; 81 | scopedPointer voxelAccessor; 82 | scopedPointer voxelSurface; 83 | scopedPointer voxelRenderer; 84 | 85 | async::dispatcher terrainDispatcher(12, false, "terrain"); 86 | 87 | t_cameraIdentifier cameraIdentifier; 88 | { 89 | const int32 numLod(3); 90 | 91 | // voxel themself 92 | voxelContainer.reset(new t_voxelContainer(terrainDispatcher)); 93 | 94 | // accessor 95 | voxelAccessor.reset(new t_voxelAccessor(terrainDispatcher, *voxelContainer, numLod)); 96 | 97 | // surface 98 | voxelSurface.reset(new t_voxelSurface(terrainDispatcher, *voxelAccessor)); 99 | 100 | // ogre3d render wrapper 101 | const t_voxelRenderer::t_createTileCallback callbackCreate = boost::bind(t_renderTile::create, handler.renderScene, "none", &handler.graphicDispatcher); 102 | 103 | // renderer 104 | t_voxelRenderer::t_syncRadiusList lodRadien(numLod); 105 | lodRadien[0] = t_config::voxelsPerTile*2.0; 106 | lodRadien[1] = t_config::voxelsPerTile*2.0; 107 | lodRadien[2] = t_config::voxelsPerTile*2.0; 108 | voxelRenderer.reset(new t_voxelRenderer(terrainDispatcher, *voxelSurface, lodRadien)); 109 | voxelRenderer->setCreateTileCallback(callbackCreate); 110 | cameraIdentifier = sync::identifier::create(); 111 | voxelRenderer->addCamera(cameraIdentifier, handler.camera->getPosition()); 112 | handler.signalFrame()->connect( 113 | [&] (real) 114 | { 115 | voxelRenderer->updateCamera(cameraIdentifier, handler.camera->getPosition()); 116 | } 117 | ); 118 | 119 | // add/cut sphere when mouse-button gets pressed 120 | handler.signalMouseGotPressed()->connect( 121 | [&] (bool left) 122 | { 123 | createSphere(voxelContainer.get(), handler.camera->getPosition()+handler.camera->getDirection()*10., !left); 124 | } 125 | ); 126 | } 127 | 128 | // create voxel 129 | { 130 | t_editNoise::pointer noise(t_editNoise::create(axisAlignedBox(vector3(-100., -100., -100), vector3(100., 100., 100.)), vector3(0.025))); 131 | voxelContainer->editVoxel(noise); 132 | } 133 | 134 | 135 | // start rendering and begin terrain worker. 136 | { 137 | terrainDispatcher.start(); 138 | handler.renderSystem->startRendering(); 139 | terrainDispatcher.stop(); 140 | } 141 | 142 | return EXIT_SUCCESS; 143 | } 144 | 145 | 146 | void createSphere(t_voxelContainer *container, const vector3 &position, const bool &cut) 147 | { 148 | BLUB_LOG_OUT() << "createSphere"; 149 | 150 | t_editSphere::pointer sphereEdit(t_editSphere::create(sphere(position, 5.))); 151 | sphereEdit->setCut(cut); 152 | container->editVoxel(sphereEdit); 153 | } 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # module macro 2 | macro (add_module module_name) 3 | if (sources) 4 | message( STATUS "Creating module ${module_name}" ) 5 | prefix_list( 6 | "source/blub/${module_name}/" 7 | sources 8 | sources_with_prefix 9 | ) 10 | prefix_list( 11 | "source/blub/${module_name}/" 12 | headers 13 | headers_with_prefix 14 | ) 15 | # export.hpp TODO this generation sucks make own. 16 | # http://gcc.gnu.org/wiki/Visibility 17 | string(TOUPPER ${module_name} module_name_upper) 18 | set(header_export "${PROJECT_BINARY_DIR}/config_files/blub/${module_name}/export.hpp") 19 | include_directories(${INCLUDES}) 20 | add_library(${module_name} ${sources_with_prefix} ${headers_with_prefix} ) 21 | target_link_libraries (${module_name} ${modules_to_link} ${LIBS}) 22 | GENERATE_EXPORT_HEADER( ${module_name} 23 | BASE_NAME BLUB_${module_name_upper} 24 | EXPORT_MACRO_NAME BLUB_${module_name_upper}_API 25 | EXPORT_FILE_NAME ${header_export} 26 | NO_EXPORT_MACRO_NAME BLUB_${module_name_upper}_LOCAL 27 | STATIC_DEFINE BLUB_${module_name_upper}_BUILD_STATIC ) 28 | install (DIRECTORY source/ 29 | DESTINATION include 30 | FILES_MATCHING PATTERN "*.hpp") 31 | install (TARGETS ${module_name} 32 | DESTINATION lib) 33 | endif(sources) 34 | endmacro (add_module) 35 | 36 | # modules 37 | foreach(LIB_TO_BUILD ${BLUB_LIBRARIES_TO_BUILD}) 38 | add_subdirectory(${LIB_TO_BUILD}) 39 | endforeach(LIB_TO_BUILD) 40 | -------------------------------------------------------------------------------- /modules/async/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(sources 3 | log/global.cpp 4 | dispatcher.cpp 5 | deadlineTimer.cpp 6 | strand.cpp 7 | updater.cpp 8 | ) 9 | 10 | set(headers 11 | log/global.hpp 12 | deadlineTimer.hpp 13 | dispatcher.hpp 14 | mutex.hpp 15 | mutexLocker.hpp 16 | mutexReadWrite.hpp 17 | predecl.hpp 18 | strand.hpp 19 | updater.hpp 20 | ) 21 | 22 | set (modules_to_link core log) 23 | add_module(async) 24 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/deadlineTimer.cpp: -------------------------------------------------------------------------------- 1 | #include "deadlineTimer.hpp" 2 | 3 | #include "blub/async/dispatcher.hpp" 4 | 5 | 6 | using namespace blub::async; 7 | using namespace blub; 8 | 9 | 10 | deadlineTimer::deadlineTimer(dispatcher &listener) 11 | : m_listener(listener) 12 | , m_timer(*m_listener._getIoService()) 13 | { 14 | ; 15 | } 16 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/deadlineTimer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_DEADLINETIMER_HPP 2 | #define BLUB_CORE_DEADLINETIMER_HPP 3 | 4 | #include "blub/async/predecl.hpp" 5 | #include "blub/core/globals.hpp" 6 | 7 | #include 8 | 9 | 10 | namespace blub 11 | { 12 | namespace async 13 | { 14 | 15 | 16 | class deadlineTimer 17 | { 18 | public: 19 | deadlineTimer(dispatcher& listener); 20 | 21 | template 22 | void addToDoOnTimeoutMilli(CompletionHandler handler, const uint32& milli) 23 | { 24 | m_timer.expires_from_now(boost::posix_time::millisec(milli)); 25 | m_timer.async_wait(handler); 26 | } 27 | 28 | void cancel() 29 | { 30 | m_timer.cancel(); 31 | } 32 | 33 | protected: 34 | dispatcher& m_listener; 35 | boost::asio::deadline_timer m_timer; 36 | 37 | }; 38 | 39 | 40 | } 41 | } 42 | 43 | 44 | #endif // BLUB_CORE_DEADLINETIMER_HPP 45 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/dispatcher.cpp: -------------------------------------------------------------------------------- 1 | #include "dispatcher.hpp" 2 | 3 | #include "blub/async/mutex.hpp" 4 | 5 | #include 6 | #include 7 | #ifdef BLUB_LINUX 8 | # include 9 | #endif 10 | 11 | 12 | using namespace blub::async; 13 | using namespace blub; 14 | 15 | 16 | dispatcher::dispatcher(const uint16 &numThreads, const bool &endThreadsAfterAllDone, const string &threadName) 17 | : m_threadName(threadName) 18 | , m_work(nullptr) 19 | , m_numThreads(numThreads) 20 | , m_endThreadsAfterAllDone(endThreadsAfterAllDone) 21 | { 22 | m_service.reset(new boost::asio::io_service()); 23 | } 24 | 25 | 26 | dispatcher::~dispatcher() 27 | { 28 | stop(); 29 | } 30 | 31 | void dispatcher::join() 32 | { 33 | for (t_threads::iterator it = m_threads.begin(); it != m_threads.end(); ++it) 34 | { 35 | (*it)->join(); 36 | } 37 | } 38 | 39 | void dispatcher::start() 40 | { 41 | if (!m_endThreadsAfterAllDone) 42 | { 43 | m_work = new boost::asio::io_service::work(*m_service.get()); 44 | } 45 | for (uint16 ind = 0; ind < m_numThreads; ++ind) 46 | { 47 | boost::thread *newOne(new boost::thread(boost::bind(&dispatcher::runThread, this, ind))); 48 | 49 | m_threads.push_back(newOne); 50 | } 51 | if (m_numThreads == 0) 52 | { 53 | run(); 54 | m_service->reset(); 55 | } 56 | } 57 | 58 | void dispatcher::run() 59 | { 60 | m_service->run(); 61 | } 62 | 63 | void dispatcher::reset() 64 | { 65 | m_service->reset(); 66 | } 67 | 68 | void dispatcher::stop() 69 | { 70 | if (m_work != nullptr) 71 | { 72 | delete static_cast(m_work); 73 | m_work = nullptr; 74 | } 75 | // m_toDo.stop(); 76 | join(); 77 | 78 | m_threads.clear(); 79 | } 80 | 81 | void dispatcher::dispatch(const dispatcher::t_toCallFunction &handler) 82 | { 83 | m_service->dispatch(handler); 84 | } 85 | 86 | void dispatcher::post(const dispatcher::t_toCallFunction &handler) 87 | { 88 | m_service->post(handler); 89 | } 90 | 91 | void dispatcher::waitForQueueDone() 92 | { 93 | blub::async::mutex mutex; 94 | mutex.lock(); 95 | post(boost::bind(&blub::async::mutex::unlock, &mutex)); 96 | mutex.lock(); 97 | } 98 | 99 | int32 dispatcher::getThreadCount() 100 | { 101 | return m_threads.size(); 102 | } 103 | 104 | boost::asio::io_service *dispatcher::_getIoService() 105 | { 106 | return m_service.get(); 107 | } 108 | 109 | void dispatcher::runThread(const int32& indThread) 110 | { 111 | nameThread(indThread); 112 | run(); 113 | } 114 | 115 | void dispatcher::nameThread(const int32& indThread) 116 | { 117 | #ifdef BLUB_LINUX 118 | blub::string threadName(m_threadName); 119 | if (m_numThreads > 1) 120 | { 121 | threadName += "_" + string::number(indThread); 122 | } 123 | if (m_threadName != "") 124 | { 125 | prctl(PR_SET_NAME, threadName.data(), 0, 0, 0); 126 | } 127 | #else 128 | (void)indThread; 129 | #endif 130 | } 131 | 132 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/dispatcher.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_DISPATCHER_HPP 2 | #define BLUB_CORE_DISPATCHER_HPP 3 | 4 | #include "blub/async/predecl.hpp" 5 | #include "blub/core/list.hpp" 6 | #include "blub/core/noncopyable.hpp" 7 | #include "blub/core/scopedPtr.hpp" 8 | #include "blub/core/string.hpp" 9 | 10 | #include 11 | 12 | 13 | namespace boost 14 | { 15 | class thread; 16 | namespace asio 17 | { 18 | class io_service; 19 | } 20 | } 21 | 22 | 23 | namespace blub 24 | { 25 | namespace async 26 | { 27 | 28 | 29 | class dispatcher : public noncopyable // TODO free me from threads! 30 | { 31 | public: 32 | typedef std::function t_toCallFunction; 33 | 34 | dispatcher(const uint16& numThreads = 0, const bool& endThreadsAfterAllDone = true, const string& threadName = ""); 35 | virtual ~dispatcher(); 36 | 37 | void join(); 38 | void start(); 39 | void run(); 40 | void reset(); 41 | void stop(); 42 | 43 | void dispatch(const t_toCallFunction &handler); 44 | void post(const t_toCallFunction &handler); 45 | 46 | /** 47 | * @brief waitForQueueDone will work only if one thread 48 | */ 49 | void waitForQueueDone(void); 50 | 51 | int32 getThreadCount(void); 52 | 53 | boost::asio::io_service* _getIoService(void); 54 | 55 | protected: 56 | void nameThread(const int32 &indThread); 57 | 58 | private: 59 | void runThread(const int32& indThread); 60 | 61 | protected: 62 | const string m_threadName; 63 | 64 | private: 65 | scopedPointer m_service; 66 | void* m_work; 67 | uint16 m_numThreads; 68 | bool m_endThreadsAfterAllDone; 69 | typedef list t_threads; 70 | t_threads m_threads; 71 | 72 | }; 73 | 74 | 75 | } 76 | } 77 | 78 | 79 | #endif // BLUB_CORE_DISPATCHER_HPP 80 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/log/global.cpp: -------------------------------------------------------------------------------- 1 | #include "global.hpp" 2 | 3 | #include "blub/core/string.hpp" 4 | 5 | 6 | using namespace blub::async::log; 7 | using namespace blub; 8 | 9 | 10 | BLUB_LOG_GLOBAL_LOGGER_INIT(global, blub::log::logger) 11 | { 12 | blub::log::logger result("async"); 13 | return result; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/log/global.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_ASYNC_LOG_GLOBAL_HPP 2 | #define BLUB_ASYNC_LOG_GLOBAL_HPP 3 | 4 | #include "blub/log/global.hpp" 5 | #include "blub/log/globalLogger.hpp" 6 | #include "blub/log/logger.hpp" 7 | #include "blub/log/predecl.hpp" 8 | 9 | 10 | namespace blub 11 | { 12 | namespace async 13 | { 14 | namespace log 15 | { 16 | BLUB_LOG_GLOBAL_LOGGER(global, blub::log::logger) 17 | } 18 | } 19 | } 20 | 21 | 22 | #define BLUB_ASYNC_LOG_OUT() BLUB_LOG_OUT_TO(blub::async::log::global::get()) 23 | #define BLUB_ASYNC_LOG_WARNING() BLUB_LOG_WARNING_TO(blub::async::log::global::get()) 24 | #define BLUB_ASYNC_LOG_ERROR() BLUB_LOG_ERROR_TO(blub::async::log::global::get()) 25 | 26 | 27 | #endif // BLUB_ASYNC_LOG_GLOBAL_HPP 28 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/mutex.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_ASYNC_MUTEX_HPP 2 | #define BLUB_ASYNC_MUTEX_HPP 3 | 4 | #include 5 | 6 | 7 | namespace blub 8 | { 9 | namespace async 10 | { 11 | 12 | 13 | class mutex : public std::mutex 14 | { 15 | public: 16 | mutex() 17 | { 18 | } 19 | bool tryLock() 20 | { 21 | return try_lock(); 22 | } 23 | }; 24 | 25 | 26 | } 27 | } 28 | 29 | #endif // BLUB_ASYNC_MUTEX_HPP 30 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/mutexLocker.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MUTEXLOCKER_HPP 2 | #define MUTEXLOCKER_HPP 3 | 4 | #include "blub/async/mutex.hpp" 5 | 6 | 7 | namespace blub 8 | { 9 | namespace async 10 | { 11 | 12 | 13 | class mutexLocker 14 | { 15 | public: 16 | mutexLocker(mutex& toLock) 17 | : m_mutex(toLock) 18 | { 19 | m_mutex.lock(); 20 | } 21 | ~mutexLocker() 22 | { 23 | m_mutex.unlock(); 24 | } 25 | private: 26 | mutex &m_mutex; 27 | }; 28 | 29 | 30 | } 31 | } 32 | 33 | 34 | #endif // MUTEXLOCKER_HPP 35 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/mutexReadWrite.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MUTEXREADWRITE_HPP 2 | #define MUTEXREADWRITE_HPP 3 | 4 | #include "blub/async/predecl.hpp" 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace blub 11 | { 12 | namespace async 13 | { 14 | 15 | class mutexReadWrite : public boost::shared_mutex 16 | { 17 | public: 18 | typedef boost::shared_mutex t_base; 19 | 20 | mutexReadWrite() 21 | { 22 | ; 23 | } 24 | 25 | void lock() 26 | { 27 | t_base::lock(); 28 | } 29 | void lockForRead() 30 | { 31 | t_base::lock_shared(); 32 | } 33 | void unlockRead() 34 | { 35 | t_base::unlock_shared(); 36 | } 37 | void lockForWrite() 38 | { 39 | t_base::lock(); 40 | } 41 | bool tryLockForWrite() 42 | { 43 | return t_base::try_lock(); 44 | } 45 | 46 | 47 | }; 48 | 49 | 50 | typedef boost::unique_lock mutexLockerWrite; // TODO: put into extra files; and take include with it 51 | typedef boost::shared_lock mutexLockerRead; 52 | 53 | 54 | } 55 | } 56 | 57 | #endif // MUTEXREADWRITE_HPP 58 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/predecl.hpp: -------------------------------------------------------------------------------- 1 | namespace blub 2 | { 3 | 4 | namespace async 5 | { 6 | class deadlineTimer; 7 | class dispatcher; 8 | class mutex; 9 | class mutexLocker; 10 | class mutexReadWrite; 11 | class seperate; 12 | class updater; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/strand.cpp: -------------------------------------------------------------------------------- 1 | #include "strand.hpp" 2 | 3 | #include "blub/async/dispatcher.hpp" 4 | 5 | 6 | using namespace blub::async; 7 | using namespace blub; 8 | 9 | 10 | strand::strand(dispatcher& disp) 11 | : m_dispatcher(disp) 12 | , m_service(*disp._getIoService()) 13 | { 14 | } 15 | 16 | 17 | const dispatcher &strand::getDispatcher() const 18 | { 19 | return m_dispatcher; 20 | } 21 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/strand.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ASYNC_STRAND_HPP 2 | #define ASYNC_STRAND_HPP 3 | 4 | #include "blub/async/predecl.hpp" 5 | #include "blub/core/globals.hpp" 6 | 7 | #include 8 | 9 | 10 | namespace blub 11 | { 12 | namespace async 13 | { 14 | 15 | 16 | class strand 17 | { 18 | public: 19 | strand(dispatcher& disp); 20 | 21 | template 22 | void dispatch(CompletionHandler handler) 23 | { 24 | m_service.dispatch(handler); 25 | } 26 | 27 | template 28 | void post(CompletionHandler handler) 29 | { 30 | m_service.post(handler); 31 | } 32 | 33 | bool isRunningInThisThread() const 34 | { 35 | return m_service.running_in_this_thread(); 36 | } 37 | 38 | const dispatcher &getDispatcher() const; 39 | 40 | private: 41 | dispatcher &m_dispatcher; 42 | 43 | boost::asio::strand m_service; 44 | 45 | }; 46 | 47 | 48 | } 49 | } 50 | 51 | 52 | #endif // ASYNC_STRAND_HPP 53 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/updater.cpp: -------------------------------------------------------------------------------- 1 | #include "updater.hpp" 2 | 3 | #include "blub/async/deadlineTimer.hpp" 4 | #include "blub/async/log/global.hpp" 5 | 6 | #include 7 | #include 8 | #ifdef BLUB_LINUX 9 | #include 10 | #endif 11 | 12 | 13 | using namespace blub::async; 14 | using namespace blub; 15 | 16 | 17 | updater::updater(const string &threadName) 18 | : dispatcher(0, true, threadName) 19 | , m_thread(nullptr) 20 | , m_frameDeadline(nullptr) 21 | , m_stop(false) 22 | { 23 | } 24 | 25 | 26 | updater::~updater() 27 | { 28 | BLUB_ASYNC_LOG_OUT() << "destructor m_threadName:" << m_threadName; 29 | stop(); 30 | } 31 | 32 | void updater::stop() 33 | { 34 | m_stop = true; 35 | if (m_thread != nullptr) 36 | { 37 | if (m_thread->joinable()) 38 | { 39 | m_thread->join(); 40 | } 41 | delete m_thread; 42 | m_thread = nullptr; 43 | } 44 | } 45 | 46 | updater::t_sigFrameListener *updater::signalFrame() 47 | { 48 | return &m_sigFrame; 49 | } 50 | 51 | void updater::run(const real& frames, const bool& threaded) 52 | { 53 | m_frames = frames; 54 | if (threaded) 55 | { 56 | BASSERT(m_thread == nullptr); 57 | m_thread = new boost::thread(boost::bind(&updater::run, this, frames, false)); 58 | return; 59 | } 60 | nameThread(0); 61 | 62 | if (m_frames != 0.) 63 | { 64 | m_frameDeadline = new deadlineTimer(*this); 65 | } 66 | 67 | m_start = boost::chrono::system_clock::now(); 68 | if (m_frameDeadline != nullptr) 69 | { 70 | uint32 millis(static_cast((1./m_frames)*1000.)); 71 | m_frameDeadline->addToDoOnTimeoutMilli(boost::bind(&updater::frame, this), millis); 72 | } 73 | else 74 | { 75 | post(boost::bind(&updater::frame, this)); 76 | } 77 | dispatcher::start(); 78 | 79 | BLUB_ASYNC_LOG_OUT() << "run end m_threadName:" << m_threadName; 80 | } 81 | 82 | bool updater::runOneFrame(const real& delta) 83 | { 84 | dispatcher::start(); 85 | m_sigFrame(delta); 86 | return true; 87 | } 88 | 89 | void updater::frame() 90 | { 91 | boost::chrono::duration delta = boost::chrono::system_clock::now() - m_start; 92 | m_start = boost::chrono::system_clock::now(); 93 | if (m_frameDeadline != nullptr && !m_stop) 94 | { 95 | m_frameDeadline->addToDoOnTimeoutMilli(boost::bind(&updater::frame, this), static_cast((1./m_frames)*1000.)); 96 | } 97 | m_sigFrame(delta.count()); 98 | if (m_frameDeadline == nullptr && !m_stop) 99 | { 100 | post(boost::bind(&updater::frame, this)); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /modules/async/source/blub/async/updater.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_ASYNC_UPDATER_HPP 2 | #define BLUB_ASYNC_UPDATER_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/core/signal.hpp" 6 | #include "blub/async/dispatcher.hpp" 7 | 8 | #include 9 | 10 | 11 | namespace blub 12 | { 13 | namespace async 14 | { 15 | 16 | 17 | class updater : public dispatcher 18 | { 19 | public: 20 | updater(const blub::string& threadName); 21 | virtual ~updater(); 22 | 23 | void stop(); 24 | 25 | typedef blub::signal t_sigFrameListener; 26 | t_sigFrameListener* signalFrame(); 27 | 28 | void run(const real &frames = 60.0, const bool &threaded = false); // change from frames to millis-wait 29 | 30 | protected: 31 | bool runOneFrame(const real& delta); 32 | void frame(); 33 | 34 | private: 35 | const blub::string m_threadName; 36 | 37 | t_sigFrameListener m_sigFrame; 38 | 39 | boost::thread *m_thread; 40 | deadlineTimer *m_frameDeadline; 41 | 42 | boost::chrono::system_clock::time_point m_start; 43 | 44 | real m_frames; 45 | bool m_stop; 46 | }; 47 | 48 | 49 | } 50 | } 51 | 52 | 53 | #endif // BLUB_ASYNC_UPDATER_HPP 54 | -------------------------------------------------------------------------------- /modules/core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(sources 3 | dateTime.cpp 4 | byteArray.cpp 5 | string.cpp 6 | timer.cpp 7 | ) 8 | 9 | set(headers 10 | array.hpp 11 | bind.hpp 12 | byteArray.hpp 13 | classVersion.hpp 14 | dateTime.hpp 15 | deque.hpp 16 | enableSharedFromThis.hpp 17 | geometry.hpp 18 | hashList.hpp 19 | hashMap.hpp 20 | hashMapMulti.hpp 21 | idCreator.hpp 22 | list.hpp 23 | map.hpp 24 | move.hpp 25 | noncopyable.hpp 26 | optional.hpp 27 | pair.hpp 28 | predecl.hpp 29 | scopedPtr.hpp 30 | sharedPointer.hpp 31 | signal.hpp 32 | state.hpp 33 | string.hpp 34 | stringList.hpp 35 | timer.hpp 36 | vector.hpp 37 | weakPointer.hpp 38 | ) 39 | 40 | add_module(core) 41 | 42 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/array.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_ARRAY_HPP 2 | #define BLUB_ARRAY_HPP 3 | 4 | #include "blub/serialization/access.hpp" 5 | #include "blub/serialization/nameValuePair.hpp" 6 | #include "blub/serialization/saveLoad.hpp" 7 | 8 | #include 9 | 10 | #include 11 | 12 | 13 | namespace blub 14 | { 15 | 16 | 17 | template 18 | class array : public std::array 19 | { 20 | public: 21 | typedef std::array t_base; 22 | 23 | 24 | private: 25 | BLUB_SERIALIZATION_ACCESS 26 | 27 | template 28 | void serialize(formatType & readWrite, const uint32& version) 29 | { 30 | (void)version; 31 | 32 | t_base& casted = *this; 33 | readWrite & serialization::nameValuePair::create("elems", casted); 34 | } 35 | 36 | }; 37 | 38 | 39 | } 40 | 41 | #endif // BLUB_ARRAY_HPP 42 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/bind.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_BIND_HPP 2 | #define BLUB_CORE_BIND_HPP 3 | 4 | #include 5 | 6 | #ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL 7 | # include 8 | # include 9 | #else 10 | # include 11 | #endif 12 | 13 | 14 | namespace blub 15 | { 16 | 17 | 18 | #ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL 19 | using boost::bind; 20 | namespace placeholders { 21 | using ::_1; 22 | using ::_2; 23 | } 24 | #else 25 | using std::bind; 26 | namespace placeholders = std::placeholders; 27 | #endif 28 | 29 | 30 | } 31 | 32 | 33 | 34 | #endif // BLUB_CORE_BIND_HPP 35 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/byteArray.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/core/byteArray.hpp" 2 | 3 | #include "blub/core/string.hpp" 4 | 5 | #include 6 | 7 | 8 | using namespace blub; 9 | 10 | 11 | 12 | byteArray::byteArray(const byteArray &array) 13 | : t_base(array.size()) 14 | { 15 | std::copy_n(array.data(), array.size(), t_base::data()); 16 | } 17 | 18 | byteArray::byteArray(const char *array, uint32 size) 19 | : t_base(size) 20 | { 21 | std::copy_n(array, size, t_base::data()); 22 | } 23 | 24 | byteArray::byteArray(const string &str) 25 | : t_base(str.size()) 26 | { 27 | std::copy_n(str.data(), str.size(), t_base::data()); 28 | } 29 | 30 | byteArray byteArray::mid(const uint32 &index, const int32 &length) const 31 | { 32 | int32 len(length); 33 | if (length < 0) 34 | { 35 | len = t_base::size()-index; 36 | } 37 | BASSERT(len >= 0); 38 | if (len == 0) 39 | { 40 | return byteArray(); 41 | } 42 | const byteArray result(t_base::data()+index, len); 43 | return result; 44 | } 45 | 46 | byteArray &byteArray::operator +=(const byteArray &other) 47 | { 48 | const uint32 oldSize(t_base::size()); 49 | t_base::resize(oldSize + other.size()); 50 | memcpy(t_base::data()+oldSize, other.data(), other.size()); 51 | 52 | return *this; 53 | } 54 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/byteArray.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_BYTEARRAY_HPP 2 | #define BLUB_CORE_BYTEARRAY_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/serialization/access.hpp" 6 | #include "blub/serialization/nameValuePair.hpp" 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | 14 | namespace blub 15 | { 16 | 17 | class byteArray : public std::vector 18 | { 19 | public: 20 | typedef std::vector t_base; 21 | 22 | byteArray() 23 | { 24 | ; 25 | } 26 | byteArray(const uint32& size) 27 | : t_base(size, 0) 28 | {;} 29 | 30 | byteArray(const byteArray &array); 31 | byteArray(const char *array, uint32 size); 32 | byteArray(const string &str); 33 | 34 | /** 35 | * @brief mid gets an copy from a specified index for a length 36 | * @param index 37 | * @param length if length is smaller zero, the method returns an array from index to the end 38 | * @return 39 | */ 40 | byteArray mid(const uint32& index, const int32& length = -1) const; 41 | uint32 size() const 42 | { 43 | return static_cast(t_base::size()); 44 | } 45 | 46 | byteArray& operator +=(const byteArray& other); 47 | 48 | private: 49 | BLUB_SERIALIZATION_ACCESS 50 | 51 | template 52 | void serialize(formatType & ar, const uint32& version) 53 | { 54 | (void)version; 55 | 56 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t_base); 57 | } 58 | 59 | }; 60 | 61 | } 62 | 63 | #endif // BLUB_CORE_BYTEARRAY_HPP 64 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/classVersion.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CLASSVERSION_HPP 2 | #define CLASSVERSION_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | #define BLUB_CLASSVERSION(T, N) BOOST_CLASS_VERSION(T, N) 10 | 11 | 12 | #endif // CLASSVERSION_HPP 13 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/dateTime.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/core/dateTime.hpp" 2 | 3 | #include 4 | 5 | 6 | using namespace blub; 7 | 8 | 9 | string dateTime::getUniversalTimeString() 10 | { 11 | const boost::posix_time::ptime timestamp(boost::posix_time::microsec_clock::universal_time()); 12 | return boost::posix_time::to_simple_string(timestamp); 13 | } 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/dateTime.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DATETIME_HPP 2 | #define DATETIME_HPP 3 | 4 | #include "blub/core/string.hpp" 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | class dateTime 11 | { 12 | public: 13 | // converts to YYYY-mmm-DD HH:MM::SS.ffffff / YYYY-mmm-DD HH:MM::SS.fffffff 14 | static string getUniversalTimeString(); 15 | 16 | }; 17 | 18 | } 19 | 20 | #endif // DATETIME_HPP 21 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/deque.hpp: -------------------------------------------------------------------------------- 1 | #ifndef DEQUE_HPP 2 | #define DEQUE_HPP 3 | 4 | #include 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | 11 | template 12 | class deque : public std::deque 13 | { 14 | public: 15 | typedef std::deque t_base; 16 | 17 | deque() 18 | { 19 | ; 20 | } 21 | 22 | 23 | }; 24 | 25 | 26 | } 27 | 28 | 29 | #endif // DEQUE_HPP 30 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/enableSharedFromThis.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ENABLESHAREDFROMTHIS_HPP 2 | #define ENABLESHAREDFROMTHIS_HPP 3 | 4 | #include "blub/core/sharedPointer.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | 12 | 13 | template 14 | class enableSharedFromThis : public std::enable_shared_from_this 15 | { 16 | public: 17 | typedef std::enable_shared_from_this t_base; 18 | typedef blub::sharedPointer t_thisPtrConst; 19 | typedef blub::sharedPointer t_thisPtr; 20 | 21 | t_thisPtrConst getSharedThisPtr() const 22 | { 23 | return blub::sharedPointer(t_base::shared_from_this()); 24 | } 25 | t_thisPtr getSharedThisPtr() 26 | { 27 | return blub::sharedPointer(t_base::shared_from_this()); 28 | } 29 | }; 30 | 31 | 32 | } 33 | 34 | 35 | #endif // ENABLESHAREDFROMTHIS_HPP 36 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/geometry.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GEOMETRY_HPP 2 | #define GEOMETRY_HPP 3 | 4 | #include 5 | 6 | namespace blub 7 | { 8 | 9 | template 10 | class geometry 11 | { 12 | public: 13 | geometry() 14 | {;} 15 | 16 | void addVertices(const blub::list *vert); 17 | void addVertices(const vertexType *vert, blub::uint32 num); 18 | void addTriangles(const blub::list *tri); 19 | void addTriangles(const blub::triangle *indices, blub::uint32 num); 20 | void removeTriangles(const blub::list *tri); 21 | void removeTriangles(const blub::triangle *tri, blub::uint32 num); 22 | 23 | blub::list *vertices() {return &m_vertices;} 24 | blub::list *triangles() {return &m_triangles;} 25 | private: 26 | blub::list m_vertices; 27 | blub::list m_triangles; 28 | }; 29 | 30 | } 31 | 32 | #endif // GEOMETRY_HPP 33 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/hashList.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_HASHLIST_HPP 2 | #define BLUB_HASHLIST_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | namespace blub 12 | { 13 | 14 | 15 | template 19 | class hashList : public std::unordered_set 20 | { 21 | 22 | }; 23 | 24 | 25 | } 26 | 27 | 28 | #endif // BLUB_HASHLIST_HPP 29 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/hashMap.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_HASHMAP_HPP 2 | #define BLUB_CORE_HASHMAP_HPP 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | namespace blub 12 | { 13 | 14 | 15 | template , 18 | class P,// = std::equal_to, 19 | class A// = std::allocator > 20 | > 21 | class hashMap : public std::unordered_map 22 | { 23 | public: 24 | typedef std::unordered_map t_base; 25 | 26 | 27 | hashMap() : t_base() {;} 28 | hashMap(const typename t_base::size_type& size) : t_base(size) {;} 29 | 30 | void insert(const typename t_base::key_type& key, const typename t_base::mapped_type& value) 31 | { 32 | t_base::operator [](key) = value; 33 | } 34 | }; 35 | 36 | 37 | } 38 | 39 | 40 | #endif // BLUB_CORE_HPP 41 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/hashMapMulti.hpp: -------------------------------------------------------------------------------- 1 | #ifndef HASHMULTIMAP_HPP 2 | #define HASHMULTIMAP_HPP 3 | 4 | #include "blub/core/pair.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | 12 | template , 15 | class P,// = std::equal_to, 16 | class A// = std::allocator > 17 | > 18 | class hashMapMulti : public boost::unordered::unordered_multimap 19 | { 20 | public: 21 | typedef boost::unordered::unordered_multimap t_base; 22 | typedef std::pair equal_range_result; 23 | typedef std::pair equal_range_result_const; 24 | 25 | 26 | hashMapMulti() : t_base() {;} 27 | 28 | 29 | typename t_base::const_iterator constBegin() const 30 | { 31 | return t_base::cbegin(); 32 | } 33 | 34 | typename t_base::const_iterator constEnd() const 35 | { 36 | return t_base::cend(); 37 | } 38 | 39 | void insert(const typename t_base::key_type& key, const typename t_base::mapped_type& value) 40 | { 41 | blub::pair toInsert(key, value); 42 | t_base::insert(toInsert); 43 | } 44 | 45 | void remove(const typename t_base::key_type& key) 46 | { 47 | t_base::erase(key); 48 | } 49 | 50 | bool contains(const typename t_base::key_type& key) const 51 | { 52 | return t_base::find(key) != t_base::cend(); 53 | } 54 | 55 | }; 56 | 57 | } 58 | 59 | 60 | #endif // HASHMULTIMAP_HPP 61 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/idCreator.hpp: -------------------------------------------------------------------------------- 1 | #ifndef IDCREATOR_HPP 2 | #define IDCREATOR_HPP 3 | 4 | #include "blub/async/mutex.hpp" 5 | #include "blub/async/mutexLocker.hpp" 6 | 7 | namespace blub 8 | { 9 | 10 | /** creates ids */ 11 | template 12 | class idCreator 13 | { 14 | public: 15 | 16 | idCreator() 17 | : m_idCounter(0) 18 | {;} 19 | 20 | /** if gets called by multiple threads lock class before or call createIdThreadSafe */ 21 | idType createId(void) 22 | { 23 | return ++m_idCounter; 24 | } 25 | 26 | /** returns threadsafe a new id, call createId if class only gets called by one thread */ 27 | idType createIdThreadSafe(void) 28 | { 29 | async::mutexLocker locker(m_mutex); (void)locker; 30 | return createId(); 31 | } 32 | 33 | private: 34 | idType m_idCounter; 35 | async::mutex m_mutex; 36 | 37 | }; 38 | 39 | 40 | } 41 | 42 | #endif // IDCREATOR_HPP 43 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/list.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_LIST_HPP 2 | #define BLUB_LIST_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | 12 | template 13 | class list : public boost::container::list 14 | { 15 | public: 16 | typedef boost::container::list t_base; 17 | 18 | list() : boost::container::list() {;} 19 | list(const uint32 &num) : boost::container::list() {this->reserve(num);} 20 | list(boost::container::list lst) : boost::container::list(lst) {;} 21 | 22 | T& at(const uint32& ind) 23 | { 24 | BASSERT(ind < t_base::size()); 25 | typename t_base::iterator it(t_base::begin()); 26 | for (uint32 index = 0; index < ind; ++index) 27 | { 28 | ++it; 29 | } 30 | return *it; 31 | } 32 | 33 | const T& at(const uint32& ind) const 34 | { 35 | BASSERT(ind < t_base::size()); 36 | typename t_base::const_iterator it(t_base::cbegin()); 37 | for (uint32 index = 0; index < ind; ++index) 38 | { 39 | ++it; 40 | } 41 | return *it; 42 | } 43 | 44 | void reserve(uint32 size) 45 | { 46 | if (t_base::size() > size) 47 | { 48 | size = t_base::size(); 49 | } 50 | t_base::resize(size); 51 | } 52 | 53 | bool isEmpty(void) const 54 | { 55 | return t_base::empty(); 56 | } 57 | 58 | void insertAt(const uint32& ind, const T& toInsert) 59 | { 60 | BASSERT(ind < t_base::size()); 61 | t_base::insert(t_base::cbegin()+ind, toInsert); 62 | } 63 | 64 | void removeAt(const uint32& ind) 65 | { 66 | BASSERT(ind < t_base::size()); 67 | typename t_base::const_iterator it(t_base::cbegin()); 68 | for (uint32 index = 0; index < ind; ++index) 69 | { 70 | ++it; 71 | } 72 | t_base::erase(it); 73 | } 74 | 75 | int32 indexOf(const T& toFind) 76 | { 77 | typename t_base::const_iterator it(t_base::cbegin()); 78 | for (uint32 index = 0; index < t_base::size(); ++index) 79 | { 80 | if (*it == toFind) 81 | { 82 | return index; 83 | } 84 | ++it; 85 | } 86 | return -1; 87 | } 88 | 89 | /* 90 | T takeAt(uint32 ind) 91 | { 92 | T result = *(this->begin()+ind); 93 | removeAt(ind); 94 | return result; 95 | } 96 | 97 | T takeFirst() 98 | { 99 | T result = *this->begin(); 100 | removeAt(0); 101 | return result; 102 | }*/ 103 | 104 | bool push_back_distinct(const T & ins) 105 | { 106 | if (t_base::indexOf(ins) == -1) 107 | { 108 | t_base::push_back(ins); 109 | return true; 110 | } 111 | else 112 | return false; 113 | } 114 | }; 115 | 116 | } 117 | 118 | #endif // BLUB_LIST_HPP 119 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/map.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MAP_HPP 2 | #define MAP_HPP 3 | 4 | #include 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | template 11 | class map : public std::map 12 | { 13 | public: 14 | typedef std::map t_base; 15 | 16 | map() : t_base() {;} 17 | 18 | typename t_base::const_iterator constBegin() const 19 | { 20 | return t_base::cbegin(); 21 | } 22 | 23 | typename t_base::const_iterator constEnd() const 24 | { 25 | return t_base::cend(); 26 | } 27 | 28 | void insert(const typename t_base::key_type& key, const typename t_base::mapped_type& value) 29 | { 30 | t_base::operator [](key) = value; 31 | } 32 | 33 | void remove(const typename t_base::key_type& key) 34 | { 35 | t_base::erase(key); 36 | } 37 | 38 | bool contains(const typename t_base::key_type& key) const 39 | { 40 | return t_base::find(key) != t_base::cend(); 41 | } 42 | 43 | }; 44 | 45 | } 46 | 47 | #endif // MAP_HPP 48 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/move.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_MOVE_HPP 2 | #define BLUB_CORE_MOVE_HPP 3 | 4 | #include 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | 11 | using std::move; 12 | 13 | 14 | } 15 | 16 | 17 | #endif // BLUB_CORE_MOVE_HPP 18 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/noncopyable.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_NONCOPYABLE_HPP 2 | #define BLUB_CORE_NONCOPYABLE_HPP 3 | 4 | #include 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | class noncopyable : public boost::noncopyable 11 | { 12 | }; 13 | 14 | } 15 | 16 | 17 | 18 | 19 | 20 | #endif // NONCOPYABLE_HPP 21 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/optional.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_OPTIONAL_HPP 2 | #define BLUB_CORE_OPTIONAL_HPP 3 | 4 | #include 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | 11 | template 12 | using optional = boost::optional; 13 | 14 | 15 | } 16 | 17 | 18 | #endif // BLUB_CORE_OPTIONAL_HPP 19 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/pair.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PAIR_HPP 2 | #define PAIR_HPP 3 | 4 | #include 5 | 6 | namespace blub 7 | { 8 | template 9 | class pair : public std::pair 10 | { 11 | public: 12 | pair() 13 | : std::pair() 14 | {;} 15 | pair(const A &a, const B &b) 16 | : std::pair(a, b) 17 | {;} 18 | pair(const std::pair ©) 19 | : std::pair(copy) 20 | {;} 21 | }; 22 | } 23 | 24 | #endif // PAIR_HPP 25 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/predecl.hpp: -------------------------------------------------------------------------------- 1 | 2 | namespace blub 3 | { 4 | class string; 5 | } 6 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/scopedPtr.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_SCOPEDPTR_HPP 2 | #define BLUB_CORE_SCOPEDPTR_HPP 3 | 4 | #include 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | 11 | template 12 | using scopedPointer = std::unique_ptr; 13 | 14 | 15 | } 16 | 17 | 18 | #endif // BLUB_CORE_SCOPEDPTR_HPP 19 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/sharedPointer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_SHAREDPOINTER_HPP 2 | #define BLUB_SHAREDPOINTER_HPP 3 | 4 | #include 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | 11 | template 12 | class sharedPointer : public std::shared_ptr 13 | { 14 | public: 15 | typedef std::shared_ptr t_base; 16 | 17 | sharedPointer() 18 | {} 19 | sharedPointer(T* ptr) 20 | : t_base(ptr) 21 | {} 22 | sharedPointer(t_base ptr) 23 | : t_base(ptr) 24 | {} 25 | template 26 | sharedPointer(std::shared_ptr ptr) 27 | : t_base(ptr) 28 | {} 29 | 30 | template 31 | sharedPointer staticCast() 32 | { 33 | std::shared_ptr result(std::static_pointer_cast(*this)); 34 | return result; 35 | } 36 | 37 | T* data() const 38 | { 39 | return t_base::get(); 40 | } 41 | 42 | void reset() 43 | { 44 | t_base::reset(); 45 | } 46 | 47 | bool isNull() const 48 | { 49 | return data() == nullptr; 50 | } 51 | 52 | protected: 53 | 54 | }; 55 | 56 | 57 | using std::make_shared; 58 | 59 | 60 | } 61 | 62 | 63 | #endif // BLUB_SHAREDPOINTER_HPP 64 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/signal.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_SIGNAL_HPP 2 | #define BLUB_CORE_SIGNAL_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | namespace blub 9 | { 10 | 11 | template 12 | class signal : public boost::signals2::signal 13 | { 14 | private: 15 | typedef boost::signals2::signal t_base; 16 | 17 | public: 18 | 19 | signal() 20 | : boost::signals2::signal() 21 | {;} 22 | 23 | 24 | uint32 getNumSlots() const 25 | { 26 | return t_base::num_slots(); 27 | } 28 | 29 | void disconnectAllSlots() 30 | { 31 | t_base::disconnect_all_slots(); 32 | } 33 | }; 34 | 35 | } 36 | 37 | 38 | #endif // BLUB_CORE_SIGNAL_HPP 39 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/state.hpp: -------------------------------------------------------------------------------- 1 | #ifndef STATE_HPP 2 | #define STATE_HPP 3 | 4 | #include 5 | 6 | namespace blub 7 | { 8 | class state 9 | { 10 | public: 11 | state() {;} 12 | virtual ~state() {clean();} 13 | 14 | typedef blub::signal t_signalDone; 15 | t_signalDone *signalDone(void) 16 | {return &m_sigDone;} 17 | 18 | virtual bool initialise() {return true;} 19 | virtual void clean() {;} 20 | 21 | void callDone() {m_sigDone(this);} 22 | protected: 23 | 24 | private: 25 | t_signalDone m_sigDone; 26 | }; 27 | } 28 | 29 | #endif // STATE_HPP 30 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/string.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/core/string.hpp" 2 | 3 | #include "blub/core/byteArray.hpp" 4 | 5 | #include 6 | 7 | #include 8 | 9 | 10 | using namespace blub; 11 | 12 | 13 | string::string(const byteArray &array) 14 | : t_base(array.data(), array.size()) 15 | { 16 | 17 | } 18 | 19 | 20 | std::ostream &operator <<(std::ostream &ostr, const string &toCast) 21 | { 22 | return ostr << static_cast(toCast); 23 | } 24 | 25 | 26 | std::size_t blub::hash_value(const string &value) 27 | { 28 | std::size_t result(boost::hash_value(static_cast(value))); 29 | 30 | return result; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/string.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_STRING_HPP 2 | #define BLUB_STRING_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/serialization/access.hpp" 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #ifdef BLUB_USE_SOCI 13 | # include 14 | # include 15 | #endif 16 | 17 | 18 | namespace blub 19 | { 20 | 21 | 22 | class string : public std::string 23 | { 24 | public: 25 | typedef std::string t_base; 26 | 27 | string() 28 | : t_base() 29 | {;} 30 | string(const char* str) 31 | : t_base(str) 32 | {} 33 | string(const char* str, uint32 len) 34 | : t_base(str, len) 35 | {} 36 | string(const t_base& str) 37 | : t_base(str) 38 | {} 39 | string(const byteArray& array); 40 | 41 | template 42 | static string number(const numberType& n) 43 | { 44 | return boost::lexical_cast(n); 45 | } 46 | 47 | protected: 48 | BLUB_SERIALIZATION_ACCESS 49 | template 50 | void serialize(Archive & readWrite, const unsigned int version) 51 | { 52 | (void)version; 53 | 54 | readWrite & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t_base); 55 | } 56 | }; 57 | 58 | 59 | std::size_t hash_value(const blub::string& value); 60 | 61 | 62 | } 63 | 64 | 65 | std::ostream& operator << (std::ostream& ostr, const blub::string& toCast); 66 | 67 | #ifdef BLUB_USE_SOCI 68 | 69 | 70 | namespace soci 71 | { 72 | 73 | 74 | template <> 75 | struct type_conversion 76 | { 77 | typedef std::string base_type; 78 | 79 | static void from_base(std::string i, soci::indicator ind, blub::string & mi) 80 | { 81 | if (ind == i_null) 82 | { 83 | throw soci_error("Null value not allowed for this type"); 84 | } 85 | 86 | mi = static_cast(i); 87 | } 88 | 89 | static void to_base(const blub::string & mi, std::string & i, indicator & ind) 90 | { 91 | i = static_cast(mi); 92 | ind = i_ok; 93 | } 94 | }; 95 | 96 | 97 | } 98 | 99 | 100 | #endif 101 | 102 | #endif // BLUB_STRING_HPP 103 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/stringList.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_STRINGLIST_HPP 2 | #define BLUB_CORE_STRINGLIST_HPP 3 | 4 | #include "blub/core/string.hpp" 5 | #include "blub/core/vector.hpp" 6 | 7 | 8 | namespace blub 9 | { 10 | 11 | typedef vector stringList; 12 | 13 | } 14 | 15 | #endif // BLUB_CORE_STRINGLIST_HPP 16 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/timer.cpp: -------------------------------------------------------------------------------- 1 | #include "timer.hpp" 2 | 3 | #include "blub/log/global.hpp" 4 | 5 | #include 6 | 7 | 8 | using namespace blub; 9 | 10 | timer::timer(const string &outputText) 11 | : m_outputText(outputText) 12 | { 13 | } 14 | 15 | void timer::start() 16 | { 17 | m_timePoint = boost::chrono::system_clock::now(); 18 | } 19 | 20 | real timer::end() 21 | { 22 | boost::chrono::duration sec = boost::chrono::system_clock::now() - m_timePoint; 23 | return sec.count(); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/timer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TIMER_HPP 2 | #define TIMER_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/core/string.hpp" 6 | 7 | #include 8 | 9 | 10 | namespace blub 11 | { 12 | 13 | class timer 14 | { 15 | public: 16 | timer(const string& outputText = blub::string("unnamed timer")); 17 | 18 | /** 19 | * @brief start gets a timepoint, call end to get the time passed from start() 20 | */ 21 | void start(); 22 | /** 23 | * @brief returns time in seconds, since last start() call 24 | */ 25 | real end(); 26 | 27 | private: 28 | boost::chrono::system_clock::time_point m_timePoint; 29 | 30 | blub::string m_outputText; 31 | }; 32 | 33 | } 34 | 35 | #endif // TIMER_HPP 36 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_VECTOR_HPP 2 | #define BLUB_CORE_VECTOR_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/serialization/access.hpp" 6 | #include "blub/serialization/nameValuePair.hpp" 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | 14 | namespace blub 15 | { 16 | 17 | 18 | template 19 | class vector : public std::vector 20 | { 21 | public: 22 | typedef std::vector t_base; 23 | 24 | vector() {;} 25 | vector(const std::size_t& size) 26 | : t_base(size) 27 | { 28 | } 29 | vector(const std::size_t& size, const T& value) 30 | : t_base(size, value) 31 | { 32 | } 33 | #if !defined BOOST_NO_CXX11_HDR_INITIALIZER_LIST || BOOST_CLANG == 1 34 | vector(const std::initializer_list &list) 35 | : t_base(list) 36 | { 37 | } 38 | #endif 39 | protected: 40 | BLUB_SERIALIZATION_ACCESS 41 | template 42 | void serialize(Archive & ar, const unsigned int version) 43 | { 44 | (void)version; 45 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t_base); // TODO remove boost macro, use blub 46 | } 47 | }; 48 | 49 | template 50 | std::ostream& operator<< (std::ostream& ostr, const vector& toCast) 51 | { 52 | ostr << "{"; 53 | for (const T& elem : toCast) 54 | { 55 | ostr << elem << ","; 56 | } 57 | return ostr << "}"; 58 | } 59 | 60 | } 61 | 62 | 63 | #endif // BLUB_CORE_VECTOR_HPP 64 | -------------------------------------------------------------------------------- /modules/core/source/blub/core/weakPointer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_CORE_WEAKPOINTER_HPP 2 | #define BLUB_CORE_WEAKPOINTER_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | 12 | 13 | } 14 | 15 | 16 | #endif // BLUB_CORE_WEAKPOINTER_HPP 17 | -------------------------------------------------------------------------------- /modules/log/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(sources 3 | system.cpp 4 | global.cpp 5 | logger.cpp 6 | ) 7 | 8 | set(headers 9 | global.hpp 10 | logger.hpp 11 | predecl.hpp 12 | system.hpp 13 | ) 14 | 15 | add_module(log) 16 | -------------------------------------------------------------------------------- /modules/log/source/blub/log/global.cpp: -------------------------------------------------------------------------------- 1 | #include "global.hpp" 2 | 3 | #include "blub/core/string.hpp" 4 | #include "blub/log/system.hpp" 5 | 6 | #include 7 | 8 | 9 | using namespace blub::log; 10 | 11 | 12 | BLUB_LOG_GLOBAL_LOGGER_INIT(global, blub::log::logger) 13 | { 14 | blub::log::system::addConsole(); 15 | 16 | boost::log::add_common_attributes(); 17 | 18 | logger result("application"); 19 | return result; 20 | } 21 | -------------------------------------------------------------------------------- /modules/log/source/blub/log/global.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_LOG_GLOBAL_HPP 2 | #define BLUB_LOG_GLOBAL_HPP 3 | 4 | #include "blub/core/string.hpp" 5 | #include "blub/log/globalLogger.hpp" 6 | #include "blub/log/logger.hpp" 7 | #include "blub/log/predecl.hpp" 8 | 9 | #include 10 | 11 | 12 | namespace blub 13 | { 14 | namespace log 15 | { 16 | BLUB_LOG_GLOBAL_LOGGER(global, logger) 17 | } 18 | } 19 | 20 | 21 | // TODO custom log source would be more beautiful http://www.boost.org/doc/libs/1_57_0/libs/log/doc/html/log/extension/sources.html 22 | #ifdef BLUB_LOG_LOCATION 23 | # define BLUB_LOG_SEV(destination, severity) BOOST_LOG_SEV(destination, severity) << boost::log::add_value("Location", __PRETTY_FUNCTION__) 24 | # define BLUB_LOG_SEV_WITHOUT_LOCATION(destination, severity) BOOST_LOG_SEV(destination, severity) << boost::log::add_value("Location", __PRETTY_FUNCTION__) 25 | #else 26 | # define BLUB_LOG_SEV(destination, severity) BOOST_LOG_SEV(destination, severity) 27 | # define BLUB_LOG_SEV_WITHOUT_LOCATION(destination, severity) BOOST_LOG_SEV(destination, severity) 28 | #endif 29 | 30 | #define BLUB_LOG_OUT_TO(destination) BLUB_LOG_SEV(destination, blub::log::severity::out) 31 | #define BLUB_LOG_OUT() BLUB_LOG_OUT_TO(blub::log::global::get()) 32 | 33 | #define BLUB_LOG_WARNING_TO(destination) BLUB_LOG_SEV(destination, blub::log::severity::warning) 34 | #define BLUB_LOG_WARNING() BLUB_LOG_WARNING_TO(blub::log::global::get()) 35 | 36 | #define BLUB_LOG_ERROR_TO(destination) BLUB_LOG_SEV(destination, blub::log::severity::error) 37 | #define BLUB_LOG_ERROR() BLUB_LOG_ERROR_TO(blub::log::global::get()) 38 | 39 | 40 | #endif // BLUB_LOG_GLOBAL_HPP 41 | -------------------------------------------------------------------------------- /modules/log/source/blub/log/globalLogger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_LOG_GLOBALLOGGER_HPP 2 | #define BLUB_LOG_GLOBALLOGGER_HPP 3 | 4 | #include 5 | 6 | #define BLUB_LOG_GLOBAL_LOGGER(name, logger_type) BOOST_LOG_GLOBAL_LOGGER(name, logger_type) 7 | #define BLUB_LOG_GLOBAL_LOGGER_INIT(name, logger_type) BOOST_LOG_GLOBAL_LOGGER_INIT(name, logger_type) 8 | 9 | #endif // BLUB_LOG_GLOBALLOGGER_HPP 10 | -------------------------------------------------------------------------------- /modules/log/source/blub/log/logger.cpp: -------------------------------------------------------------------------------- 1 | #include "logger.hpp" 2 | 3 | #include "blub/core/string.hpp" 4 | 5 | #include 6 | 7 | 8 | using namespace blub::log; 9 | 10 | 11 | logger::logger(const blub::string &moduleName) 12 | { 13 | t_base::add_attribute("Module", boost::log::attributes::constant(moduleName)); 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /modules/log/source/blub/log/logger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_LOG_LOGGER_HPP 2 | #define BLUB_LOG_LOGGER_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | 12 | namespace blub 13 | { 14 | namespace log 15 | { 16 | enum class severity 17 | { 18 | out, 19 | warning, 20 | error 21 | }; 22 | 23 | inline std::ostream& operator<< (std::ostream& strm, blub::log::severity severity_) 24 | { 25 | static const char* strings[] = 26 | { 27 | "out", 28 | "warning", 29 | "error", 30 | }; 31 | std::size_t castedLevel(static_cast< std::size_t >(severity_)); 32 | if (castedLevel < sizeof(strings) / sizeof(*strings)) 33 | { 34 | strm << strings[castedLevel]; 35 | } 36 | else 37 | { 38 | strm << castedLevel; 39 | } 40 | 41 | return strm; 42 | } 43 | 44 | class logger : public boost::log::sources::severity_logger_mt 45 | { 46 | public: 47 | typedef boost::log::sources::severity_logger_mt t_base; 48 | 49 | logger(const blub::string &moduleName); 50 | ~logger() {;} 51 | }; 52 | } 53 | } 54 | 55 | 56 | #endif // BLUB_LOG_LOGGER_HPP 57 | -------------------------------------------------------------------------------- /modules/log/source/blub/log/predecl.hpp: -------------------------------------------------------------------------------- 1 | 2 | namespace blub 3 | { 4 | namespace log 5 | { 6 | class logger; 7 | class system; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /modules/log/source/blub/log/system.cpp: -------------------------------------------------------------------------------- 1 | #include "system.hpp" 2 | 3 | #include "blub/log/logger.hpp" 4 | #include "blub/core/string.hpp" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | 18 | using namespace blub::log; 19 | using namespace blub; 20 | 21 | 22 | 23 | struct severity_tag; 24 | 25 | boost::log::formatting_ostream& operator<< 26 | ( 27 | boost::log::formatting_ostream& strm, 28 | boost::log::to_log_manip< blub::log::severity, severity_tag > const& manip 29 | ) 30 | { 31 | static const char* strings[] = 32 | { 33 | "info", 34 | "warn", 35 | "err", 36 | }; 37 | 38 | blub::log::severity level = manip.get(); 39 | std::size_t castedLevel(static_cast< std::size_t >(level)); 40 | if (castedLevel < sizeof(strings) / sizeof(*strings)) 41 | { 42 | strm << strings[castedLevel]; 43 | } 44 | else 45 | { 46 | strm << castedLevel; 47 | } 48 | 49 | return strm; 50 | } 51 | 52 | 53 | void system::addFile(const string &file) 54 | { 55 | boost::log::add_file_log( 56 | static_cast(file), 57 | boost::log::keywords::format = 58 | ( 59 | boost::log::expressions::stream 60 | << boost::log::expressions::attr< severity, severity_tag >("Severity") 61 | << " " << boost::log::expressions::attr< boost::posix_time::ptime >("TimeStamp") 62 | << " " << boost::log::expressions::attr< boost::log::attributes::current_thread_id::value_type >("ThreadID") 63 | << " " << boost::log::expressions::attr< blub::string >("Module") 64 | #ifdef BLUB_LOG_LOCATION 65 | << " " << boost::log::expressions::attr< blub::string >("Location") 66 | << "\n" 67 | #else 68 | << " " 69 | #endif 70 | << boost::log::expressions::smessage 71 | ), 72 | boost::log::keywords::auto_flush = true 73 | ); 74 | } 75 | 76 | void system::addConsole() 77 | { 78 | boost::log::add_console_log( 79 | std::cout, 80 | boost::log::keywords::format = 81 | ( 82 | boost::log::expressions::stream 83 | << boost::log::expressions::attr("Severity") 84 | << " " << boost::log::expressions::attr("TimeStamp") 85 | << " " << boost::log::expressions::attr("ThreadID") 86 | << " " << boost::log::expressions::attr< blub::string >("Module") 87 | #ifdef BLUB_LOG_LOCATION 88 | << " " << boost::log::expressions::attr< blub::string >("Location") 89 | << "\n" 90 | #else 91 | << " " 92 | #endif 93 | << boost::log::expressions::smessage 94 | ), 95 | boost::log::keywords::auto_flush = true 96 | ); 97 | } 98 | -------------------------------------------------------------------------------- /modules/log/source/blub/log/system.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_LOG_SYSTEM_HPP 2 | #define BLUB_LOG_SYSTEM_HPP 3 | 4 | #include "blub/core/predecl.hpp" 5 | #include "blub/log/predecl.hpp" 6 | 7 | 8 | 9 | namespace blub 10 | { 11 | namespace log 12 | { 13 | class system 14 | { 15 | public: 16 | static void addFile(const blub::string &file); 17 | static void addConsole(); 18 | 19 | }; 20 | } 21 | } 22 | 23 | 24 | #endif // BLUB_LOG_SYSTEM_HPP 25 | -------------------------------------------------------------------------------- /modules/math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(sources 3 | log/global.cpp 4 | axisAlignedBox.cpp 5 | colour.cpp 6 | intersection.cpp 7 | math.cpp 8 | plane.cpp 9 | quaternion.cpp 10 | ray.cpp 11 | rectangle.cpp 12 | sphere.cpp 13 | transform.cpp 14 | triangleVector3.cpp 15 | vector2.cpp 16 | vector3.cpp 17 | ) 18 | 19 | set(headers 20 | log/global.hpp 21 | predecl.hpp 22 | rectangle.hpp 23 | triangleVector3.hpp 24 | colour.hpp 25 | octree/search.hpp 26 | octree/container.hpp 27 | triangle.hpp 28 | vector3.hpp 29 | vector2int.hpp 30 | transform.hpp 31 | axisAlignedBox.hpp 32 | sphere.hpp 33 | ray.hpp 34 | intersection.hpp 35 | vector3int32map.hpp 36 | axisAlignedBoxTemplate.hpp 37 | axisAlignedBoxInt32.hpp 38 | math.hpp 39 | quaternion.hpp 40 | vector2.hpp 41 | plane.hpp 42 | ) 43 | 44 | set (modules_to_link core log) 45 | add_module(math) 46 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/axisAlignedBox.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/math/axisAlignedBox.hpp" 2 | 3 | #include "blub/math/axisAlignedBoxInt32.hpp" 4 | #include "blub/math/vector3.hpp" 5 | #include "blub/math/vector3int.hpp" 6 | 7 | #include 8 | 9 | #ifndef BLUB_NO_OGRE3D 10 | # include 11 | #endif 12 | 13 | 14 | using namespace blub; 15 | 16 | axisAlignedBox::axisAlignedBox(const axisAlignedBoxInt32 &toCast) 17 | : mMinimum(vector3::ZERO), mMaximum(vector3::UNIT_SCALE) 18 | { 19 | setExtents(vector3(toCast.getMinimum()), vector3(toCast.getMaximum())); 20 | } 21 | 22 | #ifndef BLUB_NO_OGRE3D 23 | axisAlignedBox::axisAlignedBox(const Ogre::AxisAlignedBox &vec) 24 | : mMinimum(vector3::ZERO), mMaximum(vector3::UNIT_SCALE) 25 | { 26 | setExtents(vector3(vec.getMinimum()), vector3(vec.getMaximum())); 27 | } 28 | 29 | axisAlignedBox::operator Ogre::AxisAlignedBox() const 30 | { 31 | return Ogre::AxisAlignedBox(mMinimum, mMaximum); 32 | } 33 | #endif 34 | 35 | real axisAlignedBox::volume() const 36 | { 37 | switch (mExtent) 38 | { 39 | case EXTENT_NULL: 40 | return 0.0f; 41 | 42 | case EXTENT_FINITE: 43 | { 44 | vector3 diff = mMaximum - mMinimum; 45 | return diff.x * diff.y * diff.z; 46 | } 47 | 48 | case EXTENT_INFINITE: 49 | return std::numeric_limits::infinity(); 50 | 51 | default: // shut up compiler 52 | BASSERT( false && "Never reached" ); 53 | return 0.0f; 54 | } 55 | } 56 | 57 | vector3 axisAlignedBox::getSize(void) const 58 | { 59 | switch (mExtent) 60 | { 61 | case EXTENT_NULL: 62 | return vector3::ZERO; 63 | 64 | case EXTENT_FINITE: 65 | return mMaximum - mMinimum; 66 | 67 | case EXTENT_INFINITE: 68 | return vector3( 69 | std::numeric_limits::infinity(), 70 | std::numeric_limits::infinity(), 71 | std::numeric_limits::infinity()); 72 | 73 | default: // shut up compiler 74 | BASSERT( false && "Never reached" ); 75 | return vector3::ZERO; 76 | } 77 | } 78 | 79 | vector3 axisAlignedBox::getHalfSize(void) const 80 | { 81 | switch (mExtent) 82 | { 83 | case EXTENT_NULL: 84 | return vector3::ZERO; 85 | 86 | case EXTENT_FINITE: 87 | return (mMaximum - mMinimum) * 0.5; 88 | 89 | case EXTENT_INFINITE: 90 | return vector3( 91 | std::numeric_limits::infinity(), 92 | std::numeric_limits::infinity(), 93 | std::numeric_limits::infinity()); 94 | 95 | default: // shut up compiler 96 | BASSERT( false && "Never reached" ); 97 | return vector3::ZERO; 98 | } 99 | } 100 | 101 | real axisAlignedBox::distance(const vector3 &v) const 102 | { 103 | if (this->contains(v)) 104 | return 0; 105 | else 106 | { 107 | real maxDist = std::numeric_limits::min(); 108 | 109 | if (v.x < mMinimum.x) 110 | maxDist = std::max(maxDist, mMinimum.x - v.x); 111 | if (v.y < mMinimum.y) 112 | maxDist = std::max(maxDist, mMinimum.y - v.y); 113 | if (v.z < mMinimum.z) 114 | maxDist = std::max(maxDist, mMinimum.z - v.z); 115 | 116 | if (v.x > mMaximum.x) 117 | maxDist = std::max(maxDist, v.x - mMaximum.x); 118 | if (v.y > mMaximum.y) 119 | maxDist = std::max(maxDist, v.y - mMaximum.y); 120 | if (v.z > mMaximum.z) 121 | maxDist = std::max(maxDist, v.z - mMaximum.z); 122 | 123 | return maxDist; 124 | } 125 | } 126 | 127 | 128 | 129 | std::ostream &blub::operator<<(std::ostream &ostr, const axisAlignedBox &toCast) 130 | { 131 | return ostr << "{" << toCast.getMinimum() << "," << toCast.getMaximum() << "}"; 132 | } 133 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/axisAlignedBoxInt32.hpp: -------------------------------------------------------------------------------- 1 | #ifndef AXISALIGNEDBOXINT32_HPP 2 | #define AXISALIGNEDBOXINT32_HPP 3 | 4 | #include "blub/math/axisAlignedBoxTemplate.hpp" 5 | #include "blub/math/vector3int.hpp" 6 | 7 | 8 | namespace blub 9 | { 10 | 11 | 12 | class axisAlignedBoxInt32 : public axisAlignedBoxTemplate 13 | { 14 | public: 15 | typedef axisAlignedBoxTemplate t_base; 16 | 17 | axisAlignedBoxInt32() 18 | { 19 | setInvalid(); 20 | } 21 | 22 | axisAlignedBoxInt32(const vector3int32& min, const vector3int32& max) 23 | : t_base(min, max) 24 | { 25 | ; 26 | } 27 | 28 | void setInvalid(void) 29 | { 30 | setMinimumAndMaximum(vector3int32(1), vector3int32(0)); 31 | } 32 | 33 | }; 34 | 35 | 36 | } 37 | 38 | 39 | #endif // AXISALIGNEDBOXINT32_HPP 40 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/axisAlignedBoxTemplate.hpp: -------------------------------------------------------------------------------- 1 | #ifndef AXISALIGNEDBOXTEMPLATE_HPP 2 | #define AXISALIGNEDBOXTEMPLATE_HPP 3 | 4 | #include "blub/serialization/access.hpp" 5 | #include "blub/serialization/nameValuePair.hpp" 6 | 7 | #include "blub/core/globals.hpp" 8 | 9 | 10 | namespace blub 11 | { 12 | 13 | 14 | template 15 | class axisAlignedBoxTemplate 16 | { 17 | public: 18 | typedef axisAlignedBoxTemplate t_thisClass; 19 | 20 | axisAlignedBoxTemplate() 21 | { 22 | 23 | } 24 | 25 | axisAlignedBoxTemplate(const vector3Type& min, const vector3Type& max) 26 | : m_min(min) 27 | , m_max(max) 28 | { 29 | ; 30 | } 31 | 32 | bool operator == (const t_thisClass& other) const 33 | { 34 | return other.getMinimum() == m_min && other.getMaximum() == m_max; 35 | } 36 | 37 | void setMinimumAndMaximum(const vector3Type& min, const vector3Type& max) 38 | { 39 | m_min = min; 40 | m_max = max; 41 | } 42 | 43 | const vector3Type& getMinimum(void) const 44 | { 45 | return m_min; 46 | } 47 | 48 | const vector3Type& getMaximum(void) const 49 | { 50 | return m_max; 51 | } 52 | 53 | vector3Type getSize(void) const 54 | { 55 | return m_max - m_min; 56 | } 57 | 58 | vector3Type getCenter(void) const 59 | { 60 | return (m_min + m_max) / 2; 61 | } 62 | 63 | bool isInside(const vector3Type& in) const 64 | { 65 | return in >= m_min && in <= m_max; 66 | } 67 | 68 | bool isInside(const t_thisClass& in) const 69 | { 70 | return in.isInside(m_min) && in.isInside(m_max); 71 | } 72 | 73 | void extend(const t_thisClass& ext) 74 | { 75 | if (!ext.isValid()) 76 | { 77 | return; 78 | } 79 | extend(ext.getMinimum()); 80 | extend(ext.getMaximum()); 81 | } 82 | void extend(const vector3Type& ext) 83 | { 84 | if (isValid()) 85 | { 86 | setMinimumAndMaximum(m_min.getMinimum(ext), m_max.getMaximum(ext)); 87 | return; 88 | } 89 | setMinimumAndMaximum(ext, ext); 90 | } 91 | 92 | bool isValid() const 93 | { 94 | return m_max >= m_min; 95 | } 96 | 97 | typename vector3Type::t_valueType getVolume() 98 | { 99 | const vector3Type size(getSize()); 100 | return size.x * size.y * size.z; 101 | } 102 | 103 | 104 | private: 105 | BLUB_SERIALIZATION_ACCESS 106 | 107 | template 108 | void serialize(formatType & readWrite, const uint32& version) 109 | { 110 | (void)version; 111 | 112 | readWrite & serialization::nameValuePair::create("min", m_min); 113 | readWrite & serialization::nameValuePair::create("max", m_max); 114 | } 115 | 116 | 117 | protected: 118 | vector3Type m_min; 119 | vector3Type m_max; 120 | 121 | }; 122 | 123 | 124 | } 125 | 126 | 127 | #endif // AXISALIGNEDBOXTEMPLATE_HPP 128 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/colour.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/math/colour.hpp" 2 | 3 | #ifndef BLUB_NO_OGRE3D 4 | #include 5 | #endif 6 | 7 | 8 | using namespace blub; 9 | 10 | 11 | #ifndef BLUB_NO_OGRE3D 12 | colour::colour(const Ogre::ColourValue &vec) 13 | : r(vec.r) 14 | , g(vec.g) 15 | , b(vec.b) 16 | , a(vec.a) 17 | { 18 | ; 19 | } 20 | 21 | colour::operator Ogre::ColourValue() const 22 | { 23 | return Ogre::ColourValue(r, g, b, a); 24 | } 25 | #endif 26 | 27 | 28 | std::ostream &blub::operator<<(std::ostream &ostr, const colour &toCast) 29 | { 30 | return ostr << "(" << toCast.r << "," << toCast.g << "," << toCast.b << "," << toCast.a << ")"; 31 | } 32 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/colour.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_MATH_COLOUR_HPP 2 | #define BLUB_MATH_COLOUR_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | 7 | namespace Ogre 8 | { 9 | class ColourValue; 10 | } 11 | 12 | 13 | namespace blub 14 | { 15 | 16 | 17 | class colour 18 | { 19 | public: 20 | #ifndef BLUB_NO_OGRE3D 21 | colour(const Ogre::ColourValue &vec); 22 | operator Ogre::ColourValue() const; 23 | #endif 24 | 25 | colour() 26 | : r(0.) 27 | , g(0.) 28 | , b(0.) 29 | , a(1.) 30 | {;} 31 | colour(const colour& other) 32 | : r(other.r) 33 | , g(other.g) 34 | , b(other.b) 35 | , a(other.a) 36 | {;} 37 | colour(const real& r_, const real& g_, const real& b_, const real& a_ = 1.) 38 | : r(r_) 39 | , g(g_) 40 | , b(b_) 41 | , a(a_) 42 | {;} 43 | 44 | bool operator ==(const colour& toCompare) const 45 | { 46 | return toCompare.a == a && 47 | toCompare.b == b && 48 | toCompare.g == g && 49 | toCompare.r == r; 50 | } 51 | bool operator !=(const colour& toCompare) const 52 | { 53 | return toCompare.a != a || 54 | toCompare.b != b || 55 | toCompare.g != g || 56 | toCompare.r != r; 57 | } 58 | inline colour operator + (const colour& toAdd) const 59 | { 60 | colour kSum; 61 | 62 | kSum.r = r + toAdd.r; 63 | kSum.g = g + toAdd.g; 64 | kSum.b = b + toAdd.b; 65 | kSum.a = a + toAdd.a; 66 | 67 | return kSum; 68 | } 69 | inline colour operator - (const colour& toSub) const 70 | { 71 | colour kDiff; 72 | 73 | kDiff.r = r - toSub.r; 74 | kDiff.g = g - toSub.g; 75 | kDiff.b = b - toSub.b; 76 | kDiff.a = a - toSub.a; 77 | 78 | return kDiff; 79 | } 80 | inline colour operator / (const real scalar) const 81 | { 82 | BASSERT(scalar != 0.0); 83 | 84 | colour kDiv; 85 | 86 | real fInv = 1.0f / scalar; 87 | kDiv.r = r * fInv; 88 | kDiv.g = g * fInv; 89 | kDiv.b = b * fInv; 90 | kDiv.a = a * fInv; 91 | 92 | return kDiv; 93 | } 94 | public: 95 | real r, g, b, a; 96 | 97 | }; 98 | 99 | 100 | std::ostream& operator<< (std::ostream& ostr, const colour& toCast); 101 | 102 | 103 | } 104 | 105 | #endif // BLUB_MATH_COLOUR_HPP 106 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/intersection.cpp: -------------------------------------------------------------------------------- 1 | #include "intersection.hpp" 2 | 3 | #include "blub/math/math.hpp" 4 | #include "blub/math/ray.hpp" 5 | #include "blub/math/triangleVector3.hpp" 6 | #include "blub/math/vector3.hpp" 7 | 8 | #include 9 | 10 | 11 | bool blub::intersection::intersect(const blub::ray &ray_, const blub::triangleVector3 &triangle_, blub::vector3 *position) 12 | { 13 | // 14 | // Calculate intersection with plane. 15 | // 16 | const bool negativeSide(true); 17 | const bool positiveSide(true); 18 | const vector3 normal(triangle_.getNormal()); 19 | const vector3 posA(triangle_.positions[0]); 20 | const vector3 posB(triangle_.positions[1]); 21 | const vector3 posC(triangle_.positions[2]); 22 | 23 | real t; 24 | { 25 | real denom = normal.dotProduct(ray_.getDirection()); 26 | 27 | // Check intersect side 28 | if (denom > + std::numeric_limits::epsilon()) 29 | { 30 | if (!negativeSide) 31 | { 32 | return false; 33 | } 34 | } 35 | else if (denom < - std::numeric_limits::epsilon()) 36 | { 37 | if (!positiveSide) 38 | { 39 | return false; 40 | } 41 | } 42 | else 43 | { 44 | // Parallel or triangle area is close to zero when 45 | // the plane normal not normalised. 46 | return false; 47 | } 48 | 49 | t = normal.dotProduct(posA - ray_.getOrigin()) / denom; 50 | } 51 | 52 | // 53 | // Calculate the largest area projection plane in X, Y or Z. 54 | // 55 | size_t i0, i1; 56 | { 57 | real n0 = math::abs(normal[0]); 58 | real n1 = math::abs(normal[1]); 59 | real n2 = math::abs(normal[2]); 60 | 61 | i0 = 1; i1 = 2; 62 | if (n1 > n2) 63 | { 64 | if (n1 > n0) i0 = 0; 65 | } 66 | else 67 | { 68 | if (n2 > n0) i1 = 0; 69 | } 70 | } 71 | 72 | // 73 | // Check the intersection point is inside the triangle. 74 | // 75 | { 76 | real u1 = posB[i0] - posA[i0]; 77 | real v1 = posB[i1] - posA[i1]; 78 | real u2 = posC[i0] - posA[i0]; 79 | real v2 = posC[i1] - posA[i1]; 80 | real u0 = t * ray_.getDirection()[i0] + ray_.getOrigin()[i0] - posA[i0]; 81 | real v0 = t * ray_.getDirection()[i1] + ray_.getOrigin()[i1] - posA[i1]; 82 | 83 | real alpha = u0 * v2 - u2 * v0; 84 | real beta = u1 * v0 - u0 * v1; 85 | real area = u1 * v2 - u2 * v1; 86 | 87 | // epsilon to avoid float precision error 88 | const real EPSILON = 1e-6f; // changed from ogre3d 1e-6f 89 | 90 | real tolerance = - EPSILON * area; 91 | 92 | if (area > 0) 93 | { 94 | if (alpha < tolerance || beta < tolerance || alpha+beta > area-tolerance) 95 | { 96 | return false; 97 | } 98 | } 99 | else 100 | { 101 | if (alpha > tolerance || beta > tolerance || alpha+beta < area-tolerance) 102 | { 103 | return false; 104 | } 105 | } 106 | } 107 | 108 | if (position != nullptr) 109 | { 110 | *position = ray_.getPoint(t); 111 | } 112 | 113 | return true; 114 | } 115 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/intersection.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_MATH_INTERSECTION_HPP 2 | #define BLUB_MATH_INTERSECTION_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/math/predecl.hpp" 6 | 7 | 8 | namespace blub 9 | { 10 | 11 | 12 | class intersection 13 | { 14 | public: 15 | static bool intersect(const ray &ray_, const triangleVector3 &triangle_, vector3* position); 16 | }; 17 | 18 | 19 | } 20 | 21 | 22 | #endif // BLUB_MATH_INTERSECTION_HPP 23 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/log/global.cpp: -------------------------------------------------------------------------------- 1 | #include "global.hpp" 2 | 3 | #include "blub/core/string.hpp" 4 | 5 | 6 | using namespace blub::math::log; 7 | using namespace blub; 8 | 9 | 10 | BLUB_LOG_GLOBAL_LOGGER_INIT(global, blub::log::logger) 11 | { 12 | blub::log::logger result("math"); 13 | return result; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/log/global.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_MATH_LOG_GLOBAL_HPP 2 | #define BLUB_MATH_LOG_GLOBAL_HPP 3 | 4 | #include "blub/log/global.hpp" 5 | #include "blub/log/globalLogger.hpp" 6 | #include "blub/log/logger.hpp" 7 | #include "blub/log/predecl.hpp" 8 | 9 | 10 | namespace blub 11 | { 12 | namespace math 13 | { 14 | namespace log 15 | { 16 | BLUB_LOG_GLOBAL_LOGGER(global, blub::log::logger) 17 | } 18 | } 19 | } 20 | 21 | 22 | #define BLUB_MATH_LOG_OUT() BLUB_LOG_OUT_TO(blub::math::log::global::get()) 23 | #define BLUB_MATH_LOG_WARNING() BLUB_LOG_WARNING_TO(blub::math::log::global::get()) 24 | #define BLUB_MATH_LOG_ERROR() BLUB_LOG_ERROR_TO(blub::math::log::global::get()) 25 | 26 | 27 | #endif // BLUB_GRAPHIC_LOG_GLOBAL_HPP 28 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/math.cpp: -------------------------------------------------------------------------------- 1 | #include "math.hpp" 2 | 3 | #include 4 | 5 | 6 | using namespace blub; 7 | 8 | #if defined(BOOST_NO_CXX11_CONSTEXPR) 9 | const real math::pi = 3.14159265358979323846; 10 | const real math::piHalf = math::pi / 2.; 11 | const real math::sqrtZeroPointFive = 0.707106781; 12 | const real math::sqrtOneThird = 0.577350269; 13 | #else 14 | constexpr real math::pi; 15 | constexpr real math::piHalf; 16 | constexpr real math::sqrtZeroPointFive; 17 | constexpr real math::sqrtOneThird; 18 | #endif 19 | 20 | 21 | real math::abs(const real &calc) 22 | { 23 | return std::abs(calc); 24 | } 25 | 26 | real math::map(const real &value, const real &fromMin, const real &fromMax, const real &toMin, const real &toMax) 27 | { 28 | BASSERT(between(value, fromMin, fromMax)); 29 | BASSERT(toMin < toMax); 30 | return clamp(((value-fromMin)/(fromMax-fromMin))*(toMax-toMin)+toMin, toMin, toMax); 31 | } 32 | 33 | real math::sin(const real &calc) 34 | { 35 | return std::sin(calc); 36 | } 37 | 38 | real math::asin(const real &calc) 39 | { 40 | return std::asin(calc); 41 | } 42 | 43 | real math::cos(const real &calc) 44 | { 45 | return std::cos(calc); 46 | } 47 | 48 | real math::acos(const real &calc) 49 | { 50 | return std::acos(calc); 51 | } 52 | 53 | real math::atan2(const real &fst, const real &snd) 54 | { 55 | return std::atan2(fst, snd); 56 | } 57 | 58 | real math::sqrt(const real &calc) 59 | { 60 | return std::sqrt(calc); 61 | } 62 | 63 | int32 math::pow(const int32 &number, const int32 &expo) 64 | { 65 | return (int32)std::pow((real)number, (int)expo); 66 | } 67 | 68 | real math::pow(const real &number, const real &expo) 69 | { 70 | return std::pow(number, expo); 71 | } 72 | 73 | uint32 math::rand() 74 | { 75 | return std::rand(); 76 | } 77 | 78 | real math::randReal() 79 | { 80 | return real(rand()) / real(RAND_MAX); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/math.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_MATH_HPP 2 | #define BLUB_MATH_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | #include 9 | 10 | 11 | namespace blub 12 | { 13 | 14 | 15 | class math 16 | { 17 | public: 18 | 19 | 20 | #if defined(BOOST_NO_CXX11_CONSTEXPR) 21 | static const real math::pi; 22 | static const real math::piHalf; 23 | static const real math::sqrtZeroPointFive; 24 | static const real math::sqrtOneThird; 25 | #else 26 | static constexpr real pi = 3.14159265358979323846; 27 | static constexpr real piHalf = pi / 2.; 28 | static constexpr real sqrtZeroPointFive = 0.707106781; 29 | static constexpr real sqrtOneThird = 0.577350269; // sqrt(1/3) 30 | #endif 31 | 32 | 33 | template 34 | static T min(const T &val, const T &minimum) 35 | { 36 | return std::min(val, minimum); 37 | } 38 | template 39 | static T max(const T &val, const T &maximum) 40 | { 41 | return std::max(val, maximum); 42 | } 43 | static real abs(const real& calc); 44 | 45 | template 46 | static T clamp(const T& val, const T& minval, const T& maxval) 47 | { 48 | BASSERT(minval <= maxval); 49 | return std::max(std::min(val, maxval), minval); 50 | } 51 | template 52 | static T clamp(const T& val, const pairType& minMaxVal) 53 | { 54 | BASSERT(minMaxVal.first <= minMaxVal.second); 55 | return clamp(val, minMaxVal.first, minMaxVal.second); 56 | } 57 | 58 | static real map(const real &value, const real &fromMin, const real &fromMax, const real &toMin, const real &toMax); 59 | 60 | template 61 | static T floor(const T& calc) 62 | { 63 | return std::floor(calc); 64 | } 65 | template 66 | static T ceil(const T& val) 67 | { 68 | return std::ceil(val); 69 | } 70 | 71 | template 72 | static bool between(const T& number, const T& min, const T& max) 73 | { 74 | return (number >= min) && (number <= max); 75 | } 76 | 77 | static real sin(const real& calc); 78 | static real asin(const real& calc); 79 | static real cos(const real& calc); 80 | static real acos(const real& calc); 81 | static real atan2(const real& fst, const real& snd); 82 | 83 | static real sqrt(const real& calc); 84 | 85 | static int32 pow(const int32& number, const int32& expo); 86 | static real pow(const real& number, const real& expo); 87 | 88 | static uint32 rand(); 89 | static real randReal(); 90 | 91 | private: 92 | math() 93 | {;} 94 | 95 | }; 96 | 97 | } 98 | 99 | #endif // BLUB_MATH_HPP 100 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/octree/search.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OCTREE_SEARCH_HPP 2 | #define OCTREE_SEARCH_HPP 3 | 4 | #include "blub/math/axisAlignedBox.hpp" 5 | #include "blub/math/octree/container.hpp" 6 | #include "blub/math/sphere.hpp" 7 | 8 | #include 9 | #include 10 | 11 | 12 | namespace blub 13 | { 14 | namespace octree 15 | { 16 | 17 | 18 | template 19 | class search 20 | { 21 | public: 22 | typedef search t_thisClass; 23 | 24 | typedef container t_container; 25 | typedef typename t_container::t_leafPtr t_leafPtr; 26 | typedef typename t_container::t_nodePtr t_nodePtr; 27 | typedef typename t_container::t_leafList t_leafList; 28 | typedef typename t_container::t_data t_data; 29 | typedef typename t_container::t_dataList t_dataList; 30 | 31 | 32 | static t_leafList getLeafesBySphere(const t_container& toSearchIn, const sphere& insideSphere) 33 | { 34 | return getLeafsByUserDefinedFunction(toSearchIn, boost::bind(&t_thisClass::getLeafsBySphereSearchFunction, insideSphere, _1)); 35 | } 36 | 37 | static t_dataList getDataBySphere(const t_container& toSearchIn, const sphere& insideSphere) 38 | { 39 | t_dataList result; 40 | 41 | t_leafList leafs(getLeafesBySphere(toSearchIn, insideSphere)); 42 | 43 | for (t_leafPtr leaf : leafs) 44 | { 45 | for (t_data data : leaf->getData()) 46 | { 47 | result.insert(data); 48 | } 49 | } 50 | 51 | return result; 52 | } 53 | 54 | static t_leafList getLeafsByUserDefinedFunction(const t_container& toSearchIn, const boost::function& isInside) 55 | { 56 | t_leafList result; 57 | getLeafsByUserDefinedFunctionRecursively(toSearchIn, toSearchIn.getRootNode(), isInside, &result); 58 | 59 | return result; 60 | } 61 | 62 | static t_dataList getDataByUserDefinedFunction(const t_container& toSearchIn, const boost::function& isInside) 63 | { 64 | t_dataList result; 65 | 66 | t_leafList leafs(getLeafsByUserDefinedFunction(toSearchIn, isInside)); 67 | 68 | for (t_leafPtr leaf : leafs) 69 | { 70 | for (t_data data : leaf->getData()) 71 | { 72 | result.insert(data); 73 | } 74 | } 75 | 76 | return result; 77 | } 78 | 79 | private: 80 | static void getLeafsByUserDefinedFunctionRecursively( const t_container& tree, 81 | const t_nodePtr& toSearchIn, 82 | const boost::function& isInside, 83 | t_leafList* result) 84 | { 85 | if (isInside(toSearchIn)) 86 | { 87 | t_leafPtr lf(tree.isLeaf(toSearchIn)); 88 | if (lf) 89 | { 90 | result->insert(lf); 91 | return; 92 | } 93 | for (int8 child = 0; child < 8; ++child) 94 | { 95 | t_nodePtr childNode(toSearchIn->getNode(child)); 96 | if (childNode != nullptr) 97 | { 98 | getLeafsByUserDefinedFunctionRecursively(tree, childNode, isInside, result); 99 | } 100 | } 101 | } 102 | 103 | } 104 | 105 | static bool getLeafsBySphereSearchFunction(const sphere& sphere_, t_nodePtr node) 106 | { 107 | return sphere_.intersects(node->getBoundingBox()); 108 | } 109 | 110 | 111 | }; 112 | 113 | 114 | } 115 | } 116 | 117 | 118 | #endif // OCTREE_SEARCH_HPP 119 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/plane.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/math/plane.hpp" 2 | 3 | #ifndef BLUB_NO_OGRE3D 4 | # include 5 | #endif 6 | 7 | 8 | using namespace blub; 9 | 10 | 11 | #ifndef BLUB_NO_OGRE3D 12 | plane::plane(const Ogre::Plane &vec) 13 | : normal(vec.normal) 14 | , d(vec.d) 15 | { 16 | 17 | } 18 | 19 | plane::operator Ogre::Plane() const 20 | { 21 | return Ogre::Plane(normal, d); 22 | } 23 | #endif 24 | 25 | plane::plane() 26 | { 27 | } 28 | 29 | plane::plane(const plane &other) 30 | : normal(other.normal) 31 | , d(other.d) 32 | { 33 | } 34 | 35 | plane::plane(vector3 rkPoint0, vector3 rkPoint1, vector3 rkPoint2) 36 | { 37 | vector3 kEdge1 = rkPoint1 - rkPoint0; 38 | vector3 kEdge2 = rkPoint2 - rkPoint0; 39 | normal = kEdge1.crossProduct(kEdge2); 40 | normal.normalise(); 41 | d = -normal.dotProduct(rkPoint0); 42 | } 43 | 44 | plane::plane(vector3 rkPoint, vector3 rkNormal) 45 | { 46 | normal = rkNormal; 47 | d = -rkNormal.dotProduct(rkPoint); 48 | } 49 | 50 | plane::plane(const vector3 &normal, const real &d) 51 | : normal(normal) 52 | , d(d) 53 | { 54 | ; 55 | } 56 | 57 | real plane::getDistance(const vector3 &rkPoint) const 58 | { 59 | return normal.dotProduct(rkPoint) + d; 60 | } 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/plane.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_MATH_PLANE_HPP 2 | #define BLUB_MATH_PLANE_HPP 3 | 4 | #include "blub/math/vector3.hpp" 5 | 6 | 7 | namespace Ogre 8 | { 9 | class Plane; 10 | } 11 | 12 | 13 | namespace blub 14 | { 15 | 16 | class plane 17 | { 18 | public: 19 | #ifndef BLUB_NO_OGRE3D 20 | plane(const Ogre::Plane &vec); 21 | operator Ogre::Plane() const; 22 | #endif 23 | 24 | plane(); 25 | plane(const plane& other); 26 | plane(vector3 p0, vector3 p1, vector3 p2); 27 | plane(vector3 pos, vector3 normal); 28 | plane(const vector3 &normal, const real &d); 29 | 30 | /** This is a pseudodistance. The sign of the return value is 31 | positive if the point is on the positive side of the plane, 32 | negative if the point is on the negative side, and zero if the 33 | point is on the plane. 34 | @par 35 | The absolute value of the return value is the true distance only 36 | when the plane normal is a unit length vector. 37 | */ 38 | real getDistance (const vector3 &rkPoint) const; 39 | 40 | bool operator==(const plane& rhs) const 41 | { 42 | return rhs.d == d && rhs.normal == normal; 43 | } 44 | bool operator!=(const plane& rhs) const 45 | { 46 | return rhs.d != d || rhs.normal != normal; 47 | } 48 | 49 | public: 50 | vector3 normal; 51 | real d; 52 | 53 | }; 54 | 55 | } 56 | 57 | #endif // BLUB_MATH_PLANE_HPP 58 | 59 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/predecl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_MATH_PREDECL_HPP 2 | #define BLUB_MATH_PREDECL_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | 11 | class axisAlignedBox; 12 | class axisAlignedBoxInt32; 13 | template 14 | class axisAlignedBoxTemplate; 15 | class colour; 16 | class plane; 17 | class quaternion; 18 | class rectangle; 19 | class sphere; 20 | class transform; 21 | class triangle; 22 | class triangleVector3; 23 | class vector2; 24 | template 25 | class vector2Template; 26 | typedef vector2Template vector2int32; 27 | class vector3; 28 | template 29 | class vector3Template; 30 | typedef vector3Template vector3int32; 31 | typedef vector3Template vector3uint8; 32 | 33 | 34 | 35 | } 36 | 37 | 38 | #endif // BLUB_MATH_PREDECL_HPP 39 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/ray.cpp: -------------------------------------------------------------------------------- 1 | #include "ray.hpp" 2 | 3 | #include "blub/math/plane.hpp" 4 | #include "blub/log/global.hpp" 5 | 6 | #ifndef BLUB_NO_OGRE3D 7 | # include 8 | #endif 9 | 10 | 11 | using namespace blub; 12 | 13 | 14 | #ifndef BLUB_NO_OGRE3D 15 | ray::ray(const Ogre::Ray &vec) 16 | : mOrigin(vec.getOrigin()) 17 | , mDirection(vec.getDirection()) 18 | { 19 | ; 20 | } 21 | 22 | ray::operator Ogre::Ray() const 23 | { 24 | return Ogre::Ray(mOrigin, mDirection); 25 | } 26 | #endif 27 | 28 | 29 | bool ray::intersects(const plane &pl, vector3 *point, real *tOut) const 30 | { 31 | std::pair result; 32 | real denom = pl.normal.dotProduct(getDirection()); 33 | if (math::abs(denom) < std::numeric_limits::epsilon()) 34 | { 35 | // Parallel 36 | result = std::pair(false, 0); 37 | } 38 | else 39 | { 40 | real nom = pl.normal.dotProduct(getOrigin()) + pl.d; 41 | real t = -(nom/denom); 42 | result = std::pair(true, t); 43 | } 44 | 45 | if (result.first) 46 | { 47 | if (point) 48 | { 49 | *point = getPoint(result.second); 50 | } 51 | if (tOut) 52 | { 53 | *tOut = result.second; 54 | } 55 | } 56 | return result.first; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/ray.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LINE_HPP 2 | #define LINE_HPP 3 | 4 | #include "blub/math/vector3.hpp" 5 | 6 | 7 | namespace Ogre 8 | { 9 | class Ray; 10 | } 11 | 12 | 13 | namespace blub 14 | { 15 | 16 | class ray 17 | { 18 | public: 19 | #ifndef BLUB_NO_OGRE3D 20 | ray(const Ogre::Ray &vec); 21 | operator Ogre::Ray() const; 22 | #endif 23 | 24 | ray():mOrigin(vector3::ZERO), mDirection(vector3::UNIT_Z) {} 25 | ray(const vector3& origin, const vector3& direction) 26 | :mOrigin(origin), mDirection(direction) {} 27 | 28 | /** Sets the origin of the ray. */ 29 | void setOrigin(const vector3& origin) {mOrigin = origin;} 30 | /** Gets the origin of the ray. */ 31 | const vector3& getOrigin(void) const {return mOrigin;} 32 | 33 | /** Sets the direction of the ray. */ 34 | void setDirection(const vector3& dir) {mDirection = dir;} 35 | /** Gets the direction of the ray. */ 36 | const vector3& getDirection(void) const {return mDirection;} 37 | 38 | /** Gets the position of a point t units along the ray. */ 39 | vector3 getPoint(real t) const { 40 | return vector3(mOrigin + (mDirection * t)); 41 | } 42 | 43 | /** Gets the position of a point t units along the ray. */ 44 | vector3 operator*(real t) const { 45 | return getPoint(t); 46 | } 47 | 48 | bool intersects (const plane &pl, vector3 *point = nullptr, real *tOut = nullptr) const; 49 | 50 | protected: 51 | vector3 mOrigin; 52 | vector3 mDirection; 53 | 54 | }; 55 | 56 | } 57 | 58 | #endif // LINE_HPP 59 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "rectangle.hpp" 2 | 3 | using namespace blub; 4 | 5 | rectangle::rectangle() 6 | { 7 | } 8 | 9 | rectangle::rectangle(const vector2 &topLeft_, const vector2 &rightBottom_) 10 | : topLeft(topLeft_) 11 | , rightBottom(rightBottom_) 12 | { 13 | } 14 | 15 | void rectangle::merge(const rectangle &other) 16 | { 17 | topLeft.x = other.topLeft.x > topLeft.x ? other.topLeft.x : topLeft.x; 18 | topLeft.y = other.topLeft.y > topLeft.y ? other.topLeft.y : topLeft.y; 19 | rightBottom.x = other.rightBottom.x < rightBottom.x ? other.rightBottom.x : rightBottom.x; 20 | rightBottom.y = other.rightBottom.y < rightBottom.y ? other.rightBottom.y : rightBottom.y; 21 | } 22 | 23 | void rectangle::merge(const vector2 &other) 24 | { 25 | topLeft.x = other.x > topLeft.x ? other.x : topLeft.x; 26 | topLeft.y = other.y > topLeft.y ? other.y : topLeft.y; 27 | rightBottom.x = other.x < rightBottom.x ? other.x : rightBottom.x; 28 | rightBottom.y = other.y < rightBottom.y ? other.y : rightBottom.y; 29 | } 30 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/rectangle.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RECTANGLE_HPP 2 | #define RECTANGLE_HPP 3 | 4 | #include "vector2.hpp" 5 | 6 | namespace blub 7 | { 8 | 9 | class rectangle 10 | { 11 | public: 12 | vector2 topLeft, rightBottom; 13 | 14 | rectangle(void); 15 | rectangle(const vector2 &topLeft_, const vector2 &rightBottom_); 16 | 17 | void merge(const rectangle &other); 18 | void merge(const vector2 &other); 19 | }; 20 | 21 | } 22 | 23 | #endif // RECTANGLE_HPP 24 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/sphere.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/math/sphere.hpp" 2 | 3 | #include "axisAlignedBox.hpp" 4 | 5 | 6 | using namespace blub; 7 | 8 | 9 | bool sphere::intersects(const sphere &s) const 10 | { 11 | return (s.mCenter - mCenter).squaredLength() <= (s.mRadius + mRadius)*(s.mRadius + mRadius); 12 | } 13 | 14 | void sphere::merge(const sphere& oth) 15 | { 16 | vector3 diff = oth.getCenter() - mCenter; 17 | real lengthSq = diff.squaredLength(); 18 | real radiusDiff = oth.getRadius() - mRadius; 19 | 20 | // Early-out 21 | if (radiusDiff*radiusDiff >= lengthSq) 22 | { 23 | // One fully contains the other 24 | if (radiusDiff <= 0.0f) 25 | return; // no change 26 | else 27 | { 28 | mCenter = oth.getCenter(); 29 | mRadius = oth.getRadius(); 30 | return; 31 | } 32 | } 33 | 34 | real length = math::sqrt(lengthSq); 35 | real t = (length + radiusDiff) / (2.0f * length); 36 | mCenter = mCenter + diff * t; 37 | mRadius = 0.5f * (length + mRadius + oth.getRadius()); 38 | } 39 | 40 | bool sphere::inherts(axisAlignedBox aabb) const 41 | { 42 | return aabb.getMinimum().squaredDistance(getCenter()) < getRadius()*getRadius() && 43 | aabb.getMaximum().squaredDistance(getCenter()) < getRadius()*getRadius(); 44 | } 45 | 46 | bool sphere::intersects(const axisAlignedBox &box) const 47 | { 48 | if (box.isNull()) return false; 49 | if (box.isInfinite()) return true; 50 | 51 | // Use splitting planes 52 | const vector3& center = getCenter(); 53 | real radius = getRadius(); 54 | const vector3& min = box.getMinimum(); 55 | const vector3& max = box.getMaximum(); 56 | 57 | // Arvo's algorithm 58 | real s, d = 0; 59 | for (int i = 0; i < 3; ++i) 60 | { 61 | if (center.ptr()[i] < min.ptr()[i]) 62 | { 63 | s = center.ptr()[i] - min.ptr()[i]; 64 | d += s * s; 65 | } 66 | else if(center.ptr()[i] > max.ptr()[i]) 67 | { 68 | s = center.ptr()[i] - max.ptr()[i]; 69 | d += s * s; 70 | } 71 | } 72 | return d <= radius * radius; 73 | } 74 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/sphere.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_SPHERE_HPP 2 | #define BLUB_SPHERE_HPP 3 | 4 | #include "vector3.hpp" 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | class sphere 11 | { 12 | public: 13 | /** Standard constructor - creates a unit sphere around the origin.*/ 14 | sphere() : mRadius(1.0), mCenter(vector3::ZERO) {} 15 | /** Constructor allowing arbitrary spheres. 16 | @param center The center point of the sphere. 17 | @param radius The radius of the sphere. 18 | */ 19 | sphere(const vector3& center, real radius) 20 | : mRadius(radius), mCenter(center) {} 21 | 22 | /** Returns the radius of the sphere. */ 23 | real getRadius(void) const { return mRadius; } 24 | 25 | /** Sets the radius of the sphere. */ 26 | void setRadius(real radius) { mRadius = radius; } 27 | 28 | /** Returns the center point of the sphere. */ 29 | const vector3& getCenter(void) const { return mCenter; } 30 | 31 | /** Sets the center point of the sphere. */ 32 | void setCenter(const vector3& center) { mCenter = center; } 33 | 34 | /** Returns whether or not this sphere intersects another sphere. */ 35 | bool intersects(const sphere& s) const; 36 | 37 | /** Returns whether or not this sphere intersects a box. */ 38 | bool intersects(const axisAlignedBox& box) const; 39 | 40 | /** Returns whether or not this sphere intersects a point. */ 41 | bool intersects(const vector3& v) const 42 | { 43 | return ((v - mCenter).squaredLength() <= mRadius*mRadius); 44 | } 45 | /** Merges another sphere into the current sphere */ 46 | void merge(const sphere& oth); 47 | 48 | bool contains(const vector3& vec) const 49 | {return intersects(vec);} 50 | 51 | real getSquaredRadius() const 52 | { 53 | return mRadius*mRadius; 54 | } 55 | 56 | bool inherts(axisAlignedBox aabb) const; 57 | 58 | protected: 59 | real mRadius; 60 | vector3 mCenter; 61 | 62 | }; 63 | 64 | } 65 | 66 | #endif // BLUB_SPHERE_HPP 67 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/transform.cpp: -------------------------------------------------------------------------------- 1 | #include "transform.hpp" 2 | 3 | #ifdef BLUB_USE_BULLET 4 | # include 5 | #endif 6 | 7 | using namespace blub; 8 | 9 | transform::transform(const blub::vector3 &position_, const blub::quaternion &rotation_, const blub::vector3 &scale_) 10 | : position(position_) 11 | , rotation(rotation_) 12 | , scale(scale_) 13 | { 14 | ; 15 | } 16 | 17 | /*blub::transform::transform(const blub::transform &other) 18 | : position(other.position) 19 | , rotation(other.rotation) 20 | , scale(other.scale) 21 | { 22 | }*/ 23 | 24 | #ifndef BLUB_NO_BULLET 25 | transform::transform(const btTransform &other) 26 | : position(other.getOrigin()) 27 | , rotation(other.getRotation()) 28 | , scale(1.) 29 | { 30 | } 31 | transform::operator btTransform () const 32 | { 33 | return btTransform(rotation, position); 34 | } 35 | #endif 36 | 37 | bool transform::operator ==(const transform &other) const 38 | { 39 | return position == other.position && 40 | rotation == other.rotation && 41 | scale == other.scale; 42 | } 43 | 44 | bool transform::operator !=(const transform &other) const 45 | { 46 | return position != other.position || 47 | rotation != other.rotation || 48 | scale != other.scale; 49 | } 50 | 51 | transform transform::operator +(const transform &other) const 52 | { 53 | return transform(position+(rotation*other.position), rotation*other.rotation); 54 | } 55 | 56 | transform transform::getRelativeTo(const transform &other) const 57 | { 58 | transform result; 59 | blub::vector3 buffer(other.position - position); 60 | buffer = (rotation.Inverse())*buffer; 61 | result.position = buffer; 62 | result.rotation = rotation.Inverse()*other.rotation; 63 | 64 | return result; 65 | } 66 | 67 | 68 | std::ostream &blub::operator<< (std::ostream &ostr, const transform &toCast) 69 | { 70 | return ostr << "{" << toCast.position << "," << toCast.rotation << "," << toCast.scale << "}"; 71 | } 72 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/transform.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORM_HPP 2 | #define TRANSFORM_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/math/vector3.hpp" 6 | #include "blub/math/quaternion.hpp" 7 | #ifdef BLUB_USE_PHYSX 8 | # include 9 | #endif 10 | 11 | 12 | #ifdef BLUB_USE_BULLET 13 | class btTransform; 14 | #endif 15 | 16 | 17 | namespace blub 18 | { 19 | 20 | class transform 21 | { 22 | public: 23 | transform(const vector3& position_ = vector3(), const quaternion& rotation_ = quaternion(), const vector3& scale_ = vector3(1.)); 24 | //depricated transform(const transform& other); 25 | 26 | #ifdef BLUB_USE_PHYSX 27 | transform(const physx::PxTransform& other) 28 | : position(other.p), rotation(other.q), scale(1.) 29 | {} 30 | operator physx::PxTransform() const 31 | {return physx::PxTransform(position, rotation);} 32 | #endif 33 | #ifdef BLUB_USE_BULLET 34 | transform(const btTransform& other); 35 | operator btTransform() const; 36 | #endif 37 | 38 | bool operator ==(const transform& other) const; 39 | bool operator !=(const transform& other) const; 40 | 41 | transform operator +(const transform& other) const; 42 | 43 | transform getRelativeTo(const transform& other) const; 44 | 45 | public: 46 | vector3 position; 47 | quaternion rotation; 48 | vector3 scale; 49 | 50 | protected: 51 | BLUB_SERIALIZATION_ACCESS 52 | template 53 | void serialize(Archive & readWrite, const unsigned int version) 54 | { 55 | (void)version; 56 | 57 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(position); 58 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(rotation); 59 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(scale); 60 | } 61 | }; 62 | 63 | 64 | std::ostream& operator << (std::ostream& ostr, const blub::transform& toCast); 65 | 66 | 67 | } 68 | 69 | #endif // TRANSFORM_HPP 70 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/triangle.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TRIANGLE_HPP 2 | #define TRIANGLE_HPP 3 | 4 | #include "blub/core/list.hpp" 5 | #include "blub/core/globals.hpp" 6 | 7 | namespace blub 8 | { 9 | 10 | class triangle 11 | { 12 | public: 13 | triangle() 14 | {;} 15 | triangle(blub::uint32 a, blub::uint32 b, blub::uint32 c) 16 | { 17 | ind[0] = a; 18 | ind[1] = b; 19 | ind[2] = c; 20 | } 21 | 22 | bool contains(blub::uint32 _ind) 23 | { 24 | return ind[0] == _ind || ind[1] == _ind || ind[2] == _ind; 25 | } 26 | 27 | bool valid() 28 | { 29 | return ind[0] != ind[1] && ind[0] != ind[2] && ind[1] != ind[2]; 30 | } 31 | 32 | bool operator == (const triangle & other) const 33 | { 34 | list otherVec; 35 | for (uint16 ind1 = 0; ind1 < 3; ++ind1) 36 | otherVec.push_back(other.ind[ind1]); 37 | for (uint16 ind1 = 0; ind1 < 3; ++ind1) 38 | { 39 | int32 index = otherVec.indexOf(ind[ind1]); 40 | if (index == -1) 41 | return false; 42 | else 43 | otherVec.removeAt(index); 44 | } 45 | return true; 46 | } 47 | triangle operator + (const int32 & other) const 48 | { 49 | return triangle(ind[0]+other, ind[1]+other, ind[2]+other); 50 | } 51 | 52 | blub::uint16 ind[3]; 53 | }; 54 | 55 | } 56 | 57 | #endif // TRIANGLE_HPP 58 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/triangleVector3.cpp: -------------------------------------------------------------------------------- 1 | #include "triangleVector3.hpp" 2 | 3 | #include "blub/math/axisAlignedBox.hpp" 4 | #include "blub/math/plane.hpp" 5 | 6 | 7 | using namespace blub; 8 | 9 | 10 | axisAlignedBox triangleVector3::getAxisAlignedBoundingBox() const 11 | { 12 | vector3 min(positions[0]); 13 | min.makeFloor(positions[1]); 14 | min.makeFloor(positions[2]); 15 | 16 | vector3 max(positions[0]); 17 | max.makeCeil(positions[1]); 18 | max.makeCeil(positions[2]); 19 | 20 | return axisAlignedBox(min, max); 21 | } 22 | 23 | plane triangleVector3::getPlane() const 24 | { 25 | return plane(positions[0], positions[1], positions[2]); 26 | } 27 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/triangleVector3.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TRIANGLEVECTOR3_2_HPP 2 | #define TRIANGLEVECTOR3_2_HPP 3 | 4 | #include "blub/math/vector3.hpp" 5 | 6 | 7 | namespace blub 8 | { 9 | 10 | class triangleVector3 11 | { 12 | public: 13 | triangleVector3() 14 | { 15 | positions[0] = vector3(0); 16 | positions[1] = vector3(0); 17 | positions[2] = vector3(0); 18 | } 19 | triangleVector3(const vector3& a, const vector3& b, const vector3& c) 20 | { 21 | positions[0] = a; 22 | positions[1] = b; 23 | positions[2] = c; 24 | } 25 | 26 | triangleVector3(const vector3& a) 27 | { 28 | positions[0] = a; 29 | positions[1] = a; 30 | positions[2] = a; 31 | } 32 | 33 | bool operator == (const triangleVector3 & other) const 34 | { 35 | return other.positions[0] == positions[0] 36 | && other.positions[1] == positions[1] 37 | && other.positions[2] == positions[2]; 38 | } 39 | 40 | vector3 nearest(vector3 to) const 41 | { 42 | return positions[nearestId(to)]; 43 | } 44 | 45 | uint16 nearestId(vector3 to) const 46 | { 47 | uint16 nearestId(0); 48 | real nearest(positions[0].squaredDistance(to)); 49 | for (uint16 index = 1; index < 3; ++index) 50 | { 51 | if (positions[index].squaredDistance(to) < nearest) 52 | nearestId = index; 53 | } 54 | return nearestId; 55 | } 56 | 57 | vector3 getNormal() const 58 | { 59 | return ((positions[1]-positions[0]).normalisedCopy()).crossProduct((positions[2]-positions[0]).normalisedCopy()); 60 | } 61 | 62 | axisAlignedBox getAxisAlignedBoundingBox() const; 63 | 64 | plane getPlane() const; 65 | 66 | vector3 midPoint() 67 | { 68 | return (positions[0] + positions[1] + positions[2]) / 3.0; 69 | } 70 | 71 | vector3 positions[3]; 72 | }; 73 | 74 | 75 | } 76 | 77 | #endif // TRIANGLEVECTOR3_HPP 78 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/vector2.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/math/vector2.hpp" 2 | #include "blub/math/vector2int.hpp" 3 | 4 | #include 5 | 6 | #ifndef BLUB_NO_OGRE3D 7 | # include 8 | #endif 9 | 10 | 11 | using namespace blub; 12 | 13 | 14 | #ifndef BLUB_NO_OGRE3D 15 | vector2::vector2(const Ogre::Vector2 &vec) 16 | : x(vec.x) 17 | , y(vec.y) 18 | { 19 | 20 | } 21 | 22 | vector2::operator Ogre::Vector2() const 23 | { 24 | return Ogre::Vector2(x, y); 25 | } 26 | 27 | #endif 28 | 29 | 30 | vector2::vector2(const vector2int32& cast) 31 | : x(cast.x) 32 | , y(cast.y) 33 | { 34 | } 35 | 36 | 37 | std::ostream &blub::operator<< (std::ostream &ostr, const vector2 &toCast) 38 | { 39 | return ostr << "(" << toCast.x << "," << toCast.y << ")"; 40 | } 41 | 42 | 43 | std::size_t blub::hash_value(const vector2 &value) 44 | { 45 | std::size_t result(value.x); 46 | boost::hash_combine(result, value.y); 47 | 48 | return result; 49 | } 50 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/vector2int.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_MATH_VECTOR2TEMPLATE_HPP 2 | #define BLUB_MATH_VECTOR2TEMPLATE_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/serialization/access.hpp" 6 | #include "blub/serialization/nameValuePair.hpp" 7 | 8 | #include 9 | 10 | 11 | namespace blub 12 | { 13 | 14 | template 15 | class vector2Template 16 | { 17 | public: 18 | typedef vector2Template t_thisClass; 19 | 20 | vector2Template() 21 | : x(valueDefault) 22 | , y(valueDefault) 23 | { 24 | ; 25 | } 26 | 27 | vector2Template(const valueType& x_, const valueType& y_) 28 | : x(x_) 29 | , y(y_) 30 | { 31 | ; 32 | } 33 | 34 | vector2Template(const valueType& val) 35 | : x(val) 36 | , y(val) 37 | { 38 | ; 39 | } 40 | 41 | vector2Template(const t_thisClass& copy) 42 | : x(copy.x) 43 | , y(copy.y) 44 | { 45 | ; 46 | } 47 | 48 | bool operator == (const t_thisClass& other) const 49 | { 50 | return other.x == x && other.y == y; 51 | } 52 | 53 | bool operator <= (const t_thisClass& other) const 54 | { 55 | return x <= other.x && y <= other.y; 56 | } 57 | 58 | bool operator < (const t_thisClass& other) const 59 | { 60 | return x < other.x && y < other.y; 61 | } 62 | 63 | bool operator >= (const t_thisClass& other) const 64 | { 65 | return x >= other.x && y >= other.y; 66 | } 67 | 68 | bool operator > (const t_thisClass& other) const 69 | { 70 | return x > other.x && y > other.y; 71 | } 72 | 73 | t_thisClass operator * (const t_thisClass& other) const 74 | { 75 | return t_thisClass(other.x*x, other.y*y); 76 | } 77 | 78 | t_thisClass operator * (const int32& other) const 79 | { 80 | return t_thisClass(other*x, other*y); 81 | } 82 | 83 | t_thisClass operator + (const t_thisClass& other) const 84 | { 85 | return t_thisClass(other.x+x, other.y+y); 86 | } 87 | 88 | t_thisClass operator - (const t_thisClass& other) const 89 | { 90 | return t_thisClass(x-other.x, y-other.y); 91 | } 92 | 93 | t_thisClass operator - (void) const 94 | { 95 | return t_thisClass(-x, -y); 96 | } 97 | 98 | t_thisClass operator / (const t_thisClass& other) const 99 | { 100 | return t_thisClass(x/other.x, y/other.y); 101 | } 102 | 103 | t_thisClass operator / (const valueType& other) const 104 | { 105 | return t_thisClass(x/other, y/other); 106 | } 107 | 108 | valueType calculateArea() const 109 | { 110 | return x*y; 111 | } 112 | 113 | protected: 114 | BLUB_SERIALIZATION_ACCESS 115 | template 116 | void serialize(Archive & readWrite, const unsigned int version) 117 | { 118 | (void)version; 119 | 120 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(x); 121 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(y); 122 | } 123 | 124 | public: 125 | valueType x; 126 | valueType y; 127 | 128 | }; 129 | 130 | template 131 | std::ostream& operator<< (std::ostream& ostr, const vector2Template& toCast) 132 | { 133 | return ostr << "(" << toCast.x << "," << toCast.y << ")"; 134 | } 135 | 136 | template 137 | std::size_t hash_value(const vector2Template& value) 138 | { 139 | std::size_t result(value.x); 140 | boost::hash_combine(result, value.y); 141 | 142 | return result; 143 | } 144 | 145 | 146 | } 147 | 148 | 149 | #endif // BLUB_MATH_VECTOR2TEMPLATE_HPP 150 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/vector3.cpp: -------------------------------------------------------------------------------- 1 | #include "blub/math/vector3.hpp" 2 | 3 | #include "blub/math/math.hpp" 4 | #include "blub/math/quaternion.hpp" 5 | #include "blub/math/vector3int.hpp" 6 | 7 | #include 8 | #ifndef BLUB_NO_BULLET 9 | # include 10 | #endif 11 | #ifndef BLUB_NO_OGRE3D 12 | # include 13 | #endif 14 | 15 | 16 | using namespace blub; 17 | 18 | const vector3 vector3::ZERO = vector3(0.); 19 | const vector3 vector3::UNIT_X = vector3(1., 0., 0.); 20 | const vector3 vector3::UNIT_Y = vector3(0., 1., 0.); 21 | const vector3 vector3::UNIT_Z = vector3(0., 0., 1.); 22 | const vector3 vector3::NEGATIVE_UNIT_X = vector3(-1., 0., 0.); 23 | const vector3 vector3::NEGATIVE_UNIT_Y = vector3(0., -1., 0.); 24 | const vector3 vector3::NEGATIVE_UNIT_Z = vector3(0., 0., -1.); 25 | const vector3 vector3::UNIT_SCALE = vector3(1., 1., 1.); 26 | 27 | 28 | vector3::vector3(const vector3int32 &cast) 29 | : x((real)cast.x) 30 | , y((real)cast.y) 31 | , z((real)cast.z) 32 | { 33 | } 34 | 35 | #ifndef BLUB_NO_OGRE3D 36 | vector3::vector3(const Ogre::Vector3 &vec) 37 | : x(vec.x) 38 | , y(vec.y) 39 | , z(vec.z) 40 | {;} 41 | 42 | vector3::operator Ogre::Vector3() const 43 | { 44 | return Ogre::Vector3(x, y, z); 45 | } 46 | #endif 47 | #ifndef BLUB_NO_BULLET 48 | vector3::vector3(const btVector3 &vec) 49 | : x(vec.getX()) 50 | , y(vec.getY()) 51 | , z(vec.getZ()) 52 | {;} 53 | 54 | vector3::operator btVector3() const 55 | { 56 | return btVector3(x, y, z); 57 | } 58 | #endif 59 | 60 | vector3 vector3::getFloor() const 61 | { 62 | return vector3(math::floor(x), math::floor(y), math::floor(z)); 63 | } 64 | 65 | vector3 vector3::getAbs() const 66 | { 67 | return vector3(math::abs(x), math::abs(y), math::abs(z)); 68 | } 69 | 70 | quaternion vector3::getRotationTo(const vector3 &dest, const vector3 &fallbackAxis) const 71 | { 72 | // Based on Stan Melax's article in Game Programming Gems 73 | quaternion q; 74 | // Copy, since cannot modify local 75 | vector3 v0 = *this; 76 | vector3 v1 = dest; 77 | v0.normalise(); 78 | v1.normalise(); 79 | 80 | real d = v0.dotProduct(v1); 81 | // If dot == 1, vectors are the same 82 | if (d >= 1.0f) 83 | { 84 | return quaternion::IDENTITY; 85 | } 86 | if (d < (1e-6f - 1.0f)) 87 | { 88 | if (fallbackAxis != vector3::ZERO) 89 | { 90 | // rotate 180 degrees about the fallback axis 91 | q.FromAngleAxis(real(math::pi), fallbackAxis); 92 | } 93 | else 94 | { 95 | // Generate an axis 96 | vector3 axis = vector3::UNIT_X.crossProduct(*this); 97 | if (axis.isZeroLength()) // pick another if colinear 98 | axis = vector3::UNIT_Y.crossProduct(*this); 99 | axis.normalise(); 100 | q.FromAngleAxis(real(math::pi), axis); 101 | } 102 | } 103 | else 104 | { 105 | real s = math::sqrt( (1+d)*2 ); 106 | real invs = 1 / s; 107 | 108 | vector3 c = v0.crossProduct(v1); 109 | 110 | q.x = c.x * invs; 111 | q.y = c.y * invs; 112 | q.z = c.z * invs; 113 | q.w = s * 0.5f; 114 | q.normalise(); 115 | } 116 | return q; 117 | } 118 | 119 | 120 | std::ostream &blub::operator<< (std::ostream &ostr, const vector3 &toCast) 121 | { 122 | return ostr << "(" << toCast.x << "," << toCast.y << "," << toCast.z << ")"; 123 | } 124 | 125 | std::size_t blub::hash_value(const vector3 &value) 126 | { 127 | std::size_t result(value.x); 128 | boost::hash_combine(result, value.y); 129 | boost::hash_combine(result, value.z); 130 | 131 | return result; 132 | } 133 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/vector3int.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_MATH_VECTOR3TEMPLATE_HPP 2 | #define BLUB_MATH_VECTOR3TEMPLATE_HPP 3 | 4 | #include "blub/math/math.hpp" 5 | #include "blub/math/vector3.hpp" 6 | #include "blub/serialization/access.hpp" 7 | #include "blub/serialization/nameValuePair.hpp" 8 | 9 | 10 | namespace blub 11 | { 12 | 13 | template 14 | class vector3Template 15 | { 16 | public: 17 | typedef valueType t_valueType; 18 | typedef vector3Template t_thisClass; 19 | 20 | vector3Template() 21 | : x(valueDefault) 22 | , y(valueDefault) 23 | , z(valueDefault) 24 | { 25 | ; 26 | } 27 | 28 | // not possible because of hash && multiple linking options 29 | // vector3Template(const valueType& value) 30 | 31 | vector3Template(const valueType& x_, const valueType& y_, const valueType& z_) 32 | : x(x_) 33 | , y(y_) 34 | , z(z_) 35 | { 36 | ; 37 | } 38 | 39 | vector3Template(const t_thisClass& copy) 40 | : x(copy.x) 41 | , y(copy.y) 42 | , z(copy.z) 43 | { 44 | ; 45 | } 46 | 47 | vector3Template(const valueType& val) 48 | : x(val) 49 | , y(val) 50 | , z(val) 51 | { 52 | ; 53 | } 54 | 55 | vector3Template(const vector3& cast) 56 | : x(cast.x) 57 | , y(cast.y) 58 | , z(cast.z) 59 | { 60 | ; 61 | } 62 | 63 | bool operator == (const t_thisClass& other) const 64 | { 65 | return other.x == x && other.y == y && other.z == z; 66 | } 67 | 68 | bool operator != (const t_thisClass& other) const 69 | { 70 | return other.x != x && other.y != y && other.z != z; 71 | } 72 | 73 | bool operator <= (const t_thisClass& other) const 74 | { 75 | return x <= other.x && y <= other.y && z <= other.z; 76 | } 77 | 78 | bool operator < (const t_thisClass& other) const 79 | { 80 | return x < other.x && y < other.y && z < other.z; 81 | } 82 | 83 | bool operator >= (const t_thisClass& other) const 84 | { 85 | return x >= other.x && y >= other.y && z >= other.z; 86 | } 87 | 88 | bool operator > (const t_thisClass& other) const 89 | { 90 | return x > other.x && y > other.y && z > other.z; 91 | } 92 | 93 | t_thisClass operator * (const t_thisClass& other) const 94 | { 95 | return t_thisClass(other.x*x, other.y*y, other.z*z); 96 | } 97 | 98 | t_thisClass operator * (const int32& other) const 99 | { 100 | return t_thisClass(other*x, other*y, other*z); 101 | } 102 | 103 | t_thisClass operator + (const t_thisClass& other) const 104 | { 105 | return t_thisClass(other.x+x, other.y+y, other.z+z); 106 | } 107 | 108 | t_thisClass operator - (const t_thisClass& other) const 109 | { 110 | return t_thisClass(x-other.x, y-other.y, z-other.z); 111 | } 112 | 113 | t_thisClass operator - (void) const 114 | { 115 | return t_thisClass(-x, -y, -z); 116 | } 117 | 118 | t_thisClass operator / (const t_thisClass& other) const 119 | { 120 | return t_thisClass(x/other.x, y/other.y, z/other.z); 121 | } 122 | 123 | t_thisClass operator / (const t_valueType& other) const 124 | { 125 | return t_thisClass(x/other, y/other, z/other); 126 | } 127 | 128 | t_thisClass operator % (const t_thisClass& other) const 129 | { 130 | return t_thisClass(x % other.x, y % other.y, z % other.z); 131 | } 132 | 133 | t_thisClass operator % (const t_valueType& other) const 134 | { 135 | return t_thisClass(x % other, y % other, z % other); 136 | } 137 | 138 | valueType operator [] (const blub::uint8& index) const 139 | { 140 | BASSERT(index < 3); 141 | return *((&x) + index); 142 | } 143 | 144 | t_thisClass getMinimum(const t_thisClass& other) 145 | { 146 | return t_thisClass(math::min(other.x, x), math::min(other.y, y), math::min(other.z, z)); 147 | } 148 | 149 | t_thisClass getMaximum(const t_thisClass& other) 150 | { 151 | return t_thisClass(math::max(other.x, x), math::max(other.y, y), math::max(other.z, z)); 152 | } 153 | 154 | 155 | private: 156 | BLUB_SERIALIZATION_ACCESS 157 | 158 | template 159 | void serialize(formatType & readWrite, const uint32& version) 160 | { 161 | (void)version; 162 | 163 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(x); 164 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(y); 165 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(z); 166 | } 167 | 168 | 169 | public: 170 | valueType x; 171 | valueType y; 172 | valueType z; 173 | }; 174 | 175 | 176 | template 177 | std::ostream &operator<<(std::ostream &os, const vector3Template& toCast) 178 | { 179 | return os << "(" << toCast.x << "," << toCast.y << "," << toCast.z << ")"; 180 | } 181 | 182 | template 183 | std::size_t hash_value(const vector3Template& value) 184 | { 185 | std::size_t result(value.x); 186 | boost::hash_combine(result, value.y); 187 | boost::hash_combine(result, value.z); 188 | 189 | return result; 190 | } 191 | 192 | 193 | } 194 | 195 | 196 | #endif // BLUB_MATH_VECTOR3TEMPLATE_HPP 197 | -------------------------------------------------------------------------------- /modules/math/source/blub/math/vector3int32map.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR3INT32MAP_HPP 2 | #define VECTOR3INT32MAP_HPP 3 | 4 | #include "blub/math/axisAlignedBoxInt32.hpp" 5 | #include "blub/core/noncopyable.hpp" 6 | 7 | 8 | namespace blub 9 | { 10 | 11 | template 12 | class vector3int32map : public noncopyable 13 | { 14 | public: 15 | vector3int32map() 16 | : m_data(nullptr) 17 | { 18 | ; 19 | } 20 | 21 | ~vector3int32map() 22 | { 23 | if (m_data != nullptr) 24 | { 25 | delete [] m_data; 26 | } 27 | } 28 | 29 | void setValue(const vector3int32& pos, const dataType& toSet) 30 | { 31 | const int32 index(convertToIndex(pos)); 32 | BASSERT(index < m_bounds.getVolume()); 33 | m_data[index] = toSet; 34 | } 35 | const dataType& getValue(const vector3int32& pos) const 36 | { 37 | const int32 index(convertToIndex(pos)); 38 | return m_data[index]; 39 | } 40 | 41 | 42 | void resize(const axisAlignedBoxInt32& aabb) 43 | { 44 | axisAlignedBoxInt32 resizedAabb(m_bounds); 45 | resizedAabb.extend(aabb); 46 | if (resizedAabb == m_bounds) 47 | { 48 | return; 49 | } 50 | const axisAlignedBoxInt32 oldBounds(m_bounds); 51 | const vector3int32 oldStart(oldBounds.getMinimum()); 52 | const vector3int32 oldEnd(oldBounds.getMaximum()); 53 | const dataType* oldData(m_data); 54 | 55 | m_bounds = resizedAabb; 56 | BASSERT(m_bounds.getVolume() > 0); 57 | m_data = new dataType[m_bounds.getVolume()]; 58 | 59 | if (oldData != nullptr) 60 | { 61 | for (int32 indX = oldStart.x; indX < oldEnd.x; ++indX) 62 | { 63 | for (int32 indY = oldStart.y; indY < oldEnd.y; ++indY) 64 | { 65 | for (int32 indZ = oldStart.z; indZ < oldEnd.z; ++indZ) 66 | { 67 | m_data[convertToIndex(vector3int32(indX, indY, indZ))] = oldData[convertToIndex(vector3int32(indX, indY, indZ), oldBounds)]; 68 | } 69 | } 70 | } 71 | delete [] oldData; 72 | } 73 | } 74 | 75 | void extend(const vector3int32& toExtend) 76 | { 77 | axisAlignedBoxInt32 resizedAabb(m_bounds); 78 | resizedAabb.extend(toExtend); 79 | resize(resizedAabb); 80 | } 81 | void extend(const axisAlignedBoxInt32 &toExtend) 82 | { 83 | axisAlignedBoxInt32 resizedAabb(m_bounds); 84 | resizedAabb.extend(toExtend); 85 | resize(resizedAabb); 86 | } 87 | 88 | const axisAlignedBoxInt32& getBounds(void) const 89 | { 90 | return m_bounds; 91 | } 92 | 93 | protected: 94 | 95 | int32 convertToIndex(const vector3int32& toConvert) const 96 | { 97 | return convertToIndex(toConvert, m_bounds); 98 | } 99 | static int32 convertToIndex(const vector3int32& toConvert, const axisAlignedBoxInt32& bounds) 100 | { 101 | BASSERT(toConvert >= bounds.getMinimum()); 102 | BASSERT(toConvert < bounds.getMaximum()); 103 | 104 | const vector3int32 size(bounds.getSize()); 105 | const vector3int32 min(bounds.getMinimum()); 106 | return (toConvert.x-min.x)*size.y*size.z + (toConvert.y-min.y)*size.z + (toConvert.z-min.z); 107 | } 108 | 109 | dataType *m_data; 110 | axisAlignedBoxInt32 m_bounds; 111 | 112 | 113 | }; 114 | 115 | } 116 | 117 | 118 | #endif // VECTOR3INT32MAP_HPP 119 | -------------------------------------------------------------------------------- /modules/procedural/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(sources 3 | log/global.cpp 4 | ) 5 | 6 | set(headers 7 | predecl.hpp 8 | log/global.hpp 9 | voxel/config.hpp 10 | voxel/data.hpp 11 | voxel/vertex.hpp 12 | voxel/edit/axisAlignedBox.hpp 13 | voxel/edit/base.hpp 14 | voxel/edit/box.hpp 15 | voxel/edit/mesh.hpp 16 | voxel/edit/noise.hpp 17 | voxel/edit/sphere.hpp 18 | voxel/terrain/base.hpp 19 | voxel/terrain/accessor.hpp 20 | voxel/terrain/surface.hpp 21 | voxel/terrain/renderer.hpp 22 | voxel/simple/base.hpp 23 | voxel/simple/container/base.hpp 24 | voxel/simple/container/database.hpp 25 | voxel/simple/container/inMemory.hpp 26 | voxel/simple/container/utils/tile.hpp 27 | voxel/simple/accessor.hpp 28 | voxel/simple/surface.hpp 29 | voxel/simple/renderer.hpp 30 | voxel/tile/internal/transvoxelTables.hpp 31 | voxel/tile/accessor.hpp 32 | voxel/tile/base.hpp 33 | voxel/tile/surface.hpp 34 | voxel/tile/container.hpp 35 | voxel/tile/renderer.hpp 36 | ) 37 | 38 | add_module(procedural) 39 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/log/global.cpp: -------------------------------------------------------------------------------- 1 | #include "global.hpp" 2 | 3 | #include "blub/core/string.hpp" 4 | 5 | 6 | using namespace blub::procedural::log; 7 | using namespace blub; 8 | 9 | 10 | BLUB_LOG_GLOBAL_LOGGER_INIT(global, blub::log::logger) 11 | { 12 | blub::log::logger result("procedural"); 13 | return result; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/log/global.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_LOG_GLOBAL_HPP 2 | #define BLUB_PROCEDURAL_LOG_GLOBAL_HPP 3 | 4 | #include "blub/log/global.hpp" 5 | #include "blub/log/globalLogger.hpp" 6 | #include "blub/log/logger.hpp" 7 | #include "blub/log/predecl.hpp" 8 | 9 | 10 | namespace blub 11 | { 12 | namespace procedural 13 | { 14 | namespace log 15 | { 16 | BLUB_LOG_GLOBAL_LOGGER(global, blub::log::logger) 17 | } 18 | } 19 | } 20 | 21 | 22 | #define BLUB_PROCEDURAL_LOG_OUT() BLUB_LOG_OUT_TO(blub::procedural::log::global::get()) 23 | #define BLUB_PROCEDURAL_LOG_WARNING() BLUB_LOG_WARNING_TO(blub::procedural::log::global::get()) 24 | #define BLUB_PROCEDURAL_LOG_ERROR() BLUB_LOG_ERROR_TO(blub::procedural::log::global::get()) 25 | 26 | 27 | #endif // BLUB_PROCEDURAL_LOG_GLOBAL_HPP 28 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/predecl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_PREDECL_HPP 2 | #define BLUB_PROCEDURAL_PREDECL_HPP 3 | 4 | 5 | namespace blub 6 | { 7 | namespace procedural 8 | { 9 | namespace voxel 10 | { 11 | class config; 12 | class data; 13 | struct vertex; 14 | namespace tile 15 | { 16 | template 17 | class base; 18 | template 19 | class container; 20 | template 21 | class accessor; 22 | template 23 | class renderer; 24 | template 25 | class surface; 26 | } 27 | namespace simple 28 | { 29 | template 30 | class base; 31 | namespace container 32 | { 33 | namespace utils 34 | { 35 | template 36 | class database; 37 | enum class tileState; 38 | template 39 | class tile; 40 | } 41 | template 42 | class base; 43 | template 44 | class inMemory; 45 | template 46 | class database; 47 | } 48 | template 49 | class accessor; 50 | template 51 | class renderer; 52 | template 53 | class surface; 54 | } 55 | namespace terrain 56 | { 57 | template 58 | class base; 59 | template 60 | class accessor; 61 | template 62 | class renderer; 63 | template 64 | class surface; 65 | } 66 | namespace edit 67 | { 68 | template 69 | class axisAlignedBox; 70 | template 71 | class base; 72 | template 73 | class box; 74 | template 75 | class mesh; 76 | template 77 | class noise; 78 | template 79 | class sphere; 80 | } 81 | } 82 | } 83 | } 84 | 85 | 86 | #endif // BLUB_PROCEDURAL_PREDECL_HPP 87 | 88 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/config.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_VOXEL_CONFIG 2 | #define BLUB_PROCEDURAL_VOXEL_CONFIG 3 | 4 | #include "blub/procedural/predecl.hpp" 5 | #include "blub/procedural/voxel/data.hpp" 6 | #include "blub/procedural/voxel/vertex.hpp" 7 | 8 | 9 | namespace blub 10 | { 11 | namespace procedural 12 | { 13 | namespace voxel 14 | { 15 | 16 | 17 | class config 18 | { 19 | public: 20 | typedef config t_config; 21 | 22 | typedef data t_data; 23 | typedef uint16 t_index; 24 | typedef vertex t_vertex; 25 | 26 | static const int32 voxelsPerTile = 20; // means 20^3! 27 | 28 | template 29 | struct container 30 | { 31 | typedef voxel::simple::container::inMemory t_simple; 32 | typedef voxel::tile::container t_tile; 33 | }; 34 | typedef container t_container; 35 | 36 | template 37 | struct accessor 38 | { 39 | typedef voxel::simple::accessor t_simple; 40 | typedef voxel::terrain::accessor t_terrain; 41 | typedef voxel::tile::accessor t_tile; 42 | }; 43 | 44 | typedef accessor t_accessor; 45 | 46 | template 47 | struct surface 48 | { 49 | typedef voxel::simple::surface t_simple; 50 | typedef voxel::terrain::surface t_terrain; 51 | typedef voxel::tile::surface t_tile; 52 | }; 53 | typedef surface t_surface; 54 | 55 | template 56 | struct renderer 57 | { 58 | typedef voxel::simple::renderer t_simple; 59 | typedef voxel::terrain::renderer t_terrain; 60 | typedef voxel::tile::renderer t_tile; 61 | }; 62 | typedef renderer t_renderer; 63 | }; 64 | 65 | 66 | } 67 | } 68 | } 69 | 70 | 71 | #endif // BLUB_PROCEDURAL_VOXEL_CONFIG 72 | 73 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/data.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_VOXEL_DATA_HPP 2 | #define BLUB_PROCEDURAL_VOXEL_DATA_HPP 3 | 4 | #include "blub/core/classVersion.hpp" 5 | #include "blub/core/globals.hpp" 6 | #include "blub/serialization/access.hpp" 7 | #include "blub/serialization/nameValuePair.hpp" 8 | 9 | 10 | namespace blub 11 | { 12 | namespace procedural 13 | { 14 | namespace voxel 15 | { 16 | 17 | 18 | /** 19 | * @brief The data class is the default voxel. 20 | * Contains an 8-bit interpolation value. 21 | * Replace/derive it and set it tho the voxel classes by template. 22 | * Watchout when you reimplement a isMax() and isMin(). 23 | * voxel-container doesnt save these voxel for memory-optimisation. 24 | * Only return true on isMax() / isMin() if your are able to restore the state by setMin() / setMax(). 25 | * setMin() has to to have the same results like the default contructor. 26 | */ 27 | class data 28 | { 29 | public: 30 | /** 31 | * @brief data constructor 32 | */ 33 | data() 34 | : interpolation(-127) 35 | { 36 | ; 37 | } 38 | /** 39 | * @brief operator == compares interpolation. 40 | * @param other 41 | * @return 42 | */ 43 | bool operator ==(const data& other) const 44 | { 45 | return other.interpolation == interpolation; 46 | } 47 | /** 48 | * @brief operator != compares interpolation. 49 | * @param other 50 | * @return 51 | */ 52 | bool operator !=(const data& other) const 53 | { 54 | return other.interpolation != interpolation; 55 | } 56 | 57 | /** 58 | * @brief setInterpolation sets interpolation 59 | * @param toSet 60 | */ 61 | void setInterpolation(const int8 &toSet) 62 | { 63 | interpolation = toSet; 64 | } 65 | 66 | /** 67 | * @brief getInterpolation returns reference to interpolation. 68 | * @return 69 | */ 70 | int8 &getInterpolation() 71 | { 72 | return interpolation; 73 | } 74 | 75 | /** 76 | * @brief getInterpolation returns const reference to interpolation. 77 | * @return 78 | */ 79 | const int8 &getInterpolation() const 80 | { 81 | return interpolation; 82 | } 83 | 84 | /** 85 | * @brief isMax checks if all values are maximum. See class description. 86 | * @return 87 | */ 88 | bool isMax() const 89 | { 90 | return interpolation >= 127; 91 | } 92 | 93 | /** 94 | * @brief isMin checks if all values are minimum. See class description. 95 | * @return 96 | */ 97 | bool isMin() const 98 | { 99 | return interpolation <= -127; 100 | } 101 | 102 | /** 103 | * @brief setMin sets all values to minimum. See class description. 104 | */ 105 | void setMin() 106 | { 107 | setInterpolationMin(); 108 | } 109 | 110 | /** 111 | * @brief setMax sets all values to maximum. See class description. 112 | */ 113 | void setMax() 114 | { 115 | setInterpolationMax(); 116 | } 117 | 118 | /** 119 | * @brief setInterpolationMin sets the interpolation to minimum. 120 | */ 121 | void setInterpolationMin() 122 | { 123 | interpolation = -127; 124 | } 125 | 126 | /** 127 | * @brief setInterpolationMax set interpolation to maximum. 128 | */ 129 | void setInterpolationMax() 130 | { 131 | interpolation = 127; 132 | } 133 | 134 | private: 135 | BLUB_SERIALIZATION_ACCESS 136 | 137 | template 138 | void serialize(formatType & readWrite, const uint32& version) 139 | { 140 | using namespace serialization; 141 | 142 | (void)version; 143 | 144 | readWrite & BLUB_SERIALIZATION_NAMEVALUEPAIR(interpolation); 145 | } 146 | 147 | 148 | protected: 149 | /** 150 | * @brief interpolation signed 8-bit interpolation value default used by voxel::tile::surface 151 | */ 152 | int8 interpolation; 153 | 154 | 155 | }; 156 | 157 | 158 | } 159 | } 160 | } 161 | 162 | 163 | #endif // BLUB_PROCEDURAL_VOXEL_DATA_HPP 164 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/edit/axisAlignedBox.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PROCEDURAL_VOXEL_EDIT_AXISALIGNEDBOX_HPP 2 | #define PROCEDURAL_VOXEL_EDIT_AXISALIGNEDBOX_HPP 3 | 4 | 5 | #include "blub/math/axisAlignedBox.hpp" 6 | #include "blub/procedural/voxel/edit/base.hpp" 7 | 8 | 9 | namespace blub 10 | { 11 | namespace procedural 12 | { 13 | namespace voxel 14 | { 15 | namespace edit 16 | { 17 | 18 | 19 | /** 20 | * @brief insertes/removes voxels that are included in an blub::axisAlignedBox. 21 | * Always axis-aligned - use box if you want to rotate. 22 | */ 23 | template 24 | class axisAlignedBox : public base 25 | { 26 | public: 27 | typedef configType t_config; 28 | typedef base t_base; 29 | typedef sharedPointer pointer; 30 | typedef typename t_config::t_data t_voxel; 31 | 32 | /** 33 | * @brief Allocates an instance and initialises the class 34 | * @param desc The axis-aligend-box that describes the to create voxel. desc must be a valid blub::axisAlignedBox. 35 | * @return Returns an initialised instance 36 | */ 37 | static pointer create(const ::blub::axisAlignedBox& desc) 38 | { 39 | return pointer(new axisAlignedBox(desc)); 40 | } 41 | /** 42 | * @brief Destructor 43 | */ 44 | virtual ~axisAlignedBox() 45 | { 46 | ; 47 | } 48 | 49 | /** 50 | * @brief Changes the voxel-describing bounding-box. DON'T change it while class is generating voxel. 51 | * Else incorrect and incosinstent voxel will get created. 52 | * @param desc The Voxel descriptor. 53 | */ 54 | void setAxisAlignedBox(const ::blub::axisAlignedBox& desc) 55 | { 56 | m_aab = desc; 57 | } 58 | /** 59 | * @brief Returns the describing blub::axisAlignedBox set by constructor or by setAxisAlignedBox(). 60 | * @return Returns the describing blub::axisAlignedBox 61 | */ 62 | const ::blub::axisAlignedBox& getAxisAlignedBox() const 63 | { 64 | return m_aab; 65 | } 66 | 67 | protected: 68 | /** 69 | * @brief returns the bounding box describing the voxel to be recalculated 70 | * @param trans describes the tranformation the edit uses 71 | */ 72 | blub::axisAlignedBox getAxisAlignedBoundingBox(const transform& trans) const override 73 | { 74 | return blub::axisAlignedBox(m_aab.getMinimum()*trans.scale + trans.position, 75 | m_aab.getMaximum()*trans.scale + trans.position); 76 | } 77 | 78 | /** 79 | * @brief checks if voxel is inside aab 80 | * @param pos describes the voxel-position 81 | * @param resultVoxel if pos is inside, resultVoxel interpolation gets set to maximum. Must not be nullptr 82 | * @return true if pos is inside. 83 | */ 84 | bool calculateOneVoxel(const vector3& pos, t_voxel* resultVoxel) const override 85 | { 86 | if (m_aab.contains(pos)) 87 | { 88 | resultVoxel->setInterpolationMax(); 89 | return true; 90 | } 91 | else 92 | { 93 | return false; 94 | } 95 | } 96 | 97 | private: 98 | /** 99 | * @brief see create() 100 | */ 101 | axisAlignedBox(const ::blub::axisAlignedBox& desc) 102 | : m_aab(desc) 103 | { 104 | ; 105 | } 106 | 107 | private: 108 | ::blub::axisAlignedBox m_aab; 109 | 110 | 111 | }; 112 | 113 | 114 | } 115 | } 116 | } 117 | } 118 | 119 | 120 | #endif // PROCEDURAL_VOXEL_EDIT_AXISALIGNEDBOX_HPP 121 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/edit/sphere.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_VOXEL_EDIT_SPHERE_HPP 2 | #define BLUB_PROCEDURAL_VOXEL_EDIT_SPHERE_HPP 3 | 4 | 5 | // #include "blub/log/global.hpp" 6 | #include "blub/math/axisAlignedBox.hpp" 7 | #include "blub/math/math.hpp" 8 | #include "blub/math/sphere.hpp" 9 | #include "blub/math/transform.hpp" 10 | #include "blub/procedural/voxel/edit/base.hpp" 11 | 12 | 13 | namespace blub 14 | { 15 | namespace procedural 16 | { 17 | namespace voxel 18 | { 19 | namespace edit 20 | { 21 | 22 | 23 | /** 24 | * @brief The sphere class creates an interpolated voxel-sphere 25 | */ 26 | template 27 | class sphere : public base 28 | { 29 | public: 30 | typedef configType t_config; 31 | typedef base t_base; 32 | typedef sharedPointer > pointer; 33 | typedef typename t_config::t_data t_voxel; 34 | 35 | /** 36 | * @brief creates an instance 37 | * @param desc Describes the voxels to create 38 | * @return an instance of sphere as shared_ptr 39 | */ 40 | static pointer create(const ::blub::sphere& desc) 41 | { 42 | return pointer(new sphere(desc)); 43 | } 44 | 45 | /** 46 | * @brief setSphere sets the describing sphere. Dont set it while caluculating voxel. 47 | * @param desc 48 | */ 49 | void setSphere(const ::blub::sphere& desc) 50 | { 51 | m_sphere = desc; 52 | } 53 | /** 54 | * @brief getSphere 55 | * @return Returns the describing sphere 56 | */ 57 | const ::blub::sphere& getSphere() const 58 | { 59 | return m_sphere; 60 | } 61 | 62 | /** 63 | * @brief getAxisAlignedBoundingBox returns the transformed aab that includes the sphere. 64 | * @param trans Transform. 65 | * @return 66 | */ 67 | blub::axisAlignedBox getAxisAlignedBoundingBox(const blub::transform &trans) const override 68 | { 69 | const blub::axisAlignedBox aabb(m_sphere.getCenter() - blub::vector3(m_sphere.getRadius()), 70 | m_sphere.getCenter() + blub::vector3(m_sphere.getRadius())); 71 | return blub::axisAlignedBox(aabb.getMinimum()*trans.scale + trans.position, 72 | aabb.getMaximum()*trans.scale + trans.position); 73 | } 74 | 75 | protected: 76 | /** 77 | * @brief calculateOneVoxel calculates on voxel in getAxisAlignedBoundingBox(). 78 | * @param pos absolute voxel position. 79 | * @param resultVoxel interpolation gets set if inside sphere. 80 | * @return true if voxel is inside sphere-radius+1. +1 because of interpolation. 81 | */ 82 | bool calculateOneVoxel(const vector3& pos, t_voxel* resultVoxel) const override 83 | { 84 | const blub::real &squaredDist(pos.squaredDistance(m_sphere.getCenter())); 85 | const blub::real &radius(m_sphere.getRadius()); 86 | if (squaredDist < (radius+1.)*(radius+1.)) 87 | { 88 | if (squaredDist < (radius-1.)*(radius-1.)) 89 | { 90 | resultVoxel->setInterpolationMax(); 91 | } 92 | else 93 | { 94 | const blub::real &result(blub::math::clamp((radius-blub::math::sqrt(squaredDist))*127., -127., 127.)); 95 | resultVoxel->setInterpolation(static_cast(result)); 96 | } 97 | return true; 98 | } 99 | return false; 100 | } 101 | 102 | sphere(const ::blub::sphere& desc) 103 | : m_sphere(desc) 104 | { 105 | } 106 | 107 | protected: 108 | ::blub::sphere m_sphere; 109 | 110 | }; 111 | 112 | 113 | } 114 | } 115 | } 116 | } 117 | 118 | 119 | #endif // VOXEL_EDIT_SPHERE_HPP 120 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/simple/container/base.cpp: -------------------------------------------------------------------------------- 1 | #include "base.hpp" 2 | 3 | #include "blub/math/axisAlignedBox.hpp" 4 | #include "blub/procedural/voxel/edit/base.hpp" 5 | #include "blub/procedural/voxel/tile/container.hpp" 6 | 7 | 8 | using namespace blub::procedural::voxel::simple::container; 9 | using namespace blub::procedural::voxel; 10 | using namespace blub; 11 | 12 | 13 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/simple/container/inMemory.cpp: -------------------------------------------------------------------------------- 1 | #include "inMemory.hpp" 2 | 3 | #include "blub/math/axisAlignedBox.hpp" 4 | #include "blub/math/axisAlignedBoxInt32.hpp" 5 | #include "blub/core/log.hpp" 6 | #include "blub/async/dispatcher.hpp" 7 | #include "blub/math/transform.hpp" 8 | #include "blub/math/vector3int32.hpp" 9 | #include "blub/procedural/voxel/tile/container.hpp" 10 | #include "blub/procedural/voxel/edit/base.hpp" 11 | 12 | 13 | using namespace blub::procedural::voxel::simple::container; 14 | using namespace blub::procedural::voxel; 15 | 16 | 17 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/simple/container/utils/tile.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TILEHOLDER_HPP 2 | #define TILEHOLDER_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/core/sharedPointer.hpp" 6 | #include "blub/procedural/predecl.hpp" 7 | 8 | 9 | namespace blub 10 | { 11 | namespace procedural 12 | { 13 | namespace voxel 14 | { 15 | namespace simple 16 | { 17 | namespace container 18 | { 19 | namespace utils 20 | { 21 | 22 | 23 | /** 24 | * @brief The tileState enum defines opitimized states for a tile. 25 | */ 26 | enum class tileState 27 | { 28 | full, 29 | empty, 30 | partitial 31 | }; 32 | 33 | 34 | /** 35 | * @brief The tile class contains a state and the data itself. For memory optimization no data gets saved if state is full or empty 36 | */ 37 | template 38 | class tile 39 | { 40 | public: 41 | typedef sharedPointer t_tilePtr; 42 | 43 | tile() 44 | : state(tileState::empty) 45 | { 46 | ; 47 | } 48 | tile(const tileState& state_) 49 | : state(state_) 50 | { 51 | ; 52 | } 53 | 54 | tileState state; 55 | t_tilePtr data; 56 | }; 57 | 58 | 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | 66 | 67 | #endif // TILEHOLDER_HPP 68 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/terrain/accessor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PROCEDURAL_VOXEL_TERRAIN_ACCESSOR_HPP 2 | #define PROCEDURAL_VOXEL_TERRAIN_ACCESSOR_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/core/vector.hpp" 6 | #include "blub/procedural/voxel/terrain/base.hpp" 7 | 8 | 9 | namespace blub 10 | { 11 | namespace procedural 12 | { 13 | namespace voxel 14 | { 15 | namespace terrain 16 | { 17 | 18 | 19 | /** 20 | * @brief The accessor class contains a custom amount of level of details of type simple::accessor. 21 | * 22 | */ 23 | template 24 | class accessor : public base 25 | { 26 | public: 27 | typedef configType t_config; 28 | typedef typename t_config::t_accessor::t_simple t_simple; 29 | typedef base t_base; 30 | 31 | typedef typename t_config::t_container::t_simple t_simpleContainer; 32 | 33 | /** 34 | * @brief accessor constructor 35 | * @param worker May get called by multiple threads. 36 | * @param voxels The voxel-container to get the data from and to sync with. 37 | * @param numLod Count of level of details. 38 | */ 39 | accessor(blub::async::dispatcher &worker, 40 | t_simpleContainer &voxels, 41 | const uint32& numLod) 42 | : m_voxels(voxels) 43 | { 44 | for (uint32 indLod = 0; indLod < numLod; ++indLod) 45 | { 46 | t_simple* lod = new t_simple(worker, voxels, indLod); 47 | t_base::m_lods.emplace_back(lod); 48 | } 49 | } 50 | 51 | /** 52 | * @brief ~accessor destructor 53 | */ 54 | ~accessor() 55 | { 56 | } 57 | 58 | /** 59 | * @brief getVoxelContainer returns the voxel-container to get the data from and to sync with. 60 | * @return 61 | */ 62 | t_simpleContainer &getVoxelContainer() const 63 | { 64 | return m_voxels; 65 | } 66 | 67 | private: 68 | t_simpleContainer &m_voxels; 69 | 70 | }; 71 | 72 | 73 | } 74 | } 75 | } 76 | } 77 | 78 | 79 | #endif // PROCEDURAL_VOXEL_TERRAIN_ACCESSOR_HPP 80 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/terrain/base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PROCEDURAL_VOXEL_TERRAIN_BASE_HPP 2 | #define PROCEDURAL_VOXEL_TERRAIN_BASE_HPP 3 | 4 | #include "blub/async/predecl.hpp" 5 | #include "blub/core/globals.hpp" 6 | #include "blub/core/noncopyable.hpp" 7 | #include "blub/core/scopedPtr.hpp" 8 | #include "blub/core/vector.hpp" 9 | #include "blub/procedural/predecl.hpp" 10 | #include "blub/procedural/voxel/simple/base.hpp" 11 | 12 | #include 13 | 14 | 15 | namespace blub 16 | { 17 | namespace procedural 18 | { 19 | namespace voxel 20 | { 21 | namespace terrain 22 | { 23 | 24 | 25 | /** 26 | * @brief The base class gets derived by every class in the namesapce terrain. 27 | * It holds various level of details, always of type procedural::voxel::simple::base. 28 | */ 29 | template 30 | class base : public noncopyable 31 | { 32 | public: 33 | typedef simpleType t_simple; 34 | typedef t_simple* t_lod; 35 | typedef vector > t_lodList; 36 | typedef typename t_simple::t_createTileCallback t_createTileCallback; 37 | 38 | /** 39 | * @brief base contructor 40 | */ 41 | base(); 42 | /** 43 | * @brief ~base destructor 44 | */ 45 | ~base(); 46 | 47 | /** 48 | * @brief getLod returns a level of detail. 49 | * @param lod Lod-index starting with zero. 50 | * @return 51 | */ 52 | t_lod getLod(const uint16& lod) const; 53 | /** 54 | * @brief getLodList returns all level of details. 55 | * @return 56 | */ 57 | const t_lodList& getLodList() const; 58 | 59 | /** 60 | * @brief getNumLod returns number of level of details. 61 | * @return Never negative. 62 | */ 63 | int32 getNumLod() const; 64 | 65 | /** 66 | * @brief setCreateTileCallback sets the callback for creating tiles to the lods. 67 | * @param toSet 68 | */ 69 | void setCreateTileCallback(const t_createTileCallback &toSet); 70 | 71 | protected: 72 | 73 | 74 | protected: 75 | /** 76 | * @brief m_lods container for the lods. 77 | */ 78 | t_lodList m_lods; 79 | 80 | }; 81 | 82 | template 83 | base::base() 84 | { 85 | ; 86 | } 87 | template 88 | base::~base() 89 | { 90 | ; 91 | } 92 | 93 | template 94 | typename base::t_lod base::getLod(const uint16 &lod) const 95 | { 96 | BASSERT(lod < m_lods.size()); 97 | return m_lods[lod].get(); 98 | } 99 | 100 | template 101 | const typename base::t_lodList& base::getLodList() const 102 | { 103 | return m_lods; 104 | } 105 | 106 | template 107 | int32 base::getNumLod() const 108 | { 109 | return m_lods.size(); 110 | } 111 | 112 | template 113 | void base::setCreateTileCallback(const t_createTileCallback &toSet) 114 | { 115 | for (typename t_lodList::value_type &lod : m_lods) 116 | { 117 | lod->setCreateTileCallback(toSet); 118 | } 119 | } 120 | 121 | 122 | } 123 | } 124 | } 125 | } 126 | 127 | 128 | #endif // PROCEDURAL_VOXEL_TERRAIN_BASE_HPP 129 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/terrain/renderer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_VOXEL_TERRAIN_RENDERER_HPP 2 | #define BLUB_PROCEDURAL_VOXEL_TERRAIN_RENDERER_HPP 3 | 4 | #include "blub/core/vector.hpp" 5 | #include "blub/procedural/voxel/terrain/base.hpp" 6 | 7 | #include 8 | 9 | 10 | namespace blub 11 | { 12 | namespace procedural 13 | { 14 | namespace voxel 15 | { 16 | namespace terrain 17 | { 18 | 19 | 20 | /** 21 | * @brief The renderer class contains a custom count of simple::renderer for level of detail. 22 | */ 23 | template 24 | class renderer : public base 25 | { 26 | public: 27 | typedef configType t_config; 28 | typedef typename t_config::t_renderer::t_simple t_simple; 29 | typedef base t_base; 30 | typedef sharedPointer t_cameraPtr; 31 | 32 | typedef vector t_syncRadiusList; 33 | 34 | typedef typename t_config::t_surface::t_terrain t_rendererSurface; 35 | 36 | 37 | /** 38 | * @brief renderer constructor 39 | * @param worker May get called by several threads. 40 | * @param renderer_ The surface to sync with. 41 | * @param syncRadien The radien of which of every lod should get rendered. 42 | */ 43 | renderer(blub::async::dispatcher &worker, 44 | t_rendererSurface &renderer_, 45 | const t_syncRadiusList& syncRadien) 46 | : m_worker(worker) 47 | , m_terrain(renderer_) 48 | , m_syncRadien(syncRadien) 49 | { 50 | BASSERT(m_terrain.getNumLod() <= (int32)m_syncRadien.size()); 51 | 52 | for (uint32 indLod = 0; indLod < (uint32)m_terrain.getNumLod(); ++indLod) 53 | { 54 | if (indLod == 0) 55 | { 56 | t_base::m_lods.emplace_back(new t_simple(m_worker, m_terrain.getLod(indLod), indLod, 0., syncRadien[0])); 57 | } 58 | else 59 | { 60 | t_base::m_lods.emplace_back(new t_simple(m_worker, m_terrain.getLod(indLod), indLod, syncRadien[indLod-1], syncRadien[indLod])); 61 | } 62 | } 63 | } 64 | 65 | /** 66 | * @brief ~renderer destructor 67 | */ 68 | ~renderer() 69 | { 70 | } 71 | 72 | /** 73 | * @brief addCamera adds an camera. 74 | * @param toAdd Must not be nullptr 75 | * @param position The initial position of the camera. 76 | */ 77 | void addCamera(t_cameraPtr toAdd, const blub::vector3& position) 78 | { 79 | for (uint32 indLod = 0; indLod < t_base::m_lods.size(); ++indLod) 80 | { 81 | t_base::m_lods[indLod]->addCamera(toAdd, position); 82 | } 83 | } 84 | /** 85 | * @brief updateCamera updates the position of a camera you have to add before by using addCamera() 86 | * @param toUpdate The camera, must not be nullptr. 87 | * @param position The new position. 88 | */ 89 | void updateCamera(t_cameraPtr toUpdate, const blub::vector3& position) 90 | { 91 | for (uint32 indLod = 0; indLod < t_base::m_lods.size(); ++indLod) 92 | { 93 | t_base::m_lods[indLod]->updateCamera(toUpdate, position); 94 | } 95 | } 96 | /** 97 | * @brief removeCamera removes a camera. 98 | * @param toRemove Must not be nullptr. 99 | */ 100 | void removeCamera(t_cameraPtr toRemove) 101 | { 102 | for (uint32 indLod = 0; indLod < t_base::m_lods.size(); ++indLod) 103 | { 104 | t_base::m_lods[indLod]->removeCamera(toRemove); 105 | } 106 | } 107 | 108 | protected: 109 | 110 | 111 | private: 112 | blub::async::dispatcher &m_worker; 113 | t_rendererSurface &m_terrain; 114 | 115 | t_syncRadiusList m_syncRadien; 116 | 117 | }; 118 | 119 | 120 | 121 | } 122 | } 123 | } 124 | } 125 | 126 | #endif // BLUB_PROCEDURAL_VOXEL_TERRAIN_RENDERER_HPP 127 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/terrain/surface.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PROCEDURAL_VOXEL_TERRAIN_SURFACE_HPP 2 | #define PROCEDURAL_VOXEL_TERRAIN_SURFACE_HPP 3 | 4 | #include "blub/core/list.hpp" 5 | #include "blub/procedural/voxel/terrain/base.hpp" 6 | 7 | 8 | namespace blub 9 | { 10 | namespace procedural 11 | { 12 | namespace voxel 13 | { 14 | namespace terrain 15 | { 16 | 17 | 18 | /** 19 | * @brief The surface class contains a custom count of simple::surface for level of detail. 20 | */ 21 | template 22 | class surface : public base 23 | { 24 | public: 25 | typedef configType t_config; 26 | typedef typename t_config::t_surface::t_simple t_simple; 27 | typedef t_simple t_lod; 28 | typedef t_lod* t_lodPtr; 29 | typedef base t_base; 30 | 31 | typedef typename t_config::t_accessor::t_terrain t_terrainAccessor; 32 | 33 | 34 | /** 35 | * @brief surface construtor. Creates as much lods as in voxels. 36 | * @param worker may get called by multiple threads. 37 | * @param voxels The accessor to sync with. 38 | */ 39 | surface(blub::async::dispatcher &worker, t_terrainAccessor &voxels) 40 | { 41 | for (int32 lod = 0; lod < voxels.getNumLod(); ++lod) 42 | { 43 | typename t_terrainAccessor::t_lod accessorTiles(voxels.getLod(lod)); 44 | t_lodPtr newLod(new t_lod(worker, *accessorTiles, lod)); 45 | 46 | t_base::m_lods.emplace_back(newLod); 47 | } 48 | } 49 | 50 | /** 51 | * @brief ~surface destrcutor 52 | */ 53 | ~surface() 54 | { 55 | } 56 | 57 | private: 58 | 59 | 60 | }; 61 | 62 | 63 | } 64 | } 65 | } 66 | } 67 | 68 | 69 | #endif // PROCEDURAL_VOXEL_TERRAIN_SURFACE_HPP 70 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/tile/base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_VOXEL_TILE_BASE_HPP 2 | #define BLUB_PROCEDURAL_VOXEL_TILE_BASE_HPP 3 | 4 | 5 | #include "blub/core/enableSharedFromThis.hpp" 6 | #include "blub/core/globals.hpp" 7 | #include "blub/core/noncopyable.hpp" 8 | #include "blub/core/sharedPointer.hpp" 9 | #include "blub/procedural/predecl.hpp" 10 | 11 | 12 | namespace blub 13 | { 14 | namespace procedural 15 | { 16 | namespace voxel 17 | { 18 | namespace tile 19 | { 20 | 21 | 22 | /** 23 | * @brief The base class gets derived by every class in the namespace tile::*. 24 | * Never instance this class and derived classes without a shared pointer. 25 | */ 26 | template 27 | class base : public enableSharedFromThis//, public noncopyable 28 | { 29 | public: 30 | typedef sharedPointer pointer; 31 | 32 | protected: 33 | /** 34 | * @brief base constrcutor. 35 | */ 36 | base() 37 | { 38 | 39 | } 40 | }; 41 | 42 | 43 | } 44 | } 45 | } 46 | } 47 | 48 | 49 | 50 | #endif // BLUB_PROCEDURAL_VOXEL_TILE_BASE_HPP 51 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/tile/renderer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_VOXEL_TILE_RENDERER_HPP 2 | #define BLUB_PROCEDURAL_VOXEL_TILE_RENDERER_HPP 3 | 4 | #include "blub/math/vector3int.hpp" 5 | #include "blub/procedural/voxel/tile/base.hpp" 6 | 7 | 8 | namespace blub 9 | { 10 | namespace procedural 11 | { 12 | namespace voxel 13 | { 14 | namespace tile 15 | { 16 | 17 | 18 | /** 19 | * @brief The renderer class contains information if a tile::surface should get rendered and how it should get rendered. 20 | * Class must get derived by your render-engine. In the derived class convert the vertices/indices to your hardware/software render engine. (Most likely to a hardwarebuffer) 21 | */ 22 | template 23 | class renderer : public base > 24 | { 25 | public: 26 | typedef configType t_config; 27 | typedef base > t_base; 28 | typedef typename t_config::t_renderer::t_tile* t_thiz; 29 | typedef typename t_config::t_surface::t_tile t_tileData; 30 | typedef blub::sharedPointer t_tileDataPtr; 31 | 32 | /** 33 | * @brief ~renderer destructor 34 | */ 35 | ~renderer() 36 | { 37 | ; 38 | } 39 | 40 | /** 41 | * @brief Implement this method and cast the data to your graphic engine. 42 | * @param convertToRenderAble Contains vertices and indices. 43 | * @param aabb The axisAlignedBox that describes the bound of the vertices. 44 | */ 45 | void setTileData(t_tileDataPtr convertToRenderAble, const axisAlignedBox &aabb) {;} 46 | 47 | /** 48 | * @brief setVisible sets if a tile should get rendered. All lod-submeshes must not be rendered either. 49 | * @param vis true for visible. 50 | */ 51 | virtual void setVisible(const bool& vis) 52 | { 53 | m_shouldBeVisible = vis; 54 | } 55 | 56 | /** 57 | * @brief setVisibleLod sets if one of the 6 crack closing submeshes (for lod) should get rendered. 58 | * @param indLod 0 to 6 59 | * @param vis 60 | */ 61 | virtual void setVisibleLod(const uint16& indLod, const bool& vis) 62 | { 63 | m_lodShouldBeVisible[indLod] = vis; 64 | } 65 | 66 | /** 67 | * @brief getVisible returns if a tile should get rendered. 68 | * @return 69 | */ 70 | const bool &getVisible() const 71 | { 72 | return m_shouldBeVisible; 73 | } 74 | 75 | /** 76 | * @brief getVisibleLod returns if a crack-closing lod-tile should get rendered. 77 | * @param indLod 78 | * @return 79 | */ 80 | const bool &getVisibleLod(const uint16& indLod) 81 | { 82 | return m_lodShouldBeVisible[indLod]; 83 | } 84 | 85 | protected: 86 | /** 87 | * @brief renderer constructor. 88 | */ 89 | renderer() 90 | : m_shouldBeVisible(false) 91 | { 92 | for (int32 ind = 0; ind < 6; ++ind) 93 | { 94 | m_lodShouldBeVisible[ind] = false; 95 | } 96 | } 97 | 98 | 99 | protected: 100 | /** 101 | * @brief m_shouldBeVisible saves if tile should get rendered. 102 | */ 103 | bool m_shouldBeVisible; 104 | /** 105 | * @brief saves if crack closing submesh should get rendered. 106 | */ 107 | bool m_lodShouldBeVisible[6]; 108 | 109 | 110 | }; 111 | 112 | 113 | } 114 | } 115 | } 116 | } 117 | 118 | #endif // BLUB_PROCEDURAL_VOXEL_TILE_RENDERER_HPP 119 | -------------------------------------------------------------------------------- /modules/procedural/source/blub/procedural/voxel/vertex.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_PROCEDURAL_VOXEL_VERTEX 2 | #define BLUB_PROCEDURAL_VOXEL_VERTEX 3 | 4 | #include "blub/math/vector3.hpp" 5 | 6 | 7 | namespace blub 8 | { 9 | namespace procedural 10 | { 11 | namespace voxel 12 | { 13 | 14 | 15 | struct vertex 16 | { 17 | vector3 position; 18 | vector3 normal; 19 | }; 20 | 21 | 22 | } 23 | } 24 | } 25 | 26 | 27 | #endif // BLUB_PROCEDURAL_VOXEL_VERTEX 28 | 29 | -------------------------------------------------------------------------------- /modules/serialization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(sources 3 | log/global.cpp 4 | ) 5 | 6 | set(headers 7 | log/global.hpp 8 | predecl.hpp 9 | saveLoad.hpp 10 | access.hpp 11 | callBaseObject.hpp 12 | nameValuePair.hpp 13 | format/text/output.hpp 14 | format/text/input.hpp 15 | format/xml/output.hpp 16 | format/xml/input.hpp 17 | ) 18 | 19 | set (modules_to_link log) 20 | add_module(serialization) 21 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/access.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATION_ACCESS_HPP 2 | #define SERIALIZATION_ACCESS_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | namespace serialization 12 | { 13 | 14 | 15 | // typedef boost::serialization::access access; 16 | #define BLUB_SERIALIZATION_ACCESS friend class boost::serialization::access; 17 | 18 | 19 | } 20 | } 21 | 22 | 23 | #endif // SERIALIZATION_ACCESS_HPP 24 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/callBaseObject.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATION_CALLBASEOBJECT_HPP 2 | #define SERIALIZATION_CALLBASEOBJECT_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | namespace serialization 12 | { 13 | 14 | 15 | #if defined(__BORLANDC__) && __BORLANDC__ < 0x610 16 | #error compiler not supported 17 | #else 18 | template 19 | BOOST_DEDUCED_TYPENAME boost::serialization::detail::base_cast::type & 20 | callBaseObject(Derived &d) 21 | { 22 | return boost::serialization::base_object(d); 23 | } 24 | #endif 25 | 26 | 27 | } 28 | } 29 | 30 | 31 | 32 | 33 | #endif // SERIALIZATION_CALLBASEOBJECT_HPP 34 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/format/text/input.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATION_FORMAT_TEXT_INPUT_HPP 2 | #define SERIALIZATION_FORMAT_TEXT_INPUT_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | namespace serialization 12 | { 13 | namespace format 14 | { 15 | namespace text 16 | { 17 | 18 | 19 | typedef boost::archive::text_iarchive input; 20 | 21 | 22 | } 23 | } 24 | } 25 | } 26 | 27 | 28 | #endif // SERIALIZATION_FORMAT_TEXT_INPUT_HPP 29 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/format/text/output.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATION_FORMAT_TEXT_OUTPUT_HPP 2 | #define SERIALIZATION_FORMAT_TEXT_OUTPUT_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | namespace serialization 12 | { 13 | namespace format 14 | { 15 | namespace text 16 | { 17 | 18 | 19 | typedef boost::archive::text_oarchive output; 20 | 21 | 22 | } 23 | } 24 | } 25 | } 26 | 27 | 28 | #endif // SERIALIZATION_FORMAT_TEXT_OUTPUT_HPP 29 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/format/xml/input.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATION_FORMAT_XML_INPUT_HPP 2 | #define SERIALIZATION_FORMAT_XML_INPUT_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | namespace serialization 12 | { 13 | namespace format 14 | { 15 | namespace xml 16 | { 17 | 18 | 19 | typedef boost::archive::xml_iarchive input; 20 | 21 | 22 | } 23 | } 24 | } 25 | } 26 | 27 | 28 | #endif // SERIALIZATION_FORMAT_XML_INPUT_HPP 29 | 30 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/format/xml/output.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATION_FORMAT_XML_OUTPUT_HPP 2 | #define SERIALIZATION_FORMAT_XML_OUTPUT_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | namespace blub 10 | { 11 | namespace serialization 12 | { 13 | namespace format 14 | { 15 | namespace xml 16 | { 17 | 18 | 19 | typedef boost::archive::xml_oarchive output; 20 | 21 | 22 | } 23 | } 24 | } 25 | } 26 | 27 | 28 | #endif // SERIALIZATION_FORMAT_XML_OUTPUT_HPP 29 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/log/global.cpp: -------------------------------------------------------------------------------- 1 | #include "global.hpp" 2 | 3 | #include "blub/core/string.hpp" 4 | 5 | 6 | using namespace blub::serialization::log; 7 | using namespace blub; 8 | 9 | 10 | BLUB_LOG_GLOBAL_LOGGER_INIT(global, blub::log::logger) 11 | { 12 | blub::log::logger result("serialization"); 13 | return result; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/log/global.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_SERIALIZATION_LOG_GLOBAL_HPP 2 | #define BLUB_SERIALIZATION_LOG_GLOBAL_HPP 3 | 4 | #include "blub/log/global.hpp" 5 | #include "blub/log/globalLogger.hpp" 6 | #include "blub/log/logger.hpp" 7 | #include "blub/log/predecl.hpp" 8 | 9 | 10 | namespace blub 11 | { 12 | namespace serialization 13 | { 14 | namespace log 15 | { 16 | BLUB_LOG_GLOBAL_LOGGER(global, blub::log::logger) 17 | } 18 | } 19 | } 20 | 21 | 22 | #define BLUB_SERIALIZATION_LOG_OUT() BLUB_LOG_OUT_TO(blub::serialization::log::global::get()) 23 | #define BLUB_SERIALIZATION_LOG_WARNING() BLUB_LOG_WARNING_TO(blub::serialization::log::global::get()) 24 | #define BLUB_SERIALIZATION_LOG_ERROR() BLUB_LOG_ERROR_TO(blub::serialization::log::global::get()) 25 | 26 | 27 | #endif // BLUB_SERIALIZATION_LOG_GLOBAL_HPP 28 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/nameValuePair.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATION_NAMEVALUEPAIR_HPP 2 | #define SERIALIZATION_NAMEVALUEPAIR_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | #include 7 | 8 | 9 | 10 | 11 | namespace blub 12 | { 13 | namespace serialization 14 | { 15 | 16 | 17 | class nameValuePair 18 | { 19 | public: 20 | template 21 | static inline 22 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 23 | const 24 | #endif 25 | boost::serialization::nvp< T > create(const char * name, T & t){ 26 | return boost::serialization::nvp< T >(name, t); 27 | } 28 | 29 | }; 30 | 31 | 32 | } 33 | } 34 | 35 | #define BLUB_SERIALIZATION_NAMEVALUEPAIR(x) BOOST_SERIALIZATION_NVP(x) 36 | 37 | 38 | 39 | #endif // SERIALIZATION_NAMEVALUEPAIR_HPP 40 | -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/predecl.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qwertzui11/voxelTerrain/05038fb261893dd044ae82fab96b7708ea5ed623/modules/serialization/source/blub/serialization/predecl.hpp -------------------------------------------------------------------------------- /modules/serialization/source/blub/serialization/saveLoad.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SERIALIZATION_SAVELOAD_HPP 2 | #define SERIALIZATION_SAVELOAD_HPP 3 | 4 | #include 5 | 6 | 7 | #define BLUB_SERIALIZATION_SAVELOAD() BOOST_SERIALIZATION_SPLIT_MEMBER() 8 | 9 | 10 | namespace blub 11 | { 12 | namespace serialization 13 | { 14 | 15 | 16 | template 17 | void saveLoad(Archive & ar, T & t, const unsigned int file_version) 18 | { 19 | boost::serialization::split_member(ar, t, file_version); 20 | } 21 | 22 | 23 | } 24 | } 25 | 26 | 27 | #endif // SERIALIZATION_SAVELOAD_HPP 28 | -------------------------------------------------------------------------------- /modules/sync/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(sources 3 | log/global.cpp 4 | receiver.cpp 5 | ) 6 | 7 | set(headers 8 | predecl.hpp 9 | log/global.hpp 10 | receiver.hpp 11 | sender.hpp 12 | identifier.hpp 13 | ) 14 | 15 | if (BLUB_BUILD_PROCEDURAL) 16 | set(sources ${sources} 17 | ) 18 | set(headers ${headers} 19 | voxel/accessor/multipleTiles/receiver.hpp 20 | voxel/accessor/multipleTiles/base.hpp 21 | voxel/accessor/multipleTiles/sender.hpp 22 | voxel/accessor/terrain/receiver.hpp 23 | voxel/accessor/terrain/sender.hpp 24 | voxel/container/multipleTiles/receiver.hpp 25 | voxel/container/multipleTiles/base.hpp 26 | voxel/container/multipleTiles/sender.hpp 27 | ) 28 | endif (BLUB_BUILD_PROCEDURAL) 29 | 30 | add_module(sync) 31 | 32 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/identifier.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_SYNC_IDENTIFIER_HPP 2 | #define NETWORK_SYNC_IDENTIFIER_HPP 3 | 4 | #include "blub/core/enableSharedFromThis.hpp" 5 | #include "blub/core/sharedPointer.hpp" 6 | 7 | 8 | namespace blub { 9 | namespace sync { 10 | 11 | 12 | class identifier : public enableSharedFromThis 13 | { 14 | public: 15 | typedef sharedPointer pointer; 16 | 17 | static pointer create() 18 | { 19 | return pointer(new identifier()); 20 | } 21 | virtual ~identifier() {;} 22 | 23 | protected: 24 | identifier() 25 | {;} 26 | 27 | }; 28 | 29 | 30 | } 31 | } 32 | 33 | #endif // NETWORK_SYNC_IDENTIFIER_HPP 34 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/log/global.cpp: -------------------------------------------------------------------------------- 1 | #include "global.hpp" 2 | 3 | #include "blub/core/string.hpp" 4 | 5 | 6 | using namespace blub::sync::log; 7 | using namespace blub; 8 | 9 | 10 | BLUB_LOG_GLOBAL_LOGGER_INIT(global, blub::log::logger) 11 | { 12 | blub::log::logger result("sync"); 13 | return result; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/log/global.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BLUB_SYNC_LOG_GLOBAL_HPP 2 | #define BLUB_SYNC_LOG_GLOBAL_HPP 3 | 4 | #include "blub/log/global.hpp" 5 | #include "blub/log/globalLogger.hpp" 6 | #include "blub/log/logger.hpp" 7 | #include "blub/log/predecl.hpp" 8 | 9 | 10 | namespace blub 11 | { 12 | namespace sync 13 | { 14 | namespace log 15 | { 16 | BLUB_LOG_GLOBAL_LOGGER(global, blub::log::logger) 17 | } 18 | } 19 | } 20 | 21 | 22 | #define BLUB_SYNC_LOG_OUT() BLUB_LOG_OUT_TO(blub::sync::log::global::get()) 23 | #define BLUB_SYNC_LOG_WARNING() BLUB_LOG_WARNING_TO(blub::sync::log::global::get()) 24 | #define BLUB_SYNC_LOG_ERROR() BLUB_LOG_ERROR_TO(blub::sync::log::global::get()) 25 | 26 | 27 | #endif // BLUB_SYNC_LOG_GLOBAL_HPP 28 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/predecl.hpp: -------------------------------------------------------------------------------- 1 | namespace blub 2 | { 3 | 4 | namespace sync 5 | { 6 | class identifier; 7 | template 8 | class sender; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/receiver.cpp: -------------------------------------------------------------------------------- 1 | #include "receiver.hpp" 2 | 3 | using namespace blub::sync; 4 | using namespace blub; 5 | 6 | 7 | receiver::receiver() 8 | { 9 | } 10 | 11 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/receiver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SYNC_RECEIVER_HPP 2 | #define SYNC_RECEIVER_HPP 3 | 4 | 5 | namespace blub 6 | { 7 | namespace sync 8 | { 9 | 10 | 11 | class receiver 12 | { 13 | public: 14 | receiver(); 15 | }; 16 | 17 | 18 | } 19 | } 20 | 21 | 22 | 23 | #endif // SYNC_RECEIVER_HPP 24 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/voxel/accessor/multipleTiles/base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_SYNC_VOXEL_ACCESSOR_MULTIPLETILES_BASE_HPP 2 | #define NETWORK_SYNC_VOXEL_ACCESSOR_MULTIPLETILES_BASE_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | #include "blub/serialization/format/binary/input.hpp" 6 | #include "blub/serialization/format/binary/output.hpp" 7 | 8 | 9 | namespace blub 10 | { 11 | namespace sync 12 | { 13 | namespace voxel 14 | { 15 | namespace accessor 16 | { 17 | namespace multipleTiles 18 | { 19 | 20 | 21 | enum class sendType : uint8 22 | { 23 | lockForEdit, 24 | unlockForEdit, 25 | setTile, 26 | removeTile 27 | }; 28 | 29 | 30 | 31 | 32 | } 33 | } 34 | } 35 | } 36 | } 37 | 38 | 39 | 40 | #endif // NETWORK_SYNC_VOXEL_ACCESSOR_MULTIPLETILES_BASE_HPP 41 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/voxel/accessor/multipleTiles/receiver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_SYNC_VOXEL_ACCESSOR_MULTIPLETILES_RECEIVER_HPP 2 | #define NETWORK_SYNC_VOXEL_ACCESSOR_MULTIPLETILES_RECEIVER_HPP 3 | 4 | #include "blub/core/byteArray.hpp" 5 | #include "blub/log/global.hpp" 6 | #include "blub/core/sharedPointer.hpp" 7 | #include "blub/async/dispatcher.hpp" 8 | #include "blub/sync/voxel/accessor/multipleTiles/base.hpp" 9 | #include "blub/procedural/voxel/simple/accessor.hpp" 10 | #include "blub/procedural/voxel/simple/base.hpp" 11 | #include "blub/procedural/voxel/tile/accessor.hpp" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | 20 | namespace blub 21 | { 22 | namespace sync 23 | { 24 | namespace voxel 25 | { 26 | namespace accessor 27 | { 28 | namespace multipleTiles 29 | { 30 | 31 | 32 | template 33 | class receiver : public procedural::voxel::simple::base > > 34 | { 35 | public: 36 | typedef sharedPointer t_tileDataPtr; 37 | typedef procedural::voxel::tile::accessor t_tileAccessor; 38 | typedef sharedPointer t_tilePtr; 39 | typedef procedural::voxel::simple::base t_base; 40 | typedef typename t_base::t_tileId t_tileId; 41 | 42 | 43 | receiver(blub::async::dispatcher * todoListenerMaster, const int32& lod = 0) 44 | : t_base(*todoListenerMaster) 45 | , m_lod(lod) 46 | { 47 | t_base::setCreateTileCallback(boost::bind(&t_tileAccessor::create)); 48 | } 49 | 50 | // "receive sync" 51 | void receivedTileData(const byteArray& data) 52 | { 53 | t_base::m_master.post(boost::bind(&receiver::receivedTileDataMaster, this, data)); 54 | } 55 | void receivedTilePtrData(t_tileDataPtr data) 56 | { 57 | BASSERT(!data.isNull()); 58 | 59 | t_base::m_master.post(boost::bind(&receiver::receivedTileDataPtrMaster, this, data)); 60 | } 61 | 62 | protected: 63 | void receivedTileDataMaster(const byteArray& data) 64 | { 65 | sendType type; 66 | 67 | std::istringstream input(std::string(data.data(), data.size())); 68 | blub::serialization::format::binary::input format(input); 69 | format >> type; 70 | 71 | if (type == sendType::lockForEdit) 72 | { 73 | #ifdef BLUB_LOG_VOXEL_ACCESSOR_SYNC 74 | blub::BOUT("type == sendType::lockForEdit id:" + blub::string::number(id)); 75 | #endif 76 | t_base::lockForEditMaster(); 77 | return; 78 | } 79 | if (type == sendType::unlockForEdit) 80 | { 81 | #ifdef BLUB_LOG_VOXEL_ACCESSOR_SYNC 82 | blub::BOUT("type == sendType::unlockForEdit id:" + blub::string::number(id)); 83 | #endif 84 | t_base::unlockForEditMaster(); 85 | return; 86 | } 87 | 88 | t_tileId id; 89 | format >> id; 90 | 91 | if (type == sendType::removeTile) 92 | { 93 | #ifdef BLUB_LOG_VOXEL_ACCESSOR_SYNC 94 | blub::BOUT("type == sendType::removeTile id:" + blub::string::number(id)); 95 | #endif 96 | t_base::addToChangeList(id, nullptr); 97 | return; 98 | } 99 | 100 | BASSERT((uint32)data.size() > sizeof(sendType) + sizeof(t_tileId)); 101 | BASSERT(type == sendType::setTile); 102 | #ifdef BLUB_LOG_VOXEL_ACCESSOR_SYNC 103 | blub::BOUT("type == sendType::setTile id:" + blub::string::number(id)); 104 | #endif 105 | 106 | byteArray toDecompress; 107 | format >> toDecompress; 108 | 109 | t_tilePtr workTile(t_base::createTile()); 110 | { 111 | std::stringstream toReadFromBuffer; 112 | // decompress 113 | { 114 | boost::iostreams::stream src(toDecompress.data(), toDecompress.size()); 115 | boost::iostreams::filtering_istream filterIn; 116 | filterIn.push(boost::iostreams::bzip2_decompressor()); 117 | filterIn.push(src); 118 | boost::iostreams::copy(filterIn, toReadFromBuffer); 119 | } 120 | 121 | blub::serialization::format::binary::input toReadFrom(toReadFromBuffer); 122 | 123 | toReadFrom >> *workTile.get(); 124 | } 125 | t_base::addToChangeList(id, workTile); 126 | } 127 | void receivedTileDataPtrMaster(t_tileDataPtr data) 128 | { 129 | receivedTileDataMaster(*data.data()); 130 | } 131 | 132 | const int32 m_lod; 133 | 134 | }; 135 | 136 | 137 | 138 | 139 | } 140 | } 141 | } 142 | } 143 | } 144 | 145 | 146 | 147 | 148 | 149 | #endif // NETWORK_SYNC_VOXEL_ACCESSOR_MULTIPLETILES_RECEIVER_HPP 150 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/voxel/accessor/terrain/receiver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_SYNC_VOXEL_ACCESSOR_TERRAIN_RECEIVER_HPP 2 | #define NETWORK_SYNC_VOXEL_ACCESSOR_TERRAIN_RECEIVER_HPP 3 | 4 | #include "blub/async/predecl.hpp" 5 | #include "blub/core/byteArray.hpp" 6 | #include "blub/core/globals.hpp" 7 | #include "blub/core/sharedPointer.hpp" 8 | #include "blub/core/vector.hpp" 9 | #include "blub/procedural/voxel/terrain/accessor.hpp" 10 | #include "blub/procedural/voxel/terrain/base.hpp" 11 | #include "blub/sync/voxel/accessor/multipleTiles/receiver.hpp" 12 | 13 | 14 | namespace blub 15 | { 16 | namespace sync 17 | { 18 | namespace voxel 19 | { 20 | namespace accessor 21 | { 22 | namespace terrain 23 | { 24 | 25 | 26 | template 27 | class receiver : public procedural::voxel::terrain::base< sharedPointer > > 28 | { 29 | public: 30 | typedef multipleTiles::receiver t_multipleTiles; 31 | typedef t_multipleTiles* t_multipleTilesPtr; 32 | 33 | typedef procedural::voxel::terrain::base< sharedPointer > > t_base; 34 | 35 | typedef sharedPointer t_tileDataPtr; 36 | typedef vector t_multipleTilesList; 37 | 38 | receiver(async::dispatcher *todoListenerMaster, const uint16 &numLod) 39 | { 40 | for (int32 ind = 0; ind < numLod; ++ind) 41 | { 42 | t_multipleTilesPtr lod(new t_multipleTiles(todoListenerMaster, ind)); 43 | t_base::m_lods.push_back(lod); 44 | } 45 | } 46 | virtual ~receiver() 47 | { 48 | for (auto toDelete : t_base::m_lods) 49 | { 50 | delete toDelete; 51 | } 52 | t_base::m_lods.clear(); 53 | } 54 | 55 | // "receive sync" 56 | void receivedTileData(const byteArray& data) 57 | { 58 | BASSERT((uint32)data.size() > sizeof(uint32)); 59 | 60 | uint32 lodIndex; 61 | byteArray restOftheData; 62 | 63 | std::istringstream input(std::string(data.data(), data.size())); 64 | blub::serialization::format::binary::input format(input); 65 | 66 | format >> lodIndex; 67 | format >> restOftheData; 68 | 69 | static_cast(t_base::m_lods[lodIndex])->receivedTileData(restOftheData); 70 | } 71 | void receivedTilePtrData(t_tileDataPtr data) 72 | { 73 | receivedTileData(*data); 74 | } 75 | 76 | private: 77 | 78 | 79 | }; 80 | 81 | 82 | } 83 | } 84 | } 85 | } 86 | } 87 | 88 | 89 | 90 | #endif // NETWORK_SYNC_VOXEL_ACCESSOR_TERRAIN_RECEIVER_HPP 91 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/voxel/container/multipleTiles/base.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BASE_HPP 2 | #define BASE_HPP 3 | 4 | #include "blub/core/globals.hpp" 5 | 6 | 7 | namespace blub 8 | { 9 | namespace sync 10 | { 11 | namespace voxel 12 | { 13 | namespace container 14 | { 15 | namespace simple 16 | { 17 | 18 | 19 | enum class sendType : uint8 20 | { 21 | startEditing, 22 | endEditing, 23 | setTile 24 | }; 25 | 26 | 27 | 28 | } 29 | } 30 | } 31 | } 32 | } 33 | 34 | 35 | 36 | #endif // BASE_HPP 37 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/voxel/container/multipleTiles/receiver.hpp: -------------------------------------------------------------------------------- 1 | #include "blub/sync/voxel/container/multipleTiles/network_sync_voxel_container_multipleTiles_receiver.hpp" 2 | -------------------------------------------------------------------------------- /modules/sync/source/blub/sync/voxel/container/multipleTiles/sender.hpp: -------------------------------------------------------------------------------- 1 | #include "blub/sync/voxel/container/multipleTiles/network_sync_voxel_container_multipleTiles_sender.hpp" 2 | --------------------------------------------------------------------------------