├── .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 |