1
0
Fork 0

New year reboot

Switch to FastNoise2
Hierarchy including rotate
And many more
master
May B. 2021-01-20 17:13:15 +01:00
parent e8080bffb6
commit 6288606505
400 changed files with 17217 additions and 14045 deletions

View File

@ -1,94 +1,100 @@
cmake_minimum_required(VERSION 3.11)
project (univerxel VERSION 0.0.1)
project (univerxel VERSION 0.0.2)
option(PROFILING "Build with profiling" 0)
option(FIXED_WINDOW "Lock window size: Force floating on i3" 0)
set(SIMD_LEVEL "avx2" CACHE STRING "SIMD processor acceleration (sse2, sse4.1, avx2, avx512f)")
option(USE_FMA "Use fma" 1)
option(LOG_DEBUG "Show debug logs" 0)
option(LOG_TRACE "Show trace logs" 0)
option(FIXED_WINDOW "Lock window size: Force floating on i3" 0)
option(RENDER_VK "Include vulkan renderer" 1)
option(NATIVE "Build with -march=native" 0)
option(IPO "Link time optimisation" 1)
option(LD_GOLD "Use gold linker" 1)
option(CCACHE "Use code cache" 1)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
else(CCACHE_FOUND)
#TODO: set(CMAKE_UNITY_BUILD ON)
endif(CCACHE_FOUND)
add_subdirectory("deps/glfw")
add_subdirectory("deps/glm")
add_subdirectory("deps/picoquic")
add_subdirectory("deps/zstd")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_OK OUTPUT IPO_ERROR)
if(IPO_OK)
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported: <${IPO_ERROR}>")
add_subdirectory("deps/glfw")
add_subdirectory("deps/glm")
add_subdirectory("deps/picoquic")
add_subdirectory("deps/zstd")
add_subdirectory("deps/FastNoise2/src")
if (CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
message(STATUS "CCACHE enabled")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
else(CCACHE_FOUND)
#MAYBE: set(CMAKE_UNITY_BUILD ON)
endif(CCACHE_FOUND)
endif()
if(IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_OK OUTPUT IPO_ERROR)
if(IPO_OK)
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported: <${IPO_ERROR}>")
endif()
endif()
set(LD_GOLD 1)
if(LD_GOLD)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
if("${LD_VERSION}" MATCHES "GNU gold")
message(STATUS "Gold linker enabled")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold")
endif()
endif()
if(MSVC)
add_definitions(/std:c++latest)
add_compile_definitions(WIN32_LEAN_AND_MEAN=)
else()
#FIXME: by target set(CMAKE_CXX_FLAGS "-Wall -Wextra")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_definitions(FIXED_WINDOW=${FIXED_WINDOW} LOG_DEBUG=${LOG_DEBUG} LOG_TRACE=${LOG_TRACE} HN_USE_FILESYSTEM=1)
if(PROFILING)
add_compile_definitions(TRACY_ENABLE=1)
endif(PROFILING)
add_compile_definitions(TRACY_ENABLE=1)
endif()
add_compile_definitions(FIXED_WINDOW=${FIXED_WINDOW} LOG_DEBUG=${LOG_DEBUG} LOG_TRACE=${LOG_TRACE})
if(NATIVE)
add_definitions(-march=native)
endif()
if(SIMD_LEVEL EQUAL "avx2")
add_compile_definitions(FN_COMPILE_AVX2=1)
elseif(SIMD_LEVEL EQUAL "avx512f")
add_compile_definitions(FN_COMPILE_AVX512=1)
endif()
if(MSVC)
add_definitions(/arch:AVX2)
else()
add_definitions(-m${SIMD_LEVEL})
endif()
if(USE_FMA)
if(MSVC)
add_definitions(/GL /fp:fast)
else()
add_definitions(-mfma)
endif()
endif(USE_FMA)
file(GLOB_RECURSE CORE_SOURCES "src/core/*.cpp" "deps/tracy/TracyClient.cpp")
configure_file(src/version.h.in generated/version.h @ONLY)
set(CORE_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/generated" "deps/toml++" "deps/robin_hood" "deps/libguarded" "deps/tracy")
set(CORE_HEADERS "src" "${CMAKE_CURRENT_BINARY_DIR}/generated" "deps/toml++" "deps/robin_hood" "deps/tracy")
set(CORE_LIBS glm::glm_static zstd::zstd_static) # picoquic
file(GLOB_RECURSE CLIENT_SOURCES "src/client/*.cpp" "deps/imgui/*.cpp" "deps/meshoptimizer/*.cpp" "deps/gl3w/gl3w.c" "deps/volk/volk.c")
set(CLIENT_HEADERS "deps/imgui" "deps/meshoptimizer" "deps/gl3w" "deps/volk")
file(GLOB_RECURSE CLIENT_SOURCES "src/client/*.cpp" "deps/imgui/*.cpp" "deps/meshoptimizer/*.cpp" "deps/gl3w/gl3w.c")
set(CLIENT_HEADERS "deps/imgui" "deps/meshoptimizer" "deps/gl3w")
set(CLIENT_LIBS glfw)
set(CLIENT_DEFS)
if(RENDER_VK)
list(APPEND CLIENT_SOURCES "deps/volk/volk.c")
list(APPEND CLIENT_HEADERS "deps/volk")
list(APPEND CLIENT_DEFS RENDER_VK=1)
else()
file(GLOB_RECURSE CLIENT_RENDER "src/client/render/impl/vk/*.cpp")
list(REMOVE_ITEM CLIENT_SOURCE ${CLIENT_RENDER})
endif()
file(GLOB_RECURSE SERVER_SOURCES "src/server/*.cpp" "deps/FastNoiseSIMD/*.cpp")
set(SERVER_HEADERS "deps/FastNoiseSIMD")
set(SERVER_LINKED)
file(GLOB_RECURSE SERVER_SOURCES "src/server/*.cpp")
set(SERVER_HEADERS)
set(SERVER_LIBS FastNoise)
if(WIN32)
set(CLIENT_HEADERS ${CLIENT_HEADERS} $ENV{VULKAN_SDK}\\include)
find_package(OpenSSL)
set(CORE_LIBS ${CORE_LIBS} ${CMAKE_BINARY_DIR}/libs/*.lib ${OPENSSL_LIBRARIES} ws2_32)
list(APPEND CORE_LIBS ${CMAKE_BINARY_DIR}/libs/*.lib ${OPENSSL_LIBRARIES} ws2_32)
else()
set(CORE_LIBS ${CORE_LIBS} picoquic-core pthread dl)
list(APPEND CORE_LIBS picoquic-core pthread dl)
endif()
if (WIN32)
@ -99,32 +105,56 @@ elseif (APPLE)
set(ICON univerxel.icns)
endif()
list(APPEND CORE_HEADERS "src/modules")
list(APPEND CORE_SOURCES "src/modules/core/Core.cpp")
# All in one exec
add_executable(univerxel "src/main.cpp" ${ICON} ${CORE_SOURCES} ${CLIENT_SOURCES} ${SERVER_SOURCES})
target_compile_features(univerxel PUBLIC cxx_std_17)
target_link_libraries(univerxel ${CORE_LIBS} ${CLIENT_LIBS} ${SERVER_LIBS})
target_link_libraries(univerxel PRIVATE ${CORE_LIBS} ${CLIENT_LIBS} ${SERVER_LIBS})
target_include_directories(univerxel PRIVATE ${CORE_HEADERS} ${CLIENT_HEADERS} ${SERVER_HEADERS})
target_compile_definitions(univerxel PRIVATE ${CLIENT_DEFS})
target_compile_features(univerxel PUBLIC cxx_std_17)
target_compile_options(univerxel PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra>
$<$<CXX_COMPILER_ID:MSVC>:
/WX /W4>)
# Standalone server
add_executable(univerxel-server EXCLUDE_FROM_ALL "src/server.cpp" ${ICON} ${CORE_SOURCES} ${SERVER_SOURCES})
target_compile_features(univerxel-server PUBLIC cxx_std_17)
target_link_libraries(univerxel-server ${CORE_LIBS} ${SERVER_LIBS})
target_link_libraries(univerxel-server PRIVATE ${CORE_LIBS} ${SERVER_LIBS})
target_include_directories(univerxel-server PRIVATE ${CORE_HEADERS} ${SERVER_HEADERS})
target_compile_definitions(univerxel-server PRIVATE STANDALONE_SERVER=1)
target_compile_features(univerxel-server PUBLIC cxx_std_17)
target_compile_options(univerxel-server PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra>
$<$<CXX_COMPILER_ID:MSVC>:
/WX /W4>)
# Dumb client
add_executable(univerxel-client EXCLUDE_FROM_ALL "src/client.cpp" ${ICON} ${CORE_SOURCES} ${CLIENT_SOURCES})
target_compile_features(univerxel-client PUBLIC cxx_std_17)
target_link_libraries(univerxel-client ${CORE_LIBS} ${CLIENT_LIBS})
target_link_libraries(univerxel-client PRIVATE ${CORE_LIBS} ${CLIENT_LIBS})
target_include_directories(univerxel-client PRIVATE ${CORE_HEADERS} ${CLIENT_HEADERS})
target_compile_definitions(univerxel-client PRIVATE LIGHT_CLIENT=1 ${CLIENT_DEFS})
target_compile_features(univerxel-client PUBLIC cxx_std_17)
target_compile_options(univerxel-client PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra>
$<$<CXX_COMPILER_ID:MSVC>:
/WX /W4>)
# Resource client files + default zstd.dict
file(COPY resource/content DESTINATION ${CMAKE_BINARY_DIR})
if(RENDER_VK)
file(COPY resource/shaders/vk DESTINATION ${CMAKE_BINARY_DIR}/content/shaders)
endif()
# Serialize entity model
file(GLOB_RECURSE MODELS_SOURCES "src/client/render/api/Models.cpp")
add_executable(generate_models EXCLUDE_FROM_ALL "src/tools/generate_models.cpp" ${MODELS_SOURCES})
target_compile_features(generate_models PUBLIC cxx_std_17)
target_link_libraries(generate_models glm::glm_static)
target_link_libraries(generate_models PRIVATE glm::glm_static)
target_include_directories(generate_models PRIVATE "deps/robin_hood" "deps/meshoptimizer")
# Docs

View File

@ -38,7 +38,7 @@ PROJECT_NAME = Univerxel
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = 0.0.1
PROJECT_NUMBER = 0.0.2
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a

View File

@ -96,13 +96,13 @@ CMake options: `-DKEY=VAL`
Key | Usage | Default
--- | --- | ---
SIMD_LEVEL | SIMD processor acceleration (sse2, sse4.1, avx2, avx512f) | `avx2`
USE_FMA | Fast math | `1`
CMAKE_BUILD_TYPE | Level of optimization | `Release`
PROFILING | Tracy profiling | `0`
LOG_DEBUG | Debug logs | `0`
LOG_TRACE | Trace logs | `0`
IPO | Link time optimisation | `1`
NATIVE | Optimize for native CPU | `0`
RENDER_VK | Include Vulkan renderer | `1`
1. Compile
```sh

65
TODO.md
View File

@ -4,15 +4,16 @@
Released as `0.0.1`: `Pre alpha 1`
- [ ] From the ground up cleanup
- [x] From the ground up cleanup
## System
- [~] Dependencies updater
- [x] Tracy
- [ ] ImGui
- [x] FastNoise
- Compile time
- [ ] Warnings
- [x] Warnings
- [ ] Unit build
- [ ] Ninga
- [ ] Clang
@ -28,60 +29,80 @@ Released as `0.0.1`: `Pre alpha 1`
- [ ] Review documentation
- [ ] Code cleanup
- [ ] Proper wiki
- [ ] Yaml config
- [ ] Proper logger
- [ ] I18L
## Data
- [ ] Element hierarchy
- [ ] Collide
- [~] Element hierarchy
- [x] Raycast
- [ ] Soft part break
- [ ] Relative position
- [ ] Rotate
- [ ] Merge World and Entities
- [x] Relative position
- [x] Rotate
- [ ] Bounding hierarchy
- [x] Merge World and Entities
- [ ] Galaxy
- [ ] Orbit system
- [~] Orbit system
- [x] Circular
- [ ] Elliptic
- [ ] Gravity referential
- [ ] Collisions
- [ ] Point
- [ ] Step
- [ ] Ray
- [ ] Continuous
- Bilateral advancement
- GJK
- Edits
- [ ] More shapes
- [ ] Rotate
- [ ] Anchor
- [ ] Multi-block system
- [ ] Cross chunk structure
- [ ] Lighting
- [ ] Passive chunk save
- Generation
- SIMD
- [ ] Dynamic SIMD level libs
- [ ] https://github.com/Auburn/FastNoise2/releases
- [ ] Double precision
- [ ] Surface features
- [ ] Biomes
- https://imgur.com/kM8b5Zq
- https://imgur.com/a/bh2iy
- https://speciesdevblog.files.wordpress.com/2012/11/biomemap.png
- [ ] ECS
- [x] Data oriented
- [ ] Inventory
- [ ] Octree
- [ ] Surface aware LOD
- [ ] Level converter
- [ ] Area converter
- [ ] Minecraft import
- [ ] Base unit size change
- [ ] Local generation prediction
- [ ] Modding API
- [~] Modding API
- [x] Define boundaries
- [ ] Version handling
- [ ] Client-Server negotiation
- [ ] Save file index
- [ ] List possibilities
## Graphics
- [ ] Disable VK for now
- [~] Disable VK for now
- [ ] Slash screen
- [ ] Proper UI
- [ ] Pause menu
- [ ] Start menu
- [~] Start menu
- [ ] Using texture pack
- [ ] FontAwesome (https://github.com/juliettef/IconFontCppHeaders)
- [ ] Define standard unit size
- [x] Define standard unit sizes
- Terrain (area) 1:1m
- Objects (part) 1-8:1
- Models (instance) ~16:1 manual
- Visual debug
- [ ] Chunk / Region border
- [ ] Area box
- [x] Chunk / Region border
- [x] Area box
- [ ] Collision overview
- [ ] Effective occlusion culling
- [ ] Use average
- [ ] Cast from chunk center
- Curvature
- CubeSphere
@ -99,11 +120,13 @@ Released as `0.0.1`: `Pre alpha 1`
- https://assetstore.unity.com/packages/tools/terrain/microsplat-96478
- https://www.youtube.com/user/slipster216/videos
- [x] Biplanar
- [ ] Fix stochastic (needs regionPosition bound in f16 range)
- [ ] Distance resampling
- [ ] Tesselation
- [ ] Better LOD selection
- Dynamic to target fps
- [ ] Planet scale LOD (using chunk level average)
- [ ] Hard shadow
- [ ] Ambiant occlusion
- [ ] World lights
- [ ] HDR
- https://www.youtube.com/watch?v=iikdcAA7cww
@ -116,6 +139,7 @@ Released as `0.0.1`: `Pre alpha 1`
- Bloom
- [ ] Procedural Skybox
- [ ] Deferred
- [ ] Ambiant occlusion
- [ ] Cascaded shadow maps
- [ ] Avoid transparent back-face
- [ ] Translucency
@ -136,3 +160,4 @@ Released as `0.0.1`: `Pre alpha 1`
- [ ] Commands
- [~] Authentication
- [ ] Clean kick
- [ ] Check certificate

27
deps/FastNoise2/.fix-include-path.patch vendored Normal file
View File

@ -0,0 +1,27 @@
From 2b251207adef7ab9b9f243d4bcfa2cfc1e515114 Mon Sep 17 00:00:00 2001
From: Shu <me@wadza.fr>
Date: Tue, 5 Jan 2021 18:11:53 +0100
Subject: [PATCH] Fix: include path
---
src/CMakeLists.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c72a4be..f5d134e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -55,8 +55,8 @@ set(install_targets ${install_targets} FastNoise PARENT_SCOPE)
set(install_fastnoise_headers ${FastNoise_headers} PARENT_SCOPE)
set(install_fastsimd_headers ${FastSIMD_headers} PARENT_SCOPE)
-target_include_directories(FastNoise PUBLIC
- $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
+target_include_directories(FastNoise SYSTEM PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<INSTALL_INTERFACE:include>
)
--
2.30.0

16
deps/FastNoise2/.update.sh vendored Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
BASEDIR=$(dirname "$0")
cd $BASEDIR
git clone https://github.com/Auburn/FastNoise2 .up
cd .up
echo "Apply master"
#TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
#echo "Apply tag $TAG"
#git checkout $TAG
git apply ../.fix-include-path.patch
cp -rf src include LICENSE ..
cd ..
rm -rf .up
echo "Done"

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 Jimmie Bergmann
Copyright (c) 2020 Jordan Peck
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -0,0 +1,33 @@
#pragma once
#include <memory>
#include "FastSIMD/FastSIMD.h"
#include "FastNoise_Config.h"
#include "Generators/BasicGenerators.h"
#include "Generators/Value.h"
#include "Generators/Perlin.h"
#include "Generators/Simplex.h"
#include "Generators/Cellular.h"
#include "Generators/Fractal.h"
#include "Generators/DomainWarp.h"
#include "Generators/DomainWarpFractal.h"
#include "Generators/Modifiers.h"
#include "Generators/Blends.h"
namespace FastNoise
{
template<typename T>
inline SmartNode<T> New( FastSIMD::eLevel maxLevel = FastSIMD::Level_Null )
{
static_assert( std::is_base_of_v<Generator, T>, "Use FastSIMD::New() to create non FastNoise classes" );
return SmartNode<T>( FastSIMD::New<T>( maxLevel ) );
}
inline SmartNode<> NewFromEncodedNodeTree( const char* encodedNodeTreeString, FastSIMD::eLevel maxLevel = FastSIMD::Level_Null )
{
return Metadata::DeserialiseSmartNode( encodedNodeTreeString, maxLevel );
}
}

View File

@ -0,0 +1,331 @@
#pragma once
#include <functional>
#include <memory>
#include <type_traits>
#include <vector>
#include <cstdint>
#include "FastNoise_Config.h"
#include "FastSIMD/FastSIMD.h"
namespace FastNoise
{
class Generator;
template<typename T>
struct PerDimensionVariable;
struct NodeData;
struct Metadata
{
Metadata( const char* className )
{
name = className;
id = AddMetadataClass( this );
}
static const std::vector<const Metadata*>& GetMetadataClasses()
{
return sMetadataClasses;
}
static const Metadata* GetMetadataClass( std::uint16_t nodeId )
{
if( nodeId < sMetadataClasses.size() )
{
return sMetadataClasses[nodeId];
}
return nullptr;
}
static std::string SerialiseNodeData( NodeData* nodeData, bool fixUp = false );
static SmartNode<> DeserialiseSmartNode( const char* serialisedBase64NodeData, FastSIMD::eLevel level = FastSIMD::Level_Null );
static NodeData* DeserialiseNodeData( const char* serialisedBase64NodeData, std::vector<std::unique_ptr<NodeData>>& nodeDataOut );
struct MemberVariable
{
enum eType
{
EFloat,
EInt,
EEnum
};
union ValueUnion
{
float f;
std::int32_t i;
ValueUnion( float v = 0 )
{
f = v;
}
ValueUnion( std::int32_t v )
{
i = v;
}
operator float()
{
return f;
}
operator std::int32_t()
{
return i;
}
bool operator ==( const ValueUnion& rhs ) const
{
return i == rhs.i;
}
};
const char* name;
eType type;
int dimensionIdx = -1;
ValueUnion valueDefault, valueMin, valueMax;
std::vector<const char*> enumNames;
std::function<void( Generator*, ValueUnion )> setFunc;
};
template<typename T, typename U, typename = std::enable_if_t<!std::is_enum_v<T>>>
void AddVariable( const char* name, T defaultV, U&& func, T minV = 0, T maxV = 0 )
{
MemberVariable member;
member.name = name;
member.valueDefault = defaultV;
member.valueMin = minV;
member.valueMax = maxV;
member.type = std::is_same_v<T, float> ? MemberVariable::EFloat : MemberVariable::EInt;
member.setFunc = [func]( Generator* g, MemberVariable::ValueUnion v ) { func( dynamic_cast<GetArg<U, 0>>(g), v ); };
memberVariables.push_back( member );
}
template<typename T, typename U, typename = std::enable_if_t<!std::is_enum_v<T>>>
void AddVariable( const char* name, T defaultV, void(U::* func)(T), T minV = 0, T maxV = 0 )
{
MemberVariable member;
member.name = name;
member.valueDefault = defaultV;
member.valueMin = minV;
member.valueMax = maxV;
member.type = std::is_same_v<T, float> ? MemberVariable::EFloat : MemberVariable::EInt;
member.setFunc = [func]( Generator* g, MemberVariable::ValueUnion v ) { (dynamic_cast<U*>(g)->*func)(v); };
memberVariables.push_back( member );
}
template<typename T, typename U, typename = std::enable_if_t<std::is_enum_v<T>>, typename... NAMES>
void AddVariableEnum( const char* name, T defaultV, void(U::* func)(T), NAMES... names )
{
MemberVariable member;
member.name = name;
member.type = MemberVariable::EEnum;
member.valueDefault = (int32_t)defaultV;
member.enumNames = { names... };
member.setFunc = [func]( Generator* g, MemberVariable::ValueUnion v ) { (dynamic_cast<U*>(g)->*func)((T)v.i); };
memberVariables.push_back( member );
}
template<typename T, typename U, typename = std::enable_if_t<!std::is_enum_v<T>>>
void AddPerDimensionVariable( const char* name, T defaultV, U&& func, T minV = 0, T maxV = 0 )
{
for( int idx = 0; (size_t)idx < sizeof( PerDimensionVariable<T>::varArray ) / sizeof( *PerDimensionVariable<T>::varArray ); idx++ )
{
MemberVariable member;
member.name = name;
member.valueDefault = defaultV;
member.valueMin = minV;
member.valueMax = maxV;
member.type = std::is_same_v<T, float> ? MemberVariable::EFloat : MemberVariable::EInt;
member.dimensionIdx = idx;
member.setFunc = [func, idx]( Generator* g, MemberVariable::ValueUnion v ) { func( dynamic_cast<GetArg<U, 0>>(g) ).get()[idx] = v; };
memberVariables.push_back( member );
}
}
struct MemberNode
{
const char* name;
int dimensionIdx = -1;
std::function<bool( Generator*, SmartNodeArg<> )> setFunc;
};
template<typename T, typename U>
void AddGeneratorSource( const char* name, void(U::* func)(SmartNodeArg<T>) )
{
MemberNode member;
member.name = name;
member.setFunc = [func]( Generator* g, SmartNodeArg<> s )
{
SmartNode<T> downCast = std::dynamic_pointer_cast<T>(s);
if( downCast )
{
(dynamic_cast<U*>(g)->*func)( downCast );
}
return (bool)downCast;
};
memberNodes.push_back( member );
}
template<typename U>
void AddPerDimensionGeneratorSource( const char* name, U&& func )
{
using GeneratorSourceT = typename std::invoke_result_t<U, GetArg<U, 0>>::type::Type;
using T = typename GeneratorSourceT::Type;
for( int idx = 0; (size_t)idx < sizeof( PerDimensionVariable<GeneratorSourceT>::varArray ) / sizeof( *PerDimensionVariable<GeneratorSourceT>::varArray ); idx++ )
{
MemberNode member;
member.name = name;
member.dimensionIdx = idx;
member.setFunc = [func, idx]( auto* g, SmartNodeArg<> s )
{
SmartNode<T> downCast = std::dynamic_pointer_cast<T>(s);
if( downCast )
{
g->SetSourceMemberVariable( func( dynamic_cast<GetArg<U, 0>>(g) ).get()[idx], downCast );
}
return (bool)downCast;
};
memberNodes.push_back( member );
}
}
struct MemberHybrid
{
const char* name;
float valueDefault = 0.0f;
int dimensionIdx = -1;
std::function<void( Generator*, float )> setValueFunc;
std::function<bool( Generator*, SmartNodeArg<> )> setNodeFunc;
};
template<typename T, typename U>
void AddHybridSource( const char* name, float defaultValue, void(U::* funcNode)(SmartNodeArg<T>), void(U::* funcValue)(float) )
{
MemberHybrid member;
member.name = name;
member.valueDefault = defaultValue;
member.setNodeFunc = [funcNode]( auto* g, SmartNodeArg<> s )
{
SmartNode<T> downCast = std::dynamic_pointer_cast<T>(s);
if( downCast )
{
(dynamic_cast<U*>(g)->*funcNode)( downCast );
}
return (bool)downCast;
};
member.setValueFunc = [funcValue]( Generator* g, float v )
{
(dynamic_cast<U*>(g)->*funcValue)(v);
};
memberHybrids.push_back( member );
}
template<typename U>
void AddPerDimensionHybridSource( const char* name, float defaultV, U&& func )
{
using HybridSourceT = typename std::invoke_result_t<U, GetArg<U, 0>>::type::Type;
using T = typename HybridSourceT::Type;
for( int idx = 0; (size_t)idx < sizeof( PerDimensionVariable<HybridSourceT>::varArray ) / sizeof( *PerDimensionVariable<HybridSourceT>::varArray ); idx++ )
{
MemberHybrid member;
member.name = name;
member.valueDefault = defaultV;
member.dimensionIdx = idx;
member.setNodeFunc = [func, idx]( auto* g, SmartNodeArg<> s )
{
SmartNode<T> downCast = std::dynamic_pointer_cast<T>(s);
if( downCast )
{
g->SetSourceMemberVariable( func( dynamic_cast<GetArg<U, 0>>(g) ).get()[idx], downCast );
}
return (bool)downCast;
};
member.setValueFunc = [func, idx]( Generator* g, float v ) { func( dynamic_cast<GetArg<U, 0>>(g) ).get()[idx] = v; };
memberHybrids.push_back( member );
}
}
std::uint16_t id;
const char* name;
std::vector<const char*> groups;
std::vector<MemberVariable> memberVariables;
std::vector<MemberNode> memberNodes;
std::vector<MemberHybrid> memberHybrids;
virtual Generator* NodeFactory( FastSIMD::eLevel level = FastSIMD::Level_Null ) const = 0;
private:
template<typename F, typename Ret, typename... Args>
static std::tuple<Args...> GetArg_Helper( Ret( F::* )(Args...) const );
template<typename F, std::size_t I>
using GetArg = std::tuple_element_t<I, decltype(GetArg_Helper( &F::operator() ))>;
static std::uint16_t AddMetadataClass( const Metadata* newMetadata )
{
sMetadataClasses.emplace_back( newMetadata );
return (std::uint16_t)sMetadataClasses.size() - 1;
}
static std::vector<const Metadata*> sMetadataClasses;
};
struct NodeData
{
NodeData( const Metadata* metadata );
const Metadata* metadata;
std::vector<Metadata::MemberVariable::ValueUnion> variables;
std::vector<NodeData*> nodes;
std::vector<std::pair<NodeData*, float>> hybrids;
bool operator ==( const NodeData& rhs ) const
{
return metadata == rhs.metadata &&
variables == rhs.variables &&
nodes == rhs.nodes &&
hybrids == rhs.hybrids;
}
};
}
#define FASTNOISE_METADATA( ... ) public:\
FASTSIMD_LEVEL_SUPPORT( FastNoise::SUPPORTED_SIMD_LEVELS );\
const FastNoise::Metadata* GetMetadata() const override;\
struct Metadata : __VA_ARGS__::Metadata{\
Generator* NodeFactory( FastSIMD::eLevel ) const override;
#define FASTNOISE_METADATA_ABSTRACT( ... ) public:\
struct Metadata : __VA_ARGS__::Metadata{

View File

@ -0,0 +1,130 @@
#pragma once
#ifndef FASTSIMD_BUILD_CLASS
#error Do not include this file
#endif
#ifndef FASTNOISE_CLASS
#define FASTNOISE_CLASS( CLASS ) FastNoise::CLASS
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/Generator.h"
#else
#include "Generators/Generator.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/BasicGenerators.h"
#else
#include "Generators/BasicGenerators.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/Value.h"
#else
#include "Generators/Value.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/Perlin.h"
#else
#include "Generators/Perlin.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/Simplex.h"
#else
#include "Generators/Simplex.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/Cellular.h"
#else
#include "Generators/Cellular.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/Fractal.h"
#else
#include "Generators/Fractal.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/DomainWarp.h"
#else
#include "Generators/DomainWarp.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/DomainWarpFractal.h"
#else
#include "Generators/DomainWarpFractal.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/Modifiers.h"
#else
#include "Generators/Modifiers.inl"
#endif
#ifdef FASTSIMD_INCLUDE_HEADER_ONLY
#include "Generators/Blends.h"
#else
#include "Generators/Blends.inl"
#endif
// Nodes
// Order is important!
// Always add to bottom of list,
// inserting will break existing encoded node trees
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Constant ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( White ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Checkerboard ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( SineWave ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( PositionOutput ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( DistanceToOrigin ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Value ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Perlin ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Simplex ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( OpenSimplex2 ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( CellularValue ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( CellularDistance ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( CellularLookup ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( FractalFBm ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( FractalBillow ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( FractalRidged ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( FractalRidgedMulti ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( DomainWarpGradient ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( DomainWarpFractalProgressive ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( DomainWarpFractalIndependant ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( DomainScale ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( DomainOffset ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( DomainRotate ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( SeedOffset ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Remap ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( ConvertRGBA8 ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Add ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Subtract ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Multiply ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Divide ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Min ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Max ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( MinSmooth ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( MaxSmooth ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Fade ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( Terrace ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( PowFloat ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( PowInt ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( DomainAxisScale ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( AddDimension ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( RemoveDimension ) )
FASTSIMD_BUILD_CLASS( FASTNOISE_CLASS( GeneratorCache ) )

View File

@ -0,0 +1,20 @@
#pragma once
#include "FastSIMD/FastSIMD.h"
#define FASTNOISE_CALC_MIN_MAX 1
namespace FastNoise
{
const FastSIMD::Level_BitFlags SUPPORTED_SIMD_LEVELS =
FastSIMD::Level_Scalar |
FastSIMD::Level_SSE2 |
FastSIMD::Level_SSE41 |
FastSIMD::Level_AVX2 |
FastSIMD::Level_AVX512 ;
template<typename T = class Generator>
using SmartNode = std::shared_ptr<T>;
template<typename T = class Generator>
using SmartNodeArg = const SmartNode<T>&;
}

View File

@ -0,0 +1,109 @@
#pragma once
#include "Generator.h"
namespace FastNoise
{
class Constant : public virtual Generator
{
public:
void SetValue( float value ) { mValue = value; }
protected:
float mValue = 1.0f;
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Basic Generators" );
this->AddVariable( "Value", 1.0f, &Constant::SetValue );
}
};
};
class White : public virtual Generator
{
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Basic Generators" );
}
};
};
class Checkerboard : public virtual Generator
{
public:
void SetSize( float value ) { mSize = value; }
protected:
float mSize = 1.0f;
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Basic Generators" );
this->AddVariable( "Size", 1.0f, &Checkerboard::SetSize );
}
};
};
class SineWave : public virtual Generator
{
public:
void SetScale( float value ) { mScale = value; }
protected:
float mScale = 1.0f;
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Basic Generators" );
this->AddVariable( "Scale", 1.0f, &SineWave::SetScale );
}
};
};
class PositionOutput : public virtual Generator
{
public:
template<Dim D>
void Set( float multiplier, float offset = 0.0f ) { mMultiplier[(int)D] = multiplier; mOffset[(int)D] = offset; }
protected:
PerDimensionVariable<float> mMultiplier;
PerDimensionVariable<float> mOffset;
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Basic Generators" );
this->AddPerDimensionVariable( "Multiplier", 0.0f, []( PositionOutput* p ) { return std::ref( p->mMultiplier ); } );
this->AddPerDimensionVariable( "Offset", 0.0f, []( PositionOutput* p ) { return std::ref( p->mOffset ); } );
}
};
};
class DistanceToOrigin : public virtual Generator
{
public:
void SetDistanceFunction( DistanceFunction value ) { mDistanceFunction = value; }
protected:
DistanceFunction mDistanceFunction = DistanceFunction::EuclideanSquared;
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Basic Generators" );
this->AddVariableEnum( "Distance Function", DistanceFunction::Euclidean, &DistanceToOrigin::SetDistanceFunction, "Euclidean", "Euclidean Squared", "Manhattan", "Hybrid" );
}
};
};
}

View File

@ -0,0 +1,96 @@
#include <cassert>
#include "FastSIMD/InlInclude.h"
#include "BasicGenerators.h"
#include "Utils.inl"
template<typename FS>
class FS_T<FastNoise::Constant, FS> : public virtual FastNoise::Constant, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return float32v( mValue );
}
};
template<typename FS>
class FS_T<FastNoise::White, FS> : public virtual FastNoise::White, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
size_t idx = 0;
((pos = FS_Casti32_f32( (FS_Castf32_i32( pos ) ^ (FS_Castf32_i32( pos ) >> 16)) * int32v( FnPrimes::Lookup[idx++] ) )), ...);
return FnUtils::GetValueCoord( seed, FS_Castf32_i32( pos )... );
}
};
template<typename FS>
class FS_T<FastNoise::Checkerboard, FS> : public virtual FastNoise::Checkerboard, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
float32v multiplier = FS_Reciprocal_f32( float32v( mSize ) );
int32v value = (FS_Convertf32_i32( pos * multiplier ) ^ ...);
return float32v( 1.0f ) ^ FS_Casti32_f32( value << 31 );
}
};
template<typename FS>
class FS_T<FastNoise::SineWave, FS> : public virtual FastNoise::SineWave, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
float32v multiplier = FS_Reciprocal_f32( float32v( mScale ) );
return (FS_Sin_f32( pos * multiplier ) * ...);
}
};
template<typename FS>
class FS_T<FastNoise::PositionOutput, FS> : public virtual FastNoise::PositionOutput, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
size_t offsetIdx = 0;
size_t multiplierIdx = 0;
(((pos += float32v( mOffset[offsetIdx++] )) *= float32v( mMultiplier[multiplierIdx++] )), ...);
return (pos + ...);
}
};
template<typename FS>
class FS_T<FastNoise::DistanceToOrigin, FS> : public virtual FastNoise::DistanceToOrigin, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return FnUtils::CalcDistance( mDistanceFunction, pos... );
}
};

View File

@ -0,0 +1,198 @@
#pragma once
#include "Generator.h"
#include <climits>
namespace FastNoise
{
class OperatorSourceLHS : public virtual Generator
{
public:
void SetLHS( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mLHS, gen ); }
void SetRHS( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mRHS, gen ); }
void SetRHS( float value ) { mRHS = value; }
protected:
GeneratorSource mLHS;
HybridSource mRHS;
FASTNOISE_METADATA_ABSTRACT( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Blends" );
this->AddGeneratorSource( "LHS", &OperatorSourceLHS::SetLHS );
this->AddHybridSource( "RHS", 0.0f, &OperatorSourceLHS::SetRHS, &OperatorSourceLHS::SetRHS );
}
};
};
class OperatorHybridLHS : public virtual Generator
{
public:
void SetLHS( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mLHS, gen ); }
void SetLHS( float value ) { mLHS = value; }
void SetRHS( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mRHS, gen ); }
void SetRHS( float value ) { mRHS = value; }
protected:
HybridSource mLHS;
HybridSource mRHS;
FASTNOISE_METADATA_ABSTRACT( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Blends" );
this->AddHybridSource( "LHS", 0.0f, &OperatorHybridLHS::SetLHS, &OperatorHybridLHS::SetLHS );
this->AddHybridSource( "RHS", 0.0f, &OperatorHybridLHS::SetRHS, &OperatorHybridLHS::SetRHS );
}
};
};
class Add : public virtual OperatorSourceLHS
{
FASTNOISE_METADATA( OperatorSourceLHS )
using OperatorSourceLHS::Metadata::Metadata;
};
};
class Subtract : public virtual OperatorHybridLHS
{
FASTNOISE_METADATA( OperatorHybridLHS )
using OperatorHybridLHS::Metadata::Metadata;
};
};
class Multiply : public virtual OperatorSourceLHS
{
FASTNOISE_METADATA( OperatorSourceLHS )
using OperatorSourceLHS::Metadata::Metadata;
};
};
class Divide : public virtual OperatorHybridLHS
{
FASTNOISE_METADATA( OperatorHybridLHS )
using OperatorHybridLHS::Metadata::Metadata;
};
};
class Min : public virtual OperatorSourceLHS
{
FASTNOISE_METADATA( OperatorSourceLHS )
using OperatorSourceLHS::Metadata::Metadata;
};
};
class Max : public virtual OperatorSourceLHS
{
FASTNOISE_METADATA( OperatorSourceLHS )
using OperatorSourceLHS::Metadata::Metadata;
};
};
class PowFloat : public virtual Generator
{
public:
void SetValue( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mValue, gen ); }
void SetValue( float value ) { mValue = value; }
void SetPow( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mPow, gen ); }
void SetPow( float value ) { mPow = value; }
protected:
HybridSource mValue;
HybridSource mPow;
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Blends" );
this->AddHybridSource( "Value", 2.0f, &PowFloat::SetValue, &PowFloat::SetValue );
this->AddHybridSource( "Pow", 2.0f, &PowFloat::SetPow, &PowFloat::SetPow );
}
};
};
class PowInt : public virtual OperatorHybridLHS
{
public:
void SetValue( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mValue, gen ); }
void SetPow( int32_t value ) { mPow = value; }
protected:
GeneratorSource mValue;
int32_t mPow;
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Blends" );
this->AddGeneratorSource( "Value", &PowInt::SetValue );
this->AddVariable( "Pow", 2, &PowInt::SetPow, 2, INT_MAX );
}
};
};
class MinSmooth : public virtual OperatorSourceLHS
{
public:
void SetSmoothness( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mSmoothness, gen ); }
void SetSmoothness( float value ) { mSmoothness = value; }
protected:
HybridSource mSmoothness = 0.1f;
FASTNOISE_METADATA( OperatorSourceLHS )
Metadata( const char* className ) : OperatorSourceLHS::Metadata( className )
{
this->AddHybridSource( "Smoothness", 0.1f, &MinSmooth::SetSmoothness, &MinSmooth::SetSmoothness );
}
};
};
class MaxSmooth : public virtual OperatorSourceLHS
{
public:
void SetSmoothness( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mSmoothness, gen ); }
void SetSmoothness( float value ) { mSmoothness = value; }
protected:
HybridSource mSmoothness = 0.1f;
FASTNOISE_METADATA( OperatorSourceLHS )
Metadata( const char* className ) : OperatorSourceLHS::Metadata( className )
{
this->AddHybridSource( "Smoothness", 0.1f, &MaxSmooth::SetSmoothness, &MaxSmooth::SetSmoothness );
}
};
};
class Fade : public virtual Generator
{
public:
void SetA( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mA, gen ); }
void SetB( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mB, gen ); }
void SetFade( SmartNodeArg<> gen ) { this->SetSourceMemberVariable( mFade, gen ); }
void SetFade( float value ) { mFade = value; }
protected:
GeneratorSource mA;
GeneratorSource mB;
HybridSource mFade = 0.5f;
FASTNOISE_METADATA( Generator )
Metadata( const char* className ) : Generator::Metadata( className )
{
groups.push_back( "Blends" );
this->AddGeneratorSource( "A", &Fade::SetA );
this->AddGeneratorSource( "B", &Fade::SetB );
this->AddHybridSource( "Fade", 0.5f, &Fade::SetFade, &Fade::SetFade );
}
};
};
}

View File

@ -0,0 +1,174 @@
#include "FastSIMD/InlInclude.h"
#include "Blends.h"
template<typename FS>
class FS_T<FastNoise::Add, FS> : public virtual FastNoise::Add, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return this->GetSourceValue( mLHS, seed, pos... ) + this->GetSourceValue( mRHS, seed, pos... );
}
};
template<typename FS>
class FS_T<FastNoise::Subtract, FS> : public virtual FastNoise::Subtract, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return this->GetSourceValue( mLHS, seed, pos... ) - this->GetSourceValue( mRHS, seed, pos... );
}
};
template<typename FS>
class FS_T<FastNoise::Multiply, FS> : public virtual FastNoise::Multiply, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return this->GetSourceValue( mLHS, seed, pos... ) * this->GetSourceValue( mRHS, seed, pos... );
}
};
template<typename FS>
class FS_T<FastNoise::Divide, FS> : public virtual FastNoise::Divide, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return this->GetSourceValue( mLHS, seed, pos... ) / this->GetSourceValue( mRHS, seed, pos... );
}
};
template<typename FS>
class FS_T<FastNoise::PowFloat, FS> : public virtual FastNoise::PowFloat, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return FS_Pow_f32( this->GetSourceValue( mValue, seed, pos... ), this->GetSourceValue( mPow, seed, pos... ) );
}
};
template<typename FS>
class FS_T<FastNoise::PowInt, FS> : public virtual FastNoise::PowInt, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
float32v value = this->GetSourceValue( mValue, seed, pos... );
float32v pow = value * value;
for( int32_t i = 2; i < mPow; i++ )
{
pow *= value;
}
return pow;
}
};
template<typename FS>
class FS_T<FastNoise::Min, FS> : public virtual FastNoise::Min, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return FS_Min_f32( this->GetSourceValue( mLHS, seed, pos... ), this->GetSourceValue( mRHS, seed, pos... ) );
}
};
template<typename FS>
class FS_T<FastNoise::Max, FS> : public virtual FastNoise::Max, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
return FS_Max_f32( this->GetSourceValue( mLHS, seed, pos... ), this->GetSourceValue( mRHS, seed, pos... ) );
}
};
template<typename FS>
class FS_T<FastNoise::MinSmooth, FS> : public virtual FastNoise::MinSmooth, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;
FASTNOISE_IMPL_GEN_T;
template<typename... P>
FS_INLINE float32v GenT( int32v seed, P... pos ) const
{
float32v a = this->GetSourceValue( mLHS, seed, pos... );
float32v b = this->GetSourceValue( mRHS, seed, pos... );
float32v smoothness = FS_Max_f32( float32v( 1.175494351e-38f ), FS_Abs_f32( this->GetSourceValue( mSmoothness, seed, pos... ) ) );
float32v h = FS_Max_f32( smoothness - FS_Abs_f32( a - b ), float32v( 0.0f ) );
h *= FS_Reciprocal_f32( smoothness );
return FS_FNMulAdd_f32( float32v( 1.0f / 6.0f ), h * h * h * smoothness, FS_Min_f32( a, b ) );
}
};
template<typename FS>
class FS_T<FastNoise::MaxSmooth, FS> : public virtual FastNoise::MaxSmooth, public FS_T<FastNoise::Generator, FS>
{
FASTSIMD_DECLARE_FS_TYPES;