├── .gitattributes ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── Configurations.cmake ├── Demos ├── Bin2C │ ├── Bin2C.vcxproj │ ├── Bin2C.vcxproj.filters │ ├── CMakeLists.txt │ └── main.cpp ├── CMakeLists.txt ├── MusicSynthesizer │ ├── CMakeLists.txt │ ├── EmscriptenInterface.cpp │ ├── InstrumentLibrary.cpp │ ├── InstrumentLibrary.h │ ├── MidiInstrumentMapping.cpp │ ├── MidiInstrumentMapping.h │ ├── MusicSynthesizer.cpp │ ├── MusicSynthesizer.vcxproj │ ├── MusicSynthesizer.vcxproj.filters │ ├── MusicSynthesizerCommon.cpp │ └── MusicSynthesizerCommon.h ├── Tests │ ├── CMakeLists.txt │ ├── Tests.filters │ ├── Tests.user │ ├── Tests.vcxproj │ ├── Tests.vcxproj.filters │ └── src │ │ ├── Container │ │ ├── Array.cpp │ │ ├── Array.h │ │ ├── Map.cpp │ │ ├── Map.h │ │ ├── String.cpp │ │ └── String.h │ │ ├── PerfTestRandom.cpp │ │ ├── PerfTestRandom.h │ │ ├── PerfTestSerialization.cpp │ │ ├── PerfTestSerialization.h │ │ ├── PerfTestSort.cpp │ │ ├── PerfTestSort.h │ │ ├── PerfTesting.cpp │ │ └── Range │ │ ├── Header.h │ │ └── Polymorphic.cpp └── UnitTests │ ├── CMakeLists.txt │ ├── Delegate.cpp │ ├── UnitTests.filters │ ├── UnitTests.vcxproj │ ├── UnitTests.vcxproj.filters │ └── src │ ├── Concurrency │ ├── Atomic.cpp │ ├── Concurrency.h │ └── Interruption.cpp │ ├── Container │ ├── HashMap.cpp │ ├── HashMap.h │ ├── SparseArray.cpp │ └── SparseArray.h │ ├── IO │ ├── File.cpp │ ├── IO.h │ └── Socket.cpp │ ├── Range │ ├── Composing.cpp │ ├── Heap.cpp │ ├── Polymorphic.cpp │ ├── Range.h │ ├── StlInterop.cpp │ ├── Streams.cpp │ └── Unicode.cpp │ ├── Serialization.cpp │ ├── Serialization.h │ ├── Sort.cpp │ ├── Sort.h │ └── UnitTests.cpp ├── Intra ├── Audio.hh ├── Audio │ ├── AudioBuffer.cpp │ ├── AudioBuffer.h │ ├── AudioProcessing.cpp │ ├── AudioProcessing.h │ ├── AudioSource.cpp │ ├── AudioSource.h │ ├── CMakeLists.txt │ ├── Midi │ │ ├── DeviceState.cpp │ │ ├── DeviceState.h │ │ ├── Messages.h │ │ ├── Midi.natvis │ │ ├── MidiFileParser.cpp │ │ ├── MidiFileParser.h │ │ ├── RawEvent.cpp │ │ ├── RawEvent.h │ │ ├── TrackCombiner.cpp │ │ ├── TrackCombiner.h │ │ ├── TrackParser.cpp │ │ └── TrackParser.h │ ├── MusicNote.cpp │ ├── MusicNote.h │ ├── Resample.cpp │ ├── Resample.h │ ├── SampleConversion.cpp │ ├── SampleConversion.h │ ├── Sound.cpp │ ├── Sound.h │ ├── SoundDriverInfo.cpp │ ├── SoundDriverInfo.h │ ├── SoundTypes.h │ ├── Sources.hh │ ├── Sources │ │ ├── MidiSynth.cpp │ │ ├── MidiSynth.h │ │ ├── Vorbis.cpp │ │ ├── Vorbis.h │ │ ├── Wave.cpp │ │ └── Wave.h │ ├── Synth.hh │ ├── Synth │ │ ├── ADSR.cpp │ │ ├── ADSR.h │ │ ├── Chorus.cpp │ │ ├── Chorus.h │ │ ├── ExponentialAttenuation.cpp │ │ ├── ExponentialAttenuation.h │ │ ├── Filter.cpp │ │ ├── Filter.h │ │ ├── Generators.hh │ │ ├── Generators │ │ │ ├── DrumPhysicalModel.cpp │ │ │ ├── DrumPhysicalModel.h │ │ │ ├── FunctionGenerator.h │ │ │ ├── Pulse.h │ │ │ ├── Sawtooth.h │ │ │ ├── Square.h │ │ │ ├── ViolinPhysicalModel.h │ │ │ └── WhiteNoise.h │ │ ├── InstrumentSet.cpp │ │ ├── InstrumentSet.h │ │ ├── MusicalInstrument.cpp │ │ ├── MusicalInstrument.h │ │ ├── NoteSampler.cpp │ │ ├── NoteSampler.h │ │ ├── Octaves.cpp │ │ ├── Octaves.h │ │ ├── PostEffects.cpp │ │ ├── PostEffects.hh │ │ ├── RecordedSampler.cpp │ │ ├── RecordedSampler.h │ │ ├── Types.h │ │ ├── WaveTable.cpp │ │ ├── WaveTable.h │ │ ├── WaveTableGeneration.cpp │ │ ├── WaveTableGeneration.h │ │ ├── WaveTableSampler.cpp │ │ ├── WaveTableSampler.h │ │ ├── WhiteNoiseSampler.cpp │ │ └── WhiteNoiseSampler.h │ └── detail │ │ ├── SoundALSA.hxx │ │ ├── SoundBasicData.hxx │ │ ├── SoundDirectSound.hxx │ │ ├── SoundDummy.hxx │ │ ├── SoundOpenAL.hxx │ │ └── SoundWebAudio.hxx ├── CMakeLists.txt ├── Concepts.hh ├── Concepts │ ├── Array.h │ ├── Container.h │ ├── IInput.h │ ├── IOutput.h │ ├── Iterator.h │ ├── Range.h │ └── RangeOf.h ├── Concurrency │ ├── Atomic.h │ ├── CMakeLists.txt │ ├── Concurrency.natvis │ ├── CondVar.cpp │ ├── CondVar.h │ ├── Job.cpp │ ├── Job.h │ ├── Lock.h │ ├── Mutex.cpp │ ├── Mutex.h │ ├── Synchronized.h │ ├── Thread.cpp │ ├── Thread.h │ ├── ThreadPool.h │ └── detail │ │ ├── AtomicCpp11.h │ │ ├── AtomicGNU.h │ │ ├── AtomicMSVC.h │ │ ├── BasicThreadData.hxx │ │ ├── CondVarCpp11.hxx │ │ ├── CondVarPThread.hxx │ │ ├── CondVarWinAPI.hxx │ │ ├── CondVarWinXP.hxx │ │ ├── MutexCpp11.hxx │ │ ├── MutexPThread.hxx │ │ ├── MutexWinAPI.hxx │ │ ├── ThreadCommonWinAPI.hxx │ │ ├── ThreadCpp11.hxx │ │ ├── ThreadPThread.hxx │ │ ├── ThreadSleep.hxx │ │ └── ThreadWinAPI.hxx ├── Container.hh ├── Container │ ├── AllForwardDecls.h │ ├── Associative.hh │ ├── Associative │ │ ├── HashMap.h │ │ ├── LinearMap.h │ │ └── LinearSet.h │ ├── Container.natvis │ ├── ForwardDecls.h │ ├── Operations.hh │ ├── Operations │ │ ├── Append.h │ │ ├── Comparison.h │ │ └── Info.h │ ├── ReadMe.md │ ├── Sequential.hh │ ├── Sequential │ │ ├── Array.h │ │ ├── ExtArray.h │ │ ├── List.h │ │ ├── String.h │ │ ├── StringFormatter.h │ │ └── StructureOfArrays.h │ ├── Utility.hh │ └── Utility │ │ ├── Array2D.h │ │ ├── IndexAllocator.h │ │ ├── IntervalAllocator.h │ │ ├── OwningArrayRange.h │ │ ├── SparseArray.h │ │ ├── SparseHandledArray.h │ │ ├── SparseRange.h │ │ ├── SparseRange.inl │ │ ├── StaticBitset.h │ │ └── Tree.h ├── Cpp.hh ├── Cpp │ ├── CMakeLists.txt │ ├── Compatibility.h │ ├── Cpp.natvis │ ├── Endianess.h │ ├── Features.h │ ├── Fundamental.h │ ├── InfNan.h │ ├── InitializerList.h │ ├── Intrinsics.h │ ├── PlacementNew.h │ ├── PlatformDetect.h │ ├── Runtime.cpp │ ├── Runtime.h │ ├── SharedLib.h │ └── Warnings.h ├── Data.hh ├── Data │ ├── BinarySerialization.cpp │ ├── Data.cpp │ ├── Format.h │ ├── Format │ │ ├── BinaryParser.h │ │ ├── BinaryRaw.h │ │ └── TextParser.h │ ├── Object.h │ ├── Reflection.cpp │ ├── Reflection.h │ ├── Serialization.hh │ ├── Serialization │ │ ├── BinaryDeserializer.h │ │ ├── BinarySerializer.h │ │ ├── LanguageParams.cpp │ │ ├── LanguageParams.h │ │ ├── TextDeserializer.h │ │ ├── TextSerializer.h │ │ ├── TextSerializerParams.cpp │ │ └── TextSerializerParams.h │ ├── ValueType.cpp │ ├── ValueType.h │ ├── Variable.cpp │ └── Variable.h ├── Font │ ├── CMakeLists.txt │ ├── FontLoading.cpp │ ├── FontLoading.h │ ├── FontLoadingDeclarations.h │ └── FontLoading_STB.cpp ├── Funal │ ├── Bind.h │ ├── Delegate.h │ ├── Funal.natvis │ ├── FuncRef.h │ ├── Functor.h │ ├── Method.h │ ├── ObjectMethod.h │ ├── Op.h │ └── ValueRef.h ├── Hash.hh ├── Hash │ ├── Murmur.cpp │ ├── Murmur.h │ ├── MurmurCT.h │ ├── StringHash.h │ ├── ToHash.h │ └── Types.h ├── IO.hh ├── IO │ ├── CMakeLists.txt │ ├── ConsoleInput.cpp │ ├── ConsoleInput.h │ ├── ConsoleOutput.cpp │ ├── ConsoleOutput.h │ ├── FileMapping.cpp │ ├── FileMapping.h │ ├── FilePath.cpp │ ├── FilePath.h │ ├── FileReader.h │ ├── FileSystem.cpp │ ├── FileSystem.h │ ├── FileWriter.h │ ├── FormattedLogger.cpp │ ├── FormattedLogger.h │ ├── FormattedWriter.h │ ├── Formatter.h │ ├── HtmlWriter.cpp │ ├── HtmlWriter.h │ ├── IO.natvis │ ├── Networking.cpp │ ├── Networking.h │ ├── OsFile.cpp │ ├── OsFile.h │ ├── Socket.cpp │ ├── Socket.h │ ├── SocketReader.h │ ├── SocketWriter.h │ ├── Std.cpp │ └── Std.h ├── Image │ ├── AnyImage.cpp │ ├── AnyImage.h │ ├── Bindings.hh │ ├── Bindings │ │ ├── DXGI_Formats.cpp │ │ ├── DXGI_Formats.h │ │ ├── GLenumFormats.cpp │ │ └── GLenumFormats.h │ ├── CMakeLists.txt │ ├── Font.hh │ ├── FormatConversion.cpp │ ├── FormatConversion.h │ ├── Image.hh │ ├── Image.natvis │ ├── ImageFormat.cpp │ ├── ImageFormat.h │ ├── ImageInfo.cpp │ ├── ImageInfo.h │ ├── Loaders.hh │ └── Loaders │ │ ├── Loader.cpp │ │ ├── Loader.h │ │ ├── LoaderBMP.cpp │ │ ├── LoaderBMP.h │ │ ├── LoaderDDS.cpp │ │ ├── LoaderDDS.h │ │ ├── LoaderGIF.cpp │ │ ├── LoaderGIF.h │ │ ├── LoaderJPEG.cpp │ │ ├── LoaderJPEG.h │ │ ├── LoaderKTX.cpp │ │ ├── LoaderKTX.h │ │ ├── LoaderPNG.cpp │ │ ├── LoaderPNG.h │ │ ├── LoaderPlatform.cpp │ │ ├── LoaderPlatform.h │ │ ├── LoaderTGA.cpp │ │ ├── LoaderTGA.h │ │ ├── LoaderTIFF.cpp │ │ ├── LoaderTIFF.h │ │ └── detail │ │ ├── LoaderDevIL.hxx │ │ ├── LoaderGdiplus.hxx │ │ └── LoaderQt.hxx ├── Intra.natstepfilter ├── Intra.vcxproj ├── Intra.vcxproj.filters ├── Math.hh ├── Math │ ├── Bit.h │ ├── ExponentRange.h │ ├── FixedPoint.h │ ├── Geometry.hh │ ├── Geometry │ │ ├── Aabb.h │ │ ├── BoundingVolume.h │ │ ├── Ellipse.h │ │ ├── Frustum.h │ │ ├── Intersection.h │ │ ├── Line.h │ │ ├── LineSegment.h │ │ ├── Obb.h │ │ ├── Plane.h │ │ ├── Ray.h │ │ ├── Sphere.h │ │ └── Triangle.h │ ├── HalfFloat.h │ ├── Math.h │ ├── Math.natvis │ ├── Matrix3.h │ ├── Matrix4.h │ ├── Quaternion.h │ ├── SineRange.h │ ├── Vector2.h │ ├── Vector3.h │ └── Vector4.h ├── Memory.hh ├── Memory │ ├── Align.h │ ├── Allocator.hh │ ├── Allocator │ │ ├── AllocatorRef.h │ │ ├── Basic.hh │ │ ├── Basic │ │ │ ├── Linear.h │ │ │ ├── Pool.cpp │ │ │ ├── Pool.h │ │ │ ├── Stack.cpp │ │ │ └── Stack.h │ │ ├── Compositors.hh │ │ ├── Compositors │ │ │ └── SegregatedPools.h │ │ ├── Concepts.h │ │ ├── Decorators.hh │ │ ├── Decorators │ │ │ ├── BoundsChecked.h │ │ │ ├── CallOnFail.h │ │ │ ├── Counted.h │ │ │ ├── GrowingPool.h │ │ │ ├── Sized.h │ │ │ ├── Static.h │ │ │ └── Synchronized.h │ │ ├── Global.cpp │ │ ├── Global.h │ │ ├── Polymorphic.h │ │ ├── System.cpp │ │ └── System.h │ ├── Memory.cpp │ ├── Memory.h │ ├── VirtualMemory.cpp │ └── VirtualMemory.h ├── Meta.hh ├── Meta │ ├── CMakeLists.txt │ ├── EachField.h │ ├── GetField.h │ ├── Meta.natvis │ ├── Operators.h │ ├── Pair.h │ ├── Tuple.h │ ├── Type.h │ └── TypeList.h ├── Preprocessor.hh ├── Preprocessor │ ├── Macro2ForEach.h │ ├── Macro2ForEachIndex.h │ ├── Operations.h │ └── VariadicCommon.h ├── Random │ ├── FastUniform.h │ └── FastUniformNoise.h ├── Range.hh ├── Range │ ├── Comparison.hh │ ├── Comparison │ │ ├── EndsWith.h │ │ ├── Equals.h │ │ ├── LexCompare.h │ │ └── StartsWith.h │ ├── Compositors.hh │ ├── Compositors │ │ ├── AssociativeRange.h │ │ ├── Chain.h │ │ ├── Choose.h │ │ ├── Indexed.h │ │ ├── RoundRobin.h │ │ ├── Unzip.h │ │ ├── Zip.h │ │ └── ZipKV.h │ ├── Decorators.hh │ ├── Decorators │ │ ├── Buffered.h │ │ ├── ByLine.h │ │ ├── ByLineTo.h │ │ ├── Chunks.h │ │ ├── Cycle.h │ │ ├── Filter.h │ │ ├── Join.h │ │ ├── Map.h │ │ ├── Retro.h │ │ ├── Split.h │ │ ├── Stride.h │ │ ├── Take.h │ │ ├── TakeByLine.h │ │ ├── TakeUntil.h │ │ ├── TakeUntilAny.h │ │ └── Transversal.h │ ├── ForEach.h │ ├── ForwardDecls.h │ ├── Generators.hh │ ├── Generators │ │ ├── Count.h │ │ ├── FlatArrayOfArraysRange.h │ │ ├── Generate.h │ │ ├── Iota.h │ │ ├── ListRange.h │ │ ├── Null.h │ │ ├── Recurrence.h │ │ ├── Repeat.h │ │ ├── Sequence.h │ │ └── ZStringRange.h │ ├── Iterator.hh │ ├── Iterator │ │ └── RangeForwardIterator.h │ ├── Mutation.hh │ ├── Mutation │ │ ├── Cast.cpp │ │ ├── Cast.h │ │ ├── Copy.h │ │ ├── CopyUntil.h │ │ ├── Fill.h │ │ ├── Heap.h │ │ ├── Interleave.h │ │ ├── Remove.h │ │ ├── Replace.h │ │ ├── ReplaceSubrange.h │ │ ├── Transform.cpp │ │ ├── Transform.h │ │ └── Union.h │ ├── Operations.h │ ├── Output.hh │ ├── Output │ │ ├── Inserter.h │ │ └── OutputArrayRange.h │ ├── Polymorphic.hh │ ├── Polymorphic │ │ ├── BidirectionalRange.h │ │ ├── FiniteForwardRange.h │ │ ├── FiniteInputRange.h │ │ ├── FiniteRandomAccessRange.h │ │ ├── ForwardRange.h │ │ ├── InputRange.h │ │ ├── OutputRange.h │ │ └── RandomAccessRange.h │ ├── Range.natvis │ ├── RangeConstruction.natvis │ ├── RangeIteration.natvis │ ├── RangePolymorphic.natvis │ ├── ReadMe.md │ ├── Reduction.cpp │ ├── Reduction.h │ ├── Search.hh │ ├── Search │ │ ├── Binary.h │ │ ├── Distance.h │ │ ├── RecursiveBlock.h │ │ ├── Single.h │ │ ├── Subrange.h │ │ └── Trim.h │ ├── Sort.hh │ ├── Sort │ │ ├── Heap.h │ │ ├── Insertion.h │ │ ├── IsSorted.h │ │ ├── Merge.h │ │ ├── Quick.h │ │ ├── Radix.h │ │ └── Selection.h │ ├── Special.hh │ ├── Special │ │ ├── Unicode.cpp │ │ └── Unicode.h │ ├── Stream.hh │ ├── Stream │ │ ├── InputStreamMixin.h │ │ ├── MaxLengthOfToString.h │ │ ├── OutputStreamMixin.h │ │ ├── Parse.h │ │ ├── RawRead.h │ │ ├── RawWrite.h │ │ ├── Spaces.h │ │ ├── ToString.h │ │ └── ToStringArithmetic.h │ ├── String.hh │ ├── String │ │ ├── Ascii.cpp │ │ ├── Ascii.h │ │ └── Escape.h │ └── TupleOperation.h ├── Simd │ └── Simd.h ├── Stream.hh ├── System.hh ├── System │ ├── DLL.cpp │ ├── DLL.h │ ├── DateTime.cpp │ ├── DateTime.h │ ├── Environment.cpp │ ├── Environment.h │ ├── ProcessorInfo.cpp │ ├── ProcessorInfo.h │ ├── RamInfo.cpp │ ├── RamInfo.h │ ├── Signal.cpp │ ├── Signal.h │ ├── Stopwatch.cpp │ ├── Stopwatch.h │ ├── System.natvis │ └── detail │ │ ├── Common.cpp │ │ └── Common.h ├── Test.hh ├── Test │ ├── PerfSummary.cpp │ ├── PerfSummary.h │ ├── TestData.h │ ├── TestGroup.cpp │ └── TestGroup.h ├── Utils.hh └── Utils │ ├── AnyPtr.h │ ├── ArrayAlgo.h │ ├── AsciiSet.h │ ├── Debug.cpp │ ├── Debug.h │ ├── ErrorStatus.h │ ├── Finally.h │ ├── FixedArray.h │ ├── IteratorRange.h │ ├── Logger.h │ ├── Optional.h │ ├── Promise.h │ ├── Shared.h │ ├── Span.h │ ├── StringView.h │ ├── Unique.h │ └── Utils.natvis ├── LICENSE ├── ReadMe.md ├── SetupMSVC.bat └── Solution.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | */Makefile 4 | cmake_install.cmake 5 | Intra.UB.cc 6 | libIntra.a 7 | Intra.lib 8 | *.exe 9 | TestFileSyncIO.txt 10 | Demos/MusicSynthesizer/MusicSynthesizer 11 | Demos/Bin2C/Bin2C 12 | Demos/Tests/Tests 13 | Demos/UnitTests/UnitTests 14 | 15 | /Demos/EngineDemo/ 16 | /IgnoredModules/ 17 | .vs/ 18 | 19 | *.ilk 20 | *.iobj 21 | *.ipdb 22 | *.pdb 23 | *.VC.db 24 | *.VC.VC.opendb 25 | logs.html 26 | *.map 27 | /Build 28 | *.vcxproj.user 29 | *.psess 30 | *.vspx 31 | ipch/ 32 | *.kernel.etl 33 | *.tmp.merged.etl 34 | logs*.html 35 | Tests*.exe 36 | 37 | 38 | # Windows image file caches 39 | Thumbs.db 40 | ehthumbs.db 41 | 42 | # Folder config file 43 | Desktop.ini 44 | 45 | # Recycle Bin used on file shares 46 | $RECYCLE.BIN/ 47 | 48 | # Windows Installer files 49 | *.cab 50 | *.msi 51 | *.msm 52 | *.msp 53 | 54 | # Windows shortcuts 55 | *.lnk 56 | 57 | # ========================= 58 | # Operating System Files 59 | # ========================= 60 | 61 | # OSX 62 | # ========================= 63 | 64 | .DS_Store 65 | .AppleDouble 66 | .LSOverride 67 | 68 | # Thumbnails 69 | ._* 70 | 71 | # Files that might appear in the root of a volume 72 | .DocumentRevisions-V100 73 | .fseventsd 74 | .Spotlight-V100 75 | .TemporaryItems 76 | .Trashes 77 | .VolumeIcon.icns 78 | 79 | # Directories potentially created on remote AFP share 80 | .AppleDB 81 | .AppleDesktop 82 | Network Trash Folder 83 | Temporary Items 84 | .apdisk 85 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - gcc 4 | - clang 5 | env: 6 | - CMAKE_PARAMS="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_EXCEPTIONS=1 -DUNITY_BUILD=ON" 7 | - CMAKE_PARAMS="-DCMAKE_BUILD_TYPE=Release -DUNITY_BUILD=OFF" 8 | - CMAKE_PARAMS="-DCMAKE_BUILD_TYPE=Debug -DUSE_EXCEPTIONS=1" 9 | dist: trusty 10 | sudo: false 11 | script: cmake -G"Unix Makefiles" $CMAKE_PARAMS && make -j2 && Demos/UnitTests/UnitTests -aus 12 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | add_subdirectory(Intra) 4 | add_subdirectory(Demos) 5 | -------------------------------------------------------------------------------- /Demos/Bin2C/Bin2C.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Файлы исходного кода 20 | 21 | 22 | -------------------------------------------------------------------------------- /Demos/Bin2C/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(Bin2C) 4 | 5 | include(../../Configurations.cmake) 6 | 7 | include_directories(../../Intra) 8 | 9 | file(GLOB_RECURSE BIN2C_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.h) 10 | file(GLOB_RECURSE BIN2C_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.cpp) 11 | 12 | add_executable(Bin2C ${BIN2C_HEADERS} ${BIN2C_SOURCES}) 13 | 14 | target_link_libraries(Bin2C Intra) 15 | -------------------------------------------------------------------------------- /Demos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | add_subdirectory(Bin2C) 4 | add_subdirectory(MusicSynthesizer) 5 | add_subdirectory(Tests) 6 | add_subdirectory(UnitTests) 7 | -------------------------------------------------------------------------------- /Demos/MusicSynthesizer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | include(../../Configurations.cmake) 4 | 5 | if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") 6 | set(COMMON_EMSCRIPTEN_PARAMETERS "-s NO_EXIT_RUNTIME=1 -s TOTAL_MEMORY=134217728 -s NO_FILESYSTEM=1 -s EXPORTED_RUNTIME_METHODS=\"['UTF8ToString', 'HEAPF32', '_free', '_malloc', 'HEAPU8']\" -s EXPORTED_FUNCTIONS=\"['UTF8ToString', 'HEAPF32', '_free', '_malloc', 'HEAPU8']\"") 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_EMSCRIPTEN_PARAMETERS}") 8 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COMMON_EMSCRIPTEN_PARAMETERS}") 9 | set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${COMMON_EMSCRIPTEN_PARAMETERS}") 10 | set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COMMON_EMSCRIPTEN_PARAMETERS}") 11 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMMON_EMSCRIPTEN_PARAMETERS}") 12 | endif() 13 | 14 | project(MusicSynthesizer) 15 | 16 | include_directories(../../Intra) 17 | 18 | file(GLOB_RECURSE MUSIC_SYNTH_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.h) 19 | file(GLOB_RECURSE MUSIC_SYNTH_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" *.cpp) 20 | 21 | add_executable(MusicSynthesizer ${MUSIC_SYNTH_HEADERS} ${MUSIC_SYNTH_SOURCES}) 22 | 23 | target_link_libraries(MusicSynthesizer Intra) 24 | -------------------------------------------------------------------------------- /Demos/MusicSynthesizer/InstrumentLibrary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | 5 | #include "Audio/Synth/MusicalInstrument.h" 6 | #include "Audio/Synth/Types.h" 7 | #include "Audio/Synth/RecordedSampler.h" 8 | #include "Audio/Synth/WaveTable.h" 9 | 10 | #include "Container/Sequential/String.h" 11 | #include "Container/Associative/HashMap.h" 12 | 13 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 14 | 15 | using Intra::Audio::Synth::MusicalInstrument; 16 | using Intra::Audio::Synth::RecordedSampler; 17 | using Intra::Audio::Synth::GenericDrumInstrument; 18 | using Intra::Audio::Synth::WaveTable; 19 | using Intra::Audio::Synth::WaveTableCache; 20 | using Intra::HashMap; 21 | using Intra::String; 22 | 23 | struct InstrumentLibrary 24 | { 25 | InstrumentLibrary(); 26 | ~InstrumentLibrary(); 27 | 28 | InstrumentLibrary(const InstrumentLibrary&) = delete; 29 | InstrumentLibrary& operator=(const InstrumentLibrary&) = delete; 30 | 31 | HashMap Tables; 32 | 33 | HashMap Instruments; 34 | 35 | MusicalInstrument* operator[](const String& str) 36 | { 37 | auto found = Instruments.Find(str); 38 | if(found.Empty()) 39 | return nullptr; 40 | return &found.First().Value; 41 | } 42 | 43 | GenericDrumInstrument UniDrum, AcousticBassDrum, ClosedHiHat; 44 | 45 | static MusicalInstrument CreateGuitar(size_t n=15, float c=128, float d=1.5, 46 | float e=0.75, float f=1, float freqMult=0.5f, float volume=0.6f, float ttackTime=0.005f, float releaseTime=0.2f); 47 | }; 48 | 49 | 50 | INTRA_WARNING_POP 51 | -------------------------------------------------------------------------------- /Demos/MusicSynthesizer/MidiInstrumentMapping.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Demos/MusicSynthesizer/MidiInstrumentMapping.cpp -------------------------------------------------------------------------------- /Demos/MusicSynthesizer/MidiInstrumentMapping.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Intra { namespace Audio { namespace Synth { 4 | 5 | struct MidiInstrumentSet; 6 | 7 | }}} 8 | 9 | Intra::Audio::Synth::MidiInstrumentSet GetMapping(); 10 | 11 | -------------------------------------------------------------------------------- /Demos/MusicSynthesizer/MusicSynthesizerCommon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utils/StringView.h" 4 | #include "Utils/ErrorStatus.h" 5 | #include "Utils/Unique.h" 6 | 7 | #include "Container/ForwardDecls.h" 8 | 9 | #include "Range/Polymorphic/ForwardRange.h" 10 | 11 | #include "Audio/Midi/MidiFileParser.h" 12 | 13 | namespace Intra { namespace Audio { 14 | 15 | struct Music; 16 | class Sound; 17 | class StreamedSound; 18 | class IAudioSource; 19 | 20 | namespace Midi { 21 | struct MidiFileInfo; 22 | } 23 | 24 | }} 25 | 26 | Intra::String GetMidiPath(Intra::StringView fileName); 27 | Intra::Audio::Midi::MidiFileInfo PrintMidiInfo(Intra::InputStream midiFileStream, Intra::ErrorStatus& status); 28 | bool PrintMidiFileInfo(Intra::StringView filePath); 29 | Intra::Unique CreateMidiAudioSource(Intra::InputStream stream, 30 | double duration, float startingVolume, Intra::ErrorStatus& status, Intra::uint sampleRate = 0); 31 | Intra::Audio::Sound CreateSoundFromMidi(Intra::ForwardStream midiFiletream, double duration, float startingVolume, bool printMessages); 32 | Intra::Audio::StreamedSound CreateStreamedSoundFromMidi(Intra::ForwardStream midiFiletream, float startingVolume, bool printMessages); 33 | 34 | -------------------------------------------------------------------------------- /Demos/Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(Tests) 4 | 5 | include(../../Configurations.cmake) 6 | 7 | include_directories(../../Intra) 8 | 9 | file(GLOB_RECURSE TEST_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" src/*.h) 10 | file(GLOB_RECURSE TEST_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" src/*.cpp) 11 | 12 | add_executable(Tests ${TEST_SOURCES} ${TEST_HEADERS}) 13 | target_link_libraries(Tests Intra) 14 | 15 | -------------------------------------------------------------------------------- /Demos/Tests/Tests.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Demos/Tests/src/Container/Array.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void RunContainerPerfTests(Intra::IO::FormattedWriter& logger); 6 | -------------------------------------------------------------------------------- /Demos/Tests/src/Container/Map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void RunMapPerfTests(Intra::IO::FormattedWriter& output); 6 | 7 | -------------------------------------------------------------------------------- /Demos/Tests/src/Container/String.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void RunStringPerfTests(Intra::IO::FormattedWriter& logger); 6 | 7 | -------------------------------------------------------------------------------- /Demos/Tests/src/PerfTestRandom.cpp: -------------------------------------------------------------------------------- 1 | #if(defined(_MSC_VER) && !defined(__GNUC__) && !defined(_HAS_EXCEPTIONS)) 2 | #define _HAS_EXCEPTIONS 0 3 | #endif 4 | 5 | #include "Cpp/Warnings.h" 6 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 7 | 8 | #include "PerfTestRandom.h" 9 | 10 | #include "System/Stopwatch.h" 11 | #include "Test/PerfSummary.h" 12 | #include "Cpp/Compatibility.h" 13 | #include "Random/FastUniform.h" 14 | 15 | 16 | INTRA_PUSH_DISABLE_ALL_WARNINGS 17 | #include 18 | #include 19 | INTRA_WARNING_POP 20 | 21 | using namespace Intra; 22 | 23 | float g_A = 0; 24 | int g_B = 0; 25 | 26 | void RunRandomPerfTests(IO::FormattedWriter& logger) 27 | { 28 | std::random_device r; 29 | std::mt19937 mt19937(r()); 30 | 31 | Random::FastUniform frandom(3787847832u); 32 | 33 | Stopwatch tim; 34 | 35 | for(int i=0; i<100000000; i++) g_A += float(mt19937())/float(mt19937.max()); 36 | double time2 = tim.GetElapsedSecondsAndReset(); 37 | 38 | for(int i=0; i<100000000; i++) g_A += float(rand())/32767.0f; 39 | double time1 = tim.GetElapsedSecondsAndReset(); 40 | 41 | for(int i=0; i<100000000; i++) g_A += frandom(); 42 | double time3 = tim.GetElapsedSecondsAndReset(); 43 | 44 | 45 | PrintPerformanceResults(logger, "float in range [0.0; 1.0] 100000000 times", 46 | {"rand()/32767.0f", "mt19937()/(float)mt19937.max()", "Math::Random()"}, 47 | {time1, time2}, 48 | {time3}); 49 | } 50 | 51 | INTRA_WARNING_POP 52 | -------------------------------------------------------------------------------- /Demos/Tests/src/PerfTestRandom.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void RunRandomPerfTests(Intra::IO::FormattedWriter& logger); 6 | 7 | -------------------------------------------------------------------------------- /Demos/Tests/src/PerfTestSerialization.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void RunSerializationPerfTests(Intra::IO::FormattedWriter& output); 6 | -------------------------------------------------------------------------------- /Demos/Tests/src/PerfTestSort.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void RunSortPerfTests(Intra::IO::FormattedWriter& logger); 6 | -------------------------------------------------------------------------------- /Demos/Tests/src/Range/Header.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void RunPolymorphicRangePerfTests(Intra::IO::FormattedWriter& logger); 6 | -------------------------------------------------------------------------------- /Demos/UnitTests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(UnitTests) 4 | 5 | #set(USE_EXCEPTIONS 1) 6 | include(../../Configurations.cmake) 7 | 8 | include_directories(../../Intra) 9 | 10 | file(GLOB_RECURSE TEST_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" src/*.h) 11 | file(GLOB_RECURSE TEST_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" src/*.cpp) 12 | 13 | add_executable(UnitTests ${TEST_SOURCES} ${TEST_HEADERS}) 14 | target_link_libraries(UnitTests Intra) 15 | 16 | -------------------------------------------------------------------------------- /Demos/UnitTests/Delegate.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Demos/UnitTests/Delegate.cpp -------------------------------------------------------------------------------- /Demos/UnitTests/src/Concurrency/Concurrency.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void TestAtomics(Intra::FormattedWriter& output); 6 | void TestInterruption(Intra::FormattedWriter& output); 7 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/Container/HashMap.cpp: -------------------------------------------------------------------------------- 1 | #include "HashMap.h" 2 | #include "Container/Associative/HashMap.h" 3 | 4 | using namespace Intra; 5 | using namespace IO; 6 | 7 | void TestMaps(FormattedWriter& output) 8 | { 9 | HashMap map; 10 | map["Строка"] = 6; 11 | map["Тест"] = 4; 12 | map["Вывод"] = 5; 13 | map["Ассоциативного"] = 14; 14 | map["Массива"] = 7; 15 | map["HashMap"] = 11; 16 | 17 | output.PrintLine("Заполнили HashMap, выведем его:"); 18 | output.PrintLine(map); 19 | output.LineBreak(); 20 | 21 | auto mapRange = map.Find("Вывод"); 22 | mapRange.PopLast(); 23 | 24 | output.PrintLine("Выведем все элементы, вставленные начиная от \"Вывод\" и до предпоследнего элемента:"); 25 | output.PrintLine(mapRange); 26 | output.LineBreak(); 27 | 28 | map.SortByKey(); 29 | output.PrintLine("Отсортируем элементы HashMap на месте:"); 30 | output.PrintLine(map); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/Container/HashMap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void TestMaps(Intra::IO::FormattedWriter& output); 6 | 7 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/Container/SparseArray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void TestSparseArray(Intra::IO::FormattedWriter& output); 6 | void TestSparseRange(Intra::IO::FormattedWriter& output); 7 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/IO/IO.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void TestFileSyncIO(Intra::IO::FormattedWriter& output); 6 | void TestFileAsyncIO(Intra::IO::FormattedWriter& output); 7 | void TestFileSearching(Intra::IO::FormattedWriter& output); 8 | 9 | void TestSocketIO(Intra::IO::FormattedWriter& output); 10 | void TestHttpServer(Intra::IO::FormattedWriter& output); 11 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/Range/Heap.cpp: -------------------------------------------------------------------------------- 1 | #include "Range.h" 2 | 3 | #include "Cpp/Warnings.h" 4 | 5 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 6 | 7 | #include "Range/Mutation/Heap.h" 8 | #include "IO/FormattedWriter.h" 9 | 10 | using namespace Intra; 11 | using namespace IO; 12 | using namespace Range; 13 | 14 | 15 | void TestHeap(FormattedWriter& output) 16 | { 17 | int arr[] = {4, 7, 2, 6, 9, 2}; 18 | Span span = arr; 19 | output.PrintLine("Building min-heap on array: ", span); 20 | HeapBuild(span, Funal::Greater); 21 | INTRA_ASSERT_EQUALS(span.First(), 2); 22 | output.PrintLine("Result: ", span); 23 | output.Print("Min elements: "); 24 | while(!span.Empty()) 25 | { 26 | output.Print(HeapPop(span, Funal::Greater), ' '); 27 | span.PopLast(); 28 | } 29 | output.LineBreak(); 30 | } 31 | 32 | 33 | INTRA_WARNING_POP 34 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/Range/Range.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void TestComposedRange(Intra::IO::FormattedWriter& output); 6 | void TestPolymorphicRange(Intra::IO::FormattedWriter& output); 7 | void TestStreamRange(Intra::IO::FormattedWriter& output); 8 | void TestRangeStlInterop(Intra::IO::FormattedWriter& output); 9 | void TestUnicodeConversion(Intra::IO::FormattedWriter& output); 10 | void TestHeap(Intra::IO::FormattedWriter& output); 11 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/Range/Unicode.cpp: -------------------------------------------------------------------------------- 1 | #include "Range/Special/Unicode.h" 2 | #include "IO/FormattedWriter.h" 3 | #include "Utils/Debug.h" 4 | 5 | using namespace Intra; 6 | using namespace Range; 7 | using namespace IO; 8 | 9 | void TestUnicodeConversion(FormattedWriter& output) 10 | { 11 | output.PrintLine("String to test:"); 12 | StringView originalStr = "Тестируется русский текст с иероглифами ㈇㌤㈳㌛㉨, " 13 | "а также греческим алфавитом αβγδεζηθικλμνξο."; 14 | output.PrintLine(originalStr); 15 | output.PrintLine("UTF8 -> UTF16 -> UTF32 -> UTF16 -> UTF8"); 16 | String mystr = originalStr; 17 | WString utf16 = UTF8(originalStr).ToUTF16(false); 18 | DString utf32 = UTF16(utf16).ToUTF32(); 19 | utf16 = UTF32(utf32).ToUTF16(false); 20 | auto utf8 = UTF16(utf16.View()).ToUTF8(); 21 | output.PrintLine("Result:"); 22 | output.PrintLine(originalStr); 23 | INTRA_ASSERT_EQUALS(originalStr, utf8); 24 | } 25 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/Serialization.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void TestTextSerialization(Intra::IO::FormattedWriter& output); 6 | void TestBinarySerialization(Intra::IO::FormattedWriter& output); 7 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/Sort.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | 5 | void TestSort(Intra::IO::FormattedWriter& output); 6 | -------------------------------------------------------------------------------- /Demos/UnitTests/src/UnitTests.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Demos/UnitTests/src/UnitTests.cpp -------------------------------------------------------------------------------- /Intra/Audio.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Audio/AudioBuffer.h" 4 | #include "Audio/AudioProcessing.h" 5 | #include "Audio/AudioSource.h" 6 | #include "Audio/Midi.h" 7 | #include "Audio/Music.h" 8 | #include "Audio/MusicNote.h" 9 | #include "Audio/Sound.h" 10 | #include "Audio/SoundApi.h" 11 | #include "Audio/SoundApiDeclarations.h" 12 | #include "Audio/SoundTypes.h" 13 | 14 | #include "Audio/Sources.hh" 15 | #include "Auido/Synth.hh" 16 | -------------------------------------------------------------------------------- /Intra/Audio/AudioProcessing.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utils/Span.h" 4 | 5 | namespace Intra { namespace Audio { 6 | 7 | void DiscreteFourierTransform(Span outFreqs, CSpan samples); 8 | 9 | //void InplaceFFT(Span data); 10 | //void InplaceInverseFFT(Span data); 11 | void InplaceFFT(Span real, Span imag); 12 | void InplaceInverseFFTNonNormalized(Span real, Span imag); 13 | void InplaceInverseFFT(Span real, Span imag); 14 | 15 | }} 16 | -------------------------------------------------------------------------------- /Intra/Audio/Midi/DeviceState.cpp: -------------------------------------------------------------------------------- 1 | #include "DeviceState.h" 2 | 3 | #include "Utils/Span.h" 4 | #include "Range/Mutation/Fill.h" 5 | 6 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 7 | 8 | namespace Intra { namespace Audio { namespace Midi { 9 | 10 | DeviceState::DeviceState(short headerTimeFormat): 11 | InstrumentIds{0}, HeaderTimeFormat(headerTimeFormat) 12 | { 13 | Range::Fill(Volumes, byte(127)); 14 | Range::Fill(Pans, byte(64)); 15 | if(headerTimeFormat < 0) 16 | { 17 | const float framesPerSecond = (headerTimeFormat >> 8) == 29? 29.97f: float(headerTimeFormat >> 8); 18 | TickDuration = 1.0f/framesPerSecond/float(headerTimeFormat & 0xFF); 19 | } 20 | else TickDuration = 60.0f/120/float(headerTimeFormat); 21 | } 22 | 23 | }}} 24 | 25 | INTRA_WARNING_POP 26 | -------------------------------------------------------------------------------- /Intra/Audio/Midi/DeviceState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Cpp/Fundamental.h" 6 | 7 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 8 | 9 | namespace Intra { namespace Audio { namespace Midi { 10 | 11 | struct DeviceState 12 | { 13 | DeviceState(short headerTimeFormat); 14 | 15 | byte InstrumentIds[16]; 16 | byte Volumes[16]; 17 | byte Pans[16]; 18 | double TickDuration = 0; 19 | short HeaderTimeFormat = 0; 20 | }; 21 | 22 | }}} 23 | 24 | INTRA_WARNING_POP 25 | -------------------------------------------------------------------------------- /Intra/Audio/Midi/Messages.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Cpp/Fundamental.h" 6 | 7 | #include "Audio/MusicNote.h" 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | namespace Intra { namespace Audio { namespace Midi { 12 | 13 | struct NoteOn 14 | { 15 | double Time; 16 | byte Channel; 17 | byte NoteOctaveOrDrumId; 18 | byte Velocity; 19 | byte Instrument; 20 | byte Volume; 21 | sbyte Pan; 22 | 23 | forceinline MusicNote::Type Note() const {return MusicNote::Type(NoteOctaveOrDrumId % 12);} 24 | forceinline byte Octave() const {return byte(NoteOctaveOrDrumId / 12);} 25 | forceinline ushort Id() const {return ushort((Channel << 8) | NoteOctaveOrDrumId);} 26 | forceinline float Frequency() const {return MusicNote::BasicFrequencies[Note()]*0.5f*float(1 << Octave());} 27 | forceinline float TotalVolume() const {return float(Volume*Velocity)/(127.0f*127.0f);} 28 | 29 | }; 30 | 31 | struct NoteOff 32 | { 33 | double Time; 34 | byte Channel; 35 | byte NoteOctaveOrDrumId; 36 | byte Velocity; 37 | 38 | forceinline ushort Id() const {return ushort((Channel << 8) | NoteOctaveOrDrumId);} 39 | }; 40 | 41 | struct PitchBend 42 | { 43 | double Time; 44 | byte Channel; 45 | short Pitch; 46 | }; 47 | 48 | class IDevice 49 | { 50 | public: 51 | virtual ~IDevice() {} 52 | virtual void OnNoteOn(const NoteOn& noteOn) = 0; 53 | virtual void OnNoteOff(const NoteOff& noteOff) = 0; 54 | virtual void OnPitchBend(const PitchBend& pitchBend) = 0; 55 | virtual void OnAllNotesOff(byte channel) = 0; 56 | }; 57 | 58 | }}} 59 | 60 | INTRA_WARNING_POP 61 | -------------------------------------------------------------------------------- /Intra/Audio/Midi/MidiFileParser.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Audio/Midi/MidiFileParser.h -------------------------------------------------------------------------------- /Intra/Audio/Midi/RawEvent.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Audio/Midi/RawEvent.h -------------------------------------------------------------------------------- /Intra/Audio/Midi/TrackCombiner.cpp: -------------------------------------------------------------------------------- 1 | #include "TrackCombiner.h" 2 | #include "Range/Mutation/Heap.h" 3 | #include "Funal/ObjectMethod.h" 4 | 5 | namespace Intra { namespace Audio { namespace Midi { 6 | 7 | bool TrackCombiner::trackTimeComparer(const TrackParser& a, const TrackParser& b) 8 | { 9 | return a.NextEventTime(mState) > b.NextEventTime(mState); 10 | } 11 | 12 | TrackCombiner::TrackCombiner(short headerTimeFormat): 13 | mState(headerTimeFormat) {} 14 | 15 | void TrackCombiner::AddTrack(TrackParser track) 16 | { 17 | Range::HeapContainerPush(mTracks, Cpp::Move(track), 18 | ObjectMethod(this, &TrackCombiner::trackTimeComparer)); 19 | } 20 | 21 | void TrackCombiner::ProcessEvent(IDevice& device) 22 | { 23 | auto& trackWithNearestEvent = Range::HeapPop(mTracks, ObjectMethod(this, &TrackCombiner::trackTimeComparer)); 24 | const double prevTickDuration = mState.TickDuration; 25 | trackWithNearestEvent.ProcessEvent(mState, device); 26 | const double lastEventTime = trackWithNearestEvent.Time; 27 | if(trackWithNearestEvent.Empty()) mTracks.RemoveLast(); 28 | else Range::HeapPush(mTracks, ObjectMethod(this, &TrackCombiner::trackTimeComparer)); 29 | if(mState.TickDuration != prevTickDuration) 30 | { 31 | for(auto& track: mTracks) track.OnTempoChange(lastEventTime, prevTickDuration); 32 | Range::HeapBuild(mTracks, ObjectMethod(this, &TrackCombiner::trackTimeComparer)); 33 | } 34 | } 35 | 36 | double TrackCombiner::NextEventTime() const 37 | {return mTracks.First().NextEventTime(mState);} 38 | 39 | }}} 40 | -------------------------------------------------------------------------------- /Intra/Audio/Midi/TrackCombiner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | 5 | #include "Container/Sequential/Array.h" 6 | 7 | #include "TrackParser.h" 8 | #include "DeviceState.h" 9 | #include "Messages.h" 10 | 11 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 12 | 13 | namespace Intra { namespace Audio { namespace Midi { 14 | 15 | class TrackCombiner 16 | { 17 | Array mTracks; 18 | DeviceState mState; 19 | public: 20 | explicit TrackCombiner(short headerTimeFormat); 21 | 22 | void AddTrack(TrackParser track); 23 | 24 | void ProcessEvent(IDevice& device); 25 | void ProcessAllEvents(IDevice& device) {while(!mTracks.Empty()) ProcessEvent(device);} 26 | 27 | forceinline bool Empty() const noexcept {return mTracks.Empty();} 28 | double NextEventTime() const; 29 | 30 | private: 31 | bool trackTimeComparer(const TrackParser& a, const TrackParser& b); 32 | }; 33 | 34 | }}} 35 | 36 | INTRA_WARNING_POP 37 | -------------------------------------------------------------------------------- /Intra/Audio/Midi/TrackParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Cpp/Fundamental.h" 6 | 7 | #include "Utils/Debug.h" 8 | 9 | #include "Range/Polymorphic/InputRange.h" 10 | 11 | #include "Messages.h" 12 | #include "RawEvent.h" 13 | #include "DeviceState.h" 14 | 15 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 16 | 17 | namespace Intra { namespace Audio { namespace Midi { 18 | 19 | struct TrackParser 20 | { 21 | InputRange Events; 22 | double Time = 0; 23 | uint DelayTicksPassed = 0; 24 | 25 | TrackParser(InputRange events, double time=0); 26 | 27 | TrackParser(const TrackParser&) = delete; 28 | TrackParser& operator=(const TrackParser&) = delete; 29 | TrackParser(TrackParser&&) = default; 30 | TrackParser& operator=(TrackParser&&) = default; 31 | 32 | double NextEventTime(const DeviceState& state) const 33 | { 34 | INTRA_DEBUG_ASSERT(!Events.Empty()); 35 | uint delay = Events.First().Delay(); 36 | if(delay > DelayTicksPassed) delay -= DelayTicksPassed; 37 | else delay = 0; 38 | return Time + delay * state.TickDuration; 39 | } 40 | 41 | void OnTempoChange(double time, double prevTickDuration) 42 | { 43 | const uint ticksPassed = uint(Math::Round((time - Time) / prevTickDuration)); 44 | DelayTicksPassed += ticksPassed; 45 | Time += ticksPassed * prevTickDuration; 46 | } 47 | 48 | void ProcessEvent(DeviceState& state, IDevice& device); 49 | forceinline bool Empty() const {return Events.Empty();} 50 | 51 | void processSystemEvent(DeviceState& state, const RawEvent& event); 52 | }; 53 | 54 | }}} 55 | 56 | INTRA_WARNING_POP 57 | -------------------------------------------------------------------------------- /Intra/Audio/MusicNote.cpp: -------------------------------------------------------------------------------- 1 | #include "MusicNote.h" 2 | 3 | namespace Intra { namespace Audio { 4 | 5 | const float MusicNote::BasicFrequencies[12] = { 6 | 16.352f, 17.324f, 18.354f, 19.445f, 20.602f, 21.827f, 7 | 23.125f, 24.500f, 25.957f, 27.500f, 29.135f, 30.868f 8 | }; 9 | 10 | }} 11 | -------------------------------------------------------------------------------- /Intra/Audio/MusicNote.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Fundamental.h" 5 | 6 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 7 | 8 | namespace Intra { namespace Audio { 9 | 10 | struct MusicNote 11 | { 12 | enum Type: byte {C, CSharp, D, DSharp, E, F, FSharp, G, GSharp, A, ASharp, B}; 13 | 14 | //Таблица соответствия нот субконтроктавы частотам 15 | static const float BasicFrequencies[12]; 16 | 17 | forceinline MusicNote(byte octave, Type note): NoteOctave(byte((octave << 4) | byte(note))) {} 18 | forceinline MusicNote(null_t=null): NoteOctave(255) {} 19 | 20 | forceinline Type Note() const {return Type(NoteOctave & 15);} 21 | forceinline byte Octave() const {return byte(NoteOctave >> 4);} 22 | 23 | forceinline bool operator==(const MusicNote& rhs) const {return NoteOctave == rhs.NoteOctave;} 24 | forceinline bool operator!=(const MusicNote& rhs) const {return !operator==(rhs);} 25 | 26 | forceinline bool operator==(null_t) const noexcept {return NoteOctave == 255;} 27 | forceinline bool operator!=(null_t) const noexcept {return !operator==(null);} 28 | 29 | forceinline float Frequency() const {return BasicFrequencies[byte(Note())]*float(1 << Octave());} 30 | 31 | //! Запакованные в один байт нота и октава. 32 | //! Младшие 4 бита - нота, старшие биты - октава, начиная с субконтроктавы. 33 | byte NoteOctave; 34 | }; 35 | 36 | }} 37 | 38 | INTRA_WARNING_POP 39 | -------------------------------------------------------------------------------- /Intra/Audio/Resample.cpp: -------------------------------------------------------------------------------- 1 | #include "Resample.h" 2 | #include "Math/Math.h" 3 | 4 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 5 | 6 | namespace Intra { namespace Audio { 7 | 8 | void ResampleLinear(CSpan src, Span dst) 9 | { 10 | const size_t srcL1 = src.Length() - 1; 11 | const size_t dstL1 = dst.Length() - 1; 12 | const float ratio = float(srcL1) / float(dstL1); 13 | for(size_t i = 0; i < dstL1; i++) 14 | dst[i] = LinearSample(src, float(i)*ratio); 15 | dst.Last() = src.Last(); 16 | } 17 | 18 | 19 | Span DecimateX2LinearInPlace(Span inOutSamples) 20 | { 21 | const size_t newLen = inOutSamples.Length() / 2; 22 | for(size_t i = 0; i < newLen; i++) 23 | inOutSamples.Begin[i] = (inOutSamples.Begin[2*i] + inOutSamples.Begin[2*i + 1]) * 0.5f; 24 | return inOutSamples.TakeExactly(newLen); 25 | } 26 | 27 | Span DecimateX2Linear(Span dst, CSpan src) 28 | { 29 | const size_t newLen = src.Length() / 2; 30 | INTRA_DEBUG_ASSERT(dst.Length() >= newLen); 31 | for(size_t i = 0; i < newLen; i++) 32 | dst.Begin[i] = (src.Begin[2*i] + src.Begin[2*i + 1]) * 0.5f; 33 | return dst.TakeExactly(newLen); 34 | } 35 | 36 | Span UpsampleX2Linear(Span dst, CSpan src) 37 | { 38 | const size_t newLen = src.Length()*2; 39 | dst = dst.TakeExactly(newLen); 40 | if(src.Empty()) return dst; 41 | 42 | dst.First() = src.First(); 43 | for(size_t i = 1; i < src.Length(); i++) 44 | { 45 | dst.Begin[2*i - 1] = src.Begin[i-1]; 46 | dst.Begin[2*i] = (src.Begin[i-1] + src.Begin[i]) * 0.5f; 47 | } 48 | dst.Last() = src.Last(); 49 | return dst; 50 | } 51 | 52 | }} 53 | 54 | INTRA_WARNING_POP 55 | -------------------------------------------------------------------------------- /Intra/Audio/Resample.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Audio/Resample.h -------------------------------------------------------------------------------- /Intra/Audio/SoundDriverInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | 5 | namespace Intra { namespace Audio { 6 | 7 | struct SoundDeviceInfo 8 | { 9 | static SoundDeviceInfo Get(bool* oSupported = null); 10 | 11 | uint SampleRate = 44100; 12 | ushort Channels = 2; 13 | ushort BitDepth = 16; 14 | }; 15 | 16 | }} 17 | -------------------------------------------------------------------------------- /Intra/Audio/SoundTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Fundamental.h" 5 | 6 | #include "Data/ValueType.h" 7 | 8 | namespace Intra { namespace Audio { 9 | 10 | struct AudioBuffer; 11 | class IAudioSource; 12 | 13 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 14 | 15 | struct SoundInfo 16 | { 17 | size_t SampleCount; 18 | uint SampleRate; 19 | ushort Channels; 20 | Data::ValueType SampleType; 21 | 22 | SoundInfo(null_t): SoundInfo() {} 23 | 24 | SoundInfo(size_t sampleCount=0, uint sampleRate=44100, ushort channels=1, Data::ValueType sampleType=Data::ValueType::Void): 25 | SampleCount(sampleCount), SampleRate(sampleRate), Channels(channels), SampleType(sampleType) {} 26 | 27 | size_t GetBufferSize() const {return SampleCount*Channels*SampleType.Size();} 28 | double Duration() const {return SampleRate == 0? 0: double(SampleCount)/SampleRate;} 29 | 30 | bool operator==(null_t) const noexcept {return SampleType == Data::ValueType::Void;} 31 | bool operator!=(null_t) const noexcept {return !operator==(null);} 32 | }; 33 | 34 | INTRA_WARNING_POP 35 | 36 | }} 37 | -------------------------------------------------------------------------------- /Intra/Audio/Sources.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sources/MusicSynth.h" 4 | #include "Sources/Vorbis.h" 5 | #include "Sources/Wave.h" 6 | -------------------------------------------------------------------------------- /Intra/Audio/Sources/Vorbis.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/PlatformDetect.h" 4 | #include "Utils/Span.h" 5 | #include "Container/Sequential/Array.h" 6 | #include "Audio/AudioSource.h" 7 | 8 | namespace Intra { namespace Audio { namespace Sources { 9 | 10 | //! Используемый декодер ogg vorbis 11 | #define INTRA_LIBRARY_VORBIS_DECODER_None 0 12 | #define INTRA_LIBRARY_VORBIS_DECODER_STB 1 13 | #define INTRA_LIBRARY_VORBIS_DECODER_libvorbis 2 14 | 15 | #ifndef INTRA_LIBRARY_VORBIS_DECODER 16 | 17 | #if(INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_Windows) 18 | #define INTRA_LIBRARY_VORBIS_DECODER INTRA_LIBRARY_VORBIS_DECODER_None 19 | #else 20 | #define INTRA_LIBRARY_VORBIS_DECODER INTRA_LIBRARY_VORBIS_DECODER_None 21 | #endif 22 | 23 | #endif 24 | 25 | #if(INTRA_LIBRARY_VORBIS_DECODER!=INTRA_LIBRARY_VORBIS_DECODER_None) 26 | 27 | class Vorbis: public AAudioSource 28 | { 29 | struct Decoder; 30 | typedef Decoder* DecoderHandle; 31 | CSpan data; 32 | DecoderHandle decoder; 33 | public: 34 | Vorbis(CSpan srcFileData); 35 | ~Vorbis(); 36 | 37 | Vorbis& operator=(const Vorbis&) = delete; 38 | 39 | size_t SampleCount() const override; 40 | size_t CurrentSamplePosition() const override; 41 | 42 | size_t GetInterleavedSamples(Span outShorts) override; 43 | size_t GetInterleavedSamples(Span outFloats) override; 44 | size_t GetUninterleavedSamples(CSpan> outFloats) override; 45 | FixedArray GetRawSamplesData(size_t maxSamplesToRead, 46 | ValueType* outType, bool* outInterleaved, size_t* outSamplesRead) override; 47 | }; 48 | 49 | #endif 50 | 51 | }}} 52 | -------------------------------------------------------------------------------- /Intra/Audio/Synth.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "AttackDecayAttenuation.h" 4 | #include "AttenuatorPass.h" 5 | #include "DrumInstrument.h" 6 | #include "ExponentialAttenuation.h" 7 | #include "GeneratorSynth.h" 8 | #include "HighLowPass.h" 9 | #include "InstrumentLibrary.h" 10 | #include "ModifierPass.h" 11 | #include "PeriodicSynth.h" 12 | #include "SawtoothSynth.h" 13 | #include "SineExpSynth.h" 14 | #include "SineSynth.h" 15 | #include "SynthesizedInstrument.h" 16 | #include "TableAttenuation.h" 17 | #include "Types.h" 18 | 19 | #include "Modifiers.hh" 20 | #include "Generators.hh" 21 | #include "PostEffects.hh" 22 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/ADSR.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Audio/Synth/ADSR.h -------------------------------------------------------------------------------- /Intra/Audio/Synth/Chorus.cpp: -------------------------------------------------------------------------------- 1 | #include "Chorus.h" 2 | 3 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 4 | 5 | namespace Intra { namespace Audio { namespace Synth { 6 | 7 | void Chorus::operator()(Span inOutSamples) 8 | { 9 | const float oscillatorOffset = float(DelayCircularBuffer.Length())*0.5f; 10 | for(float& sample: inOutSamples) 11 | { 12 | DelayCircularBuffer[CircularBufferOffset++] = sample; 13 | if(CircularBufferOffset == DelayCircularBuffer.Length()) CircularBufferOffset = 0; 14 | 15 | const size_t delayInSamples = size_t(Oscillator.Next() + oscillatorOffset); 16 | size_t sampleIndex = CircularBufferOffset; 17 | if(sampleIndex < delayInSamples) sampleIndex += DelayCircularBuffer.Length(); 18 | sampleIndex -= delayInSamples; 19 | 20 | sample *= MainVolume; 21 | sample += DelayCircularBuffer[sampleIndex]*SecondaryVolume; 22 | } 23 | } 24 | 25 | }}} 26 | 27 | INTRA_WARNING_POP 28 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Generators.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Generators/DrumPhysicalModel.h" 4 | #include "Generators/FunctionGenerator.h" 5 | #include "Generators/Pulse.h" 6 | #include "Generators/Sawtooth.h" 7 | #include "Generators/ViolinPhysicalModel.h" 8 | #include "Generators/WhiteNoise.h" 9 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Generators/DrumPhysicalModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/PlatformDetect.h" 4 | 5 | #ifndef INTRA_NO_AUDIO_SYNTH 6 | 7 | #include "Random/FastUniform.h" 8 | #include "Container/Utility/Array2D.h" 9 | #include "Audio/Synth/Types.h" 10 | 11 | namespace Intra { namespace Audio { namespace Synth { namespace Generators { 12 | 13 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 14 | 15 | class DrumPhysicalModel 16 | { 17 | byte mCnt; 18 | byte mDX, mDY; 19 | float mFrc, mK1, mK2; 20 | Array2D mP, mS, mF; 21 | Random::FastUniform mFRandom; 22 | float mPrevRand; 23 | 24 | public: 25 | enum: bool {RangeIsInfinite = true}; 26 | 27 | void PopFirst(); 28 | 29 | float First() const {return mP(1, mDY/2u);} 30 | 31 | bool Empty() const {return mP.Width() == 0;} 32 | 33 | DrumPhysicalModel(null_t=null); 34 | 35 | DrumPhysicalModel(byte count, byte dx, byte dy, float frc, float kDemp, float kRand); 36 | float sRand(); 37 | 38 | Span operator()(Span dst, bool add); 39 | }; 40 | 41 | INTRA_WARNING_POP 42 | 43 | }}}} 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Generators/FunctionGenerator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | 6 | namespace Intra { namespace Audio { namespace Synth { namespace Generators { 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | template class FunctionGenerator 11 | { 12 | float mFreq, mAmplitude; 13 | float mTime, mDT; 14 | T mGenerator; 15 | public: 16 | FunctionGenerator(T generator): mFreq(0), mAmplitude(0), 17 | mTime(0), mDT(0), mGenerator(generator) {} 18 | 19 | void SetParams(float frequency, float amplitude, double step) 20 | { 21 | mFreq = frequency; 22 | mAmplitude = amplitude; 23 | mDT = float(step); 24 | } 25 | 26 | forceinline float NextSample() 27 | { 28 | const float result = operator()(mTime); 29 | mTime += mDT; 30 | return result; 31 | } 32 | 33 | forceinline float operator()(float t) 34 | {return mGenerator(mFreq, t)*mAmplitude;} 35 | }; 36 | 37 | template forceinline FunctionGenerator CreateFunctionGenerator(T generator) 38 | {return FunctionGenerator(generator);} 39 | 40 | INTRA_WARNING_POP 41 | 42 | }}}} 43 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Generators/Pulse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Cpp/Fundamental.h" 6 | 7 | #include "Math/Math.h" 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | namespace Intra { namespace Audio { namespace Synth { namespace Generators { 12 | 13 | struct Pulse 14 | { 15 | Pulse(float updownRatio, float frequency, uint sampleRate): 16 | mUpdownPercent(updownRatio / (updownRatio + 1)), mPhase(0), mDeltaPhase(frequency*2 / float(sampleRate)) {} 17 | 18 | forceinline void PopFirst() {mPhase += mDeltaPhase;} 19 | forceinline float First() const {return Math::Fract(mPhase) > mUpdownPercent? 1.0f: - 1.0f;} 20 | forceinline bool Empty() const {return false;} 21 | 22 | private: 23 | float mUpdownPercent, mPhase, mDeltaPhase; 24 | }; 25 | 26 | }}}} 27 | 28 | INTRA_WARNING_POP 29 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Generators/Sawtooth.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Math/Math.h" 7 | 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | namespace Intra { namespace Audio { namespace Synth { namespace Generators { 12 | 13 | struct Sawtooth 14 | { 15 | enum: bool {RangeIsInfinite = true}; 16 | 17 | Sawtooth(float updownRatio, float freq, float amplitude, uint sampleRate): 18 | mUpdownValue(updownRatio / (updownRatio + 1)), mFreq(freq), 19 | mP(mUpdownValue/2), mDP(mFreq / float(sampleRate)), 20 | mC1(2*amplitude/mUpdownValue), mC2(2*amplitude / (1 - mUpdownValue)), mAmplitude(amplitude) 21 | {} 22 | 23 | forceinline void PopFirst() {mP += mDP;} 24 | 25 | float First() const 26 | { 27 | const float sawPos = float(Math::Fract(mP)); 28 | return sawPos < mUpdownValue? 29 | sawPos*mC1 - mAmplitude: 30 | mAmplitude - (sawPos - mUpdownValue)*mC2; 31 | } 32 | 33 | forceinline bool Empty() const {return false;} 34 | 35 | private: 36 | float mUpdownValue, mFreq; 37 | double mP, mDP; 38 | float mC1, mC2, mAmplitude; 39 | }; 40 | 41 | }}}} 42 | 43 | INTRA_WARNING_POP 44 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Generators/Square.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Cpp/Fundamental.h" 6 | 7 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 8 | 9 | namespace Intra { namespace Audio { namespace Synth { namespace Generators { 10 | 11 | struct Square 12 | { 13 | Square(float frequency, uint sampleRate): 14 | mPhase(0), mDeltaPhase(frequency*2 / float(sampleRate)) {} 15 | 16 | forceinline void PopFirst() { mPhase += mDeltaPhase; } 17 | forceinline float First() const { return float(int(mPhase) & 1)*2.0f - 1.0f; } 18 | forceinline bool Empty() const { return false; } 19 | 20 | private: 21 | float mPhase, mDeltaPhase; 22 | }; 23 | 24 | }}}} 25 | 26 | INTRA_WARNING_POP 27 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Generators/WhiteNoise.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Random/FastUniformNoise.h" 6 | 7 | namespace Intra { namespace Audio { namespace Synth { namespace Generators { 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | struct WhiteNoise 12 | { 13 | WhiteNoise(): mAmplitude(0), mDS(0), mS(0) {} 14 | 15 | void SetParams(float frequency, float amplitude, double step) 16 | { 17 | mAmplitude = amplitude; 18 | mDS = float(frequency*step); 19 | } 20 | 21 | forceinline void PopFirst() {mS += mDS;} 22 | forceinline float First() const {return mAmplitude*Random::FastUniformNoise::Linear(mS);} 23 | forceinline bool Empty() const {return false;} 24 | 25 | private: 26 | float mAmplitude; 27 | float mDS; 28 | float mS; 29 | }; 30 | 31 | INTRA_WARNING_POP 32 | 33 | }}}} 34 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/InstrumentSet.cpp: -------------------------------------------------------------------------------- 1 | #include "InstrumentSet.h" 2 | #include "Audio/Midi/MidiFileParser.h" 3 | 4 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 5 | 6 | namespace Intra { namespace Audio { namespace Synth { 7 | 8 | void MidiInstrumentSet::Preload(const Midi::MidiFileInfo& info, uint sampleRate) 9 | { 10 | for(size_t i = 0; i < 128; i++) 11 | { 12 | if(info.UsedDrumInstrumentsFlags[i]) (*DrumInstruments[i])(1, sampleRate); 13 | } 14 | } 15 | 16 | }}} 17 | 18 | INTRA_WARNING_POP 19 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/InstrumentSet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 6 | 7 | namespace Intra { namespace Audio { 8 | 9 | namespace Midi { 10 | struct MidiFileInfo; 11 | } 12 | 13 | namespace Synth { 14 | 15 | struct MusicalInstrument; 16 | 17 | struct MidiInstrumentSet 18 | { 19 | MusicalInstrument* Instruments[128]{null}; 20 | GenericDrumInstrument* DrumInstruments[128]{null}; 21 | 22 | void Preload(const Midi::MidiFileInfo& info, uint sampleRate); 23 | }; 24 | 25 | } 26 | 27 | }} 28 | 29 | INTRA_WARNING_POP 30 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/MusicalInstrument.cpp: -------------------------------------------------------------------------------- 1 | #include "MusicalInstrument.h" 2 | #include "Range/ForEach.h" 3 | 4 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 5 | 6 | namespace Intra { namespace Audio { namespace Synth { 7 | 8 | NoteSampler MusicalInstrument::operator()(float freq, float volume, uint sampleRate) const 9 | { 10 | NoteSampler result; 11 | 12 | for(auto& wave: Waves) result.WaveTableSamplers.AddLast(wave(freq, volume, sampleRate)); 13 | for(auto& wave: WaveTables) result.WaveTableSamplers.AddLast(wave(freq, volume, sampleRate)); 14 | if(WhiteNoise) result.GenericSamplers.AddLast(WhiteNoise(freq, volume, sampleRate)); 15 | for(auto& instrument: GenericInstruments) result.GenericSamplers.AddLast(instrument(freq, volume, sampleRate)); 16 | 17 | if(ExponentAttenuation) result.Modifiers.AddLast(ExponentAttenuation(freq, volume, sampleRate)); 18 | if(ADSR) result.ADSR = ADSR(freq, volume, sampleRate); 19 | if(Chorus) result.Modifiers.AddLast(Chorus(freq, volume, sampleRate)); 20 | for(auto& mod: GenericModifiers) result.Modifiers.AddLast(mod(freq, volume, sampleRate)); 21 | 22 | return result; 23 | } 24 | 25 | }}} 26 | 27 | INTRA_WARNING_POP 28 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/MusicalInstrument.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Utils/Span.h" 5 | #include "Container/Sequential/Array.h" 6 | 7 | #include "Types.h" 8 | #include "WaveTableSampler.h" 9 | #include "WhiteNoiseSampler.h" 10 | #include "ExponentialAttenuation.h" 11 | #include "ADSR.h" 12 | #include "NoteSampler.h" 13 | #include "Chorus.h" 14 | 15 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 16 | 17 | namespace Intra { namespace Audio { namespace Synth { 18 | 19 | struct MusicalInstrument 20 | { 21 | Array Waves; 22 | Array WaveTables; 23 | WhiteNoiseInstrument WhiteNoise; 24 | Array GenericInstruments; 25 | 26 | ExponentAttenuatorFactory ExponentAttenuation; 27 | AdsrAttenuatorFactory ADSR; 28 | ChorusFactory Chorus; 29 | Array GenericModifiers; 30 | 31 | NoteSampler operator()(float freq, float volume, uint sampleRate) const; 32 | }; 33 | 34 | }}} 35 | 36 | INTRA_WARNING_POP 37 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/NoteSampler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Container/Sequential/Array.h" 7 | 8 | #include "Audio/MusicNote.h" 9 | 10 | #include "WaveTableSampler.h" 11 | #include "ADSR.h" 12 | 13 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 14 | 15 | namespace Intra { namespace Audio { namespace Synth { 16 | 17 | 18 | class NoteSampler 19 | { 20 | public: 21 | Array WaveTableSamplers; 22 | Array GenericSamplers; 23 | Array Modifiers; 24 | AdsrAttenuator ADSR; 25 | float Pan = 0; 26 | 27 | Span operator()(Span dst, bool add); 28 | size_t operator()(Span dstLeft, Span dstRight, bool add); 29 | 30 | void MultiplyPitch(float freqMultiplier); 31 | void NoteRelease(); 32 | void SetPan(float pan); 33 | 34 | bool Empty() const noexcept {return (WaveTableSamplers.Empty() && GenericSamplers.Empty()) || ADSR.SamplesLeft() == 0;} 35 | 36 | private: 37 | void fill(Span dst, bool add); 38 | void fillStereo(Span dstLeft, Span dstRight, bool add); 39 | void applyModifiers(Span dst); 40 | }; 41 | 42 | 43 | }}} 44 | 45 | INTRA_WARNING_POP 46 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Octaves.cpp: -------------------------------------------------------------------------------- 1 | #include "Octaves.h" 2 | #include "Random/FastUniform.h" 3 | 4 | namespace Intra { namespace Audio { namespace Synth { 5 | 6 | void SelfOctaveMix(CSpan src, Span dst, float multiplier) 7 | { 8 | src = src.Take(dst.Length()); 9 | dst = dst.Take(src.Length()); 10 | INTRA_DEBUG_ASSERT(src != dst); 11 | const size_t len = src.Length(); 12 | size_t i = 0; 13 | while(2*i < len) 14 | { 15 | dst[i] = src[i] + multiplier*src[2*i]; 16 | i++; 17 | } 18 | while(i < len) 19 | { 20 | dst[i] = src[i] + multiplier*src[2*i - len]; 21 | i++; 22 | } 23 | } 24 | 25 | void GenOctaves(Span& srcResult, Span buffer, uint octavesCount, uint maxSampleDelay) 26 | { 27 | if(octavesCount == 1) return; 28 | if(octavesCount == 2) 29 | { 30 | SelfOctaveMix(srcResult, buffer, 0.5f); 31 | srcResult = buffer; 32 | return; 33 | } 34 | 35 | Random::FastUniform rand(3453411347u ^ uint(srcResult.Length()) ^ uint(buffer.Length() << 10) ^ (octavesCount << 20)); 36 | buffer = DecimateX2Linear(buffer, srcResult); 37 | float volume = 0.5f; 38 | while(octavesCount --> 1) 39 | { 40 | auto result = srcResult; 41 | result.PopFirstN(AddMultiplied(result, buffer.Drop(rand(maxSampleDelay)), volume)); 42 | while(!result.Empty()) result.PopFirstN(AddMultiplied(result, buffer, volume)); 43 | buffer = DecimateX2LinearInPlace(buffer); 44 | volume /= 2; 45 | } 46 | } 47 | 48 | }}} 49 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/Octaves.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Audio/Synth/Octaves.h -------------------------------------------------------------------------------- /Intra/Audio/Synth/PostEffects.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | 6 | #include "Utils/Span.h" 7 | 8 | #include "Math/SineRange.h" 9 | 10 | #include "Types.h" 11 | 12 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 13 | 14 | namespace Intra { namespace Audio { namespace Synth { namespace PostEffects { 15 | 16 | struct Echo 17 | { 18 | float Delay; 19 | float MainVolume, SecondaryVolume; 20 | 21 | Echo(float delay=0.03f, float mainVolume=0.5f, float secondaryVolume=0.5f): 22 | Delay(delay), MainVolume(mainVolume), SecondaryVolume(secondaryVolume) {} 23 | 24 | void operator()(Span inOutSamples, uint sampleRate) const; 25 | }; 26 | 27 | struct FilterDrive 28 | { 29 | float K; 30 | FilterDrive(float k): K(k) {} 31 | 32 | void operator()(Span inOutSamples, uint sampleRate) const; 33 | }; 34 | 35 | struct FilterHP 36 | { 37 | float K; 38 | FilterHP(float k): K(k) {} 39 | 40 | void operator()(Span inOutSamples, uint sampleRate) const; 41 | }; 42 | 43 | 44 | struct FilterQ 45 | { 46 | float Frq, K; 47 | FilterQ(float frq, float k): Frq(frq), K(k) {} 48 | 49 | void operator()(Span samples, uint sampleRate) const; 50 | }; 51 | 52 | struct Fade 53 | { 54 | uint FadeIn, FadeOut; 55 | 56 | Fade(uint fadeIn=0, uint fadeOut=0): 57 | FadeIn(fadeIn), FadeOut(fadeOut) {} 58 | 59 | void operator()(Span inOutSamples, uint sampleRate) const; 60 | }; 61 | 62 | }}}} 63 | 64 | INTRA_WARNING_POP 65 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/RecordedSampler.cpp: -------------------------------------------------------------------------------- 1 | #include "RecordedSampler.h" 2 | 3 | #include "Range/Mutation/Copy.h" 4 | #include "Range/Mutation/Transform.h" 5 | 6 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 7 | 8 | namespace Intra { namespace Audio { namespace Synth { 9 | 10 | Span RecordedSampler::operator()(Span dst, bool add) 11 | { 12 | if(!add) MultiplyAdvance(dst, Data, Volume); 13 | else AddMultipliedAdvance(dst, Data, Volume); 14 | return dst; 15 | } 16 | 17 | RecordedSampler CachedDrumInstrument::operator()(float volume, uint sampleRate) const 18 | { 19 | if(SampleRate == 0) 20 | { 21 | SampleRate = sampleRate; 22 | DataSampler(Data, false); 23 | float u = 1; 24 | LinearMultiply(Data.Tail(300), u, -0.00333f); 25 | } 26 | return {Data, volume*VolumeScale, float(SampleRate)/float(sampleRate)}; 27 | } 28 | 29 | 30 | }}} 31 | 32 | INTRA_WARNING_POP 33 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/RecordedSampler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Utils/Span.h" 5 | #include "Container/Sequential/Array.h" 6 | #include "Types.h" 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | namespace Intra { namespace Audio { namespace Synth { 11 | 12 | struct RecordedSampler 13 | { 14 | CSpan Data; 15 | float Volume; 16 | float PlaybackRate; 17 | 18 | Span operator()(Span dst, bool add); 19 | }; 20 | 21 | struct CachedDrumInstrument 22 | { 23 | mutable Array Data; 24 | mutable GenericSampler DataSampler; 25 | mutable uint SampleRate = 0; 26 | float VolumeScale; 27 | 28 | CachedDrumInstrument(GenericSampler sampler, size_t sampleCount = 44100, float volumeScale = 1): 29 | DataSampler(Cpp::Move(sampler)), VolumeScale(volumeScale) {Data.SetCountUninitialized(sampleCount);} 30 | 31 | RecordedSampler operator()(float volume, uint sampleRate) const; 32 | 33 | void Preload(uint sampleRate = 44100) const {operator()(1, sampleRate);} 34 | }; 35 | 36 | }}} 37 | 38 | INTRA_WARNING_POP 39 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/WaveTable.cpp: -------------------------------------------------------------------------------- 1 | #include "WaveTable.h" 2 | #include "Audio/Resample.h" 3 | 4 | namespace Intra { namespace Audio { namespace Synth { 5 | 6 | void WaveTable::GenerateNextLevel() 7 | { 8 | INTRA_DEBUG_ASSERT(CheckInvariant()); 9 | size_t index = LevelStartIndex(LevelCount); 10 | Data.SetCountUninitialized(index + LevelSize(LevelCount++)); 11 | DecimateX2Linear(LevelSamples(LevelCount-1), LevelSamples(LevelCount-2)); 12 | } 13 | 14 | void WaveTable::UpsampleBaseLevel() 15 | { 16 | INTRA_DEBUG_ASSERT(CheckInvariant()); 17 | BaseLevelLength *= 2; 18 | BaseLevelRatio /= 2; 19 | LevelCount++; 20 | Data.AddLeftUninitialized(BaseLevelLength); 21 | UpsampleX2Linear(Data.Take(BaseLevelLength), LevelSamples(1)); 22 | } 23 | 24 | void WaveTable::GenerateAllNextLevels() 25 | { 26 | while(LevelSize(LevelCount) > 1) GenerateNextLevel(); 27 | } 28 | 29 | }}} 30 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/WaveTable.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Audio/Synth/WaveTable.h -------------------------------------------------------------------------------- /Intra/Audio/Synth/WhiteNoiseSampler.cpp: -------------------------------------------------------------------------------- 1 | #include "WhiteNoiseSampler.h" 2 | 3 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 4 | 5 | namespace Intra { namespace Audio { namespace Synth { 6 | 7 | Span WhiteNoiseSampler::operator()(Span inOutSamples, bool add) 8 | { 9 | if(add) while(!inOutSamples.Empty()) 10 | { 11 | inOutSamples.Next() += mAmplitude*Random::FastUniformNoise::Linear(mT); 12 | mT += mDT; 13 | } 14 | else while(!inOutSamples.Empty()) 15 | { 16 | inOutSamples.Next() = mAmplitude*Random::FastUniformNoise::Linear(mT); 17 | mT += mDT; 18 | } 19 | return inOutSamples; 20 | } 21 | 22 | }}} 23 | 24 | INTRA_WARNING_POP 25 | -------------------------------------------------------------------------------- /Intra/Audio/Synth/WhiteNoiseSampler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | 5 | #include "Utils/Span.h" 6 | 7 | #include "Random/FastUniformNoise.h" 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | namespace Intra { namespace Audio { namespace Synth { 12 | 13 | class WhiteNoiseSampler 14 | { 15 | float mT, mDT; 16 | float mAmplitude; 17 | public: 18 | WhiteNoiseSampler(float dt, float amplitude): 19 | mT(0), mDT(dt), mAmplitude(amplitude) {} 20 | 21 | Span operator()(Span inOutSamples, bool add); 22 | }; 23 | 24 | struct WhiteNoiseInstrument 25 | { 26 | float VolumeScale; 27 | float FreqMultiplier; 28 | 29 | forceinline WhiteNoiseInstrument(null_t=null): VolumeScale(0), FreqMultiplier(1) {} 30 | forceinline WhiteNoiseInstrument(float volumeScale, float freqMult = 1): 31 | VolumeScale(volumeScale), FreqMultiplier(freqMult) {} 32 | 33 | WhiteNoiseSampler operator()(float freq, float volume, uint sampleRate) const 34 | {return WhiteNoiseSampler(freq*FreqMultiplier/float(sampleRate), volume*VolumeScale);} 35 | 36 | forceinline explicit operator bool() const noexcept {return VolumeScale > 0;} 37 | forceinline bool operator==(null_t) const noexcept {return VolumeScale <= 0;} 38 | forceinline bool operator!=(null_t) const noexcept {return !operator==(null);} 39 | }; 40 | 41 | }}} 42 | 43 | INTRA_WARNING_POP 44 | -------------------------------------------------------------------------------- /Intra/Concepts.hh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concepts.hh -------------------------------------------------------------------------------- /Intra/Concepts/Array.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concepts/Array.h -------------------------------------------------------------------------------- /Intra/Concepts/IInput.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concepts/IInput.h -------------------------------------------------------------------------------- /Intra/Concepts/IOutput.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concepts/IOutput.h -------------------------------------------------------------------------------- /Intra/Concurrency/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | find_package(Threads) 4 | if(THREADS_FOUND) 5 | if(UNIX) 6 | option(LIBRARY_THREADING_PThread "Use pthread" ON) 7 | else() 8 | option(LIBRARY_THREADING_PThread "Use pthread" OFF) 9 | endif() 10 | endif() 11 | 12 | if(LIBRARY_THREADING_PThread) 13 | add_definitions(-DINTRA_LIBRARY_THREADING=INTRA_LIBRARY_THREADING_PThread) 14 | include_directories(${THREADS_INCLUDE_DIRS}) 15 | target_link_libraries(Intra ${CMAKE_THREAD_LIBS_INIT}) 16 | elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 17 | add_definitions(-DINTRA_LIBRARY_THREADING=INTRA_LIBRARY_THREADING_WinAPI) 18 | else() 19 | add_definitions(-DINTRA_LIBRARY_THREADING=INTRA_LIBRARY_THREADING_Dummy) 20 | endif() 21 | -------------------------------------------------------------------------------- /Intra/Concurrency/CondVar.cpp: -------------------------------------------------------------------------------- 1 | #include "CondVar.h" 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/PlatformDetect.h" 5 | #include "Cpp/Runtime.h" 6 | 7 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 8 | 9 | #if(INTRA_LIBRARY_MUTEX == INTRA_LIBRARY_MUTEX_Cpp11) 10 | 11 | #include "detail/CondVarCpp11.hxx" 12 | 13 | #elif(INTRA_LIBRARY_MUTEX == INTRA_LIBRARY_MUTEX_WinAPI) 14 | 15 | #include "detail/CondVarWinAPI.hxx" 16 | 17 | #elif(INTRA_LIBRARY_MUTEX == INTRA_LIBRARY_MUTEX_PThread) 18 | 19 | #include "detail/CondVarPThread.hxx" 20 | 21 | #endif 22 | 23 | INTRA_WARNING_POP 24 | -------------------------------------------------------------------------------- /Intra/Concurrency/CondVar.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concurrency/CondVar.h -------------------------------------------------------------------------------- /Intra/Concurrency/Lock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Preprocessor/Operations.h" 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | namespace Intra { namespace Concurrency { 11 | 12 | template class Lock 13 | { 14 | T* mLockable; 15 | public: 16 | forceinline Lock(T& lockable): mLockable(&lockable) {lockable.Lock();} 17 | forceinline Lock(Lock&& rhs): mLockable(rhs.mLockable) {rhs.mLockable = null;} 18 | forceinline ~Lock() {mLockable->Unlock();} 19 | forceinline operator bool() const noexcept {return true;} 20 | 21 | T& Primitive() {return *mLockable;} 22 | 23 | private: 24 | Lock(const Lock&) = delete; 25 | Lock& operator=(const Lock&) = delete; 26 | }; 27 | 28 | template static forceinline Lock MakeLock(T& lockable) {return lockable;} 29 | template static forceinline Lock MakeLock(T* lockable) {return *lockable;} 30 | 31 | #define INTRA_SYNCHRONIZED(lockable) \ 32 | if(auto INTRA_CONCATENATE_TOKENS(locker__, __LINE__) = ::Intra::Concurrency::MakeLock(lockable)) 33 | 34 | }} 35 | 36 | INTRA_WARNING_POP 37 | -------------------------------------------------------------------------------- /Intra/Concurrency/Mutex.cpp: -------------------------------------------------------------------------------- 1 | #include "Mutex.h" 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/PlatformDetect.h" 5 | #include "Cpp/Runtime.h" 6 | 7 | #if(INTRA_LIBRARY_MUTEX != INTRA_LIBRARY_MUTEX_None) 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | #if(INTRA_LIBRARY_MUTEX == INTRA_LIBRARY_MUTEX_Cpp11) 12 | 13 | #include "detail/MutexCpp11.hxx" 14 | 15 | #elif(INTRA_LIBRARY_MUTEX == INTRA_LIBRARY_MUTEX_WinAPI) 16 | 17 | #include "detail/MutexWinAPI.hxx" 18 | 19 | #elif(INTRA_LIBRARY_MUTEX == INTRA_LIBRARY_MUTEX_PThread) 20 | 21 | #include "detail/MutexPThread.hxx" 22 | 23 | #endif 24 | 25 | namespace Intra { namespace Concurrency { 26 | const int Mutex::DataSize = Mutex::DATA_SIZE; 27 | const int Mutex::ImplementationType = INTRA_LIBRARY_MUTEX; 28 | }} 29 | 30 | INTRA_WARNING_POP 31 | 32 | #endif -------------------------------------------------------------------------------- /Intra/Concurrency/Mutex.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concurrency/Mutex.h -------------------------------------------------------------------------------- /Intra/Concurrency/ThreadPool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /Intra/Concurrency/detail/AtomicMSVC.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concurrency/detail/AtomicMSVC.h -------------------------------------------------------------------------------- /Intra/Concurrency/detail/CondVarCpp11.hxx: -------------------------------------------------------------------------------- 1 | #include "Concurrency/CondVar.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Intra { namespace Concurrency { 8 | 9 | SeparateCondVar::SeparateCondVar() 10 | { 11 | static_assert(sizeof(mData) >= sizeof(std::condition_variable), "Invalid DATA_SIZE in CondVar.h!"); 12 | new(mData) std::condition_variable; 13 | } 14 | 15 | SeparateCondVar::~SeparateCondVar() {reinterpret_cast(mData)->~condition_variable();} 16 | 17 | bool SeparateCondVar::wait(Mutex& mutex) 18 | { 19 | std::unique_lock lck(*reinterpret_cast(mutex.mData), std::adopt_lock); 20 | reinterpret_cast(mData)->wait(lck); 21 | lck.release(); 22 | return true; 23 | } 24 | 25 | static std::chrono::system_clock::time_point absTimeToTimePoint(ulong64 msecs) 26 | { 27 | return std::chrono::system_clock::from_time_t(std::time_t(msecs / 1000)) + std::chrono::milliseconds(msecs % 1000); 28 | } 29 | 30 | bool SeparateCondVar::waitUntil(Mutex& mutex, ulong64 absTimeMs) 31 | { 32 | std::unique_lock lck(*reinterpret_cast(mutex.mData), std::adopt_lock); 33 | const bool result = reinterpret_cast(mData)->wait_until(lck, absTimeToTimePoint(absTimeMs)) == std::cv_status::no_timeout; 34 | lck.release(); 35 | return result; 36 | } 37 | 38 | void SeparateCondVar::Notify() {reinterpret_cast(mData)->notify_one();} 39 | void SeparateCondVar::NotifyAll() {reinterpret_cast(mData)->notify_all();} 40 | 41 | }} 42 | -------------------------------------------------------------------------------- /Intra/Concurrency/detail/CondVarPThread.hxx: -------------------------------------------------------------------------------- 1 | #include "Concurrency/CondVar.h" 2 | 3 | #include 4 | 5 | #ifdef _MSC_VER 6 | #pragma comment(lib, "pthread.lib") 7 | #endif 8 | 9 | namespace Intra { namespace Concurrency { 10 | 11 | SeparateCondVar::SeparateCondVar() 12 | { 13 | static_assert(sizeof(mData) >= sizeof(pthread_cond_t), "Invalid DATA_SIZE in CondVar.h!"); 14 | pthread_cond_init(reinterpret_cast(mData), null); 15 | } 16 | 17 | SeparateCondVar::~SeparateCondVar() {pthread_cond_destroy(reinterpret_cast(mData));} 18 | 19 | bool SeparateCondVar::wait(Mutex& lock) 20 | {return pthread_cond_wait(reinterpret_cast(mData), reinterpret_cast(lock.mData)) == 0;} 21 | 22 | bool SeparateCondVar::waitUntil(Mutex& mutex, ulong64 absTimeMs) 23 | { 24 | timespec absTime = {time_t(absTimeMs / 1000), long((absTimeMs % 1000) * 1000000)}; 25 | return pthread_cond_timedwait(reinterpret_cast(mData), reinterpret_cast(mutex.mData), &absTime) == 0; 26 | } 27 | 28 | void SeparateCondVar::Notify() {pthread_cond_signal(reinterpret_cast(mData));} 29 | void SeparateCondVar::NotifyAll() {pthread_cond_broadcast(reinterpret_cast(mData));} 30 | 31 | }} 32 | -------------------------------------------------------------------------------- /Intra/Concurrency/detail/MutexCpp11.hxx: -------------------------------------------------------------------------------- 1 | #include "Concurrency/Mutex.h" 2 | 3 | #include 4 | 5 | namespace Intra { namespace Concurrency { 6 | 7 | Mutex::Mutex() 8 | { 9 | static_assert(sizeof(mData) >= sizeof(std::mutex), "Invalid DATA_SIZE in Mutex.h!"); 10 | new(mData) std::mutex; 11 | } 12 | Mutex::~Mutex() {reinterpret_cast(mData)->~mutex();} 13 | void Mutex::Lock() {reinterpret_cast(mData)->lock();} 14 | bool Mutex::TryLock() {return reinterpret_cast(mData)->try_lock();} 15 | void Mutex::Unlock() {reinterpret_cast(mData)->unlock();} 16 | 17 | RecursiveMutex::RecursiveMutex() 18 | { 19 | static_assert(sizeof(mData) >= sizeof(std::recursive_mutex), "Invalid DATA_SIZE in Mutex.h!"); 20 | new(mData) std::recursive_mutex; 21 | } 22 | RecursiveMutex::~RecursiveMutex() {reinterpret_cast(mData)->~recursive_mutex();} 23 | void RecursiveMutex::Lock() {reinterpret_cast(mData)->lock();} 24 | bool RecursiveMutex::TryLock() {return reinterpret_cast(mData)->try_lock();} 25 | void RecursiveMutex::Unlock() {reinterpret_cast(mData)->unlock();} 26 | 27 | }} 28 | -------------------------------------------------------------------------------- /Intra/Concurrency/detail/MutexPThread.hxx: -------------------------------------------------------------------------------- 1 | #include "Concurrency/Mutex.h" 2 | 3 | #include 4 | 5 | #ifdef _MSC_VER 6 | #pragma comment(lib, "pthread.lib") 7 | #endif 8 | 9 | namespace Intra { namespace Concurrency { 10 | 11 | static void createMutex(void* mutexData, bool recursive) 12 | { 13 | pthread_mutexattr_t attr; 14 | pthread_mutexattr_init(&attr); 15 | pthread_mutexattr_settype(&attr, recursive? PTHREAD_MUTEX_RECURSIVE: PTHREAD_MUTEX_ERRORCHECK); 16 | pthread_mutex_init(static_cast(mutexData), &attr); 17 | } 18 | 19 | Mutex::Mutex() 20 | { 21 | static_assert(sizeof(mData) >= sizeof(pthread_mutex_t), "Invalid DATA_SIZE in Mutex.h!"); 22 | createMutex(mData, false); 23 | } 24 | Mutex::~Mutex() {pthread_mutex_destroy(reinterpret_cast(mData));} 25 | void Mutex::Lock() {pthread_mutex_lock(reinterpret_cast(mData));} 26 | bool Mutex::TryLock() {return pthread_mutex_trylock(reinterpret_cast(mData)) != 0;} 27 | void Mutex::Unlock() {pthread_mutex_unlock(reinterpret_cast(mData));} 28 | 29 | 30 | RecursiveMutex::RecursiveMutex() 31 | { 32 | static_assert(sizeof(mData) >= sizeof(pthread_mutex_t), "Invalid DATA_SIZE in Mutex.h!"); 33 | createMutex(mData, true); 34 | } 35 | RecursiveMutex::~RecursiveMutex() {pthread_mutex_destroy(reinterpret_cast(mData));} 36 | void RecursiveMutex::Lock() {pthread_mutex_lock(reinterpret_cast(mData));} 37 | bool RecursiveMutex::TryLock() {return pthread_mutex_trylock(reinterpret_cast(mData)) != 0;} 38 | void RecursiveMutex::Unlock() {pthread_mutex_unlock(reinterpret_cast(mData));} 39 | 40 | }} 41 | -------------------------------------------------------------------------------- /Intra/Concurrency/detail/ThreadCpp11.hxx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concurrency/detail/ThreadCpp11.hxx -------------------------------------------------------------------------------- /Intra/Concurrency/detail/ThreadPThread.hxx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concurrency/detail/ThreadPThread.hxx -------------------------------------------------------------------------------- /Intra/Concurrency/detail/ThreadSleep.hxx: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Concurrency/Thread.h" 4 | 5 | #if(INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_Windows) 6 | 7 | #ifndef WIN32_LEAN_AND_MEAN 8 | #define WIN32_LEAN_AND_MEAN 9 | #endif 10 | 11 | #ifdef _MSC_VER 12 | #pragma warning(push) 13 | #pragma warning(disable: 4668) 14 | #endif 15 | 16 | #include 17 | #undef Yield 18 | 19 | #ifdef _MSC_VER 20 | #pragma warning(pop) 21 | #endif 22 | 23 | #else 24 | #include 25 | #endif 26 | 27 | namespace Intra { namespace Concurrency { 28 | 29 | #if(INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_Windows) 30 | 31 | static bool ThisThreadSleep(ulong64 milliseconds) 32 | { 33 | if(milliseconds == 0) 34 | { 35 | ThisThread.Yield(); 36 | return true; 37 | } 38 | 39 | while(milliseconds >= INFINITE - 1) 40 | { 41 | ::Sleep(INFINITE - 1); 42 | milliseconds -= INFINITE - 1; 43 | } 44 | ::Sleep(DWORD(milliseconds)); 45 | return true; 46 | } 47 | 48 | #else 49 | 50 | static bool ThisThreadSleep(ulong64 milliseconds) 51 | { 52 | while(milliseconds / 1000 >= 0xFFFFFFFF) 53 | { 54 | sleep(0xFFFFFFFF); 55 | milliseconds -= 0xFFFFFFFFULL * 1000; 56 | } 57 | if(milliseconds >= 0xFFFFFFFF / 1000) 58 | { 59 | sleep(unsigned(milliseconds / 1000)); 60 | milliseconds = milliseconds % 1000; 61 | } 62 | usleep(unsigned(milliseconds) * 1000); 63 | return true; 64 | } 65 | 66 | #endif 67 | 68 | }} 69 | -------------------------------------------------------------------------------- /Intra/Concurrency/detail/ThreadWinAPI.hxx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Concurrency/detail/ThreadWinAPI.hxx -------------------------------------------------------------------------------- /Intra/Container.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Container/Sequential.hh" 4 | #include "Container/Utility.hh" 5 | #include "Container/Associative.hh" 6 | #include "Container/Operations.hh" 7 | -------------------------------------------------------------------------------- /Intra/Container/AllForwardDecls.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Memory/Allocator/Global.h" 4 | #include "ForwardDecls.h" 5 | 6 | namespace Intra { namespace Container { 7 | 8 | template class BList; 9 | template class HashMap; 10 | 11 | } 12 | 13 | using Container::HashMap; 14 | using Container::BList; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Intra/Container/Associative.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Associative/HashMap.h" 4 | #include "Associative/LinearMap.h" 5 | #include "Associative/LinearSet.h" 6 | -------------------------------------------------------------------------------- /Intra/Container/ForwardDecls.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | 5 | namespace Intra { namespace Container { 6 | 7 | template class Array; 8 | template class LinearMap; 9 | template class GenericString; 10 | typedef GenericString String; 11 | typedef GenericString WString; 12 | typedef GenericString DString; 13 | 14 | } 15 | 16 | using Container::Array; 17 | using Container::LinearMap; 18 | using Container::GenericString; 19 | using Container::String; 20 | using Container::WString; 21 | using Container::DString; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Intra/Container/Operations.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Operations/Append.h" 4 | #include "Operations/Comparison.h" 5 | #include "Operations/Info.h" 6 | -------------------------------------------------------------------------------- /Intra/Container/Operations/Comparison.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Meta/Type.h" 6 | #include "Concepts/Range.h" 7 | #include "Concepts/RangeOf.h" 8 | #include "Concepts/Container.h" 9 | #include "Range/Comparison/Equals.h" 10 | 11 | namespace Intra { namespace Container { 12 | 13 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 14 | 15 | template forceinline Meta::EnableIf< 16 | (Concepts::IsSequentialContainer::_ && 17 | Concepts::IsAsConsumableRange::_) || 18 | (Concepts::IsSequentialContainer::_ && 19 | Concepts::IsAsConsumableRange::_), 20 | bool> operator==(L&& lhs, R&& rhs) 21 | { 22 | using Concepts::RangeOf; 23 | return Range::Equals(RangeOf(lhs), RangeOf(rhs)); 24 | } 25 | 26 | template forceinline Meta::EnableIf< 27 | (Concepts::IsSequentialContainer::_ && 28 | Concepts::IsAsConsumableRange::_) || 29 | (Concepts::IsSequentialContainer::_ && 30 | Concepts::IsAsConsumableRange::_), 31 | bool> operator!=(L&& lhs, R&& rhs) 32 | {return !operator==(Cpp::Forward(lhs), Cpp::Forward(rhs));} 33 | 34 | template forceinline Meta::EnableIf< 35 | Concepts::IsSequentialContainer::_, 36 | bool> operator==(L&& lhs, InitializerList rhs) 37 | { 38 | using Concepts::RangeOf; 39 | return Range::Equals(RangeOf(lhs), SpanOf(rhs)); 40 | } 41 | 42 | template forceinline Meta::EnableIf< 43 | Concepts::IsSequentialContainer::_, 44 | bool> operator!=(L&& lhs, InitializerList rhs) 45 | {return !operator==(Cpp::Forward(lhs), rhs);} 46 | 47 | INTRA_WARNING_POP 48 | 49 | }} 50 | -------------------------------------------------------------------------------- /Intra/Container/Operations/Info.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Concepts/Container.h" 5 | 6 | namespace Intra { namespace Container { 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | template forceinline Meta::EnableIf< 11 | Concepts::Has_empty::_, 12 | bool> operator==(const C& lhs, null_t) {return lhs.empty();} 13 | 14 | 15 | template forceinline Meta::EnableIf< 16 | Concepts::Has_empty::_, 17 | bool> operator==(null_t, const C& rhs) {return rhs.empty();} 18 | 19 | template forceinline Meta::EnableIf< 20 | Concepts::Has_empty::_, 21 | bool> operator!=(const C& lhs, null_t) {return !lhs.empty();} 22 | 23 | template forceinline Meta::EnableIf< 24 | Concepts::Has_empty::_, 25 | bool> operator!=(null_t, const C& rhs) {return !rhs.empty();} 26 | 27 | INTRA_WARNING_POP 28 | 29 | }} 30 | -------------------------------------------------------------------------------- /Intra/Container/ReadMe.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Container/ReadMe.md -------------------------------------------------------------------------------- /Intra/Container/Sequential.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sequential/Array.h" 4 | #include "Sequential/List.h" 5 | #include "Sequential/String.h" 6 | #include "Sequential/StructureOfArrays.h" 7 | -------------------------------------------------------------------------------- /Intra/Container/Sequential/ExtArray.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Container/Sequential/ExtArray.h -------------------------------------------------------------------------------- /Intra/Container/Sequential/StringFormatter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Container/Sequential/StringFormatter.h -------------------------------------------------------------------------------- /Intra/Container/Sequential/StructureOfArrays.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if INTRA_DISABLED 4 | 5 | #include "Meta/TypeList.h" 6 | #include "Meta/Tuple.h" 7 | 8 | namespace Intra { 9 | 10 | template class StructureOfArrays 11 | { 12 | public: 13 | typedef Tuple AoS; 14 | typedef Tuple SoA; 15 | typedef TypeList TL; 16 | enum: uint {ColumnCount = TypeListLength(TL);}; 17 | 18 | void AddLast() 19 | { 20 | CheckSpace(1); 21 | add<0>(); 22 | } 23 | 24 | void CheckSpace(size_t space) {Reserve(count+space);} 25 | 26 | void Reserve(size_t capacityToReserve) 27 | { 28 | if(capacityToReserve>size) 29 | Resize(Math::max(capacityToReserve, size+size/2)); 30 | } 31 | 32 | void Resize(size_t size); 33 | 34 | void SetCount(size_t newCount); 35 | 36 | size_t Count() const {return count;} 37 | size_t Size() const {return size;} 38 | 39 | private: 40 | SoA data; 41 | size_t count, size; 42 | 43 | template void add() 44 | { 45 | new(data.Get()) TypeListTypeAt; 46 | add(); 47 | } 48 | 49 | template<> void add() {} 50 | 51 | 52 | template void add(const AoS& aos) 53 | { 54 | new(data.Get()) TypeListTypeAt(aos.Get()); 55 | add(aos); 56 | } 57 | 58 | template<> void add(const AoS& aos) {} 59 | 60 | 61 | template void add(AoS&& aos) 62 | { 63 | new(data.Get()) TypeListTypeAt(std::move(aos.Get())); 64 | add(std::move(aos)); 65 | } 66 | 67 | template<> void add(AoS&& aos) {} 68 | }; 69 | 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /Intra/Container/Utility.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utility/Array2D.h" 4 | #include "Utility/IndexAllocator.h" 5 | #include "Utility/IntervalAllocator.h" 6 | #include "Utility/SparseArray.h" 7 | #include "Utility/SparseHandledArray.h" 8 | #include "Utility/Tree.h" 9 | -------------------------------------------------------------------------------- /Intra/Container/Utility/OwningArrayRange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Container/Sequential/Array.h" 4 | 5 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 6 | 7 | namespace Intra { namespace Container { 8 | 9 | template struct OwningArrayRange 10 | { 11 | forceinline OwningArrayRange(Array elements): Elements(Cpp::Move(elements)) {} 12 | 13 | forceinline T& First() {return Elements.First();} 14 | forceinline const T& First() const {return Elements.First();} 15 | forceinline void PopFirst() {Elements.RemoveFirst();} 16 | 17 | forceinline T& Last() {return Elements.Last();} 18 | forceinline const T& Last() const {return Elements.Last();} 19 | forceinline void PopLast() {Elements.RemoveLast();} 20 | 21 | forceinline bool Empty() const {return Elements.Empty();} 22 | 23 | forceinline size_t Length() const {return Elements.Length();} 24 | forceinline T& operator[](size_t index) {return Elements[index];} 25 | forceinline const T& operator[](size_t index) const {return Elements[index];} 26 | 27 | forceinline T* Data() {return Elements.Data();} 28 | forceinline const T* Data() const {return Elements.Data();} 29 | 30 | forceinline Span AsSpan() {return Elements;} 31 | forceinline Span AsSpan() const {return Elements;} 32 | 33 | Array Elements; 34 | }; 35 | 36 | } 37 | using Container::OwningArrayRange; 38 | 39 | } 40 | 41 | INTRA_WARNING_POP 42 | -------------------------------------------------------------------------------- /Intra/Container/Utility/StaticBitset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Utils/Debug.h" 5 | 6 | namespace Intra { namespace Container { 7 | 8 | template struct StaticBitset 9 | { 10 | uint Data[(N + 31) >> 5]{}; 11 | 12 | bool operator[](size_t index) const 13 | { 14 | INTRA_DEBUG_ASSERT(index < N); 15 | return ((Data[index >> 5] >> (index & 31)) & 1) != 0; 16 | } 17 | 18 | void Set(size_t index) 19 | { 20 | INTRA_DEBUG_ASSERT(index < N); 21 | Data[index >> 5] |= 1u << (index & 31); 22 | } 23 | 24 | void Reset(size_t index) 25 | { 26 | INTRA_DEBUG_ASSERT(index < N); 27 | Data[index >> 5] &= ~(1u << (index & 31)); 28 | } 29 | }; 30 | 31 | } 32 | using Container::StaticBitset; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Intra/Container/Utility/Tree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Container/Sequential/Array.h" 4 | 5 | namespace Intra { 6 | 7 | template struct Tree 8 | { 9 | explicit Tree(const T& value=T(), size_t nodeCount=0): 10 | Nodes(nodeCount), Value(value) {AddNodes(nodeCount);} 11 | 12 | Tree(const T& value, CSpan nodeValues): 13 | Nodes(nodeValues.Count()), Value(value) {AddNodes(nodeValues);} 14 | 15 | void AddNodes(size_t nodeCount=0, const T& value=T()) 16 | { 17 | for(size_t i=0; i nodeValues) {for(auto& v: nodeValues) Nodes.AddLast(Tree(v));} 22 | void AddNodes(const Tree& rootOfNodes) {for(auto& n: rootOfNodes) Nodes.AddLast(n);} 23 | 24 | Array* operator->() {return &Nodes;} 25 | Tree& operator[](size_t index) {return Nodes[index];} 26 | const Array* operator->() const {return &Nodes;} 27 | const Tree& operator[](size_t index) const {return Nodes[index];} 28 | 29 | Array Nodes; 30 | T Value; 31 | }; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Intra/Cpp.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Compatibility.h" 5 | #include "Cpp/Features.h" 6 | #include "Cpp/InitializerList.h" 7 | #include "Cpp/Intrinsics.h" 8 | #include "Cpp/PlatformDetect.h" 9 | #include "Cpp/Runtime.h" 10 | #include "Cpp/SharedLib.h" 11 | #include "Cpp/Warnings.h" 12 | -------------------------------------------------------------------------------- /Intra/Cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(IntraCpp) 4 | 5 | include(../../Configurations.cmake) 6 | 7 | init_project_sources(${CMAKE_CURRENT_SOURCE_DIR} CPP_HEADERS CPP_SOURCES) 8 | add_library(IntraCpp STATIC ${CPP_SOURCES} ${CPP_HEADERS}) 9 | -------------------------------------------------------------------------------- /Intra/Cpp/Compatibility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _MSC_VER 4 | 5 | #if(!defined(__GNUC__) && !defined(__clang__)) 6 | #pragma execution_character_set("utf-8") 7 | #endif 8 | 9 | #elif(defined(__clang__)) 10 | 11 | //extern "C" char* gets(char* str); //Затыкаем ошибку в стандартной библиотеке glibc, из-за которой clang не компилирует 12 | 13 | #endif 14 | 15 | #ifdef _MSC_VER 16 | #define INTRA_CRTDECL __cdecl 17 | #else 18 | #define INTRA_CRTDECL 19 | #endif 20 | 21 | #ifdef _MSC_VER 22 | //Clang 3.7 with Microsoft CodeGen (v140_clang_3_7) почему-то без этого не компилирует 23 | #define _ALLOW_KEYWORD_MACROS 24 | #endif 25 | -------------------------------------------------------------------------------- /Intra/Cpp/InitializerList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compatibility.h" 4 | #include "Features.h" 5 | #include "Fundamental.h" 6 | #include "Warnings.h" 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | #if(defined(_MSC_VER) && defined(INTRA_AVOID_STD_HEADERS)) 11 | 12 | #ifndef _INITIALIZER_LIST_ 13 | #define _INITIALIZER_LIST_ 14 | 15 | namespace std { 16 | 17 | template class initializer_list 18 | { 19 | public: 20 | typedef T value_type; 21 | typedef const T& reference; 22 | typedef const T& const_reference; 23 | typedef size_t size_type; 24 | 25 | typedef const T* iterator; 26 | typedef const T* const_iterator; 27 | 28 | constexpr initializer_list() throw(): _First(nullptr), _Last(nullptr) {} 29 | constexpr initializer_list(const T* first, const T* last) throw(): _First(first), _Last(last) {} 30 | 31 | constexpr const T* begin() const throw() {return _First;} 32 | constexpr const T* end() const throw() {return _Last;} 33 | constexpr size_t size() const throw() {return size_t(_Last-_First);} 34 | 35 | private: 36 | const T* _First; 37 | const T* _Last; 38 | }; 39 | 40 | template inline constexpr const T* begin(initializer_list list) throw() {return list.begin();} 41 | template inline constexpr const T* end(initializer_list list) throw() {return list.end();} 42 | 43 | } 44 | 45 | #endif 46 | 47 | #else 48 | 49 | #include 50 | 51 | #endif 52 | 53 | namespace Intra { 54 | 55 | template using InitializerList = std::initializer_list; 56 | 57 | } 58 | 59 | INTRA_WARNING_POP 60 | -------------------------------------------------------------------------------- /Intra/Cpp/Intrinsics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Fundamental.h" 4 | #include "Compatibility.h" 5 | 6 | #if !defined(_MSC_VER) || !defined(INTRA_AVOID_STD_HEADERS) 7 | #include 8 | #include 9 | #include 10 | #endif 11 | 12 | namespace Intra { 13 | 14 | #ifdef _MSC_VER 15 | #define INTRA_DEBUG_BREAK __debugbreak() 16 | #elif defined(__GNUC__) 17 | #define INTRA_DEBUG_BREAK __builtin_trap() 18 | #else 19 | #include 20 | #define INTRA_DEBUG_BREAK raise(SIGTRAP) 21 | #endif 22 | 23 | namespace C { extern "C" { 24 | 25 | #if defined(_MSC_VER) && defined(INTRA_AVOID_STD_HEADERS) 26 | const void* INTRA_CRTDECL memchr(const void* buf, int val, size_t maxCount); 27 | int INTRA_CRTDECL memcmp(const void* buf1, const void* buf2, size_t size); 28 | void* INTRA_CRTDECL memcpy(void* dst, const void* src, size_t size); 29 | void* INTRA_CRTDECL memmove(void* _Dst, const void* src, size_t size); 30 | void* INTRA_CRTDECL memset(void*, int val, size_t size); 31 | size_t INTRA_CRTDECL strlen(const char* str) throw(); 32 | size_t INTRA_CRTDECL wcslen(const wchar_t* str) throw(); 33 | 34 | void* INTRA_CRTDECL malloc(size_t bytes) throw(); 35 | void* INTRA_CRTDECL realloc(void* oldPtr, size_t bytes) throw(); 36 | void INTRA_CRTDECL free(void* ptr) throw(); 37 | #else 38 | using ::memchr; 39 | using ::memcmp; 40 | using ::memcpy; 41 | using ::memmove; 42 | using ::memset; 43 | using ::strlen; 44 | using ::wcslen; 45 | using ::malloc; 46 | using ::realloc; 47 | using ::free; 48 | #endif 49 | 50 | }}} 51 | -------------------------------------------------------------------------------- /Intra/Cpp/PlacementNew.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 4 | 5 | #ifdef _MSC_VER 6 | 7 | #ifndef __PLACEMENT_NEW_INLINE 8 | #define __PLACEMENT_NEW_INLINE 9 | inline void* operator new(size_t, void* dst) {return dst;} 10 | inline void operator delete(void*, void*) {} 11 | #endif 12 | 13 | #ifndef __PLACEMENT_VEC_NEW_INLINE 14 | #define __PLACEMENT_VEC_NEW_INLINE 15 | inline void* operator new[](size_t, void* dst) {return dst;} 16 | inline void operator delete[](void*, void*) {} 17 | #endif 18 | 19 | #else 20 | 21 | #include 22 | 23 | #endif 24 | 25 | INTRA_WARNING_POP 26 | -------------------------------------------------------------------------------- /Intra/Cpp/PlatformDetect.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Cpp/PlatformDetect.h -------------------------------------------------------------------------------- /Intra/Cpp/Runtime.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if(defined(_MSC_VER) && defined(INTRA_MINIMIZE_CRT)) 4 | 5 | #define _NO_CRT_STDIO_INLINE 6 | 7 | #define INTRA_NOT_LINK_CRT_LIB 8 | 9 | #pragma comment(lib, "msvcrtOLD.lib") 10 | 11 | #if _MSC_VER>=1900 12 | #pragma comment(lib, "msvcrtOLD2015.lib") 13 | #endif 14 | 15 | #ifdef INTRA_NOT_LINK_CRT_LIB 16 | #pragma comment(linker, "/NODEFAULTLIB:libcmt.lib") 17 | #pragma comment(linker, "/NODEFAULTLIB:libcpmt.lib") 18 | #pragma comment(linker, "/NODEFAULTLIB:msvcrt.lib") 19 | #pragma comment(linker, "/NODEFAULTLIB:msvcrt100.lib") 20 | #pragma comment(linker, "/NODEFAULTLIB:msvcrt110.lib") 21 | #pragma comment(linker, "/NODEFAULTLIB:msvcrt120.lib") 22 | #pragma comment(linker, "/NODEFAULTLIB:msvcrt140.lib") 23 | #pragma comment(linker, "/NODEFAULTLIB:msvcp100.lib") 24 | #pragma comment(linker, "/NODEFAULTLIB:msvcp110.lib") 25 | #pragma comment(linker, "/NODEFAULTLIB:msvcp120.lib") 26 | #pragma comment(linker, "/NODEFAULTLIB:msvcp140.lib") 27 | #pragma comment(linker, "/NODEFAULTLIB:msvcr100.lib") 28 | #pragma comment(linker, "/NODEFAULTLIB:msvcr110.lib") 29 | #pragma comment(linker, "/NODEFAULTLIB:msvcr120.lib") 30 | #pragma comment(linker, "/NODEFAULTLIB:msvcr140.lib") 31 | //TODO: add libs for MSVC 2017 32 | #endif 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Intra/Cpp/SharedLib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef INTRA_IMPORTS_FROM_DLL 4 | #define INTRA_DLL_API __declspec(dllimport) 5 | #else 6 | #define INTRA_DLL_API __declspec(dllexport) 7 | #endif 8 | -------------------------------------------------------------------------------- /Intra/Data.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Data/Reflection.h" 4 | #include "Data/Variable.h" 5 | #include "Data/ValueType.h" 6 | #include "Data/Object.h" 7 | 8 | #include "Data/Serialization.hh" 9 | -------------------------------------------------------------------------------- /Intra/Data/BinarySerialization.cpp: -------------------------------------------------------------------------------- 1 | #include "Data/Serialization/BinarySerializer.h" 2 | #include "Data/Reflection.h" 3 | #include "Cpp/Warnings.h" 4 | 5 | //TODO: вынести этот файл в отдельный проект для Unit-тестов 6 | 7 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 8 | 9 | #ifdef INTRA_RUN_UNITTESTS 10 | 11 | #include "Container/Sequential/Array.h" 12 | #include "Container/Sequential/String.h" 13 | 14 | namespace Intra { namespace Data { 15 | 16 | }} 17 | 18 | #endif 19 | 20 | INTRA_WARNING_POP 21 | -------------------------------------------------------------------------------- /Intra/Data/Format.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Data/Format.h -------------------------------------------------------------------------------- /Intra/Data/Format/BinaryParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Data/Serialization/BinaryDeserializer.h" 4 | #include "BinaryRaw.h" 5 | 6 | namespace Intra { namespace Data { namespace Format { 7 | 8 | class BinaryParser 9 | { 10 | public: 11 | forceinline BinaryParser(CSpan data): mStream(data) {} 12 | 13 | private: 14 | CSpan mStream; 15 | }; 16 | 17 | }}} 18 | -------------------------------------------------------------------------------- /Intra/Data/Format/BinaryRaw.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Data/Format/BinaryRaw.h -------------------------------------------------------------------------------- /Intra/Data/Format/TextParser.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Data/Format/TextParser.h -------------------------------------------------------------------------------- /Intra/Data/Reflection.cpp: -------------------------------------------------------------------------------- 1 | #include "Data/Reflection.h" 2 | 3 | -------------------------------------------------------------------------------- /Intra/Data/Serialization.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Serialization/BinarySerializer.h" 4 | #include "Serialization/BinaryDeserializer.h" 5 | #include "Serialization/TextSerializer.h" 6 | #include "Serialization/TextDeserializer.h" 7 | #include "Serialization/TextSerializerParams.h" 8 | -------------------------------------------------------------------------------- /Intra/Data/Serialization/LanguageParams.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Data/Serialization/LanguageParams.h -------------------------------------------------------------------------------- /Intra/Data/Serialization/TextSerializerParams.cpp: -------------------------------------------------------------------------------- 1 | #include "Data/Serialization/TextSerializerParams.h" 2 | 3 | namespace Intra { namespace Data { 4 | 5 | const TextSerializerParams TextSerializerParams::Verbose = 6 | { 7 | false, 8 | true, 9 | true, 10 | TypeFlags_Struct|TypeFlags_StructArray, 11 | TypeFlags_Struct|TypeFlags_StructArray, 12 | "\t", 13 | "\r\n" 14 | }; 15 | 16 | const TextSerializerParams TextSerializerParams::VerboseNoSpaces = 17 | { 18 | false, 19 | true, 20 | false, 21 | TypeFlags_Struct|TypeFlags_StructArray, 22 | TypeFlags_Struct|TypeFlags_StructArray, 23 | "\t", 24 | "\r\n" 25 | }; 26 | 27 | const TextSerializerParams TextSerializerParams::Compact = 28 | { 29 | false, 30 | false, 31 | true, 32 | TypeFlags_StructArray, 33 | TypeFlags_StructArray, 34 | "\t", 35 | "\r\n" 36 | }; 37 | 38 | const TextSerializerParams TextSerializerParams::CompactSingleLine = 39 | { 40 | false, 41 | false, 42 | false, 43 | TypeFlags_None, 44 | TypeFlags_None, 45 | "\t", 46 | "\r\n" 47 | }; 48 | 49 | }} 50 | -------------------------------------------------------------------------------- /Intra/Font/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 4 | option(LIBRARY_FONT_LOADING_STB "Use STB_TrueType" ON) 5 | else() 6 | option(LIBRARY_FONT_LOADING_STB "Use STB_TrueType" OFF) 7 | endif() 8 | 9 | find_package(Freetype) 10 | if(FREETYPE_FOUND) 11 | if(UNIX) 12 | option(LIBRARY_FONT_LOADING_FreeType "Use FreeType" ON) 13 | else() 14 | option(LIBRARY_FONT_LOADING_FreeType "Use FreeType" OFF) 15 | endif() 16 | endif() 17 | 18 | if(LIBRARY_FONT_LOADING_FreeType) 19 | add_definitions(-DINTRA_LIBRARY_FONT_LOADING=INTRA_LIBRARY_FONT_LOADING_FreeType) 20 | include_directories(${FREETYPE_INCLUDE_DIRS}) 21 | target_link_libraries(Intra ${FREETYPE_LIBRARIES}) 22 | elseif(LIBRARY_FONT_LOADING_STB) 23 | add_definitions(-DINTRA_LIBRARY_FONT_LOADING=INTRA_LIBRARY_FONT_LOADING_STB) 24 | else() 25 | add_definitions(-DINTRA_LIBRARY_FONT_LOADING=INTRA_LIBRARY_FONT_LOADING_Dummy) 26 | endif() 27 | -------------------------------------------------------------------------------- /Intra/Font/FontLoading.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Font/FontLoadingDeclarations.h" 4 | #include "Math/Vector2.h" 5 | #include "Utils/StringView.h" 6 | 7 | namespace Intra { namespace FontLoadingAPI { 8 | 9 | FontHandle FontCreate(StringView name, uint height, uint* yadvance); 10 | FontHandle FontCreateFromMemory(const void* data, size_t length, uint height, uint* yadvance); 11 | void FontDelete(FontHandle font); 12 | const byte* FontGetCharBitmap(FontHandle font, int code, Math::SVec2* offset, Math::USVec2* size); 13 | void FontGetCharMetrics(FontHandle font, int code, short* xadvance, short* leftSideBearing); 14 | short FontGetKerning(FontHandle font, int left, int right); 15 | 16 | }} 17 | -------------------------------------------------------------------------------- /Intra/Font/FontLoadingDeclarations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/PlatformDetect.h" 4 | 5 | //! Используемая библиотека для загрузки TrueType шрифтов 6 | #define INTRA_LIBRARY_FONT_LOADING_Dummy 0 7 | #define INTRA_LIBRARY_FONT_LOADING_STB 1 8 | #define INTRA_LIBRARY_FONT_LOADING_FreeType 2 9 | #define INTRA_LIBRARY_FONT_LOADING_Gdiplus 3 10 | #define INTRA_LIBRARY_FONT_LOADING_Qt 4 11 | #define INTRA_LIBRARY_FONT_LOADING_SDL 5 12 | 13 | #ifndef INTRA_LIBRARY_FONT_LOADING 14 | 15 | #if(INTRA_PLATFORM_OS==INTRA_PLATFORM_OS_Windows) 16 | #define INTRA_LIBRARY_FONT_LOADING INTRA_LIBRARY_FONT_LOADING_Dummy 17 | //#define INTRA_LIBRARY_FONT_LOADING INTRA_LIBRARY_FONT_LOADING_Gdiplus 18 | #else 19 | #define INTRA_LIBRARY_FONT_LOADING INTRA_LIBRARY_FONT_LOADING_Dummy 20 | #endif 21 | 22 | #endif 23 | 24 | namespace Intra { namespace FontLoadingAPI { 25 | 26 | struct Font; 27 | typedef Font* FontHandle; 28 | 29 | }} 30 | -------------------------------------------------------------------------------- /Intra/Funal/Method.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | 5 | namespace Intra { namespace Funal { 6 | 7 | template struct MethodWrapper 8 | { 9 | typedef R(T::*Pointer)(Args...); 10 | Pointer Ptr; 11 | 12 | forceinline R operator()(T& object, Args... args) const {return (object.*Ptr)(args...);} 13 | }; 14 | 15 | template struct ConstMethodWrapper 16 | { 17 | typedef R(T::*Pointer)(Args...) const; 18 | Pointer Ptr; 19 | 20 | forceinline R operator()(const T& object, Args... args) const {return (object.*Ptr)(args...);} 21 | }; 22 | 23 | template 24 | forceinline MethodWrapper Method(R(T::*ptr)(Args...)) {return {ptr};} 25 | 26 | template 27 | forceinline ConstMethodWrapper Method(R(T::*ptr)(Args...) const) {return {ptr};} 28 | 29 | }} 30 | -------------------------------------------------------------------------------- /Intra/Funal/ObjectMethod.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Utils/Debug.h" 5 | 6 | namespace Intra { namespace Funal { 7 | 8 | template struct ObjectMethodWrapper 9 | { 10 | typedef R(T::*MethodPtr)(Args...); 11 | T* ObjectRef; 12 | MethodPtr Method; 13 | 14 | forceinline R operator()(Args... args) const 15 | { 16 | INTRA_DEBUG_ASSERT(ObjectRef != null); 17 | INTRA_DEBUG_ASSERT(Method != null); 18 | return (ObjectRef->*Method)(args...); 19 | } 20 | }; 21 | 22 | template struct ObjectConstMethodWrapper 23 | { 24 | typedef R(T::*MethodPtr)(Args...) const; 25 | const T* ObjectRef; 26 | MethodPtr Method; 27 | 28 | forceinline R operator()(Args... args) const 29 | { 30 | INTRA_DEBUG_ASSERT(ObjectRef != null); 31 | INTRA_DEBUG_ASSERT(Method != null); 32 | return (ObjectRef->*Method)(args...); 33 | } 34 | }; 35 | 36 | template 37 | forceinline ObjectMethodWrapper ObjectMethod(T* obj, R(T::*method)(Args...)) {return {obj, method};} 38 | 39 | template 40 | forceinline ObjectConstMethodWrapper ObjectMethod(T* obj, R(T::*method)(Args...) const) {return {obj, method};} 41 | 42 | } 43 | using Funal::ObjectMethod; 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Intra/Funal/ValueRef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Meta/Type.h" 5 | 6 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 7 | INTRA_WARNING_DISABLE_COPY_MOVE_IMPLICITLY_DELETED 8 | 9 | namespace Intra { namespace Funal { 10 | 11 | template struct TValue 12 | { 13 | T Value; 14 | constexpr forceinline TValue(T&& value) noexcept: Value(Cpp::Move(value)) {} 15 | constexpr forceinline TValue(const T& value): Value(value) {} 16 | constexpr forceinline const T& operator()() const noexcept {return Value;} 17 | forceinline T& operator()() noexcept {return Value;} 18 | }; 19 | 20 | template constexpr forceinline TValue> Value(T&& val) {return Cpp::Forward(val);} 21 | 22 | template struct TRef 23 | { 24 | T& Ref; 25 | constexpr forceinline TRef(T& ref) noexcept: Ref(ref) {} 26 | constexpr forceinline T& operator()() const noexcept {return Ref;} 27 | }; 28 | 29 | template constexpr forceinline TRef Ref(T& ref) {return ref;} 30 | 31 | }} 32 | 33 | INTRA_WARNING_POP 34 | -------------------------------------------------------------------------------- /Intra/Hash.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hash/Types.h" 4 | #include "Hash/MurmurCT.h" 5 | #include "Hash/Murmur.h" 6 | #include "Hash/StringHash.h" 7 | #include "Hash/ToHash.h" 8 | -------------------------------------------------------------------------------- /Intra/Hash/Murmur.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Types.h" 7 | 8 | #include "Utils/StringView.h" 9 | 10 | namespace Intra { namespace Hash { 11 | 12 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 13 | 14 | uint Murmur3_32(StringView key, uint seed); 15 | hash128 Murmur3_128_x64(StringView key, uint seed); 16 | hash128 Murmur3_128_x32(StringView key, uint seed); 17 | ulong64 Murmur2_64_x64(StringView key, uint seed); 18 | ulong64 Murmur2_64_x32(StringView key, uint seed); 19 | 20 | inline uint Murmur3_32(const char* key, uint seed) 21 | {return Murmur3_32(StringView(key), seed);} 22 | 23 | inline hash128 Murmur3_128_x64(const char* key, uint seed) 24 | {return Murmur3_128_x64(StringView(key), seed);} 25 | 26 | inline hash128 Murmur3_128_x32(const char* key, uint seed) 27 | {return Murmur3_128_x32(StringView(key), seed);} 28 | 29 | inline ulong64 Murmur2_64_x64(const char* key, uint seed) 30 | {return Murmur2_64_x64(StringView(key), seed);} 31 | 32 | inline ulong64 Murmur2_64_x32(const char* key, uint seed) 33 | {return Murmur2_64_x32(StringView(key), seed);} 34 | 35 | INTRA_WARNING_POP 36 | 37 | }} 38 | -------------------------------------------------------------------------------- /Intra/Hash/StringHash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Cpp/Fundamental.h" 6 | #include "MurmurCT.h" 7 | #include "Murmur.h" 8 | 9 | namespace Intra { namespace Range { 10 | 11 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 12 | 13 | struct StringHash 14 | { 15 | uint hash; 16 | #ifdef _DEBUG 17 | union 18 | { 19 | char strEnd[12]; 20 | const char* strLiteral; 21 | }; 22 | #endif 23 | 24 | template constexpr StringHash(const char(&str)[len]); 25 | constexpr StringHash(uint val): hash(val) 26 | #ifdef _DEBUG 27 | , strLiteral(null) 28 | #endif 29 | {} 30 | constexpr StringHash(null_t=null): hash(0) 31 | #ifdef _DEBUG 32 | , strLiteral(null) 33 | #endif 34 | {} 35 | 36 | StringHash(StringView sv); 37 | 38 | constexpr bool operator==(const StringHash& rhs) const 39 | {return hash==rhs.hash;} 40 | 41 | bool operator!=(const StringHash& rhs) const {return !operator==(rhs);} 42 | }; 43 | 44 | template constexpr inline StringHash::StringHash(const char(&str)[len]): 45 | hash(HashCT::Murmur3_32(str, 0)) 46 | #ifdef _DEBUG 47 | , strLiteral(str) 48 | #endif 49 | {} 50 | 51 | inline StringHash::StringHash(StringView sv): hash(Hash::Murmur3_32(sv, 0)) 52 | { 53 | #ifdef _DEBUG 54 | Span dst = strEnd; 55 | Range::WriteTo(sv.Tail(dst.Length()), dst); 56 | Range::FillZeros(dst); 57 | #endif 58 | } 59 | 60 | INTRA_WARNING_POP 61 | 62 | }} 63 | -------------------------------------------------------------------------------- /Intra/Hash/ToHash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Meta/Type.h" 7 | 8 | #include "Murmur.h" 9 | 10 | namespace Intra { namespace Hash { 11 | 12 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 13 | 14 | INTRA_DEFINE_EXPRESSION_CHECKER(HasToHashMethod, Meta::Val().ToHash()); 15 | 16 | template constexpr inline Meta::EnableIf< 17 | Meta::IsIntegralType::_, 18 | uint> ToHash(T k) {return uint(k*2659435761u);} 19 | 20 | template inline Meta::EnableIf< 21 | Meta::IsFloatType::_, 22 | uint> ToHash(T k) 23 | { 24 | union {T t; Meta::IntegralTypeFromMinSize i;}; 25 | t = k; 26 | return ToHash(i); 27 | } 28 | 29 | template inline uint ToHash(T* k) 30 | {return ToHash(reinterpret_cast(k));} 31 | 32 | inline uint ToHash(StringView k) 33 | {return Murmur3_32(k, 0);} 34 | 35 | template Meta::EnableIf< 36 | HasToHashMethod::_, 37 | uint> ToHash(const T& value) {return value.ToHash();} 38 | 39 | template Meta::EnableIf< 40 | Meta::IsAlmostPod::_ && !HasToHashMethod::_ && 41 | !Meta::IsPointerType::_ && !Meta::IsArithmeticType::_, 42 | uint> ToHash(const T& value) {return ToHash(StringView(reinterpret_cast(&value), sizeof(T)));} 43 | 44 | struct HasherObject { 45 | template uint operator()(const T& k) const {return ToHash(k);} 46 | }; 47 | 48 | INTRA_WARNING_POP 49 | 50 | } 51 | using Hash::ToHash; 52 | } 53 | -------------------------------------------------------------------------------- /Intra/Hash/Types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Cpp/Warnings.h" 5 | #include "Cpp/Fundamental.h" 6 | 7 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 8 | 9 | namespace Intra { namespace Hash { 10 | 11 | struct hash128 12 | { 13 | hash128() = default; 14 | constexpr hash128(ulong64 _h1, ulong64 _h2) : h1(_h1), h2(_h2) {} 15 | constexpr bool operator==(const hash128& rhs) const {return h1 == rhs.h1 && h2 == rhs.h2;} 16 | constexpr bool operator!=(const hash128& rhs) const {return !operator==(rhs);} 17 | 18 | ulong64 h1, h2; 19 | }; 20 | 21 | 22 | }} 23 | 24 | INTRA_WARNING_POP 25 | -------------------------------------------------------------------------------- /Intra/IO.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "IO/FormattedWriter.h" 4 | #include "IO/HtmlWriter.h" 5 | #include "IO/ConsoleInput.h" 6 | #include "IO/ConsoleOutput.h" 7 | #include "IO/OsFile.h" 8 | #include "IO/FileSystem.h" 9 | #include "IO/FileMapping.h" 10 | #include "IO/LogSystem.h" 11 | #include "IO/FileReader.h" 12 | #include "IO/FileWriter.h" 13 | #include "IO/SocketReader.h" 14 | #include "IO/SocketWriter.h" 15 | -------------------------------------------------------------------------------- /Intra/IO/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 4 | find_library(WSOCK32_LIBRARY wsock32) 5 | find_library(WS2_32_LIBRARY ws2_32) 6 | target_link_libraries(Intra wsock32 ws2_32) 7 | endif() 8 | -------------------------------------------------------------------------------- /Intra/IO/ConsoleInput.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/ConsoleInput.h -------------------------------------------------------------------------------- /Intra/IO/ConsoleOutput.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Range/Stream.hh" 4 | #include "IO/FormattedWriter.h" 5 | 6 | namespace Intra { namespace IO { 7 | 8 | extern FormattedWriter ConsoleOut; 9 | FormattedWriter ConsoleOutput(); 10 | 11 | }} 12 | -------------------------------------------------------------------------------- /Intra/IO/FilePath.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utils/Span.h" 4 | #include "Utils/StringView.h" 5 | #include "Container/ForwardDecls.h" 6 | #include "Cpp/Warnings.h" 7 | 8 | namespace Intra { namespace IO { namespace Path { 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | void NormalizeSlashesAndSpaces(Span& path); 13 | String AddTrailingSlash(StringView path); 14 | StringView RemoveTrailingSlash(StringView path); 15 | 16 | inline bool IsPathSeparator(char c) {return c=='/' || c=='\\';} 17 | void SplitPath(StringView fullPath, StringView* oDirectoryPath, 18 | StringView* oNameOnly, StringView* oExtension, StringView* oName); 19 | StringView ExtractDirectoryPath(StringView fullPath); 20 | StringView ExtractNameWithoutExtension(StringView fullPath); 21 | StringView ExtractName(StringView fullPath); 22 | StringView ExtractExtension(StringView fullPath); 23 | 24 | INTRA_WARNING_POP 25 | 26 | }}} 27 | -------------------------------------------------------------------------------- /Intra/IO/FileWriter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/FileWriter.h -------------------------------------------------------------------------------- /Intra/IO/FormattedLogger.cpp: -------------------------------------------------------------------------------- 1 | #include "IO/FormattedLogger.h" 2 | #include "Cpp/Warnings.h" 3 | 4 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 5 | 6 | namespace Intra { namespace IO { 7 | 8 | void FormattedLogger::Log(LogLevel level, StringView msg, const Utils::SourceInfo& srcInfo) 9 | { 10 | if(level < Verbosity) return; 11 | Math::Vec3 color; 12 | switch(level) 13 | { 14 | case LogLevel::Info: color = InfoColor; break; 15 | case LogLevel::Success: color = SuccessColor; break; 16 | case LogLevel::PerfWarning: color = PerfWarningColor; break; 17 | case LogLevel::Warning: color = WarningColor; break; 18 | case LogLevel::Error: color = ErrorColor; break; 19 | case LogLevel::CriticalError: color = CriticalErrorColor; break; 20 | default: color = {0.5, 0.5, 0.5}; 21 | } 22 | Writer.PushFont(color); 23 | static const char* const names[] = {"INFO", "SUCCESS", "PERF WARNING", "WARNING", "ERROR", "CRITICAL ERROR"}; 24 | if(srcInfo != null) Writer.Print(srcInfo.File, '(', srcInfo.Line, ") "); 25 | if(WriteLevelType) Writer.Print(names[size_t(level) - 1], ": "); 26 | Writer.PrintLine(msg); 27 | Writer.PopFont(); 28 | } 29 | 30 | }} 31 | 32 | INTRA_WARNING_POP 33 | -------------------------------------------------------------------------------- /Intra/IO/FormattedLogger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Utils/Logger.h" 5 | #include "IO/FormattedWriter.h" 6 | #include "Math/Vector3.h" 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | namespace Intra { namespace IO { 11 | 12 | class FormattedLogger: public ILogger 13 | { 14 | public: 15 | forceinline explicit FormattedLogger(FormattedWriter writer=null) noexcept: Writer(Cpp::Move(writer)) {} 16 | FormattedLogger(const FormattedLogger&) = delete; 17 | FormattedLogger(FormattedLogger&&) = default; 18 | FormattedLogger& operator=(const FormattedLogger&) = delete; 19 | FormattedLogger& operator=(FormattedLogger&&) = default; 20 | 21 | void Log(LogLevel level, StringView msg, const Utils::SourceInfo& srcInfo) override; 22 | 23 | FormattedWriter Writer; 24 | LogLevel Verbosity = LogLevel::All; 25 | Math::Vec3 InfoColor = {0.45f, 0.45f, 0.45f}; 26 | Math::Vec3 SuccessColor = {0, 0.6f, 0}; 27 | Math::Vec3 PerfWarningColor = {0.55f, 0.55f, 0.2f}; 28 | Math::Vec3 WarningColor = {0.9f, 0.75f, 0.2f}; 29 | Math::Vec3 ErrorColor = {1, 0.15f, 0.1f}; 30 | Math::Vec3 CriticalErrorColor = {0.8f, 0, 0}; 31 | bool WriteLevelType = true; 32 | }; 33 | 34 | }} 35 | 36 | INTRA_WARNING_POP 37 | -------------------------------------------------------------------------------- /Intra/IO/Formatter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/Formatter.h -------------------------------------------------------------------------------- /Intra/IO/HtmlWriter.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/HtmlWriter.cpp -------------------------------------------------------------------------------- /Intra/IO/HtmlWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "FormattedWriter.h" 4 | #include "Hash/ToHash.h" 5 | #include "Random/FastUniform.h" 6 | #include "Range/Polymorphic/OutputRange.h" 7 | 8 | namespace Intra { namespace IO { 9 | 10 | FormattedWriter HtmlWriter(OutputStream stream, bool addDefinitions=false); 11 | 12 | }} 13 | -------------------------------------------------------------------------------- /Intra/IO/Networking.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utils/StringView.h" 4 | #include "Container/ForwardDecls.h" 5 | 6 | 7 | namespace Intra { namespace IO { 8 | 9 | Array DownloadFile(StringView path); 10 | 11 | }} 12 | 13 | -------------------------------------------------------------------------------- /Intra/IO/OsFile.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/OsFile.cpp -------------------------------------------------------------------------------- /Intra/IO/OsFile.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/OsFile.h -------------------------------------------------------------------------------- /Intra/IO/SocketReader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/SocketReader.h -------------------------------------------------------------------------------- /Intra/IO/SocketWriter.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/SocketWriter.h -------------------------------------------------------------------------------- /Intra/IO/Std.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/IO/Std.h -------------------------------------------------------------------------------- /Intra/Image/Bindings.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Bindings/DXGI_Formats.h" 4 | #include "Bindings/GLenumFormats.h" 5 | -------------------------------------------------------------------------------- /Intra/Image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") 4 | option(LIBRARY_IMAGE_LOADING_Gdiplus "Use Gdiplus for image loading" ON) 5 | endif() 6 | 7 | find_package(DevIL) 8 | if(DEVIL_FOUND) 9 | option(LIBRARY_IMAGE_LOADING_DevIL "Use DevIL for image loading" OFF) 10 | endif() 11 | 12 | find_package(Qt4) 13 | if(QT4_FOUND) 14 | option(LIBRARY_IMAGE_LOADING_Qt "Use Qt for image loading" OFF) 15 | endif() 16 | 17 | 18 | if(LIBRARY_IMAGE_LOADING_Gdiplus) 19 | add_definitions(-DINTRA_LIBRARY_IMAGE_LOADING=INTRA_LIBRARY_IMAGE_LOADING_Gdiplus) 20 | target_link_libraries(Intra gdiplus) 21 | elseif(LIBRARY_IMAGE_LOADING_DevIL) 22 | add_definitions(-DINTRA_LIBRARY_IMAGE_LOADING=INTRA_LIBRARY_IMAGE_LOADING_DevIL) 23 | include_directories(${DEVIL_INCLUDE_DIRS}) 24 | target_link_libraries(Intra ${DEVIL_LIBRARIES}) 25 | elseif(LIBRARY_IMAGE_LOADING_Qt) 26 | add_definitions(-DINTRA_LIBRARY_IMAGE_LOADING=INTRA_LIBRARY_IMAGE_LOADING_Qt) 27 | include_directories(${QT4_INCLUDE_DIRS}) 28 | target_link_libraries(Intra ${QT4_LIBRARIES}) 29 | else() 30 | add_definitions(-DINTRA_LIBRARY_IMAGE_LOADING=INTRA_LIBRARY_IMAGE_LOADING_Dummy) 31 | endif() 32 | -------------------------------------------------------------------------------- /Intra/Image/Font.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Font/FontLoadingDeclarations.h" 4 | #include "Font/FontLoading.h" 5 | -------------------------------------------------------------------------------- /Intra/Image/FormatConversion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | 5 | #include "Math/Vector2.h" 6 | #include "Math/Math.h" 7 | #include "Math/Bit.h" 8 | 9 | #include "Utils/Span.h" 10 | 11 | #include "Concepts/IInput.h" 12 | 13 | #include "Image/ImageFormat.h" 14 | 15 | namespace Intra { namespace Image { 16 | 17 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 18 | 19 | inline uint ComponentByMask(uint color, uint mask) 20 | {return (color&mask) >> Math::FindBitPosition(mask);} 21 | 22 | uint ConvertColorBits(uint color, uint fromBitCount, uint toBitCount); 23 | void SwapRedBlueChannels(ImageFormat format, ushort lineAlignment, Math::USVec2 sizes, Span data); 24 | 25 | void ReadPixelDataBlock(IInputStream& stream, Math::USVec2 sizes, 26 | ImageFormat srcFormat, ImageFormat dstFormat, 27 | bool swapRB, bool flipVert, ushort srcAlignment, ushort dstAlignment, Span dstBuf); 28 | 29 | void ReadPalettedPixelDataBlock(IInputStream& stream, CSpan palette, 30 | ushort bpp, Math::USVec2 sizes, ImageFormat format, bool flipVert, 31 | ushort srcAlignment, ushort dstAlignment, Span dstBuf); 32 | 33 | INTRA_WARNING_POP 34 | 35 | }} 36 | -------------------------------------------------------------------------------- /Intra/Image/Image.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Image/Complex.h" 4 | #include "Image/FormatConversion.h" 5 | #include "Image/AnyImage.h" 6 | #include "Image/ImageFormat.h" 7 | #include "Image/ImageInfo.h" 8 | 9 | #include "Image/Bindings.hh" 10 | #include "Image/Loaders.hh" 11 | -------------------------------------------------------------------------------- /Intra/Image/Image.natvis: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {value} 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Intra/Image/Loaders.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Loader.h" 4 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/Loader.cpp: -------------------------------------------------------------------------------- 1 | #include "Image/Loaders/Loader.h" 2 | 3 | namespace Intra { namespace Image { 4 | 5 | AImageLoader* AImageLoader::firstLoader = null; 6 | 7 | }} 8 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/Loader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Image/ImageInfo.h" 4 | #include "Range/Generators/ListRange.h" 5 | #include "Cpp/Warnings.h" 6 | #include "Range/Polymorphic/InputRange.h" 7 | 8 | namespace Intra { 9 | 10 | namespace Image { 11 | 12 | class AnyImage; 13 | 14 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 15 | 16 | enum class FileFormat: byte {JPEG, BMP, GIF, TIFF, DDS, PNG, TGA, KTX, Unknown}; 17 | 18 | class AImageLoader 19 | { 20 | AImageLoader* mNextLoader; 21 | static AImageLoader* firstLoader; 22 | protected: 23 | AImageLoader(): mNextLoader(firstLoader) {firstLoader = this;} 24 | virtual ~AImageLoader() {} 25 | public: 26 | AImageLoader* NextListNode() const {return mNextLoader;} 27 | 28 | virtual ImageInfo GetInfo(IInputStream& stream) const = 0; 29 | virtual AnyImage Load(IInputStream& stream) const = 0; 30 | virtual bool IsValidHeader(const void* header, size_t headerSize) const = 0; 31 | virtual FileFormat FileFormatOfLoader() const = 0; 32 | 33 | static forceinline FListRange GetRegisteredLoaders() 34 | {return FListRange(firstLoader);} 35 | }; 36 | 37 | INTRA_WARNING_POP 38 | 39 | }} 40 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderBMP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef INTRA_NO_BMP_LOADER 4 | 5 | #include "Loader.h" 6 | #include "Cpp/Warnings.h" 7 | 8 | namespace Intra { namespace Image { 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | class LoaderBMP: public AImageLoader 13 | { 14 | LoaderBMP() {} 15 | public: 16 | ImageInfo GetInfo(IInputStream& stream) const override; 17 | AnyImage Load(IInputStream& stream) const override; 18 | bool IsValidHeader(const void* header, size_t headerSize) const override; 19 | FileFormat FileFormatOfLoader() const override {return FileFormat::BMP;} 20 | 21 | static const LoaderBMP Instance; 22 | }; 23 | 24 | INTRA_WARNING_POP 25 | 26 | }} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderDDS.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef INTRA_NO_DDS_LOADER 4 | 5 | #include "Loader.h" 6 | #include "Cpp/Warnings.h" 7 | #include "Concepts/IInput.h" 8 | #include "Concepts/IOutput.h" 9 | 10 | namespace Intra { 11 | 12 | namespace Image { 13 | 14 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 15 | 16 | class LoaderDDS: public AImageLoader 17 | { 18 | LoaderDDS() {} 19 | public: 20 | ImageInfo GetInfo(IInputStream& stream) const override; 21 | AnyImage Load(IInputStream& stream) const override; 22 | void Save(const AnyImage& img, IOutputStream& stream) const; 23 | bool IsValidHeader(const void* header, size_t headerSize) const override; 24 | FileFormat FileFormatOfLoader() const override {return FileFormat::DDS;} 25 | 26 | static const LoaderDDS Instance; 27 | }; 28 | 29 | INTRA_WARNING_POP 30 | 31 | }} 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderGIF.cpp: -------------------------------------------------------------------------------- 1 | #include "Image/Loaders/LoaderGIF.h" 2 | #include "Image/Loaders/LoaderPlatform.h" 3 | #include "Image/AnyImage.h" 4 | 5 | namespace Intra { namespace Image { 6 | 7 | bool LoaderGIF::IsValidHeader(const void* header, size_t headerSize) const 8 | { 9 | const byte* headerBytes = reinterpret_cast(header); 10 | return headerSize >= 3 && 11 | headerBytes[0] == 'G' && headerBytes[1] == 'I' && headerBytes[2] == 'F'; 12 | } 13 | 14 | AnyImage LoaderGIF::Load(IInputStream& stream) const 15 | { 16 | #if(INTRA_LIBRARY_IMAGE_LOADING!=INTRA_LIBRARY_IMAGE_LOADING_None) 17 | return LoadWithPlatform(stream); 18 | #else 19 | (void)stream; 20 | return null; 21 | #endif 22 | } 23 | 24 | }} 25 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderGIF.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef INTRA_NO_JPEG_LOADER 4 | 5 | #include "Loader.h" 6 | #include "Cpp/Warnings.h" 7 | 8 | namespace Intra { namespace Image { 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | class LoaderGIF: public AImageLoader 13 | { 14 | LoaderGIF() {} 15 | public: 16 | ImageInfo GetInfo(IInputStream& stream) const override; 17 | AnyImage Load(IInputStream& stream) const override; 18 | bool IsValidHeader(const void* header, size_t headerSize) const override; 19 | FileFormat FileFormatOfLoader() const override {return FileFormat::GIF;} 20 | 21 | //static const LoaderGIF Instance; 22 | }; 23 | 24 | INTRA_WARNING_POP 25 | 26 | }} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderJPEG.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef INTRA_NO_JPEG_LOADER 4 | 5 | #include "Loader.h" 6 | #include "Cpp/Warnings.h" 7 | 8 | namespace Intra { namespace Image { 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | class LoaderJPEG: public AImageLoader 13 | { 14 | LoaderJPEG() {} 15 | public: 16 | ImageInfo GetInfo(IInputStream& stream) const override; 17 | AnyImage Load(IInputStream& stream) const override; 18 | bool IsValidHeader(const void* header, size_t headerSize) const override; 19 | FileFormat FileFormatOfLoader() const override {return FileFormat::JPEG;} 20 | 21 | static const LoaderJPEG Instance; 22 | }; 23 | 24 | INTRA_WARNING_POP 25 | 26 | }} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderKTX.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef INTRA_NO_DDS_LOADER 4 | 5 | #include "Loader.h" 6 | 7 | #include "Cpp/Warnings.h" 8 | #include "Concepts/IInput.h" 9 | #include "Concepts/IOutput.h" 10 | 11 | namespace Intra { 12 | 13 | namespace Image { 14 | 15 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 16 | 17 | class LoaderKTX: public AImageLoader 18 | { 19 | LoaderKTX() {} 20 | public: 21 | ImageInfo GetInfo(IInputStream& stream) const override; 22 | AnyImage Load(IInputStream& stream) const override; 23 | void Save(const AnyImage& img, IOutputStream& stream) const; 24 | bool IsValidHeader(const void* header, size_t headerSize) const override; 25 | FileFormat FileFormatOfLoader() const override {return FileFormat::KTX;} 26 | 27 | static const LoaderKTX Instance; 28 | }; 29 | 30 | INTRA_WARNING_POP 31 | 32 | }} 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderPNG.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef INTRA_NO_PNG_LOADER 4 | 5 | #include "Loader.h" 6 | #include "Cpp/Warnings.h" 7 | 8 | namespace Intra { namespace Image { 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | class LoaderPNG: public AImageLoader 13 | { 14 | LoaderPNG() {} 15 | public: 16 | ImageInfo GetInfo(IInputStream& stream) const override; 17 | AnyImage Load(IInputStream& stream) const override; 18 | bool IsValidHeader(const void* header, size_t headerSize) const override; 19 | FileFormat FileFormatOfLoader() const override {return FileFormat::PNG;} 20 | 21 | static const LoaderPNG Instance; 22 | }; 23 | 24 | INTRA_WARNING_POP 25 | 26 | }} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderPlatform.cpp: -------------------------------------------------------------------------------- 1 | #include "Image/Loaders/LoaderPlatform.h" 2 | 3 | #if(INTRA_LIBRARY_IMAGE_LOADING == INTRA_LIBRARY_IMAGE_LOADING_STB) 4 | #error "INTRA_LIBRARY_IMAGE_LOADING_STB is not implemented!" 5 | #elif(INTRA_LIBRARY_IMAGE_LOADING == INTRA_LIBRARY_IMAGE_LOADING_DevIL) 6 | #include "detail/LoaderDevIL.hxx" 7 | #elif(INTRA_LIBRARY_IMAGE_LOADING == INTRA_LIBRARY_IMAGE_LOADING_Gdiplus) 8 | #include "detail/LoaderGdiplus.hxx" 9 | #elif(INTRA_LIBRARY_IMAGE_LOADING == INTRA_LIBRARY_IMAGE_LOADING_Qt) 10 | #include "detail/LoaderQt.hxx" 11 | #elif(INTRA_LIBRARY_IMAGE_LOADING == INTRA_LIBRARY_IMAGE_LOADING_SDL) 12 | #error Not implemented! 13 | #endif 14 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderPlatform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/PlatformDetect.h" 4 | 5 | //! Используемая библиотека\API системы для загрузки изображений 6 | #define INTRA_LIBRARY_IMAGE_LOADING_None 0 7 | #define INTRA_LIBRARY_IMAGE_LOADING_STB 1 8 | #define INTRA_LIBRARY_IMAGE_LOADING_DevIL 2 9 | #define INTRA_LIBRARY_IMAGE_LOADING_Gdiplus 3 10 | #define INTRA_LIBRARY_IMAGE_LOADING_Qt 4 11 | #define INTRA_LIBRARY_IMAGE_LOADING_SDL 5 12 | #define INTRA_LIBRARY_IMAGE_LOADING_Android 6 13 | 14 | //Пытаемся автоматически определить доступную системную библиотеку для загрузки изображений 15 | #ifndef INTRA_LIBRARY_IMAGE_LOADING 16 | 17 | #if(INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_Windows) 18 | #define INTRA_LIBRARY_IMAGE_LOADING INTRA_LIBRARY_IMAGE_LOADING_Gdiplus 19 | #elif(INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_Android) 20 | //TODO: сделать загрузку изображений средствами Java через JNI 21 | #define INTRA_LIBRARY_IMAGE_LOADING INTRA_LIBRARY_IMAGE_LOADING_None 22 | #else 23 | #define INTRA_LIBRARY_IMAGE_LOADING INTRA_LIBRARY_IMAGE_LOADING_None 24 | #endif 25 | 26 | #endif 27 | 28 | #if(INTRA_LIBRARY_IMAGE_LOADING != INTRA_LIBRARY_IMAGE_LOADING_None) 29 | 30 | #include "Image/AnyImage.h" 31 | 32 | namespace Intra { namespace Image { 33 | 34 | //! Загрузить изображение средствами библиотек операционной системы 35 | //! или сторонних библиотек, поддерживающих сразу множество форматов: 36 | //! GDI+ (Windows) 37 | //! Java API через JNI (Android) 38 | //! Qt (стороння библиотека, входит во многие дистрибутивы Linux) 39 | //! DevIL (сторонняя библиотека) 40 | //! STB image (сторонняя библиотека) 41 | //! SDL image (сторонняя библиотека) 42 | AnyImage LoadWithPlatform(IInputStream& stream); 43 | 44 | }} 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderTGA.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef INTRA_NO_TGA_LOADER 4 | 5 | #include "Loader.h" 6 | #include "Cpp/Warnings.h" 7 | 8 | namespace Intra { namespace Image { 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | class LoaderTGA: public AImageLoader 13 | { 14 | LoaderTGA() {} 15 | public: 16 | ImageInfo GetInfo(IInputStream& stream) const override; 17 | AnyImage Load(IInputStream& stream) const override; 18 | bool IsValidHeader(const void* header, size_t headerSize) const override; 19 | FileFormat FileFormatOfLoader() const override {return FileFormat::TGA;} 20 | 21 | static const LoaderTGA Instance; 22 | }; 23 | 24 | INTRA_WARNING_POP 25 | 26 | }} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderTIFF.cpp: -------------------------------------------------------------------------------- 1 | #include "Image/Loaders/LoaderTIFF.h" 2 | #include "Image/Loaders/LoaderPlatform.h" 3 | #include "Image/AnyImage.h" 4 | 5 | namespace Intra { namespace Image { 6 | 7 | bool LoaderTIFF::IsValidHeader(const void* header, size_t headerSize) const 8 | { 9 | const byte* headerBytes = reinterpret_cast(header); 10 | return headerSize>=3 && headerBytes[0]=='I' && headerBytes[1]=='I' && headerBytes[2]=='*'; 11 | } 12 | 13 | 14 | 15 | AnyImage LoaderTIFF::Load(IInputStream& stream) const 16 | { 17 | #if(INTRA_LIBRARY_IMAGE_LOADING != INTRA_LIBRARY_IMAGE_LOADING_None) 18 | return LoadWithPlatform(stream); 19 | #else 20 | (void)stream; 21 | return null; 22 | #endif 23 | } 24 | 25 | }} 26 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/LoaderTIFF.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef INTRA_NO_TIFF_LOADER 4 | 5 | #include "Loader.h" 6 | #include "Cpp/Warnings.h" 7 | 8 | namespace Intra { namespace Image { 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | class LoaderTIFF: public AImageLoader 13 | { 14 | LoaderTIFF() {} 15 | public: 16 | ImageInfo GetInfo(IInputStream& stream) const override; 17 | AnyImage Load(IInputStream& stream) const override; 18 | bool IsValidHeader(const void* header, size_t headerSize) const override; 19 | FileFormat FileFormatOfLoader() const override {return FileFormat::TIFF;} 20 | 21 | //static const LoaderGIF Instance; 22 | }; 23 | 24 | INTRA_WARNING_POP 25 | 26 | }} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Intra/Image/Loaders/detail/LoaderDevIL.hxx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Image/Loaders/detail/LoaderDevIL.hxx -------------------------------------------------------------------------------- /Intra/Image/Loaders/detail/LoaderGdiplus.hxx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Image/Loaders/detail/LoaderGdiplus.hxx -------------------------------------------------------------------------------- /Intra/Image/Loaders/detail/LoaderQt.hxx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Image/Loaders/detail/LoaderQt.hxx -------------------------------------------------------------------------------- /Intra/Math.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Math/Bit.h" 4 | #include "Math/FixedPoint.h" 5 | #include "Math/ExponentRange.h" 6 | #include "Math/SineRange.h" 7 | #include "Math/HalfFloat.h" 8 | #include "Math/Math.h" 9 | #include "Math/Geometry.hh" 10 | #include "Math/Matrix3.h" 11 | #include "Math/Matrix4.h" 12 | #include "Math/Quaternion.h" 13 | #include "Math/Vector2.h" 14 | #include "Math/Vector3.h" 15 | #include "Math/Vector4.h" 16 | -------------------------------------------------------------------------------- /Intra/Math/Bit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Cpp/Warnings.h" 5 | #include "Meta/Type.h" 6 | 7 | namespace Intra { namespace Math { 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | template constexpr forceinline Meta::EnableIf< 12 | Meta::IsScalarType::_, 13 | flag32> BitsOf(T value) 14 | { 15 | return flag32(value); 16 | } 17 | 18 | template constexpr forceinline Meta::EnableIf< 19 | Meta::IsScalarType::_, 20 | flag32> BitsOf(T value, uint offset) 21 | { 22 | return BitsOf(value) << offset; 23 | } 24 | 25 | 26 | template Meta::EnableIf< 27 | Meta::IsUnsignedIntegralType::_, 28 | uint> Count1Bits(T mask) 29 | { 30 | uint bitCount = 0; 31 | while(mask!=0) mask &= mask-1, bitCount++; 32 | return bitCount; 33 | } 34 | 35 | template forceinline Meta::EnableIf< 36 | Meta::IsUnsignedIntegralType::_, 37 | uint> FindBitPosition(T mask) 38 | { 39 | return Count1Bits((mask&(~mask+1))-1); 40 | } 41 | 42 | forceinline uint BitCountToMask(uint bitCount) 43 | { 44 | return (bitCount==32)? 0xFFFFFFFFu: (1u << bitCount)-1u; 45 | } 46 | 47 | INTRA_WARNING_POP 48 | 49 | }} 50 | -------------------------------------------------------------------------------- /Intra/Math/ExponentRange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Meta/Type.h" 7 | 8 | #include "Math/Math.h" 9 | 10 | namespace Intra { namespace Range { 11 | 12 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 13 | 14 | template struct ExponentRange 15 | { 16 | enum: bool {RangeIsInfinite = true}; 17 | 18 | ExponentRange(T scale=0, double step=0, T k=0): 19 | mEkSr(T(Math::Exp(-k*step))), mExponent(scale/mEkSr) {} 20 | 21 | forceinline bool Empty() const {return false;} 22 | forceinline void PopFirst() {mExponent *= mEkSr;} 23 | forceinline T First() const {return mExponent;} 24 | 25 | private: 26 | T mEkSr, mExponent; 27 | }; 28 | 29 | INTRA_WARNING_POP 30 | 31 | } 32 | 33 | namespace Math { 34 | using Range::ExponentRange; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Intra/Math/Geometry.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Geometry/Aabb.h" 4 | #include "Geometry/BoundingVolume.h" 5 | #include "Geometry/Ellipse.h" 6 | #include "Geometry/Frustum.h" 7 | #include "Geometry/Intersection.h" 8 | #include "Geometry/Line.h" 9 | #include "Geometry/LineSegment.h" 10 | #include "Geometry/Obb.h" 11 | #include "Geometry/Plane.h" 12 | #include "Geometry/Ray.h" 13 | #include "Geometry/Sphere.h" 14 | #include "Geometry/Triangle.h" 15 | -------------------------------------------------------------------------------- /Intra/Math/Geometry/Aabb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Math/Geometry/Aabb.h -------------------------------------------------------------------------------- /Intra/Math/Geometry/BoundingVolume.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Math/Geometry/BoundingVolume.h -------------------------------------------------------------------------------- /Intra/Math/Geometry/Ellipse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Math/Vector2.h" 4 | 5 | namespace Intra { namespace Math { 6 | 7 | template struct Ellipse 8 | { 9 | Vector2 Center; 10 | T a, b; 11 | 12 | 13 | }; 14 | 15 | template T Distance(Ellipse ellipse, Vector2 pt) 16 | { 17 | pt -= ellipse.Center; 18 | const Vector2 ptAbs = Abs(pt); 19 | if(ptAbs.x > ptAbs.y) 20 | { 21 | Cpp::Swap(pt.x, pt.y); 22 | Cpp::Swap(ellipse.a, ellipse.b); 23 | //swap ptAbs??? 24 | } 25 | 26 | const T l = ellipse.b*ellipse.b - ellipse.a*ellipse.a; 27 | const T m = ellipse.a*ptAbs.x/l, m2=m*m; 28 | const T n = ellipse.b*ptAbs.y/l; 29 | const T n2 = n*n; 30 | const T c = (m2+n2-1)/3; 31 | const T c3 = c*c*c; 32 | const T q = c3+m2*n2*2; 33 | const T d = c3+m2*n2; 34 | const T g = m+m*n2; 35 | 36 | T co; 37 | if(d<0) 38 | { 39 | const T p = Acos(q/c3)/3; 40 | const T s = Cos(p); 41 | const T t = Sin(p)*Sqrt(3.0); 42 | const T rx = Sqrt(-c*(s+t+2)+m2); 43 | const T ry = Sqrt(-c*(s-t+2)+m2); 44 | co = (ry+Sign(l)*rx+Abs(g)/(rx*ry)-m)/2; 45 | } 46 | else 47 | { 48 | const T h = 2*m*n*Sqrt(d); 49 | const T s = Sign(q+h)*Pow(Abs(q+h), T(0.333333333333333)); 50 | const T u = Sign(q-h)*Pow(Abs(q-h), T(0.333333333333333)); 51 | const T rx = -s-u-c*4+2*m2; 52 | const T ry = (s-u)*T(1.73205080757); 53 | const T rm = Sqrt(rx*rx+ry*ry); 54 | const T p = ry/Sqrt(rm-rx); 55 | co = (p+2*g/rm-m)/2; 56 | } 57 | 58 | const T si = Sqrt(T(1)-co*co); 59 | const Vector2 closestPoint = Vector2(ellipse.a*co, ellipse.b*si); 60 | return Distance(closestPoint, ptAbs)*Sign(ptAbs.y-closestPoint.y); 61 | } 62 | 63 | }} 64 | -------------------------------------------------------------------------------- /Intra/Math/Geometry/Intersection.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Math/Geometry/Intersection.h -------------------------------------------------------------------------------- /Intra/Math/Geometry/Line.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Math/Geometry/Line.h -------------------------------------------------------------------------------- /Intra/Math/Geometry/LineSegment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Math/Math.h" 5 | #include "Math/Vector3.h" 6 | 7 | namespace Intra { namespace Math { 8 | 9 | template struct LineSegment 10 | { 11 | Vector3 A, B; 12 | 13 | LineSegment() = default; 14 | constexpr LineSegment(const Vector3& a, const Vector3& b) noexcept: A(a), B(b) {} 15 | constexpr forceinline Vector3 Midpoint() const noexcept {return (A + B)/2;} 16 | }; 17 | 18 | template constexpr forceinline T LengthSqr(const LineSegment& l) noexcept {return DistanceSqr(l.A, l.B);} 19 | template INTRA_MATH_CONSTEXPR forceinline T Length(const LineSegment& l) noexcept {return Distance(l.A, l.B);} 20 | 21 | }} 22 | -------------------------------------------------------------------------------- /Intra/Math/Geometry/Obb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Math/Geometry/Obb.h -------------------------------------------------------------------------------- /Intra/Math/Geometry/Plane.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Math/Geometry/Plane.h -------------------------------------------------------------------------------- /Intra/Math/Geometry/Ray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Intra { namespace Math { 4 | 5 | template struct Ray 6 | { 7 | Vector3 Origin, Direction; 8 | 9 | Ray() = default; 10 | constexpr forceinline Ray(const Vector3& origin, const Vector3& direction) noexcept: 11 | Origin(origin), Direction(direction) {} 12 | 13 | template constexpr Ray Transform(const Matrix3& mat, const Vector3& offset) 14 | {return Ray((mat*Vector4(Origin, 1)).xyz, mat*Direction);} 15 | 16 | template constexpr Ray Transform(const Matrix4& mat) 17 | {return Ray((mat*Vector4(Origin, 1)).xyz, Matrix3(mat)*Direction);} 18 | 19 | }; 20 | 21 | typedef Ray RayF; 22 | 23 | 24 | }} 25 | -------------------------------------------------------------------------------- /Intra/Math/Geometry/Sphere.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Math/Math.h" 4 | #include "Math/Vector3.h" 5 | #include "Math/Matrix4.h" 6 | #include "Aabb.h" 7 | 8 | namespace Intra { namespace Math { 9 | 10 | template struct Sphere 11 | { 12 | Vector3 Center; 13 | T Radius; 14 | 15 | constexpr forceinline Sphere(const Vector3& center, const T& radius) noexcept: Center(center), Radius(radius) {} 16 | 17 | void AddPoint(const Vector3& p) 18 | { 19 | const T distSqr = DistanceSqr(p, Center); 20 | if(distSqr > Radius*Radius) Radius = T(Sqrt(distSqr)); 21 | } 22 | 23 | void AddSphere(const Sphere& s) 24 | { 25 | const T dist = Distance(s.Center, Center) + s.Radius; 26 | if(dist > Radius) Radius = dist; 27 | } 28 | }; 29 | 30 | template INTRA_MATH_CONSTEXPR Sphere operator*(const Matrix4& m, const Sphere& s) 31 | {return {(m*Vector4(s.Center, 1)).xyz, m.ExtractScaleVector().MaxElement()*s.Radius};} 32 | 33 | template INTRA_MATH_CONSTEXPR T SignedDistanceFromZero(const Sphere& sphere) 34 | {return Length(sphere.Center) - sphere.Radius;} 35 | 36 | template INTRA_MATH_CONSTEXPR T SignedDistance(const Sphere& sphere, const Vector3& pt) 37 | {return SignedDistanceFromZero({sphere.Center - pt, sphere.Radius});} 38 | 39 | template INTRA_MATH_CONSTEXPR T Distance(const Sphere& sphere, const Vector3& pt) 40 | {return Max(SignedDistance(sphere.Center, pt), T(0));} 41 | 42 | typedef Sphere SphereF; 43 | 44 | }} 45 | -------------------------------------------------------------------------------- /Intra/Math/Math.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {(long double)data/Divisor} 6 | 7 | 8 | 9 | {{{x}, {y}}} 10 | 11 | 12 | 13 | {{{x}, {y}, {z}}} 14 | 15 | 16 | 17 | {{{x}, {y}, {z}, {w}}} 18 | 19 | 20 | 21 | {{{rows[0]}, {rows[1]}, {rows[2]}, {rows[3]}}} 22 | 23 | rows 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Intra/Math/SineRange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Meta/Type.h" 7 | 8 | #include "Math/Math.h" 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | namespace Intra { namespace Range { 13 | 14 | template struct SineRange 15 | { 16 | enum: bool {RangeIsInfinite = true}; 17 | 18 | SineRange(null_t=null): 19 | mS1(0), mS2(0), mK(2) {} 20 | 21 | SineRange(T amplitude, T phi0, T dphi): 22 | mS1(amplitude*Math::Sin(phi0)), 23 | mS2(amplitude*Math::Sin(phi0 + dphi)), 24 | mK(2*Math::Cos(dphi)) {} 25 | 26 | forceinline bool Empty() const noexcept {return false;} 27 | forceinline T First() const noexcept {return mS1;} 28 | 29 | forceinline T Next() noexcept 30 | { 31 | const T result = mS1; 32 | PopFirst(); 33 | return result; 34 | } 35 | 36 | forceinline void PopFirst() noexcept 37 | { 38 | const T newS = mK*mS2 - mS1; 39 | mS1 = mS2; 40 | mS2 = newS; 41 | } 42 | 43 | forceinline bool operator==(null_t) const noexcept {return mS1 == 0 && mS2 == 0 && mK == 2;} 44 | forceinline bool operator!=(null_t) const noexcept {return !operator==(null);} 45 | 46 | private: 47 | T mS1, mS2, mK; 48 | }; 49 | 50 | } 51 | 52 | namespace Math { 53 | using Range::SineRange; 54 | } 55 | 56 | } 57 | 58 | INTRA_WARNING_POP 59 | -------------------------------------------------------------------------------- /Intra/Memory.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Memory/Align.h" 4 | #include "Memory/Memory.h" 5 | #include "Memory/PlacementNew.h" 6 | #include "Memory/VirtualMemory.h" 7 | 8 | #include "Memory/Allocator.hh" 9 | -------------------------------------------------------------------------------- /Intra/Memory/Align.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Utils/Debug.h" 5 | 6 | namespace Intra { namespace Memory { 7 | 8 | inline size_t AlignmentBytes(size_t value, size_t alignment) 9 | { 10 | INTRA_DEBUG_ASSERT(alignment != 0); 11 | size_t remainder = value % alignment; 12 | if(remainder==0) return 0; 13 | return alignment-remainder; 14 | } 15 | 16 | inline size_t Aligned(size_t value, size_t alignment, size_t offset=0) 17 | {return value+AlignmentBytes(value+offset, alignment);} 18 | 19 | inline byte* Aligned(byte* value, size_t alignment, size_t offset=0) 20 | {return reinterpret_cast(Aligned(reinterpret_cast(value), alignment, offset));} 21 | 22 | }} 23 | 24 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Basic.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Basic/Linear.h" 4 | #include "Basic/Stack.h" 5 | #include "Basic/Pool.h" 6 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Basic/Linear.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Warnings.h" 5 | #include "Utils/Debug.h" 6 | #include "Utils/Span.h" 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | namespace Intra { namespace Memory { 11 | 12 | struct ALinear 13 | { 14 | ALinear(Span buf=null, size_t allocatorAlignment=16): 15 | mStart(buf.Begin), mRest(buf), mAlignment(allocatorAlignment) {} 16 | 17 | size_t GetAlignment() const {return mAlignment;} 18 | 19 | AnyPtr Allocate(size_t bytes, const Utils::SourceInfo& sourceInfo) 20 | { 21 | (void)sourceInfo; 22 | 23 | byte* userPtr = Aligned(mRest.Begin, mAlignment); 24 | if(mRest.Begin + bytes >= mRest.End) return null; 25 | mRest.Begin += bytes; 26 | 27 | return userPtr; 28 | } 29 | 30 | void Free(void* ptr, size_t size) {(void)ptr; (void)size;} 31 | 32 | void Reset() {mRest.Begin = mStart;} 33 | 34 | private: 35 | byte* mStart; 36 | Span mRest; 37 | size_t mAlignment; 38 | }; 39 | 40 | }} 41 | 42 | INTRA_WARNING_POP 43 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Basic/Pool.cpp: -------------------------------------------------------------------------------- 1 | #include "Memory/Allocator/Basic/Pool.h" 2 | #include "Memory/Align.h" 3 | #include "Utils/Span.h" 4 | 5 | namespace Intra { namespace Memory { 6 | 7 | void FreeList::InitBuffer(Span buf, size_t elementSize, size_t alignment) 8 | { 9 | if(elementSizemNext = asSelf; 28 | runner = asSelf; 29 | asByte += elementSize; 30 | } 31 | 32 | runner->mNext = null; 33 | } 34 | 35 | AnyPtr FreeList::Allocate() 36 | { 37 | if(mNext==null) return null; 38 | FreeList* head = mNext; 39 | mNext = head->mNext; 40 | return head; 41 | } 42 | 43 | void FreeList::Free(void* ptr) 44 | { 45 | FreeList* head = static_cast(ptr); 46 | head->mNext = mNext; 47 | mNext = head; 48 | } 49 | 50 | 51 | AnyPtr APool::Allocate(size_t& bytes, const Utils::SourceInfo& sourceInfo) 52 | { 53 | (void)sourceInfo; 54 | INTRA_DEBUG_ASSERT(bytes <= mElementSize); 55 | if(bytes>mElementSize) return null; 56 | bytes = mElementSize; 57 | return mList.Allocate(); 58 | } 59 | 60 | void APool::Free(void* ptr, size_t size) 61 | { 62 | (void)size; 63 | INTRA_DEBUG_ASSERT(size == mElementSize); 64 | mList.Free(ptr); 65 | } 66 | 67 | }} 68 | 69 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Basic/Pool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Utils/Span.h" 5 | #include "Utils/AnyPtr.h" 6 | 7 | namespace Intra { namespace Memory { 8 | 9 | struct FreeList 10 | { 11 | FreeList(null_t=null): mNext(null) {} 12 | 13 | FreeList(Span buf, size_t elementSize, size_t alignment): mNext(null) 14 | {InitBuffer(buf, elementSize, alignment);} 15 | 16 | void InitBuffer(Span buf, size_t elementSize, size_t alignment); 17 | 18 | AnyPtr Allocate(); 19 | void Free(void* ptr); 20 | 21 | bool HasFree() const {return mNext!=null;} 22 | 23 | private: 24 | FreeList* mNext; 25 | }; 26 | 27 | 28 | struct APool 29 | { 30 | APool(null_t=null): mElementSize(0), mAlignment(0) {} 31 | APool(Span buf, size_t elementSize, size_t allocatorAlignment): 32 | mList(buf, elementSize, allocatorAlignment), 33 | mElementSize(ushort(elementSize)), 34 | mAlignment(ushort(allocatorAlignment)) {} 35 | 36 | size_t GetAlignment() const {return mAlignment;} 37 | 38 | AnyPtr Allocate(size_t& bytes, const Utils::SourceInfo& sourceInfo); 39 | void Free(void* ptr, size_t size); 40 | 41 | size_t ElementSize() const {return mElementSize;} 42 | 43 | forceinline size_t GetAllocationSize(void* ptr) const {(void)ptr; return mElementSize;} 44 | 45 | bool operator==(null_t) const {return mElementSize==0;} 46 | bool operator!=(null_t) const {return !operator==(null);} 47 | 48 | private: 49 | FreeList mList; 50 | ushort mElementSize, mAlignment; 51 | }; 52 | 53 | }} 54 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Basic/Stack.cpp: -------------------------------------------------------------------------------- 1 | #include "Memory/Allocator/Basic/Stack.h" 2 | #include "Memory/Align.h" 3 | 4 | namespace Intra { namespace Memory { 5 | 6 | AnyPtr AStack::Allocate(size_t bytes, const Utils::SourceInfo& sourceInfo) 7 | { 8 | (void)sourceInfo; 9 | 10 | // store the allocation offset right in front of the allocation 11 | bytes += sizeof(uint); 12 | const uint allocationOffset = uint(mRest.Begin - mStart); 13 | 14 | if(mRest.Length()(ptr) < mRest.Begin); 36 | 37 | // grab the allocation offset from the 4 bytes right before the given pointer 38 | const uint allocationOffset = *--reinterpret_cast(ptr); 39 | mRest.Begin = mStart+allocationOffset; 40 | } 41 | 42 | }} 43 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Basic/Stack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Warnings.h" 5 | #include "Utils/Debug.h" 6 | #include "Utils/Span.h" 7 | #include "Utils/AnyPtr.h" 8 | 9 | namespace Intra { namespace Memory { 10 | 11 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 12 | 13 | struct AStack 14 | { 15 | AStack(Span buf, size_t allocatorAlignment): 16 | mStart(buf.Begin), mRest(buf), mAlignment(allocatorAlignment) {} 17 | 18 | size_t GetAlignment() const {return mAlignment;} 19 | AnyPtr Allocate(size_t size, const Utils::SourceInfo& sourceInfo); 20 | void Free(void* ptr, size_t size); 21 | 22 | private: 23 | byte* mStart; 24 | Span mRest; 25 | size_t mAlignment; 26 | }; 27 | 28 | }} 29 | 30 | INTRA_WARNING_POP 31 | 32 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Compositors.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compositors/SegregatedPools.h" 4 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Concepts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Meta/Type.h" 5 | 6 | namespace Intra { namespace Memory { 7 | 8 | INTRA_DEFINE_EXPRESSION_CHECKER(HasGetAllocationSize,\ 9 | static_cast(Meta::Val().GetAllocationSize(static_cast(null)))); 10 | 11 | }} 12 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Decorators.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Decorators/CallOnFail.h" 4 | #include "Decorators/BoundsChecked.h" 5 | #include "Decorators/Counted.h" 6 | #include "Decorators/Synchronized.h" 7 | #include "Decorators/Sized.h" 8 | #include "Decorators/Static.h" 9 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Decorators/CallOnFail.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Warnings.h" 5 | #include "Utils/Debug.h" 6 | #include "Utils/StringView.h" 7 | #include "Range/Stream/ToString.h" 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | INTRA_WARNING_DISABLE_COPY_IMPLICITLY_DELETED 11 | 12 | namespace Intra { namespace Memory { 13 | 14 | inline void NoMemoryBreakpoint(size_t bytes, Utils::SourceInfo sourceInfo) 15 | { 16 | (void)bytes; (void)sourceInfo; 17 | INTRA_DEBUGGER_BREAKPOINT; 18 | } 19 | 20 | inline void NoMemoryAbort(size_t bytes, Utils::SourceInfo sourceInfo) 21 | { 22 | char errorMsg[512]; 23 | GenericStringView(errorMsg) << StringView(sourceInfo.File).Tail(400) << '(' << sourceInfo.Line << "): " << 24 | "Out of memory!\n" << "Couldn't allocate " << bytes << " byte memory block." << '\0'; 25 | INTRA_FATAL_ERROR(errorMsg); 26 | } 27 | 28 | template struct ACallOnFail: A 29 | { 30 | ACallOnFail() = default; 31 | ACallOnFail(A&& allocator): A(Cpp::Move(allocator)) {} 32 | 33 | AnyPtr Allocate(size_t& bytes, Utils::SourceInfo sourceInfo) 34 | { 35 | auto result = A::Allocate(bytes, sourceInfo); 36 | if(result==null) F(bytes, sourceInfo); 37 | return result; 38 | } 39 | }; 40 | 41 | }} 42 | 43 | INTRA_WARNING_POP 44 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Decorators/Counted.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Utils/Debug.h" 5 | #include "Meta/Type.h" 6 | 7 | namespace Intra { namespace Memory { 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | INTRA_WARNING_DISABLE_COPY_IMPLICITLY_DELETED 11 | 12 | template struct ACounted: A 13 | { 14 | private: 15 | size_t mCounter=0; 16 | public: 17 | ACounted() = default; 18 | ACounted(A&& allocator): A(Cpp::Move(allocator)) {} 19 | 20 | AnyPtr Allocate(size_t& bytes, const Utils::SourceInfo& sourceInfo) 21 | { 22 | auto result = A::Allocate(bytes, sourceInfo); 23 | if(result!=null) mCounter++; 24 | return result; 25 | } 26 | 27 | void Free(void* ptr, size_t size) 28 | { 29 | if(ptr==null) return; 30 | A::Free(ptr, size); 31 | mCounter--; 32 | } 33 | 34 | size_t AllocationCount() const {return mCounter;} 35 | }; 36 | 37 | INTRA_WARNING_POP 38 | 39 | }} 40 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Decorators/Sized.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Utils/AnyPtr.h" 7 | #include "Utils/Debug.h" 8 | 9 | #include "Meta/Type.h" 10 | 11 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 12 | INTRA_WARNING_DISABLE_DEFAULT_CONSTRUCTOR_IMPLICITLY_DELETED 13 | INTRA_WARNING_DISABLE_COPY_IMPLICITLY_DELETED 14 | 15 | namespace Intra { namespace Memory { 16 | 17 | template struct ASized: A 18 | { 19 | size_t GetAlignment() const {return sizeof(size_t);} 20 | 21 | ASized() = default; 22 | ASized(A&& allocator): A(Cpp::Move(allocator)) {} 23 | 24 | AnyPtr Allocate(size_t& bytes, Utils::SourceInfo sourceInfo) 25 | { 26 | INTRA_DEBUG_ASSERT(bytes!=0); 27 | size_t totalBytes = bytes+sizeof(size_t); 28 | size_t* data = A::Allocate(totalBytes, sourceInfo); 29 | if(data!=null) 30 | { 31 | bytes = totalBytes-sizeof(size_t); 32 | *data++ = bytes; 33 | } 34 | return data; 35 | } 36 | 37 | /*AnyPtr Reallocate(void* ptr, size_t newBytes) 38 | { 39 | size_t* newData = A::Reallocate(ptr!=null? (size_t*)ptr-1: null, newBytes+sizeof(size_t)); 40 | if(newData!=null) *newData = newBytes; 41 | return newData+1; 42 | }*/ 43 | 44 | void Free(void* ptr, size_t size) 45 | { 46 | INTRA_DEBUG_ASSERT(GetAllocationSize(ptr)==size); 47 | size_t* originalPtr = reinterpret_cast(ptr)-1; 48 | A::Free(originalPtr, size+sizeof(size_t)); 49 | } 50 | 51 | forceinline size_t GetAllocationSize(void* ptr) const 52 | {return *(reinterpret_cast(ptr)-1);} 53 | }; 54 | 55 | }} 56 | 57 | INTRA_WARNING_POP 58 | 59 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Decorators/Static.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Meta/Type.h" 5 | #include "Memory/Allocator/Concepts.h" 6 | #include "Cpp/Warnings.h" 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | INTRA_WARNING_DISABLE_COPY_IMPLICITLY_DELETED 10 | 11 | namespace Intra { namespace Memory { 12 | 13 | template struct AStatic 14 | { 15 | size_t GetAlignment() const {return Get().GetAlignment();} 16 | 17 | static A& Get() 18 | { 19 | static A allocator; 20 | return allocator; 21 | } 22 | 23 | static AnyPtr Allocate(size_t& bytes, const Utils::SourceInfo& sourceInfo) 24 | {return Get().Allocate(bytes, sourceInfo);} 25 | 26 | static void Free(void* ptr, size_t size) 27 | {Get().Free(ptr, size);} 28 | 29 | template static forceinline Meta::EnableIf< 30 | HasGetAllocationSize::_, 31 | size_t> GetAllocationSize(void* ptr) 32 | {return Get().GetAllocationSize(ptr);} 33 | }; 34 | 35 | }} 36 | 37 | INTRA_WARNING_POP 38 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Decorators/Synchronized.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Utils/Debug.h" 5 | #include "Meta/Type.h" 6 | 7 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 8 | INTRA_WARNING_DISABLE_COPY_IMPLICITLY_DELETED 9 | 10 | namespace Intra { namespace Memory { 11 | 12 | template struct ASynchronized: A 13 | { 14 | ASynchronized() = default; 15 | ASynchronized(A&& allocator): A(Cpp::Move(allocator)) {} 16 | 17 | AnyPtr Allocate(size_t& bytes, const Utils::SourceInfo& sourceInfo) 18 | { 19 | mSync.Lock(); 20 | auto result = A::Allocate(bytes, sourceInfo); 21 | mSync.Unlock(); 22 | return result; 23 | } 24 | 25 | void Free(void* ptr, size_t size) 26 | { 27 | if(ptr==null) return; 28 | mSync.Lock(); 29 | A::Free(ptr, size); 30 | mSync.Unlock(); 31 | } 32 | 33 | private: 34 | Sync mSync; 35 | }; 36 | 37 | }} 38 | 39 | INTRA_WARNING_POP 40 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Global.cpp: -------------------------------------------------------------------------------- 1 | #include "Memory/Allocator/Global.h" 2 | 3 | namespace Intra { namespace Memory { 4 | 5 | GlobalHeapType GlobalHeap; 6 | SizedHeapType SizedHeap; 7 | 8 | }} 9 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Global.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Decorators/Sized.h" 4 | #include "Decorators/BoundsChecked.h" 5 | #include "Decorators/CallOnFail.h" 6 | #include "System.h" 7 | #include "Utils/Debug.h" 8 | 9 | namespace Intra { namespace Memory { 10 | 11 | #ifdef INTRA_DEBUG_ALLOCATORS 12 | using SizedHeapType = ASized>>; 13 | using GlobalHeapType = ABoundsChecked>; 14 | #else 15 | using SizedHeapType = ASized>; 16 | using GlobalHeapType = ACallOnFail; 17 | #endif 18 | 19 | extern SizedHeapType SizedHeap; 20 | extern GlobalHeapType GlobalHeap; 21 | 22 | }} 23 | -------------------------------------------------------------------------------- /Intra/Memory/Allocator/Polymorphic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Utils/Debug.h" 5 | #include "Cpp/Warnings.h" 6 | #include "Memory/Memory.h" 7 | 8 | namespace Intra { namespace Memory { 9 | 10 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 11 | 12 | class IAllocator 13 | { 14 | public: 15 | virtual AnyPtr Allocate(size_t bytes, const SourceInfo& sourceInfo) = 0; 16 | virtual void Free(void* ptr) = 0; 17 | virtual ~IAllocator() {} 18 | }; 19 | 20 | class ISizedAllocator: public IAllocator 21 | { 22 | public: 23 | virtual size_t GetAllocationSize() const = 0; 24 | }; 25 | 26 | template class PolymorphicUnsizedAllocator: public IAllocator, private Allocator 27 | { 28 | AnyPtr Allocate(size_t bytes, const SourceInfo& sourceInfo) final 29 | { 30 | return Allocator::Allocate(bytes, sourceInfo); 31 | } 32 | 33 | void Free(void* ptr) final 34 | { 35 | Allocator::Free(ptr); 36 | } 37 | }; 38 | 39 | template class PolymorphicSizedAllocator: public ISizedAllocator, private Allocator 40 | { 41 | AnyPtr Allocate(size_t& bytes, const SourceInfo& sourceInfo) final 42 | { 43 | return Allocator::Allocate(bytes, sourceInfo); 44 | } 45 | 46 | void Free(void* ptr) final 47 | { 48 | Allocator::Free(ptr); 49 | } 50 | 51 | size_t GetAllocationSize(void* ptr) const final { return Allocator::GetAllocationSize(ptr); } 52 | }; 53 | 54 | template class PolymorphicAllocator: public Meta::SelectType< 55 | PolymorphicSizedAllocator, 56 | PolymorphicUnsizedAllocator, 57 | AllocatorHasGetAllocationSize::_> 58 | {}; 59 | 60 | INTRA_WARNING_POP 61 | 62 | }} 63 | -------------------------------------------------------------------------------- /Intra/Memory/Memory.cpp: -------------------------------------------------------------------------------- 1 | #include "Cpp/Warnings.h" 2 | #include "Memory/Memory.h" 3 | #include "Memory/Allocator/Global.h" 4 | 5 | INTRA_DISABLE_REDUNDANT_WARNINGS 6 | 7 | namespace Intra { namespace Memory { 8 | 9 | AnyPtr Allocate(size_t bytes, size_t alignment) 10 | { 11 | (void)alignment; 12 | return GlobalHeap.Allocate(bytes, INTRA_SOURCE_INFO); 13 | } 14 | 15 | void Free(void* data) 16 | { 17 | GlobalHeap.Free(data, 0); 18 | } 19 | 20 | }} 21 | -------------------------------------------------------------------------------- /Intra/Memory/VirtualMemory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Warnings.h" 5 | #include "Utils/AnyPtr.h" 6 | 7 | namespace Intra { namespace Memory { 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | enum class Access: byte { 12 | None, Read, Write, ReadWrite, Execute, 13 | ExecuteRead, ExecuteWrite, ExecuteReadWrite, 14 | End}; 15 | 16 | //! Получает память напрямую от ОС. 17 | //! Память выделяется страницами, поэтому параметр bytes округляется вверх до размера страницы. 18 | //! Если access==None, физическая память не выделяется, а резервируется только адресное пространство процесса. 19 | //! Если access!=None выделяется физическая память с доступом access. 20 | AnyPtr VirtualAlloc(size_t bytes, Access access); 21 | 22 | //! Освобождает память, выделенную VirtualAlloc. 23 | //! \param ptr Указатель, полученный от VirtualAlloc. 24 | void VirtualFree(void* ptr, size_t size); 25 | 26 | //! Для страниц, попадающих в интервал [ptr, ptr+bytes) устанавливается режим доступа access. 27 | /*! 28 | Если access==None, физическая память освобождается и соответствующие интервалу страницы остаются в зарезервированном состоянии. 29 | Если access!=None выделяется физическая память с доступом access. 30 | Для тех страниц, для которых физическая память уже была выделена просто меняется доступ. 31 | */ 32 | void VirtualCommit(void* ptr, size_t bytes, Access access); 33 | 34 | size_t VirtualMemoryPageSize(); 35 | 36 | INTRA_WARNING_POP 37 | 38 | }} 39 | -------------------------------------------------------------------------------- /Intra/Meta.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Meta/Type.h" 4 | #include "Meta/Tuple.h" 5 | #include "Meta/EachField.h" 6 | #include "Meta/GetField.h" 7 | #include "Meta/TypeList.h" 8 | #include "Meta/Operators.h" 9 | #include "Meta/Pair.h" 10 | -------------------------------------------------------------------------------- /Intra/Meta/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(IntraMeta) 4 | 5 | include(../../Configurations.cmake) 6 | 7 | include_directories(..) 8 | 9 | init_project_sources(${CMAKE_CURRENT_SOURCE_DIR} META_HEADERS META_SOURCES) 10 | add_library(IntraMeta INTERFACE ${META_SOURCES} ${META_HEADERS}) 11 | -------------------------------------------------------------------------------- /Intra/Meta/Operators.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Meta/Type.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 7 | 8 | namespace Intra { 9 | 10 | namespace Meta { 11 | INTRA_DEFINE_EXPRESSION_CHECKER2(HasOpEquals, Val() == Val(),, = U1); 12 | INTRA_DEFINE_EXPRESSION_CHECKER2(HasOpNotEquals, Val() != Val(),, = U1); 13 | } 14 | 15 | template Meta::EnableIf< 16 | Meta::HasOpEquals::_ && !Meta::HasOpNotEquals::_ && 17 | (!Meta::IsScalarType::_ || !Meta::IsScalarType::_), 18 | bool> operator!=(const T1& lhs, const T2& rhs) 19 | {return !(lhs==rhs);} 20 | 21 | template Meta::EnableIf< 22 | Meta::HasOpNotEquals::_ && !Meta::HasOpEquals::_ && 23 | (!Meta::IsScalarType::_ || !Meta::IsScalarType::_), 24 | bool> operator==(const T1& lhs, const T2& rhs) 25 | {return !(lhs!=rhs);} 26 | 27 | } 28 | 29 | INTRA_WARNING_POP 30 | -------------------------------------------------------------------------------- /Intra/Preprocessor.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Preprocessor/Operations.h" 4 | #include "Preprocessor/VariadicCommon.h" 5 | #include "Preprocessor/Macro2ForEach.h" 6 | #include "Preprocessor/Macro2ForEachIndex.h" 7 | -------------------------------------------------------------------------------- /Intra/Preprocessor/Operations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define INTRA_DETAIL_SKIP_FIRST_ARG(firstArg, ...) __VA_ARGS__ 4 | #define INTRA_SKIP_FIRST_ARG(x, ...) INTRA_DETAIL_SKIP_FIRST_ARG x 5 | 6 | #define INTRA_DETAIL_SELECT_FIRST_ARG(firstArg, ...) firstArg 7 | #define INTRA_DETAIL_SELECT_FIRST_ARG_CONVERT(args) INTRA_DETAIL_SELECT_FIRST_ARG args 8 | #define INTRA_SELECT_FIRST_ARG(x) INTRA_DETAIL_SELECT_FIRST_ARG_CONVERT( (x) ) 9 | 10 | #ifndef INTRA_CONCATENATE_TOKENS 11 | #define INTRA_DETAIL_CONCATENATE_TOKENS(x, y) x ## y 12 | #define INTRA_CONCATENATE_TOKENS(x, y) INTRA_DETAIL_CONCATENATE_TOKENS(x, y) 13 | #endif 14 | 15 | #define INTRA_MACRO_ARGUMENT(...) __VA_ARGS__ 16 | #define INTRA_MACRO_EXPAND(x) x 17 | 18 | -------------------------------------------------------------------------------- /Intra/Preprocessor/VariadicCommon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define INTRA_DETAIL_PREPROCESSOR_FUNC_CHOOSER_30(_f1, _f2, _f3, _f4, _f5, _f6, _f7, _f8, _f9, _f10, _f11, _f12, _f13, _f14, _f15, _f16, _f17, _f18, _f19, _f20, _f21, _f22, _f23, _f24, _f25, _f26, _f27, _f28, _f29, _f30, ...) _f30 4 | 5 | #define INTRA_DETAIL_PREPROCESSOR_FUNC_RECOMPOSER(argsWithParentheses) \ 6 | INTRA_DETAIL_PREPROCESSOR_FUNC_CHOOSER_30 argsWithParentheses 7 | 8 | #define INTRA_DETAIL_PREPROCESSOR_MACRO_CHOOSER(target_, ...) \ 9 | INTRA_DETAIL_PREPROCESSOR_CHOOSE_FROM_ARG_COUNT(target_, target_##_NO_ARG_EXPANDER __VA_ARGS__ ()) 10 | 11 | #define INTRA_DETAIL_PREPROCESSOR_CHOOSE_FROM_ARG_COUNT(arg_, ...) \ 12 | INTRA_DETAIL_PREPROCESSOR_FUNC_RECOMPOSER((__VA_ARGS__, \ 13 | arg_##_29, arg_##_28, arg_##_27, arg_##_26, \ 14 | arg_##_25, arg_##_24, arg_##_23, arg_##_22, arg_##_21, arg_##_20, arg_##_19, arg_##_18, arg_##_17, \ 15 | arg_##_16, arg_##_15, arg_##_14, arg_##_13, arg_##_12, arg_##_11, arg_##_10, arg_##_9, arg_##_8, \ 16 | arg_##_7, arg_##_6, arg_##_5, arg_##_4, arg_##_3, arg_##_2, arg_##_1, )) 17 | -------------------------------------------------------------------------------- /Intra/Random/FastUniformNoise.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Fundamental.h" 4 | #include "Cpp/Features.h" 5 | 6 | #include "Math/Math.h" 7 | 8 | #include "FastUniform.h" 9 | 10 | namespace Intra { namespace Random { 11 | 12 | struct FastUniformNoise 13 | { 14 | private: 15 | struct Data 16 | { 17 | Data(): data(new float[16384]) 18 | { 19 | FastUniform fRandom(3259417823U); 20 | for(size_t i=0; i<16384; i++) data[i] = fRandom.SignedNext(); 21 | } 22 | 23 | ~Data() {delete[] data;} 24 | 25 | float* data; 26 | }; 27 | 28 | static forceinline float get(size_t index) {static Data data; return data.data[index & 16383];} 29 | 30 | public: 31 | static forceinline float Discrete(float t) 32 | {return get(size_t(t + 0.5f));} 33 | 34 | static forceinline float Linear(float t) 35 | { 36 | const size_t n = size_t(t); 37 | return Math::LinearMix(get(n), get(n+1), Math::Fract(t)); 38 | } 39 | 40 | static forceinline float Cubic(float t) 41 | { 42 | const size_t n = size_t(t); 43 | const float x = Math::Fract(t), x2 = x*x; 44 | return 0.5f*( ( ( (2.0f-x)*x2 - x ) ) * get(n+16383) + 45 | (x2*(3.0f*x-5.0f) + 2.0f) * get(n) + 46 | ((4.0f-3.0f*x)*x2 + x) * get(n+1) + 47 | (x-1.0f)*x2*get(n+2)); 48 | } 49 | }; 50 | 51 | }} 52 | -------------------------------------------------------------------------------- /Intra/Range.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Range/Operations.h" 4 | #include "Range/TupleOperation.h" 5 | #include "Range/ForwardDecls.h" 6 | 7 | #include "Range/Generators.hh" 8 | #include "Range/Decorators.hh" 9 | #include "Range/Compositors.hh" 10 | #include "Range/Iterator.hh" 11 | #include "Range/Polymorphic.hh" 12 | #include "Range/Special.hh" 13 | 14 | #include "Range/Mutation.hh" 15 | #include "Range/Reduction.h" 16 | #include "Range/Comparison.hh" 17 | #include "Range/ForEach.h" 18 | -------------------------------------------------------------------------------- /Intra/Range/Comparison.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Comparison/EndsWith.h" 4 | #include "Comparison/Equals.h" 5 | #include "Comparison/LexCompare.h" 6 | #include "Comparison/StartsWith.h" 7 | -------------------------------------------------------------------------------- /Intra/Range/Comparison/LexCompare.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/PlatformDetect.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Funal/Op.h" 7 | 8 | #include "Utils/ArrayAlgo.h" 9 | #include "Utils/StringView.h" 10 | 11 | #include "Concepts/Range.h" 12 | 13 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 14 | 15 | namespace Intra { namespace Range { 16 | 17 | template Meta::EnableIf< 18 | Concepts::IsForwardRange::_ && 19 | Concepts::IsForwardRange::_ && 20 | Meta::IsCallable, Concepts::ValueTypeOf>::_, 21 | int> LexCompare(const R1& r1, const R2& r2, P pred) 22 | { 23 | R1 range1 = r1; 24 | R2 range2 = r2; 25 | while(!range1.Empty() && !range2.Empty()) 26 | { 27 | if(pred(range1.First(), range2.First())) return -1; 28 | if(pred(range2.First(), range1.First())) return 1; 29 | } 30 | if(range1.Empty()) 31 | { 32 | if(range2.Empty()) return 0; 33 | return -1; 34 | } 35 | return 1; 36 | } 37 | 38 | template Meta::EnableIf< 39 | Concepts::IsForwardRange::_ && 40 | Concepts::IsForwardRange::_ && 41 | !((Meta::IsIntegralType>::_ || 42 | Meta::IsCharType>::_) && 43 | Meta::TypeEquals, Concepts::ElementTypeOfArray>::_ && 44 | Concepts::IsArrayClass::_ && 45 | Concepts::IsArrayClass::_ && 46 | (sizeof(Concepts::ElementTypeOfArray)==1 || 47 | INTRA_PLATFORM_ENDIANESS == INTRA_PLATFORM_ENDIANESS_BigEndian)), 48 | int> LexCompare(const R1& r1, const R2& r2) 49 | {return LexCompare(r1, r2, Funal::Less);} 50 | 51 | }} 52 | 53 | INTRA_WARNING_POP 54 | -------------------------------------------------------------------------------- /Intra/Range/Compositors.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compositors/AssociativeRange.h" 4 | #include "Compositors/RoundRobin.h" 5 | #include "Compositors/Choose.h" 6 | #include "Compositors/Zip.h" 7 | #include "Compositors/Indexed.h" 8 | #include "Compositors/Chain.h" 9 | -------------------------------------------------------------------------------- /Intra/Range/Compositors/AssociativeRange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /Intra/Range/Decorators.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Decorators/Take.h" 4 | #include "Decorators/TakeUntil.h" 5 | #include "Decorators/TakeUntilAny.h" 6 | #include "Decorators/Filter.h" 7 | #include "Decorators/Map.h" 8 | #include "Decorators/Stride.h" 9 | #include "Decorators/Transversal.h" 10 | #include "Decorators/Retro.h" 11 | #include "Decorators/Cycle.h" 12 | #include "Decorators/Split.h" 13 | #include "Decorators/Join.h" 14 | #include "Decorators/Chunks.h" 15 | #include "Decorators/ByLine.h" 16 | -------------------------------------------------------------------------------- /Intra/Range/Decorators/Buffered.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Range/Decorators/Buffered.h -------------------------------------------------------------------------------- /Intra/Range/ForEach.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Meta/Type.h" 4 | #include "Concepts/Range.h" 5 | #include "Concepts/RangeOf.h" 6 | 7 | namespace Intra { namespace Range { 8 | 9 | template 11 | > Meta::EnableIf< 12 | Concepts::IsConsumableRange::_ && 13 | Meta::IsCallable>::_ 14 | > ForEach(R&& r, F&& f) 15 | { 16 | auto range = Range::Forward(r); 17 | while(!range.Empty()) 18 | { 19 | f(range.First()); 20 | range.PopFirst(); 21 | } 22 | } 23 | 24 | template 26 | > Meta::EnableIf< 27 | Concepts::IsConsumableRange::_ 28 | > ForEach(R&& r, FR(Concepts::ValueTypeOf::*f)()) 29 | { 30 | auto range = Range::Forward(r); 31 | while(!range.Empty()) 32 | { 33 | (range.First().*f)(); 34 | range.PopFirst(); 35 | } 36 | } 37 | 38 | template 40 | > Meta::EnableIf< 41 | Concepts::IsConsumableRange::_ 42 | > ForEach(R&& r, FR(Concepts::ValueTypeOf::*f)() const) 43 | { 44 | auto range = Range::Forward(r); 45 | while(!range.Empty()) 46 | { 47 | (range.First().*f)(); 48 | range.PopFirst(); 49 | } 50 | } 51 | 52 | template, typename... Args 54 | > Meta::EnableIf< 55 | Concepts::IsConsumableRange::_ && 56 | Meta::IsCallable, Args...>::_ 57 | > CallEach(R&& r, Args&&... args) 58 | { 59 | auto range = Range::Forward(r); 60 | while(!range.Empty()) 61 | { 62 | range.First()(args...); 63 | range.PopFirst(); 64 | } 65 | } 66 | 67 | 68 | }} 69 | -------------------------------------------------------------------------------- /Intra/Range/ForwardDecls.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | 5 | namespace Intra { namespace Range { 6 | 7 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 8 | 9 | namespace Tags { 10 | 11 | enum TKeepTerminator: bool {KeepTerminator = true}; 12 | 13 | } 14 | 15 | INTRA_WARNING_POP 16 | 17 | }} 18 | -------------------------------------------------------------------------------- /Intra/Range/Generators.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Generators/ListRange.h" 4 | #include "Generators/Iota.h" 5 | #include "Generators/Repeat.h" 6 | #include "Generators/Generate.h" 7 | #include "Generators/Sequence.h" 8 | #include "Generators/Recurrence.h" 9 | #include "Generators/Count.h" 10 | #include "Generators/Null.h" 11 | -------------------------------------------------------------------------------- /Intra/Range/Generators/Count.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Concepts/Range.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | namespace Intra { namespace Range { 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | template struct CountRange 11 | { 12 | enum: bool {RangeIsInfinite = true}; 13 | 14 | forceinline CountRange(null_t=null): Counter(0) {} 15 | forceinline CountRange(size_t counter): Counter(counter) {} 16 | 17 | forceinline bool Empty() const {return false;} 18 | forceinline const T& First() const {static const T empty; return empty;} 19 | forceinline void PopFirst() {Counter++;} 20 | 21 | forceinline void Put(const T&) {Counter++;} 22 | 23 | forceinline bool operator==(const CountRange& rhs) const {return Counter==rhs.Counter;} 24 | 25 | size_t Counter; 26 | }; 27 | 28 | INTRA_WARNING_POP 29 | 30 | } 31 | using Range::CountRange; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Intra/Range/Generators/FlatArrayOfArraysRange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Meta/Type.h" 4 | #include "Utils/Span.h" 5 | #include "Utils/StringView.h" 6 | #include "Range/Stream/RawRead.h" 7 | 8 | namespace Intra { namespace Range { 9 | 10 | template class FlatArrayOfArraysRange 11 | { 12 | static_assert(Meta::IsTriviallySerializable::_, "T must be trivial."); 13 | public: 14 | typedef Meta::SelectType, Span, Meta::IsCharType::_> ArrayOrStringView; 15 | 16 | forceinline FlatArrayOfArraysRange(const void* data, size_t size): mData(static_cast(data), size) {} 17 | forceinline FlatArrayOfArraysRange(CSpan data): mData(data) {} 18 | 19 | ArrayOrStringView First() const 20 | { 21 | auto dataCopy = mData; 22 | const size_t count = ParseVarUInt(dataCopy); 23 | return dataCopy.Reinterpret().Take(count); 24 | } 25 | 26 | void PopFirst() 27 | { 28 | const size_t count = ParseVarUInt(mData); 29 | mData.PopFirstN(count*sizeof(T)); 30 | } 31 | 32 | forceinline bool Empty() const {return mData.Empty();} 33 | 34 | forceinline const byte* RawData() const {return mData.Data();} 35 | forceinline const byte* RawEnd() const {return mData.End;} 36 | forceinline CSpan RawRange() const {return mData;} 37 | 38 | private: 39 | CSpan mData; 40 | }; 41 | 42 | typedef FlatArrayOfArraysRange FlatStringRange; 43 | typedef FlatArrayOfArraysRange FlatConstStringRange; 44 | 45 | }} 46 | -------------------------------------------------------------------------------- /Intra/Range/Generators/Generate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Concepts/Range.h" 4 | 5 | INTRA_WARNING_PUSH 6 | INTRA_DISABLE_REDUNDANT_WARNINGS 7 | INTRA_WARNING_DISABLE_COPY_IMPLICITLY_DELETED 8 | 9 | namespace Intra { namespace Range { 10 | 11 | template struct RGenerate 12 | { 13 | private: 14 | typedef Meta::RemoveConstRef> value_type; 15 | typedef const value_type& return_value_type; 16 | public: 17 | enum: bool {RangeIsInfinite = true}; 18 | 19 | forceinline RGenerate(null_t=null): mFunc(null) {} 20 | forceinline RGenerate(F function): mFunc(function), mFront(mFunc()()) {} 21 | 22 | RGenerate(const RGenerate&) = delete; 23 | RGenerate& operator=(const RGenerate&) = delete; 24 | RGenerate(RGenerate&& rhs) = default; 25 | RGenerate& operator=(RGenerate&& rhs) = default; 26 | 27 | forceinline bool Empty() const {return mFunc==null;} 28 | forceinline return_value_type First() const {return mFront;} 29 | 30 | forceinline void PopFirst() {mFront = mFunc()();} 31 | 32 | private: 33 | Utils::Optional mFunc; 34 | value_type mFront; 35 | }; 36 | 37 | template forceinline RGenerate Generate(F func) 38 | {return Cpp::Move(func);} 39 | 40 | }} 41 | 42 | INTRA_WARNING_POP 43 | -------------------------------------------------------------------------------- /Intra/Range/Generators/Null.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Concepts/Range.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | namespace Intra { namespace Range { 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | template struct NullRange 11 | { 12 | forceinline T* begin() const {return null;} 13 | forceinline T* end() const {return null;} 14 | 15 | forceinline NullRange(null_t=null) {} 16 | forceinline bool Empty() const {return true;} 17 | forceinline size_t Length() const {return 0;} 18 | forceinline T First() const {INTRA_DEBUG_ASSERT(false); return T();} 19 | forceinline T Last() const {INTRA_DEBUG_ASSERT(false); return T();} 20 | forceinline void PopFirst() {INTRA_DEBUG_ASSERT(false);} 21 | forceinline void PopLast() {INTRA_DEBUG_ASSERT(false);} 22 | forceinline T operator[](size_t) {INTRA_DEBUG_ASSERT(false); return T();} 23 | 24 | NullRange operator()(size_t startIndex, size_t endIndex) const 25 | { 26 | (void)startIndex; (void)endIndex; 27 | INTRA_DEBUG_ASSERT(startIndex==0 && endIndex==0); 28 | return NullRange(); 29 | } 30 | 31 | forceinline void Put(const T&) {} 32 | }; 33 | 34 | INTRA_WARNING_POP 35 | 36 | }} 37 | -------------------------------------------------------------------------------- /Intra/Range/Generators/Sequence.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Concepts/Range.h" 4 | #include "Range/Decorators/Take.h" 5 | #include "Utils/Optional.h" 6 | 7 | namespace Intra { namespace Range { 8 | 9 | INTRA_WARNING_PUSH 10 | INTRA_DISABLE_REDUNDANT_WARNINGS 11 | INTRA_WARNING_DISABLE_COPY_IMPLICITLY_DELETED 12 | 13 | template struct RSequence 14 | { 15 | enum: bool {RangeIsInfinite = true}; 16 | 17 | forceinline RSequence(null_t=null): Function(), Offset(0) {} 18 | forceinline RSequence(F function, size_t offset=0): Function(function), Offset(offset) {} 19 | 20 | forceinline T First() const {return Function()(Offset);} 21 | forceinline void PopFirst() {Offset++;} 22 | forceinline bool Empty() const {return false;} 23 | forceinline T operator[](size_t index) const {return Function()(Offset+index);} 24 | 25 | forceinline bool operator==(const RSequence& rhs) const {return Offset==rhs.Offset;} 26 | 27 | forceinline RTake> operator()(size_t start, size_t end) const 28 | { 29 | INTRA_DEBUG_ASSERT(start<=end); 30 | auto result = *this; 31 | result.Offset += start; 32 | return RTake>(Cpp::Move(result), end-start); 33 | } 34 | 35 | Utils::Optional Function; 36 | size_t Offset; 37 | }; 38 | 39 | INTRA_WARNING_POP 40 | 41 | template forceinline 42 | RSequence, size_t>, Meta::RemoveConstRef> Sequence(F&& function) 43 | {return {Cpp::Forward(function)};} 44 | 45 | }} 46 | -------------------------------------------------------------------------------- /Intra/Range/Generators/ZStringRange.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Range/Generators/ZStringRange.h -------------------------------------------------------------------------------- /Intra/Range/Iterator.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Iterator/RangeForwardIterator.h" 4 | -------------------------------------------------------------------------------- /Intra/Range/Iterator/RangeForwardIterator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Concepts/Range.h" 5 | 6 | namespace Intra { namespace Range { 7 | 8 | template struct RangeForwardIterator 9 | { 10 | typedef Concepts::ValueTypeOf value_type; 11 | typedef Concepts::ReturnValueTypeOf return_value_type; 12 | typedef return_value_type& reference; 13 | typedef value_type* pointer; 14 | typedef intptr difference_type; 15 | 16 | forceinline RangeForwardIterator(null_t=null) {} 17 | forceinline RangeForwardIterator(const R& range): Range(range) {} 18 | forceinline RangeForwardIterator& operator++() { Range.PopFirst(); return *this;} 19 | forceinline RangeForwardIterator operator++(int) {auto copy = Range; Range.PopFirst(); return copy;} 20 | forceinline return_value_type operator*() const {return Range.First();} 21 | forceinline Meta::RemoveReference* operator->() const {return &Range.First();} 22 | 23 | forceinline bool operator==(const RangeForwardIterator& rhs) const {return Range==rhs.Range;} 24 | forceinline bool operator!=(const RangeForwardIterator& rhs) const {return !operator==(rhs);} 25 | forceinline bool operator==(null_t) const {return Range.Empty();} 26 | 27 | R Range; 28 | }; 29 | 30 | } 31 | using Range::RangeForwardIterator; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Intra/Range/Mutation.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Mutation/Cast.h" 4 | #include "Mutation/Copy.h" 5 | #include "Mutation/CopyUntil.h" 6 | #include "Mutation/Fill.h" 7 | #include "Mutation/Transform.h" 8 | #include "Mutation/Remove.h" 9 | #include "Mutation/Replace.h" 10 | #include "Mutation/ReplaceSubrange.h" 11 | -------------------------------------------------------------------------------- /Intra/Range/Mutation/Cast.cpp: -------------------------------------------------------------------------------- 1 | #include "Range/Mutation/Copy.h" 2 | #include "Utils/Span.h" 3 | #include "Simd/Simd.h" 4 | 5 | namespace Intra { namespace Range { 6 | 7 | void CastAdvanceToAdvance(CSpan& src, Span& dst) 8 | { 9 | INTRA_DEBUG_ASSERT(dst.Length() >= src.Length()); 10 | #if(INTRA_SIMD_SUPPORT >= INTRA_SIMD_SSE && INTRA_PLATFORM_ARCH == INTRA_PLATFORM_X86) 11 | while(src.End - src.Begin >= 4) 12 | { 13 | *(__m64*)dst.Begin = _mm_cvtps_pi16(Simd::SetFloat4U(src.Begin)); 14 | src.Begin += 4; 15 | dst.Begin += 4; 16 | } 17 | _mm_empty(); 18 | #else 19 | while(src.End - src.Begin >= 4) 20 | { 21 | *dst.Begin++ = short(*src.Begin++); 22 | *dst.Begin++ = short(*src.Begin++); 23 | *dst.Begin++ = short(*src.Begin++); 24 | *dst.Begin++ = short(*src.Begin++); 25 | } 26 | #endif 27 | while(src.Begin < src.End) 28 | { 29 | //INTRA_DEBUG_ASSERT(*src>=-32768.0f && *src<=32767.0f); 30 | *dst.Begin++ = short(*src.Begin++); 31 | } 32 | } 33 | 34 | }} 35 | -------------------------------------------------------------------------------- /Intra/Range/Mutation/CopyUntil.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Range/Mutation/CopyUntil.h -------------------------------------------------------------------------------- /Intra/Range/Mutation/Heap.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Range/Mutation/Heap.h -------------------------------------------------------------------------------- /Intra/Range/Mutation/Interleave.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Range/Concepts.h" 4 | #include "Range/ArrayRange.h" 5 | 6 | namespace Intra { namespace Algo { 7 | 8 | //! Скопировать нескольких массивов src в один массив dst с чередующимися элементами: 9 | //! dst = {src[0][0], ..., src.Last()[0], src[0][1], ..., src.Last()[1], ...} 10 | template void Interleave(ArrayRange dst, ArrayRange> src) 11 | { 12 | INTRA_ASSERT(!dst.Empty()); 13 | INTRA_ASSERT(!src.Empty()); 14 | const size_t channelCount = src.Length(); 15 | const size_t valuesPerChannel = src.First().Length(); 16 | INTRA_ASSERT(dst.Length() == valuesPerChannel*channelCount); 17 | 18 | for(size_t i=0; i void Deinterleave(ArrayRange> dst, ArrayRange src) 31 | { 32 | INTRA_ASSERT(!dst.Empty()); 33 | INTRA_ASSERT(!src.Empty()); 34 | const size_t channelCount = dst.Length(); 35 | const size_t valuesPerChannel = dst.First().Length(); 36 | INTRA_ASSERT(src.Length() == valuesPerChannel*channelCount); 37 | 38 | for(size_t i=0; i struct RUnion 18 | { 19 | typedef Concepts::ValueTypeOf R; 20 | typedef Concepts::ReturnValueTypeOf T; 21 | 22 | RUnion(RR ranges, P pred): mRanges(Cpp::Move(ranges)), mPred(Cpp::Move(pred)) 23 | { 24 | RemoveRightAdvance(mRanges, Funal::IsEmpty); 25 | HeapBuild(mRanges); 26 | } 27 | 28 | forceinline T First() const {return mRanges.First().First();} 29 | forceinline bool Empty() const {return mRanges.Empty();} 30 | 31 | void PopFirst() 32 | { 33 | auto& range = HeapPop(mRanges, mPred); 34 | range.PopFirst(); 35 | if(range.Empty()) mRanges.PopLast(); 36 | else HeapPush(mRanges, mPred); 37 | } 38 | 39 | private: 40 | RR mRanges; 41 | P mPred; 42 | }; 43 | 44 | template, 46 | typename T = Concepts::ValueTypeOf 47 | > forceinline Meta::EnableIf< 48 | Concepts::IsRandomAccessRange::_, 49 | Meta::IsCallable::_, 50 | RUnion> Union(RR&& range, P pred) {return {Range::Forward(range), Cpp::Move(pred)};} 51 | 52 | }} 53 | 54 | INTRA_WARNING_POP 55 | -------------------------------------------------------------------------------- /Intra/Range/Output.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Output/Inserter.h" 4 | #include "Output/OutputArrayRange.h" 5 | -------------------------------------------------------------------------------- /Intra/Range/Output/Inserter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | #include "Meta/Type.h" 6 | #include "Concepts/RangeOf.h" 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | INTRA_WARNING_DISABLE_SIGN_CONVERSION 10 | INTRA_WARNING_DISABLE_COPY_MOVE_CONSTRUCT_IMPLICITLY_DELETED 11 | INTRA_WARNING_DISABLE_DEFAULT_CONSTRUCTOR_IMPLICITLY_DELETED 12 | 13 | namespace Intra { namespace Range { 14 | 15 | template struct RLastAppender 16 | { 17 | C& Dst; 18 | 19 | typedef typename C::value_type value_type; 20 | 21 | void Put(value_type&& v) {Dst.push_back(Cpp::Move(v));} 22 | void Put(const value_type& v) {Dst.push_back(v);} 23 | }; 24 | 25 | template struct RFirstAppender 26 | { 27 | C& Dst; 28 | 29 | typedef typename C::value_type value_type; 30 | 31 | void Put(value_type&& v) {Dst.push_front(Cpp::Move(v));} 32 | void Put(const value_type& v) {Dst.push_front(v);} 33 | }; 34 | 35 | template forceinline RLastAppender LastAppender(C& container) {return RLastAppender{container};} 36 | template forceinline RFirstAppender FirstAppender(C& container) {return RFirstAppender{container};} 37 | 38 | } 39 | using Range::LastAppender; 40 | 41 | } 42 | 43 | INTRA_WARNING_POP 44 | -------------------------------------------------------------------------------- /Intra/Range/Output/OutputArrayRange.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Range/Output/OutputArrayRange.h -------------------------------------------------------------------------------- /Intra/Range/Polymorphic.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Polymorphic/InputRange.h" 4 | #include "Polymorphic/FiniteInputRange.h" 5 | #include "Polymorphic/ForwardRange.h" 6 | #include "Polymorphic/FiniteForwardRange.h" 7 | #include "Polymorphic/BidirectionalRange.h" 8 | #include "Polymorphic/RandomAccessRange.h" 9 | #include "Polymorphic/FiniteRandomAccessRange.h" 10 | #include "Polymorphic/OutputRange.h" 11 | -------------------------------------------------------------------------------- /Intra/Range/RangePolymorphic.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | null 6 | {*mInterface.mPtr} 7 | 8 | *mInterface.mPtr 9 | 10 | 11 | 12 | 13 | {OriginalRange} 14 | 15 | OriginalRange 16 | 17 | 18 | 19 | 20 | null 21 | {*Stream.mPtr} 22 | 23 | *Stream.mPtr 24 | 25 | 26 | 27 | 28 | {OriginalRange} 29 | 30 | OriginalRange 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Intra/Range/ReadMe.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Range/ReadMe.md -------------------------------------------------------------------------------- /Intra/Range/Search.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Search/Trim.h" 4 | #include "Search/Single.h" 5 | #include "Search/Subrange.h" 6 | #include "Search/Binary.h" 7 | #include "Search/Distance.h" 8 | -------------------------------------------------------------------------------- /Intra/Range/Search/Binary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Intra { namespace Range { 4 | 5 | 6 | 7 | }} 8 | 9 | -------------------------------------------------------------------------------- /Intra/Range/Sort.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Sort/IsSorted.h" 4 | #include "Sort/Insertion.h" 5 | #include "Sort/Heap.h" 6 | #include "Sort/Quick.h" 7 | #include "Sort/Radix.h" 8 | #include "Sort/Merge.h" 9 | #include "Sort/Selection.h" 10 | -------------------------------------------------------------------------------- /Intra/Range/Sort/IsSorted.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | 5 | #include "Funal/Op.h" 6 | 7 | #include "Concepts/Range.h" 8 | #include "Concepts/RangeOf.h" 9 | 10 | namespace Intra { namespace Range { 11 | 12 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 13 | 14 | template Meta::EnableIf< 15 | Concepts::IsConsumableRange::_, 16 | bool> IsSorted(R&& range, P comparer = Funal::Less) 17 | { 18 | if(range.Empty()) return true; 19 | R rangeCopy = Cpp::Forward(range); 20 | Concepts::ValueTypeOf prev; 21 | auto cur = rangeCopy.First(); 22 | rangeCopy.PopFirst(); 23 | while(!rangeCopy.Empty()) 24 | { 25 | prev = Cpp::Move(cur); 26 | cur = rangeCopy.First(); 27 | if(comparer(cur, prev)) return false; 28 | rangeCopy.PopFirst(); 29 | } 30 | return true; 31 | } 32 | 33 | template 35 | > Meta::EnableIf< 36 | !Concepts::IsInputRange::_ && 37 | Concepts::IsNonInfiniteForwardRange::_, 38 | bool> IsSorted(R&& range, P comparer = Funal::Less) 39 | {return IsSorted(Range::Forward(range), comparer);} 40 | 41 | INTRA_WARNING_POP 42 | 43 | }} 44 | -------------------------------------------------------------------------------- /Intra/Range/Sort/Selection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Cpp/Warnings.h" 5 | 6 | #include "Utils/Span.h" 7 | 8 | #include "Funal/Op.h" 9 | 10 | #include "Range/Operations.h" 11 | 12 | namespace Intra { namespace Range { 13 | 14 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 15 | 16 | //! Сортировка выбором диапазона range с предикатом сравнения comparer. 17 | //! Характеристики алгоритма: 18 | //! - Худшее, среднее и лучшее время - O(n^2); 19 | //! - Неустойчив. 20 | template Meta::EnableIf< 21 | Concepts::IsRandomAccessRangeWithLength::_ && 22 | Concepts::IsAssignableRange::_ 23 | > SelectionSort(const R& range, C comparer = Funal::Less) 24 | { 25 | const size_t count = Count(range); 26 | for(size_t i=0; i 40 | > forceinline Meta::EnableIf< 41 | !Concepts::IsInputRange::_ && 42 | Concepts::IsRandomAccessRangeWithLength::_ && 43 | Concepts::IsAssignableRange::_ 44 | > SelectionSort(R&& range, C comparer = Funal::Less) 45 | {SelectionSort(Range::Forward(range), comparer);} 46 | 47 | INTRA_WARNING_POP 48 | 49 | }} 50 | -------------------------------------------------------------------------------- /Intra/Range/Special.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Special/Unicode.h" 4 | -------------------------------------------------------------------------------- /Intra/Range/Stream.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Stream/Parse.h" 4 | #include "Stream/ToStringArithmetic.h" 5 | #include "Stream/MaxLengthOfToString.h" 6 | #include "Stream/ToString.h" 7 | #include "Stream/Spaces.h" 8 | #include "Stream/InputStreamMixin.h" 9 | #include "Stream/OutputStreamMixin.h" 10 | #include "Stream/RawRead.h" 11 | #include "Stream/RawWrite.h" 12 | -------------------------------------------------------------------------------- /Intra/Range/Stream/RawWrite.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Concepts/Range.h" 4 | #include "Range/Mutation/Copy.h" 5 | 6 | namespace Intra { namespace Range { 7 | 8 | template forceinline Meta::EnableIf< 9 | Concepts::IsOutputRangeOf::_ || 10 | Concepts::IsOutputRangeOf::_, 11 | size_t> RawWriteFrom(OR& dst, const void* src, size_t n) 12 | { 13 | return WriteTo(CSpan(reinterpret_cast(src), n), dst); 14 | } 15 | 16 | template Meta::EnableIf< 17 | Concepts::IsOutputRangeOf::_ || 18 | Concepts::IsOutputRangeOf::_, 19 | size_t> RawWriteFrom(OR& dst, CSpan src) 20 | { 21 | const size_t srcLen = src.Length()*sizeof(T); 22 | return RawWriteFrom(dst, src.Data(), srcLen); 23 | } 24 | 25 | template Meta::EnableIf< 26 | Concepts::IsOutputRangeOf::_ || 27 | Concepts::IsOutputRangeOf::_, 28 | size_t> RawWriteFrom(OR& dst, Span src, size_t n) 29 | { 30 | const size_t srcLen = src.Length()*sizeof(T); 31 | if(n > srcLen) n = srcLen; 32 | return RawWriteFrom(dst, src.Data(), n); 33 | } 34 | 35 | template Meta::EnableIf< 36 | Concepts::IsOutputRangeOf::_ || 37 | Concepts::IsOutputRangeOf::_, 38 | size_t> RawWriteFrom(OR& dst, const T& src) 39 | { 40 | const size_t srcLen = src.Length()*sizeof(T); 41 | return RawWriteFrom(dst, &src, srcLen); 42 | } 43 | 44 | 45 | template Meta::EnableIf< 46 | Concepts::IsOutputRangeOf::_ || 47 | Concepts::IsOutputRangeOf::_ 48 | > RawWrite(OR& dst, const T& value) 49 | { 50 | RawWriteFrom(dst, &value, sizeof(T)); 51 | } 52 | 53 | }} 54 | -------------------------------------------------------------------------------- /Intra/Range/Stream/Spaces.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Features.h" 5 | 6 | #include "Concepts/Range.h" 7 | 8 | #include "Funal/Op.h" 9 | 10 | namespace Intra { namespace Range { 11 | 12 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 13 | 14 | template Meta::EnableIf< 15 | Concepts::IsCharRange::_ && 16 | !Meta::IsConst::_, 17 | size_t> SkipSpacesCountLinesAdvance(R& src) 18 | { 19 | size_t lines = 0; 20 | bool wasCR = false; 21 | while(!src.Empty() && Funal::IsSpace(src.First())) 22 | { 23 | char c = src.First(); 24 | if(c=='\r' || (c=='\n' && !wasCR)) 25 | lines++; 26 | wasCR = (c=='\r'); 27 | src.PopFirst(); 28 | } 29 | return lines; 30 | } 31 | 32 | template Meta::EnableIf< 33 | Concepts::IsCharRange::_ && 34 | !Meta::IsConst::_, 35 | size_t> CountLinesAdvance(R& src) 36 | { 37 | size_t lines = 0; 38 | bool wasCR = false; 39 | while(!src.Empty()) 40 | { 41 | char c = src.First(); 42 | if(c=='\r' || (c=='\n' && !wasCR)) 43 | lines++; 44 | wasCR = c=='\r'; 45 | src.PopFirst(); 46 | } 47 | return lines; 48 | } 49 | 50 | template forceinline Meta::EnableIf< 51 | Concepts::IsAsCharRange::_, 52 | size_t> CountLines(R&& range) 53 | { 54 | auto rangeCopy = Range::Forward(range); 55 | return CountLinesAdvance(rangeCopy); 56 | } 57 | 58 | INTRA_WARNING_POP 59 | 60 | }} 61 | 62 | -------------------------------------------------------------------------------- /Intra/Range/String.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "String/Ascii.h" 4 | #include "String/Escape.h" 5 | 6 | -------------------------------------------------------------------------------- /Intra/Range/String/Ascii.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utils/Span.h" 4 | #include "Utils/StringView.h" 5 | 6 | namespace Intra { namespace Range { 7 | 8 | void StringFindAscii(StringView& str, CSpan subStrs, size_t* oWhichIndex=null); 9 | 10 | StringView StringReadUntilAscii(StringView& str, CSpan stopSubStrSet, size_t* oWhichIndex=null); 11 | 12 | 13 | size_t StringMultiReplaceAsciiLength(StringView src, 14 | CSpan fromSubStrs, CSpan toSubStrs); 15 | 16 | StringView StringMultiReplaceAscii(StringView src, GenericStringView& dstBuffer, 17 | CSpan fromSubStrs, CSpan toSubStrs); 18 | 19 | }} 20 | -------------------------------------------------------------------------------- /Intra/Stream.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Stream/Operators.h" 4 | #include "Stream/InputStreamMixin.h" 5 | #include "Stream/OutputStreamMixin.h" 6 | -------------------------------------------------------------------------------- /Intra/System.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "System/Signal.h" 4 | #include "System/Environment.h" 5 | #include "System/ProcessorInfo.h" 6 | #include "System/RamInfo.h" 7 | #include "System/Stopwatch.h" 8 | #include "System/DateTime.h" 9 | #include "System/Sleep.h" 10 | -------------------------------------------------------------------------------- /Intra/System/DLL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utils/StringView.h" 4 | 5 | namespace Intra { namespace System { 6 | 7 | class DLL 8 | { 9 | struct Data; 10 | Data* mHandle; 11 | public: 12 | typedef Data* NativeHandle; 13 | 14 | DLL(null_t = null): mHandle(null) {} 15 | DLL(DLL&& rhs): mHandle(rhs.mHandle) {rhs.mHandle = null;} 16 | 17 | DLL& operator=(DLL&& rhs) 18 | { 19 | if(this == &rhs) return *this; 20 | Unload(); 21 | mHandle = rhs.mHandle; 22 | rhs.mHandle = null; 23 | return *this; 24 | } 25 | 26 | forceinline DLL& operator=(null_t) {Unload(); return *this;} 27 | 28 | ~DLL() {Unload();} 29 | 30 | DLL(const DLL&) = delete; 31 | DLL& operator=(const DLL&) = delete; 32 | 33 | static DLL Load(StringView dllName); 34 | void* FunctionAddress(StringView name) const; 35 | void Unload(); 36 | 37 | template forceinline F* Function(StringView name) 38 | {return static_cast(FunctionAddress(name));} 39 | 40 | template forceinline void Function(StringView name, F*& f) 41 | {return f = static_cast(FunctionAddress(name));} 42 | 43 | forceinline NativeHandle GetNativeHandle() const {return mHandle;} 44 | }; 45 | 46 | } 47 | using System::DLL; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Intra/System/DateTime.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/System/DateTime.h -------------------------------------------------------------------------------- /Intra/System/Environment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | 5 | #include "Utils/Span.h" 6 | #include "Utils/FixedArray.h" 7 | 8 | #include "Meta/Pair.h" 9 | 10 | #include "Container/Sequential/String.h" 11 | 12 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 13 | 14 | namespace Intra { namespace System { 15 | 16 | struct TEnvironment 17 | { 18 | CSpan CommandLine; 19 | 20 | struct VarSet 21 | { 22 | VarSet(FixedArray&& data, size_t count): 23 | mData(Cpp::Move(data)), mCount(count) {} 24 | 25 | VarSet(const VarSet&) = delete; 26 | 27 | VarSet(VarSet&& rhs): 28 | mData(Cpp::Move(rhs.mData)), mCount(rhs.mCount) {} 29 | 30 | VarSet& operator=(const VarSet&) = delete; 31 | 32 | VarSet& operator=(VarSet&& rhs) 33 | { 34 | mData = Cpp::Move(rhs.mData); 35 | mCount = rhs.mCount; 36 | return *this; 37 | } 38 | 39 | CSpan> AsRange() const; 40 | size_t Length() const {return mCount;} 41 | private: 42 | FixedArray mData; 43 | size_t mCount; 44 | }; 45 | 46 | TEnvironment(); 47 | VarSet Variables() const; 48 | String Get(StringView var, bool* oExists) const; 49 | 50 | String operator[](StringView var) const {return Get(var, null);} 51 | 52 | String Get(StringView var, StringView fallbackValue) const 53 | { 54 | bool exists; 55 | String result = Get(var, &exists); 56 | if(exists) return result; 57 | return fallbackValue; 58 | } 59 | }; 60 | 61 | 62 | extern const TEnvironment Environment; 63 | 64 | } 65 | using System::Environment; 66 | 67 | } 68 | 69 | INTRA_WARNING_POP 70 | -------------------------------------------------------------------------------- /Intra/System/ProcessorInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Container/Sequential/String.h" 5 | 6 | namespace Intra { namespace System { 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | struct ProcessorInfo 11 | { 12 | String BrandString; 13 | ushort CoreNumber = 1; 14 | ushort LogicalProcessorNumber = 1; 15 | ulong64 Frequency = 0; 16 | 17 | static ProcessorInfo Get(); 18 | }; 19 | 20 | INTRA_WARNING_POP 21 | 22 | }} 23 | -------------------------------------------------------------------------------- /Intra/System/RamInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Fundamental.h" 5 | 6 | namespace Intra { namespace System { 7 | 8 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 9 | 10 | struct RamInfo 11 | { 12 | ulong64 TotalPhysicalMemory = 0; 13 | ulong64 FreePhysicalMemory = 0; 14 | ulong64 TotalVirtualMemory = 0; 15 | ulong64 FreeVirtualMemory = 0; 16 | ulong64 TotalSwapMemory = 0; 17 | ulong64 FreeSwapMemory = 0; 18 | 19 | static RamInfo Get(); 20 | }; 21 | 22 | INTRA_WARNING_POP 23 | 24 | }} 25 | -------------------------------------------------------------------------------- /Intra/System/Signal.cpp: -------------------------------------------------------------------------------- 1 | #include "System/Signal.h" 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Compatibility.h" 5 | 6 | #include "Utils/StringView.h" 7 | 8 | INTRA_DISABLE_REDUNDANT_WARNINGS 9 | 10 | #include 11 | #include 12 | 13 | namespace Intra { 14 | 15 | static void INTRA_CRTDECL SignalHandler(int signum) 16 | { 17 | if(System::CrashHandler != null) 18 | System::CrashHandler(signum); 19 | if(signum == SIGTERM) exit(1); 20 | INTRA_FATAL_ERROR(System::CrashSignalDesc(signum)); 21 | } 22 | 23 | 24 | namespace System { 25 | 26 | void InitSignals() 27 | { 28 | signal(SIGSEGV, SignalHandler); 29 | signal(SIGTERM, SignalHandler); 30 | signal(SIGILL, SignalHandler); 31 | //signal(SIGABRT, SignalHandler); 32 | signal(SIGFPE, SignalHandler); 33 | } 34 | 35 | StringView CrashSignalName(int signum) 36 | { 37 | switch(signum) 38 | { 39 | case SIGSEGV: return "SIGSEGV"; 40 | case SIGTERM: return "SIGTERM"; 41 | case SIGILL: return "SIGILL"; 42 | case SIGABRT: return "SIGABRT"; 43 | case SIGFPE: return "SIGFPE"; 44 | default: return "Unknown"; 45 | } 46 | } 47 | 48 | StringView CrashSignalDesc(int signum) 49 | { 50 | switch(signum) 51 | { 52 | case SIGSEGV: return "SEGMENTATION FAULT"; 53 | case SIGTERM: return "PROCESS TERMINATION"; 54 | case SIGILL: return "ILLEGAL INSTRUCTION"; 55 | case SIGABRT: return "ABORT CALL"; 56 | case SIGFPE: return "FLOATING POINT EXCEPTION"; 57 | default: return "UNKNOWN SIGNAL"; 58 | } 59 | } 60 | 61 | void(*CrashHandler)(int signum)=null; 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Intra/System/Signal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Fundamental.h" 5 | #include "Utils/StringView.h" 6 | 7 | namespace Intra { 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | namespace System 12 | { 13 | void InitSignals(); 14 | StringView CrashSignalName(int signum); 15 | StringView CrashSignalDesc(int signum); 16 | extern void(*CrashHandler)(int signum); 17 | } 18 | 19 | INTRA_WARNING_POP 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Intra/System/Stopwatch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Warnings.h" 4 | #include "Cpp/Fundamental.h" 5 | #include "Cpp/PlatformDetect.h" 6 | 7 | #define INTRA_LIBRARY_STOPWATCH_QPC 1 8 | #define INTRA_LIBRARY_STOPWATCH_clock_gettime 2 9 | #define INTRA_LIBRARY_STOPWATCH_clock 3 10 | #define INTRA_LIBRARY_STOPWATCH_gettimeofday 4 11 | #define INTRA_LIBRARY_STOPWATCH_Cpp11 5 12 | 13 | 14 | #ifndef INTRA_LIBRARY_STOPWATCH 15 | 16 | #ifdef INTRA_LIBRARY_USE_STD_CLOCK 17 | #define INTRA_LIBRARY_STOPWATCH INTRA_LIBRARY_STOPWATCH_Cpp11 18 | #elif(INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_Windows) 19 | #define INTRA_LIBRARY_STOPWATCH INTRA_LIBRARY_STOPWATCH_QPC 20 | #elif(INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_MacOS || INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_iOS) 21 | #define INTRA_LIBRARY_STOPWATCH INTRA_LIBRARY_STOPWATCH_gettimeofday 22 | #else 23 | #define INTRA_LIBRARY_STOPWATCH INTRA_LIBRARY_STOPWATCH_clock_gettime 24 | #endif 25 | 26 | #endif 27 | 28 | namespace Intra { namespace System { 29 | 30 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 31 | 32 | class Stopwatch 33 | { 34 | public: 35 | Stopwatch(); 36 | ~Stopwatch(); 37 | 38 | void Reset(); 39 | double ElapsedSeconds() const; 40 | double GetElapsedSecondsAndReset(); 41 | 42 | uint ElapsedUs() {return uint(ElapsedSeconds()*1000000);} 43 | uint GetElapsedUsAndReset() {return uint(GetElapsedSecondsAndReset()*1000000);} 44 | 45 | uint ElapsedMs() {return uint(ElapsedSeconds()*1000);} 46 | uint GetElapsedMsAndReset() {return uint(GetElapsedSecondsAndReset()*1000);} 47 | 48 | private: 49 | ulong64 mData; 50 | }; 51 | 52 | INTRA_WARNING_POP 53 | 54 | } 55 | using System::Stopwatch; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Intra/System/System.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Environment(...) 6 | $env 7 | 8 | CommandLine 9 | $env 10 | $pid 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Intra/System/detail/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/PlatformDetect.h" 4 | #include "Utils/ErrorStatus.h" 5 | #include "Container/ForwardDecls.h" 6 | 7 | namespace Intra { namespace System { namespace detail { 8 | 9 | #if(INTRA_PLATFORM_OS == INTRA_PLATFORM_OS_Windows) 10 | //! Converts UTF-8 to UTF-16 null-terminated string, using MultibyteToWideChar from WinAPI. 11 | GenericString Utf8ToWStringZ(StringView str); 12 | #endif 13 | 14 | //! Calls error on status with description of GetLastError on Windows and errno on other systems. 15 | void ProcessLastError(ErrorStatus& status, StringView message, const Utils::SourceInfo& srcInfo); 16 | 17 | }}} 18 | -------------------------------------------------------------------------------- /Intra/Test.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Test/PerfSummary.h" 4 | #include "Test/TestData.h" 5 | #include "Test/TestGroup.h" 6 | -------------------------------------------------------------------------------- /Intra/Test/PerfSummary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utils/Span.h" 4 | #include "IO/FormattedWriter.h" 5 | #include "Utils/StringView.h" 6 | 7 | namespace Intra { 8 | 9 | INTRA_PUSH_DISABLE_REDUNDANT_WARNINGS 10 | 11 | void PrintPerformanceResults(IO::FormattedWriter& logger, StringView testName, 12 | CSpan comparedTypes, 13 | CSpan stdTimes, 14 | CSpan times); 15 | 16 | INTRA_WARNING_POP 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Intra/Test/TestGroup.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Test/TestGroup.h -------------------------------------------------------------------------------- /Intra/Utils.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Utils/AnyPtr.h" 4 | #include "Utils/ArrayAlgo.h" 5 | #include "Utils/AsciiSet.h" 6 | #include "Utils/Callable.h" 7 | #include "Utils/Callback.h" 8 | #include "Utils/Debug.h" 9 | #include "Utils/Delegate.h" 10 | #include "Utils/ErrorStatus.h" 11 | #include "Utils/Finally.h" 12 | #include "Utils/FixedArray.h" 13 | #include "Utils/IteratorRange.h" 14 | #include "Utils/Logger.h" 15 | #include "Utils/Method.h" 16 | #include "Utils/Op.h" 17 | #include "Utils/Optional.h" 18 | #include "Utils/Promise.h" 19 | #include "Utils/Span.h" 20 | #include "Utils/StringView.h" 21 | #include "Utils/Shared.h" 22 | #include "Utils/Unique.h" 23 | -------------------------------------------------------------------------------- /Intra/Utils/AnyPtr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Cpp/Fundamental.h" 5 | 6 | namespace Intra { namespace Utils { 7 | 8 | class AnyPtr 9 | { 10 | void* mPtr; 11 | public: 12 | 13 | forceinline AnyPtr(null_t=null): mPtr(null) {} 14 | 15 | template forceinline AnyPtr(T* p) 16 | { 17 | typedef void* pvoid; 18 | mPtr = pvoid(p); 19 | } 20 | 21 | template forceinline operator T*() const 22 | { 23 | typedef T* Tptr; 24 | return Tptr(mPtr); 25 | } 26 | 27 | forceinline bool operator==(null_t) const {return mPtr == null;} 28 | forceinline bool operator!=(null_t) const {return mPtr != null;} 29 | }; 30 | 31 | } 32 | using Utils::AnyPtr; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Intra/Utils/ErrorStatus.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Utils/ErrorStatus.h -------------------------------------------------------------------------------- /Intra/Utils/FixedArray.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devoln/Intra/aed1647cd2cf1781ab0976c2809533d0f347e87e/Intra/Utils/FixedArray.h -------------------------------------------------------------------------------- /Intra/Utils/IteratorRange.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cpp/Features.h" 4 | #include "Debug.h" 5 | 6 | #ifndef INTRA_UTILS_NO_CONCEPTS 7 | #include "Concepts/Iterator.h" 8 | #endif 9 | 10 | namespace Intra { 11 | 12 | namespace Range { 13 | 14 | template struct IteratorRange 15 | { 16 | #ifndef INTRA_UTILS_NO_CONCEPTS 17 | static_assert(Concepts::IsMinimalInputIterator::_, 18 | "I1 must implement at least minimal input iterator concept!"); 19 | #endif 20 | 21 | I1 Begin; 22 | I2 End; 23 | 24 | forceinline bool Empty() const {return Begin == End;} 25 | forceinline void PopFirst() {INTRA_DEBUG_ASSERT(!Empty()); ++Begin;} 26 | forceinline decltype(*Meta::Val()) First() const {INTRA_DEBUG_ASSERT(!Empty()); return *Begin;} 27 | 28 | #ifndef INTRA_UTILS_NO_CONCEPTS 29 | template forceinline Meta::EnableIf< 30 | Concepts::IsMinimalBidirectionalIterator::_ 31 | > PopLast() {INTRA_DEBUG_ASSERT(!Empty()); --End;} 32 | 33 | template forceinline Meta::EnableIf< 34 | Concepts::IsMinimalBidirectionalIterator::_, 35 | decltype(*Meta::Val())> Last() const {INTRA_DEBUG_ASSERT(!Empty()); return *--I2(End);} 36 | 37 | template forceinline Meta::EnableIf< 38 | Concepts::HasDifference::_, 39 | size_t> Length() const {INTRA_DEBUG_ASSERT(!Empty()); return size_t(End-Begin);} 40 | #endif 41 | 42 | forceinline I1 begin() const {return Begin;} 43 | forceinline I2 end() const {return End;} 44 | }; 45 | 46 | } 47 | 48 | namespace Utils { 49 | using Range::IteratorRange; 50 | } 51 | using Range::IteratorRange; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Intra/Utils/Promise.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Volnov Alexander (gammaker) 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. -------------------------------------------------------------------------------- /SetupMSVC.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Install debugger settings for Visual Studio 4 | 5 | @FOR /F "tokens=3* delims= " %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal"') do @(Set UserDocuments=%%a) 6 | 7 | if exist "%UserDocuments%\Visual Studio 2015\" ( 8 | xcopy Intra\Intra.natstepfilter "%UserDocuments%\Visual Studio 2015\Visualizers\" /I /Y 9 | ) 10 | 11 | if exist "%UserDocuments%\Visual Studio 2017\" ( 12 | xcopy Intra\Intra.natstepfilter "%UserDocuments%\Visual Studio 2017\Visualizers\" /I /Y 13 | ) 14 | pause --------------------------------------------------------------------------------