aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Object/Updates/WowCSEntityDefinitions.h
blob: a65ca60978a5df131f2c44a1d5e7599bf85f21d3 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TRINITYCORE_WOWCS_ENTITY_DEFINITIONS_H
#define TRINITYCORE_WOWCS_ENTITY_DEFINITIONS_H

#include "Define.h"
#include <array>
#include <span>

namespace WowCS
{
enum class EntityFragment : uint8
{
    CGObject                    = 0, //  UPDATEABLE, INDIRECT,
    Tag_Item                    = 1, //  TAG,
    Tag_Container               = 2, //  TAG,
    Tag_AzeriteEmpoweredItem    = 3, //  TAG,
    Tag_AzeriteItem             = 4, //  TAG,
    Tag_Unit                    = 5, //  TAG,
    Tag_Player                  = 6, //  TAG,
    Tag_GameObject              = 7, //  TAG,
    Tag_DynamicObject           = 8, //  TAG,
    Tag_Corpse                  = 9, //  TAG,
    Tag_AreaTrigger             = 10, //  TAG,
    Tag_SceneObject             = 11, //  TAG,
    Tag_Conversation            = 12, //  TAG,
    Tag_AIGroup                 = 13, //  TAG,
    Tag_Scenario                = 14, //  TAG,
    Tag_LootObject              = 15, //  TAG,
    Tag_ActivePlayer            = 16, //  TAG,
    Tag_ActiveClient_S          = 17, //  TAG,
    Tag_ActiveObject_C          = 18, //  TAG,
    Tag_VisibleObject_C         = 19, //  TAG,
    Tag_UnitVehicle             = 20, //  TAG,
    FEntityPosition             = 112,
    FEntityLocalMatrix          = 113,
    FEntityWorldMatrix          = 114,
    CActor                      = 115, //  INDIRECT,
    FVendor_C                   = 117, //  UPDATEABLE, INDIRECT,
    FMirroredObject_C           = 119,
    End                         = 255,
};

inline constexpr bool IsUpdateableFragment(EntityFragment frag)
{
    return frag == EntityFragment::CGObject || frag == EntityFragment::FVendor_C;
}

inline constexpr bool IsIndirectFragment(EntityFragment frag)
{
    return frag == EntityFragment::CGObject || frag == EntityFragment::CActor || frag == EntityFragment::FVendor_C;
}

// common case optimization, make use of the fact that fragment arrays are sorted
inline constexpr uint8 CGObjectActiveMask   = 0x1;
inline constexpr uint8 CGObjectChangedMask  = 0x2;
inline constexpr uint8 CGObjectUpdateMask   = CGObjectActiveMask | CGObjectChangedMask;

struct EntityFragmentsHolder
{
    std::array<EntityFragment, 8> Ids =
    {
        EntityFragment::End, EntityFragment::End, EntityFragment::End, EntityFragment::End,
        EntityFragment::End, EntityFragment::End, EntityFragment::End, EntityFragment::End
    };
    uint8 Count = 0;
    bool IdsChanged = false;

    std::array<EntityFragment, 2> UpdateableIds = { EntityFragment::End, EntityFragment::End };
    std::array<uint8, 2> UpdateableMasks = { };
    uint8 UpdateableCount = 0;
    uint8 ContentsChangedMask = 0;

    void Add(EntityFragment fragment, bool update);
    void Remove(EntityFragment fragment);

    std::span<EntityFragment const> GetIds() const { return std::span(Ids.begin(), Count); }
    std::span<EntityFragment const> GetUpdateableIds() const { return std::span(UpdateableIds.begin(), UpdateableCount); }

    uint8 GetUpdateMaskFor(EntityFragment fragment) const
    {
        if (fragment == EntityFragment::CGObject)   // common case optimization, make use of the fact that fragment arrays are sorted
            return CGObjectChangedMask;

        for (uint8 i = 1; i < UpdateableCount; ++i)
            if (UpdateableIds[i] == fragment)
                return UpdateableMasks[i];

        return 0;
    }
};

enum class EntityFragmentSerializationType : uint8
{
    Full    = 0,
    Partial = 1
};
}

#endif // TRINITYCORE_WOWCS_ENTITY_DEFINITIONS_H