LCOV - code coverage report
Current view: top level - include/simlab - WorldHasher.hpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 1 1
Test Date: 2026-04-10 19:03:25 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2025 aeml
       3              :  *
       4              :  * This program is free software: you can redistribute it and/or modify
       5              :  * it under the terms of the GNU General Public License as published by
       6              :  * the Free Software Foundation, either version 3 of the License, or
       7              :  * (at your option) any later version.
       8              :  *
       9              :  * This program is distributed in the hope that it will be useful,
      10              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12              :  * GNU General Public License for more details.
      13              :  *
      14              :  * You should have received a copy of the GNU General Public License
      15              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      16              :  */
      17              : 
      18              : #pragma once
      19              : 
      20              : #include <cstdint>
      21              : #include <vector>
      22              : 
      23              : #include "physics/Components.hpp"
      24              : 
      25              : namespace ecs { class World; }
      26              : 
      27              : namespace simlab
      28              : {
      29              :     // Deterministic FNV-1a based hashing over simulation state for regression tests,
      30              :     // headless analysis, and repeated-run validation.
      31              :     class WorldHasher
      32              :     {
      33              :     public:
      34              :         std::uint64_t HashBodies(const std::vector<physics::TransformComponent>& transforms,
      35              :                                  const std::vector<physics::RigidBodyComponent>& bodies) const noexcept;
      36              :         std::uint64_t HashAABBs(const std::vector<physics::AABBComponent>& aabbs) const noexcept;
      37              :         std::uint64_t HashWorld(const ecs::World& world) const noexcept;
      38            2 :         std::uint64_t Combine(std::uint64_t h1, std::uint64_t h2) const noexcept { return h1 ^ (h2 + 0x9e3779b97f4a7c15ull + (h1<<6) + (h1>>2)); }
      39              :     private:
      40              :         static constexpr std::uint64_t kOffset = 1469598103934665603ull;
      41              :         static constexpr std::uint64_t kPrime  = 1099511628211ull;
      42              :         void HashBytes(std::uint64_t& h, const void* data, std::size_t len) const noexcept;
      43              :     };
      44              : }
        

Generated by: LCOV version 2.0-1