Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EntityDescription.h « Game « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 533da95d9828b1fa9d2d80491cf20b5ed53ac9c8 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//-----------------------------------------------------------------------------
//           Name: EntityDescription.h
//      Developer: Wolfire Games LLC
//    Description:
//        License: Read below
//-----------------------------------------------------------------------------
//
//
//   Copyright 2022 Wolfire Games LLC
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
//-----------------------------------------------------------------------------
#pragma once

#include <Asset/Asset/attachmentasset.h>
#include <Asset/assetinfobase.h>

#include <Editors/entity_type.h>
#include <Scripting/scriptparams.h>
#include <Graphics/palette.h>
#include <Game/attachment_type.h>
#include <AI/sample.h>

#include <vector>

class vec3;
class mat4;
class quaternion;

enum EntityDescriptionFieldType {
    EDF_ENTITY_TYPE,
    EDF_NAME,
    EDF_TRANSLATION,
    EDF_SCALE,
	EDF_ROTATION,
	EDF_VERSION,
    EDF_COLOR,
    EDF_OVERBRIGHT,
    EDF_ID,
    EDF_FILE_PATH,
    EDF_BILLBOARD_PATH,
    EDF_SPECIAL_TYPE,
    EDF_CONNECTIONS,
    EDF_ITEM_CONNECTIONS,
    EDF_DIRECTION,
    EDF_DECAL_MISS_LIST,
    EDF_DECAL_ISOLATION_ID,
    EDF_DISPLAY_MODE,
    EDF_DIMENSIONS,
    EDF_USING_IMPOSTER,
    EDF_IS_PLAYER,
    EDF_SCRIPT_PARAMS,
    EDF_PALETTE,
    EDF_SKY_ROTATION,
    EDF_SUN_RADIUS,
    EDF_SUN_COLOR_ANGLE,
    EDF_SUN_DIRECTION,
    EDF_ENV_OBJECT_ATTACH,
    EDF_NEGATIVE_LIGHT_PROBE,
    EDF_GI_COEFFICIENTS,
    EDF_NAV_MESH_CONNECTIONS,
    EDF_NO_NAVMESH,
    EDF_PREFAB_LOCKED,
    EDF_PREFAB_PATH,
    EDF_ORIGINAL_SCALE,
    EDF_ROTATION_EULER,
    EDF_HOTSPOT_CONNECTED_TO, // This is never saved to disk, only used internally
    EDF_HOTSPOT_CONNECTED_FROM, // This is never saved to disk, only used internally
    EDF_NPC_SCRIPT_PATH,
    EDF_PC_SCRIPT_PATH,
    // EDF_CONNECTIONS means connections to other objects, EDF_CONNECTIONS_FROM
    // means objects connected to this object (i.e. coming from another other)
    EDF_CONNECTIONS_FROM 
};

struct ItemConnection {
    int id;
    AttachmentType attachment_type;
    AttachmentRef attachment_ref;
    bool mirrored;
};

struct ItemConnectionData {
    int32_t id;
    int32_t attachment_type;
    std::string attachment_str;
    int32_t mirrored;
};

struct NavMeshConnectionData {
    int32_t other_object_id;
    int32_t offmesh_connection_id;
    SamplePolyAreas poly_area;
};

struct EntityDescriptionField {
    int type;
    std::vector<char> data;
    void ReadBool(bool* val) const;
    void WriteBool(bool val);
	void ReadInt(int* id) const;
	void WriteInt(int id);
	void ReadIntVec(std::vector<int>* vec) const;
	void WriteIntVec(const std::vector<int>& val);
	void ReadItemConnectionDataVec(std::vector<ItemConnectionData>* item_connections) const;
	void WriteItemConnectionDataVec(const std::vector<ItemConnectionData> &val);
	void ReadNavMeshConnectionDataVec(std::vector<NavMeshConnectionData>* navmesh_connections) const;
	void WriteNavMeshConnectionDataVec(const std::vector<NavMeshConnectionData> &val);
    void ReadString( std::string* type_file ) const;
    void WriteString(const std::string& str);
    void ReadPath( Path* path ) const;
    void WritePath( const Path& val );
};

struct EntityDescription;
typedef std::vector<EntityDescription> EntityDescriptionList;

struct EntityDescription {
    EntityDescriptionList children;
    std::vector<EntityDescriptionField> fields;
    
    void AddPath(EntityDescriptionFieldType type, const Path& val);
    void AddVec3(EntityDescriptionFieldType type, const vec3& val);
    void AddInt(EntityDescriptionFieldType type, const int& val);
    void AddFloat(EntityDescriptionFieldType type, const float& val);
    void AddMat4(EntityDescriptionFieldType type, const mat4& val);
    void AddQuaternion(EntityDescriptionFieldType type, const quaternion& val);
    void AddEntityType(EntityDescriptionFieldType type, const EntityType& val);
    void AddIntVec(EntityDescriptionFieldType type, const std::vector<int>& val);
    void AddItemConnectionVec(EntityDescriptionFieldType type, const std::vector<ItemConnectionData>& val);
    void AddNavMeshConnnectionVec(EntityDescriptionFieldType type, const std::vector<NavMeshConnectionData>& val);
    void AddScriptParams(EntityDescriptionFieldType type, const ScriptParamMap& val);
    void AddPalette(EntityDescriptionFieldType type, const OGPalette& val);
    void AddString(EntityDescriptionFieldType type, const std::string& val);
    void AddData(EntityDescriptionFieldType type, const std::vector<char> &val);
    void AddBool(EntityDescriptionFieldType type, const bool& val);
	const EntityDescriptionField* GetField(EntityDescriptionFieldType type) const;
	EntityDescriptionField* GetField(EntityDescriptionFieldType type);
    EntityDescriptionField* GetEditableField( EntityDescriptionFieldType type );
    void ReturnPaths(PathSet& path_set);
    void SaveToXML( TiXmlElement* object ) const;
    
    private:
    void AddType(EntityDescriptionFieldType type);
};

inline bool operator==(const EntityDescription& a, const EntityDescription& b){
    return a.children == b.children && a.fields == b.fields;
}

inline bool operator!=(const EntityDescription& a, const EntityDescription& b){
    return !(a == b);
}

inline bool operator==(const EntityDescriptionField& a, const EntityDescriptionField& b){
    return a.type == b.type && a.data == b.data;
}

void GetTSRIinfo( EntityDescription &desc, const TiXmlElement* pElement );
void LoadEntityDescriptionFromXML(EntityDescription& ed, const TiXmlElement* el);
void LoadEntityDescriptionListFromXML( EntityDescriptionList& desc_list, const TiXmlElement* el );
void GetTSREinfo( const TiXmlElement* pElement, vec3 &translation, vec3 &scale, quaternion &rotation, vec3 &rotation_euler );
void GetTSRinfo( const TiXmlElement* pElement, vec3 &translation, vec3 &scale, quaternion &rotation );
void ClearDescID(EntityDescription *desc);