summaryrefslogtreecommitdiffstats
path: root/src/Runtime/Source/runtime/Qt3DSKernelTypes.h
blob: db2909967b4b8e8790e20eae34330cfb109ce6b7 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/****************************************************************************
**
** Copyright (C) 1993-2009 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#pragma once

//==============================================================================
//	Includes
//==============================================================================
#include "Qt3DSArray.h"

namespace qt3ds {
namespace runtime {
    namespace element {
        struct SElement;
        struct SComponent;
    }
}
}

namespace Q3DStudio {
typedef qt3ds::runtime::element::SElement TElement;
typedef qt3ds::runtime::element::SComponent TComponent;
}
//==============================================================================
//	Namespace
//==============================================================================
namespace Q3DStudio {

//==============================================================================
//	Forwards
//==============================================================================
class CString;

//==============================================================================
//	Typedefs
//==============================================================================
typedef CArray<TElement *> TElementList; ///< Dynamic list of CElements
typedef CArray<const CString *> TEventList; ///< Dynamic list of CStrings
typedef CArray<INT32> TAssociationList; ///< Dynamic list of IDs used for the association process

typedef UINT32 TEventCommandHash; ///< Value from CHash::Hash31
typedef UINT32 TStringHash; ///< Value from CHash::Hash
typedef UINT32 TAttributeHash; ///< Value from CHash::Hash27
typedef UINT32 THashValue; ///< 32 bit value indicating a hash

//==============================================================================
//	Enumerations
//==============================================================================

/// Each attribute knows the type of its value and uses 4 bits for this enum
enum EAttributeType {
    ATTRIBUTETYPE_NONE = 0,
    ATTRIBUTETYPE_INT32,
    ATTRIBUTETYPE_HASH,
    ATTRIBUTETYPE_FLOAT,
    ATTRIBUTETYPE_BOOL,
    ATTRIBUTETYPE_STRING,
    ATTRIBUTETYPE_POINTER,
    ATTRIBUTETYPE_ELEMENTREF,
    ATTRIBUTETYPE_DATADRIVEN_PARENT,
    ATTRIBUTETYPE_DATADRIVEN_CHILD,
    ATTRIBUTETYPE_FLOAT3,
    ATTRIBUTETYPE_FLOAT2,
    ATTRIBUTETYPE_DATAINPUT_TIMELINE,
    ATTRIBUTETYPE_DATAINPUT_SLIDE,
    ATTRIBUTETYPECOUNT
};

/// Elements represent various types of objects
enum EElementType {
    ELEMENTTYPE_UNKNOWN = 0,
    ELEMENTTYPE_NODE,
    ELEMENTTYPE_CAMERA,
    ELEMENTTYPE_LIGHT,
    ELEMENTTYPE_TEXT,
    ELEMENTTYPE_MATERIAL,
    ELEMENTTYPE_TEXTURE,
    ELEMENTTYPE_COMPONENT,
    ELEMENTTYPE_BEHAVIOR,
    ELEMENTTYPE_PATH,
    ELEMENTTYPE_PATHANCHORPOINT,
    ELEMENTTYPE_SUBPATH,
    ELEMENTTYPECOUNT
};

//==============================================================================
//	Enumerations
//==============================================================================

/// Various bit flags packed into a single 16bit space.
enum EElementFlag {
    // Persistent flags (set only at creation)
    ELEMENTFLAG_COMPONENT = 1, ///< Element is a component
    ELEMENTFLAG_TIMELINE = 1 << 1, ///< Element has start time and duration attributes
    ELEMENTFLAG_CLONE = 1 << 2, ///< Element is a clone
    ELEMENTFLAG_ATTRIBUTELOCK =
        1 << 3, ///< No more attributes can be added (always true during runtime)

    // Configuration flags (seldom changed)
    ELEMENTFLAG_SCRIPTCALLBACKS = 1
        << 4, ///< At least one script has requested notify on onActivate, onDeactivate, onUpdate
    ELEMENTFLAG_SCRIPTINITIALIZE = 1
        << 5, ///< At least one script has requested notify on onInitialize
    ELEMENTFLAG_REGISTEREDFORATTRIBUTECHANGE = 1 << 6, ///< Element monitored for attribute change
    ELEMENTFLAG_REGISTEREDFOREVENTCALLBACK = 1 << 7, ///< Element registered for event callbacks
    ELEMENTFLAG_PICKENABLED = 1 << 8, ///< At least one script or action has registered for mouse
                                      ///events based on this element

    // Runtime flags
    ELEMENTFLAG_GLOBALACTIVE =
        1 << 9, ///< Combination active flag based on explicit, time and parent active
    ELEMENTFLAG_EXPLICITACTIVE = 1 << 10, ///< Explicit On/Off switch on each element
    ELEMENTFLAG_PLAYTHROUGH = 1 << 11, ///< Playthrough slides enabled if this is a component
    ELEMENTFLAG_DIRTY = 1 << 12, ///< Attributes or user visible flags have changed

    // Flags used by the activation manager
    ELEMENTFLAG_AMGR_TIMEACTIVE = 1 << 13, ///< Is the element alive according to time information
};

// Four byte aligned time unit structure.
struct SAlignedTimeUnit
{
    UINT32 m_LowWord;
    UINT32 m_HighWord;

    SAlignedTimeUnit() {}
    SAlignedTimeUnit(const TTimeUnit &inUnit);
    SAlignedTimeUnit(const SAlignedTimeUnit &inOther)
        : m_LowWord(inOther.m_LowWord)
        , m_HighWord(inOther.m_HighWord)
    {
    }
    SAlignedTimeUnit &operator=(const SAlignedTimeUnit &inOther)
    {
        m_LowWord = inOther.m_LowWord;
        m_HighWord = inOther.m_HighWord;
        return *this;
    }
    operator TTimeUnit() const;

    void operator-=(const TTimeUnit &inTime);
    void operator%=(const TTimeUnit &inTime);
};

//==============================================================================
//	Defines
//==============================================================================
#define Q3DStudio_ATTRIBUTEKEYBITS 26 /* Number of bits to store attributes index */
#define Q3DStudio_ATTRIBUTEKEYMASK 0x03ffffff /* Bit mask covering 26 bits */

