summaryrefslogtreecommitdiffstats
path: root/src/game/client/entity/factory.cc
blob: 019d855e293b7fa2ed15ef2b27e59d22af2998b4 (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
34
35
36
37
38
39
40
// SPDX-License-Identifier: BSD-2-Clause
// Copyright (c) 2025 Kirill Dmitrievich
// File: factory.cc
// Description: Boilerplate entity creation

#include "client/pch.hh"

#include "client/entity/factory.hh"

#include "shared/entity/factory.hh"
#include "shared/entity/head.hh"
#include "shared/entity/transform.hh"
#include "shared/entity/velocity.hh"

#include "shared/world/dimension.hh"

#include "client/entity/sound_emitter.hh"

#include "client/globals.hh"

void client::create_player(Dimension* dimension, entt::entity entity)
{
    shared::create_player(dimension, entity);

    const auto& head = dimension->entities.get<Head>(entity);
    dimension->entities.emplace_or_replace<client::HeadIntr>(entity, head);
    dimension->entities.emplace_or_replace<client::HeadPrev>(entity, head);

    const auto& transform = dimension->entities.get<Transform>(entity);
    dimension->entities.emplace_or_replace<client::TransformIntr>(entity, transform);
    dimension->entities.emplace_or_replace<client::TransformPrev>(entity, transform);

    const auto& velocity = dimension->entities.get<Velocity>(entity);
    dimension->entities.emplace_or_replace<client::VelocityIntr>(entity, velocity);
    dimension->entities.emplace_or_replace<client::VelocityPrev>(entity, velocity);

    if(globals::sound_ctx) {
        dimension->entities.emplace_or_replace<SoundEmitter>(entity);
    }
}