All Projects → celtera → ahsohtoa

celtera / ahsohtoa

Licence: other
Structure-of-array synthesis in C++20

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to ahsohtoa

gal
Geometric Algebra Library
Stars: ✭ 78 (+32.2%)
Mutual labels:  cplusplus-20
cordisproject
Custom engine based on OpenXRay engine. Global mod for S.T.A.L.K.E.R. - Call of Pripyat.
Stars: ✭ 25 (-57.63%)
Mutual labels:  cplusplus-20
wg21
Various documents and code related to proposals for WG21
Stars: ✭ 53 (-10.17%)
Mutual labels:  cplusplus-20
xtd
Free open-source modern C++17 / C++20 framework to create console, forms (GUI like WinForms) and unit test applications on Microsoft Windows, Apple macOS and Linux.
Stars: ✭ 321 (+444.07%)
Mutual labels:  cplusplus-20
any invocable
Сonservative, move-only equivalent of std::function
Stars: ✭ 14 (-76.27%)
Mutual labels:  cplusplus-20

ahsohtoa - automatic AoS-to-SoA

C++ Sponsor License Platforms

Automatic structure-of-array generation for C++20: this library takes a structure such as:

struct Foo {
  int a;
  float b;
  struct Bar {
    float x;
    char y;
  } c;
};

and, given:

ahso::arrays<std::vector, Foo> storage_direct;

ahso::recursive_arrays<std::vector, Foo> storage_recursive;

will respectively synthesize types which look like:

// for storage_direct: 
std::tuple<std::vector<int>, std::vector<float>, std::vector<Bar>>

// for storage_recursive: 
std::tuple<std::vector<int>, std::vector<float>, std::vector<float>, std::vector<char>> 

Dependencies

  • Boost.PFR
  • C++20

Simple example

struct vec3 { float x,y,z; };
struct color { float r,g,b,a; };
struct physics_component {
  vec3 position;
  vec3 speed;
  vec3 acceleration;
};

struct render_component {
  color col;
};

struct entity {
  physics_component physics;
  render_component render;
}

int main()
{
  // Define our storage
  ahso::arrays<std::vector, entity> e;

  // Preallocate some space like you would with std::vector
  e.reserve(1000);

  // Add a new entity
  auto index = e.add_entity({
    .physics {
      .position { 0., 0., 0. }
    , .acceleration { 1., 0., 0. }
    },
    .render {
      .col { 0., 1., 0., 1. }
    }
  });

  // Access a specific component for entity "index"
  e.get<physics_component>(index).position.x = 2;
  
  // Or if the proper type is provided (until we get metaclasses, see example): 
  e[index].physics.position.x = 2;

  // Remove an entity
  e.erase(index);
}

Example with all the features

See https://github.com/celtera/ahsohtoa/blob/main/tests/test.cpp !

Licensing

The library is licensed under GPLv3 + commercial.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].