//==============================================================================
//	Structs
//==============================================================================

/// Each element has a number of attributes associated with it - This is the key.
struct SAttributeKey
{
    TAttributeHash m_Hash : Q3DStudio_ATTRIBUTEKEYBITS; ///< hash of attribute name
    TAttributeHash m_Type : 4; ///< Attribute type such as INT32, FLOAT, STRING
    TAttributeHash m_Dirty : 1; ///< Dirty bit signalling that the attribute value has been modified
    TAttributeHash
        m_DontOptimize : 1; ///< Used by the exporter/optimizer to flag attributes as un-optimizable

    void Convert(const UINT32 &inKey)
    {
        m_Hash = inKey & Q3DStudio_ATTRIBUTEKEYMASK;
        m_Type = (inKey & 0x3c000000) >> Q3DStudio_ATTRIBUTEKEYBITS;
        m_Dirty = (inKey & 0x40000000) >> (Q3DStudio_ATTRIBUTEKEYBITS + 4);
        m_DontOptimize = (inKey & 0x80000000) >> (Q3DStudio_ATTRIBUTEKEYBITS + 5);
    }
};

/// The structure to store a memory pool for clones.
/// The actual data pool will start at the address after these 8 bytes.
struct SClone
{
    SClone *m_Next; ///< Pointer to the next block of memory
    UINT32 m_Size; ///< Size of the current block of memory
};

//==============================================================================
//	Unions
//==============================================================================

/// Each element has a number of attributes associated with it - This is the value.
union UVariant {
    INT32 m_INT32; ///< Integer representation
    FLOAT m_FLOAT; ///< Float representation
    THashValue m_Hash; ///< Explicit hash representation
    UINT32 m_StringHandle; ///< Handle into the IStringTable member of the presentation
    void *m_VoidPointer; ///< Generic data Pointer
    UINT32 m_ElementHandle; ///< Element handle.  Resolve using IApplication object.
    FLOAT m_FLOAT3[3]; ///< Vector 3 representation
};

} // namespace Q3DStudio