summaryrefslogtreecommitdiffstats
path: root/src/game/shared/entity/transform.cc
blob: 379ddd596256ea8578bccf9d20fa666444fa66ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "shared/pch.hh"

#include "shared/entity/transform.hh"

#include "shared/world/dimension.hh"

#include "shared/const.hh"

constexpr inline static void update_component(unsigned int dim, entity::Transform& component)
{
    if(component.local[dim] >= CHUNK_SIZE) {
        component.local[dim] -= CHUNK_SIZE;
        component.chunk[dim] += 1;
        return;
    }

    if(component.local[dim] < 0.0f) {
        component.local[dim] += CHUNK_SIZE;
        component.chunk[dim] -= 1;
        return;
    }
}

void entity::Transform::fixed_update(world::Dimension* dimension)
{
    auto view = dimension->entities.view<entity::Transform>();

    for(auto [entity, transform] : view.each()) {
        update_component(0U, transform);
        update_component(1U, transform);
        update_component(2U, transform);
    }
}