From 4f1cbd98f9d8995f64413697aca552067868a695 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 21 Mar 2025 01:08:09 +0000 Subject: [PATCH] started templating --- animation/Animation.h | 4 +- animation/AnimationEaseType.h | 4 +- architecture/CpuInfo.cpp | 4 +- architecture/CpuInfo.h | 4 +- architecture/Intrinsics.h | 4 +- architecture/arm/CpuInfo.cpp | 4 +- architecture/arm/Intrinsics.h | 4 +- architecture/arm/neon/utils/Utils.h | 4 +- architecture/arm/sve/utils/Utils.h | 4 +- architecture/x86/CpuInfo.cpp | 4 +- architecture/x86/Intrinsics.h | 4 +- architecture/x86/simd/SIMD_F32.h | 4 +- architecture/x86/simd/SIMD_F64.h | 4 +- architecture/x86/simd/SIMD_I16.h | 49 +-- architecture/x86/simd/SIMD_I32.h | 138 ++++++-- architecture/x86/simd/SIMD_I64.h | 4 +- architecture/x86/simd/SIMD_I8.h | 49 +-- architecture/x86/simd/SIMD_SVML.h | 10 +- architecture/x86/simd/utils/Utils.h | 4 +- asset/Asset.h | 4 +- asset/AssetArchive.h | 4 +- asset/AssetManagementSystem.h | 24 +- asset/AssetType.h | 4 +- audio/Audio.cpp | 4 +- audio/Audio.h | 4 +- audio/AudioMixer.h | 6 +- audio/AudioSetting.h | 4 +- audio/Qoa.h | 4 +- audio/QoaSimd.h | 4 +- audio/Wav.h | 4 +- auth/Auth.h | 4 +- camera/Camera.h | 4 +- camera/CameraMovement.h | 4 +- color/ColorVisionDeficiency.h | 4 +- command/AppCmdBuffer.cpp | 16 +- command/AppCmdBuffer.h | 6 +- command/Command.h | 4 +- compiler/CompilerUtils.h | 4 +- compiler/gcc/Atomic.h | 126 +++++++- compiler/gcc/CompilerUtils.h | 12 +- compiler/msvc/CompilerUtils.h | 4 +- compression/Huffman.h | 8 +- compression/LZP.h | 4 +- compression/RLE.h | 4 +- database/Database.h | 4 +- database/DatabaseConnection.h | 4 +- database/DatabaseType.h | 4 +- encryption/CeasarEncryption.h | 4 +- encryption/XorEncryption.h | 4 +- entity/AnimationEntityComponent.h | 4 +- entity/CursorEntity.h | 4 +- entity/Entity.h | 4 +- entity/EntityComponentSystem.h | 12 +- entity/EntitySize.h | 4 +- environment/Globe.h | 4 +- environment/Universe.h | 4 +- error/HammingCodes.h | 4 +- font/Font.h | 4 +- gpuapi/AntiAliasing.h | 4 +- gpuapi/GpuApiType.h | 4 +- gpuapi/GpuAttributeType.h | 4 +- gpuapi/RenderUtils.h | 4 +- gpuapi/ShaderType.h | 4 +- gpuapi/direct3d/AppCmdBuffer.h | 4 +- gpuapi/direct3d/DirectXUtils.h | 4 +- gpuapi/direct3d/FramesInFlightContainer.h | 4 +- gpuapi/direct3d/Shader.h | 4 +- gpuapi/direct3d/ShaderUtils.h | 4 +- gpuapi/opengl/AppCmdBuffer.h | 4 +- gpuapi/opengl/FramesInFlightContainer.h | 4 +- gpuapi/opengl/Opengl.h | 4 +- gpuapi/opengl/OpenglDefines.h | 4 +- .../opengl/OpenglDescriptorSetLayoutBinding.h | 4 +- gpuapi/opengl/OpenglLinux.h | 4 +- gpuapi/opengl/OpenglUtils.h | 4 +- gpuapi/opengl/OpenglWin32.h | 4 +- gpuapi/opengl/Shader.h | 4 +- gpuapi/opengl/ShaderUtils.h | 4 +- gpuapi/vulkan/AppCmdBuffer.h | 4 +- gpuapi/vulkan/FramesInFlightContainer.h | 4 +- gpuapi/vulkan/Shader.h | 4 +- gpuapi/vulkan/ShaderUtils.h | 4 +- gpuapi/vulkan/VulkanUtils.h | 4 +- hash/Crc.h | 4 +- hash/GeneralHash.h | 22 +- html/template/HtmlTemplate.h | 30 ++ html/template/HtmlTemplateCache.h | 159 ++++++++++ html/template/HtmlTemplateContext.h | 42 +++ html/template/HtmlTemplateInterpreter.h | 297 ++++++++++++++++++ html/template/HtmlTemplateLexer.h | 272 ++++++++++++++++ html/template/HtmlTemplateParser.h | 246 +++++++++++++++ image/Bitmap.h | 18 +- image/Image.cpp | 4 +- image/Image.h | 4 +- image/Png.h | 4 +- image/Qoi.h | 4 +- image/Tga.h | 4 +- image/default_colors.h | 4 +- input/ControllerInput.h | 4 +- input/ControllerType.h | 4 +- input/Input.h | 6 +- input/InputConnectionType.h | 4 +- localization/Language.h | 4 +- log/DebugContainer.h | 6 +- log/DebugMemory.h | 10 +- log/Log.h | 22 +- log/PerformanceProfiler.h | 26 +- log/Stats.h | 8 +- math/Evaluator.h | 4 +- math/matrix/MatrixFloat32.h | 4 +- math/matrix/MatrixInt32.h | 4 +- math/matrix/MatrixInt64.h | 4 +- math/matrix/QuaternionFloat32.h | 4 +- math/matrix/VectorFloat32.h | 4 +- math/matrix/VectorFloat64.h | 4 +- math/matrix/VectorInt32.h | 4 +- math/matrix/VectorInt64.h | 4 +- math/random/BlueNoise.h | 4 +- memory/BufferMemory.h | 4 +- memory/ChunkMemory.h | 4 +- memory/Heap.h | 4 +- memory/Queue.h | 8 +- memory/RingMemory.h | 10 +- memory/ThreadedChunkMemory.h | 8 +- memory/ThreadedQueue.h | 124 ++++---- memory/ThreadedRingMemory.h | 46 +-- models/Location.h | 4 +- models/Obj.h | 4 +- models/Sound.h | 4 +- models/account/Account.h | 4 +- models/bracket/Bracket.h | 4 +- models/bracket/BracketMatch.h | 4 +- models/bracket/BracketSeeding.h | 4 +- models/bracket/BracketTeam.h | 4 +- models/chat/Chat.h | 4 +- models/chat/ChatLevel.h | 4 +- models/chat/ChatStatus.h | 4 +- models/chat/ChatType.h | 4 +- models/event/Event.h | 4 +- models/event/EventTaskType.h | 4 +- models/event/tmp | 4 +- models/extension/ExtensionType.h | 4 +- models/guild/GuildBanner.h | 4 +- models/item/Consumable.h | 4 +- models/item/ConsumableType.h | 4 +- models/item/Equipment.cpp | 4 +- models/item/Equipment.h | 4 +- models/item/EquipmentType.h | 4 +- models/item/Item.h | 4 +- models/item/ItemAffixDistribution.h | 4 +- models/item/ItemLevelStats.h | 4 +- models/item/ItemRarityDefinition.h | 4 +- models/item/ItemRarityStats.h | 4 +- models/item/ItemStatsDistribution.h | 4 +- models/item/MobLevelStats.h | 4 +- models/item/_equipment_slots.h | 4 +- models/item/_equipment_types.h | 4 +- models/item/_item_rarity.h | 4 +- models/mob/ActivityStats.h | 4 +- models/mob/FixedStats.h | 4 +- models/mob/Mob.cpp | 4 +- models/mob/Mob.h | 4 +- models/mob/MobAction.h | 4 +- models/mob/MobState.h | 4 +- models/mob/MobStats.cpp | 4 +- models/mob/MobStats.h | 4 +- models/mob/MobStatsType.h | 4 +- models/mob/PrimaryStatsPoints.cpp | 4 +- models/mob/PrimaryStatsPoints.h | 4 +- models/mob/SecondaryStatsPoints.cpp | 4 +- models/mob/SecondaryStatsPoints.h | 4 +- models/mob/_mob_category.h | 4 +- models/mob/_mob_list.h | 4 +- models/mob/monster/Drop.h | 4 +- models/mob/monster/LootTable.h | 4 +- models/mob/monster/Monster.h | 4 +- models/mob/monster/MonsterStats.h | 4 +- models/mob/player/Backpack.h | 4 +- models/mob/player/Guild.h | 4 +- models/mob/player/Player.h | 4 +- models/mob/player/PlayerStats.h | 4 +- models/mob/player/PlayerXPRequirement.h | 4 +- models/mob/player/Reputation.h | 4 +- models/mob/player/_player_class.h | 4 +- models/mob/skill/AoeDistribution.h | 4 +- models/mob/skill/AoeShape.h | 4 +- models/mob/skill/ProjectileDistribution.h | 4 +- models/mob/skill/Skill.h | 4 +- models/mob/skill/StatsTarget.h | 4 +- models/object/Block.h | 4 +- models/object/Chunk.h | 4 +- models/object/Object.h | 4 +- models/object/ObjectType.h | 4 +- models/object/_object_list.h | 4 +- models/object/_object_types.h | 4 +- models/settings/DungeonSettings.h | 4 +- models/settings/ItemDistributionType.h | 4 +- models/settings/Settings.h | 4 +- models/settings/setting_types.h | 4 +- module/Module.h | 4 +- module/ModuleManager.h | 4 +- network/Server.h | 18 ++ network/Socket.h | 4 +- network/SocketConnection.h | 4 +- network/packet/OMSPacket.h | 4 +- network/packet/PacketCache.h | 4 +- network/packet/PacketHeader.h | 4 +- network/packet/UDPPacket.h | 4 +- network/packet/chat/ChatMessagePacket.h | 4 +- network/packet/general/AckPacket.h | 4 +- network/packet/general/PingPacket.h | 4 +- network/packet/mob/MobInfoPacket.h | 4 +- network/packet/mob/MobStatePacket.h | 4 +- network/packet/mob/player/PlayerInfoPacket.h | 4 +- network/packet/mob/player/PlayerState.h | 4 +- network/packet/packet_types.h | 4 +- noise/FractalNoise.h | 4 +- noise/SimplexNoise.h | 4 +- noise/ValueNoise.h | 4 +- noise/WorleyNoise.h | 4 +- object/Animation.h | 4 +- object/Hitbox.h | 4 +- object/Material.h | 4 +- object/Mesh.h | 4 +- object/Texture.h | 4 +- object/Vertex.h | 4 +- particle/Particle.h | 4 +- pathfinding/Jpsp.h | 4 +- pathfinding/Metric2d.h | 4 +- pathfinding/Metric3d.h | 4 +- pathfinding/Path.h | 4 +- pathfinding/jps/Jps.h | 4 +- pathfinding/jps/JpsGrid.h | 4 +- pathfinding/jps/JpsNode.h | 4 +- platform/linux/Allocator.h | 6 +- platform/linux/ExceptionHandler.h | 4 +- platform/linux/FileUtils.cpp | 55 +++- platform/linux/Library.cpp | 4 +- platform/linux/Library.h | 4 +- platform/linux/SystemInfo.cpp | 4 +- platform/linux/TimeUtils.h | 30 ++ platform/linux/UtilsLinux.h | 8 +- platform/linux/network/Server.h | 57 +++- platform/linux/network/Socket.h | 4 +- platform/linux/threading/Atomic.h | 4 +- platform/linux/threading/Semaphore.h | 4 +- platform/linux/threading/Spinlock.cpp | 4 +- platform/linux/threading/Spinlock.h | 4 +- platform/linux/threading/Thread.h | 261 +++++++++------ platform/linux/threading/ThreadDefines.h | 47 ++- platform/win32/Allocator.h | 4 +- platform/win32/Clipboard.h | 4 +- platform/win32/ExceptionHandler.h | 4 +- platform/win32/FastPipes.h | 4 +- platform/win32/FileUtils.cpp | 45 ++- platform/win32/LeanWin32.h | 4 +- platform/win32/Library.cpp | 4 +- platform/win32/Library.h | 4 +- platform/win32/SystemInfo.cpp | 4 +- platform/win32/TimeUtils.h | 4 +- platform/win32/UtilsWin32.h | 9 +- platform/win32/UtilsWindows.h | 4 +- platform/win32/Window.h | 4 +- platform/win32/audio/DirectSound.h | 4 +- platform/win32/audio/Wasapi.h | 4 +- platform/win32/audio/XAudio2.h | 4 +- platform/win32/input/DirectInput.h | 4 +- platform/win32/input/HidInput.h | 4 +- platform/win32/input/RawInput.h | 4 +- platform/win32/input/XInput.h | 4 +- .../input/controller/ControllerHandler.h | 4 +- platform/win32/input/controller/DualSense.h | 4 +- platform/win32/input/controller/DualShock4.h | 4 +- platform/win32/network/Client.h | 4 +- platform/win32/network/Server.h | 47 ++- platform/win32/network/Socket.h | 6 +- platform/win32/threading/Atomic.h | 11 +- platform/win32/threading/Semaphore.h | 4 +- platform/win32/threading/Spinlock.cpp | 4 +- platform/win32/threading/Spinlock.h | 4 +- platform/win32/threading/Thread.h | 48 +-- platform/win32/threading/ThreadDefines.h | 18 +- scene/SceneInfo.h | 4 +- sort/BinarySearch.h | 4 +- sort/EytzingerSearch.h | 4 +- sort/HeapSort.h | 4 +- sort/InsertionSort.h | 4 +- sort/IntroSort.h | 4 +- sort/QuickSort.h | 4 +- sort/Sort.h | 4 +- stdlib/HashMap.h | 28 +- stdlib/PerfectHashMap.h | 93 +++--- stdlib/Simd.h | 4 +- stdlib/ThreadedHashMap.h | 54 ++-- stdlib/Types.h | 10 +- system/Allocator.h | 4 +- system/FileUtils.cpp | 4 +- system/Library.cpp | 4 +- system/Library.h | 4 +- system/SystemInfo.cpp | 4 +- system/SystemInfo.h | 4 +- system/Window.h | 4 +- tests/TestFramework.h | 4 +- thread/Atomic.h | 4 +- thread/Semaphore.h | 4 +- thread/Spinlock.cpp | 4 +- thread/Spinlock.h | 4 +- thread/Thread.h | 10 +- thread/ThreadDefines.h | 4 +- thread/ThreadJob.h | 12 +- thread/ThreadPool.h | 76 ++--- ui/UIAlignment.h | 4 +- ui/UIAnimation.h | 4 +- ui/UIButton.h | 4 +- ui/UICursor.h | 4 +- ui/UICustom.h | 4 +- ui/UIElement.h | 6 +- ui/UIElementType.h | 4 +- ui/UIImage.h | 4 +- ui/UIInput.h | 4 +- ui/UILabel.h | 4 +- ui/UILayout.cpp | 4 +- ui/UILayout.h | 4 +- ui/UILink.h | 4 +- ui/UIPanel.h | 4 +- ui/UISelect.h | 4 +- ui/UIStyleType.h | 4 +- ui/UITab.h | 4 +- ui/UITable.h | 4 +- ui/UIText.h | 4 +- ui/UITextarea.h | 4 +- ui/UITheme.h | 4 +- ui/UIWindow.h | 4 +- ui/attribute/UIAttribute.h | 4 +- ui/attribute/UIAttributeBackground.h | 4 +- ui/attribute/UIAttributeBorder.h | 4 +- ui/attribute/UIAttributeDimension.h | 4 +- ui/attribute/UIAttributeFont.h | 4 +- ui/attribute/UIAttributeShadow.h | 4 +- ui/attribute/UIAttributeType.h | 4 +- utils/BitUtils.h | 20 +- utils/EndianUtils.h | 4 +- utils/MathUtils.h | 4 +- utils/RandomUtils.h | 4 +- utils/StringUtils.h | 63 ++-- utils/TestUtils.h | 4 +- utils/TimeUtils.h | 18 ++ utils/Utils.h | 19 +- 348 files changed, 2748 insertions(+), 1303 deletions(-) create mode 100644 html/template/HtmlTemplate.h create mode 100644 html/template/HtmlTemplateCache.h create mode 100644 html/template/HtmlTemplateContext.h create mode 100644 html/template/HtmlTemplateInterpreter.h create mode 100644 html/template/HtmlTemplateLexer.h create mode 100644 html/template/HtmlTemplateParser.h create mode 100644 network/Server.h create mode 100644 platform/linux/TimeUtils.h create mode 100644 utils/TimeUtils.h diff --git a/animation/Animation.h b/animation/Animation.h index 92c9798..1b04948 100644 --- a/animation/Animation.h +++ b/animation/Animation.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ANIMATION_H -#define TOS_ANIMATION_H +#ifndef COMS_ANIMATION_H +#define COMS_ANIMATION_H #include #include "../stdlib/Types.h" diff --git a/animation/AnimationEaseType.h b/animation/AnimationEaseType.h index ba8597c..0b0795d 100644 --- a/animation/AnimationEaseType.h +++ b/animation/AnimationEaseType.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ANIMATION_EASE_TYPE_H -#define TOS_ANIMATION_EASE_TYPE_H +#ifndef COMS_ANIMATION_EASE_TYPE_H +#define COMS_ANIMATION_EASE_TYPE_H #include "../stdlib/Types.h" diff --git a/architecture/CpuInfo.cpp b/architecture/CpuInfo.cpp index 55a02d7..dea70c2 100644 --- a/architecture/CpuInfo.cpp +++ b/architecture/CpuInfo.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_CPU_INFO_C -#define TOS_ARCHITECTURE_CPU_INFO_C +#ifndef COMS_ARCHITECTURE_CPU_INFO_C +#define COMS_ARCHITECTURE_CPU_INFO_C #include "CpuInfo.h" diff --git a/architecture/CpuInfo.h b/architecture/CpuInfo.h index 6eefb0d..1ef33ac 100644 --- a/architecture/CpuInfo.h +++ b/architecture/CpuInfo.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_CPU_INFO_H -#define TOS_ARCHITECTURE_CPU_INFO_H +#ifndef COMS_ARCHITECTURE_CPU_INFO_H +#define COMS_ARCHITECTURE_CPU_INFO_H #include "../stdlib/Types.h" diff --git a/architecture/Intrinsics.h b/architecture/Intrinsics.h index 7399a6f..9b87ae4 100644 --- a/architecture/Intrinsics.h +++ b/architecture/Intrinsics.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_INTRINSICS_H -#define TOS_ARCHITECTURE_INTRINSICS_H +#ifndef COMS_ARCHITECTURE_INTRINSICS_H +#define COMS_ARCHITECTURE_INTRINSICS_H #if ARM #include "arm/Intrinsics.h" diff --git a/architecture/arm/CpuInfo.cpp b/architecture/arm/CpuInfo.cpp index 163ae84..a1e2c10 100644 --- a/architecture/arm/CpuInfo.cpp +++ b/architecture/arm/CpuInfo.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_ARM_CPU_INFO_C -#define TOS_ARCHITECTURE_ARM_CPU_INFO_C +#ifndef COMS_ARCHITECTURE_ARM_CPU_INFO_C +#define COMS_ARCHITECTURE_ARM_CPU_INFO_C #include #include diff --git a/architecture/arm/Intrinsics.h b/architecture/arm/Intrinsics.h index b64025a..08bfb69 100644 --- a/architecture/arm/Intrinsics.h +++ b/architecture/arm/Intrinsics.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_ARM_INTRINSICS_ARM_H -#define TOS_ARCHITECTURE_ARM_INTRINSICS_ARM_H +#ifndef COMS_ARCHITECTURE_ARM_INTRINSICS_ARM_H +#define COMS_ARCHITECTURE_ARM_INTRINSICS_ARM_H #include #include diff --git a/architecture/arm/neon/utils/Utils.h b/architecture/arm/neon/utils/Utils.h index 5b9fefc..88c3d59 100644 --- a/architecture/arm/neon/utils/Utils.h +++ b/architecture/arm/neon/utils/Utils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_ARM_NEON_UTILS_H -#define TOS_ARCHITECTURE_ARM_NEON_UTILS_H +#ifndef COMS_ARCHITECTURE_ARM_NEON_UTILS_H +#define COMS_ARCHITECTURE_ARM_NEON_UTILS_H #include #include "../../../../stdlib/Types.h" diff --git a/architecture/arm/sve/utils/Utils.h b/architecture/arm/sve/utils/Utils.h index e633638..2fd759e 100644 --- a/architecture/arm/sve/utils/Utils.h +++ b/architecture/arm/sve/utils/Utils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_ARM_SVE_UTILS_H -#define TOS_ARCHITECTURE_ARM_SVE_UTILS_H +#ifndef COMS_ARCHITECTURE_ARM_SVE_UTILS_H +#define COMS_ARCHITECTURE_ARM_SVE_UTILS_H #include #include "../../../../stdlib/Types.h" diff --git a/architecture/x86/CpuInfo.cpp b/architecture/x86/CpuInfo.cpp index 69e12f1..edea828 100644 --- a/architecture/x86/CpuInfo.cpp +++ b/architecture/x86/CpuInfo.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_X86_CPU_INFO_C -#define TOS_ARCHITECTURE_X86_CPU_INFO_C +#ifndef COMS_ARCHITECTURE_X86_CPU_INFO_C +#define COMS_ARCHITECTURE_X86_CPU_INFO_C #include #include diff --git a/architecture/x86/Intrinsics.h b/architecture/x86/Intrinsics.h index f351d1f..20319e9 100644 --- a/architecture/x86/Intrinsics.h +++ b/architecture/x86/Intrinsics.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_X86_INTRINSICS_H -#define TOS_ARCHITECTURE_X86_INTRINSICS_H +#ifndef COMS_ARCHITECTURE_X86_INTRINSICS_H +#define COMS_ARCHITECTURE_X86_INTRINSICS_H #include #include diff --git a/architecture/x86/simd/SIMD_F32.h b/architecture/x86/simd/SIMD_F32.h index 7925f3b..edf374d 100644 --- a/architecture/x86/simd/SIMD_F32.h +++ b/architecture/x86/simd/SIMD_F32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_STDLIB_SIMD_F32_H -#define TOS_STDLIB_SIMD_F32_H +#ifndef COMS_STDLIB_SIMD_F32_H +#define COMS_STDLIB_SIMD_F32_H #include #include diff --git a/architecture/x86/simd/SIMD_F64.h b/architecture/x86/simd/SIMD_F64.h index 9a19795..9166cb2 100644 --- a/architecture/x86/simd/SIMD_F64.h +++ b/architecture/x86/simd/SIMD_F64.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_STDLIB_SIMD_F64_H -#define TOS_STDLIB_SIMD_F64_H +#ifndef COMS_STDLIB_SIMD_F64_H +#define COMS_STDLIB_SIMD_F64_H #include #include diff --git a/architecture/x86/simd/SIMD_I16.h b/architecture/x86/simd/SIMD_I16.h index 938d0c9..190b7f8 100644 --- a/architecture/x86/simd/SIMD_I16.h +++ b/architecture/x86/simd/SIMD_I16.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_TOS_STDLIB_SIMD_I16_H -#define TOS_TOS_STDLIB_SIMD_I16_H +#ifndef COMS_TOS_STDLIB_SIMD_I16_H +#define COMS_TOS_STDLIB_SIMD_I16_H #include #include @@ -242,30 +242,6 @@ inline int16_32 operator*(int16_32 a, int16_32 b) return simd; } -inline int16_8 operator/(int16_8 a, int16_8 b) -{ - int16_8 simd; - simd.s = _mm_div_epi16(a.s, b.s); - - return simd; -} - -inline int16_16 operator/(int16_16 a, int16_16 b) -{ - int16_16 simd; - simd.s = _mm256_div_epi16(a.s, b.s); - - return simd; -} - -inline int16_32 operator/(int16_32 a, int16_32 b) -{ - int16_32 simd; - simd.s = _mm512_div_epi16(a.s, b.s); - - return simd; -} - inline int16_8 operator^(int16_8 a, int16_8 b) { int16_8 simd; @@ -353,27 +329,6 @@ inline int16_32 &operator*=(int16_32 &a, int16_32 b) return a; } -inline int16_8 &operator/=(int16_8 &a, int16_8 b) -{ - a.s = (a / b).s; - - return a; -} - -inline int16_16 &operator/=(int16_16 &a, int16_16 b) -{ - a.s = (a / b).s; - - return a; -} - -inline int16_32 &operator/=(int16_32 &a, int16_32 b) -{ - a.s = (a / b).s; - - return a; -} - inline int16_8 &operator^=(int16_8 &a, int16_8 b) { a = a ^ b; diff --git a/architecture/x86/simd/SIMD_I32.h b/architecture/x86/simd/SIMD_I32.h index 5781a63..3633319 100644 --- a/architecture/x86/simd/SIMD_I32.h +++ b/architecture/x86/simd/SIMD_I32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_TOS_STDLIB_SIMD_I32_H -#define TOS_TOS_STDLIB_SIMD_I32_H +#ifndef COMS_TOS_STDLIB_SIMD_I32_H +#define COMS_TOS_STDLIB_SIMD_I32_H #include #include @@ -1582,25 +1582,11 @@ bool str_compare_avx512(const char* str1, const char* str2) { } void -endian_swap(const int* val, int* result, int32 size, int32 steps) +endian_swap(const int32* val, int32* result, int32 size, int32 steps) { int32 i = 0; - if (steps == 16) { - const __m512i mask_512 = _mm512_setr_epi8( - 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, - 19, 18, 17, 16, 23, 22, 21, 20, 27, 26, 25, 24, 31, 30, 29, 28, - 35, 34, 33, 32, 39, 38, 37, 36, 43, 42, 41, 40, 47, 46, 45, 44, - 51, 50, 49, 48, 55, 54, 53, 60, 59, 58, 57, 56, 64, 63, 62, 61 - ); - - for (i = 0; i <= size - steps; i += steps) { - __m512i vec = _mm512_load_si512((const __m512i *) (val + i)); - vec = _mm512_shuffle_epi8(vec, mask_512); - - _mm512_storeu_si512((__m512i *) (result + i), vec); - } - } else if (steps == 8) { + if (steps >= 8) { const __m256i mask_256 = _mm256_setr_epi8( 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, @@ -1639,6 +1625,122 @@ endian_swap(const int* val, int* result, int32 size, int32 steps) } } +void +endian_swap(const uint32* val, uint32* result, int32 size, int32 steps) +{ + int32 i = 0; + + if (steps >= 8) { + const __m256i mask_256 = _mm256_setr_epi8( + 3, 2, 1, 0, 7, 6, 5, 4, + 11, 10, 9, 8, 15, 14, 13, 12, + 19, 18, 17, 16, 23, 22, 21, 20, + 27, 26, 25, 24, 31, 30, 29, 28 + ); + + for (i = 0; i <= size - steps; i += steps) { + __m256i vec = _mm256_load_si256((const __m256i *) (val + i)); + vec = _mm256_shuffle_epi8(vec, mask_256); + + _mm256_storeu_si256((__m256i *) (result + i), vec); + } + } else if (steps == 4) { + const __m128i mask_128 = _mm_setr_epi8( + 3, 2, 1, 0, + 7, 6, 5, 4, + 11, 10, 9, 8, + 15, 14, 13, 12 + ); + + for (i = 0; i <= size - steps; i += steps) { + __m128i vec = _mm_load_si128((__m128i *) (const __m128i *) (val + i)); + vec = _mm_shuffle_epi8(vec, mask_128); + + _mm_storeu_si128((__m128i *) (result + i), vec); + } + } + + for (; i < size; ++i) { + uint32 v = ((uint32 *) val)[i]; + ((uint32 *) result)[i] = ((v << 24) + | ((v & 0xFF00) << 8) + | ((v >> 8) & 0xFF00) + | (v >> 24)); + } +} + +void endian_swap(const int16* val, int16* result, int32 size, int32 steps) +{ + int32 i = 0; + + if (steps >= 8) { + const __m256i mask_256 = _mm256_setr_epi8( + 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, + 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30 + ); + + for (i = 0; i <= size - steps; i += steps) { + __m256i vec = _mm256_load_si256((const __m256i *) (val + i)); + vec = _mm256_shuffle_epi8(vec, mask_256); + + _mm256_storeu_si256((__m256i *) (result + i), vec); + } + } else if (steps == 4) { + const __m128i mask_128 = _mm_setr_epi8( + 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14 + ); + + for (i = 0; i <= size - steps; i += steps) { + __m128i vec = _mm_load_si128((const __m128i *) (val + i)); + vec = _mm_shuffle_epi8(vec, mask_128); + + _mm_storeu_si128((__m128i *) (result + i), vec); + } + } + + // Handle remaining elements + for (; i < size; ++i) { + uint16 v = ((uint16 *) val)[i]; + ((int16 *) result)[i] = ((v << 8) | (v >> 8)); + } +} + +void endian_swap(const uint16* val, uint16* result, int32 size, int32 steps) +{ + int32 i = 0; + + if (steps >= 8) { + const __m256i mask_256 = _mm256_setr_epi8( + 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, + 17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30 + ); + + for (i = 0; i <= size - steps; i += steps) { + __m256i vec = _mm256_load_si256((const __m256i *) (val + i)); + vec = _mm256_shuffle_epi8(vec, mask_256); + + _mm256_storeu_si256((__m256i *) (result + i), vec); + } + } else if (steps == 4) { + const __m128i mask_128 = _mm_setr_epi8( + 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14 + ); + + for (i = 0; i <= size - steps; i += steps) { + __m128i vec = _mm_load_si128((const __m128i *) (val + i)); + vec = _mm_shuffle_epi8(vec, mask_128); + + _mm_storeu_si128((__m128i *) (result + i), vec); + } + } + + // Handle remaining elements + for (; i < size; ++i) { + uint16 v = ((uint16 *) val)[i]; + ((uint16 *) result)[i] = ((v << 8) | (v >> 8)); + } +} + #if _WIN32 || __LITTLE_ENDIAN__ #define SWAP_ENDIAN_LITTLE_SIMD(val, result, size, steps) ((void)0) #define SWAP_ENDIAN_BIG_SIMD(val, result, size, steps) endian_swap((val), (result), (size), (steps)) diff --git a/architecture/x86/simd/SIMD_I64.h b/architecture/x86/simd/SIMD_I64.h index 407b446..33bbc41 100644 --- a/architecture/x86/simd/SIMD_I64.h +++ b/architecture/x86/simd/SIMD_I64.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_TOS_STDLIB_SIMD_I64_H -#define TOS_TOS_STDLIB_SIMD_I64_H +#ifndef COMS_TOS_STDLIB_SIMD_I64_H +#define COMS_TOS_STDLIB_SIMD_I64_H #include #include diff --git a/architecture/x86/simd/SIMD_I8.h b/architecture/x86/simd/SIMD_I8.h index 31b1821..6885808 100644 --- a/architecture/x86/simd/SIMD_I8.h +++ b/architecture/x86/simd/SIMD_I8.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_TOS_STDLIB_SIMD_I8_H -#define TOS_TOS_STDLIB_SIMD_I8_H +#ifndef COMS_TOS_STDLIB_SIMD_I8_H +#define COMS_TOS_STDLIB_SIMD_I8_H #include #include @@ -278,30 +278,6 @@ inline int8_64 operator*(int8_64 a, int8_64 b) return simd; } -inline int8_16 operator/(int8_16 a, int8_16 b) -{ - int8_16 simd; - simd.s = _mm_div_epi8(a.s, b.s); - - return simd; -} - -inline int8_32 operator/(int8_32 a, int8_32 b) -{ - int8_32 simd; - simd.s = _mm256_div_epi8(a.s, b.s); - - return simd; -} - -inline int8_64 operator/(int8_64 a, int8_64 b) -{ - int8_64 simd; - simd.s = _mm512_div_epi8(a.s, b.s); - - return simd; -} - inline int8_16 operator^(int8_16 a, int8_16 b) { int8_16 simd; @@ -389,27 +365,6 @@ inline int8_64 &operator*=(int8_64 &a, int8_64 b) return a; } -inline int8_16 &operator/=(int8_16 &a, int8_16 b) -{ - a.s = (a / b).s; - - return a; -} - -inline int8_32 &operator/=(int8_32 &a, int8_32 b) -{ - a.s = (a / b).s; - - return a; -} - -inline int8_64 &operator/=(int8_64 &a, int8_64 b) -{ - a.s = (a / b).s; - - return a; -} - inline int8_16 &operator^=(int8_16 &a, int8_16 b) { a = a ^ b; diff --git a/architecture/x86/simd/SIMD_SVML.h b/architecture/x86/simd/SIMD_SVML.h index d76f262..022e658 100644 --- a/architecture/x86/simd/SIMD_SVML.h +++ b/architecture/x86/simd/SIMD_SVML.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_STDLIB_SIMD_SVML_H -#define TOS_STDLIB_SIMD_SVML_H +#ifndef COMS_STDLIB_SIMD_SVML_H +#define COMS_STDLIB_SIMD_SVML_H #include #include @@ -18,7 +18,7 @@ #include "math.h" inline __m128i _mm_div_epi32(__m128i a, __m128i b) { - alignas(16) int32_t a_array[4], b_array[4], result[4]; + alignas(16) int32 a_array[4], b_array[4], result[4]; _mm_storeu_si128((__m128i*) a_array, a); _mm_storeu_si128((__m128i*) b_array, b); @@ -31,7 +31,7 @@ } inline __m256i _mm256_div_epi32(__m256i a, __m256i b) { - alignas(32) int32_t a_array[8], b_array[8], result[8]; + alignas(32) int32 a_array[8], b_array[8], result[8]; _mm256_storeu_si256((__m256i*) a_array, a); _mm256_storeu_si256((__m256i*) b_array, b); @@ -44,7 +44,7 @@ } inline __m512i _mm512_div_epi32(__m512i a, __m512i b) { - alignas(64) int32_t a_array[16], b_array[16], result[16]; + alignas(64) int32 a_array[16], b_array[16], result[16]; _mm512_storeu_si512((__m512i*) a_array, a); _mm512_storeu_si512((__m512i*) b_array, b); diff --git a/architecture/x86/simd/utils/Utils.h b/architecture/x86/simd/utils/Utils.h index 5f6afa9..9554392 100644 --- a/architecture/x86/simd/utils/Utils.h +++ b/architecture/x86/simd/utils/Utils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ARCHITECTURE_X86_UTILS_H -#define TOS_ARCHITECTURE_X86_UTILS_H +#ifndef COMS_ARCHITECTURE_X86_UTILS_H +#define COMS_ARCHITECTURE_X86_UTILS_H #include #include "../../../../stdlib/Types.h" diff --git a/asset/Asset.h b/asset/Asset.h index 10af81d..3255887 100644 --- a/asset/Asset.h +++ b/asset/Asset.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ASSET_H -#define TOS_ASSET_H +#ifndef COMS_ASSET_H +#define COMS_ASSET_H #include "../stdlib/Types.h" #include "AssetType.h" diff --git a/asset/AssetArchive.h b/asset/AssetArchive.h index 4c792ae..2577673 100644 --- a/asset/AssetArchive.h +++ b/asset/AssetArchive.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ASSET_ARCHIVE_H -#define TOS_ASSET_ARCHIVE_H +#ifndef COMS_ASSET_ARCHIVE_H +#define COMS_ASSET_ARCHIVE_H #include "../stdlib/Types.h" #include "../utils/StringUtils.h" diff --git a/asset/AssetManagementSystem.h b/asset/AssetManagementSystem.h index 3fabeca..512a499 100644 --- a/asset/AssetManagementSystem.h +++ b/asset/AssetManagementSystem.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ASSET_MANAGEMENT_SYSTEM_H -#define TOS_ASSET_MANAGEMENT_SYSTEM_H +#ifndef COMS_ASSET_MANAGEMENT_SYSTEM_H +#define COMS_ASSET_MANAGEMENT_SYSTEM_H #include #include "../stdlib/Types.h" @@ -29,7 +29,7 @@ struct AssetComponent { uint64 asset_count; // @question Do we want to add a mutex to assets. This way we don't have to lock the entire ams. - pthread_mutex_t mutex; + coms_pthread_mutex_t mutex; }; struct AssetManagementSystem { @@ -55,7 +55,7 @@ void ams_component_create(AssetComponent* ac, BufferMemory* buf, int32 chunk_siz LOG_1("Create AMS Component for %n assets and %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_UINT32, &chunk_size}}); chunk_init(&ac->asset_memory, buf, count, chunk_size, 64); - pthread_mutex_init(&ac->mutex, NULL); + coms_pthread_mutex_init(&ac->mutex, NULL); } inline @@ -71,13 +71,13 @@ void ams_component_create(AssetComponent* ac, byte* buf, int32 chunk_size, int32 ac->asset_memory.memory = buf; ac->asset_memory.free = (uint64 *) (ac->asset_memory.memory + ac->asset_memory.chunk_size * count); - pthread_mutex_init(&ac->mutex, NULL); + coms_pthread_mutex_init(&ac->mutex, NULL); } inline void ams_component_free(AssetComponent* ac) { - pthread_mutex_destroy(&ac->mutex); + coms_pthread_mutex_destroy(&ac->mutex); } inline @@ -400,15 +400,15 @@ Asset* thrd_ams_reserve_asset(AssetManagementSystem* ams, byte type, const char* AssetComponent* ac = &ams->asset_components[type]; uint16 elements = ams_calculate_chunks(ac, size, overhead); - pthread_mutex_lock(&ams->asset_components[type].mutex); + coms_pthread_mutex_lock(&ams->asset_components[type].mutex); int32 free_data = chunk_reserve(&ac->asset_memory, elements); if (free_data < 0) { - pthread_mutex_unlock(&ams->asset_components[type].mutex); + coms_pthread_mutex_unlock(&ams->asset_components[type].mutex); ASSERT_SIMPLE(free_data >= 0); return NULL; } - pthread_mutex_unlock(&ams->asset_components[type].mutex); + coms_pthread_mutex_unlock(&ams->asset_components[type].mutex); byte* asset_data = chunk_get_element(&ac->asset_memory, free_data, true); @@ -514,15 +514,15 @@ Asset* thrd_ams_insert_asset(AssetManagementSystem* ams, Asset* asset_temp, cons { AssetComponent* ac = &ams->asset_components[asset_temp->component_id]; - pthread_mutex_lock(&ams->asset_components[asset_temp->component_id].mutex); + coms_pthread_mutex_lock(&ams->asset_components[asset_temp->component_id].mutex); int32 free_data = chunk_reserve(&ac->asset_memory, asset_temp->size); if (free_data < 0) { - pthread_mutex_unlock(&ams->asset_components[asset_temp->component_id].mutex); + coms_pthread_mutex_unlock(&ams->asset_components[asset_temp->component_id].mutex); ASSERT_SIMPLE(free_data >= 0); return NULL; } - pthread_mutex_unlock(&ams->asset_components[asset_temp->component_id].mutex); + coms_pthread_mutex_unlock(&ams->asset_components[asset_temp->component_id].mutex); byte* asset_data = chunk_get_element(&ac->asset_memory, free_data); memcpy(asset_data, asset_temp->self, sizeof(Asset)); diff --git a/asset/AssetType.h b/asset/AssetType.h index 5377362..40f43eb 100644 --- a/asset/AssetType.h +++ b/asset/AssetType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ASSET_TYPE_H -#define TOS_ASSET_TYPE_H +#ifndef COMS_ASSET_TYPE_H +#define COMS_ASSET_TYPE_H enum AssetType : byte { ASSET_TYPE_GENERAL, diff --git a/audio/Audio.cpp b/audio/Audio.cpp index bc5ba1f..f5fe72e 100644 --- a/audio/Audio.cpp +++ b/audio/Audio.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_AUDIO_C -#define TOS_AUDIO_C +#ifndef COMS_AUDIO_C +#define COMS_AUDIO_C #include "../utils/StringUtils.h" #include "../memory/RingMemory.h" diff --git a/audio/Audio.h b/audio/Audio.h index cb0a016..56b65cb 100644 --- a/audio/Audio.h +++ b/audio/Audio.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_AUDIO_H -#define TOS_AUDIO_H +#ifndef COMS_AUDIO_H +#define COMS_AUDIO_H #include "../stdlib/Types.h" diff --git a/audio/AudioMixer.h b/audio/AudioMixer.h index 6df8d6c..c8ca6ed 100644 --- a/audio/AudioMixer.h +++ b/audio/AudioMixer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_AUDIO_MIXER_H -#define TOS_AUDIO_MIXER_H +#ifndef COMS_AUDIO_MIXER_H +#define COMS_AUDIO_MIXER_H #include "../stdlib/Types.h" #include "Audio.h" @@ -71,7 +71,7 @@ enum AudioMixerState { struct AudioMixer { ChunkMemory audio_instances; AudioMixerState state_old; - atomic_64 int32 state_new; + alignas(8) atomic_64 int32 state_new; uint64 effect; diff --git a/audio/AudioSetting.h b/audio/AudioSetting.h index 96f2a87..3fcf51e 100644 --- a/audio/AudioSetting.h +++ b/audio/AudioSetting.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_AUDIO_SETTING_H -#define TOS_AUDIO_SETTING_H +#ifndef COMS_AUDIO_SETTING_H +#define COMS_AUDIO_SETTING_H #include "../stdlib/Types.h" #include "../math/matrix/MatrixFloat32.h" diff --git a/audio/Qoa.h b/audio/Qoa.h index 39492e7..78ac721 100644 --- a/audio/Qoa.h +++ b/audio/Qoa.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_AUDIO_QOA_H -#define TOS_AUDIO_QOA_H +#ifndef COMS_AUDIO_QOA_H +#define COMS_AUDIO_QOA_H #include "../stdlib/Types.h" #include "../utils/EndianUtils.h" diff --git a/audio/QoaSimd.h b/audio/QoaSimd.h index 00668df..d6d0a14 100644 --- a/audio/QoaSimd.h +++ b/audio/QoaSimd.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_AUDIO_QOA_H -#define TOS_AUDIO_QOA_H +#ifndef COMS_AUDIO_QOA_H +#define COMS_AUDIO_QOA_H #include "../stdlib/Types.h" #include "../utils/EndianUtils.h" diff --git a/audio/Wav.h b/audio/Wav.h index b5661ac..36d6bad 100644 --- a/audio/Wav.h +++ b/audio/Wav.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_AUDIO_WAV_H -#define TOS_AUDIO_WAV_H +#ifndef COMS_AUDIO_WAV_H +#define COMS_AUDIO_WAV_H #include #include "../stdlib/Types.h" diff --git a/auth/Auth.h b/auth/Auth.h index 54913ba..20bb3c6 100644 --- a/auth/Auth.h +++ b/auth/Auth.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_AUTH_H -#define TOS_AUTH_H +#ifndef COMS_AUTH_H +#define COMS_AUTH_H #include #include diff --git a/camera/Camera.h b/camera/Camera.h index 95a7666..d2e0a92 100644 --- a/camera/Camera.h +++ b/camera/Camera.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_CAMERA_H -#define TOS_CAMERA_H +#ifndef COMS_CAMERA_H +#define COMS_CAMERA_H #include "../stdlib/Types.h" #include "../math/matrix/MatrixFloat32.h" diff --git a/camera/CameraMovement.h b/camera/CameraMovement.h index 65885e1..e4f30a8 100644 --- a/camera/CameraMovement.h +++ b/camera/CameraMovement.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_CAMERA_MOVEMENT_H -#define TOS_CAMERA_MOVEMENT_H +#ifndef COMS_CAMERA_MOVEMENT_H +#define COMS_CAMERA_MOVEMENT_H enum CameraMovement { CAMERA_MOVEMENT_NONE, diff --git a/color/ColorVisionDeficiency.h b/color/ColorVisionDeficiency.h index 7c164ef..2e2eae8 100644 --- a/color/ColorVisionDeficiency.h +++ b/color/ColorVisionDeficiency.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COLOR_VISION_DEFICIENCY_H -#define TOS_COLOR_VISION_DEFICIENCY_H +#ifndef COMS_COLOR_VISION_DEFICIENCY_H +#define COMS_COLOR_VISION_DEFICIENCY_H #include "../stdlib/Types.h" diff --git a/command/AppCmdBuffer.cpp b/command/AppCmdBuffer.cpp index 9e932f8..3a22033 100644 --- a/command/AppCmdBuffer.cpp +++ b/command/AppCmdBuffer.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_APP_COMMAND_BUFFER_C -#define TOS_APP_COMMAND_BUFFER_C +#ifndef COMS_APP_COMMAND_BUFFER_C +#define COMS_APP_COMMAND_BUFFER_C /** * The AppCmdBuffer by itself doesn't do much, it simply takes in commands and executes them. @@ -38,7 +38,7 @@ inline void cmd_buffer_create(AppCmdBuffer* cb, BufferMemory* buf, int32 commands_count) { chunk_init(&cb->commands, buf, commands_count, sizeof(Command), 64); - pthread_mutex_init(&cb->mutex, NULL); + coms_pthread_mutex_init(&cb->mutex, NULL); LOG_1("Created AppCmdBuffer: %n B", {{LOG_DATA_UINT64, &cb->commands.size}}); } @@ -181,10 +181,10 @@ Asset* cmd_font_load_async(AppCmdBuffer* __restrict cb, Command* __restrict cmd) inline void thrd_cmd_insert(AppCmdBuffer* __restrict cb, Command* __restrict cmd_temp) { - pthread_mutex_lock(&cb->mutex); + coms_pthread_mutex_lock(&cb->mutex); int32 index = chunk_reserve(&cb->commands, 1); if (index < 0) { - pthread_mutex_unlock(&cb->mutex); + coms_pthread_mutex_unlock(&cb->mutex); ASSERT_SIMPLE(false); return; @@ -196,7 +196,7 @@ void thrd_cmd_insert(AppCmdBuffer* __restrict cb, Command* __restrict cmd_temp) Command* cmd = (Command *) chunk_get_element(&cb->commands, index); memcpy(cmd, cmd_temp, sizeof(Command)); - pthread_mutex_unlock(&cb->mutex); + coms_pthread_mutex_unlock(&cb->mutex); } inline @@ -697,9 +697,9 @@ void cmd_iterate(AppCmdBuffer* cb) // This shouldn't happen since the command buffer shouldn't fill up in just 1-3 frames void thrd_cmd_iterate(AppCmdBuffer* cb) { - pthread_mutex_lock(&cb->mutex); + coms_pthread_mutex_lock(&cb->mutex); cmd_iterate(cb); - pthread_mutex_unlock(&cb->mutex); + coms_pthread_mutex_unlock(&cb->mutex); } #endif \ No newline at end of file diff --git a/command/AppCmdBuffer.h b/command/AppCmdBuffer.h index 0571015..79da41f 100644 --- a/command/AppCmdBuffer.h +++ b/command/AppCmdBuffer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_APP_COMMAND_BUFFER_H -#define TOS_APP_COMMAND_BUFFER_H +#ifndef COMS_APP_COMMAND_BUFFER_H +#define COMS_APP_COMMAND_BUFFER_H #include "../stdlib/Types.h" #include "../memory/ChunkMemory.h" @@ -29,7 +29,7 @@ struct AppCmdBuffer { ChunkMemory commands; int32 last_element; - pthread_mutex_t mutex; + coms_pthread_mutex_t mutex; // Application data for cmd access // The list below depends on what kind of systems our command buffer needs access to diff --git a/command/Command.h b/command/Command.h index 54cbd21..f11efb0 100644 --- a/command/Command.h +++ b/command/Command.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COMMAND_H -#define TOS_COMMAND_H +#ifndef COMS_COMMAND_H +#define COMS_COMMAND_H #include "../stdlib/Types.h" diff --git a/compiler/CompilerUtils.h b/compiler/CompilerUtils.h index aec3403..931fc58 100644 --- a/compiler/CompilerUtils.h +++ b/compiler/CompilerUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COMPILER_COMPILER_UTILS_H -#define TOS_COMPILER_COMPILER_UTILS_H +#ifndef COMS_COMPILER_COMPILER_UTILS_H +#define COMS_COMPILER_COMPILER_UTILS_H #include "../utils/TestUtils.h" diff --git a/compiler/gcc/Atomic.h b/compiler/gcc/Atomic.h index b18e3a8..61a2705 100644 --- a/compiler/gcc/Atomic.h +++ b/compiler/gcc/Atomic.h @@ -6,12 +6,14 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COMPILER_GCC_ATOMIC_H -#define TOS_COMPILER_GCC_ATOMIC_H +#ifndef COMS_COMPILER_GCC_ATOMIC_H +#define COMS_COMPILER_GCC_ATOMIC_H #include "../../stdlib/Types.h" #include "CompilerUtils.h" -#include + +typedef union { f32 f; int32 l; } _atomic_32; +typedef union { f64 f; int64 l; } _atomic_64; FORCE_INLINE void atomic_set_relaxed(void** target, void* value) noexcept { __atomic_store_n(target, value, __ATOMIC_RELAXED); } FORCE_INLINE void* atomic_get_relaxed(void** target) noexcept { return __atomic_load_n(target, __ATOMIC_RELAXED); } @@ -43,8 +45,32 @@ FORCE_INLINE void atomic_add_relaxed(volatile int32* value, int32 increment) noe FORCE_INLINE void atomic_sub_relaxed(volatile int32* value, int32 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_RELAXED); } FORCE_INLINE void atomic_add_relaxed(volatile int64* value, int64 increment) noexcept { __atomic_add_fetch(value, increment, __ATOMIC_RELAXED); } FORCE_INLINE void atomic_sub_relaxed(volatile int64* value, int64 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_RELAXED); } -FORCE_INLINE f32 atomic_compare_exchange_weak_relaxed(volatile f32* value, f32* expected, f32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return *expected; } -FORCE_INLINE f64 atomic_compare_exchange_weak_relaxed(volatile f64* value, f64* expected, f64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return *expected; } +FORCE_INLINE f32 atomic_compare_exchange_weak_relaxed(volatile f32* value, f32* expected, f32 desired) noexcept { + volatile _atomic_32* value_as_union = (volatile _atomic_32*)value; + _atomic_32* expected_as_union = (_atomic_32*)expected; + _atomic_32 desired_as_union; + desired_as_union.f = desired; + + __atomic_compare_exchange_n( + &value_as_union->l, &expected_as_union->l, desired_as_union.l, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED + ); + + return expected_as_union->f; +} +FORCE_INLINE f64 atomic_compare_exchange_weak_relaxed(volatile f64* value, f64* expected, f64 desired) noexcept { + volatile _atomic_64* value_as_union = (volatile _atomic_64*)value; + _atomic_64* expected_as_union = (_atomic_64*)expected; + _atomic_64 desired_as_union; + desired_as_union.f = desired; + + __atomic_compare_exchange_n( + &value_as_union->l, &expected_as_union->l, desired_as_union.l, 0, + __ATOMIC_RELAXED, __ATOMIC_RELAXED + ); + + return expected_as_union->f; +} FORCE_INLINE int32 atomic_compare_exchange_weak_relaxed(volatile int32* value, int32* expected, int32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return *expected; } FORCE_INLINE int64 atomic_compare_exchange_weak_relaxed(volatile int64* value, int64* expected, int64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return *expected; } FORCE_INLINE int8 atomic_fetch_add_relaxed(volatile int8* value, int8 operand) noexcept { return __atomic_add_fetch(value, operand, __ATOMIC_RELAXED); } @@ -110,12 +136,7 @@ FORCE_INLINE void atomic_or_relaxed(volatile int32* value, int32 mask) noexcept FORCE_INLINE void atomic_or_relaxed(volatile uint64* value, uint64 mask) noexcept { __atomic_fetch_or(value, mask, __ATOMIC_RELAXED); } FORCE_INLINE void atomic_or_relaxed(volatile int64* value, int64 mask) noexcept { __atomic_fetch_or(value, mask, __ATOMIC_RELAXED); } -FORCE_INLINE void atomic_set_acquire(void** target, void* value) noexcept { __atomic_store_n(target, value, __ATOMIC_ACQUIRE); } FORCE_INLINE void* atomic_get_acquire(void** target) noexcept { return __atomic_load_n(target, __ATOMIC_ACQUIRE); } -FORCE_INLINE void atomic_set_acquire(volatile int8* value, int8 new_value) noexcept { __atomic_store_n(value, new_value, __ATOMIC_ACQUIRE); } -FORCE_INLINE void atomic_set_acquire(volatile int16* value, int16 new_value) noexcept { __atomic_store_n(value, new_value, __ATOMIC_ACQUIRE); } -FORCE_INLINE void atomic_set_acquire(volatile int32* value, int32 new_value) noexcept { __atomic_store_n(value, new_value, __ATOMIC_ACQUIRE); } -FORCE_INLINE void atomic_set_acquire(volatile int64* value, int64 new_value) noexcept { __atomic_store_n(value, new_value, __ATOMIC_ACQUIRE); } FORCE_INLINE int8 atomic_fetch_set_acquire(volatile int8* value, int8 new_value) noexcept { return __atomic_exchange_n(value, new_value, __ATOMIC_ACQUIRE); } FORCE_INLINE int16 atomic_fetch_set_acquire(volatile int16* value, int16 new_value) noexcept { return __atomic_exchange_n(value, new_value, __ATOMIC_ACQUIRE); } FORCE_INLINE int32 atomic_fetch_set_acquire(volatile int32* value, int32 new_value) noexcept { return __atomic_exchange_n(value, new_value, __ATOMIC_ACQUIRE); } @@ -140,8 +161,32 @@ FORCE_INLINE void atomic_add_acquire(volatile int32* value, int32 increment) noe FORCE_INLINE void atomic_sub_acquire(volatile int32* value, int32 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_ACQUIRE); } FORCE_INLINE void atomic_add_acquire(volatile int64* value, int64 increment) noexcept { __atomic_add_fetch(value, increment, __ATOMIC_ACQUIRE); } FORCE_INLINE void atomic_sub_acquire(volatile int64* value, int64 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_ACQUIRE); } -FORCE_INLINE f32 atomic_compare_exchange_weak_acquire(volatile f32* value, f32* expected, f32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return *expected; } -FORCE_INLINE f64 atomic_compare_exchange_weak_acquire(volatile f64* value, f64* expected, f64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return *expected; } +FORCE_INLINE f32 atomic_compare_exchange_weak_acquire(volatile f32* value, f32* expected, f32 desired) noexcept { + volatile _atomic_32* value_as_union = (volatile _atomic_32*)value; + _atomic_32* expected_as_union = (_atomic_32*)expected; + _atomic_32 desired_as_union; + desired_as_union.f = desired; + + __atomic_compare_exchange_n( + &value_as_union->l, &expected_as_union->l, desired_as_union.l, 0, + __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE + ); + + return expected_as_union->f; +} +FORCE_INLINE f64 atomic_compare_exchange_weak_acquire(volatile f64* value, f64* expected, f64 desired) noexcept { + volatile _atomic_64* value_as_union = (volatile _atomic_64*)value; + _atomic_64* expected_as_union = (_atomic_64*)expected; + _atomic_64 desired_as_union; + desired_as_union.f = desired; + + __atomic_compare_exchange_n( + &value_as_union->l, &expected_as_union->l, desired_as_union.l, 0, + __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE + ); + + return expected_as_union->f; +} FORCE_INLINE int32 atomic_compare_exchange_weak_acquire(volatile int32* value, int32* expected, int32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return *expected; } FORCE_INLINE int64 atomic_compare_exchange_weak_acquire(volatile int64* value, int64* expected, int64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return *expected; } FORCE_INLINE int8 atomic_fetch_add_acquire(volatile int8* value, int8 operand) noexcept { return __atomic_add_fetch(value, operand, __ATOMIC_ACQUIRE); } @@ -237,8 +282,32 @@ FORCE_INLINE void atomic_add_release(volatile int32* value, int32 increment) noe FORCE_INLINE void atomic_sub_release(volatile int32* value, int32 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_RELEASE); } FORCE_INLINE void atomic_add_release(volatile int64* value, int64 increment) noexcept { __atomic_add_fetch(value, increment, __ATOMIC_RELEASE); } FORCE_INLINE void atomic_sub_release(volatile int64* value, int64 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_RELEASE); } -FORCE_INLINE f32 atomic_compare_exchange_weak_release(volatile f32* value, f32* expected, f32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELEASE, __ATOMIC_RELEASE); return *expected; } -FORCE_INLINE f64 atomic_compare_exchange_weak_release(volatile f64* value, f64* expected, f64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELEASE, __ATOMIC_RELEASE); return *expected; } +FORCE_INLINE f32 atomic_compare_exchange_weak_release(volatile f32* value, f32* expected, f32 desired) noexcept { + volatile _atomic_32* value_as_union = (volatile _atomic_32*)value; + _atomic_32* expected_as_union = (_atomic_32*)expected; + _atomic_32 desired_as_union; + desired_as_union.f = desired; + + __atomic_compare_exchange_n( + &value_as_union->l, &expected_as_union->l, desired_as_union.l, 0, + __ATOMIC_RELEASE, __ATOMIC_RELEASE + ); + + return expected_as_union->f; +} +FORCE_INLINE f64 atomic_compare_exchange_weak_release(volatile f64* value, f64* expected, f64 desired) noexcept { + volatile _atomic_64* value_as_union = (volatile _atomic_64*)value; + _atomic_64* expected_as_union = (_atomic_64*)expected; + _atomic_64 desired_as_union; + desired_as_union.f = desired; + + __atomic_compare_exchange_n( + &value_as_union->l, &expected_as_union->l, desired_as_union.l, 0, + __ATOMIC_RELEASE, __ATOMIC_RELEASE + ); + + return expected_as_union->f; +} FORCE_INLINE int32 atomic_compare_exchange_weak_release(volatile int32* value, int32* expected, int32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELEASE, __ATOMIC_RELEASE); return *expected; } FORCE_INLINE int64 atomic_compare_exchange_weak_release(volatile int64* value, int64* expected, int64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELEASE, __ATOMIC_RELEASE); return *expected; } FORCE_INLINE int8 atomic_fetch_add_release(volatile int8* value, int8 operand) noexcept { return __atomic_add_fetch(value, operand, __ATOMIC_RELEASE); } @@ -334,8 +403,32 @@ FORCE_INLINE void atomic_add_acquire_release(volatile int32* value, int32 increm FORCE_INLINE void atomic_sub_acquire_release(volatile int32* value, int32 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_SEQ_CST); } FORCE_INLINE void atomic_add_acquire_release(volatile int64* value, int64 increment) noexcept { __atomic_add_fetch(value, increment, __ATOMIC_SEQ_CST); } FORCE_INLINE void atomic_sub_acquire_release(volatile int64* value, int64 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_SEQ_CST); } -FORCE_INLINE f32 atomic_compare_exchange_weak_acquire_release(volatile f32* value, f32* expected, f32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return *expected; } -FORCE_INLINE f64 atomic_compare_exchange_weak_acquire_release(volatile f64* value, f64* expected, f64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return *expected; } +FORCE_INLINE f32 atomic_compare_exchange_weak_acquire_release(volatile f32* value, f32* expected, f32 desired) noexcept { + volatile _atomic_32* value_as_union = (volatile _atomic_32*)value; + _atomic_32* expected_as_union = (_atomic_32*)expected; + _atomic_32 desired_as_union; + desired_as_union.f = desired; + + __atomic_compare_exchange_n( + &value_as_union->l, &expected_as_union->l, desired_as_union.l, 0, + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST + ); + + return expected_as_union->f; +} +FORCE_INLINE f64 atomic_compare_exchange_weak_acquire_release(volatile f64* value, f64* expected, f64 desired) noexcept { + volatile _atomic_64* value_as_union = (volatile _atomic_64*)value; + _atomic_64* expected_as_union = (_atomic_64*)expected; + _atomic_64 desired_as_union; + desired_as_union.f = desired; + + __atomic_compare_exchange_n( + &value_as_union->l, &expected_as_union->l, desired_as_union.l, 0, + __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST + ); + + return expected_as_union->f; +} FORCE_INLINE int32 atomic_compare_exchange_weak_acquire_release(volatile int32* value, int32* expected, int32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return *expected; } FORCE_INLINE int64 atomic_compare_exchange_weak_acquire_release(volatile int64* value, int64* expected, int64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return *expected; } FORCE_INLINE int8 atomic_fetch_add_acquire_release(volatile int8* value, int8 operand) noexcept { return __atomic_add_fetch(value, operand, __ATOMIC_SEQ_CST); } @@ -409,5 +502,4 @@ FORCE_INLINE void atomic_or_acquire_release(volatile int64* value, int64 mask) n // These are much faster and could accomplish what you are doing #define atomic_fence_release() __atomic_thread_fence(__ATOMIC_RELEASE) - #endif \ No newline at end of file diff --git a/compiler/gcc/CompilerUtils.h b/compiler/gcc/CompilerUtils.h index 0597e84..ec73859 100644 --- a/compiler/gcc/CompilerUtils.h +++ b/compiler/gcc/CompilerUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COMPILER_GCC_COMPILER_UTILS_H -#define TOS_COMPILER_GCC_COMPILER_UTILS_H +#ifndef COMS_COMPILER_GCC_COMPILER_UTILS_H +#define COMS_COMPILER_GCC_COMPILER_UTILS_H #include "../../utils/TestUtils.h" @@ -22,10 +22,10 @@ #define UNREACHABLE() __builtin_unreachable() #endif -#define FORCE_INLINE __attribute__((always_inline)) +#define FORCE_INLINE __attribute__((always_inline)) inline #include -#define compiler_debug_print(message) while (*message++) { write(STDOUT_FILENO, (message), 1); } +#define compiler_debug_print(message) ({ const char* message_temp = message; while (*message_temp) { write(STDOUT_FILENO, (message_temp++), 1); } }) #define compiler_popcount_32(data) __builtin_popcount((data)) #define compiler_popcount_64(data) __builtin_popcountl((data)) @@ -42,7 +42,7 @@ int32 compiler_find_first_bit_r2l(uint64 mask) noexcept { } #if __LITTLE_ENDIAN__ - return return 63 - __builtin_clzll(mask); + return 63 - __builtin_clzll(mask); #else return __builtin_ctzll(mask); #endif @@ -66,7 +66,7 @@ int32 compiler_find_first_bit_l2r(uint64 mask) noexcept { } #if __LITTLE_ENDIAN__ - return return 63 - __builtin_clzll(mask); + return 63 - __builtin_clzll(mask); #else return __builtin_ctzll(mask); #endif diff --git a/compiler/msvc/CompilerUtils.h b/compiler/msvc/CompilerUtils.h index 4d332c6..4094f8b 100644 --- a/compiler/msvc/CompilerUtils.h +++ b/compiler/msvc/CompilerUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COMPILER_MSVC_COMPILER_UTILS_H -#define TOS_COMPILER_MSVC_COMPILER_UTILS_H +#ifndef COMS_COMPILER_MSVC_COMPILER_UTILS_H +#define COMS_COMPILER_MSVC_COMPILER_UTILS_H #include "../../utils/TestUtils.h" #include diff --git a/compression/Huffman.h b/compression/Huffman.h index 0de0473..ef03353 100644 --- a/compression/Huffman.h +++ b/compression/Huffman.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COMPRESSION_HUFFMAN_H -#define TOS_COMPRESSION_HUFFMAN_H +#ifndef COMS_COMPRESSION_HUFFMAN_H +#define COMS_COMPRESSION_HUFFMAN_H #include #include @@ -146,7 +146,7 @@ inline void huffman_dump(const Huffman* hf, byte* out) { // dump the char -> code relations as relative indices - for (int32 i = 0; i < ARRAY_COUNT(hf->code); ++i) { + for (uint32 i = 0; i < ARRAY_COUNT(hf->code); ++i) { *((int64 *) out) = hf->code[i] ? SWAP_ENDIAN_LITTLE(hf->code[i] - hf->buffer) : SWAP_ENDIAN_LITTLE(-1); @@ -162,7 +162,7 @@ inline void huffman_load(Huffman* hf, const byte* in) { // load the char -> code relations and convert relative indices to pointers - for (int32 i = 0; i < ARRAY_COUNT(hf->code); ++i) { + for (uint32 i = 0; i < ARRAY_COUNT(hf->code); ++i) { int64 value = SWAP_ENDIAN_LITTLE(*((int64 *) in)); in += sizeof(value); diff --git a/compression/LZP.h b/compression/LZP.h index 19b13cb..de3fa03 100644 --- a/compression/LZP.h +++ b/compression/LZP.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COMPRESSION_LZP_H -#define TOS_COMPRESSION_LZP_H +#ifndef COMS_COMPRESSION_LZP_H +#define COMS_COMPRESSION_LZP_H #include #include diff --git a/compression/RLE.h b/compression/RLE.h index ceacd5f..4d6f9af 100644 --- a/compression/RLE.h +++ b/compression/RLE.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_COMPRESSION_RLE_H -#define TOS_COMPRESSION_RLE_H +#ifndef COMS_COMPRESSION_RLE_H +#define COMS_COMPRESSION_RLE_H #include #include diff --git a/database/Database.h b/database/Database.h index 9b442c6..3506570 100644 --- a/database/Database.h +++ b/database/Database.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_DATABASE_H -#define TOS_DATABASE_H +#ifndef COMS_DATABASE_H +#define COMS_DATABASE_H #include "../stdlib/Types.h" #include "../../EngineDependencies/sqlite/src/sqlite3.h" diff --git a/database/DatabaseConnection.h b/database/DatabaseConnection.h index 3de6947..92ffdf0 100644 --- a/database/DatabaseConnection.h +++ b/database/DatabaseConnection.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_DATABASE_CONNECTION_H -#define TOS_DATABASE_CONNECTION_H +#ifndef COMS_DATABASE_CONNECTION_H +#define COMS_DATABASE_CONNECTION_H #include "../stdlib/Types.h" #include "../../EngineDependencies/sqlite/src/sqlite3.h" diff --git a/database/DatabaseType.h b/database/DatabaseType.h index 3a51b03..839e5b5 100644 --- a/database/DatabaseType.h +++ b/database/DatabaseType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_DATABASE_TYPE_H -#define TOS_DATABASE_TYPE_H +#ifndef COMS_DATABASE_TYPE_H +#define COMS_DATABASE_TYPE_H enum DatabaseType { DB_TYPE_SQLITE, diff --git a/encryption/CeasarEncryption.h b/encryption/CeasarEncryption.h index 0aaf920..33eb910 100644 --- a/encryption/CeasarEncryption.h +++ b/encryption/CeasarEncryption.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ENCRYPTION_CEASAR_H -#define TOS_ENCRYPTION_CEASAR_H +#ifndef COMS_ENCRYPTION_CEASAR_H +#define COMS_ENCRYPTION_CEASAR_H #include "../stdlib/Types.h" diff --git a/encryption/XorEncryption.h b/encryption/XorEncryption.h index e578d0c..1e4e25c 100644 --- a/encryption/XorEncryption.h +++ b/encryption/XorEncryption.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ENCRYPTION_XOR_H -#define TOS_ENCRYPTION_XOR_H +#ifndef COMS_ENCRYPTION_XOR_H +#define COMS_ENCRYPTION_XOR_H #include "../stdlib/Types.h" diff --git a/entity/AnimationEntityComponent.h b/entity/AnimationEntityComponent.h index 484a5fc..59b6c35 100644 --- a/entity/AnimationEntityComponent.h +++ b/entity/AnimationEntityComponent.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ANIMATION_ENTITY_H -#define TOS_ANIMATION_ENTITY_H +#ifndef COMS_ANIMATION_ENTITY_H +#define COMS_ANIMATION_ENTITY_H #include "../stdlib/Types.h" #include "../animation/AnimationEaseType.h" diff --git a/entity/CursorEntity.h b/entity/CursorEntity.h index e00a48a..36d6903 100644 --- a/entity/CursorEntity.h +++ b/entity/CursorEntity.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ENTITY_CURSOR_H -#define TOS_ENTITY_CURSOR_H +#ifndef COMS_ENTITY_CURSOR_H +#define COMS_ENTITY_CURSOR_H #include "Entity.h" #include "AnimationEntityComponent.h" diff --git a/entity/Entity.h b/entity/Entity.h index 6e7ed66..3a2f9c5 100644 --- a/entity/Entity.h +++ b/entity/Entity.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ENTITY_H -#define TOS_ENTITY_H +#ifndef COMS_ENTITY_H +#define COMS_ENTITY_H #include "../stdlib/Types.h" #include "../stdlib/HashMap.h" diff --git a/entity/EntityComponentSystem.h b/entity/EntityComponentSystem.h index 720edfa..152c203 100644 --- a/entity/EntityComponentSystem.h +++ b/entity/EntityComponentSystem.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ENTITY_COMPONENT_SYSTEM_H -#define TOS_ENTITY_COMPONENT_SYSTEM_H +#ifndef COMS_ENTITY_COMPONENT_SYSTEM_H +#define COMS_ENTITY_COMPONENT_SYSTEM_H #include #include "../stdlib/Types.h" @@ -34,8 +34,8 @@ struct EntityComponentSystem { uint64 component_count; // @question Do we want to add a mutex to assets. This way we don't have to lock the entire ams. - pthread_mutex_t* entity_mutex; - pthread_mutex_t* component_mutex; + coms_pthread_mutex_t* entity_mutex; + coms_pthread_mutex_t* component_mutex; }; inline @@ -54,7 +54,7 @@ void ecs_entity_type_create(ChunkMemory* ec, BufferMemory* buf, int32 chunk_size ASSERT_SIMPLE(chunk_size); chunk_init(ec, buf, count, chunk_size, 64); - //pthread_mutex_init(&ec->mutex, NULL); + //coms_pthread_mutex_init(&ec->mutex, NULL); } inline @@ -63,7 +63,7 @@ void ecs_component_type_create(ChunkMemory* ec, BufferMemory* buf, int32 chunk_s ASSERT_SIMPLE(chunk_size); chunk_init(ec, buf, count, chunk_size, 64); - //pthread_mutex_init(&ec->mutex, NULL); + //coms_pthread_mutex_init(&ec->mutex, NULL); } Entity* ecs_get_entity(EntityComponentSystem* ecs, int32 entity_id) diff --git a/entity/EntitySize.h b/entity/EntitySize.h index dfe4819..0684ab0 100644 --- a/entity/EntitySize.h +++ b/entity/EntitySize.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_ENTITY_SIZE_H -#define TOS_ENTITY_SIZE_H +#ifndef COMS_ENTITY_SIZE_H +#define COMS_ENTITY_SIZE_H enum EntitySize { ENTITY_SIZE_32, diff --git a/environment/Globe.h b/environment/Globe.h index 885f055..7a15975 100644 --- a/environment/Globe.h +++ b/environment/Globe.h @@ -1,5 +1,5 @@ -#ifndef TOS_ENVIRONMENT_GLOBE_H -#define TOS_ENVIRONMENT_GLOBE_H +#ifndef COMS_ENVIRONMENT_GLOBE_H +#define COMS_ENVIRONMENT_GLOBE_H #include "../stdlib/Types.h" #include diff --git a/environment/Universe.h b/environment/Universe.h index d629cd4..f6b79a9 100644 --- a/environment/Universe.h +++ b/environment/Universe.h @@ -1,5 +1,5 @@ -#ifndef TOS_ENVIRONMENT_UNIVERSE_H -#define TOS_ENVIRONMENT_UNIVERSE_H +#ifndef COMS_ENVIRONMENT_UNIVERSE_H +#define COMS_ENVIRONMENT_UNIVERSE_H #include "../stdlib/Types.h" diff --git a/error/HammingCodes.h b/error/HammingCodes.h index 4eacfc5..198431b 100644 --- a/error/HammingCodes.h +++ b/error/HammingCodes.h @@ -1,5 +1,5 @@ -#ifndef TOS_ERROR_HAMMING_CODES_H -#define TOS_ERROR_HAMMING_CODES_H +#ifndef COMS_ERROR_HAMMING_CODES_H +#define COMS_ERROR_HAMMING_CODES_H #include "../stdlib/Types.h" #include "../utils/BitUtils.h" diff --git a/font/Font.h b/font/Font.h index 1af9cac..4d8a44f 100644 --- a/font/Font.h +++ b/font/Font.h @@ -1,5 +1,5 @@ -#ifndef TOS_FONT_H -#define TOS_FONT_H +#ifndef COMS_FONT_H +#define COMS_FONT_H #include "../stdlib/Types.h" #include "../memory/BufferMemory.h" diff --git a/gpuapi/AntiAliasing.h b/gpuapi/AntiAliasing.h index e12ece8..478057c 100644 --- a/gpuapi/AntiAliasing.h +++ b/gpuapi/AntiAliasing.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_ANTI_ALIASING_H -#define TOS_GPUAPI_ANTI_ALIASING_H +#ifndef COMS_GPUAPI_ANTI_ALIASING_H +#define COMS_GPUAPI_ANTI_ALIASING_H enum AntiAliasingType : byte { ANTI_ALIASING_TYPE_NONE, diff --git a/gpuapi/GpuApiType.h b/gpuapi/GpuApiType.h index 8188b0d..1e723b0 100644 --- a/gpuapi/GpuApiType.h +++ b/gpuapi/GpuApiType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_TYPE_H -#define TOS_GPUAPI_TYPE_H +#ifndef COMS_GPUAPI_TYPE_H +#define COMS_GPUAPI_TYPE_H enum GpuApiType { GPU_API_TYPE_NONE, diff --git a/gpuapi/GpuAttributeType.h b/gpuapi/GpuAttributeType.h index d8f36cd..ef9cd76 100644 --- a/gpuapi/GpuAttributeType.h +++ b/gpuapi/GpuAttributeType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_ATTRIBUTE_TYPE_H -#define TOS_GPUAPI_ATTRIBUTE_TYPE_H +#ifndef COMS_GPUAPI_ATTRIBUTE_TYPE_H +#define COMS_GPUAPI_ATTRIBUTE_TYPE_H #include "../stdlib/Types.h" #include "../compiler/CompilerUtils.h" diff --git a/gpuapi/RenderUtils.h b/gpuapi/RenderUtils.h index 51f8962..8abd742 100644 --- a/gpuapi/RenderUtils.h +++ b/gpuapi/RenderUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_RENDER_UTILS_H -#define TOS_GPUAPI_RENDER_UTILS_H +#ifndef COMS_GPUAPI_RENDER_UTILS_H +#define COMS_GPUAPI_RENDER_UTILS_H #include #include diff --git a/gpuapi/ShaderType.h b/gpuapi/ShaderType.h index 9b191ec..d0c4fc7 100644 --- a/gpuapi/ShaderType.h +++ b/gpuapi/ShaderType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_SHADER_TYPE_H -#define TOS_GPUAPI_SHADER_TYPE_H +#ifndef COMS_GPUAPI_SHADER_TYPE_H +#define COMS_GPUAPI_SHADER_TYPE_H enum ShaderType { SHADER_TYPE_NONE, diff --git a/gpuapi/direct3d/AppCmdBuffer.h b/gpuapi/direct3d/AppCmdBuffer.h index ada822a..0c28605 100644 --- a/gpuapi/direct3d/AppCmdBuffer.h +++ b/gpuapi/direct3d/AppCmdBuffer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_DIRECTX_APP_CMD_BUFFER_H -#define TOS_GPUAPI_DIRECTX_APP_CMD_BUFFER_H +#ifndef COMS_GPUAPI_DIRECTX_APP_CMD_BUFFER_H +#define COMS_GPUAPI_DIRECTX_APP_CMD_BUFFER_H #include "../../stdlib/Types.h" #include "../../log/PerformanceProfiler.h" diff --git a/gpuapi/direct3d/DirectXUtils.h b/gpuapi/direct3d/DirectXUtils.h index 6717aa4..4d8eeff 100644 --- a/gpuapi/direct3d/DirectXUtils.h +++ b/gpuapi/direct3d/DirectXUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_DIRECTX_UTILS_H -#define TOS_GPUAPI_DIRECTX_UTILS_H +#ifndef COMS_GPUAPI_DIRECTX_UTILS_H +#define COMS_GPUAPI_DIRECTX_UTILS_H #include "../../stdlib/Types.h" #include diff --git a/gpuapi/direct3d/FramesInFlightContainer.h b/gpuapi/direct3d/FramesInFlightContainer.h index a80454f..b8c0c74 100644 --- a/gpuapi/direct3d/FramesInFlightContainer.h +++ b/gpuapi/direct3d/FramesInFlightContainer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_DIRECT3D_FRAMES_IN_FLIGHT_CONTAINER_H -#define TOS_GPUAPI_DIRECT3D_FRAMES_IN_FLIGHT_CONTAINER_H +#ifndef COMS_GPUAPI_DIRECT3D_FRAMES_IN_FLIGHT_CONTAINER_H +#define COMS_GPUAPI_DIRECT3D_FRAMES_IN_FLIGHT_CONTAINER_H #include "../../stdlib/Types.h" #include diff --git a/gpuapi/direct3d/Shader.h b/gpuapi/direct3d/Shader.h index f20d299..0eebad1 100644 --- a/gpuapi/direct3d/Shader.h +++ b/gpuapi/direct3d/Shader.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_DIRECT3D_SHADER_H -#define TOS_GPUAPI_DIRECT3D_SHADER_H +#ifndef COMS_GPUAPI_DIRECT3D_SHADER_H +#define COMS_GPUAPI_DIRECT3D_SHADER_H #include "../../stdlib/Types.h" #include diff --git a/gpuapi/direct3d/ShaderUtils.h b/gpuapi/direct3d/ShaderUtils.h index 5a83471..ac78262 100644 --- a/gpuapi/direct3d/ShaderUtils.h +++ b/gpuapi/direct3d/ShaderUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_DIRECTX_SHADER_UTILS_H -#define TOS_GPUAPI_DIRECTX_SHADER_UTILS_H +#ifndef COMS_GPUAPI_DIRECTX_SHADER_UTILS_H +#define COMS_GPUAPI_DIRECTX_SHADER_UTILS_H #include #include diff --git a/gpuapi/opengl/AppCmdBuffer.h b/gpuapi/opengl/AppCmdBuffer.h index 4f6da61..55dec1e 100644 --- a/gpuapi/opengl/AppCmdBuffer.h +++ b/gpuapi/opengl/AppCmdBuffer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_APP_CMD_BUFFER_H -#define TOS_GPUAPI_OPENGL_APP_CMD_BUFFER_H +#ifndef COMS_GPUAPI_OPENGL_APP_CMD_BUFFER_H +#define COMS_GPUAPI_OPENGL_APP_CMD_BUFFER_H #include "../../stdlib/Types.h" #include "../../log/PerformanceProfiler.h" diff --git a/gpuapi/opengl/FramesInFlightContainer.h b/gpuapi/opengl/FramesInFlightContainer.h index c9c9d38..331c20c 100644 --- a/gpuapi/opengl/FramesInFlightContainer.h +++ b/gpuapi/opengl/FramesInFlightContainer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_FRAMES_IN_FLIGHT_CONTAINER_H -#define TOS_GPUAPI_OPENGL_FRAMES_IN_FLIGHT_CONTAINER_H +#ifndef COMS_GPUAPI_OPENGL_FRAMES_IN_FLIGHT_CONTAINER_H +#define COMS_GPUAPI_OPENGL_FRAMES_IN_FLIGHT_CONTAINER_H #include "../../stdlib/Types.h" #include "OpenglUtils.h" diff --git a/gpuapi/opengl/Opengl.h b/gpuapi/opengl/Opengl.h index 9e1e48b..18e6d91 100644 --- a/gpuapi/opengl/Opengl.h +++ b/gpuapi/opengl/Opengl.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_H -#define TOS_GPUAPI_OPENGL_H +#ifndef COMS_GPUAPI_OPENGL_H +#define COMS_GPUAPI_OPENGL_H // Some apis require a different sign for various operations (left/right) #define GPU_API_SIGN -1 diff --git a/gpuapi/opengl/OpenglDefines.h b/gpuapi/opengl/OpenglDefines.h index 6989df1..ef6c9b9 100644 --- a/gpuapi/opengl/OpenglDefines.h +++ b/gpuapi/opengl/OpenglDefines.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_DEFINES_H -#define TOS_GPUAPI_OPENGL_DEFINES_H +#ifndef COMS_GPUAPI_OPENGL_DEFINES_H +#define COMS_GPUAPI_OPENGL_DEFINES_H #include diff --git a/gpuapi/opengl/OpenglDescriptorSetLayoutBinding.h b/gpuapi/opengl/OpenglDescriptorSetLayoutBinding.h index 9a4e9e5..8ede791 100644 --- a/gpuapi/opengl/OpenglDescriptorSetLayoutBinding.h +++ b/gpuapi/opengl/OpenglDescriptorSetLayoutBinding.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_DESCRIPTOR_SET_LAYOUT_BINDING_H -#define TOS_GPUAPI_OPENGL_DESCRIPTOR_SET_LAYOUT_BINDING_H +#ifndef COMS_GPUAPI_OPENGL_DESCRIPTOR_SET_LAYOUT_BINDING_H +#define COMS_GPUAPI_OPENGL_DESCRIPTOR_SET_LAYOUT_BINDING_H #include "../../stdlib/Types.h" diff --git a/gpuapi/opengl/OpenglLinux.h b/gpuapi/opengl/OpenglLinux.h index 3c72bd5..7a92f99 100644 --- a/gpuapi/opengl/OpenglLinux.h +++ b/gpuapi/opengl/OpenglLinux.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_LINUX_H -#define TOS_GPUAPI_OPENGL_LINUX_H +#ifndef COMS_GPUAPI_OPENGL_LINUX_H +#define COMS_GPUAPI_OPENGL_LINUX_H typedef void type_glTexImage2DMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); typedef void type_glBindFramebuffer(GLenum target, GLuint framebuffer); diff --git a/gpuapi/opengl/OpenglUtils.h b/gpuapi/opengl/OpenglUtils.h index 34fb62c..195b668 100644 --- a/gpuapi/opengl/OpenglUtils.h +++ b/gpuapi/opengl/OpenglUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_UTILS_H -#define TOS_GPUAPI_OPENGL_UTILS_H +#ifndef COMS_GPUAPI_OPENGL_UTILS_H +#define COMS_GPUAPI_OPENGL_UTILS_H #include "../../stdlib/Types.h" #include "../../memory/RingMemory.h" diff --git a/gpuapi/opengl/OpenglWin32.h b/gpuapi/opengl/OpenglWin32.h index e93c1e8..d248e7e 100644 --- a/gpuapi/opengl/OpenglWin32.h +++ b/gpuapi/opengl/OpenglWin32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_WIN32_H -#define TOS_GPUAPI_OPENGL_WIN32_H +#ifndef COMS_GPUAPI_OPENGL_WIN32_H +#define COMS_GPUAPI_OPENGL_WIN32_H #include #include "../../platform/win32/Window.h" diff --git a/gpuapi/opengl/Shader.h b/gpuapi/opengl/Shader.h index 3dfc102..45e3e9f 100644 --- a/gpuapi/opengl/Shader.h +++ b/gpuapi/opengl/Shader.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_SHADER_H -#define TOS_GPUAPI_OPENGL_SHADER_H +#ifndef COMS_GPUAPI_OPENGL_SHADER_H +#define COMS_GPUAPI_OPENGL_SHADER_H #include "../../stdlib/Types.h" #include "OpenglDescriptorSetLayoutBinding.h" diff --git a/gpuapi/opengl/ShaderUtils.h b/gpuapi/opengl/ShaderUtils.h index 4e1be6a..23c1a9e 100644 --- a/gpuapi/opengl/ShaderUtils.h +++ b/gpuapi/opengl/ShaderUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_OPENGL_SHADER_UTILS_H -#define TOS_GPUAPI_OPENGL_SHADER_UTILS_H +#ifndef COMS_GPUAPI_OPENGL_SHADER_UTILS_H +#define COMS_GPUAPI_OPENGL_SHADER_UTILS_H #include "../../stdlib/Types.h" #include "../../memory/RingMemory.h" diff --git a/gpuapi/vulkan/AppCmdBuffer.h b/gpuapi/vulkan/AppCmdBuffer.h index f01dc78..b86bee1 100644 --- a/gpuapi/vulkan/AppCmdBuffer.h +++ b/gpuapi/vulkan/AppCmdBuffer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_VULKAN_APP_CMD_BUFFER_H -#define TOS_GPUAPI_VULKAN_APP_CMD_BUFFER_H +#ifndef COMS_GPUAPI_VULKAN_APP_CMD_BUFFER_H +#define COMS_GPUAPI_VULKAN_APP_CMD_BUFFER_H #include "../../stdlib/Types.h" #include "../../log/PerformanceProfiler.h" diff --git a/gpuapi/vulkan/FramesInFlightContainer.h b/gpuapi/vulkan/FramesInFlightContainer.h index 045a785..fb6e031 100644 --- a/gpuapi/vulkan/FramesInFlightContainer.h +++ b/gpuapi/vulkan/FramesInFlightContainer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_VULKAN_FRAMES_IN_FLIGHT_CONTAINER_H -#define TOS_GPUAPI_VULKAN_FRAMES_IN_FLIGHT_CONTAINER_H +#ifndef COMS_GPUAPI_VULKAN_FRAMES_IN_FLIGHT_CONTAINER_H +#define COMS_GPUAPI_VULKAN_FRAMES_IN_FLIGHT_CONTAINER_H #include "../../stdlib/Types.h" #include diff --git a/gpuapi/vulkan/Shader.h b/gpuapi/vulkan/Shader.h index 330ef73..96aab3f 100644 --- a/gpuapi/vulkan/Shader.h +++ b/gpuapi/vulkan/Shader.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_VULKAN_SHADER_H -#define TOS_GPUAPI_VULKAN_SHADER_H +#ifndef COMS_GPUAPI_VULKAN_SHADER_H +#define COMS_GPUAPI_VULKAN_SHADER_H #include "../../stdlib/Types.h" #include diff --git a/gpuapi/vulkan/ShaderUtils.h b/gpuapi/vulkan/ShaderUtils.h index 9f12a3d..c24e47f 100644 --- a/gpuapi/vulkan/ShaderUtils.h +++ b/gpuapi/vulkan/ShaderUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_VULKAN_SHADER_UTILS_H -#define TOS_GPUAPI_VULKAN_SHADER_UTILS_H +#ifndef COMS_GPUAPI_VULKAN_SHADER_UTILS_H +#define COMS_GPUAPI_VULKAN_SHADER_UTILS_H #include diff --git a/gpuapi/vulkan/VulkanUtils.h b/gpuapi/vulkan/VulkanUtils.h index 2a3bba1..78d5145 100644 --- a/gpuapi/vulkan/VulkanUtils.h +++ b/gpuapi/vulkan/VulkanUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_GPUAPI_VULKAN_UTILS_H -#define TOS_GPUAPI_VULKAN_UTILS_H +#ifndef COMS_GPUAPI_VULKAN_UTILS_H +#define COMS_GPUAPI_VULKAN_UTILS_H #if _WIN32 #ifndef VK_USE_PLATFORM_WIN32_KHR diff --git a/hash/Crc.h b/hash/Crc.h index 80e503e..85c7457 100644 --- a/hash/Crc.h +++ b/hash/Crc.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_HASH_CRC_H -#define TOS_HASH_CRC_H +#ifndef COMS_HASH_CRC_H +#define COMS_HASH_CRC_H #include "../stdlib/Types.h" #include "../architecture/Intrinsics.h" diff --git a/hash/GeneralHash.h b/hash/GeneralHash.h index 87969db..9a5901f 100644 --- a/hash/GeneralHash.h +++ b/hash/GeneralHash.h @@ -6,18 +6,18 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_HASH_GENERAL_H -#define TOS_HASH_GENERAL_H +#ifndef COMS_HASH_GENERAL_H +#define COMS_HASH_GENERAL_H #include "../stdlib/Types.h" -inline constexpr +inline uint64 hash_djb2(const char* key) noexcept { uint64 hash = 5381; int32 c; - while ((c = *key++)) { + while (((c = *key++))) { hash = ((hash << 5) + hash) + c; } @@ -30,7 +30,7 @@ uint64 hash_sdbm(const byte* key) noexcept uint64 hash = 0; int32 c; - while (c = *key++) { + while ((c = *key++)) { hash = c + (hash << 6) + (hash << 16) - hash; } @@ -43,7 +43,7 @@ uint64 hash_lose_lose(const byte* key) noexcept uint64 hash = 0; int32 c; - while (c = *key++) { + while ((c = *key++)) { hash += c; } @@ -116,7 +116,7 @@ uint32 hash_ejb(const char* str) noexcept } #define ROTL32(x, r) ((x) << (r)) | ((x) >> (32 - (r))) -inline constexpr +inline uint32 hash_murmur3_32(const byte* key, size_t len, uint32 seed = 0) noexcept { uint32 h = seed; @@ -290,13 +290,13 @@ uint64 hash_murmur3_64(const void* key, size_t len, uint64 seed = 0) noexcept // Seeded hash functions //////////////////////////////////// -inline constexpr +inline uint64 hash_djb2_seeded(const char* key, int32 seed) noexcept { uint64 hash = 5381; int32 c; - while ((c = *key++)) { + while (((c = *key++))) { hash = ((hash << 5) + hash) + c; } @@ -309,7 +309,7 @@ uint64 hash_sdbm_seeded(const char* key, int32 seed) noexcept uint64 hash = 0; int32 c; - while (c = *key++) { + while ((c = *key++)) { hash = c + (hash << 6) + (hash << 16) - hash; } @@ -322,7 +322,7 @@ uint64 hash_lose_lose_seeded(const char* key, int32 seed) noexcept uint64 hash = 0; int32 c; - while (c = *key++) { + while ((c = *key++)) { hash += c; } diff --git a/html/template/HtmlTemplate.h b/html/template/HtmlTemplate.h new file mode 100644 index 0000000..35fe21d --- /dev/null +++ b/html/template/HtmlTemplate.h @@ -0,0 +1,30 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_HTML_TEMPLATE_H +#define COMS_HTML_TEMPLATE_H + +#include "../../stdlib/Types.h" + +struct HtmlTemplate { + +}; + +bool html_template_load_txt() { + +} + +void html_template_save_bin() { + +} + +void html_template_load_bin() { + +} + +#endif \ No newline at end of file diff --git a/html/template/HtmlTemplateCache.h b/html/template/HtmlTemplateCache.h new file mode 100644 index 0000000..3c1164f --- /dev/null +++ b/html/template/HtmlTemplateCache.h @@ -0,0 +1,159 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_HTML_TEMPLATE_CACHE_H +#define COMS_HTML_TEMPLATE_CACHE_H + +#include "../../stdlib/Types.h" +#include "../../stdlib/PerfectHashMap.h" +#include "../../memory/RingMemory.h" +#include "../../system/FileUtils.cpp" +#include "../../html/template/HtmlTemplateInterpreter.h" + +struct HtmlTemplateCache { + // Contains the offsets into the cache + PerfectHashMap hm; + + // the layout of the cache is as follows: + // * Perfect hash map memory which contains the offsets into this cache where the root AST node per template can be found (hash_entries) + // * Per template memory: + // * minified template string (64 byte aligned) + // * AST, with it's own values or alternatively a pointer into the template string depending on the data (32 byte aligned for EVERY AST node) + byte* cache; + + // Total cache size + uint32 cache_size; + + // Current position + uint32 cache_pos; +}; + +static +void html_template_find(const char* path, va_list args) { + char** paths = va_arg(args, char**); + uint32* path_count = va_arg(args, uint32*); + uint32* max_path_count = va_arg(args, uint32*); + RingMemory* ring = va_arg(args, RingMemory*); + + if (path_count == max_path_count) { + uint32 old_max_path_count = *max_path_count; + + *max_path_count += 1000; + char* new_paths = (char *) ring_get_memory(ring, (*max_path_count) * 256 * sizeof(char), 8, true); + memcpy(new_paths, *paths, old_max_path_count * 256 * sizeof(char)); + *paths = new_paths; + } + + str_copy_short(paths[*path_count], path, 256); + ++(*path_count); +} + +void html_template_cache_init(HtmlTemplateCache* cache, const char* basedir, BufferMemory* buf, RingMemory* ring) { + uint32 max_path_count = 1000; + uint32 path_count = 0; + char* paths = (char *) ring_get_memory(ring, max_path_count * 256 * sizeof(char), 8, true); + + iterate_directory(basedir, ".tpl.html", html_template_find, &paths, &path_count, &max_path_count, ring); + + perfect_hashmap_create(&cache->hm, path_count, sizeof(uint32), buf); + perfect_hashmap_prepare(&cache->hm, (const char**) paths, path_count, 10000, ring); +} + +bool html_template_in_control_structure(const char* str, const char** controls, int32 control_length) { + for (int32 i = 0; i < control_length; ++i) { + if (str_compare(controls[i], str) == 0) { + return true; + } + } + + return false; +} + +void html_template_cache_load(HtmlTemplateCache* cache, const char* key, const char* str) { + char* minified = (char *) ROUND_TO_NEAREST((uintptr_t) cache->cache + (uintptr_t) cache->cache_pos, 64); + char* minified_start = minified; + + static const char* CONTROL_STRUCTURE_START[] = { + "'", "\"", "", "", "/>", "", + }; + + // Remove empty content to reduce template size + // We could handle this inside the lexer but the lexer itself often uses pointers into the template + // The lexer would also have to create additional tokens in that case whenever it "splits" the template due to empty text + // All-in-all let's consider this a pre-pass that we might want to move to the lexer in the future but I don't think so + int32 in_control_structure = 0; + while (*str) { + if (!in_control_structure && str_is_empty(*str)) { + ++str; + str_skip_empty(&str); + } + + if (!in_control_structure + && html_template_in_control_structure(str, CONTROL_STRUCTURE_START, ARRAY_COUNT(CONTROL_STRUCTURE_START)) + ) { + ++in_control_structure; + } else if (in_control_structure + && html_template_in_control_structure(str, CONTROL_STRUCTURE_END, ARRAY_COUNT(CONTROL_STRUCTURE_END)) + ) { + --in_control_structure; + } + + *minified++ = *str++; + } + + cache->cache_pos += ((uintptr_t) minified - (uintptr_t) minified_start); + + HtmlTemplateToken current_token = html_template_token_next((const char**) &minified_start, HTML_TEMPLATE_CONTEXT_FLAG_HTML); + + HtmlTemplateContextStack context_stack = {}; + HtmlTemplateContext initial_context = {}; + pushContext(&context_stack, initial_context); + + // @todo Instead of doing this, we want to use the cache.memory + // For this to work we need to pass the current memory position however into this function + byte* memory_start = cache->cache + cache->cache_pos; + byte* memory = memory_start; + HtmlTemplateASTNode* ast = html_template_statement_parse( + (const char**) &minified_start, + ¤t_token, + &context_stack, + current_token.type == TOKEN_CODE_START + ? HTML_TEMPLATE_CONTEXT_FLAG_TEMPLATE + : HTML_TEMPLATE_CONTEXT_FLAG_HTML, + &memory + ); + + cache->cache_pos += ((uintptr_t) memory - (uintptr_t) memory_start); + + ASSERT_SIMPLE(((uintptr_t) ast) % 64 == 0); + perfect_hashmap_insert(&cache->hm, key, (int32) ((uintptr_t) ast - (uintptr_t) cache->cache)); + + // @todo This belongs to wherever we want to output the user specified template + //interpret(ast, &context_stack); +} + +static +void html_template_cache_iter(const char* path, va_list args) { + HtmlTemplateCache* cache = va_arg(args, HtmlTemplateCache*); + RingMemory* ring = va_arg(args, RingMemory*); + + FileBody file = {}; + file_read(path, &file, ring); + + html_template_cache_load(cache, path, (const char *) file.content); +} + +void html_template_cache_load_all(HtmlTemplateCache* cache, const char* basedir, RingMemory* ring) { + iterate_directory(basedir, ".tpl.html", html_template_cache_iter, cache, ring); +} + +#endif \ No newline at end of file diff --git a/html/template/HtmlTemplateContext.h b/html/template/HtmlTemplateContext.h new file mode 100644 index 0000000..4ecc5bd --- /dev/null +++ b/html/template/HtmlTemplateContext.h @@ -0,0 +1,42 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_HTML_TEMPLATE_CONTEXT_H +#define COMS_HTML_TEMPLATE_CONTEXT_H + +#include "../../stdlib/Types.h" +#include "../../utils/TestUtils.h" + +struct HtmlTemplateContext { + int32 scope_level; + int32 loop_nesting_level; +}; + +#define MAX_STACK_SIZE 2400 + +struct HtmlTemplateContextStack { + HtmlTemplateContext stack[MAX_STACK_SIZE]; + int32 top; +}; + +void pushContext(HtmlTemplateContextStack* stack, HtmlTemplateContext context) { + ASSERT_SIMPLE(stack->top < MAX_STACK_SIZE); + stack->stack[stack->top++] = context; +} + +HtmlTemplateContext popContext(HtmlTemplateContextStack* stack) { + ASSERT_SIMPLE(stack->top > 0); + return stack->stack[--stack->top]; +} + +HtmlTemplateContext peekContext(HtmlTemplateContextStack* stack) { + ASSERT_SIMPLE(stack->top > 0); + return stack->stack[stack->top - 1]; +} + +#endif \ No newline at end of file diff --git a/html/template/HtmlTemplateInterpreter.h b/html/template/HtmlTemplateInterpreter.h new file mode 100644 index 0000000..db872eb --- /dev/null +++ b/html/template/HtmlTemplateInterpreter.h @@ -0,0 +1,297 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_HTML_TEMPLATE_INTERPRETER_H +#define COMS_HTML_TEMPLATE_INTERPRETER_H + +#include "HtmlTemplateContext.h" +#include "HtmlTemplateParser.h" +#include "../../utils/StringUtils.h" + +#define MAX_VARIABLES 1000 + +enum HtmlTemplateValueType : byte { + VALUE_BOOL, + VALUE_INTEGER64, + VALUE_FLOAT64, + VALUE_STRING +}; + +struct HtmlTemplateValue { + HtmlTemplateValueType type; + int32 value_length; + union { + bool boolValue; + int64 int64Value; + f64 f64Value; + char* ptrValue; + }; +}; + +enum HtmlTemplateVariableType : byte { + VAR_BOOL, + VAR_INTEGER64, + VAR_FLOAT64, + VAR_STRING +}; + +struct HtmlTemplateVariable { + char name[32]; + HtmlTemplateVariableType type; + int32 value_length; + union { + bool boolValue; + int64 int64Value; + f64 f64Value; + char* ptrValue; + }; +}; + +HtmlTemplateVariable symbol_table[MAX_VARIABLES]; +int32 symbol_table_size = 0; + +HtmlTemplateValue html_template_variable_get(const char* name, HtmlTemplateContextStack*) { + for (int32 i = 0; i < symbol_table_size; i++) { + if (str_compare(symbol_table[i].name, name) == 0) { + HtmlTemplateValue result; + switch (symbol_table[i].type) { + case VAR_BOOL: { + result.type = VALUE_BOOL; + result.boolValue = symbol_table[i].boolValue; + } break; + case VAR_INTEGER64: { + result.type = VALUE_INTEGER64; + result.int64Value = symbol_table[i].int64Value; + } break; + case VAR_FLOAT64: { + result.type = VALUE_FLOAT64; + result.f64Value = symbol_table[i].f64Value; + } break; + case VAR_STRING: { + result.type = VALUE_STRING; + result.ptrValue = symbol_table[i].ptrValue; + result.value_length = symbol_table[i].value_length; + } break; + default: { + UNREACHABLE(); + } + } + + return result; + } + } + printf("Error: Variable %s not found\n", name); + exit(1); +} + +void html_template_variable_set(const char* name, HtmlTemplateValue value, HtmlTemplateContextStack*) { + for (int32 i = 0; i < symbol_table_size; i++) { + if (str_compare(symbol_table[i].name, name) == 0) { + switch (value.type) { + case VALUE_BOOL: { + symbol_table[i].type = VAR_BOOL; + symbol_table[i].boolValue = value.boolValue; + } break; + case VALUE_INTEGER64: { + symbol_table[i].type = VAR_INTEGER64; + symbol_table[i].int64Value = value.int64Value; + } break; + case VALUE_FLOAT64: { + symbol_table[i].type = VAR_FLOAT64; + symbol_table[i].f64Value = value.f64Value; + } break; + case VALUE_STRING: { + symbol_table[i].type = VAR_STRING; + symbol_table[i].ptrValue = value.ptrValue; + symbol_table[i].value_length = value.value_length; + } break; + default: + UNREACHABLE(); + } + return; + } + } + + // If the variable doesn't exist, add it to the symbol table + if (symbol_table_size < MAX_VARIABLES) { + str_copy_short(symbol_table[symbol_table_size].name, name); + switch (value.type) { + case VALUE_BOOL: { + symbol_table[symbol_table_size].type = VAR_BOOL; + symbol_table[symbol_table_size].boolValue = value.boolValue; + } break; + case VALUE_INTEGER64: { + symbol_table[symbol_table_size].type = VAR_INTEGER64; + symbol_table[symbol_table_size].int64Value = value.int64Value; + } break; + case VALUE_FLOAT64: { + symbol_table[symbol_table_size].type = VAR_FLOAT64; + symbol_table[symbol_table_size].f64Value = value.f64Value; + } break; + case VALUE_STRING: { + symbol_table[symbol_table_size].type = VAR_STRING; + symbol_table[symbol_table_size].ptrValue = value.ptrValue; + symbol_table[symbol_table_size].value_length = value.value_length; + } break; + default: + UNREACHABLE(); + } + + ++symbol_table_size; + } else { + printf("Error: Symbol table overflow\n"); + exit(1); + } +} + +HtmlTemplateValue html_template_expression_eval(HtmlTemplateASTNode* node, HtmlTemplateContextStack* context_stack) { + HtmlTemplateValue result; + switch (node->type) { + case NODE_INTEGER64: + result.type = VALUE_INTEGER64; + result.int64Value = node->int64Value; + + return result; + case NODE_FLOAT64: + result.type = VALUE_FLOAT64; + result.f64Value = node->f64Value; + + return result; + case NODE_IDENTIFIER: + return html_template_variable_get(node->ptrValue, context_stack); + case NODE_STRING: + result.type = VALUE_STRING; + result.ptrValue = node->ptrValue; + result.value_length = node->value_length; + + return result; + case NODE_BINOP: { + HtmlTemplateValue leftValue = html_template_expression_eval(node->left, context_stack); + HtmlTemplateValue rightValue = html_template_expression_eval(node->right, context_stack); + if (leftValue.type == VALUE_INTEGER64 && rightValue.type == VALUE_INTEGER64) { + result.type = VALUE_INTEGER64; + if (str_compare(node->ptrValue, "+") == 0) { + result.int64Value = leftValue.int64Value + rightValue.int64Value; + } else if (str_compare(node->ptrValue, "-") == 0) { + result.int64Value = leftValue.int64Value - rightValue.int64Value; + } else if (str_compare(node->ptrValue, "*") == 0) { + result.int64Value = leftValue.int64Value * rightValue.int64Value; + } else if (str_compare(node->ptrValue, "/") == 0) { + result.int64Value = leftValue.int64Value / rightValue.int64Value; + } else { + exit(1); + } + + return result; + } else if (leftValue.type == VALUE_FLOAT64 || rightValue.type == VALUE_FLOAT64) { + // Promote to double if either operand is a double + result.type = VALUE_FLOAT64; + double left = (leftValue.type == VALUE_FLOAT64) ? leftValue.f64Value : (f64)leftValue.int64Value; + f64 right = (rightValue.type == VALUE_FLOAT64) ? rightValue.f64Value : (f64)rightValue.int64Value; + if (str_compare(node->ptrValue, "+") == 0) { + result.f64Value = left + right; + } else if (str_compare(node->ptrValue, "-") == 0) { + result.f64Value = left - right; + } else if (str_compare(node->ptrValue, "*") == 0) { + result.f64Value = left * right; + } else if (str_compare(node->ptrValue, "/") == 0) { + result.f64Value = left / right; + } else { + exit(1); + } + + return result; + } else { + printf("Error: Incompatible types for binary operation\n"); + exit(1); + } + } + default: + printf("Error: Unknown node type in expression\n"); + exit(1); + } +} + +bool html_template_condition_eval(HtmlTemplateASTNode *node, HtmlTemplateContextStack *context_stack) { + if (node->type == NODE_BINOP) { + HtmlTemplateValue leftValue = html_template_expression_eval(node->left, context_stack); + HtmlTemplateValue rightValue = html_template_expression_eval(node->right, context_stack); + + if (leftValue.type == VALUE_INTEGER64 && rightValue.type == VALUE_INTEGER64) { + // Integer comparison + if (str_compare(node->ptrValue, ">") == 0) { + return leftValue.int64Value > rightValue.int64Value; + } else if (str_compare(node->ptrValue, "<") == 0) { + return leftValue.int64Value < rightValue.int64Value; + } else if (str_compare(node->ptrValue, "==") == 0) { + return leftValue.int64Value == rightValue.int64Value; + } else if (str_compare(node->ptrValue, "!=") == 0) { + return leftValue.int64Value != rightValue.int64Value; + } else if (str_compare(node->ptrValue, ">=") == 0) { + return leftValue.int64Value >= rightValue.int64Value; + } else if (str_compare(node->ptrValue, "<=") == 0) { + return leftValue.int64Value <= rightValue.int64Value; + } else { + exit(1); + } + } else if (leftValue.type == VALUE_FLOAT64 || rightValue.type == VALUE_FLOAT64) { + // Promote to double for comparison + f64 left = (leftValue.type == VALUE_FLOAT64) ? leftValue.f64Value : (f64)leftValue.int64Value; + f64 right = (rightValue.type == VALUE_FLOAT64) ? rightValue.f64Value : (f64)rightValue.int64Value; + if (str_compare(node->ptrValue, ">") == 0) { + return left > right; + } else if (str_compare(node->ptrValue, "<") == 0) { + return left < right; + } else if (str_compare(node->ptrValue, "==") == 0) { + return left == right; + } else if (str_compare(node->ptrValue, "!=") == 0) { + return left != right; + } else if (str_compare(node->ptrValue, ">=") == 0) { + return left >= right; + } else if (str_compare(node->ptrValue, "<=") == 0) { + return left <= right; + } else { + exit(1); + } + } else { + printf("Error: Incompatible types for comparison\n"); + exit(1); + } + } else { + printf("Error: Expected a binary operation in condition\n"); + exit(1); + } +} + +// @todo should take in a buffer for template output +// @performance, what if there is no template data, just html? -> a simple pointer to the resource data should be created?! +// This would maybe allow us to also return files in the future +void html_template_interpret(HtmlTemplateASTNode *node, HtmlTemplateContextStack *context_stack) { + switch (node->type) { + case NODE_ASSIGN: + // Handle assignment + break; + case NODE_IF: + // Handle if statement + html_template_interpret(node->left, context_stack); // Condition + html_template_interpret(node->right, context_stack); // Body + break; + case NODE_FOR: + // Handle for loop + html_template_interpret(node->left, context_stack); // Init + while (html_template_condition_eval(node->right->left, context_stack)) { // Condition + html_template_interpret(node->right->right, context_stack); // Body + html_template_interpret(node->right->left->right, context_stack); // Update + } + break; + default: + break; + } +} + +#endif \ No newline at end of file diff --git a/html/template/HtmlTemplateLexer.h b/html/template/HtmlTemplateLexer.h new file mode 100644 index 0000000..41cc2dc --- /dev/null +++ b/html/template/HtmlTemplateLexer.h @@ -0,0 +1,272 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_HTML_TEMPLATE_LEXER_H +#define COMS_HTML_TEMPLATE_LEXER_H + +#include +#include +#include +#include +#include "../../stdlib/Types.h" +#include "../../utils/StringUtils.h" + +enum HtmlTemplateTokenType : byte { + TOKEN_HTML, + TOKEN_BOOL, + TOKEN_INTEGER64, + TOKEN_FLOAT64, + TOKEN_IDENTIFIER, + TOKEN_ASSIGN, // = + TOKEN_INCREMENT, // ++ + TOKEN_DECREMENT, // -- + TOKEN_ADD_ASSIGN, // += + TOKEN_SUBTRACT_ASSIGN, // -= + TOKEN_MULTIPLY_ASSIGN, // *= + TOKEN_DIVIDE_ASSIGN, // /= + TOKEN_EQUALS, // == + TOKEN_UNEQUAL, // != + TOKEN_GREATER, // > + TOKEN_GREATER_EQUAL, // >= + TOKEN_LESSER, // < + TOKEN_LESSER_EQUAL, // <= + TOKEN_PLUS, + TOKEN_MINUS, + TOKEN_MULTIPLY, + TOKEN_DIVIDE, + TOKEN_COLON, // : + TOKEN_QUESTION, // ? + TOKEN_EXCLAMATION, // ! + TOKEN_CODE_START, // + TOKEN_LBRACK, // [ + TOKEN_RBRACK, // ] + TOKEN_LPAREN, // ( + TOKEN_RPAREN, // ) + TOKEN_LBRACE, // { + TOKEN_RBRACE, // } + TOKEN_SEMICOLON, // ; + TOKEN_STRING, // "..." + TOKEN_WHILE, + TOKEN_ENDWHILE, + TOKEN_IF, + TOKEN_ENDIF, + TOKEN_ELSEIF, + TOKEN_ELSE, + TOKEN_FOR, + TOKEN_ENDFOR, + TOKEN_FOREACH, + TOKEN_ENDFOREACH, + TOKEN_EOF, + TOKEN_UNKNOWN +}; + +#define HTML_TEMPLATE_TOKEN_VALUE_SIZE 127 + +struct HtmlTemplateToken { + HtmlTemplateTokenType type; + + // Normally we would actually store the value instead of a pointer + // However, since html templates can have long sections without any template code and only html + // We would rather use pointers compared to huge arrays for value storage + const char* value; + size_t length; +}; + +enum HtmlTemplateContextFlag { + HTML_TEMPLATE_CONTEXT_FLAG_HTML, + HTML_TEMPLATE_CONTEXT_FLAG_TEMPLATE, +}; + +HtmlTemplateToken html_template_token_next(const char** input, HtmlTemplateContextFlag context_flag) { + str_skip_empty(input); + + HtmlTemplateToken token = { TOKEN_HTML, *input, 0 }; + if (**input == '\0') { + token.type = TOKEN_EOF; + } else if (context_flag == HTML_TEMPLATE_CONTEXT_FLAG_HTML) { + // We might be in html mode or template mode + // Depending on the mode we must handle chars differently + if ((**input == '<' && **input == '?')) { + token.type = TOKEN_CODE_START; + token.length = 2; + + *input += 2; + } else { + token.type = TOKEN_HTML; + + // Move input along until EOF or template code is found + while (**input != '\0' && (**input != '<' || **input != '?')) { + ++(*input); + ++token.length; + } + } + } else if (**input == '"') { + ++(*input); + token.type = TOKEN_STRING; + token.value = *input; + + while (**input != '"' && **input != '\0') { + ++(*input); + ++token.length; + } + + if (**input == '"') { + ++(*input); + } + } else if (str_is_num(**input)) { + token.type = TOKEN_INTEGER64; + + while (str_is_num(**input) || **input == '.') { + if (**input == '.') { + token.type = TOKEN_FLOAT64; + } + + ++(*input); + ++token.length; + } + } else if (str_is_alpha(**input)) { + while (str_is_alphanum(**input)) { + ++(*input); + ++token.length; + } + + if (str_compare(token.value, "if") == 0) { + token.type = TOKEN_IF; + } else if (str_compare(token.value, "endif") == 0) { + token.type = TOKEN_ENDIF; + } else if (str_compare(token.value, "elseif") == 0) { + token.type = TOKEN_ELSEIF; + } else if (str_compare(token.value, "else") == 0) { + token.type = TOKEN_ELSE; + } else if (str_compare(token.value, "for") == 0) { + token.type = TOKEN_FOR; + } else if (str_compare(token.value, "endfor") == 0) { + token.type = TOKEN_ENDFOR; + } else if (str_compare(token.value, "while") == 0) { + token.type = TOKEN_WHILE; + } else if (str_compare(token.value, "endwhile") == 0) { + token.type = TOKEN_ENDWHILE; + } else if (str_compare(token.value, "foreach") == 0) { + token.type = TOKEN_FOREACH; + } else if (str_compare(token.value, "endforeach") == 0) { + token.type = TOKEN_ENDFOREACH; + } else { + token.type = TOKEN_IDENTIFIER; + } + } else { + token.length = 1; + + switch (**input) { + case '=': { + if (*input[1] == '=') { + token.type = TOKEN_EQUALS; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_ASSIGN; + } + } break; + case '!': { + if (*input[1] == '=') { + token.type = TOKEN_UNEQUAL; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_EXCLAMATION; + } + } break; + case ':': token.type = TOKEN_COLON; break; + case '?': { + if (*input[1] == '>') { + token.type = TOKEN_CODE_END; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_QUESTION; + } + } break; + case '>': { + if (*input[1] == '=') { + token.type = TOKEN_GREATER_EQUAL; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_GREATER; + } + } break; + case '<': { + if (*input[1] == '=') { + token.type = TOKEN_LESSER_EQUAL; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_LESSER; + } + } break; + case '+': { + if (*input[1] == '=') { + token.type = TOKEN_ADD_ASSIGN; + token.length = 2; + ++(*input); + } else if (*input[1] == '+') { + token.type = TOKEN_INCREMENT; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_PLUS; + } + } break; + case '-': { + if (*input[1] == '=') { + token.type = TOKEN_SUBTRACT_ASSIGN; + token.length = 2; + ++(*input); + } else if (*input[1] == '-') { + token.type = TOKEN_DECREMENT; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_MINUS; + } + } break; + case '*': { + if (*input[1] == '=') { + token.type = TOKEN_MULTIPLY_ASSIGN; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_MULTIPLY; + } + } break; + case '/': { + if (*input[1] == '=') { + token.type = TOKEN_DIVIDE_ASSIGN; + token.length = 2; + ++(*input); + } else { + token.type = TOKEN_DIVIDE; + } + } break; + case '[': token.type = TOKEN_LBRACK; break; + case ']': token.type = TOKEN_RBRACK; break; + case '(': token.type = TOKEN_LPAREN; break; + case ')': token.type = TOKEN_RPAREN; break; + case '{': token.type = TOKEN_LBRACE; break; + case '}': token.type = TOKEN_RBRACE; break; + case ';': token.type = TOKEN_SEMICOLON; break; + default: token.type = TOKEN_UNKNOWN; break; + } + + ++(*input); + } + + return token; +} + +#endif \ No newline at end of file diff --git a/html/template/HtmlTemplateParser.h b/html/template/HtmlTemplateParser.h new file mode 100644 index 0000000..ea20617 --- /dev/null +++ b/html/template/HtmlTemplateParser.h @@ -0,0 +1,246 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_HTML_TEMPLATE_PARSER_H +#define COMS_HTML_TEMPLATE_PARSER_H + +#include "HtmlTemplateLexer.h" +#include "HtmlTemplateContext.h" + +enum HtmlTemplateNodeType : byte { + NODE_BINOP, + NODE_PTR, + NODE_IDENTIFIER, + NODE_BOOL, + NODE_INTEGER64, + NODE_FLOAT64, + NODE_ASSIGN, // = + NODE_INCREMENT, // ++ + NODE_DECREMENT, // -- + NODE_ADD_ASSIGN, // += + NODE_SUBTRACT_ASSIGN, // -= + NODE_MULTIPLY_ASSIGN, // *= + NODE_DIVIDE_ASSIGN, // /= + NODE_EQUALS, // == + NODE_UNEQUAL, // != + NODE_GREATER, // > + NODE_GREATER_EQUAL, // >= + NODE_LESSER, // < + NODE_LESSER_EQUAL, // <= + NODE_PLUS, + NODE_MINUS, + NODE_MULTIPLY, + NODE_DIVIDE, + NODE_COLON, // : + NODE_QUESTION, // ? + NODE_EXCLAMATION, // ! + NODE_CODE_START, // + NODE_LBRACK, // [ + NODE_RBRACK, // ] + NODE_LPAREN, // ( + NODE_RPAREN, // ) + NODE_LBRACE, // { + NODE_RBRACE, // } + NODE_SEMICOLON, // ; + NODE_STRING, // "..." + NODE_WHILE, + NODE_ENDWHILE, + NODE_IF, + NODE_ENDIF, + NODE_ELSEIF, + NODE_ELSE, + NODE_FOR, + NODE_ENDFOR, + NODE_FOREACH, + NODE_ENDFOREACH, +}; + +struct HtmlTemplateASTNode { + HtmlTemplateASTNode* left; + HtmlTemplateASTNode* right; + + HtmlTemplateNodeType type; + uint32 value_length; + union { + bool boolValue; + int64 int64Value; + f64 f64Value; + char* ptrValue; + }; +}; + +HtmlTemplateASTNode* html_template_node_create(HtmlTemplateNodeType type, HtmlTemplateToken* token, byte** memory) { + *memory = (byte *) ROUND_TO_NEAREST((uintptr_t) memory, 32); + HtmlTemplateASTNode* node = (HtmlTemplateASTNode *) *memory; + *memory = (byte *) ROUND_TO_NEAREST((uintptr_t) (memory + sizeof(HtmlTemplateASTNode)), 32); + + node->type = type; + node->left = NULL; + node->right = NULL; + node->value_length = token->length; + + // @question instead of handling the parsing below, why not handle it here for known types such as int, float, bool, string + memcpy(&node->int64Value, token->value, sizeof(uintptr_t)); + + return node; +} + +HtmlTemplateASTNode* html_template_factor_parse(const char**, HtmlTemplateToken*, HtmlTemplateContextFlag, byte**); +HtmlTemplateASTNode* html_template_term_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextFlag context_flag, byte** memory) { + // @bug This is wrong + HtmlTemplateASTNode* left = html_template_factor_parse(input, token_current, context_flag, memory); + while (token_current->type == TOKEN_MULTIPLY || token_current->type == TOKEN_DIVIDE) { + HtmlTemplateToken* old = token_current; + *token_current = html_template_token_next(input, context_flag); + HtmlTemplateASTNode* right = html_template_factor_parse(input, token_current, context_flag, memory); + // @bug This is wrong + left = html_template_node_create(NODE_BINOP, old, memory); + left->left = left; + left->right = right; + } + + return left; +} + +HtmlTemplateASTNode* html_template_expression_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextFlag context_flag, byte** memory) { + HtmlTemplateASTNode* left = html_template_term_parse(input, token_current, context_flag, memory); + while (token_current->type == TOKEN_PLUS || token_current->type == TOKEN_MINUS) { + HtmlTemplateToken* old = token_current; + *token_current = html_template_token_next(input, context_flag); + HtmlTemplateASTNode* right = html_template_term_parse(input, token_current, context_flag, memory); + left = html_template_node_create(NODE_BINOP, old, memory); + left->left = left; + left->right = right; + } + + return left; +} + +HtmlTemplateASTNode* html_template_factor_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextFlag context_flag, byte** memory) { + // @performance Consider to order the token types in a smart way and perform range check here + // @todo use switch + if (token_current->type == TOKEN_INTEGER64) { + HtmlTemplateASTNode* node = html_template_node_create(NODE_INTEGER64, token_current, memory); + *token_current = html_template_token_next(input, context_flag); + + // @todo parse string representation of int + + return node; + } else if (token_current->type == TOKEN_FLOAT64) { + HtmlTemplateASTNode* node = html_template_node_create(NODE_FLOAT64, token_current, memory); + *token_current = html_template_token_next(input, context_flag); + + // @todo parse string representation of float + + return node; + } else if (token_current->type == TOKEN_STRING) { + HtmlTemplateASTNode* node = html_template_node_create(NODE_STRING, token_current, memory); + *token_current = html_template_token_next(input, context_flag); + return node; + } else if (token_current->type == TOKEN_IDENTIFIER) { + HtmlTemplateASTNode* node = html_template_node_create(NODE_IDENTIFIER, token_current, memory); + *token_current = html_template_token_next(input, context_flag); + return node; + } else if (token_current->type == TOKEN_LPAREN) { + *token_current = html_template_token_next(input, context_flag); // Consume '(' + HtmlTemplateASTNode* node = html_template_expression_parse(input, token_current, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume ')' + return node; + } else if (token_current->type == TOKEN_LBRACK) { + *token_current = html_template_token_next(input, context_flag); // Consume '[' + HtmlTemplateASTNode* node = html_template_expression_parse(input, token_current, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume ']' + return node; + } else if (token_current->type == TOKEN_LBRACE) { + *token_current = html_template_token_next(input, context_flag); // Consume '{' + HtmlTemplateASTNode* node = html_template_expression_parse(input, token_current, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume '}' + return node; + } + + ASSERT_SIMPLE(false); + + return NULL; +} + +HtmlTemplateASTNode* html_template_statement_parse(const char**, HtmlTemplateToken*, HtmlTemplateContextStack*, HtmlTemplateContextFlag, byte**); +HtmlTemplateASTNode* html_template_assignment_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextFlag context_flag, byte** memory) { + /*HtmlTemplateASTNode* left =*/ html_template_node_create(NODE_IDENTIFIER, token_current, memory); + *token_current = html_template_token_next(input, context_flag); // Consume identifier + *token_current = html_template_token_next(input, context_flag); // Consume '=' + /*HtmlTemplateASTNode* right =*/ html_template_expression_parse(input, token_current, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume ';' + + return html_template_node_create(NODE_ASSIGN, {}, memory); +} + +HtmlTemplateASTNode* html_template_parse_if(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextStack* contextStack, HtmlTemplateContextFlag context_flag, byte** memory) { + HtmlTemplateContext newContext = peekContext(contextStack); + ++newContext.scope_level; + pushContext(contextStack, newContext); + + *token_current = html_template_token_next(input, context_flag); // Consume 'if' + *token_current = html_template_token_next(input, context_flag); // Consume '(' + HtmlTemplateASTNode* condition = html_template_expression_parse(input, token_current, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume ')' + *token_current = html_template_token_next(input, context_flag); // Consume '{' + HtmlTemplateASTNode* body = html_template_statement_parse(input, token_current, contextStack, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume '}' + + popContext(contextStack); + + HtmlTemplateASTNode* ifNode = html_template_node_create(NODE_IF, {}, memory); + ifNode->left = condition; // Condition + ifNode->right = body; // Body + + return ifNode; +} + +HtmlTemplateASTNode* html_template_parse_for(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextStack* contextStack, HtmlTemplateContextFlag context_flag, byte** memory) { + HtmlTemplateContext newContext = peekContext(contextStack); + ++newContext.scope_level; + ++newContext.loop_nesting_level; + pushContext(contextStack, newContext); + + *token_current = html_template_token_next(input, context_flag); // Consume 'for' + *token_current = html_template_token_next(input, context_flag); // Consume '(' + HtmlTemplateASTNode* init = html_template_assignment_parse(input, token_current, context_flag, memory); + HtmlTemplateASTNode* condition = html_template_expression_parse(input, token_current, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume ';' + HtmlTemplateASTNode* update = html_template_assignment_parse(input, token_current, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume ')' + *token_current = html_template_token_next(input, context_flag); // Consume '{' + HtmlTemplateASTNode* body = html_template_statement_parse(input, token_current, contextStack, context_flag, memory); + *token_current = html_template_token_next(input, context_flag); // Consume '}' + + popContext(contextStack); + + HtmlTemplateASTNode* forNode = html_template_node_create(NODE_FOR, {}, memory); + forNode->left = init; // Initialization + forNode->right = html_template_node_create(NODE_BINOP, {}, memory); + forNode->right->left = condition; // Condition + forNode->right->right = update; // Update + forNode->right->right->right = body; // Body + + return forNode; +} + +HtmlTemplateASTNode* html_template_statement_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextStack* contextStack, HtmlTemplateContextFlag context_flag, byte** memory) { + if (token_current->type == TOKEN_ASSIGN) { + return html_template_assignment_parse(input, token_current, context_flag, memory); + } else if (token_current->type == TOKEN_IF) { + return html_template_parse_if(input, token_current, contextStack, context_flag, memory); + } else if (token_current->type == TOKEN_FOR) { + return html_template_parse_for(input, token_current, contextStack, context_flag, memory); + } else { + exit(1); + } +} + +#endif \ No newline at end of file diff --git a/image/Bitmap.h b/image/Bitmap.h index c4a859f..f358641 100644 --- a/image/Bitmap.h +++ b/image/Bitmap.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_IMAGE_BITMAP_H -#define TOS_IMAGE_BITMAP_H +#ifndef COMS_IMAGE_BITMAP_H +#define COMS_IMAGE_BITMAP_H #include #include @@ -108,16 +108,16 @@ struct DIB_BITMAPV3INFOHEADER { }; -struct TOS_CIEXYZ { +struct COMS_CIEXYZ { int32 ciexyzX; int32 ciexyzY; int32 ciexyzZ; }; -struct TOS_CIEXYZTRIPLE { - TOS_CIEXYZ ciexyzRed; - TOS_CIEXYZ ciexyzGreen; - TOS_CIEXYZ ciexyzBlue; +struct COMS_CIEXYZTRIPLE { + COMS_CIEXYZ ciexyzRed; + COMS_CIEXYZ ciexyzGreen; + COMS_CIEXYZ ciexyzBlue; }; #define DIB_BITMAP_TYPE_BITMAPV4HEADER 108 @@ -139,7 +139,7 @@ struct DIB_BITMAPV4HEADER { int32 bV4BlueMask; int32 bV4AlphaMask; int32 bV4CSType; - TOS_CIEXYZTRIPLE bV4Endpoints; + COMS_CIEXYZTRIPLE bV4Endpoints; int32 bV4GammaRed; int32 bV4GammaGreen; int32 bV4GammaBlue; @@ -164,7 +164,7 @@ struct DIB_BITMAPV5HEADER { int32 bV5BlueMask; int32 bV5AlphaMask; int32 bV5CSType; - TOS_CIEXYZTRIPLE bV5Endpoints; + COMS_CIEXYZTRIPLE bV5Endpoints; int32 bV5GammaRed; int32 bV5GammaGreen; int32 bV5GammaBlue; diff --git a/image/Image.cpp b/image/Image.cpp index 240bc9b..40376da 100644 --- a/image/Image.cpp +++ b/image/Image.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_IMAGE_C -#define TOS_IMAGE_C +#ifndef COMS_IMAGE_C +#define COMS_IMAGE_C #include "../utils/StringUtils.h" #include "../memory/RingMemory.h" diff --git a/image/Image.h b/image/Image.h index fecf1ac..3b57fe8 100644 --- a/image/Image.h +++ b/image/Image.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_IMAGE_H -#define TOS_IMAGE_H +#ifndef COMS_IMAGE_H +#define COMS_IMAGE_H #include "../stdlib/Types.h" diff --git a/image/Png.h b/image/Png.h index 482ff4d..b29d70c 100644 --- a/image/Png.h +++ b/image/Png.h @@ -11,8 +11,8 @@ * zlib: https://www.ietf.org/rfc/rfc1950.txt * deflate: https://www.ietf.org/rfc/rfc1951.txt */ -#ifndef TOS_IMAGE_PNG_H -#define TOS_IMAGE_PNG_H +#ifndef COMS_IMAGE_PNG_H +#define COMS_IMAGE_PNG_H #include #include "../stdlib/Types.h" diff --git a/image/Qoi.h b/image/Qoi.h index 4407326..ea74f8e 100644 --- a/image/Qoi.h +++ b/image/Qoi.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_IMAGE_QOI_H -#define TOS_IMAGE_QOI_H +#ifndef COMS_IMAGE_QOI_H +#define COMS_IMAGE_QOI_H #include "../stdlib/Types.h" #include diff --git a/image/Tga.h b/image/Tga.h index bc19854..e743391 100644 --- a/image/Tga.h +++ b/image/Tga.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_IMAGE_TGA_H -#define TOS_IMAGE_TGA_H +#ifndef COMS_IMAGE_TGA_H +#define COMS_IMAGE_TGA_H #include #include "../stdlib/Types.h" diff --git a/image/default_colors.h b/image/default_colors.h index 6eee2a4..a871476 100644 --- a/image/default_colors.h +++ b/image/default_colors.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_IMAGE_DEFAULT_COLORS_H -#define TOS_IMAGE_DEFAULT_COLORS_H +#ifndef COMS_IMAGE_DEFAULT_COLORS_H +#define COMS_IMAGE_DEFAULT_COLORS_H #include "../stdlib/Types.h" diff --git a/input/ControllerInput.h b/input/ControllerInput.h index 8963120..93cc6f2 100644 --- a/input/ControllerInput.h +++ b/input/ControllerInput.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_INPUT_CONTROLLER_CONTROLLER_INPUT_H -#define TOS_PLATFORM_WIN32_INPUT_CONTROLLER_CONTROLLER_INPUT_H +#ifndef COMS_PLATFORM_WIN32_INPUT_CONTROLLER_CONTROLLER_INPUT_H +#define COMS_PLATFORM_WIN32_INPUT_CONTROLLER_CONTROLLER_INPUT_H #include "../stdlib/Types.h" diff --git a/input/ControllerType.h b/input/ControllerType.h index 636f341..33c5d90 100644 --- a/input/ControllerType.h +++ b/input/ControllerType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_INPUT_CONTROLLER_TYPE_H -#define TOS_PLATFORM_WIN32_INPUT_CONTROLLER_TYPE_H +#ifndef COMS_PLATFORM_WIN32_INPUT_CONTROLLER_TYPE_H +#define COMS_PLATFORM_WIN32_INPUT_CONTROLLER_TYPE_H #include "../stdlib/Types.h" diff --git a/input/Input.h b/input/Input.h index ccbda0a..8e3ac99 100644 --- a/input/Input.h +++ b/input/Input.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_INPUT_H -#define TOS_INPUT_H +#ifndef COMS_INPUT_H +#define COMS_INPUT_H #include "../stdlib/Types.h" #include "../utils/BitUtils.h" @@ -574,7 +574,7 @@ void input_hotkey_state(Input* input) noexcept // Create text from input char* pos = input->text; - for (int32 i = 0; i < ARRAY_COUNT(characters); ++i) { + for (uint32 i = 0; i < ARRAY_COUNT(characters); ++i) { pos += utf8_decode(characters[i], pos); } diff --git a/input/InputConnectionType.h b/input/InputConnectionType.h index 88879ee..40b4bae 100644 --- a/input/InputConnectionType.h +++ b/input/InputConnectionType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_INPUT_CONNECTION_TYPE_H -#define TOS_PLATFORM_WIN32_INPUT_CONNECTION_TYPE_H +#ifndef COMS_PLATFORM_WIN32_INPUT_CONNECTION_TYPE_H +#define COMS_PLATFORM_WIN32_INPUT_CONNECTION_TYPE_H // Important, since some connection protocols differ between for example USB and Bluetooth (see Playstation DualSense) enum InputConnectionType { diff --git a/localization/Language.h b/localization/Language.h index 29c7ecd..7ab359e 100644 --- a/localization/Language.h +++ b/localization/Language.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_LANGUAGE_H -#define TOS_UI_LANGUAGE_H +#ifndef COMS_UI_LANGUAGE_H +#define COMS_UI_LANGUAGE_H #include "../stdlib/Types.h" #include "../memory/RingMemory.h" diff --git a/log/DebugContainer.h b/log/DebugContainer.h index 0b3dfb5..7a26cbc 100644 --- a/log/DebugContainer.h +++ b/log/DebugContainer.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_LOG_DEBUG_CONTAINER_H -#define TOS_LOG_DEBUG_CONTAINER_H +#ifndef COMS_LOG_DEBUG_CONTAINER_H +#define COMS_LOG_DEBUG_CONTAINER_H #include "Log.h" #include "DebugMemory.h" @@ -24,7 +24,7 @@ struct DebugContainer { #endif LogMemory* log_memory; - atomic_64 int64* stats_counter; + alignas(8) atomic_64 int64* stats_counter; PerformanceProfileResult* perf_stats; PerformanceProfiler** perf_current_scope; diff --git a/log/DebugMemory.h b/log/DebugMemory.h index a7dc05c..b40cb90 100644 --- a/log/DebugMemory.h +++ b/log/DebugMemory.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_LOG_DEBUG_MEMORY_H -#define TOS_LOG_DEBUG_MEMORY_H +#ifndef COMS_LOG_DEBUG_MEMORY_H +#define COMS_LOG_DEBUG_MEMORY_H #include "../stdlib/Types.h" #include "../thread/Atomic.h" @@ -114,7 +114,7 @@ void debug_memory_log(uintptr_t start, uint64 size, int32 type, const char* func uint64 idx = atomic_fetch_add_relaxed(&mem->action_idx, 1); if (idx >= ARRAY_COUNT(mem->last_action)) { - atomic_set_acquire(&mem->action_idx, 1); + atomic_set_release(&mem->action_idx, 1); idx %= ARRAY_COUNT(mem->last_action); } @@ -146,7 +146,7 @@ void debug_memory_reserve(uintptr_t start, uint64 size, int32 type, const char* uint64 idx = atomic_fetch_add_relaxed(&mem->reserve_action_idx, 1); if (idx >= ARRAY_COUNT(mem->reserve_action)) { - atomic_set_acquire(&mem->reserve_action_idx, 1); + atomic_set_release(&mem->reserve_action_idx, 1); idx %= ARRAY_COUNT(mem->reserve_action); } @@ -171,7 +171,7 @@ void debug_memory_free(uintptr_t start) noexcept return; } - for (int32 i = 0; i < ARRAY_COUNT(mem->reserve_action); ++i) { + for (uint32 i = 0; i < ARRAY_COUNT(mem->reserve_action); ++i) { DebugMemoryRange* dmr = &mem->reserve_action[i]; if (dmr->start == start - mem->start) { dmr->size = 0; diff --git a/log/Log.h b/log/Log.h index a961c4e..9fc45ee 100644 --- a/log/Log.h +++ b/log/Log.h @@ -6,14 +6,14 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_LOG_H -#define TOS_LOG_H +#ifndef COMS_LOG_H +#define COMS_LOG_H #include "../stdlib/Types.h" #include "../compiler/CompilerUtils.h" #include "../architecture/Intrinsics.h" #include "../utils/StringUtils.h" -#include "../platform/win32/TimeUtils.h" +#include "../utils/TimeUtils.h" /** * The logging is both using file logging and in-memory logging. @@ -142,13 +142,24 @@ void log_to_file() #endif } +// Same as log_to_file with the exception that reset the log pos to avoid repeated output +void log_flush() +{ + if (!_log_memory || _log_memory->pos == 0 || !_log_fp) { + return; + } + + log_to_file(); + _log_memory->pos = 0; +} + void log(const char* str, const char* file, const char* function, int32 line) { if (!_log_memory) { return; } - int64 len = str_length(str); + size_t len = str_length(str); while (len > 0) { LogMessage* msg = (LogMessage *) log_get_memory(); @@ -247,7 +258,7 @@ void log(const char* format, LogDataArray data, const char* file, const char* fu } } - #if DEBUG + #if DEBUG || VERBOSE // In debug mode we always output the log message to the debug console compiler_debug_print(msg->message); compiler_debug_print("\n"); @@ -260,6 +271,7 @@ void log(const char* format, LogDataArray data, const char* file, const char* fu } #define LOG_TO_FILE() log_to_file() +#define LOG_FLUSH() log_flush() #if LOG_LEVEL == 4 #define LOG_1(format, ...) log((format), LogDataArray{__VA_ARGS__}, __FILE__, __func__, __LINE__) diff --git a/log/PerformanceProfiler.h b/log/PerformanceProfiler.h index 2b4748f..3d32706 100644 --- a/log/PerformanceProfiler.h +++ b/log/PerformanceProfiler.h @@ -6,11 +6,11 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_LOG_PERFORMANCE_PROFILER_H -#define TOS_LOG_PERFORMANCE_PROFILER_H +#ifndef COMS_LOG_PERFORMANCE_PROFILER_H +#define COMS_LOG_PERFORMANCE_PROFILER_H #include "../stdlib/Types.h" -#include "../platform/win32/TimeUtils.h" +#include "../utils/TimeUtils.h" #include "../thread/Spinlock.cpp" #include "../thread/Atomic.h" #include "../system/Allocator.h" @@ -53,12 +53,12 @@ #endif struct PerformanceProfileResult { - atomic_64 const char* name; + alignas(8) atomic_64 const char* name; - atomic_64 int64 total_cycle; - atomic_64 int64 self_cycle; + alignas(8) atomic_64 int64 total_cycle; + alignas(8) atomic_64 int64 self_cycle; - atomic_32 uint32 counter; + alignas(4) atomic_32 uint32 counter; uint32 parent; }; static PerformanceProfileResult* _perf_stats = NULL; @@ -72,7 +72,7 @@ struct PerformanceProfiler { const char* name; const char* info_msg; - int32 id; + int32 _id; int64 start_cycle; int64 total_cycle; @@ -95,8 +95,8 @@ struct PerformanceProfiler { return; } - this->id = id; - ++_perf_stats[id].counter; + this->_id = id; + atomic_increment_acquire_release(&_perf_stats[id].counter); this->name = scope_name; this->info_msg = info; @@ -131,7 +131,7 @@ struct PerformanceProfiler { // Store result PerformanceProfileResult temp_perf = {}; - PerformanceProfileResult* perf = this->is_stateless ? &temp_perf : &_perf_stats[this->id]; + PerformanceProfileResult* perf = this->is_stateless ? &temp_perf : &_perf_stats[this->_id]; perf->name = this->name; perf->total_cycle = this->total_cycle; @@ -140,7 +140,7 @@ struct PerformanceProfiler { if (!this->is_stateless) { if (this->parent) { this->parent->self_cycle -= this->total_cycle; - perf->parent = this->parent->id; + perf->parent = this->parent->_id; } if (_perf_current_scope) { @@ -179,7 +179,7 @@ void performance_profiler_reset(int32 id) noexcept PerformanceProfileResult* perf = &_perf_stats[id]; perf->total_cycle = 0; perf->self_cycle = 0; - perf->parent = NULL; + perf->parent = 0; } inline diff --git a/log/Stats.h b/log/Stats.h index bd410a5..9e8bb56 100644 --- a/log/Stats.h +++ b/log/Stats.h @@ -1,6 +1,6 @@ -#ifndef TOS_LOG_STATS_H -#define TOS_LOG_STATS_H +#ifndef COMS_LOG_STATS_H +#define COMS_LOG_STATS_H #include "../stdlib/Types.h" #include "../thread/Atomic.h" @@ -37,7 +37,7 @@ void reset_counter(int32 id) noexcept return; } - atomic_set_acquire(&_stats_counter[id], 0); + atomic_set_release(&_stats_counter[id], 0); } inline @@ -57,7 +57,7 @@ void log_counter(int32 id, int64 value) noexcept return; } - atomic_set_acquire(&_stats_counter[id], value); + atomic_set_release(&_stats_counter[id], value); } #if (!DEBUG && !INTERNAL) || RELEASE diff --git a/math/Evaluator.h b/math/Evaluator.h index 0180bae..8dc70be 100644 --- a/math/Evaluator.h +++ b/math/Evaluator.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_EVALUATOR_H -#define TOS_MATH_EVALUATOR_H +#ifndef COMS_MATH_EVALUATOR_H +#define COMS_MATH_EVALUATOR_H #include "../stdlib/Types.h" #include "../utils/StringUtils.h" diff --git a/math/matrix/MatrixFloat32.h b/math/matrix/MatrixFloat32.h index 08188ca..faca090 100644 --- a/math/matrix/MatrixFloat32.h +++ b/math/matrix/MatrixFloat32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_MATRIX_FLOAT32_H -#define TOS_MATH_MATRIX_FLOAT32_H +#ifndef COMS_MATH_MATRIX_FLOAT32_H +#define COMS_MATH_MATRIX_FLOAT32_H #include #include diff --git a/math/matrix/MatrixInt32.h b/math/matrix/MatrixInt32.h index 13712b3..019c0fb 100644 --- a/math/matrix/MatrixInt32.h +++ b/math/matrix/MatrixInt32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_MATRIX_INT32_H -#define TOS_MATH_MATRIX_INT32_H +#ifndef COMS_MATH_MATRIX_INT32_H +#define COMS_MATH_MATRIX_INT32_H #if ARM #include "../../stdlib/IntrinsicsArm.h" diff --git a/math/matrix/MatrixInt64.h b/math/matrix/MatrixInt64.h index 397c6eb..5d49629 100644 --- a/math/matrix/MatrixInt64.h +++ b/math/matrix/MatrixInt64.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_MATRIX_INT64_H -#define TOS_MATH_MATRIX_INT64_H +#ifndef COMS_MATH_MATRIX_INT64_H +#define COMS_MATH_MATRIX_INT64_H #if ARM #include "../../stdlib/IntrinsicsArm.h" diff --git a/math/matrix/QuaternionFloat32.h b/math/matrix/QuaternionFloat32.h index 9b89d03..a573e3c 100644 --- a/math/matrix/QuaternionFloat32.h +++ b/math/matrix/QuaternionFloat32.h @@ -7,8 +7,8 @@ * @link https://jingga.app * @link https://danceswithcode.net/engineeringnotes/quaternions/quaternions.html */ -#ifndef TOS_MATH_MATRIX_QUATERNION_FLOAT32_H -#define TOS_MATH_MATRIX_QUATERNION_FLOAT32_H +#ifndef COMS_MATH_MATRIX_QUATERNION_FLOAT32_H +#define COMS_MATH_MATRIX_QUATERNION_FLOAT32_H #include "../../utils/TestUtils.h" #include "MatrixFloat32.h" diff --git a/math/matrix/VectorFloat32.h b/math/matrix/VectorFloat32.h index 83f91ce..24e949a 100644 --- a/math/matrix/VectorFloat32.h +++ b/math/matrix/VectorFloat32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_MATRIX_VECTOR_FLOAT32_H -#define TOS_MATH_MATRIX_VECTOR_FLOAT32_H +#ifndef COMS_MATH_MATRIX_VECTOR_FLOAT32_H +#define COMS_MATH_MATRIX_VECTOR_FLOAT32_H #include "../../stdlib/Simd.h" diff --git a/math/matrix/VectorFloat64.h b/math/matrix/VectorFloat64.h index abee9e1..cce8108 100644 --- a/math/matrix/VectorFloat64.h +++ b/math/matrix/VectorFloat64.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_MATRIX_VECTOR_FLOAT64_H -#define TOS_MATH_MATRIX_VECTOR_FLOAT64_H +#ifndef COMS_MATH_MATRIX_VECTOR_FLOAT64_H +#define COMS_MATH_MATRIX_VECTOR_FLOAT64_H #include "../../stdlib/Simd.h" diff --git a/math/matrix/VectorInt32.h b/math/matrix/VectorInt32.h index 8f82cb1..857dd7b 100644 --- a/math/matrix/VectorInt32.h +++ b/math/matrix/VectorInt32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_MATRIX_VECTOR_INT32_H -#define TOS_MATH_MATRIX_VECTOR_INT32_H +#ifndef COMS_MATH_MATRIX_VECTOR_INT32_H +#define COMS_MATH_MATRIX_VECTOR_INT32_H #include #include diff --git a/math/matrix/VectorInt64.h b/math/matrix/VectorInt64.h index a279cc1..bcd9df1 100644 --- a/math/matrix/VectorInt64.h +++ b/math/matrix/VectorInt64.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_MATRIX_VECTOR_INT64_H -#define TOS_MATH_MATRIX_VECTOR_INT64_H +#ifndef COMS_MATH_MATRIX_VECTOR_INT64_H +#define COMS_MATH_MATRIX_VECTOR_INT64_H #include #include diff --git a/math/random/BlueNoise.h b/math/random/BlueNoise.h index 4bb9a23..b4773c3 100644 --- a/math/random/BlueNoise.h +++ b/math/random/BlueNoise.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MATH_RANDOM_BLUE_NOISE -#define TOS_MATH_RANDOM_BLUE_NOISE +#ifndef COMS_MATH_RANDOM_BLUE_NOISE +#define COMS_MATH_RANDOM_BLUE_NOISE #include "../../stdlib/Types.h" diff --git a/memory/BufferMemory.h b/memory/BufferMemory.h index 92b4fe2..e903a31 100644 --- a/memory/BufferMemory.h +++ b/memory/BufferMemory.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MEMORY_BUFFER_MEMORY_H -#define TOS_MEMORY_BUFFER_MEMORY_H +#ifndef COMS_MEMORY_BUFFER_MEMORY_H +#define COMS_MEMORY_BUFFER_MEMORY_H #include #include "../stdlib/Types.h" diff --git a/memory/ChunkMemory.h b/memory/ChunkMemory.h index 6d0f611..22e3f90 100644 --- a/memory/ChunkMemory.h +++ b/memory/ChunkMemory.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MEMORY_CHUNK_MEMORY_H -#define TOS_MEMORY_CHUNK_MEMORY_H +#ifndef COMS_MEMORY_CHUNK_MEMORY_H +#define COMS_MEMORY_CHUNK_MEMORY_H #include #include "../stdlib/Types.h" diff --git a/memory/Heap.h b/memory/Heap.h index 4231a76..6356c70 100644 --- a/memory/Heap.h +++ b/memory/Heap.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MEMORY_HEAP_H -#define TOS_MEMORY_HEAP_H +#ifndef COMS_MEMORY_HEAP_H +#define COMS_MEMORY_HEAP_H #include #include diff --git a/memory/Queue.h b/memory/Queue.h index 7dee67c..fafca57 100644 --- a/memory/Queue.h +++ b/memory/Queue.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MEMORY_QUEUE_H -#define TOS_MEMORY_QUEUE_H +#ifndef COMS_MEMORY_QUEUE_H +#define COMS_MEMORY_QUEUE_H #include "../stdlib/Types.h" #include "../utils/Utils.h" @@ -72,8 +72,8 @@ bool queue_is_empty(Queue* queue) noexcept { } inline -bool queue_set_empty(Queue* queue) noexcept { - return queue->head = queue->tail; +void queue_set_empty(Queue* queue) noexcept { + queue->head = queue->tail; } inline diff --git a/memory/RingMemory.h b/memory/RingMemory.h index 2377b87..7dbb6d1 100644 --- a/memory/RingMemory.h +++ b/memory/RingMemory.h @@ -6,12 +6,10 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MEMORY_RING_MEMORY_H -#define TOS_MEMORY_RING_MEMORY_H +#ifndef COMS__MEMORY_RING_MEMORY_H +#define COMS__MEMORY_RING_MEMORY_H #include -#include - #include "../stdlib/Types.h" #include "../utils/EndianUtils.h" #include "../utils/TestUtils.h" @@ -27,7 +25,7 @@ #include "../system/Allocator.h" // WARNING: Changing this structure has effects on other data structures (e.g. Queue) -// When chaning make sure you understand what you are doing +// When changing make sure you understand what you are doing struct RingMemory { byte* memory; byte* end; @@ -171,6 +169,8 @@ void ring_move_pointer(RingMemory* ring, byte** pos, uint64 size, uint32 aligned *pos += size; } +// @todo Implement a function called ring_grow_memory that tries to grow a memory range +// this of course is only possible if the memory range is the last memory range returned and if the growing part still fits into the ring byte* ring_get_memory(RingMemory* ring, uint64 size, uint32 aligned = 4, bool zeroed = false) noexcept { ASSERT_SIMPLE(size <= ring->size); diff --git a/memory/ThreadedChunkMemory.h b/memory/ThreadedChunkMemory.h index 10341ef..b02c6df 100644 --- a/memory/ThreadedChunkMemory.h +++ b/memory/ThreadedChunkMemory.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MEMORY_THREADED_CHUNK_MEMORY_H -#define TOS_MEMORY_THREADED_CHUNK_MEMORY_H +#ifndef COMS_MEMORY_THREADED_CHUNK_MEMORY_H +#define COMS_MEMORY_THREADED_CHUNK_MEMORY_H #include #include "../stdlib/Types.h" @@ -30,8 +30,8 @@ struct ThreadedChunkMemory { // The completeness indicates if the data is completely written to uint64* completeness; - pthread_mutex_t mutex; - pthread_cond_t cond; + coms_pthread_mutex_t mutex; + coms_pthread_cond_t cond; }; #endif \ No newline at end of file diff --git a/memory/ThreadedQueue.h b/memory/ThreadedQueue.h index b9c5952..a8599d0 100644 --- a/memory/ThreadedQueue.h +++ b/memory/ThreadedQueue.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MEMORY_THREADED_QUEUE_H -#define TOS_MEMORY_THREADED_QUEUE_H +#ifndef COMS_MEMORY_THREADED_QUEUE_H +#define COMS_MEMORY_THREADED_QUEUE_H // @todo This is a horrible implementation. Please implement a lock free solution @@ -37,8 +37,8 @@ struct ThreadedQueue { // We support both conditional locking and semaphore locking // These values are not initialized and not used unless you use the queue - pthread_mutex_t mutex; - pthread_cond_t cond; + coms_pthread_mutex_t mutex; + coms_pthread_cond_t cond; sem_t empty; sem_t full; @@ -53,8 +53,8 @@ void thrd_queue_alloc(ThreadedQueue* queue, uint32 element_count, uint32 element queue->element_size = element_size; - pthread_mutex_init(&queue->mutex, NULL); - pthread_cond_init(&queue->cond, NULL); + coms_pthread_mutex_init(&queue->mutex, NULL); + coms_pthread_cond_init(&queue->cond, NULL); sem_init(&queue->empty, element_count); sem_init(&queue->full, 0); @@ -69,8 +69,8 @@ void thrd_queue_init(ThreadedQueue* queue, BufferMemory* buf, uint32 element_cou queue->element_size = element_size; - pthread_mutex_init(&queue->mutex, NULL); - pthread_cond_init(&queue->cond, NULL); + coms_pthread_mutex_init(&queue->mutex, NULL); + coms_pthread_cond_init(&queue->cond, NULL); sem_init(&queue->empty, element_count); sem_init(&queue->full, 0); @@ -85,8 +85,8 @@ void thrd_queue_init(ThreadedQueue* queue, byte* buf, uint32 element_count, uint queue->element_size = element_size; - pthread_mutex_init(&queue->mutex, NULL); - pthread_cond_init(&queue->cond, NULL); + coms_pthread_mutex_init(&queue->mutex, NULL); + coms_pthread_cond_init(&queue->cond, NULL); sem_init(&queue->empty, element_count); sem_init(&queue->full, 0); @@ -98,8 +98,8 @@ void thrd_queue_free(ThreadedQueue* queue) ring_free((RingMemory *) queue); sem_destroy(&queue->empty); sem_destroy(&queue->full); - pthread_mutex_destroy(&queue->mutex); - pthread_cond_destroy(&queue->cond); + coms_pthread_mutex_destroy(&queue->mutex); + coms_pthread_cond_destroy(&queue->cond); } // @todo Create enqueue_unique and enqueue_unique_sem @@ -107,7 +107,7 @@ inline void thrd_queue_enqueue_unique_wait(ThreadedQueue* queue, const byte* data) noexcept { ASSERT_SIMPLE((uint64_t) data % 4 == 0); - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); byte* tail = queue->tail; while (tail != queue->tail) { @@ -115,7 +115,7 @@ void thrd_queue_enqueue_unique_wait(ThreadedQueue* queue, const byte* data) noex // @performance we could probably make this faster since we don't need to compare the entire range if (is_equal(tail, data, queue->element_size) == 0) { - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); return; } @@ -124,21 +124,21 @@ void thrd_queue_enqueue_unique_wait(ThreadedQueue* queue, const byte* data) noex } while (!ring_commit_safe((RingMemory *) queue, queue->element_size, queue->alignment)) { - pthread_cond_wait(&queue->cond, &queue->mutex); + coms_pthread_cond_wait(&queue->cond, &queue->mutex); } byte* mem = ring_get_memory((RingMemory *) queue, queue->element_size, queue->alignment); memcpy(mem, data, queue->element_size); - pthread_cond_signal(&queue->cond); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_cond_signal(&queue->cond); + coms_pthread_mutex_unlock(&queue->mutex); } inline void thrd_queue_enqueue_unique(ThreadedQueue* queue, const byte* data) noexcept { ASSERT_SIMPLE((uint64_t) data % 4 == 0); - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); byte* tail = queue->tail; while (tail != queue->tail) { @@ -146,7 +146,7 @@ void thrd_queue_enqueue_unique(ThreadedQueue* queue, const byte* data) noexcept // @performance we could probably make this faster since we don't need to compare the entire range if (is_equal(tail, data, queue->element_size) == 0) { - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); return; } @@ -155,7 +155,7 @@ void thrd_queue_enqueue_unique(ThreadedQueue* queue, const byte* data) noexcept } if (!ring_commit_safe((RingMemory *) queue, queue->element_size, queue->alignment)) { - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); return; } @@ -163,18 +163,18 @@ void thrd_queue_enqueue_unique(ThreadedQueue* queue, const byte* data) noexcept byte* mem = ring_get_memory((RingMemory *) queue, queue->element_size, queue->alignment); memcpy(mem, data, queue->element_size); - pthread_cond_signal(&queue->cond); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_cond_signal(&queue->cond); + coms_pthread_mutex_unlock(&queue->mutex); } // Conditional Lock inline void thrd_queue_enqueue(ThreadedQueue* queue, const byte* data) noexcept { - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); if (!ring_commit_safe((RingMemory *) queue, queue->element_size, queue->alignment)) { - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); return; } @@ -182,33 +182,33 @@ void thrd_queue_enqueue(ThreadedQueue* queue, const byte* data) noexcept byte* mem = ring_get_memory((RingMemory *) queue, queue->element_size, queue->alignment); memcpy(mem, data, queue->element_size); - pthread_cond_signal(&queue->cond); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_cond_signal(&queue->cond); + coms_pthread_mutex_unlock(&queue->mutex); } inline void thrd_queue_enqueue_wait(ThreadedQueue* queue, const byte* data) noexcept { - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); while (!ring_commit_safe((RingMemory *) queue, queue->element_size, queue->alignment)) { - pthread_cond_wait(&queue->cond, &queue->mutex); + coms_pthread_cond_wait(&queue->cond, &queue->mutex); } byte* mem = ring_get_memory((RingMemory *) queue, queue->element_size, queue->alignment); memcpy(mem, data, queue->element_size); - pthread_cond_signal(&queue->cond); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_cond_signal(&queue->cond); + coms_pthread_mutex_unlock(&queue->mutex); } inline byte* thrd_queue_enqueue_start_wait(ThreadedQueue* queue) noexcept { - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); while (!ring_commit_safe((RingMemory *) queue, queue->element_size, queue->alignment)) { - pthread_cond_wait(&queue->cond, &queue->mutex); + coms_pthread_cond_wait(&queue->cond, &queue->mutex); } return ring_get_memory((RingMemory *) queue, queue->element_size, queue->alignment); @@ -217,8 +217,8 @@ byte* thrd_queue_enqueue_start_wait(ThreadedQueue* queue) noexcept inline void thrd_queue_enqueue_end_wait(ThreadedQueue* queue) noexcept { - pthread_cond_signal(&queue->cond); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_cond_signal(&queue->cond); + coms_pthread_mutex_unlock(&queue->mutex); } inline @@ -229,9 +229,9 @@ bool thrd_queue_dequeue(ThreadedQueue* queue, byte* data) noexcept } // we do this twice because the first one is very fast but may return a false positive - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); if (queue->head == queue->tail) { - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); return false; } @@ -243,26 +243,26 @@ bool thrd_queue_dequeue(ThreadedQueue* queue, byte* data) noexcept } ring_move_pointer((RingMemory *) queue, &queue->tail, queue->element_size, queue->alignment); - pthread_cond_signal(&queue->cond); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_cond_signal(&queue->cond); + coms_pthread_mutex_unlock(&queue->mutex); return true; } inline bool thrd_queue_empty(ThreadedQueue* queue) noexcept { - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); bool is_empty = queue->head == queue->tail; - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); return is_empty; } inline bool thrd_queue_full(ThreadedQueue* queue) noexcept { - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); bool is_full = !ring_commit_safe((RingMemory *) queue, queue->element_size, queue->alignment); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); return is_full; } @@ -271,26 +271,26 @@ bool thrd_queue_full(ThreadedQueue* queue) noexcept { inline void thrd_queue_dequeue_wait(ThreadedQueue* queue, byte* data) noexcept { - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); while (queue->head == queue->tail) { - pthread_cond_wait(&queue->cond, &queue->mutex); + coms_pthread_cond_wait(&queue->cond, &queue->mutex); } memcpy(data, queue->tail, queue->element_size); ring_move_pointer((RingMemory *) queue, &queue->tail, queue->element_size, queue->alignment); - pthread_cond_signal(&queue->cond); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_cond_signal(&queue->cond); + coms_pthread_mutex_unlock(&queue->mutex); } inline byte* thrd_queue_dequeue_start_wait(ThreadedQueue* queue) noexcept { - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); while (queue->head == queue->tail) { - pthread_cond_wait(&queue->cond, &queue->mutex); + coms_pthread_cond_wait(&queue->cond, &queue->mutex); } return queue->tail; @@ -301,8 +301,8 @@ void thrd_queue_dequeue_end_wait(ThreadedQueue* queue) noexcept { ring_move_pointer((RingMemory *) queue, &queue->tail, queue->element_size, queue->alignment); - pthread_cond_signal(&queue->cond); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_cond_signal(&queue->cond); + coms_pthread_mutex_unlock(&queue->mutex); } // Semaphore Lock @@ -310,12 +310,12 @@ inline void thrd_queue_enqueue_sem_wait(ThreadedQueue* queue, const byte* data) noexcept { sem_wait(&queue->empty); - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); byte* mem = ring_get_memory((RingMemory *) queue, queue->element_size, queue->alignment); memcpy(mem, data, queue->element_size); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); sem_post(&queue->full); } @@ -326,12 +326,12 @@ bool thrd_queue_enqueue_sem_timedwait(ThreadedQueue* queue, const byte* data, ui return false; } - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); byte* mem = ring_get_memory((RingMemory *) queue, queue->element_size, queue->alignment); memcpy(mem, data, queue->element_size); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); sem_post(&queue->full); return true; @@ -341,7 +341,7 @@ inline byte* thrd_queue_enqueue_start_sem_wait(ThreadedQueue* queue) noexcept { sem_wait(&queue->empty); - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); return ring_get_memory((RingMemory *) queue, queue->element_size, queue->alignment); } @@ -349,7 +349,7 @@ byte* thrd_queue_enqueue_start_sem_wait(ThreadedQueue* queue) noexcept inline void thrd_queue_enqueue_end_sem_wait(ThreadedQueue* queue) noexcept { - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); sem_post(&queue->full); } @@ -357,12 +357,12 @@ inline byte* thrd_queue_dequeue_sem_wait(ThreadedQueue* queue, byte* data) noexcept { sem_wait(&queue->full); - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); memcpy(data, queue->tail, queue->element_size); ring_move_pointer((RingMemory *) queue, &queue->tail, queue->element_size, queue->alignment); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); sem_post(&queue->empty); } @@ -373,12 +373,12 @@ bool thrd_queue_dequeue_sem_timedwait(ThreadedQueue* queue, byte* data, uint64 w return false; } - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); memcpy(data, queue->tail, queue->element_size); ring_move_pointer((RingMemory *) queue, &queue->tail, queue->element_size, queue->alignment); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); sem_post(&queue->empty); return true; @@ -388,7 +388,7 @@ inline byte* thrd_queue_dequeue_start_sem_wait(ThreadedQueue* queue) noexcept { sem_wait(&queue->full); - pthread_mutex_lock(&queue->mutex); + coms_pthread_mutex_lock(&queue->mutex); return queue->tail; } @@ -398,7 +398,7 @@ void thrd_queue_dequeue_end_sem_wait(ThreadedQueue* queue) noexcept { ring_move_pointer((RingMemory *) queue, &queue->tail, queue->element_size, queue->alignment); - pthread_mutex_unlock(&queue->mutex); + coms_pthread_mutex_unlock(&queue->mutex); sem_post(&queue->empty); } diff --git a/memory/ThreadedRingMemory.h b/memory/ThreadedRingMemory.h index 862c4ce..36a911b 100644 --- a/memory/ThreadedRingMemory.h +++ b/memory/ThreadedRingMemory.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MEMORY_THREADED_RING_MEMORY_H -#define TOS_MEMORY_THREADED_RING_MEMORY_H +#ifndef COMS_MEMORY_THREADED_RING_MEMORY_H +#define COMS_MEMORY_THREADED_RING_MEMORY_H #include "RingMemory.h" #include "../thread/Thread.h" @@ -30,7 +30,7 @@ struct ThreadedRingMemory { int32 alignment; // The ring memory ends here - pthread_mutex_t mutex; + coms_pthread_mutex_t mutex; }; // @bug alignment should also include the end point, not just the start @@ -39,36 +39,36 @@ inline void thrd_ring_alloc(ThreadedRingMemory* ring, uint64 size, int32 alignment = 64) { ring_alloc((RingMemory *) ring, size, alignment); - pthread_mutex_init(&ring->mutex, NULL); + coms_pthread_mutex_init(&ring->mutex, NULL); } inline void thrd_ring_init(ThreadedRingMemory* ring, BufferMemory* buf, uint64 size, int32 alignment = 64) { ring_init((RingMemory *) ring, buf, size, alignment); - pthread_mutex_init(&ring->mutex, NULL); + coms_pthread_mutex_init(&ring->mutex, NULL); } inline void thrd_ring_init(ThreadedRingMemory* ring, byte* buf, uint64 size, int32 alignment = 64) { ring_init((RingMemory *) ring, buf, size, alignment); - pthread_mutex_init(&ring->mutex, NULL); + coms_pthread_mutex_init(&ring->mutex, NULL); } inline void thrd_ring_free(ThreadedRingMemory* ring) { ring_free((RingMemory *) ring); - pthread_mutex_destroy(&ring->mutex); + coms_pthread_mutex_destroy(&ring->mutex); } inline byte* thrd_ring_calculate_position(ThreadedRingMemory* ring, uint64 size, byte aligned = 4) noexcept { - pthread_mutex_lock(&ring->mutex); + coms_pthread_mutex_lock(&ring->mutex); byte* result = ring_calculate_position((RingMemory *) ring, size, aligned); - pthread_mutex_unlock(&ring->mutex); + coms_pthread_mutex_unlock(&ring->mutex); return result; } @@ -76,24 +76,24 @@ byte* thrd_ring_calculate_position(ThreadedRingMemory* ring, uint64 size, byte a inline void thrd_ring_reset(ThreadedRingMemory* ring) noexcept { - pthread_mutex_lock(&ring->mutex); + coms_pthread_mutex_lock(&ring->mutex); ring_reset((RingMemory *) ring); - pthread_mutex_unlock(&ring->mutex); + coms_pthread_mutex_unlock(&ring->mutex); } // Moves a pointer based on the size you want to consume (new position = after consuming size) void thrd_ring_move_pointer(ThreadedRingMemory* ring, byte** pos, uint64 size, byte aligned = 4) noexcept { - pthread_mutex_lock(&ring->mutex); + coms_pthread_mutex_lock(&ring->mutex); ring_move_pointer((RingMemory *) ring, pos, size, aligned); - pthread_mutex_unlock(&ring->mutex); + coms_pthread_mutex_unlock(&ring->mutex); } byte* thrd_ring_get_memory(ThreadedRingMemory* ring, uint64 size, byte aligned = 4, bool zeroed = false) noexcept { - pthread_mutex_lock(&ring->mutex); + coms_pthread_mutex_lock(&ring->mutex); byte* result = ring_get_memory((RingMemory *) ring, size, aligned, zeroed); - pthread_mutex_unlock(&ring->mutex); + coms_pthread_mutex_unlock(&ring->mutex); return result; } @@ -101,9 +101,9 @@ byte* thrd_ring_get_memory(ThreadedRingMemory* ring, uint64 size, byte aligned = // Same as ring_get_memory but DOESN'T move the head byte* thrd_ring_get_memory_nomove(ThreadedRingMemory* ring, uint64 size, byte aligned = 4, bool zeroed = false) noexcept { - pthread_mutex_lock(&ring->mutex); + coms_pthread_mutex_lock(&ring->mutex); byte* result = ring_get_memory_nomove((RingMemory *) ring, size, aligned, zeroed); - pthread_mutex_unlock(&ring->mutex); + coms_pthread_mutex_unlock(&ring->mutex); return result; } @@ -113,9 +113,9 @@ byte* thrd_ring_get_memory_nomove(ThreadedRingMemory* ring, uint64 size, byte al inline byte* thrd_ring_get_element(ThreadedRingMemory* ring, uint64 element, uint64 size) noexcept { - pthread_mutex_lock(&ring->mutex); + coms_pthread_mutex_lock(&ring->mutex); byte* result = ring_get_element((RingMemory *) ring, element, size); - pthread_mutex_unlock(&ring->mutex); + coms_pthread_mutex_unlock(&ring->mutex); return result; } @@ -126,9 +126,9 @@ byte* thrd_ring_get_element(ThreadedRingMemory* ring, uint64 element, uint64 siz inline bool thrd_ring_commit_safe(ThreadedRingMemory* ring, uint64 size, byte aligned = 4) noexcept { - pthread_mutex_lock(&ring->mutex); + coms_pthread_mutex_lock(&ring->mutex); bool result = ring_commit_safe((RingMemory *) ring, size, aligned); - pthread_mutex_unlock(&ring->mutex); + coms_pthread_mutex_unlock(&ring->mutex); return result; } @@ -148,9 +148,9 @@ void thrd_ring_force_tail_update(const ThreadedRingMemory* ring) noexcept inline int64 thrd_ring_dump(ThreadedRingMemory* ring, byte* data) noexcept { - pthread_mutex_lock(&ring->mutex); + coms_pthread_mutex_lock(&ring->mutex); int64 result = ring_dump((RingMemory *) ring, data); - pthread_mutex_unlock(&ring->mutex); + coms_pthread_mutex_unlock(&ring->mutex); return result; } diff --git a/models/Location.h b/models/Location.h index 567a280..9c53b4b 100644 --- a/models/Location.h +++ b/models/Location.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_LOCATION_H -#define TOS_MODELS_LOCATION_H +#ifndef COMS_MODELS_LOCATION_H +#define COMS_MODELS_LOCATION_H #include "../stdlib/Types.h" diff --git a/models/Obj.h b/models/Obj.h index f4ed869..17d2d38 100644 --- a/models/Obj.h +++ b/models/Obj.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_OBJ_H -#define TOS_MODELS_OBJ_H +#ifndef COMS_MODELS_OBJ_H +#define COMS_MODELS_OBJ_H #include "../stdlib/Types.h" diff --git a/models/Sound.h b/models/Sound.h index 0d12b6d..297e6e0 100644 --- a/models/Sound.h +++ b/models/Sound.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_SOUND_H -#define TOS_MODELS_SOUND_H +#ifndef COMS_MODELS_SOUND_H +#define COMS_MODELS_SOUND_H #include "../stdlib/Types.h" diff --git a/models/account/Account.h b/models/account/Account.h index e2b0359..7cc5337 100644 --- a/models/account/Account.h +++ b/models/account/Account.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_ACCOUNT_H -#define TOS_MODELS_ACCOUNT_H +#ifndef COMS_MODELS_ACCOUNT_H +#define COMS_MODELS_ACCOUNT_H #include "../../stdlib/Types.h" diff --git a/models/bracket/Bracket.h b/models/bracket/Bracket.h index c5df59b..49af2b3 100644 --- a/models/bracket/Bracket.h +++ b/models/bracket/Bracket.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_BRACKET_SIMPLE_BRACKET_H -#define TOS_MODELS_BRACKET_SIMPLE_BRACKET_H +#ifndef COMS_MODELS_BRACKET_SIMPLE_BRACKET_H +#define COMS_MODELS_BRACKET_SIMPLE_BRACKET_H #include "BracketTeam.h" #include "BracketSeeding.h" diff --git a/models/bracket/BracketMatch.h b/models/bracket/BracketMatch.h index 6eb7c14..ecdc48d 100644 --- a/models/bracket/BracketMatch.h +++ b/models/bracket/BracketMatch.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_BRACKET_MATCH_H -#define TOS_MODELS_BRACKET_MATCH_H +#ifndef COMS_MODELS_BRACKET_MATCH_H +#define COMS_MODELS_BRACKET_MATCH_H #include "BracketTeam.h" diff --git a/models/bracket/BracketSeeding.h b/models/bracket/BracketSeeding.h index 697fb26..a725af6 100644 --- a/models/bracket/BracketSeeding.h +++ b/models/bracket/BracketSeeding.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_BRACKET_SEEDING_H -#define TOS_MODELS_BRACKET_SEEDING_H +#ifndef COMS_MODELS_BRACKET_SEEDING_H +#define COMS_MODELS_BRACKET_SEEDING_H #include "../../stdlib/Types.h" #include "BracketTeam.h" diff --git a/models/bracket/BracketTeam.h b/models/bracket/BracketTeam.h index f563157..35f19e8 100644 --- a/models/bracket/BracketTeam.h +++ b/models/bracket/BracketTeam.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_BRACKET_TEAM_H -#define TOS_MODELS_BRACKET_TEAM_H +#ifndef COMS_MODELS_BRACKET_TEAM_H +#define COMS_MODELS_BRACKET_TEAM_H #include "../../stdlib/Types.h" diff --git a/models/chat/Chat.h b/models/chat/Chat.h index 195cd76..a376e35 100644 --- a/models/chat/Chat.h +++ b/models/chat/Chat.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_CHAT_H -#define TOS_MODELS_CHAT_H +#ifndef COMS_MODELS_CHAT_H +#define COMS_MODELS_CHAT_H #include "../../stdlib/Types.h" #include "ChatLevel.h" diff --git a/models/chat/ChatLevel.h b/models/chat/ChatLevel.h index 43f6468..2698db1 100644 --- a/models/chat/ChatLevel.h +++ b/models/chat/ChatLevel.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_CHAT_LEVEL_H -#define TOS_MODELS_CHAT_LEVEL_H +#ifndef COMS_MODELS_CHAT_LEVEL_H +#define COMS_MODELS_CHAT_LEVEL_H enum ChatLevel { CHAT_LEVEL_NORMAL, diff --git a/models/chat/ChatStatus.h b/models/chat/ChatStatus.h index e43d1cb..bd623f0 100644 --- a/models/chat/ChatStatus.h +++ b/models/chat/ChatStatus.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_CHAT_STATUS_H -#define TOS_MODELS_CHAT_STATUS_H +#ifndef COMS_MODELS_CHAT_STATUS_H +#define COMS_MODELS_CHAT_STATUS_H enum ChatStatus { CHAT_STATUS_OFFLINE, diff --git a/models/chat/ChatType.h b/models/chat/ChatType.h index ec5694e..fcafd67 100644 --- a/models/chat/ChatType.h +++ b/models/chat/ChatType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_CHAT_TYPE_H -#define TOS_MODELS_CHAT_TYPE_H +#ifndef COMS_MODELS_CHAT_TYPE_H +#define COMS_MODELS_CHAT_TYPE_H #include "../../stdlib/Types.h" diff --git a/models/event/Event.h b/models/event/Event.h index 1442584..52fe1b2 100644 --- a/models/event/Event.h +++ b/models/event/Event.h @@ -1,5 +1,5 @@ -#ifndef TOS_EVENT_H -#define TOS_EVENT_H +#ifndef COMS_EVENT_H +#define COMS_EVENT_H #include "../../stdlib/Types.h" #include "../mob/monster/LootTable.h" diff --git a/models/event/EventTaskType.h b/models/event/EventTaskType.h index 1dbe5b3..9f8d2be 100644 --- a/models/event/EventTaskType.h +++ b/models/event/EventTaskType.h @@ -1,5 +1,5 @@ -#ifndef TOS_QUEST_EVENT_TASK_TYPE_H -#define TOS_QUEST_EVENT_TASK_TYPE_H +#ifndef COMS_QUEST_EVENT_TASK_TYPE_H +#define COMS_QUEST_EVENT_TASK_TYPE_H enum EventTaskType { TASK_COLLECT, // Collect a specific item or set of items diff --git a/models/event/tmp b/models/event/tmp index 1dbe5b3..9f8d2be 100644 --- a/models/event/tmp +++ b/models/event/tmp @@ -1,5 +1,5 @@ -#ifndef TOS_QUEST_EVENT_TASK_TYPE_H -#define TOS_QUEST_EVENT_TASK_TYPE_H +#ifndef COMS_QUEST_EVENT_TASK_TYPE_H +#define COMS_QUEST_EVENT_TASK_TYPE_H enum EventTaskType { TASK_COLLECT, // Collect a specific item or set of items diff --git a/models/extension/ExtensionType.h b/models/extension/ExtensionType.h index f9e328e..5eb572d 100644 --- a/models/extension/ExtensionType.h +++ b/models/extension/ExtensionType.h @@ -1,5 +1,5 @@ -#ifndef TOS_EXTENSION_TYPE_H -#define TOS_EXTENSION_TYPE_H +#ifndef COMS_EXTENSION_TYPE_H +#define COMS_EXTENSION_TYPE_H enum ExtensionType { EXTENSION_TYPE_NONE, diff --git a/models/guild/GuildBanner.h b/models/guild/GuildBanner.h index 04a64e2..78f01c0 100644 --- a/models/guild/GuildBanner.h +++ b/models/guild/GuildBanner.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_GUILD_BANNER_H -#define TOS_MODELS_GUILD_BANNER_H +#ifndef COMS_MODELS_GUILD_BANNER_H +#define COMS_MODELS_GUILD_BANNER_H struct GuildBanner { int shape; diff --git a/models/item/Consumable.h b/models/item/Consumable.h index b610000..ea96260 100644 --- a/models/item/Consumable.h +++ b/models/item/Consumable.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_CONSUMABLE_H -#define TOS_MODELS_CONSUMABLE_H +#ifndef COMS_MODELS_CONSUMABLE_H +#define COMS_MODELS_CONSUMABLE_H #include "../../stdlib/Types.h" diff --git a/models/item/ConsumableType.h b/models/item/ConsumableType.h index dee9e49..423c0f9 100644 --- a/models/item/ConsumableType.h +++ b/models/item/ConsumableType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_CONSUMABLE_TYPE_H -#define TOS_MODELS_CONSUMABLE_TYPE_H +#ifndef COMS_MODELS_CONSUMABLE_TYPE_H +#define COMS_MODELS_CONSUMABLE_TYPE_H #include "../../stdlib/Types.h" diff --git a/models/item/Equipment.cpp b/models/item/Equipment.cpp index ce80276..96e9773 100644 --- a/models/item/Equipment.cpp +++ b/models/item/Equipment.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_EQUIPMENT_C -#define TOS_MODELS_EQUIPMENT_C +#ifndef COMS_MODELS_EQUIPMENT_C +#define COMS_MODELS_EQUIPMENT_C #include #include diff --git a/models/item/Equipment.h b/models/item/Equipment.h index 993f01d..3231951 100644 --- a/models/item/Equipment.h +++ b/models/item/Equipment.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_EQUIPMENT_H -#define TOS_MODELS_EQUIPMENT_H +#ifndef COMS_MODELS_EQUIPMENT_H +#define COMS_MODELS_EQUIPMENT_H #include "../../stdlib/Types.h" diff --git a/models/item/EquipmentType.h b/models/item/EquipmentType.h index 7140424..fcc259d 100644 --- a/models/item/EquipmentType.h +++ b/models/item/EquipmentType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_EQUIPMENT_TYPE_H -#define TOS_MODELS_EQUIPMENT_TYPE_H +#ifndef COMS_MODELS_EQUIPMENT_TYPE_H +#define COMS_MODELS_EQUIPMENT_TYPE_H #include "../../stdlib/Types.h" diff --git a/models/item/Item.h b/models/item/Item.h index c53b906..25b50df 100644 --- a/models/item/Item.h +++ b/models/item/Item.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_ITEM_H -#define TOS_MODELS_ITEM_H +#ifndef COMS_MODELS_ITEM_H +#define COMS_MODELS_ITEM_H #include "../../stdlib/Types.h" diff --git a/models/item/ItemAffixDistribution.h b/models/item/ItemAffixDistribution.h index 7607632..fe4d9e0 100644 --- a/models/item/ItemAffixDistribution.h +++ b/models/item/ItemAffixDistribution.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_ITEM_AFFIX_DISTRIBUTION_H -#define TOS_MODELS_ITEM_AFFIX_DISTRIBUTION_H +#ifndef COMS_MODELS_ITEM_AFFIX_DISTRIBUTION_H +#define COMS_MODELS_ITEM_AFFIX_DISTRIBUTION_H // WARNING: The sum of all mins must be smaller than max count of the whole category // This allows us to define how many phys dmg stats an item should have etc. diff --git a/models/item/ItemLevelStats.h b/models/item/ItemLevelStats.h index 0712fd9..b247716 100644 --- a/models/item/ItemLevelStats.h +++ b/models/item/ItemLevelStats.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_ITEM_LEVEL_STATS_H -#define TOS_MODELS_ITEM_LEVEL_STATS_H +#ifndef COMS_MODELS_ITEM_LEVEL_STATS_H +#define COMS_MODELS_ITEM_LEVEL_STATS_H #include "ItemRarityStats.h" #include "MobLevelStats.h" diff --git a/models/item/ItemRarityDefinition.h b/models/item/ItemRarityDefinition.h index 85f720b..fd34d90 100644 --- a/models/item/ItemRarityDefinition.h +++ b/models/item/ItemRarityDefinition.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_ITEM_RARITY_DEFINITION_H -#define TOS_MODELS_ITEM_RARITY_DEFINITION_H +#ifndef COMS_MODELS_ITEM_RARITY_DEFINITION_H +#define COMS_MODELS_ITEM_RARITY_DEFINITION_H #include "ItemStatsDistribution.h" diff --git a/models/item/ItemRarityStats.h b/models/item/ItemRarityStats.h index 7d430a5..eb43e3d 100644 --- a/models/item/ItemRarityStats.h +++ b/models/item/ItemRarityStats.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_ITEM_RARITY_STATS_H -#define TOS_MODELS_ITEM_RARITY_STATS_H +#ifndef COMS_MODELS_ITEM_RARITY_STATS_H +#define COMS_MODELS_ITEM_RARITY_STATS_H /** * This defines the basic stat range and averge for all item rarities. diff --git a/models/item/ItemStatsDistribution.h b/models/item/ItemStatsDistribution.h index b405441..84f7c42 100644 --- a/models/item/ItemStatsDistribution.h +++ b/models/item/ItemStatsDistribution.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_ITEM_STATS_DISTRIBUTION_H -#define TOS_MODELS_ITEM_STATS_DISTRIBUTION_H +#ifndef COMS_MODELS_ITEM_STATS_DISTRIBUTION_H +#define COMS_MODELS_ITEM_STATS_DISTRIBUTION_H #include "ItemAffixDistribution.h" diff --git a/models/item/MobLevelStats.h b/models/item/MobLevelStats.h index da16cb4..9d35107 100644 --- a/models/item/MobLevelStats.h +++ b/models/item/MobLevelStats.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_ITEM_MOB_LEVEL_STATS_H -#define TOS_MODELS_ITEM_MOB_LEVEL_STATS_H +#ifndef COMS_MODELS_ITEM_MOB_LEVEL_STATS_H +#define COMS_MODELS_ITEM_MOB_LEVEL_STATS_H /** * This defines the bounds for what items can drop based on the mob level. diff --git a/models/item/_equipment_slots.h b/models/item/_equipment_slots.h index 7336167..c29ff98 100644 --- a/models/item/_equipment_slots.h +++ b/models/item/_equipment_slots.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_ITEM_EQUIPMENT_SLOTS_H -#define TOS_MODELS_ITEM_EQUIPMENT_SLOTS_H +#ifndef COMS_MODELS_ITEM_EQUIPMENT_SLOTS_H +#define COMS_MODELS_ITEM_EQUIPMENT_SLOTS_H #define EQUIPMENT_SLOT_SIZE 14 diff --git a/models/item/_equipment_types.h b/models/item/_equipment_types.h index 73c329e..df2c7db 100644 --- a/models/item/_equipment_types.h +++ b/models/item/_equipment_types.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_ITEM_EQUIPMENT_TYPES_H -#define TOS_MODELS_ITEM_EQUIPMENT_TYPES_H +#ifndef COMS_MODELS_ITEM_EQUIPMENT_TYPES_H +#define COMS_MODELS_ITEM_EQUIPMENT_TYPES_H #define EQUIPMENT_TYPE_SIZE 54 diff --git a/models/item/_item_rarity.h b/models/item/_item_rarity.h index 1868eb1..06b1826 100644 --- a/models/item/_item_rarity.h +++ b/models/item/_item_rarity.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_ITEM_RARITY_TYPES_H -#define TOS_MODELS_ITEM_RARITY_TYPES_H +#ifndef COMS_MODELS_ITEM_RARITY_TYPES_H +#define COMS_MODELS_ITEM_RARITY_TYPES_H #define RARITY_TYPE_SIZE 7 diff --git a/models/mob/ActivityStats.h b/models/mob/ActivityStats.h index e4eb10b..04c023b 100644 --- a/models/mob/ActivityStats.h +++ b/models/mob/ActivityStats.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_ACTIVITY_STATS_H -#define TOS_MODELS_MOB_ACTIVITY_STATS_H +#ifndef COMS_MODELS_MOB_ACTIVITY_STATS_H +#define COMS_MODELS_MOB_ACTIVITY_STATS_H #include "../../stdlib/Types.h" diff --git a/models/mob/FixedStats.h b/models/mob/FixedStats.h index 4b7f3e4..2a4fc5e 100644 --- a/models/mob/FixedStats.h +++ b/models/mob/FixedStats.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_SECONDARY_STATS_POINTS_H -#define TOS_MODELS_MOB_SECONDARY_STATS_POINTS_H +#ifndef COMS_MODELS_MOB_SECONDARY_STATS_POINTS_H +#define COMS_MODELS_MOB_SECONDARY_STATS_POINTS_H #include "../stdlib/Types.h" diff --git a/models/mob/Mob.cpp b/models/mob/Mob.cpp index 5404d43..07268ab 100644 --- a/models/mob/Mob.cpp +++ b/models/mob/Mob.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_C -#define TOS_MODELS_MOB_C +#ifndef COMS_MODELS_MOB_C +#define COMS_MODELS_MOB_C #include "Mob.h" #include "MobState.h" diff --git a/models/mob/Mob.h b/models/mob/Mob.h index c2e18c4..ae13182 100644 --- a/models/mob/Mob.h +++ b/models/mob/Mob.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_H -#define TOS_MODELS_MOB_H +#ifndef COMS_MODELS_MOB_H +#define COMS_MODELS_MOB_H #include "../../stdlib/Types.h" diff --git a/models/mob/MobAction.h b/models/mob/MobAction.h index 818d1d0..2331e0f 100644 --- a/models/mob/MobAction.h +++ b/models/mob/MobAction.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_ACTION_H -#define TOS_MODELS_MOB_ACTION_H +#ifndef COMS_MODELS_MOB_ACTION_H +#define COMS_MODELS_MOB_ACTION_H // @todo Consider to create better ranges // This would allow easier checks during the game (e.g. can be healed if > X and < Y) diff --git a/models/mob/MobState.h b/models/mob/MobState.h index 1a93426..dac858a 100644 --- a/models/mob/MobState.h +++ b/models/mob/MobState.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_STATE_H -#define TOS_MODELS_MOB_STATE_H +#ifndef COMS_MODELS_MOB_STATE_H +#define COMS_MODELS_MOB_STATE_H #include "../Location.h" #include "../../stdlib/Types.h" diff --git a/models/mob/MobStats.cpp b/models/mob/MobStats.cpp index 1ae8ef5..b736877 100644 --- a/models/mob/MobStats.cpp +++ b/models/mob/MobStats.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_STATS_C -#define TOS_MODELS_MOB_STATS_C +#ifndef COMS_MODELS_MOB_STATS_C +#define COMS_MODELS_MOB_STATS_C #include "MobStats.h" #include "../../stdlib/Simd.h" diff --git a/models/mob/MobStats.h b/models/mob/MobStats.h index a9ba944..a3fc71b 100644 --- a/models/mob/MobStats.h +++ b/models/mob/MobStats.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_STATS_H -#define TOS_MODELS_MOB_STATS_H +#ifndef COMS_MODELS_MOB_STATS_H +#define COMS_MODELS_MOB_STATS_H #include "../../stdlib/Types.h" #include "PrimaryStatsPoints.h" diff --git a/models/mob/MobStatsType.h b/models/mob/MobStatsType.h index 18fbbf6..409cf05 100644 --- a/models/mob/MobStatsType.h +++ b/models/mob/MobStatsType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_STATS_TYPE_H -#define TOS_MODELS_MOB_STATS_TYPE_H +#ifndef COMS_MODELS_MOB_STATS_TYPE_H +#define COMS_MODELS_MOB_STATS_TYPE_H // physical #define MOB_STATS_TYPE_SLASHING 1 diff --git a/models/mob/PrimaryStatsPoints.cpp b/models/mob/PrimaryStatsPoints.cpp index ca8beff..093b3ef 100644 --- a/models/mob/PrimaryStatsPoints.cpp +++ b/models/mob/PrimaryStatsPoints.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_PRIMARY_STATS_POINTS_C -#define TOS_MODELS_MOB_PRIMARY_STATS_POINTS_C +#ifndef COMS_MODELS_MOB_PRIMARY_STATS_POINTS_C +#define COMS_MODELS_MOB_PRIMARY_STATS_POINTS_C #include "../../stdlib/Simd.h" #include "PrimaryStatsPoints.h" diff --git a/models/mob/PrimaryStatsPoints.h b/models/mob/PrimaryStatsPoints.h index bf2187d..9610ac0 100644 --- a/models/mob/PrimaryStatsPoints.h +++ b/models/mob/PrimaryStatsPoints.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_PRIMARY_STATS_POINTS_H -#define TOS_MODELS_MOB_PRIMARY_STATS_POINTS_H +#ifndef COMS_MODELS_MOB_PRIMARY_STATS_POINTS_H +#define COMS_MODELS_MOB_PRIMARY_STATS_POINTS_H #include "../../stdlib/Types.h" diff --git a/models/mob/SecondaryStatsPoints.cpp b/models/mob/SecondaryStatsPoints.cpp index 0057e34..35da671 100644 --- a/models/mob/SecondaryStatsPoints.cpp +++ b/models/mob/SecondaryStatsPoints.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_SECONDARY_STATS_POINTS_C -#define TOS_MODELS_MOB_SECONDARY_STATS_POINTS_C +#ifndef COMS_MODELS_MOB_SECONDARY_STATS_POINTS_C +#define COMS_MODELS_MOB_SECONDARY_STATS_POINTS_C #include "../../stdlib/Simd.h" #include "SecondaryStatsPoints.h" diff --git a/models/mob/SecondaryStatsPoints.h b/models/mob/SecondaryStatsPoints.h index 46e2e68..abf94a9 100644 --- a/models/mob/SecondaryStatsPoints.h +++ b/models/mob/SecondaryStatsPoints.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_SECONDARY_STATS_POINTS_H -#define TOS_MODELS_MOB_SECONDARY_STATS_POINTS_H +#ifndef COMS_MODELS_MOB_SECONDARY_STATS_POINTS_H +#define COMS_MODELS_MOB_SECONDARY_STATS_POINTS_H #include "../../stdlib/Types.h" #include "MobStatsType.h" diff --git a/models/mob/_mob_category.h b/models/mob/_mob_category.h index 5db643d..fe3265a 100644 --- a/models/mob/_mob_category.h +++ b/models/mob/_mob_category.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_MOB_CATEGORY_H -#define TOS_MODELS_MOB_CATEGORY_H +#ifndef COMS_MODELS_MOB_CATEGORY_H +#define COMS_MODELS_MOB_CATEGORY_H #define MOB_CATEGORY_REGULAR 0x01 #define MOB_CATEGORY_CHAMPION 0x02 diff --git a/models/mob/_mob_list.h b/models/mob/_mob_list.h index 99b10a0..85d164a 100644 --- a/models/mob/_mob_list.h +++ b/models/mob/_mob_list.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_MOB_LIST_H -#define TOS_MODELS_MOB_LIST_H +#ifndef COMS_MODELS_MOB_LIST_H +#define COMS_MODELS_MOB_LIST_H #define MOB_LIST_COW 0x01 #define MOB_LIST_CHICKEN 0x02 diff --git a/models/mob/monster/Drop.h b/models/mob/monster/Drop.h index 34bdab3..b609566 100644 --- a/models/mob/monster/Drop.h +++ b/models/mob/monster/Drop.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_DROP_H -#define TOS_MODELS_MOB_DROP_H +#ifndef COMS_MODELS_MOB_DROP_H +#define COMS_MODELS_MOB_DROP_H #include "../../../stdlib/Types.h" diff --git a/models/mob/monster/LootTable.h b/models/mob/monster/LootTable.h index d9c0900..eb89378 100644 --- a/models/mob/monster/LootTable.h +++ b/models/mob/monster/LootTable.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_LOOT_TABLE_H -#define TOS_MODELS_MOB_LOOT_TABLE_H +#ifndef COMS_MODELS_MOB_LOOT_TABLE_H +#define COMS_MODELS_MOB_LOOT_TABLE_H #include "../../../stdlib/Types.h" #include "../../../utils/Utils.h" diff --git a/models/mob/monster/Monster.h b/models/mob/monster/Monster.h index 1a5155d..30be3d4 100644 --- a/models/mob/monster/Monster.h +++ b/models/mob/monster/Monster.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_MONSTER_H -#define TOS_MODELS_MOB_MONSTER_H +#ifndef COMS_MODELS_MOB_MONSTER_H +#define COMS_MODELS_MOB_MONSTER_H #include "../../../stdlib/Types.h" diff --git a/models/mob/monster/MonsterStats.h b/models/mob/monster/MonsterStats.h index ecbd29e..f2e87ca 100644 --- a/models/mob/monster/MonsterStats.h +++ b/models/mob/monster/MonsterStats.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_MONSTER_STATS_H -#define TOS_MODELS_MOB_MONSTER_STATS_H +#ifndef COMS_MODELS_MOB_MONSTER_STATS_H +#define COMS_MODELS_MOB_MONSTER_STATS_H #include "../../../stdlib/Types.h" diff --git a/models/mob/player/Backpack.h b/models/mob/player/Backpack.h index 168c6cf..f454170 100644 --- a/models/mob/player/Backpack.h +++ b/models/mob/player/Backpack.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_BACKPACK_H -#define TOS_MODELS_BACKPACK_H +#ifndef COMS_MODELS_BACKPACK_H +#define COMS_MODELS_BACKPACK_H #include "../../../stdlib/Types.h" #include "../../item/Item.h" diff --git a/models/mob/player/Guild.h b/models/mob/player/Guild.h index 095cb2d..3fed972 100644 --- a/models/mob/player/Guild.h +++ b/models/mob/player/Guild.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_GUILD_H -#define TOS_MODELS_GUILD_H +#ifndef COMS_MODELS_GUILD_H +#define COMS_MODELS_GUILD_H #include "../../../stdlib/Types.h" diff --git a/models/mob/player/Player.h b/models/mob/player/Player.h index b8a3766..4cdbe62 100644 --- a/models/mob/player/Player.h +++ b/models/mob/player/Player.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_PLAYER_H -#define TOS_MODELS_MOB_PLAYER_H +#ifndef COMS_MODELS_MOB_PLAYER_H +#define COMS_MODELS_MOB_PLAYER_H #include "../../../stdlib/Types.h" diff --git a/models/mob/player/PlayerStats.h b/models/mob/player/PlayerStats.h index a4ab004..f6f8e1b 100644 --- a/models/mob/player/PlayerStats.h +++ b/models/mob/player/PlayerStats.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_PLAYER_STATS_H -#define TOS_MODELS_MOB_PLAYER_STATS_H +#ifndef COMS_MODELS_MOB_PLAYER_STATS_H +#define COMS_MODELS_MOB_PLAYER_STATS_H #include "../../../stdlib/Types.h" diff --git a/models/mob/player/PlayerXPRequirement.h b/models/mob/player/PlayerXPRequirement.h index f986fb5..a5093e6 100644 --- a/models/mob/player/PlayerXPRequirement.h +++ b/models/mob/player/PlayerXPRequirement.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_PLAYER_XP_REQUIREMENT_H -#define TOS_MODELS_MOB_PLAYER_XP_REQUIREMENT_H +#ifndef COMS_MODELS_MOB_PLAYER_XP_REQUIREMENT_H +#define COMS_MODELS_MOB_PLAYER_XP_REQUIREMENT_H #include "../../../stdlib/Types.h" diff --git a/models/mob/player/Reputation.h b/models/mob/player/Reputation.h index 1bfaeda..d52b106 100644 --- a/models/mob/player/Reputation.h +++ b/models/mob/player/Reputation.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_MOB_PLAYER_REPUTATION_H -#define TOS_MODELS_MOB_PLAYER_REPUTATION_H +#ifndef COMS_MODELS_MOB_PLAYER_REPUTATION_H +#define COMS_MODELS_MOB_PLAYER_REPUTATION_H #include "../../../stdlib/Types.h" diff --git a/models/mob/player/_player_class.h b/models/mob/player/_player_class.h index 33a934d..3c1ab71 100644 --- a/models/mob/player/_player_class.h +++ b/models/mob/player/_player_class.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_MOB_PLAYER_CLASS_H -#define TOS_MODELS_MOB_PLAYER_CLASS_H +#ifndef COMS_MODELS_MOB_PLAYER_CLASS_H +#define COMS_MODELS_MOB_PLAYER_CLASS_H #define PLAYER_CLASS_MAGE 1 diff --git a/models/mob/skill/AoeDistribution.h b/models/mob/skill/AoeDistribution.h index 234eac9..263be98 100644 --- a/models/mob/skill/AoeDistribution.h +++ b/models/mob/skill/AoeDistribution.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_SKILL_AOE_DISTRIBUTIOM_H -#define TOS_MODELS_SKILL_AOE_DISTRIBUTIOM_H +#ifndef COMS_MODELS_SKILL_AOE_DISTRIBUTIOM_H +#define COMS_MODELS_SKILL_AOE_DISTRIBUTIOM_H enum AoeDistribution { AOE_DISTRIBUTION_FILL, diff --git a/models/mob/skill/AoeShape.h b/models/mob/skill/AoeShape.h index 001415d..253a354 100644 --- a/models/mob/skill/AoeShape.h +++ b/models/mob/skill/AoeShape.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_SKILL_AOE_SHAPE_H -#define TOS_MODELS_SKILL_AOE_SHAPE_H +#ifndef COMS_MODELS_SKILL_AOE_SHAPE_H +#define COMS_MODELS_SKILL_AOE_SHAPE_H enum AoeShape { AOE_SHAPE_RECTANGLE, diff --git a/models/mob/skill/ProjectileDistribution.h b/models/mob/skill/ProjectileDistribution.h index 01a2d21..85ae4b0 100644 --- a/models/mob/skill/ProjectileDistribution.h +++ b/models/mob/skill/ProjectileDistribution.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_SKILL_PROJECTILE_DISTRIBUTION_H -#define TOS_MODELS_SKILL_PROJECTILE_DISTRIBUTION_H +#ifndef COMS_MODELS_SKILL_PROJECTILE_DISTRIBUTION_H +#define COMS_MODELS_SKILL_PROJECTILE_DISTRIBUTION_H enum ProjectileDistribution { diff --git a/models/mob/skill/Skill.h b/models/mob/skill/Skill.h index 0e126e4..fc20773 100644 --- a/models/mob/skill/Skill.h +++ b/models/mob/skill/Skill.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_SKILL_H -#define TOS_MODELS_SKILL_H +#ifndef COMS_MODELS_SKILL_H +#define COMS_MODELS_SKILL_H #include "../../../stdlib/Types.h" #include "ProjectileDistribution.h" diff --git a/models/mob/skill/StatsTarget.h b/models/mob/skill/StatsTarget.h index d9f0333..c48a62c 100644 --- a/models/mob/skill/StatsTarget.h +++ b/models/mob/skill/StatsTarget.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_SKILL_STATS_TARGET_H -#define TOS_MODELS_SKILL_STATS_TARGET_H +#ifndef COMS_MODELS_SKILL_STATS_TARGET_H +#define COMS_MODELS_SKILL_STATS_TARGET_H enum StatsTarget { STATS_TARGET_NONE, diff --git a/models/object/Block.h b/models/object/Block.h index f6a66bc..8a58852 100644 --- a/models/object/Block.h +++ b/models/object/Block.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_BLOCK_H -#define TOS_MODELS_BLOCK_H +#ifndef COMS_MODELS_BLOCK_H +#define COMS_MODELS_BLOCK_H #include "../../stdlib/Types.h" #include "../../stdlib/SIMD/SIMD_I32.h" diff --git a/models/object/Chunk.h b/models/object/Chunk.h index 6b385a6..36baa3b 100644 --- a/models/object/Chunk.h +++ b/models/object/Chunk.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_OBJECT_CHUNK_H -#define TOS_MODELS_OBJECT_CHUNK_H +#ifndef COMS_MODELS_OBJECT_CHUNK_H +#define COMS_MODELS_OBJECT_CHUNK_H #include "../../stdlib/SIMD/SIMD_I32.h" #include "../../../stdlib/Types.h" diff --git a/models/object/Object.h b/models/object/Object.h index 9e1b230..419bc64 100644 --- a/models/object/Object.h +++ b/models/object/Object.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_OBJECT_H -#define TOS_MODELS_OBJECT_H +#ifndef COMS_MODELS_OBJECT_H +#define COMS_MODELS_OBJECT_H #include "../../../stdlib/Types.h" diff --git a/models/object/ObjectType.h b/models/object/ObjectType.h index 97ac977..f986d40 100644 --- a/models/object/ObjectType.h +++ b/models/object/ObjectType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_Object_TYPE_H -#define TOS_MODELS_Object_TYPE_H +#ifndef COMS_MODELS_Object_TYPE_H +#define COMS_MODELS_Object_TYPE_H #include "../../config.h" #include "../../../stdlib/Types.h" diff --git a/models/object/_object_list.h b/models/object/_object_list.h index 7fe2b84..59eb5ae 100644 --- a/models/object/_object_list.h +++ b/models/object/_object_list.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_OBJECT_LIST_H -#define TOS_MODELS_OBJECT_LIST_H +#ifndef COMS_MODELS_OBJECT_LIST_H +#define COMS_MODELS_OBJECT_LIST_H // (null) #define OBJ_UNASSIGNED 0x00000000 diff --git a/models/object/_object_types.h b/models/object/_object_types.h index 472ae59..7e325f6 100644 --- a/models/object/_object_types.h +++ b/models/object/_object_types.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_OBJECT_TYPES_H -#define TOS_MODELS_OBJECT_TYPES_H +#ifndef COMS_MODELS_OBJECT_TYPES_H +#define COMS_MODELS_OBJECT_TYPES_H #define OBJECT_TYPE_LADDER 0x01 #define OBJECT_TYPE_ROPE 0x02 diff --git a/models/settings/DungeonSettings.h b/models/settings/DungeonSettings.h index ec12a19..1d245b9 100644 --- a/models/settings/DungeonSettings.h +++ b/models/settings/DungeonSettings.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_SETTINGS_DUNGEON_SETTINGS_H -#define TOS_MODELS_SETTINGS_DUNGEON_SETTINGS_H +#ifndef COMS_MODELS_SETTINGS_DUNGEON_SETTINGS_H +#define COMS_MODELS_SETTINGS_DUNGEON_SETTINGS_H #include "../../stdlib/Types.h" #include "ItemDistributionType.h" diff --git a/models/settings/ItemDistributionType.h b/models/settings/ItemDistributionType.h index e78e5ae..f90b731 100644 --- a/models/settings/ItemDistributionType.h +++ b/models/settings/ItemDistributionType.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_SETTINGS_ITEM_DISTRIBUTION_TYPE_H -#define TOS_MODELS_SETTINGS_ITEM_DISTRIBUTION_TYPE_H +#ifndef COMS_MODELS_SETTINGS_ITEM_DISTRIBUTION_TYPE_H +#define COMS_MODELS_SETTINGS_ITEM_DISTRIBUTION_TYPE_H enum ItemDistributionType { ITEM_DISTRIBUTION_TYPE_DEFAULT, // Mix of individual and shared drops diff --git a/models/settings/Settings.h b/models/settings/Settings.h index d0bd7cc..a01d7e0 100644 --- a/models/settings/Settings.h +++ b/models/settings/Settings.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_SETTINGS_H -#define TOS_MODELS_SETTINGS_H +#ifndef COMS_MODELS_SETTINGS_H +#define COMS_MODELS_SETTINGS_H #include "../../stdlib/Types.h" diff --git a/models/settings/setting_types.h b/models/settings/setting_types.h index 4fa22f0..d30e1e0 100644 --- a/models/settings/setting_types.h +++ b/models/settings/setting_types.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODELS_SETTING_TYPES_H -#define TOS_MODELS_SETTING_TYPES_H +#ifndef COMS_MODELS_SETTING_TYPES_H +#define COMS_MODELS_SETTING_TYPES_H enum SettingGpuDetail { SETTING_TYPE_GPU_DETAIL_CUSTOM, diff --git a/module/Module.h b/module/Module.h index 7fb606f..f696a94 100644 --- a/module/Module.h +++ b/module/Module.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODULE_H -#define TOS_MODULE_H +#ifndef COMS_MODULE_H +#define COMS_MODULE_H #include "../stdlib/Types.h" #include "../../GameEngine/system/Library.h" diff --git a/module/ModuleManager.h b/module/ModuleManager.h index b14c4f1..011ec25 100644 --- a/module/ModuleManager.h +++ b/module/ModuleManager.h @@ -1,5 +1,5 @@ -#ifndef TOS_MODULE_MANAGER_H -#define TOS_MODULE_MANAGER_H +#ifndef COMS_MODULE_MANAGER_H +#define COMS_MODULE_MANAGER_H #include "Module.h" #include "../memory/RingMemory.h" diff --git a/network/Server.h b/network/Server.h new file mode 100644 index 0000000..178ac62 --- /dev/null +++ b/network/Server.h @@ -0,0 +1,18 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_NETWORK_SERVER_H +#define COMS_NETWORK_SERVER_H + +#if _WIN32 + #include "../platform/win32/network/Server.h" +#elif __linux__ + #include "../platform/linux/network/Server.h" +#endif + +#endif \ No newline at end of file diff --git a/network/Socket.h b/network/Socket.h index 6524492..04f71d2 100644 --- a/network/Socket.h +++ b/network/Socket.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_NETWORK_SOCKET_H -#define TOS_NETWORK_SOCKET_H +#ifndef COMS_NETWORK_SOCKET_H +#define COMS_NETWORK_SOCKET_H #if _WIN32 #include "../platform/win32/network/Socket.h" diff --git a/network/SocketConnection.h b/network/SocketConnection.h index ce836cc..31eb782 100644 --- a/network/SocketConnection.h +++ b/network/SocketConnection.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_NETWORK_SOCKET_CONNECTION_H -#define TOS_NETWORK_SOCKET_CONNECTION_H +#ifndef COMS_NETWORK_SOCKET_CONNECTION_H +#define COMS_NETWORK_SOCKET_CONNECTION_H #include "../stdlib/Types.h" diff --git a/network/packet/OMSPacket.h b/network/packet/OMSPacket.h index ea20a5a..b7dabb9 100644 --- a/network/packet/OMSPacket.h +++ b/network/packet/OMSPacket.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_OMS_H -#define TOS_NETWORK_PACKET_OMS_H +#ifndef COMS_NETWORK_PACKET_OMS_H +#define COMS_NETWORK_PACKET_OMS_H #include diff --git a/network/packet/PacketCache.h b/network/packet/PacketCache.h index 3964c9d..ae72d32 100644 --- a/network/packet/PacketCache.h +++ b/network/packet/PacketCache.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_NETWORK_PACKET_CACHE_H -#define TOS_NETWORK_PACKET_CACHE_H +#ifndef COMS_NETWORK_PACKET_CACHE_H +#define COMS_NETWORK_PACKET_CACHE_H #include "../../memory/RingMemory.h" #include "../../memory/BufferMemory.h" diff --git a/network/packet/PacketHeader.h b/network/packet/PacketHeader.h index f04d701..2b89c5b 100644 --- a/network/packet/PacketHeader.h +++ b/network/packet/PacketHeader.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_HEADER_H -#define TOS_NETWORK_PACKET_HEADER_H +#ifndef COMS_NETWORK_PACKET_HEADER_H +#define COMS_NETWORK_PACKET_HEADER_H #include diff --git a/network/packet/UDPPacket.h b/network/packet/UDPPacket.h index 04be133..35e4843 100644 --- a/network/packet/UDPPacket.h +++ b/network/packet/UDPPacket.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_UDP_H -#define TOS_NETWORK_PACKET_UDP_H +#ifndef COMS_NETWORK_PACKET_UDP_H +#define COMS_NETWORK_PACKET_UDP_H #include diff --git a/network/packet/chat/ChatMessagePacket.h b/network/packet/chat/ChatMessagePacket.h index b3ed801..904529b 100644 --- a/network/packet/chat/ChatMessagePacket.h +++ b/network/packet/chat/ChatMessagePacket.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_CHAT_MESSAGE_H -#define TOS_NETWORK_PACKET_CHAT_MESSAGE_H +#ifndef COMS_NETWORK_PACKET_CHAT_MESSAGE_H +#define COMS_NETWORK_PACKET_CHAT_MESSAGE_H #include diff --git a/network/packet/general/AckPacket.h b/network/packet/general/AckPacket.h index 203351c..20a459c 100644 --- a/network/packet/general/AckPacket.h +++ b/network/packet/general/AckPacket.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_GENERAL_PING_H -#define TOS_NETWORK_PACKET_GENERAL_PING_H +#ifndef COMS_NETWORK_PACKET_GENERAL_PING_H +#define COMS_NETWORK_PACKET_GENERAL_PING_H #include diff --git a/network/packet/general/PingPacket.h b/network/packet/general/PingPacket.h index 345930f..d0a429e 100644 --- a/network/packet/general/PingPacket.h +++ b/network/packet/general/PingPacket.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_GENERAL_PING_H -#define TOS_NETWORK_PACKET_GENERAL_PING_H +#ifndef COMS_NETWORK_PACKET_GENERAL_PING_H +#define COMS_NETWORK_PACKET_GENERAL_PING_H #include diff --git a/network/packet/mob/MobInfoPacket.h b/network/packet/mob/MobInfoPacket.h index cd4a8ba..a2ac62f 100644 --- a/network/packet/mob/MobInfoPacket.h +++ b/network/packet/mob/MobInfoPacket.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_MOB_INFO_H -#define TOS_NETWORK_PACKET_MOB_INFO_H +#ifndef COMS_NETWORK_PACKET_MOB_INFO_H +#define COMS_NETWORK_PACKET_MOB_INFO_H #include diff --git a/network/packet/mob/MobStatePacket.h b/network/packet/mob/MobStatePacket.h index f440b57..43b861d 100644 --- a/network/packet/mob/MobStatePacket.h +++ b/network/packet/mob/MobStatePacket.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_MOB_STATE_H -#define TOS_NETWORK_PACKET_MOB_STATE_H +#ifndef COMS_NETWORK_PACKET_MOB_STATE_H +#define COMS_NETWORK_PACKET_MOB_STATE_H #include diff --git a/network/packet/mob/player/PlayerInfoPacket.h b/network/packet/mob/player/PlayerInfoPacket.h index e9f60e6..777bd5f 100644 --- a/network/packet/mob/player/PlayerInfoPacket.h +++ b/network/packet/mob/player/PlayerInfoPacket.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_MOB_PLAYER_INFO_H -#define TOS_NETWORK_PACKET_MOB_PLAYER_INFO_H +#ifndef COMS_NETWORK_PACKET_MOB_PLAYER_INFO_H +#define COMS_NETWORK_PACKET_MOB_PLAYER_INFO_H #include diff --git a/network/packet/mob/player/PlayerState.h b/network/packet/mob/player/PlayerState.h index 408c56a..53784a6 100644 --- a/network/packet/mob/player/PlayerState.h +++ b/network/packet/mob/player/PlayerState.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKAGE_PLAYER_STATE_H -#define TOS_NETWORK_PACKAGE_PLAYER_STATE_H +#ifndef COMS_NETWORK_PACKAGE_PLAYER_STATE_H +#define COMS_NETWORK_PACKAGE_PLAYER_STATE_H #include "../../../stdlib/Types.h" diff --git a/network/packet/packet_types.h b/network/packet/packet_types.h index 67be333..ef639ab 100644 --- a/network/packet/packet_types.h +++ b/network/packet/packet_types.h @@ -1,5 +1,5 @@ -#ifndef TOS_NETWORK_PACKET_TYPES_H -#define TOS_NETWORK_PACKET_TYPES_H +#ifndef COMS_NETWORK_PACKET_TYPES_H +#define COMS_NETWORK_PACKET_TYPES_H #define PACKET_TYPE_AUTH 0 #define SUB_PACKET_TYPE_AUTH_LOGIN 0 diff --git a/noise/FractalNoise.h b/noise/FractalNoise.h index 7d8439b..4def56b 100644 --- a/noise/FractalNoise.h +++ b/noise/FractalNoise.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_NOISE_FRACTAL_H -#define TOS_NOISE_FRACTAL_H +#ifndef COMS_NOISE_FRACTAL_H +#define COMS_NOISE_FRACTAL_H #include diff --git a/noise/SimplexNoise.h b/noise/SimplexNoise.h index a4a2a1d..56764d1 100644 --- a/noise/SimplexNoise.h +++ b/noise/SimplexNoise.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_NOISE_SIMPLEX_H -#define TOS_NOISE_SIMPLEX_H +#ifndef COMS_NOISE_SIMPLEX_H +#define COMS_NOISE_SIMPLEX_H #include diff --git a/noise/ValueNoise.h b/noise/ValueNoise.h index dbc61b8..81bee6f 100644 --- a/noise/ValueNoise.h +++ b/noise/ValueNoise.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_NOISE_VALUE_H -#define TOS_NOISE_VALUE_H +#ifndef COMS_NOISE_VALUE_H +#define COMS_NOISE_VALUE_H #include #include diff --git a/noise/WorleyNoise.h b/noise/WorleyNoise.h index cca885f..d044073 100644 --- a/noise/WorleyNoise.h +++ b/noise/WorleyNoise.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_NOISE_WORLEY_H -#define TOS_NOISE_WORLEY_H +#ifndef COMS_NOISE_WORLEY_H +#define COMS_NOISE_WORLEY_H #include #include diff --git a/object/Animation.h b/object/Animation.h index 34d0091..e5c5cef 100644 --- a/object/Animation.h +++ b/object/Animation.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_OBJECT_ANIMATION_H -#define TOS_OBJECT_ANIMATION_H +#ifndef COMS_OBJECT_ANIMATION_H +#define COMS_OBJECT_ANIMATION_H #include "../stdlib/Types.h" #include "../memory/RingMemory.h" diff --git a/object/Hitbox.h b/object/Hitbox.h index 7dbdd3d..6e91b84 100644 --- a/object/Hitbox.h +++ b/object/Hitbox.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_OBJECT_HITBOX_H -#define TOS_OBJECT_HITBOX_H +#ifndef COMS_OBJECT_HITBOX_H +#define COMS_OBJECT_HITBOX_H #include "../stdlib/Types.h" #include "../memory/RingMemory.h" diff --git a/object/Material.h b/object/Material.h index 9e0a57b..b19455c 100644 --- a/object/Material.h +++ b/object/Material.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_OBJECT_MATERIAL_H -#define TOS_OBJECT_MATERIAL_H +#ifndef COMS_OBJECT_MATERIAL_H +#define COMS_OBJECT_MATERIAL_H #include "../stdlib/Types.h" #include "../memory/RingMemory.h" diff --git a/object/Mesh.h b/object/Mesh.h index c96f0dc..db5916c 100644 --- a/object/Mesh.h +++ b/object/Mesh.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_OBJECT_MESH_H -#define TOS_OBJECT_MESH_H +#ifndef COMS_OBJECT_MESH_H +#define COMS_OBJECT_MESH_H #include "Vertex.h" #include "../stdlib/Types.h" diff --git a/object/Texture.h b/object/Texture.h index 3437abf..e6d0d83 100644 --- a/object/Texture.h +++ b/object/Texture.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_MODELS_TEXTURE_H -#define TOS_MODELS_TEXTURE_H +#ifndef COMS_MODELS_TEXTURE_H +#define COMS_MODELS_TEXTURE_H #define TEXTURE_DATA_TYPE_2D 0 #define TEXTURE_DATA_TYPE_1D 1 diff --git a/object/Vertex.h b/object/Vertex.h index 592eba0..4ac55ec 100644 --- a/object/Vertex.h +++ b/object/Vertex.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_OBJECT_VERTEX_H -#define TOS_OBJECT_VERTEX_H +#ifndef COMS_OBJECT_VERTEX_H +#define COMS_OBJECT_VERTEX_H #include "../stdlib/Types.h" diff --git a/particle/Particle.h b/particle/Particle.h index 914cc69..7a1b307 100644 --- a/particle/Particle.h +++ b/particle/Particle.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PARTICLE_H -#define TOS_PARTICLE_H +#ifndef COMS_PARTICLE_H +#define COMS_PARTICLE_H #include "../stdlib/Types.h" diff --git a/pathfinding/Jpsp.h b/pathfinding/Jpsp.h index 1ff59ed..2cdf2be 100644 --- a/pathfinding/Jpsp.h +++ b/pathfinding/Jpsp.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PATHFINDING_JPSP_H -#define TOS_PATHFINDING_JPSP_H +#ifndef COMS_PATHFINDING_JPSP_H +#define COMS_PATHFINDING_JPSP_H #include #include diff --git a/pathfinding/Metric2d.h b/pathfinding/Metric2d.h index f3f05f8..ccb2fd1 100644 --- a/pathfinding/Metric2d.h +++ b/pathfinding/Metric2d.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PATHFINDING_METRIC2D_H -#define TOS_PATHFINDING_METRIC2D_H +#ifndef COMS_PATHFINDING_METRIC2D_H +#define COMS_PATHFINDING_METRIC2D_H #include #include diff --git a/pathfinding/Metric3d.h b/pathfinding/Metric3d.h index 2c384f6..61e340c 100644 --- a/pathfinding/Metric3d.h +++ b/pathfinding/Metric3d.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PATHFINDING_METRIC3D_H -#define TOS_PATHFINDING_METRIC3D_H +#ifndef COMS_PATHFINDING_METRIC3D_H +#define COMS_PATHFINDING_METRIC3D_H #include #include diff --git a/pathfinding/Path.h b/pathfinding/Path.h index 32807a4..dd1d5d4 100644 --- a/pathfinding/Path.h +++ b/pathfinding/Path.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PATHFINDING_PATH_H -#define TOS_PATHFINDING_PATH_H +#ifndef COMS_PATHFINDING_PATH_H +#define COMS_PATHFINDING_PATH_H #include #include diff --git a/pathfinding/jps/Jps.h b/pathfinding/jps/Jps.h index 1a047f1..fa14057 100644 --- a/pathfinding/jps/Jps.h +++ b/pathfinding/jps/Jps.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PATHFINDING_JPS_H -#define TOS_PATHFINDING_JPS_H +#ifndef COMS_PATHFINDING_JPS_H +#define COMS_PATHFINDING_JPS_H #include #include diff --git a/pathfinding/jps/JpsGrid.h b/pathfinding/jps/JpsGrid.h index 01968eb..813f313 100644 --- a/pathfinding/jps/JpsGrid.h +++ b/pathfinding/jps/JpsGrid.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PATHFINDING_JPS_GRID_H -#define TOS_PATHFINDING_JPS_GRID_H +#ifndef COMS_PATHFINDING_JPS_GRID_H +#define COMS_PATHFINDING_JPS_GRID_H #include #include diff --git a/pathfinding/jps/JpsNode.h b/pathfinding/jps/JpsNode.h index 308ea96..d1ebdf4 100644 --- a/pathfinding/jps/JpsNode.h +++ b/pathfinding/jps/JpsNode.h @@ -7,8 +7,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PATHFINDING_JPS_NODE_H -#define TOS_PATHFINDING_JPS_NODE_H +#ifndef COMS_PATHFINDING_JPS_NODE_H +#define COMS_PATHFINDING_JPS_NODE_H #include #include diff --git a/platform/linux/Allocator.h b/platform/linux/Allocator.h index 8c0206c..c13b7a5 100644 --- a/platform/linux/Allocator.h +++ b/platform/linux/Allocator.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_ALLOCATOR_H -#define TOS_PLATFORM_LINUX_ALLOCATOR_H +#ifndef COMS_PLATFORM_LINUX_ALLOCATOR_H +#define COMS_PLATFORM_LINUX_ALLOCATOR_H #include #include @@ -15,6 +15,8 @@ #include #include "../../stdlib/Types.h" #include "../../utils/TestUtils.h" +#include "../../log/DebugMemory.h" +#include "../../log/Stats.h" // @todo Currently alignment only effects the starting position, but it should also effect the ending/size diff --git a/platform/linux/ExceptionHandler.h b/platform/linux/ExceptionHandler.h index e15f97c..a236581 100644 --- a/platform/linux/ExceptionHandler.h +++ b/platform/linux/ExceptionHandler.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_EXCEPTION_HANDLER_H -#define TOS_PLATFORM_LINUX_EXCEPTION_HANDLER_H +#ifndef COMS_PLATFORM_LINUX_EXCEPTION_HANDLER_H +#define COMS_PLATFORM_LINUX_EXCEPTION_HANDLER_H #include #include diff --git a/platform/linux/FileUtils.cpp b/platform/linux/FileUtils.cpp index 93f110e..42034bf 100644 --- a/platform/linux/FileUtils.cpp +++ b/platform/linux/FileUtils.cpp @@ -6,13 +6,14 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_FILE_UTILS_C -#define TOS_PLATFORM_LINUX_FILE_UTILS_C +#ifndef COMS_PLATFORM_LINUX_FILE_UTILS_C +#define COMS_PLATFORM_LINUX_FILE_UTILS_C #include #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ #include "../../stdlib/Types.h" #include "../../utils/Utils.h" #include "../../utils/TestUtils.h" +#include "../../utils/StringUtils.h" #include "../../memory/RingMemory.h" #include "../../log/PerformanceProfiler.h" @@ -44,7 +46,7 @@ void* mmf_region_init(MMFHandle fh, size_t offset, size_t length = 0) { if (length == 0) { struct stat st; if (fstat(fh, &st) != 0) { - return null; + return NULL; } length = st.st_size - offset; @@ -57,10 +59,10 @@ void* mmf_region_init(MMFHandle fh, size_t offset, size_t length = 0) { size_t offset_diff = offset - aligned_offset; size_t map_length = length + offset_diff; - void *mapped_region = mmap(nullptr, map_length, PROT_READ, MAP_PRIVATE, fh, aligned_offset); + void *mapped_region = mmap(NULL, map_length, PROT_READ, MAP_PRIVATE, fh, aligned_offset); if (mapped_region == MAP_FAILED) { - return null; + return NULL; } return (char *) mapped_region + offset_diff; @@ -257,7 +259,7 @@ void file_read(const char* __restrict path, FileBody* __restrict file, RingMemor } ssize_t bytes_read = read(fp, file->content, file->size); - if (bytes_read != file->size) { + if (bytes_read <= 0 || (size_t) bytes_read != file->size) { close(fp); file->content = NULL; file->size = 0; @@ -376,6 +378,47 @@ void self_path(char* path) { } } +void iterate_directory(const char *base_path, const char* file_ending, void (*handler)(const char *, va_list), ...) { + va_list args; + va_start(args, handler); + DIR *dir = opendir(base_path); + if (!dir) { + return; + } + + struct dirent *entry; + while ((entry = readdir(dir)) != NULL) { + if (entry->d_name[0] == '.' + && (entry->d_name[1] == '\0' + || (entry->d_name[1] == '.' && entry->d_name[2] == '\0') + ) + ) { + continue; + } + + char full_path[1024]; + // @performance This is bad, we are internally moving two times too often to the end of full_path + // Maybe make str_copy_short return the length, same as append? + str_copy_short(full_path, base_path); + str_concat_append(full_path, "/"); + str_concat_append(full_path, entry->d_name); + + struct stat statbuf; + if (stat(full_path, &statbuf) == -1) { + continue; + } + + if (S_ISDIR(statbuf.st_mode)) { + iterate_directory(full_path, file_ending, handler, args); + } else if (str_ends_with(full_path, file_ending)) { + handler(full_path, args); + } + } + + closedir(dir); + + va_end(args); +} #endif \ No newline at end of file diff --git a/platform/linux/Library.cpp b/platform/linux/Library.cpp index ffa068d..789527b 100644 --- a/platform/linux/Library.cpp +++ b/platform/linux/Library.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_LIBRARY_C -#define TOS_PLATFORM_LINUX_LIBRARY_C +#ifndef COMS_PLATFORM_LINUX_LIBRARY_C +#define COMS_PLATFORM_LINUX_LIBRARY_C #include #include diff --git a/platform/linux/Library.h b/platform/linux/Library.h index 6350038..d916629 100644 --- a/platform/linux/Library.h +++ b/platform/linux/Library.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_LIBRARY_H -#define TOS_PLATFORM_LINUX_LIBRARY_H +#ifndef COMS_PLATFORM_LINUX_LIBRARY_H +#define COMS_PLATFORM_LINUX_LIBRARY_H typedef void* LibraryHandle; diff --git a/platform/linux/SystemInfo.cpp b/platform/linux/SystemInfo.cpp index cbf9adf..60f51b6 100644 --- a/platform/linux/SystemInfo.cpp +++ b/platform/linux/SystemInfo.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_SYSTEM_INFO_C -#define TOS_PLATFORM_LINUX_SYSTEM_INFO_C +#ifndef COMS_PLATFORM_LINUX_SYSTEM_INFO_C +#define COMS_PLATFORM_LINUX_SYSTEM_INFO_C #include #include diff --git a/platform/linux/TimeUtils.h b/platform/linux/TimeUtils.h new file mode 100644 index 0000000..c05a0d0 --- /dev/null +++ b/platform/linux/TimeUtils.h @@ -0,0 +1,30 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_PLATFORM_LINUX_TIME_UTILS_H +#define COMS_PLATFORM_LINUX_TIME_UTILS_H + +#include +#include +#include "../../stdlib/Types.h" + +uint64 system_time() { + struct timeval tv; + gettimeofday(&tv, NULL); + + return (uint64) tv.tv_sec * 1000000ULL + (uint64) tv.tv_usec; +} + +uint64 time_mu() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + + return (uint64) ts.tv_sec * 1000000ULL + (uint64) (ts.tv_nsec / 1000); +} + +#endif \ No newline at end of file diff --git a/platform/linux/UtilsLinux.h b/platform/linux/UtilsLinux.h index da03af0..d5189de 100644 --- a/platform/linux/UtilsLinux.h +++ b/platform/linux/UtilsLinux.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_UTILS_LINUX_H -#define TOS_UTILS_LINUX_H +#ifndef COMS_UTILS_LINUX_H +#define COMS_UTILS_LINUX_H #include "../../stdlib/Types.h" #include @@ -58,8 +58,4 @@ void clipboard_get(char* text, int32 max_length) XCloseDisplay(display); } -void output_char(char c) { - write(STDOUT_FILENO, &c, 1); -} - #endif \ No newline at end of file diff --git a/platform/linux/network/Server.h b/platform/linux/network/Server.h index f25908a..f0e9c8f 100644 --- a/platform/linux/network/Server.h +++ b/platform/linux/network/Server.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_NETWORK_SERVER_H -#define TOS_PLATFORM_LINUX_NETWORK_SERVER_H +#ifndef COMS_PLATFORM_LINUX_NETWORK_SERVER_H +#define COMS_PLATFORM_LINUX_NETWORK_SERVER_H #include #include @@ -26,77 +26,118 @@ #include "../../../utils/EndianUtils.h" // WARNING: requires `sudo setcap cap_net_raw=eip /path/to/your_program` -void socket_server_raw_create(const char* hostname, SocketConnection* con) { +void socket_server_raw_create(SocketConnection* con) { con->sd = socket(AF_INET6, SOCK_RAW, 255); int32 flags; if ((flags = fcntl(con->sd, F_GETFL, 0)) < 0) { close(con->sd); con->sd = 0; + return; } if (fcntl(con->sd, F_SETFL, flags | O_NONBLOCK) < 0) { close(con->sd); con->sd = 0; + return; } + memset(&con->addr, 0, sizeof(con->addr)); con->addr.sin6_family = AF_INET6; con->addr.sin6_addr = in6addr_any; - con->addr.sin6_port = SWAP_ENDIAN_BIG(con->port); + con->addr.sin6_port = htons(con->port); if (bind(con->sd, (sockaddr *) &con->addr, sizeof(con->addr)) < 0) { close(con->sd); con->sd = 0; + return; } } // WARNING: requires `sudo setcap cap_net_raw=eip /path/to/your_program` -void socket_server_udp_raw_create(const char* hostname, SocketConnection* con) { +void socket_server_udp_raw_create(SocketConnection* con) { con->sd = socket(AF_INET6, SOCK_RAW, IPPROTO_UDP); int32 flags; if ((flags = fcntl(con->sd, F_GETFL, 0)) < 0) { close(con->sd); con->sd = 0; + return; } if (fcntl(con->sd, F_SETFL, flags | O_NONBLOCK) < 0) { close(con->sd); con->sd = 0; + return; } + memset(&con->addr, 0, sizeof(con->addr)); con->addr.sin6_family = AF_INET6; con->addr.sin6_addr = in6addr_any; - con->addr.sin6_port = SWAP_ENDIAN_BIG(con->port); + con->addr.sin6_port = htons(con->port); if (bind(con->sd, (sockaddr *) &con->addr, sizeof(con->addr)) < 0) { close(con->sd); con->sd = 0; + return; } } -void socket_server_udp_create(const char* hostname, SocketConnection* con) { +void socket_server_udp_create(SocketConnection* con) { con->sd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); int32 flags; if ((flags = fcntl(con->sd, F_GETFL, 0)) < 0) { close(con->sd); con->sd = 0; + return; } if (fcntl(con->sd, F_SETFL, flags | O_NONBLOCK) < 0) { close(con->sd); con->sd = 0; + return; } + memset(&con->addr, 0, sizeof(con->addr)); con->addr.sin6_family = AF_INET6; con->addr.sin6_addr = in6addr_any; - con->addr.sin6_port = SWAP_ENDIAN_BIG(con->port); + con->addr.sin6_port = htons(con->port); if (bind(con->sd, (sockaddr *) &con->addr, sizeof(con->addr)) < 0) { close(con->sd); con->sd = 0; + return; } } +bool socket_server_http_create(SocketConnection* con) +{ + // Create socket + con->sd = socket(AF_INET6, SOCK_STREAM, 0); + if (con->sd < 0) { + con->sd = 0; + return false; + } + + // Bind socket + memset(&con->addr, 0, sizeof(con->addr)); + con->addr.sin6_family = AF_INET6; + con->addr.sin6_addr = in6addr_any; + con->addr.sin6_port = htons(con->port); + + if (bind(con->sd, (struct sockaddr *) &con->addr, sizeof(con->addr)) < 0) { + return false; + } + + // Listen for incoming connections + if (listen(con->sd, 5) < 0) { + close(con->sd); + con->sd = 0; + return false; + } + + return true; +} + #endif \ No newline at end of file diff --git a/platform/linux/network/Socket.h b/platform/linux/network/Socket.h index f4fa6a3..c15a7ab 100644 --- a/platform/linux/network/Socket.h +++ b/platform/linux/network/Socket.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_NETWORK_SOCKET_H -#define TOS_PLATFORM_LINUX_NETWORK_SOCKET_H +#ifndef COMS_PLATFORM_LINUX_NETWORK_SOCKET_H +#define COMS_PLATFORM_LINUX_NETWORK_SOCKET_H #define socket_close close diff --git a/platform/linux/threading/Atomic.h b/platform/linux/threading/Atomic.h index dfbbbcf..7150146 100644 --- a/platform/linux/threading/Atomic.h +++ b/platform/linux/threading/Atomic.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_THREADING_ATOMIC_H -#define TOS_PLATFORM_LINUX_THREADING_ATOMIC_H +#ifndef COMS_PLATFORM_LINUX_THREADING_ATOMIC_H +#define COMS_PLATFORM_LINUX_THREADING_ATOMIC_H #if __GNUC__ #include "../../../compiler/gcc/Atomic.h" diff --git a/platform/linux/threading/Semaphore.h b/platform/linux/threading/Semaphore.h index 24e5e88..c92ade9 100644 --- a/platform/linux/threading/Semaphore.h +++ b/platform/linux/threading/Semaphore.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_THREADING_SEMAPHORE_H -#define TOS_PLATFORM_LINUX_THREADING_SEMAPHORE_H +#ifndef COMS_PLATFORM_LINUX_THREADING_SEMAPHORE_H +#define COMS_PLATFORM_LINUX_THREADING_SEMAPHORE_H #include diff --git a/platform/linux/threading/Spinlock.cpp b/platform/linux/threading/Spinlock.cpp index d755f8b..f961659 100644 --- a/platform/linux/threading/Spinlock.cpp +++ b/platform/linux/threading/Spinlock.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_THREADING_SPINLOCK_C -#define TOS_PLATFORM_LINUX_THREADING_SPINLOCK_C +#ifndef COMS_PLATFORM_LINUX_THREADING_SPINLOCK_C +#define COMS_PLATFORM_LINUX_THREADING_SPINLOCK_C #include "../../../stdlib/Types.h" #include "Spinlock.h" diff --git a/platform/linux/threading/Spinlock.h b/platform/linux/threading/Spinlock.h index 488bb38..b0723cb 100644 --- a/platform/linux/threading/Spinlock.h +++ b/platform/linux/threading/Spinlock.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_THREADING_SPINLOCK_H -#define TOS_PLATFORM_LINUX_THREADING_SPINLOCK_H +#ifndef COMS_PLATFORM_LINUX_THREADING_SPINLOCK_H +#define COMS_PLATFORM_LINUX_THREADING_SPINLOCK_H #include "../../../stdlib/Types.h" diff --git a/platform/linux/threading/Thread.h b/platform/linux/threading/Thread.h index fcc9de2..897a5cb 100644 --- a/platform/linux/threading/Thread.h +++ b/platform/linux/threading/Thread.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_THREADING_THREAD_H -#define TOS_PLATFORM_LINUX_THREADING_THREAD_H +#ifndef COMS_PLATFORM_LINUX_THREADING_THREAD_H +#define COMS_PLATFORM_LINUX_THREADING_THREAD_H #include #include @@ -21,148 +21,211 @@ #include "../Allocator.h" #include "ThreadDefines.h" -inline -int32 pthread_create(pthread_t* thread, void *(*start_routine)(void *), void* arg) { - thread->stack = platform_alloc_aligned(1 * MEGABYTE, 64); - if (!thread->stack) { - return -1; +inline int32 futex_wait(int32 *futex, int32 val) { + return syscall(SYS_futex, futex, FUTEX_WAIT, val, NULL, NULL, 0); +} + +inline int32 futex_wake(int32 *futex, int32 n) { + return syscall(SYS_futex, futex, FUTEX_WAKE, n, NULL, NULL, 0); +} + +inline int32 coms_pthread_create(coms_pthread_t* thread, void*, ThreadJobFunc start_routine, void* arg) { + if (thread == NULL || start_routine == NULL) { + return 1; } - thread->stack = clone( - (int32 (*)(void *)) start_routine, - stack + 1 * MEGABYTE, - CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD, - arg - ); - - if (thread->stack == -1) { - platform_aligned_free(thread->stack); - - return -1; + int32 flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM; + *thread = clone((int32 (*)(void*))start_routine, (void*)((char*)malloc(4096) + 4096), flags, arg); + if (*thread == -1) { + return 1; } return 0; } -inline -int32 pthread_join(pthread_t thread, void** retval) { - int32 status; - if (waitpid(thread->id, &status, 0) == -1) { - platform_aligned_free(thread->stack); - - return -1; +inline int32 coms_pthread_join(coms_pthread_t thread, void** retval) { + if (syscall(SYS_waitid, P_PID, thread, retval, WEXITED, NULL) == -1) { + return 1; } + return 0; +} - if (retval) { - *retval = (void *) status; +inline int32 coms_pthread_detach(coms_pthread_t) { + // In Linux, threads are automatically detached when they exit. + return 0; +} + +inline int32 coms_pthread_mutex_init(coms_pthread_mutex_t* mutex, coms_pthread_mutexattr_t*) { + if (mutex == NULL) { + return 1; } - - platform_aligned_free(thread->stack); - + mutex->futex = 0; return 0; } -inline -int32 pthread_mutex_init(pthread_mutex_t* mutex, pthread_mutexattr_t*) { - atomic_set_acquire(mutex, 0); - - return 0; -} - -inline -int32 pthread_mutex_lock(pthread_mutex_t* mutex) { - int32 expected = 0; - while (!atomic_compare_exchange_weak(mutex, &expected, 1)) { - syscall(SYS_futex, mutex, FUTEX_WAIT, 1, NULL, NULL, 0); - expected = 0; +inline int32 coms_pthread_mutex_destroy(coms_pthread_mutex_t* mutex) { + if (mutex == NULL) { + return 1; } - return 0; } -inline -int32 pthread_mutex_unlock(pthread_mutex_t* mutex) { - atomic_set_release(mutex, 0); - syscall(SYS_futex, mutex, FUTEX_WAKE, 1, NULL, NULL, 0); - +inline int32 coms_pthread_mutex_lock(coms_pthread_mutex_t* mutex) { + if (mutex == NULL) { + return 1; + } + while (__atomic_exchange_n(&mutex->futex, 1, __ATOMIC_ACQUIRE) != 0) { + futex_wait(&mutex->futex, 1); + } return 0; } -inline -int32 pthread_cond_init(pthread_cond_t* cond, pthread_condattr_t*) { - atomic_set_release(cond, 0); - +inline int32 coms_pthread_mutex_unlock(coms_pthread_mutex_t* mutex) { + if (mutex == NULL) { + return 1; + } + __atomic_store_n(&mutex->futex, 0, __ATOMIC_RELEASE); + futex_wake(&mutex->futex, 1); return 0; } -inline -int32 pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) { - pthread_mutex_unlock(mutex); - syscall(SYS_futex, cond, FUTEX_WAIT, atomic_get_acquire(cond), NULL, NULL, 0); - pthread_mutex_lock(mutex); - +inline int32 coms_pthread_cond_init(coms_pthread_cond_t* cond, coms_pthread_condattr_t*) { + if (cond == NULL) { + return 1; + } + cond->futex = 0; return 0; } -inline -int32 pthread_cond_signal(pthread_cond_t* cond) { - atomic_fetch_add_acquire(cond, 1); - syscall(SYS_futex, cond, FUTEX_WAKE, 1, NULL, NULL, 0); - +inline int32 coms_pthread_cond_destroy(coms_pthread_cond_t* cond) { + if (cond == NULL) { + return 1; + } return 0; } -inline -int32 pthread_rwlock_init(pthread_rwlock_t* rwlock, const pthread_rwlockattr_t*) { - atomic_set_release((int64 *) &rwlock->readers, 0); - +inline int32 coms_pthread_cond_timedwait(coms_pthread_cond_t* cond, coms_pthread_mutex_t* mutex, const struct timespec*) { + if (cond == NULL || mutex == NULL) { + return 1; + } + int32 oldval = __atomic_load_n(&cond->futex, __ATOMIC_ACQUIRE); + coms_pthread_mutex_unlock(mutex); + futex_wait(&cond->futex, oldval); + coms_pthread_mutex_lock(mutex); return 0; } -inline -int32 pthread_rwlock_rdlock(pthread_rwlock_t* rwlock) { - while (atomic_get_acquire_release(&rwlock->writer)) {} - - atomic_fetch_add_acquire(&rwlock->readers, 1); +inline int32 coms_pthread_cond_wait(coms_pthread_cond_t* cond, coms_pthread_mutex_t* mutex) { + return coms_pthread_cond_timedwait(cond, mutex, NULL); +} +inline int32 coms_pthread_cond_signal(coms_pthread_cond_t* cond) { + if (cond == NULL) { + return 1; + } + __atomic_add_fetch(&cond->futex, 1, __ATOMIC_RELEASE); + futex_wake(&cond->futex, 1); return 0; } -inline -int32 pthread_rwlock_wrlock(pthread_rwlock_t* rwlock) { - while (!atomic_compare_exchange_weak(&rwlock->writer, 0, 1)) {} - +inline int32 coms_pthread_cond_broadcast(coms_pthread_cond_t* cond) { + if (cond == NULL) { + return 1; + } + __atomic_add_fetch(&cond->futex, 1, __ATOMIC_RELEASE); + futex_wake(&cond->futex, INT32_MAX); return 0; } -inline -int32 pthread_rwlock_unlock(pthread_rwlock_t* rwlock) { - if (atomic_get_acquire(&rwlock->writer)) { - atomic_set_release(&rwlock->writer, 0); +inline int32 coms_pthread_rwlock_init(coms_pthread_rwlock_t* rwlock, const coms_pthread_rwlockattr_t*) { + if (rwlock == NULL) { + return 1; + } + rwlock->futex = 0; + rwlock->exclusive = false; + return 0; +} + +inline int32 coms_pthread_rwlock_destroy(coms_pthread_rwlock_t* rwlock) { + if (rwlock == NULL) { + return 1; + } + return 0; +} + +inline int32 coms_pthread_rwlock_rdlock(coms_pthread_rwlock_t* rwlock) { + if (rwlock == NULL) { + return 1; + } + while (1) { + int32 val = __atomic_load_n(&rwlock->futex, __ATOMIC_ACQUIRE); + if (val >= 0 && __atomic_compare_exchange_n(&rwlock->futex, &val, val + 1, false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) { + break; + } + futex_wait(&rwlock->futex, val); + } + return 0; +} + +inline int32 coms_pthread_rwlock_tryrdlock(coms_pthread_rwlock_t* rwlock) { + if (rwlock == NULL) { + return 1; + } + int32 val = __atomic_load_n(&rwlock->futex, __ATOMIC_ACQUIRE); + if (val >= 0 && __atomic_compare_exchange_n(&rwlock->futex, &val, val + 1, false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) { + return 0; + } + return 1; +} + +inline int32 coms_pthread_rwlock_wrlock(coms_pthread_rwlock_t* rwlock) { + if (rwlock == NULL) { + return 1; + } + while (1) { + int32 val = __atomic_load_n(&rwlock->futex, __ATOMIC_ACQUIRE); + if (val == 0 && __atomic_compare_exchange_n(&rwlock->futex, &val, -1, false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) { + rwlock->exclusive = true; + break; + } + futex_wait(&rwlock->futex, val); + } + return 0; +} + +inline int32 coms_pthread_rwlock_trywrlock(coms_pthread_rwlock_t* rwlock) { + if (rwlock == NULL) { + return 1; + } + int32 val = __atomic_load_n(&rwlock->futex, __ATOMIC_ACQUIRE); + if (val == 0 && __atomic_compare_exchange_n(&rwlock->futex, &val, -1, false, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) { + rwlock->exclusive = true; + return 0; + } + return 1; +} + +inline int32 coms_pthread_rwlock_unlock(coms_pthread_rwlock_t* rwlock) { + if (rwlock == NULL) { + return 1; + } + if (rwlock->exclusive) { + rwlock->exclusive = false; + __atomic_store_n(&rwlock->futex, 0, __ATOMIC_RELEASE); + futex_wake(&rwlock->futex, 1); } else { - atomic_fetch_sub_acquire(&rwlock->readers, 1); + int32 val = __atomic_sub_fetch(&rwlock->futex, 1, __ATOMIC_RELEASE); + if (val == 0) { + futex_wake(&rwlock->futex, 1); + } } - return 0; } -inline -int32 pthread_detach(pthread_t) { - // For detached threads, the OS will clean up automatically. We do nothing here. - // Optionally, mark this thread as detached in your data structure if tracking threads. - return 0; +inline uint32 pcthread_get_num_procs() { + return sysconf(_SC_NPROCESSORS_ONLN); } -inline -int32 pthread_rwlock_destroy(pthread_rwlock_t*) -{ - return 0; -} - -inline -uint32 pthread_get_num_procs() -{ - return (uint32) sysconf(_SC_NPROCESSORS_ONLN); -} +#define coms_pthread_exit(a) { return (a); } #endif \ No newline at end of file diff --git a/platform/linux/threading/ThreadDefines.h b/platform/linux/threading/ThreadDefines.h index e5ad3f2..cb982a1 100644 --- a/platform/linux/threading/ThreadDefines.h +++ b/platform/linux/threading/ThreadDefines.h @@ -6,45 +6,34 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_LINUX_THREADING_THREAD_DEFINES_H -#define TOS_PLATFORM_LINUX_THREADING_THREAD_DEFINES_H +#ifndef COMS_PLATFORM_LINUX_THREADING_THREAD_DEFINES_H +#define COMS_PLATFORM_LINUX_THREADING_THREAD_DEFINES_H // #include // #include #include "../../../stdlib/Types.h" -typedef void* (*ThreadJobFunc)(void*); -#define THREAD_RETURN void* +#define THREAD_RETURN int32 +typedef THREAD_RETURN (*ThreadJobFunc)(void*); -typedef volatile int32 pthread_mutex_t; -typedef volatile int32 pthread_cond_t; +typedef struct { + int32 futex; +} coms_pthread_mutex_t; -struct pthread_t { - int32 id; - void* stack; -}; +typedef void coms_pthread_mutexattr_t; +typedef void coms_pthread_condattr_t; +typedef void coms_pthread_rwlockattr_t; -/* -struct pthread_mutex_t { - volatile int32 lock; -}; +typedef struct { + int32 futex; +} coms_pthread_cond_t; -struct pthread_cond_t { - volatile int32 futex; -}; -*/ +typedef struct { + int32 futex; + bool exclusive; +} coms_pthread_rwlock_t; -struct pthread_rwlock_t { - atomic_32 int32 readers; - atomic_32 int32 writer; -}; - -typedef void pthread_mutexattr_t; -typedef void pthread_condattr_t; -typedef void pthread_rwlockattr_t; - -// Thread local variable Already exists in c++11 -// #define thread_local __thread +typedef int coms_pthread_t; #endif \ No newline at end of file diff --git a/platform/win32/Allocator.h b/platform/win32/Allocator.h index 5374090..e2b88b6 100644 --- a/platform/win32/Allocator.h +++ b/platform/win32/Allocator.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_ALLOCATOR_H -#define TOS_PLATFORM_WIN32_ALLOCATOR_H +#ifndef COMS_PLATFORM_WIN32_ALLOCATOR_H +#define COMS_PLATFORM_WIN32_ALLOCATOR_H #include #include diff --git a/platform/win32/Clipboard.h b/platform/win32/Clipboard.h index c50f03a..44262aa 100644 --- a/platform/win32/Clipboard.h +++ b/platform/win32/Clipboard.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_CLIPBOARD_H -#define TOS_PLATFORM_WIN32_CLIPBOARD_H +#ifndef COMS_PLATFORM_WIN32_CLIPBOARD_H +#define COMS_PLATFORM_WIN32_CLIPBOARD_H #include "../../stdlib/Types.h" #include "../../utils/StringUtils.h" diff --git a/platform/win32/ExceptionHandler.h b/platform/win32/ExceptionHandler.h index 7c7a23c..5850bbe 100644 --- a/platform/win32/ExceptionHandler.h +++ b/platform/win32/ExceptionHandler.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_EXCEPTION_HANDLER_H -#define TOS_PLATFORM_WIN32_EXCEPTION_HANDLER_H +#ifndef COMS_PLATFORM_WIN32_EXCEPTION_HANDLER_H +#define COMS_PLATFORM_WIN32_EXCEPTION_HANDLER_H #include #include diff --git a/platform/win32/FastPipes.h b/platform/win32/FastPipes.h index 072ad1e..4db1738 100644 --- a/platform/win32/FastPipes.h +++ b/platform/win32/FastPipes.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_FAST_PIPES_H -#define TOS_PLATFORM_WIN32_FAST_PIPES_H +#ifndef COMS_PLATFORM_WIN32_FAST_PIPES_H +#define COMS_PLATFORM_WIN32_FAST_PIPES_H #include "../stdlib/Types.h" diff --git a/platform/win32/FileUtils.cpp b/platform/win32/FileUtils.cpp index ce83100..b7dcfe8 100644 --- a/platform/win32/FileUtils.cpp +++ b/platform/win32/FileUtils.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_FILE_UTILS_C -#define TOS_PLATFORM_WIN32_FILE_UTILS_C +#ifndef COMS_PLATFORM_WIN32_FILE_UTILS_C +#define COMS_PLATFORM_WIN32_FILE_UTILS_C #include #include @@ -829,4 +829,45 @@ inline void self_path(char* path) GetModuleFileNameA(NULL, (LPSTR) path, MAX_PATH); } +void iterate_directory(const char *base_path, const char* file_ending, void (*handler)(const char *, void *), ...) { + va_list args; + va_start(args, handler); + + WIN32_FIND_DATA find_file_data; + char search_path[MAX_PATH]; + snprintf(search_path, MAX_PATH, "%s\\*", base_path); + + HANDLE hFind = FindFirstFile(search_path, &find_file_data); + if (hFind == INVALID_HANDLE_VALUE) { + return; + } + + do { + if (find_file_data.cFileName[0] == '.' + && (find_file_data.cFileName[1] == '\0' + || (find_file_data.cFileName[1] == '.' && find_file_data.cFileName[2] == '\0') + ) + ) { + continue; + } + + char full_path[MAX_PATH]; + // @performance This is bad, we are internally moving two times too often to the end of full_path + // Maybe make str_copy_short return the length, same as append? + str_copy_short(full_path, base_path); + str_concat_append(full_path, "/"); + str_concat_append(full_path, entry->d_name); + + if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + iterate_directory(full_path, file_ending, handler, args); + } else if (str_ends_with(full_path, file_ending)) { + handler(full_path, args); + } + } while (FindNextFile(hFind, &find_file_data) != 0); + + FindClose(hFind); + + va_end(args); +} + #endif \ No newline at end of file diff --git a/platform/win32/LeanWin32.h b/platform/win32/LeanWin32.h index 0bee680..d678ace 100644 --- a/platform/win32/LeanWin32.h +++ b/platform/win32/LeanWin32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_LEAN_H -#define TOS_PLATFORM_WIN32_LEAN_H +#ifndef COMS_PLATFORM_WIN32_LEAN_H +#define COMS_PLATFORM_WIN32_LEAN_H #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN 1 diff --git a/platform/win32/Library.cpp b/platform/win32/Library.cpp index 03df397..436fc67 100644 --- a/platform/win32/Library.cpp +++ b/platform/win32/Library.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_LIBRARY_C -#define TOS_PLATFORM_WIN32_LIBRARY_C +#ifndef COMS_PLATFORM_WIN32_LIBRARY_C +#define COMS_PLATFORM_WIN32_LIBRARY_C #include #include diff --git a/platform/win32/Library.h b/platform/win32/Library.h index 16bbd26..102b4ea 100644 --- a/platform/win32/Library.h +++ b/platform/win32/Library.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_LIBRARY_H -#define TOS_PLATFORM_WIN32_LIBRARY_H +#ifndef COMS_PLATFORM_WIN32_LIBRARY_H +#define COMS_PLATFORM_WIN32_LIBRARY_H #include diff --git a/platform/win32/SystemInfo.cpp b/platform/win32/SystemInfo.cpp index c381339..4a3b1d1 100644 --- a/platform/win32/SystemInfo.cpp +++ b/platform/win32/SystemInfo.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_SYSTEM_INFO_C -#define TOS_PLATFORM_WIN32_SYSTEM_INFO_C +#ifndef COMS_PLATFORM_WIN32_SYSTEM_INFO_C +#define COMS_PLATFORM_WIN32_SYSTEM_INFO_C #include #include diff --git a/platform/win32/TimeUtils.h b/platform/win32/TimeUtils.h index 18dd7fa..d1db47d 100644 --- a/platform/win32/TimeUtils.h +++ b/platform/win32/TimeUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_TIME_UTILS_H -#define TOS_PLATFORM_WIN32_TIME_UTILS_H +#ifndef COMS_PLATFORM_WIN32_TIME_UTILS_H +#define COMS_PLATFORM_WIN32_TIME_UTILS_H #include #include diff --git a/platform/win32/UtilsWin32.h b/platform/win32/UtilsWin32.h index a0e729a..3879219 100644 --- a/platform/win32/UtilsWin32.h +++ b/platform/win32/UtilsWin32.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_UTILS_H -#define TOS_PLATFORM_WIN32_UTILS_H +#ifndef COMS_PLATFORM_WIN32_UTILS_H +#define COMS_PLATFORM_WIN32_UTILS_H #include "../../stdlib/Types.h" #include "../../utils/StringUtils.h" @@ -31,9 +31,4 @@ uint32 key_to_unicode(byte scan_code, byte vkey, byte keyboard_state[256]) noexc } } -void output_char(char c) { - HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); - WriteFile(hStdout, &c, 1, NULL, NULL); -} - #endif \ No newline at end of file diff --git a/platform/win32/UtilsWindows.h b/platform/win32/UtilsWindows.h index 90ac1a2..6dabad8 100644 --- a/platform/win32/UtilsWindows.h +++ b/platform/win32/UtilsWindows.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_UTILS_WINDOWS_H -#define TOS_PLATFORM_WIN32_UTILS_WINDOWS_H +#ifndef COMS_PLATFORM_WIN32_UTILS_WINDOWS_H +#define COMS_PLATFORM_WIN32_UTILS_WINDOWS_H #include #include "Window.h" diff --git a/platform/win32/Window.h b/platform/win32/Window.h index 3c0429b..6b21930 100644 --- a/platform/win32/Window.h +++ b/platform/win32/Window.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_WINDOW_H -#define TOS_PLATFORM_WIN32_WINDOW_H +#ifndef COMS_PLATFORM_WIN32_WINDOW_H +#define COMS_PLATFORM_WIN32_WINDOW_H #include #include "../../stdlib/Types.h" diff --git a/platform/win32/audio/DirectSound.h b/platform/win32/audio/DirectSound.h index 9724377..0d68f70 100644 --- a/platform/win32/audio/DirectSound.h +++ b/platform/win32/audio/DirectSound.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SOUND_DIRECT_SOUND_H -#define TOS_SOUND_DIRECT_SOUND_H +#ifndef COMS_SOUND_DIRECT_SOUND_H +#define COMS_SOUND_DIRECT_SOUND_H #include #include diff --git a/platform/win32/audio/Wasapi.h b/platform/win32/audio/Wasapi.h index b406f72..ca1350f 100644 --- a/platform/win32/audio/Wasapi.h +++ b/platform/win32/audio/Wasapi.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SOUND_WASAPI_H -#define TOS_SOUND_WASAPI_H +#ifndef COMS_SOUND_WASAPI_H +#define COMS_SOUND_WASAPI_H #include #include diff --git a/platform/win32/audio/XAudio2.h b/platform/win32/audio/XAudio2.h index 62ae8ca..7476f30 100644 --- a/platform/win32/audio/XAudio2.h +++ b/platform/win32/audio/XAudio2.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SOUND_XAUDIO2_H -#define TOS_SOUND_XAUDIO2_H +#ifndef COMS_SOUND_XAUDIO2_H +#define COMS_SOUND_XAUDIO2_H #include #include diff --git a/platform/win32/input/DirectInput.h b/platform/win32/input/DirectInput.h index edc7505..5603774 100644 --- a/platform/win32/input/DirectInput.h +++ b/platform/win32/input/DirectInput.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_INPUT_DIRECTINPUT_H -#define TOS_PLATFORM_WIN32_INPUT_DIRECTINPUT_H +#ifndef COMS_PLATFORM_WIN32_INPUT_DIRECTINPUT_H +#define COMS_PLATFORM_WIN32_INPUT_DIRECTINPUT_H #include #include "../../../input/Input.h" diff --git a/platform/win32/input/HidInput.h b/platform/win32/input/HidInput.h index 787a657..e627a51 100644 --- a/platform/win32/input/HidInput.h +++ b/platform/win32/input/HidInput.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_INPUT_HID_H -#define TOS_PLATFORM_WIN32_INPUT_HID_H +#ifndef COMS_PLATFORM_WIN32_INPUT_HID_H +#define COMS_PLATFORM_WIN32_INPUT_HID_H #include #include diff --git a/platform/win32/input/RawInput.h b/platform/win32/input/RawInput.h index 4e2b5d9..b318e6f 100644 --- a/platform/win32/input/RawInput.h +++ b/platform/win32/input/RawInput.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_INPUT_RAW_H -#define TOS_PLATFORM_WIN32_INPUT_RAW_H +#ifndef COMS_PLATFORM_WIN32_INPUT_RAW_H +#define COMS_PLATFORM_WIN32_INPUT_RAW_H #include diff --git a/platform/win32/input/XInput.h b/platform/win32/input/XInput.h index bf7c011..6c80af4 100644 --- a/platform/win32/input/XInput.h +++ b/platform/win32/input/XInput.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_INPUT_XINPUT_H -#define TOS_PLATFORM_WIN32_INPUT_XINPUT_H +#ifndef COMS_PLATFORM_WIN32_INPUT_XINPUT_H +#define COMS_PLATFORM_WIN32_INPUT_XINPUT_H #include #include diff --git a/platform/win32/input/controller/ControllerHandler.h b/platform/win32/input/controller/ControllerHandler.h index 55fca04..50c2d18 100644 --- a/platform/win32/input/controller/ControllerHandler.h +++ b/platform/win32/input/controller/ControllerHandler.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_INPUT_CONTROLLER_HANDLER_H -#define TOS_PLATFORM_WIN32_INPUT_CONTROLLER_HANDLER_H +#ifndef COMS_PLATFORM_WIN32_INPUT_CONTROLLER_HANDLER_H +#define COMS_PLATFORM_WIN32_INPUT_CONTROLLER_HANDLER_H enum ControllerHandlerType { CONTROLLER_HANDLER_TYPE_AUTO, // Automatically picks a handler based on the device info and hard coded preferences diff --git a/platform/win32/input/controller/DualSense.h b/platform/win32/input/controller/DualSense.h index f1cc39a..51675a0 100644 --- a/platform/win32/input/controller/DualSense.h +++ b/platform/win32/input/controller/DualSense.h @@ -7,8 +7,8 @@ * @link https://jingga.app * @see https://dsremap.readthedocs.io/en/latest/reverse.html */ -#ifndef TOS_PLATFORM_WIN32_INPUT_CONTROLLER_DUALSENSE_H -#define TOS_PLATFORM_WIN32_INPUT_CONTROLLER_DUALSENSE_H +#ifndef COMS_PLATFORM_WIN32_INPUT_CONTROLLER_DUALSENSE_H +#define COMS_PLATFORM_WIN32_INPUT_CONTROLLER_DUALSENSE_H #include "../../../../stdlib/Types.h" #include "../../../../input/ControllerInput.h" diff --git a/platform/win32/input/controller/DualShock4.h b/platform/win32/input/controller/DualShock4.h index 6a35523..0dc75e2 100644 --- a/platform/win32/input/controller/DualShock4.h +++ b/platform/win32/input/controller/DualShock4.h @@ -7,8 +7,8 @@ * @link https://jingga.app * @see https://dsremap.readthedocs.io/en/latest/reverse.html */ -#ifndef TOS_PLATFORM_WIN32_INPUT_CONTROLLER_DUALSHOCK4_H -#define TOS_PLATFORM_WIN32_INPUT_CONTROLLER_DUALSHOCK4_H +#ifndef COMS_PLATFORM_WIN32_INPUT_CONTROLLER_DUALSHOCK4_H +#define COMS_PLATFORM_WIN32_INPUT_CONTROLLER_DUALSHOCK4_H #include "../../../../stdlib/Types.h" #include "../../../../input/ControllerInput.h" diff --git a/platform/win32/network/Client.h b/platform/win32/network/Client.h index 3b25575..43c14fe 100644 --- a/platform/win32/network/Client.h +++ b/platform/win32/network/Client.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_NETWORK_SERVER_H -#define TOS_PLATFORM_WIN32_NETWORK_SERVER_H +#ifndef COMS_PLATFORM_WIN32_NETWORK_SERVER_H +#define COMS_PLATFORM_WIN32_NETWORK_SERVER_H #include #include diff --git a/platform/win32/network/Server.h b/platform/win32/network/Server.h index 3c7a36c..28dcb1a 100644 --- a/platform/win32/network/Server.h +++ b/platform/win32/network/Server.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_NETWORK_SERVER_H -#define TOS_PLATFORM_WIN32_NETWORK_SERVER_H +#ifndef COMS_PLATFORM_WIN32_NETWORK_SERVER_H +#define COMS_PLATFORM_WIN32_NETWORK_SERVER_H #include #include @@ -21,7 +21,7 @@ #pragma comment(lib, "Ws2_32.lib") -void socket_server_udp_create(const char* hostname, SocketConnection* con) { +void socket_server_udp_create(SocketConnection* con) { WSADATA wsaData; // Initialize Winsock @@ -45,9 +45,10 @@ void socket_server_udp_create(const char* hostname, SocketConnection* con) { } // Bind socket + memset(&con->addr, 0, sizeof(con->addr)); con->addr.sin6_family = AF_INET6; con->addr.sin6_addr = in6addr_any; - con->addr.sin6_port = SWAP_ENDIAN_BIG(con->port); + con->addr.sin6_port = htons(con->port); if (bind(con->sd, (struct sockaddr *) &con->addr, sizeof(con->addr)) == SOCKET_ERROR) { closesocket(con->sd); @@ -56,4 +57,42 @@ void socket_server_udp_create(const char* hostname, SocketConnection* con) { } } +bool socket_server_http_create(SocketConnection* con) +{ + WSADATA wsaData; + + // Initialize Winsock + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { + return false; + } + + // Create socket + con->sd = socket(AF_INET6, SOCK_STREAM, 0); + if (con->sd == INVALID_SOCKET) { + WSACleanup(); + return false; + } + + // Bind socket + memset(&con->addr, 0, sizeof(con->addr)); + con->addr.sin6_family = AF_INET6; + con->addr.sin6_addr = in6addr_any; + con->addr.sin6_port = htons(con->port); + + if (bind(con->sd, (struct sockaddr *) &con->addr, sizeof(con->addr)) == SOCKET_ERROR) { + closesocket(con->sd); + WSACleanup(); + return false; + } + + // Listen for incoming connections + if (listen(con->sd, 5) < 0) { + closesocket(con->sd); + WSACleanup(); + return false; + } + + return true; +} + #endif \ No newline at end of file diff --git a/platform/win32/network/Socket.h b/platform/win32/network/Socket.h index 709bb7e..6fa2e95 100644 --- a/platform/win32/network/Socket.h +++ b/platform/win32/network/Socket.h @@ -6,9 +6,9 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_NETWORK_SOCKET_H -#define TOS_PLATFORM_WIN32_NETWORK_SOCKET_H +#ifndef COMS_PLATFORM_WIN32_NETWORK_SOCKET_H +#define COMS_PLATFORM_WIN32_NETWORK_SOCKET_H -#define socket_close closesocket +#define socket_close(sd) closesocket(sd); WSACleanup() #endif \ No newline at end of file diff --git a/platform/win32/threading/Atomic.h b/platform/win32/threading/Atomic.h index b33f5f2..3126afa 100644 --- a/platform/win32/threading/Atomic.h +++ b/platform/win32/threading/Atomic.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_THREADING_ATOMIC_H -#define TOS_PLATFORM_WIN32_THREADING_ATOMIC_H +#ifndef COMS_PLATFORM_WIN32_THREADING_ATOMIC_H +#define COMS_PLATFORM_WIN32_THREADING_ATOMIC_H #include "../../../stdlib/Types.h" #include "../../../compiler/CompilerUtils.h" @@ -126,14 +126,7 @@ FORCE_INLINE void atomic_or_relaxed(volatile int32* value, int32 mask) noexcept FORCE_INLINE void atomic_or_relaxed(volatile uint64* value, uint64 mask) noexcept { InterlockedOr64NoFence((volatile LONG64 *) value, mask); } FORCE_INLINE void atomic_or_relaxed(volatile int64* value, int64 mask) noexcept { InterlockedOr64NoFence((volatile LONG64 *) value, mask); } -FORCE_INLINE void atomic_set_acquire(void** target, void* new_pointer) noexcept { InterlockedExchangePointerAcquire(target, new_pointer); } FORCE_INLINE void* atomic_get_acquire(void** target) noexcept { return InterlockedCompareExchangePointerAcquire(target, NULL, NULL); } -FORCE_INLINE void atomic_set_acquire(volatile int8* value, int8 new_value) noexcept { InterlockedExchangeAcquire8((volatile char *) value, new_value); } -FORCE_INLINE void atomic_set_acquire(volatile int16* value, int16 new_value) noexcept { InterlockedExchangeAcquire16((volatile short *) value, new_value); } -FORCE_INLINE void atomic_set_acquire(volatile int32* value, int32 new_value) noexcept { InterlockedExchangeAcquire((volatile long *) value, new_value); } -FORCE_INLINE void atomic_set_acquire(volatile int64* value, int64 new_value) noexcept { InterlockedExchangeAcquire64((volatile LONG64 *) value, (LONG64) new_value); } -FORCE_INLINE void atomic_set_acquire(volatile f32* value, f32 new_value) noexcept { _atomic_32 temp = {.f = new_value}; InterlockedExchangeAcquire((volatile long *) value, (long) temp.l); } -FORCE_INLINE void atomic_set_acquire(volatile f64* value, f64 new_value) noexcept { _atomic_64 temp = {.f = new_value}; InterlockedExchangeAcquire64((volatile LONG64 *) value, (LONG64) temp.l); } FORCE_INLINE int8 atomic_fetch_set_acquire(volatile int8* value, int8 new_value) noexcept { return (int8) InterlockedExchangeAcquire8((volatile char *) value, (char) new_value); } FORCE_INLINE int16 atomic_fetch_set_acquire(volatile int16* value, int16 new_value) noexcept { return (int16) InterlockedExchangeAcquire16((volatile short *) value, (short) new_value); } FORCE_INLINE int32 atomic_fetch_set_acquire(volatile int32* value, int32 new_value) noexcept { return (int32) InterlockedExchangeAcquire((volatile long *) value, new_value); } diff --git a/platform/win32/threading/Semaphore.h b/platform/win32/threading/Semaphore.h index 0ee0fd1..5d177d6 100644 --- a/platform/win32/threading/Semaphore.h +++ b/platform/win32/threading/Semaphore.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_THREADING_SEMAPHORE_H -#define TOS_PLATFORM_WIN32_THREADING_SEMAPHORE_H +#ifndef COMS_PLATFORM_WIN32_THREADING_SEMAPHORE_H +#define COMS_PLATFORM_WIN32_THREADING_SEMAPHORE_H #include #include "../../../stdlib/Types.h" diff --git a/platform/win32/threading/Spinlock.cpp b/platform/win32/threading/Spinlock.cpp index 0b05388..069855d 100644 --- a/platform/win32/threading/Spinlock.cpp +++ b/platform/win32/threading/Spinlock.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_THREADING_SPINLOCK_C -#define TOS_PLATFORM_WIN32_THREADING_SPINLOCK_C +#ifndef COMS_PLATFORM_WIN32_THREADING_SPINLOCK_C +#define COMS_PLATFORM_WIN32_THREADING_SPINLOCK_C #include #include "../../../stdlib/Types.h" diff --git a/platform/win32/threading/Spinlock.h b/platform/win32/threading/Spinlock.h index 5fa5d23..91bc6a8 100644 --- a/platform/win32/threading/Spinlock.h +++ b/platform/win32/threading/Spinlock.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_THREADING_SPINLOCK_H -#define TOS_PLATFORM_WIN32_THREADING_SPINLOCK_H +#ifndef COMS_PLATFORM_WIN32_THREADING_SPINLOCK_H +#define COMS_PLATFORM_WIN32_THREADING_SPINLOCK_H #include diff --git a/platform/win32/threading/Thread.h b/platform/win32/threading/Thread.h index feba623..4204138 100644 --- a/platform/win32/threading/Thread.h +++ b/platform/win32/threading/Thread.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_THREADING_THREAD_H -#define TOS_PLATFORM_WIN32_THREADING_THREAD_H +#ifndef COMS_PLATFORM_WIN32_THREADING_THREAD_H +#define COMS_PLATFORM_WIN32_THREADING_THREAD_H #include "../../../stdlib/Types.h" #include "../TimeUtils.h" @@ -15,7 +15,7 @@ #include inline -int32 pthread_create(pthread_t* thread, void*, ThreadJobFunc start_routine, void* arg) +int32 coms_pthread_create(coms_pthread_t* thread, void*, ThreadJobFunc start_routine, void* arg) { if (thread == NULL || start_routine == NULL) { return 1; @@ -30,7 +30,7 @@ int32 pthread_create(pthread_t* thread, void*, ThreadJobFunc start_routine, void } inline -int32 pthread_join(pthread_t thread, void**) +int32 coms_pthread_join(coms_pthread_t thread, void**) { WaitForSingleObject(thread, INFINITE); CloseHandle(thread); @@ -39,7 +39,7 @@ int32 pthread_join(pthread_t thread, void**) } inline -int32 pthread_detach(pthread_t thread) +int32 coms_pthread_detach(coms_pthread_t thread) { CloseHandle(thread); @@ -47,7 +47,7 @@ int32 pthread_detach(pthread_t thread) } inline -int32 pthread_mutex_init(pthread_mutex_t* mutex, pthread_mutexattr_t*) +int32 coms_pthread_mutex_init(coms_pthread_mutex_t* mutex, coms_pthread_mutexattr_t*) { if (mutex == NULL) { return 1; @@ -59,7 +59,7 @@ int32 pthread_mutex_init(pthread_mutex_t* mutex, pthread_mutexattr_t*) } inline -int32 pthread_mutex_destroy(pthread_mutex_t* mutex) +int32 coms_pthread_mutex_destroy(coms_pthread_mutex_t* mutex) { if (mutex == NULL) { return 1; @@ -71,7 +71,7 @@ int32 pthread_mutex_destroy(pthread_mutex_t* mutex) } inline -int32 pthread_mutex_lock(pthread_mutex_t* mutex) +int32 coms_pthread_mutex_lock(coms_pthread_mutex_t* mutex) { if (mutex == NULL) { return 1; @@ -83,7 +83,7 @@ int32 pthread_mutex_lock(pthread_mutex_t* mutex) } inline -int32 pthread_mutex_unlock(pthread_mutex_t* mutex) +int32 coms_pthread_mutex_unlock(coms_pthread_mutex_t* mutex) { if (mutex == NULL) { return 1; @@ -96,7 +96,7 @@ int32 pthread_mutex_unlock(pthread_mutex_t* mutex) // WARNING: We don't support windows events since they are much slower than conditional variables/mutexes inline -int32 pthread_cond_init(pthread_cond_t* cond, pthread_condattr_t*) +int32 coms_pthread_cond_init(coms_pthread_cond_t* cond, coms_pthread_condattr_t*) { if (cond == NULL) { return 1; @@ -108,7 +108,7 @@ int32 pthread_cond_init(pthread_cond_t* cond, pthread_condattr_t*) } inline -int32 pthread_cond_destroy(pthread_cond_t*) +int32 coms_pthread_cond_destroy(coms_pthread_cond_t*) { /* Windows does not have a destroy for conditionals */ return 0; @@ -116,7 +116,7 @@ int32 pthread_cond_destroy(pthread_cond_t*) // @question Can't we turn timespec in a typedef of uint64? I would like to avoid the time.h class inline -int32 pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const timespec* abstime) +int32 coms_pthread_cond_timedwait(coms_pthread_cond_t* cond, coms_pthread_mutex_t* mutex, const timespec* abstime) { if (cond == NULL || mutex == NULL) { return 1; @@ -130,17 +130,17 @@ int32 pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const } inline -int32 pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) +int32 coms_pthread_cond_wait(coms_pthread_cond_t* cond, coms_pthread_mutex_t* mutex) { if (cond == NULL || mutex == NULL) { return 1; } - return pthread_cond_timedwait(cond, mutex, NULL); + return coms_pthread_cond_timedwait(cond, mutex, NULL); } inline -int32 pthread_cond_signal(pthread_cond_t* cond) +int32 coms_pthread_cond_signal(coms_pthread_cond_t* cond) { if (cond == NULL) { return 1; @@ -152,7 +152,7 @@ int32 pthread_cond_signal(pthread_cond_t* cond) } inline -int32 pthread_cond_broadcast(pthread_cond_t* cond) +int32 coms_pthread_cond_broadcast(coms_pthread_cond_t* cond) { if (cond == NULL) { return 1; @@ -164,7 +164,7 @@ int32 pthread_cond_broadcast(pthread_cond_t* cond) } inline -int32 pthread_rwlock_init(pthread_rwlock_t* rwlock, const pthread_rwlockattr_t*) +int32 coms_pthread_rwlock_init(coms_pthread_rwlock_t* rwlock, const coms_pthread_rwlockattr_t*) { if (rwlock == NULL) { return 1; @@ -177,13 +177,13 @@ int32 pthread_rwlock_init(pthread_rwlock_t* rwlock, const pthread_rwlockattr_t*) } inline -int32 pthread_rwlock_destroy(pthread_rwlock_t*) +int32 coms_pthread_rwlock_destroy(coms_pthread_rwlock_t*) { return 0; } inline -int32 pthread_rwlock_rdlock(pthread_rwlock_t* rwlock) +int32 coms_pthread_rwlock_rdlock(coms_pthread_rwlock_t* rwlock) { if (rwlock == NULL) { return 1; @@ -195,7 +195,7 @@ int32 pthread_rwlock_rdlock(pthread_rwlock_t* rwlock) } inline -int32 pthread_rwlock_tryrdlock(pthread_rwlock_t* rwlock) +int32 coms_pthread_rwlock_tryrdlock(coms_pthread_rwlock_t* rwlock) { if (rwlock == NULL) { return 1; @@ -205,7 +205,7 @@ int32 pthread_rwlock_tryrdlock(pthread_rwlock_t* rwlock) } inline -int32 pthread_rwlock_wrlock(pthread_rwlock_t* rwlock) +int32 coms_pthread_rwlock_wrlock(coms_pthread_rwlock_t* rwlock) { if (rwlock == NULL) { return 1; @@ -218,7 +218,7 @@ int32 pthread_rwlock_wrlock(pthread_rwlock_t* rwlock) } inline -int32 pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) +int32 coms_pthread_rwlock_trywrlock(coms_pthread_rwlock_t *rwlock) { if (rwlock == NULL) { return 1; @@ -233,7 +233,7 @@ int32 pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) } inline -int32 pthread_rwlock_unlock(pthread_rwlock_t* rwlock) +int32 coms_pthread_rwlock_unlock(coms_pthread_rwlock_t* rwlock) { if (rwlock == NULL) { return 1; @@ -258,6 +258,6 @@ uint32 pcthread_get_num_procs() return sysinfo.dwNumberOfProcessors; } -#define pthread_exit(a) { return (a); } +#define coms_pthread_exit(a) { return (a); } #endif \ No newline at end of file diff --git a/platform/win32/threading/ThreadDefines.h b/platform/win32/threading/ThreadDefines.h index b9b4c53..aaa7795 100644 --- a/platform/win32/threading/ThreadDefines.h +++ b/platform/win32/threading/ThreadDefines.h @@ -6,25 +6,25 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_PLATFORM_WIN32_THREADING_THREAD_DEFINES_H -#define TOS_PLATFORM_WIN32_THREADING_THREAD_DEFINES_H +#ifndef COMS_PLATFORM_WIN32_THREADING_THREAD_DEFINES_H +#define COMS_PLATFORM_WIN32_THREADING_THREAD_DEFINES_H #include "../../../stdlib/Types.h" #include #define THREAD_RETURN DWORD WINAPI typedef DWORD (WINAPI *ThreadJobFunc)(void*); -typedef CRITICAL_SECTION pthread_mutex_t; -typedef void pthread_mutexattr_t; -typedef void pthread_condattr_t; -typedef void pthread_rwlockattr_t; -typedef HANDLE pthread_t; -typedef CONDITION_VARIABLE pthread_cond_t; +typedef CRITICAL_SECTION coms_pthread_mutex_t; +typedef void coms_pthread_mutexattr_t; +typedef void coms_pthread_condattr_t; +typedef void coms_pthread_rwlockattr_t; +typedef HANDLE coms_pthread_t; +typedef CONDITION_VARIABLE coms_pthread_cond_t; // Thread local variable Already exists in c++11 // #define thread_local __declspec(thread) -struct pthread_rwlock_t { +struct coms_pthread_rwlock_t { SRWLOCK lock; bool exclusive; }; diff --git a/scene/SceneInfo.h b/scene/SceneInfo.h index c899421..67876b0 100644 --- a/scene/SceneInfo.h +++ b/scene/SceneInfo.h @@ -1,5 +1,5 @@ -#ifndef TOS_SCENE_INFO_H -#define TOS_SCENE_INFO_H +#ifndef COMS_SCENE_INFO_H +#define COMS_SCENE_INFO_H #include "../stdlib/Types.h" #include "../ui/UILayout.h" diff --git a/sort/BinarySearch.h b/sort/BinarySearch.h index 932aa56..2636c14 100644 --- a/sort/BinarySearch.h +++ b/sort/BinarySearch.h @@ -1,5 +1,5 @@ -#ifndef TOS_SORT_BINARY_SEARCH_H -#define TOS_SORT_BINARY_SEARCH_H +#ifndef COMS_SORT_BINARY_SEARCH_H +#define COMS_SORT_BINARY_SEARCH_H #include "../stdlib/Types.h" diff --git a/sort/EytzingerSearch.h b/sort/EytzingerSearch.h index 0d1bc4e..422ea75 100644 --- a/sort/EytzingerSearch.h +++ b/sort/EytzingerSearch.h @@ -1,5 +1,5 @@ -#ifndef TOS_SORT_EYTZINGER_SEARCH_H -#define TOS_SORT_EYTZINGER_SEARCH_H +#ifndef COMS_SORT_EYTZINGER_SEARCH_H +#define COMS_SORT_EYTZINGER_SEARCH_H #include "../stdlib/Types.h" #include "../memory/RingMemory.h" diff --git a/sort/HeapSort.h b/sort/HeapSort.h index fbb32c9..a50daad 100644 --- a/sort/HeapSort.h +++ b/sort/HeapSort.h @@ -1,5 +1,5 @@ -#ifndef TOS_SORT_HEAP_SORT_H -#define TOS_SORT_HEAP_SORT_H +#ifndef COMS_SORT_HEAP_SORT_H +#define COMS_SORT_HEAP_SORT_H #include "../stdlib/Types.h" #include "../utils/Utils.h" diff --git a/sort/InsertionSort.h b/sort/InsertionSort.h index 4dab7a0..2946d0a 100644 --- a/sort/InsertionSort.h +++ b/sort/InsertionSort.h @@ -1,5 +1,5 @@ -#ifndef TOS_SORT_Insertion_SORT_H -#define TOS_SORT_Insertion_SORT_H +#ifndef COMS_SORT_Insertion_SORT_H +#define COMS_SORT_Insertion_SORT_H #include "../stdlib/Types.h" #include "../utils/Utils.h" diff --git a/sort/IntroSort.h b/sort/IntroSort.h index 3373121..a2f7121 100644 --- a/sort/IntroSort.h +++ b/sort/IntroSort.h @@ -1,5 +1,5 @@ -#ifndef TOS_SORT_INTRO_SORT_H -#define TOS_SORT_INTRO_SORT_H +#ifndef COMS_SORT_INTRO_SORT_H +#define COMS_SORT_INTRO_SORT_H #include "../stdlib/Types.h" #include "InsertionSort.h" diff --git a/sort/QuickSort.h b/sort/QuickSort.h index 56d7325..c304ccf 100644 --- a/sort/QuickSort.h +++ b/sort/QuickSort.h @@ -1,5 +1,5 @@ -#ifndef TOS_SORT_QUICK_SORT_H -#define TOS_SORT_QUICK_SORT_H +#ifndef COMS_SORT_QUICK_SORT_H +#define COMS_SORT_QUICK_SORT_H #include "../stdlib/Types.h" #include "../utils/Utils.h" diff --git a/sort/Sort.h b/sort/Sort.h index 94dd9c1..7318a34 100644 --- a/sort/Sort.h +++ b/sort/Sort.h @@ -1,5 +1,5 @@ -#ifndef TOS_SORT_H -#define TOS_SORT_H +#ifndef COMS_SORT_H +#define COMS_SORT_H #include "../stdlib/Types.h" #include "QuickSort.h" diff --git a/stdlib/HashMap.h b/stdlib/HashMap.h index 778abf7..37a5fa7 100644 --- a/stdlib/HashMap.h +++ b/stdlib/HashMap.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_STDLIB_HASH_MAP_H -#define TOS_STDLIB_HASH_MAP_H +#ifndef COMS_STDLIB_HASH_MAP_H +#define COMS_STDLIB_HASH_MAP_H #include "Types.h" #include "../hash/GeneralHash.h" @@ -25,6 +25,7 @@ ///////////////////////////// // string key ///////////////////////////// +// Next below always represents the index in the chunk memory of the next entry with the same hash (not the byte offset) struct HashEntryInt32 { char key[HASH_MAP_MAX_KEY_LENGTH]; uint16 next; @@ -121,6 +122,7 @@ struct HashMap { ChunkMemory buf; }; +// @todo Change so the hashmap can grow or maybe even better create a static and dynamic version inline void hashmap_alloc(HashMap* hm, int32 count, int32 element_size) { @@ -531,7 +533,7 @@ void hashmap_remove(HashMap* hm, const char* key) noexcept { // int key ///////////////////////////// void hashmap_insert(HashMap* hm, int32 key, int32 value) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; int32 element = chunk_reserve(&hm->buf, 1); HashEntryInt32KeyInt32* entry = (HashEntryInt32KeyInt32 *) chunk_get_element(&hm->buf, element, true); @@ -549,7 +551,7 @@ void hashmap_insert(HashMap* hm, int32 key, int32 value) noexcept { } void hashmap_insert(HashMap* hm, int32 key, int64 value) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; int32 element = chunk_reserve(&hm->buf, 1); HashEntryInt64KeyInt32* entry = (HashEntryInt64KeyInt32 *) chunk_get_element(&hm->buf, element, true); @@ -567,7 +569,7 @@ void hashmap_insert(HashMap* hm, int32 key, int64 value) noexcept { } void hashmap_insert(HashMap* hm, int32 key, uintptr_t value) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; int32 element = chunk_reserve(&hm->buf, 1); HashEntryUIntPtrKeyInt32* entry = (HashEntryUIntPtrKeyInt32 *) chunk_get_element(&hm->buf, element, true); @@ -585,7 +587,7 @@ void hashmap_insert(HashMap* hm, int32 key, uintptr_t value) noexcept { } void hashmap_insert(HashMap* hm, int32 key, void* value) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; int32 element = chunk_reserve(&hm->buf, 1); HashEntryVoidPKeyInt32* entry = (HashEntryVoidPKeyInt32 *) chunk_get_element(&hm->buf, element, true); @@ -603,7 +605,7 @@ void hashmap_insert(HashMap* hm, int32 key, void* value) noexcept { } void hashmap_insert(HashMap* hm, int32 key, f32 value) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; int32 element = chunk_reserve(&hm->buf, 1); HashEntryFloatKeyInt32* entry = (HashEntryFloatKeyInt32 *) chunk_get_element(&hm->buf, element, true); @@ -621,7 +623,7 @@ void hashmap_insert(HashMap* hm, int32 key, f32 value) noexcept { } void hashmap_insert(HashMap* hm, int32 key, const char* value) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; int32 element = chunk_reserve(&hm->buf, 1); HashEntryStrKeyInt32* entry = (HashEntryStrKeyInt32 *) chunk_get_element(&hm->buf, element, true); @@ -642,7 +644,7 @@ void hashmap_insert(HashMap* hm, int32 key, const char* value) noexcept { } void hashmap_insert(HashMap* hm, int32 key, byte* value) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; int32 element = chunk_reserve(&hm->buf, 1); HashEntryKeyInt32* entry = (HashEntryKeyInt32 *) chunk_get_element(&hm->buf, element, true); @@ -663,7 +665,7 @@ void hashmap_insert(HashMap* hm, int32 key, byte* value) noexcept { } HashEntryKeyInt32* hashmap_get_entry(HashMap* hm, int32 key) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; HashEntryKeyInt32* entry = (HashEntryKeyInt32 *) chunk_get_element(&hm->buf, hm->table[index] - 1, false); while (entry != NULL) { @@ -672,7 +674,7 @@ HashEntryKeyInt32* hashmap_get_entry(HashMap* hm, int32 key) noexcept { return entry; } - entry = (HashEntryKeyInt32 *) entry->next; + entry = (HashEntryKeyInt32 *) chunk_get_element(&hm->buf, entry->next - 1, false); } return NULL; @@ -690,7 +692,7 @@ HashEntryKeyInt32* hashmap_get_entry(HashMap* hm, int32 key, uint64 hash) noexce return entry; } - entry = (HashEntryKeyInt32 *) entry->next; + entry = (HashEntryKeyInt32 *) chunk_get_element(&hm->buf, entry->next - 1, false); } return NULL; @@ -700,7 +702,7 @@ HashEntryKeyInt32* hashmap_get_entry(HashMap* hm, int32 key, uint64 hash) noexce // However that would make insertion slower // Maybe we create a nother hashmap that is doubly linked void hashmap_remove(HashMap* hm, int32 key) noexcept { - uint64 index = key % hm->buf.count; + uint64 index = ((uint32) key) % hm->buf.count; HashEntryKeyInt32* entry = (HashEntryKeyInt32 *) chunk_get_element(&hm->buf, hm->table[index] - 1, false); HashEntryKeyInt32* prev = NULL; diff --git a/stdlib/PerfectHashMap.h b/stdlib/PerfectHashMap.h index 56bba62..7af5124 100644 --- a/stdlib/PerfectHashMap.h +++ b/stdlib/PerfectHashMap.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_STDLIB_PERFECT_HASH_MAP_H -#define TOS_STDLIB_PERFECT_HASH_MAP_H +#ifndef COMS_STDLIB_PERFECT_HASH_MAP_H +#define COMS_STDLIB_PERFECT_HASH_MAP_H #include "Types.h" #include "HashMap.h" @@ -26,38 +26,40 @@ const PerfectHashFunction PERFECT_HASH_FUNCTIONS[] = { hash_ejb_seeded }; +#define PERFECT_HASH_MAP_MAX_KEY_LENGTH 28 + struct PerfectHashEntryInt32 { - char key[HASH_MAP_MAX_KEY_LENGTH]; + char key[PERFECT_HASH_MAP_MAX_KEY_LENGTH]; int32 value; }; struct PerfectHashEntryInt64 { - char key[HASH_MAP_MAX_KEY_LENGTH]; + char key[PERFECT_HASH_MAP_MAX_KEY_LENGTH]; int64 value; }; struct PerfectHashEntryUIntPtr { - char key[HASH_MAP_MAX_KEY_LENGTH]; + char key[PERFECT_HASH_MAP_MAX_KEY_LENGTH]; uintptr_t value; }; struct PerfectHashEntryVoidP { - char key[HASH_MAP_MAX_KEY_LENGTH]; + char key[PERFECT_HASH_MAP_MAX_KEY_LENGTH]; void* value; }; struct PerfectHashEntryFloat { - char key[HASH_MAP_MAX_KEY_LENGTH]; + char key[PERFECT_HASH_MAP_MAX_KEY_LENGTH]; f32 value; }; struct PerfectHashEntryStr { - char key[HASH_MAP_MAX_KEY_LENGTH]; - char value[HASH_MAP_MAX_KEY_LENGTH]; + char key[PERFECT_HASH_MAP_MAX_KEY_LENGTH]; + char value[PERFECT_HASH_MAP_MAX_KEY_LENGTH]; }; struct PerfectHashEntry { - char key[HASH_MAP_MAX_KEY_LENGTH]; + char key[PERFECT_HASH_MAP_MAX_KEY_LENGTH]; byte* value; }; @@ -66,26 +68,26 @@ struct PerfectHashMap { PerfectHashFunction hash_function; uint32 entry_size; - uint32 map_size; + uint32 map_count; byte* hash_entries; }; -PerfectHashMap* perfect_hashmap_prepare(PerfectHashMap* hm, const char** keys, int32 key_count, int32 seed_trys, RingMemory* ring) +PerfectHashMap* perfect_hashmap_prepare(PerfectHashMap* hm, const char** keys, int32 key_count, int32 seed_tries, RingMemory* ring) { - int32* indices = (int32 *) ring_get_memory(ring, hm->map_size * sizeof(int32), 4); + int32* indices = (int32 *) ring_get_memory(ring, hm->map_count * sizeof(int32), 4); bool is_unique = false; - for (int32 i = 0; i < ARRAY_COUNT(PERFECT_HASH_FUNCTIONS); ++i) { + for (uint32 i = 0; i < ARRAY_COUNT(PERFECT_HASH_FUNCTIONS); ++i) { int32 seed; int32 c = 0; - while (!is_unique && c < seed_trys) { + while (!is_unique && c < seed_tries) { is_unique = true; seed = rand(); - memset(indices, 0, hm->map_size * sizeof(int32)); + memset(indices, 0, hm->map_count * sizeof(int32)); for (int32 j = 0; j < key_count; ++j) { - int32 index = (PERFECT_HASH_FUNCTIONS[i])(keys[j], seed) % hm->map_size; + int32 index = (PERFECT_HASH_FUNCTIONS[i])(keys[j], seed) % hm->map_count; if (indices[index]) { is_unique = false; break; @@ -105,6 +107,8 @@ PerfectHashMap* perfect_hashmap_prepare(PerfectHashMap* hm, const char** keys, i } } + ASSERT_SIMPLE(false); + return NULL; } @@ -112,7 +116,7 @@ PerfectHashMap* perfect_hashmap_prepare(PerfectHashMap* hm, const char** keys, i void perfect_hashmap_create(PerfectHashMap* hm, int32 count, int32 element_size, BufferMemory* buf) { LOG_1("Create PerfectHashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); - hm->map_size = count; + hm->map_count = count; hm->entry_size = element_size; hm->hash_entries = buffer_get_memory( buf, @@ -125,27 +129,28 @@ void perfect_hashmap_create(PerfectHashMap* hm, int32 count, int32 element_size, void perfect_hashmap_create(PerfectHashMap* hm, int32 count, int32 element_size, byte* buf) { LOG_1("Create PerfectHashMap for %n elements with %n B per element", {{LOG_DATA_INT32, &count}, {LOG_DATA_INT32, &element_size}}); - hm->map_size = count; + hm->map_count = count; hm->entry_size = element_size; hm->hash_entries = buf; } // Calculates how large a hashmap will be inline -int64 perfect_hashmap_size(int count, int32 element_size) +int64 perfect_hashmap_count(int count, int32 element_size) { return count * element_size; } inline -int64 perfect_hashmap_size(const PerfectHashMap* hm) +int64 perfect_hashmap_count(const PerfectHashMap* hm) { - return hm->entry_size * hm->map_size; + return hm->entry_size * hm->map_count; } +// @bug the insert functions don't handle too long keys like the HashMap does inline void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, int32 value) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntryInt32* entry = (PerfectHashEntryInt32 *) (hm->hash_entries + hm->entry_size * index); str_copy_short(entry->key, key); entry->value = value; @@ -153,7 +158,7 @@ void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, int32 value) { inline void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, int64 value) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntryInt64* entry = (PerfectHashEntryInt64 *) (hm->hash_entries + hm->entry_size * index); str_copy_short(entry->key, key); entry->value = value; @@ -161,7 +166,7 @@ void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, int64 value) { inline void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, uintptr_t value) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntryUIntPtr* entry = (PerfectHashEntryUIntPtr *) (hm->hash_entries + hm->entry_size * index); str_copy_short(entry->key, key); entry->value = value; @@ -169,7 +174,7 @@ void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, uintptr_t value inline void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, void* value) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntryVoidP* entry = (PerfectHashEntryVoidP *) (hm->hash_entries + hm->entry_size * index); str_copy_short(entry->key, key); entry->value = value; @@ -177,7 +182,7 @@ void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, void* value) { inline void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, f32 value) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntryFloat* entry = (PerfectHashEntryFloat *) (hm->hash_entries + hm->entry_size * index); str_copy_short(entry->key, key); entry->value = value; @@ -185,15 +190,15 @@ void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, f32 value) { inline void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, const char* value) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntryStr* entry = (PerfectHashEntryStr *) (hm->hash_entries + hm->entry_size * index); str_copy_short(entry->key, key); - memcpy(entry->value, value, HASH_MAP_MAX_KEY_LENGTH); + str_copy_short(entry->value, value, PERFECT_HASH_MAP_MAX_KEY_LENGTH); } inline void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, byte* value) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntryStr* entry = (PerfectHashEntryStr *) (hm->hash_entries + hm->entry_size * index); str_copy_short(entry->key, key); memcpy(entry->value, value, hm->entry_size - sizeof(PerfectHashEntry)); @@ -201,7 +206,7 @@ void perfect_hashmap_insert(PerfectHashMap* hm, const char* key, byte* value) { inline PerfectHashEntry* perfect_hashmap_get_entry(const PerfectHashMap* hm, const char* key) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntry* entry = (PerfectHashEntry *) (hm->hash_entries + hm->entry_size * index); return str_compare(entry->key, key) == 0 ? entry : NULL; @@ -209,7 +214,7 @@ PerfectHashEntry* perfect_hashmap_get_entry(const PerfectHashMap* hm, const char inline void perfect_hashmap_delete_entry(PerfectHashMap* hm, const char* key) { - int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_size; + int32 index = hm->hash_function(key, hm->hash_seed) % hm->map_count; PerfectHashEntry* entry = (PerfectHashEntry *) (hm->hash_entries + hm->entry_size * index); if (str_compare(entry->key, key) != 0) { @@ -226,13 +231,13 @@ int64 perfect_hashmap_dump(const PerfectHashMap* hm, byte* data) { byte* start = data; - *((int32 *) data) = SWAP_ENDIAN_LITTLE(hm->map_size); - data += sizeof(hm->map_size); + *((int32 *) data) = SWAP_ENDIAN_LITTLE(hm->map_count); + data += sizeof(hm->map_count); *((int32 *) data) = SWAP_ENDIAN_LITTLE(hm->hash_seed); data += sizeof(hm->hash_seed); - for (int32 i = 0; i < ARRAY_COUNT(PERFECT_HASH_FUNCTIONS); ++i) { + for (uint32 i = 0; i < ARRAY_COUNT(PERFECT_HASH_FUNCTIONS); ++i) { if (hm->hash_function == PERFECT_HASH_FUNCTIONS[i]) { *((int32 *) data) = SWAP_ENDIAN_LITTLE((uint64) i); data += sizeof(i); @@ -244,8 +249,8 @@ int64 perfect_hashmap_dump(const PerfectHashMap* hm, byte* data) *((int32 *) data) = SWAP_ENDIAN_LITTLE(hm->entry_size); data += sizeof(hm->entry_size); - memcpy(data, hm->hash_entries, hm->map_size * hm->entry_size); - data += hm->map_size * hm->entry_size; + memcpy(data, hm->hash_entries, hm->map_count * hm->entry_size); + data += hm->map_count * hm->entry_size; return (int64) (data - start); } @@ -256,8 +261,8 @@ int64 perfect_hashmap_load(PerfectHashMap* hm, const byte* data) { const byte* start = data; - hm->map_size = SWAP_ENDIAN_LITTLE(*((int32 *) data)); - data += sizeof(hm->map_size); + hm->map_count = SWAP_ENDIAN_LITTLE(*((int32 *) data)); + data += sizeof(hm->map_count); hm->hash_seed = SWAP_ENDIAN_LITTLE(*((int32 *) data)); data += sizeof(hm->hash_seed); @@ -268,17 +273,17 @@ int64 perfect_hashmap_load(PerfectHashMap* hm, const byte* data) hm->entry_size = SWAP_ENDIAN_LITTLE(*((int32 *) data)); data += sizeof(hm->entry_size); - memcpy(hm->hash_entries, data, hm->map_size * hm->entry_size); - data += hm->map_size * hm->entry_size; + memcpy(hm->hash_entries, data, hm->map_count * hm->entry_size); + data += hm->map_count * hm->entry_size; return (int64) (data - start); } // WARNiNG: Requires the phm to be initialized already incl. element count and element size etc. inline -bool perfect_hashmap_from_hashmap(PerfectHashMap* phm, const HashMap* hm, int32 seed_trys, RingMemory* ring) +bool perfect_hashmap_from_hashmap(PerfectHashMap* phm, const HashMap* hm, int32 seed_tries, RingMemory* ring) { - const char** keys = (char **) ring_get_memory(ring, sizeof(char *) * hm->buf.count, 8); + char** keys = (char **) ring_get_memory(ring, sizeof(char *) * hm->buf.count, 8); // Find all keys int32 key_index = 0; @@ -289,7 +294,7 @@ bool perfect_hashmap_from_hashmap(PerfectHashMap* phm, const HashMap* hm, int32 } chunk_iterate_end; // Check if we can turn it into a perfect hash map - PerfectHashMap* is_perfect = perfect_hashmap_prepare(phm, keys, key_index, seed_trys, ring); + PerfectHashMap* is_perfect = perfect_hashmap_prepare(phm, (const char**) keys, key_index, seed_tries, ring); if (!is_perfect) { return false; } diff --git a/stdlib/Simd.h b/stdlib/Simd.h index 0aee0aa..44d87e4 100644 --- a/stdlib/Simd.h +++ b/stdlib/Simd.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_STDLIB_SIMD_H -#define TOS_STDLIB_SIMD_H +#ifndef COMS_STDLIB_SIMD_H +#define COMS_STDLIB_SIMD_H // Adjusts the step size based on the memory alignment inline diff --git a/stdlib/ThreadedHashMap.h b/stdlib/ThreadedHashMap.h index 4b4de93..c64ada8 100644 --- a/stdlib/ThreadedHashMap.h +++ b/stdlib/ThreadedHashMap.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_STDLIB_THREADED_HASH_MAP_H -#define TOS_STDLIB_THREADED_HASH_MAP_H +#ifndef COMS_STDLIB_THREADED_HASH_MAP_H +#define COMS_STDLIB_THREADED_HASH_MAP_H #include "../stdlib/Types.h" #include "HashMap.h" @@ -20,7 +20,7 @@ struct ThreadedHashMap { void** table; ChunkMemory buf; - pthread_mutex_t mutex; + coms_pthread_mutex_t mutex; }; // WARNING: element_size = element size + remaining HashEntry data size @@ -28,7 +28,7 @@ inline void thrd_hashmap_create(ThreadedHashMap* hm, int32 count, int32 element_size, RingMemory* ring) { hashmap_create((HashMap *) hm, count, element_size, ring); - pthread_mutex_init(&hm->mutex, NULL); + coms_pthread_mutex_init(&hm->mutex, NULL); } // WARNING: element_size = element size + remaining HashEntry data size @@ -36,7 +36,7 @@ inline void thrd_hashmap_create(ThreadedHashMap* hm, int32 count, int32 element_size, BufferMemory* buf) { hashmap_create((HashMap *) hm, count, element_size, buf); - pthread_mutex_init(&hm->mutex, NULL); + coms_pthread_mutex_init(&hm->mutex, NULL); } // WARNING: element_size = element size + remaining HashEntry data size @@ -44,85 +44,85 @@ inline void thrd_hashmap_create(ThreadedHashMap* hm, int32 count, int32 element_size, byte* buf) { hashmap_create((HashMap *) hm, count, element_size, buf); - pthread_mutex_init(&hm->mutex, NULL); + coms_pthread_mutex_init(&hm->mutex, NULL); } inline void thrd_hashmap_free(ThreadedHashMap* hm) { - pthread_mutex_destroy(&hm->mutex); + coms_pthread_mutex_destroy(&hm->mutex); } inline void thrd_hashmap_insert(ThreadedHashMap* hm, const char* key, int32 value) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); hashmap_insert((HashMap *) hm, key, value); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_insert(ThreadedHashMap* hm, const char* key, int64 value) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); hashmap_insert((HashMap *) hm, key, value); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_insert(ThreadedHashMap* hm, const char* key, uintptr_t value) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); hashmap_insert((HashMap *) hm, key, value); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_insert(ThreadedHashMap* hm, const char* key, void* value) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); hashmap_insert((HashMap *) hm, key, value); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_insert(ThreadedHashMap* hm, const char* key, f32 value) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); hashmap_insert((HashMap *) hm, key, value); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_insert(ThreadedHashMap* hm, const char* key, const char* value) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); hashmap_insert((HashMap *) hm, key, value); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_insert(ThreadedHashMap* hm, const char* key, byte* value) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); hashmap_insert((HashMap *) hm, key, value); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_get_entry(ThreadedHashMap* hm, HashEntry* entry, const char* key) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); HashEntry* temp = hashmap_get_entry((HashMap *) hm, key); memcpy(entry, temp, hm->buf.chunk_size); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_get_entry(ThreadedHashMap* hm, HashEntry* entry, const char* key, uint64 index) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); HashEntry* temp = hashmap_get_entry((HashMap *) hm, key, index); memcpy(entry, temp, hm->buf.chunk_size); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } inline void thrd_hashmap_remove(ThreadedHashMap* hm, const char* key) { - pthread_mutex_lock(&hm->mutex); + coms_pthread_mutex_lock(&hm->mutex); hashmap_remove((HashMap *) hm, key); - pthread_mutex_unlock(&hm->mutex); + coms_pthread_mutex_unlock(&hm->mutex); } #endif \ No newline at end of file diff --git a/stdlib/Types.h b/stdlib/Types.h index ef5e124..3bf7808 100644 --- a/stdlib/Types.h +++ b/stdlib/Types.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_STDLIB_TYPES_H -#define TOS_STDLIB_TYPES_H +#ifndef COMS_STDLIB_TYPES_H +#define COMS_STDLIB_TYPES_H #include @@ -44,9 +44,9 @@ typedef intptr_t smm; // @question consider to implement atomic_16 depending on intrinsic support #define atomic_8 volatile -#define atomic_16 alignas(2) volatile -#define atomic_32 alignas(4) volatile -#define atomic_64 alignas(8) volatile +#define atomic_16 volatile +#define atomic_32 volatile +#define atomic_64 volatile #define OMS_PI 3.14159265358979323846f #define OMS_PI_OVER_TWO (OMS_PI / 2.0f) diff --git a/system/Allocator.h b/system/Allocator.h index 833cbc0..8d3986b 100644 --- a/system/Allocator.h +++ b/system/Allocator.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SYSTEM_ALLOCATOR_H -#define TOS_SYSTEM_ALLOCATOR_H +#ifndef COMS_SYSTEM_ALLOCATOR_H +#define COMS_SYSTEM_ALLOCATOR_H #if _WIN32 #include "../platform/win32/Allocator.h" diff --git a/system/FileUtils.cpp b/system/FileUtils.cpp index 402281d..030b49f 100644 --- a/system/FileUtils.cpp +++ b/system/FileUtils.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SYSTEM_FILE_UTILS_C -#define TOS_SYSTEM_FILE_UTILS_C +#ifndef COMS_SYSTEM_FILE_UTILS_C +#define COMS_SYSTEM_FILE_UTILS_C #if _WIN32 #include "../platform/win32/FileUtils.cpp" diff --git a/system/Library.cpp b/system/Library.cpp index db62a91..a6bea7d 100644 --- a/system/Library.cpp +++ b/system/Library.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SYSTEM_LIBRARY_C -#define TOS_SYSTEM_LIBRARY_C +#ifndef COMS_SYSTEM_LIBRARY_C +#define COMS_SYSTEM_LIBRARY_C #if _WIN32 #include "../platform/win32/Library.cpp" diff --git a/system/Library.h b/system/Library.h index 7ad50a7..a479e61 100644 --- a/system/Library.h +++ b/system/Library.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SYSTEM_LIBRARY_H -#define TOS_SYSTEM_LIBRARY_H +#ifndef COMS_SYSTEM_LIBRARY_H +#define COMS_SYSTEM_LIBRARY_H #include "../stdlib/Types.h" diff --git a/system/SystemInfo.cpp b/system/SystemInfo.cpp index de85d55..948edb0 100644 --- a/system/SystemInfo.cpp +++ b/system/SystemInfo.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SYSTEM_INFO_C -#define TOS_SYSTEM_INFO_C +#ifndef COMS_SYSTEM_INFO_C +#define COMS_SYSTEM_INFO_C #if _WIN32 #include "../platform/win32/SystemInfo.cpp" diff --git a/system/SystemInfo.h b/system/SystemInfo.h index 8318357..0837f16 100644 --- a/system/SystemInfo.h +++ b/system/SystemInfo.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SYSTEM_INFO_H -#define TOS_SYSTEM_INFO_H +#ifndef COMS_SYSTEM_INFO_H +#define COMS_SYSTEM_INFO_H #include "../stdlib/Types.h" #include "../architecture/CpuInfo.h" diff --git a/system/Window.h b/system/Window.h index 4e3c43b..7fa1bbc 100644 --- a/system/Window.h +++ b/system/Window.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_SYSTEM_WINDOW_H -#define TOS_SYSTEM_WINDOW_H +#ifndef COMS_SYSTEM_WINDOW_H +#define COMS_SYSTEM_WINDOW_H #include "../stdlib/Types.h" diff --git a/tests/TestFramework.h b/tests/TestFramework.h index 7c42451..8451652 100644 --- a/tests/TestFramework.h +++ b/tests/TestFramework.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_TEST_FRAMEWORK_H -#define TOS_TEST_FRAMEWORK_H +#ifndef COMS_TEST_FRAMEWORK_H +#define COMS_TEST_FRAMEWORK_H #include #include diff --git a/thread/Atomic.h b/thread/Atomic.h index 5d3dc12..78dff62 100644 --- a/thread/Atomic.h +++ b/thread/Atomic.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_THREADS_ATOMIC_H -#define TOS_THREADS_ATOMIC_H +#ifndef COMS_THREADS_ATOMIC_H +#define COMS_THREADS_ATOMIC_H #if _WIN32 #include "../platform/win32/threading/Atomic.h" diff --git a/thread/Semaphore.h b/thread/Semaphore.h index d0233e2..81576bd 100644 --- a/thread/Semaphore.h +++ b/thread/Semaphore.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_THREADS_SEMAPHORE_H -#define TOS_THREADS_SEMAPHORE_H +#ifndef COMS_THREADS_SEMAPHORE_H +#define COMS_THREADS_SEMAPHORE_H #if _WIN32 #include "../platform/win32/threading/Semaphore.h" diff --git a/thread/Spinlock.cpp b/thread/Spinlock.cpp index 1740134..61b2542 100644 --- a/thread/Spinlock.cpp +++ b/thread/Spinlock.cpp @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_THREADS_SPINLOCK_C -#define TOS_THREADS_SPINLOCK_C +#ifndef COMS_THREADS_SPINLOCK_C +#define COMS_THREADS_SPINLOCK_C #if _WIN32 #include "../platform/win32/threading/Spinlock.cpp" diff --git a/thread/Spinlock.h b/thread/Spinlock.h index 6d6444b..98b6db3 100644 --- a/thread/Spinlock.h +++ b/thread/Spinlock.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_THREADS_SPINLOCK_H -#define TOS_THREADS_SPINLOCK_H +#ifndef COMS_THREADS_SPINLOCK_H +#define COMS_THREADS_SPINLOCK_H #if _WIN32 #include "../platform/win32/threading/Spinlock.h" diff --git a/thread/Thread.h b/thread/Thread.h index 97bc857..3ca2bda 100644 --- a/thread/Thread.h +++ b/thread/Thread.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_THREADS_THREAD_H -#define TOS_THREADS_THREAD_H +#ifndef COMS_THREADS_THREAD_H +#define COMS_THREADS_THREAD_H #include #include "../stdlib/Types.h" @@ -26,13 +26,13 @@ void thread_create(Worker* worker, ThreadJobFunc routine, void* arg) { LOG_1("Thread started"); - pthread_create(&worker->thread, NULL, routine, arg); + coms_pthread_create(&worker->thread, NULL, routine, arg); } void thread_stop(Worker* worker) { - atomic_set_acquire(&worker->state, 0); - pthread_join(worker->thread, NULL); + atomic_set_release(&worker->state, 0); + coms_pthread_join(worker->thread, NULL); LOG_1("Thread ended"); } diff --git a/thread/ThreadDefines.h b/thread/ThreadDefines.h index e57594a..214968f 100644 --- a/thread/ThreadDefines.h +++ b/thread/ThreadDefines.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_THREADS_THREAD_DEFINES_H -#define TOS_THREADS_THREAD_DEFINES_H +#ifndef COMS_THREADS_THREAD_DEFINES_H +#define COMS_THREADS_THREAD_DEFINES_H #if _WIN32 #include "../platform/win32/threading/ThreadDefines.h" diff --git a/thread/ThreadJob.h b/thread/ThreadJob.h index 5fe89da..1bbfd4e 100644 --- a/thread/ThreadJob.h +++ b/thread/ThreadJob.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_THREADS_JOB_H -#define TOS_THREADS_JOB_H +#ifndef COMS_THREADS_JOB_H +#define COMS_THREADS_JOB_H #include #include @@ -19,8 +19,8 @@ typedef void (*ThreadPoolJobFunc)(void*); struct PoolWorker { - atomic_32 int32 id; - atomic_32 int32 state; + alignas(4) atomic_32 int32 id; + alignas(4) atomic_32 int32 state; void* arg; void* result; RingMemory ring; @@ -29,8 +29,8 @@ struct PoolWorker { }; struct Worker { - atomic_32 int32 state; - pthread_t thread; + alignas(4) atomic_32 int32 state; + coms_pthread_t thread; }; #endif \ No newline at end of file diff --git a/thread/ThreadPool.h b/thread/ThreadPool.h index bab9229..2ff2f33 100644 --- a/thread/ThreadPool.h +++ b/thread/ThreadPool.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_THREADS_THREAD_POOL_H -#define TOS_THREADS_THREAD_POOL_H +#ifndef COMS_THREADS_THREAD_POOL_H +#define COMS_THREADS_THREAD_POOL_H #include "../stdlib/Types.h" #include "../memory/Queue.h" @@ -21,17 +21,17 @@ struct ThreadPool { // This is not a threaded queue since we want to handle the mutex in here, not in the queue for finer control Queue work_queue; - pthread_mutex_t work_mutex; - pthread_cond_t work_cond; - pthread_cond_t working_cond; + coms_pthread_mutex_t work_mutex; + coms_pthread_cond_t work_cond; + coms_pthread_cond_t working_cond; - atomic_32 int32 working_cnt; - atomic_32 int32 thread_cnt; + alignas(4) atomic_32 int32 working_cnt; + alignas(4) atomic_32 int32 thread_cnt; int32 size; - atomic_32 int32 state; + alignas(4) atomic_32 int32 state; - atomic_32 int32 id_counter; + alignas(4) atomic_32 int32 id_counter; }; static THREAD_RETURN thread_pool_worker(void* arg) @@ -40,19 +40,19 @@ static THREAD_RETURN thread_pool_worker(void* arg) PoolWorker* work; while (true) { - pthread_mutex_lock(&pool->work_mutex); + coms_pthread_mutex_lock(&pool->work_mutex); while (queue_is_empty(&pool->work_queue) && !pool->state) { - pthread_cond_wait(&pool->work_cond, &pool->work_mutex); + coms_pthread_cond_wait(&pool->work_cond, &pool->work_mutex); } if (pool->state == 1) { - pthread_mutex_unlock(&pool->work_mutex); + coms_pthread_mutex_unlock(&pool->work_mutex); break; } work = (PoolWorker *) queue_dequeue_keep(&pool->work_queue); - pthread_mutex_unlock(&pool->work_mutex); + coms_pthread_mutex_unlock(&pool->work_mutex); if (!work) { continue; @@ -76,14 +76,14 @@ static THREAD_RETURN thread_pool_worker(void* arg) atomic_decrement_relaxed(&pool->working_cnt); if (atomic_get_relaxed(&pool->state) == 0 && atomic_get_relaxed(&pool->working_cnt) == 0) { - pthread_cond_signal(&pool->working_cond); + coms_pthread_cond_signal(&pool->working_cond); } } - pthread_cond_signal(&pool->working_cond); + coms_pthread_cond_signal(&pool->working_cond); atomic_decrement_relaxed(&pool->thread_cnt); - return NULL; + return (THREAD_RETURN) NULL; } void thread_pool_create(ThreadPool* pool, BufferMemory* buf, int32 thread_count) @@ -94,48 +94,48 @@ void thread_pool_create(ThreadPool* pool, BufferMemory* buf, int32 thread_count) // @todo switch from pool mutex and pool cond to threadjob mutex/cond // thread_pool_wait etc. should just iterate over all mutexes - pthread_mutex_init(&pool->work_mutex, NULL); - pthread_cond_init(&pool->work_cond, NULL); - pthread_cond_init(&pool->working_cond, NULL); + coms_pthread_mutex_init(&pool->work_mutex, NULL); + coms_pthread_cond_init(&pool->work_cond, NULL); + coms_pthread_cond_init(&pool->working_cond, NULL); - pthread_t thread; + coms_pthread_t thread; for (pool->size = 0; pool->size < thread_count; ++pool->size) { - pthread_create(&thread, NULL, thread_pool_worker, pool); - pthread_detach(thread); + coms_pthread_create(&thread, NULL, thread_pool_worker, pool); + coms_pthread_detach(thread); } } void thread_pool_wait(ThreadPool* pool) { - pthread_mutex_lock(&pool->work_mutex); + coms_pthread_mutex_lock(&pool->work_mutex); while ((!pool->state && pool->working_cnt != 0) || (pool->state && pool->thread_cnt != 0)) { - pthread_cond_wait(&pool->working_cond, &pool->work_mutex); + coms_pthread_cond_wait(&pool->working_cond, &pool->work_mutex); } - pthread_mutex_unlock(&pool->work_mutex); + coms_pthread_mutex_unlock(&pool->work_mutex); } void thread_pool_destroy(ThreadPool* pool) { // This sets the queue to empty - atomic_set_acquire((void **) &pool->work_queue.tail, pool->work_queue.head); + atomic_set_release((void **) &pool->work_queue.tail, pool->work_queue.head); // This sets the state to "shutdown" atomic_set_release(&pool->state, 1); - pthread_cond_broadcast(&pool->work_cond); + coms_pthread_cond_broadcast(&pool->work_cond); thread_pool_wait(pool); - pthread_mutex_destroy(&pool->work_mutex); - pthread_cond_destroy(&pool->work_cond); - pthread_cond_destroy(&pool->working_cond); + coms_pthread_mutex_destroy(&pool->work_mutex); + coms_pthread_cond_destroy(&pool->work_cond); + coms_pthread_cond_destroy(&pool->working_cond); } PoolWorker* thread_pool_add_work(ThreadPool* pool, const PoolWorker* job) { - pthread_mutex_lock(&pool->work_mutex); + coms_pthread_mutex_lock(&pool->work_mutex); PoolWorker* temp_job = (PoolWorker *) ring_get_memory_nomove((RingMemory *) &pool->work_queue, sizeof(PoolWorker), 64); if (atomic_get_relaxed(&temp_job->id) > 0) { - pthread_mutex_unlock(&pool->work_mutex); + coms_pthread_mutex_unlock(&pool->work_mutex); ASSERT_SIMPLE(temp_job->id == 0); return NULL; @@ -148,8 +148,8 @@ PoolWorker* thread_pool_add_work(ThreadPool* pool, const PoolWorker* job) temp_job->id = atomic_fetch_add_acquire(&pool->id_counter, 1); } - pthread_cond_broadcast(&pool->work_cond); - pthread_mutex_unlock(&pool->work_mutex); + coms_pthread_cond_broadcast(&pool->work_cond); + coms_pthread_mutex_unlock(&pool->work_mutex); return temp_job; } @@ -158,11 +158,11 @@ PoolWorker* thread_pool_add_work(ThreadPool* pool, const PoolWorker* job) // This makes it faster, since we can avoid a memcpy PoolWorker* thread_pool_add_work_start(ThreadPool* pool) { - pthread_mutex_lock(&pool->work_mutex); + coms_pthread_mutex_lock(&pool->work_mutex); PoolWorker* temp_job = (PoolWorker *) queue_enqueue_start(&pool->work_queue); if (atomic_get_relaxed(&temp_job->id) > 0) { - pthread_mutex_unlock(&pool->work_mutex); + coms_pthread_mutex_unlock(&pool->work_mutex); ASSERT_SIMPLE(temp_job->id == 0); return NULL; @@ -179,8 +179,8 @@ PoolWorker* thread_pool_add_work_start(ThreadPool* pool) void thread_pool_add_work_end(ThreadPool* pool) { queue_enqueue_end(&pool->work_queue); - pthread_cond_broadcast(&pool->work_cond); - pthread_mutex_unlock(&pool->work_mutex); + coms_pthread_cond_broadcast(&pool->work_cond); + coms_pthread_mutex_unlock(&pool->work_mutex); } diff --git a/ui/UIAlignment.h b/ui/UIAlignment.h index c7a5b9d..69d3b5c 100644 --- a/ui/UIAlignment.h +++ b/ui/UIAlignment.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ALIGNMENT_H -#define TOS_UI_ALIGNMENT_H +#ifndef COMS_UI_ALIGNMENT_H +#define COMS_UI_ALIGNMENT_H #include "../stdlib/Types.h" diff --git a/ui/UIAnimation.h b/ui/UIAnimation.h index 74d24ef..6f892cc 100644 --- a/ui/UIAnimation.h +++ b/ui/UIAnimation.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ANIMATION_H -#define TOS_UI_ANIMATION_H +#ifndef COMS_UI_ANIMATION_H +#define COMS_UI_ANIMATION_H #include "../stdlib/Types.h" #include "../animation/AnimationEaseType.h" diff --git a/ui/UIButton.h b/ui/UIButton.h index a4401a5..80a88a9 100644 --- a/ui/UIButton.h +++ b/ui/UIButton.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_BUTTON_H -#define TOS_UI_BUTTON_H +#ifndef COMS_UI_BUTTON_H +#define COMS_UI_BUTTON_H #include "../stdlib/Types.h" #include "attribute/UIAttribute.h" diff --git a/ui/UICursor.h b/ui/UICursor.h index 78d0cb2..a5e2d54 100644 --- a/ui/UICursor.h +++ b/ui/UICursor.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_CURSOR_H -#define TOS_UI_CURSOR_H +#ifndef COMS_UI_CURSOR_H +#define COMS_UI_CURSOR_H #include "../stdlib/Types.h" #include "attribute/UIAttributeDimension.h" diff --git a/ui/UICustom.h b/ui/UICustom.h index a43a536..7f3b7da 100644 --- a/ui/UICustom.h +++ b/ui/UICustom.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_CUSTOM_H -#define TOS_UI_CUSTOM_H +#ifndef COMS_UI_CUSTOM_H +#define COMS_UI_CUSTOM_H #include "../stdlib/Types.h" #include "attribute/UIAttribute.h" diff --git a/ui/UIElement.h b/ui/UIElement.h index 47ae418..e688053 100644 --- a/ui/UIElement.h +++ b/ui/UIElement.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ELEMENT_H -#define TOS_UI_ELEMENT_H +#ifndef COMS_UI_ELEMENT_H +#define COMS_UI_ELEMENT_H #include "../stdlib/Types.h" #include "UIStyleType.h" @@ -77,7 +77,7 @@ struct UIElement { // Every element can have a fixed state, which is element type specific // This state is shared across all style_type (see below) - atomic_32 uint32 state; + alignas(4) atomic_32 uint32 state; // Every element can have multiple implementations for different states (e.g. hover, focus, ...) // These implementations are also element type specific and can be found in here diff --git a/ui/UIElementType.h b/ui/UIElementType.h index 65c86f2..eac67f6 100644 --- a/ui/UIElementType.h +++ b/ui/UIElementType.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ELEMENT_TYPE_H -#define TOS_UI_ELEMENT_TYPE_H +#ifndef COMS_UI_ELEMENT_TYPE_H +#define COMS_UI_ELEMENT_TYPE_H #include #include "../stdlib/Types.h" diff --git a/ui/UIImage.h b/ui/UIImage.h index dc4c1bf..4a44b11 100644 --- a/ui/UIImage.h +++ b/ui/UIImage.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_IMAGE_H -#define TOS_UI_IMAGE_H +#ifndef COMS_UI_IMAGE_H +#define COMS_UI_IMAGE_H #include "../stdlib/Types.h" diff --git a/ui/UIInput.h b/ui/UIInput.h index 52b6cb9..b9a02fc 100644 --- a/ui/UIInput.h +++ b/ui/UIInput.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_INPUT_H -#define TOS_UI_INPUT_H +#ifndef COMS_UI_INPUT_H +#define COMS_UI_INPUT_H #include "../stdlib/Types.h" #include "../camera/Camera.h" diff --git a/ui/UILabel.h b/ui/UILabel.h index b096806..2165ec0 100644 --- a/ui/UILabel.h +++ b/ui/UILabel.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_LABEL_H -#define TOS_UI_LABEL_H +#ifndef COMS_UI_LABEL_H +#define COMS_UI_LABEL_H #include "../stdlib/Types.h" #include "attribute/UIAttributeFont.h" diff --git a/ui/UILayout.cpp b/ui/UILayout.cpp index 55416bf..7576943 100644 --- a/ui/UILayout.cpp +++ b/ui/UILayout.cpp @@ -1,5 +1,5 @@ -#ifndef TOS_UI_LAYOUT_C -#define TOS_UI_LAYOUT_C +#ifndef COMS_UI_LAYOUT_C +#define COMS_UI_LAYOUT_C #include #include "../stdlib/Types.h" diff --git a/ui/UILayout.h b/ui/UILayout.h index 02bf26e..88442bb 100644 --- a/ui/UILayout.h +++ b/ui/UILayout.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_LAYOUT_H -#define TOS_UI_LAYOUT_H +#ifndef COMS_UI_LAYOUT_H +#define COMS_UI_LAYOUT_H #include #include "../stdlib/Types.h" diff --git a/ui/UILink.h b/ui/UILink.h index ea8a35e..83166af 100644 --- a/ui/UILink.h +++ b/ui/UILink.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_LINK_H -#define TOS_UI_LINK_H +#ifndef COMS_UI_LINK_H +#define COMS_UI_LINK_H #include "../stdlib/Types.h" diff --git a/ui/UIPanel.h b/ui/UIPanel.h index dc04112..befb9c6 100644 --- a/ui/UIPanel.h +++ b/ui/UIPanel.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_PANEL_H -#define TOS_UI_PANEL_H +#ifndef COMS_UI_PANEL_H +#define COMS_UI_PANEL_H #include "../stdlib/Types.h" #include "attribute/UIAttributeDimension.h" diff --git a/ui/UISelect.h b/ui/UISelect.h index 59f0af6..98d5a5b 100644 --- a/ui/UISelect.h +++ b/ui/UISelect.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_SELECT_H -#define TOS_UI_SELECT_H +#ifndef COMS_UI_SELECT_H +#define COMS_UI_SELECT_H #include "../stdlib/Types.h" diff --git a/ui/UIStyleType.h b/ui/UIStyleType.h index 0b1074a..fda86b2 100644 --- a/ui/UIStyleType.h +++ b/ui/UIStyleType.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_STYLE_TYPE_H -#define TOS_UI_STYLE_TYPE_H +#ifndef COMS_UI_STYLE_TYPE_H +#define COMS_UI_STYLE_TYPE_H #include "../stdlib/Types.h" diff --git a/ui/UITab.h b/ui/UITab.h index 5213848..70ca390 100644 --- a/ui/UITab.h +++ b/ui/UITab.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_TAB_H -#define TOS_UI_TAB_H +#ifndef COMS_UI_TAB_H +#define COMS_UI_TAB_H #include "../stdlib/Types.h" diff --git a/ui/UITable.h b/ui/UITable.h index a1b5597..5053164 100644 --- a/ui/UITable.h +++ b/ui/UITable.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_TABLE_H -#define TOS_UI_TABLE_H +#ifndef COMS_UI_TABLE_H +#define COMS_UI_TABLE_H #include "../stdlib/Types.h" diff --git a/ui/UIText.h b/ui/UIText.h index 39b4c58..e7d8d9f 100644 --- a/ui/UIText.h +++ b/ui/UIText.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_TEXT_H -#define TOS_UI_TEXT_H +#ifndef COMS_UI_TEXT_H +#define COMS_UI_TEXT_H #include "../stdlib/Types.h" diff --git a/ui/UITextarea.h b/ui/UITextarea.h index 2b742a0..e7a575b 100644 --- a/ui/UITextarea.h +++ b/ui/UITextarea.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_TEXTAREA_H -#define TOS_UI_TEXTAREA_H +#ifndef COMS_UI_TEXTAREA_H +#define COMS_UI_TEXTAREA_H #include "../stdlib/Types.h" diff --git a/ui/UITheme.h b/ui/UITheme.h index e1002c9..e3a0e2f 100644 --- a/ui/UITheme.h +++ b/ui/UITheme.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_THEME_H -#define TOS_UI_THEME_H +#ifndef COMS_UI_THEME_H +#define COMS_UI_THEME_H #include "../stdlib/Types.h" #include "../memory/RingMemory.h" diff --git a/ui/UIWindow.h b/ui/UIWindow.h index 4959db9..1b1e054 100644 --- a/ui/UIWindow.h +++ b/ui/UIWindow.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_WINDOW_H -#define TOS_UI_WINDOW_H +#ifndef COMS_UI_WINDOW_H +#define COMS_UI_WINDOW_H #include "../stdlib/Types.h" #include "attribute/UIAttributeBorder.h" diff --git a/ui/attribute/UIAttribute.h b/ui/attribute/UIAttribute.h index a15cf99..4dd24de 100644 --- a/ui/attribute/UIAttribute.h +++ b/ui/attribute/UIAttribute.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ATTRIBUTE_H -#define TOS_UI_ATTRIBUTE_H +#ifndef COMS_UI_ATTRIBUTE_H +#define COMS_UI_ATTRIBUTE_H #include "../../stdlib/Types.h" #include "../../utils/StringUtils.h" diff --git a/ui/attribute/UIAttributeBackground.h b/ui/attribute/UIAttributeBackground.h index 87e10fa..c15ffde 100644 --- a/ui/attribute/UIAttributeBackground.h +++ b/ui/attribute/UIAttributeBackground.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ATTRIBUTE_BACKGROUND_STYLE_H -#define TOS_UI_ATTRIBUTE_BACKGROUND_STYLE_H +#ifndef COMS_UI_ATTRIBUTE_BACKGROUND_STYLE_H +#define COMS_UI_ATTRIBUTE_BACKGROUND_STYLE_H #include "../../stdlib/Types.h" diff --git a/ui/attribute/UIAttributeBorder.h b/ui/attribute/UIAttributeBorder.h index 4892e79..47e5125 100644 --- a/ui/attribute/UIAttributeBorder.h +++ b/ui/attribute/UIAttributeBorder.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ATTRIBUTE_BORDER_H -#define TOS_UI_ATTRIBUTE_BORDER_H +#ifndef COMS_UI_ATTRIBUTE_BORDER_H +#define COMS_UI_ATTRIBUTE_BORDER_H #include "../../stdlib/Types.h" diff --git a/ui/attribute/UIAttributeDimension.h b/ui/attribute/UIAttributeDimension.h index 267dae1..812464d 100644 --- a/ui/attribute/UIAttributeDimension.h +++ b/ui/attribute/UIAttributeDimension.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ATTRIBUTE_DIMENSION_H -#define TOS_UI_ATTRIBUTE_DIMENSION_H +#ifndef COMS_UI_ATTRIBUTE_DIMENSION_H +#define COMS_UI_ATTRIBUTE_DIMENSION_H #include "../../stdlib/Types.h" diff --git a/ui/attribute/UIAttributeFont.h b/ui/attribute/UIAttributeFont.h index 9180ca8..912406e 100644 --- a/ui/attribute/UIAttributeFont.h +++ b/ui/attribute/UIAttributeFont.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ATTRIBUTE_FONT_H -#define TOS_UI_ATTRIBUTE_FONT_H +#ifndef COMS_UI_ATTRIBUTE_FONT_H +#define COMS_UI_ATTRIBUTE_FONT_H #include "../../stdlib/Types.h" #include "UIAttributeShadow.h" diff --git a/ui/attribute/UIAttributeShadow.h b/ui/attribute/UIAttributeShadow.h index 6d2fbe4..0127b9b 100644 --- a/ui/attribute/UIAttributeShadow.h +++ b/ui/attribute/UIAttributeShadow.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ATTRIBUTE_SHADOW_H -#define TOS_UI_ATTRIBUTE_SHADOW_H +#ifndef COMS_UI_ATTRIBUTE_SHADOW_H +#define COMS_UI_ATTRIBUTE_SHADOW_H #include "../../stdlib/Types.h" diff --git a/ui/attribute/UIAttributeType.h b/ui/attribute/UIAttributeType.h index f376b90..71355c4 100644 --- a/ui/attribute/UIAttributeType.h +++ b/ui/attribute/UIAttributeType.h @@ -1,5 +1,5 @@ -#ifndef TOS_UI_ATTRIBUTE_TYPE_H -#define TOS_UI_ATTRIBUTE_TYPE_H +#ifndef COMS_UI_ATTRIBUTE_TYPE_H +#define COMS_UI_ATTRIBUTE_TYPE_H #include "../../stdlib/Types.h" diff --git a/utils/BitUtils.h b/utils/BitUtils.h index d5d646f..2f82fa4 100644 --- a/utils/BitUtils.h +++ b/utils/BitUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_UTILS_BIT_H -#define TOS_UTILS_BIT_H +#ifndef COMS_UTILS_BIT_H +#define COMS_UTILS_BIT_H //#include #include "../stdlib/Types.h" @@ -326,7 +326,7 @@ uint32 bits_reverse(uint32 data, uint32 count) noexcept return reversed; } -static const int32 BIT_COUNT_LOOKUP_TABLE[256] = { +static const byte BIT_COUNT_LOOKUP_TABLE[256] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, @@ -345,9 +345,10 @@ static const int32 BIT_COUNT_LOOKUP_TABLE[256] = { 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; -int32 bits_count(uint64 data, bool use_abm = false) noexcept { +inline +byte bits_count(uint64 data, bool use_abm = false) noexcept { if (use_abm) { - return (int32) intrin_bits_count_64(data); + return (byte) intrin_bits_count_64(data); } else { return BIT_COUNT_LOOKUP_TABLE[data & 0xFF] + BIT_COUNT_LOOKUP_TABLE[(data >> 8) & 0xFF] @@ -360,7 +361,8 @@ int32 bits_count(uint64 data, bool use_abm = false) noexcept { } } -int32 bits_count(uint32 data, bool use_abm = false) noexcept { +inline +byte bits_count(uint32 data, bool use_abm = false) noexcept { if (use_abm) { return intrin_bits_count_32(data); } else { @@ -371,12 +373,14 @@ int32 bits_count(uint32 data, bool use_abm = false) noexcept { } } -int32 bits_count(uint16 data) noexcept { +inline +byte bits_count(uint16 data) noexcept { return BIT_COUNT_LOOKUP_TABLE[data & 0xFF] + BIT_COUNT_LOOKUP_TABLE[(data >> 8) & 0xFF]; } -int32 bits_count(uint8 data) noexcept { +inline +byte bits_count(uint8 data) noexcept { return BIT_COUNT_LOOKUP_TABLE[data]; } diff --git a/utils/EndianUtils.h b/utils/EndianUtils.h index d01a94a..0415da5 100644 --- a/utils/EndianUtils.h +++ b/utils/EndianUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_UTILS_ENDIAN_H -#define TOS_UTILS_ENDIAN_H +#ifndef COMS_UTILS_ENDIAN_H +#define COMS_UTILS_ENDIAN_H #include "../stdlib/Types.h" diff --git a/utils/MathUtils.h b/utils/MathUtils.h index ab7aaf3..e8f8169 100644 --- a/utils/MathUtils.h +++ b/utils/MathUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_UTILS_MATH_UTILS_H -#define TOS_UTILS_MATH_UTILS_H +#ifndef COMS_UTILS_MATH_UTILS_H +#define COMS_UTILS_MATH_UTILS_H #include "../stdlib/Types.h" #include "../utils/TestUtils.h" diff --git a/utils/RandomUtils.h b/utils/RandomUtils.h index 808ce16..de58190 100644 --- a/utils/RandomUtils.h +++ b/utils/RandomUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_UTILS_RANDOM_H -#define TOS_UTILS_RANDOM_H +#ifndef COMS_UTILS_RANDOM_H +#define COMS_UTILS_RANDOM_H #include #include "../stdlib/Types.h" diff --git a/utils/StringUtils.h b/utils/StringUtils.h index b955e7b..4029ac1 100644 --- a/utils/StringUtils.h +++ b/utils/StringUtils.h @@ -6,10 +6,11 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_UTILS_STRING_UTILS_H -#define TOS_UTILS_STRING_UTILS_H +#ifndef COMS_UTILS_STRING_UTILS_H +#define COMS_UTILS_STRING_UTILS_H #include +#include #include "../stdlib/Types.h" #include "../utils/TestUtils.h" @@ -289,7 +290,7 @@ void wchar_to_char(const char* __restrict str, char* __restrict dest) noexcept *dest = '\0'; } -static const bool STR_IS_ALPHA_LOOKUP_TABLE[] = { +static constexpr const bool STR_IS_ALPHA_LOOKUP_TABLE[] = { false, false, false, false, false, false, false, false, // 0-7 false, false, false, false, false, false, false, false, // 8-15 false, false, false, false, false, false, false, false, // 16-23 @@ -301,11 +302,11 @@ static const bool STR_IS_ALPHA_LOOKUP_TABLE[] = { false, true, true, true, true, true, true, true, // 64-71 ('A'-'G') true, true, true, true, true, true, true, true, // 72-79 ('H'-'O') true, true, true, true, true, true, true, true, // 80-87 ('P'-'W') - true, true, true, false, false, false, false, false, // 88-95 ('X'-'Z', others) + true, true, true, false, false, false, false, false, // 88-95 ('X'-'Z', others) false, true, true, true, true, true, true, true, // 96-103 ('a'-'g') true, true, true, true, true, true, true, true, // 104-111 ('h'-'o') true, true, true, true, true, true, true, true, // 112-119 ('p'-'w') - true, true, true, false, false, false, false, false, // 120-127 ('x'-'z', others) + true, true, true, false, false, false, false, false, // 120-127 ('x'-'z', others) false, false, false, false, false, false, false, false, // 128-135 false, false, false, false, false, false, false, false, // 136-143 false, false, false, false, false, false, false, false, // 144-151 @@ -340,7 +341,7 @@ bool str_is_alpha(const char* str) noexcept { return true; } -static const bool STR_IS_NUM_LOOKUP_TABLE[] = { +static constexpr const bool STR_IS_NUM_LOOKUP_TABLE[] = { false, false, false, false, false, false, false, false, // 0-7 false, false, false, false, false, false, false, false, // 8-15 false, false, false, false, false, false, false, false, // 16-23 @@ -349,13 +350,13 @@ static const bool STR_IS_NUM_LOOKUP_TABLE[] = { false, false, false, false, false, false, false, false, // 40-47 true, true, true, true, true, true, true, true, // 48-55 ('0'-'7') true, true, false, false, false, false, false, false, // 56-63 ('8'-'9', others) - false, true, false, false, false, false, false, false, // 64-71 ('A'-'G') - false, false, false, false, false, false, false, false, // 72-79 ('H'-'O') - false, false, false, false, false, false, false, false, // 80-87 ('P'-'W') + false, true, false, false, false, false, false, false, // 64-71 ('A'-'G') + false, false, false, false, false, false, false, false, // 72-79 ('H'-'O') + false, false, false, false, false, false, false, false, // 80-87 ('P'-'W') false, false, false, false, false, false, false, false, // 88-95 ('X'-'Z', others) - false, false, false, false, false, false, false, false, // 96-103 ('a'-'g') - false, false, false, false, false, false, false, false, // 104-111 ('h'-'o') - false, false, false, false, false, false, false, false, // 112-119 ('p'-'w') + false, false, false, false, false, false, false, false, // 96-103 ('a'-'g') + false, false, false, false, false, false, false, false, // 104-111 ('h'-'o') + false, false, false, false, false, false, false, false, // 112-119 ('p'-'w') false, false, false, false, false, false, false, false, // 120-127 ('x'-'z', others) false, false, false, false, false, false, false, false, // 128-135 false, false, false, false, false, false, false, false, // 136-143 @@ -380,7 +381,7 @@ bool str_is_num(char str) noexcept { return STR_IS_NUM_LOOKUP_TABLE[(byte) str]; } -static const bool STR_IS_ALPHANUM_LOOKUP_TABLE[] = { +static constexpr const bool STR_IS_ALPHANUM_LOOKUP_TABLE[] = { false, false, false, false, false, false, false, false, // 0-7 false, false, false, false, false, false, false, false, // 8-15 false, false, false, false, false, false, false, false, // 16-23 @@ -388,15 +389,15 @@ static const bool STR_IS_ALPHANUM_LOOKUP_TABLE[] = { false, false, false, false, false, false, false, false, // 32-39 false, false, false, false, false, false, false, false, // 40-47 true, true, true, true, true, true, true, true, // 48-55 ('0'-'7') - true, true, false, false, false, false, false, false, // 56-63 ('8'-'9', others) + true, true, false, false, false, false, false, false, // 56-63 ('8'-'9', others) false, true, true, true, true, true, true, true, // 64-71 ('A'-'G') true, true, true, true, true, true, true, true, // 72-79 ('H'-'O') true, true, true, true, true, true, true, true, // 80-87 ('P'-'W') - true, true, true, false, false, false, false, false, // 88-95 ('X'-'Z', others) + true, true, true, false, false, false, false, false, // 88-95 ('X'-'Z', others) false, true, true, true, true, true, true, true, // 96-103 ('a'-'g') true, true, true, true, true, true, true, true, // 104-111 ('h'-'o') true, true, true, true, true, true, true, true, // 112-119 ('p'-'w') - true, true, true, false, false, false, false, false, // 120-127 ('x'-'z', others) + true, true, true, false, false, false, false, false, // 120-127 ('x'-'z', others) false, false, false, false, false, false, false, false, // 128-135 false, false, false, false, false, false, false, false, // 136-143 false, false, false, false, false, false, false, false, // 144-151 @@ -591,12 +592,12 @@ int32 uint_to_str(uint64 number, char str[12]) noexcept { return i; } -static const char HEX_TABLE[] = { +static constexpr const char HEX_TABLE[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; -static const bool HEX_LOOKUP_TABLE[256] = { +static constexpr const bool HEX_LOOKUP_TABLE[256] = { false, false, false, false, false, false, false, false, // 0-7 false, false, false, false, false, false, false, false, // 8-15 false, false, false, false, false, false, false, false, // 16-23 @@ -605,13 +606,13 @@ static const bool HEX_LOOKUP_TABLE[256] = { false, false, false, false, false, false, false, false, // 40-47 true, true, true, true, true, true, true, true, // 48-55 ('0'-'7') true, true, false, false, false, false, false, false, // 56-63 ('8'-'9', others) - false, true, true, true, true, true, true, false, // 64-71 ('A'-'G') - false, false, false, false, false, false, false, false, // 72-79 ('H'-'O') - false, false, false, false, false, false, false, false, // 80-87 ('P'-'W') + false, true, true, true, true, true, true, false, // 64-71 ('A'-'G') + false, false, false, false, false, false, false, false, // 72-79 ('H'-'O') + false, false, false, false, false, false, false, false, // 80-87 ('P'-'W') false, false, false, false, false, false, false, false, // 88-95 ('X'-'Z', others) - false, false, false, false, false, false, false, false, // 96-103 ('a'-'g') - false, false, false, false, false, false, false, false, // 104-111 ('h'-'o') - false, false, false, false, false, false, false, false, // 112-119 ('p'-'w') + false, false, false, false, false, false, false, false, // 96-103 ('a'-'g') + false, false, false, false, false, false, false, false, // 104-111 ('h'-'o') + false, false, false, false, false, false, false, false, // 112-119 ('p'-'w') false, false, false, false, false, false, false, false, // 120-127 ('x'-'z', others) false, false, false, false, false, false, false, false, // 128-135 false, false, false, false, false, false, false, false, // 136-143 @@ -744,7 +745,7 @@ void str_copy_until(const char* __restrict src, char* __restrict dest, const cha size_t len = str_length(delim); while (*src != '\0') { - for (int32 i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { if (*src == delim[i]) { *dest = '\0'; return; @@ -761,7 +762,7 @@ inline void str_copy_short(char* __restrict dest, const char* __restrict src, int32 length) noexcept { int32 i = -1; - while (*src != '\0' && ++i < length) { + while (*src != '\0' && ++i < length - 1) { *dest++ = *src++; } @@ -1036,7 +1037,7 @@ void tolower_ascii(char* str) noexcept } } -constexpr inline +inline constexpr bool str_contains(const char* haystack, const char* needle) noexcept { // @performance would it make sense to only check until haystack - strlen(needle)? @@ -1060,7 +1061,7 @@ bool str_contains(const char* haystack, const char* needle) noexcept return false; } -constexpr inline +inline int32 str_compare(const char* str1, const char* str2) noexcept { byte c1, c2; @@ -1286,6 +1287,12 @@ void str_skip_whitespace(const char** str) noexcept } } +inline +bool str_is_empty(const char str) noexcept +{ + return str == ' ' || str == '\t' || str == '\n' || str == '\r'; +} + inline void str_skip_empty(const char** str) noexcept { diff --git a/utils/TestUtils.h b/utils/TestUtils.h index ea7c313..05839c2 100644 --- a/utils/TestUtils.h +++ b/utils/TestUtils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_UTILS_TEST_UTILS_H -#define TOS_UTILS_TEST_UTILS_H +#ifndef COMS_UTILS_TEST_UTILS_H +#define COMS_UTILS_TEST_UTILS_H #if DEBUG #define ASSERT_SIMPLE(a) if (!(a)) { *(volatile int *)0 = 0; } diff --git a/utils/TimeUtils.h b/utils/TimeUtils.h new file mode 100644 index 0000000..a6c0b7a --- /dev/null +++ b/utils/TimeUtils.h @@ -0,0 +1,18 @@ +/** + * Jingga + * + * @copyright Jingga + * @license OMS License 2.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef COMS_UTILS_TIME_UTILS_H +#define COMS_UTILS_TIME_UTILS_H + +#if _WIN32 + #include "../platform/win32/TimeUtils.h" +#else + #include "../platform/linux/TimeUtils.h" +#endif + +#endif \ No newline at end of file diff --git a/utils/Utils.h b/utils/Utils.h index f082c03..850a10a 100644 --- a/utils/Utils.h +++ b/utils/Utils.h @@ -6,8 +6,8 @@ * @version 1.0.0 * @link https://jingga.app */ -#ifndef TOS_UTILS_H -#define TOS_UTILS_H +#ifndef COMS_UTILS_H +#define COMS_UTILS_H #include #include "../stdlib/Types.h" @@ -24,12 +24,6 @@ #include "../architecture/x86/simd/utils/Utils.h" #endif -#if _WIN32 - #include "../platform/win32/UtilsWin32.h" -#else - #include "../platform/linux/UtilsLinux.h" -#endif - struct FileBody { uint64 size; // doesn't include null termination (same as strlen) byte* content; @@ -51,9 +45,12 @@ void str_output(const char* __restrict str, ...) { str = buffer; } - while (*str) { - output_char(*str++); - } + #if _WIN32 + HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); + WriteFile(hStdout, str, str_length(str), NULL, NULL); + else + write(STDOUT_FILENO, str, str_length(str)); + #endif } inline