summaryrefslogtreecommitdiffstats
path: root/src/Runtime/ogl-runtime/src/runtime/Qt3DSApplication.h
blob: 39cd3c4b9d488e14f139d2ceb23a1cf3775552ba (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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/****************************************************************************
**
** Copyright (C) 2013 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
#ifndef QT3DS_APPLICATION_H
#define QT3DS_APPLICATION_H
#include "foundation/Qt3DSRefCounted.h"
#include "EASTL/string.h"
#include "foundation/Qt3DSAllocator.h"
#include "foundation/Utils.h"
#include "Qt3DSKernelTypes.h"
#include "Qt3DSMetadata.h"
#include "QtQml/qjsengine.h"

namespace Q3DStudio {
class IRuntimeFactory;
class IRuntimeFactoryCore;
class CRuntime;
class CPresentation;
class CInputEngine;
class IAudioPlayer;
}

namespace qt3ds {
namespace state {
namespace debugger {
class IDebugger;
class ISceneGraphRuntimeDebugger;
}
}
}

namespace qt3ds {
class Qt3DSAssetVisitor;
namespace runtime {
using namespace qt3ds::foundation;
using namespace qt3ds;

class IElementAllocator;
class IActivityZoneManager;

class CAppStr : public eastl::basic_string<char8_t, ForwardingAllocator>
{
    typedef eastl::basic_string<char8_t, ForwardingAllocator> TBase;

public:
    CAppStr(NVAllocatorCallback &alloc, const char8_t *inStr = NULL);
    CAppStr(const CAppStr &inOther);
    CAppStr();
    CAppStr &operator=(const CAppStr &inOther);
};

class IApplication;

class IAppRunnable : public NVRefCounted
{
public:
    virtual void Run() = 0;
};

struct DataInOutAttribute
{
    QByteArray elementPath;
    QVector<QByteArray> attributeName;
    Q3DStudio::EAttributeType propertyType = Q3DStudio::ATTRIBUTETYPE_NONE;
};

enum DataInOutType {
    DataInOutTypeInvalid = 0,
    DataInOutTypeRangedNumber,
    DataInOutTypeString,
    DataInOutTypeFloat,
    DataInOutTypeEvaluator,
    DataInOutTypeBoolean,
    DataInOutTypeVector4,
    DataInOutTypeVector3,
    DataInOutTypeVector2,
    DataInOutTypeVariant
};

// Duplicated from Q3DSDataInput class on viewer side
enum class DataInputValueRole {
    Value = 0,
    Min = 1,
    Max = 2
};

struct DataInputDef
{
    QVector<DataInOutAttribute> controlledAttributes;
    DataInOutType type = DataInOutTypeInvalid;
    float min = 0.0f;
    float max = 0.0f;
    QString evaluator;
    QJSValue evalFunc;  // keep both evaluator string and JS function
                        // to avoid having to evaluate string several times
    QVariant value;     // most recently set value
    // evaluator datainputs that need to re-evaluate when this datainput changes value
    QVector<QString> dependents;

};

struct DataOutputDef
{
    DataInOutAttribute observedAttribute;
    DataInOutType type = DataInOutTypeInvalid;
    QVariant value;     // most recently notified value
    QString name;
    QT3DSU32 observedHandle;
    float min = 0.0f;
    float max = 0.0f;
    Q3DStudio::TComponent *timelineComponent;  // Valid only for @timeline
};

typedef QMap<QString, DataInputDef> DataInputMap;
typedef QMap<QString, DataOutputDef> DataOutputMap;

class QT3DS_AUTOTEST_EXPORT IApplication : public NVRefCounted
{
public:
    virtual Q3DStudio::IRuntimeFactory &GetRuntimeFactory() const = 0;

    virtual void SetFrameCount(Q3DStudio::INT32 inFrameCount) = 0;
    virtual Q3DStudio::INT32 GetFrameCount() = 0;

    // Allow overriding the global wall time. This way animations can be
    // advanced at an arbitrary rate when rendering offscreen. Set to 0 to
    // disable (the default).
    virtual void SetTimeMilliSecs(Q3DStudio::INT64 inMilliSecs) = 0;

    virtual Q3DStudio::INT64 GetTimeMilliSecs() = 0;
    virtual void ResetTime() = 0;

    // Setup during UpdateAndRender.  Returns 0 for first frame.
    virtual double GetMillisecondsSinceLastFrame() = 0;

    virtual Q3DStudio::CInputEngine &GetInputEngine() = 0;

    virtual Q3DStudio::CPresentation *GetPrimaryPresentation() = 0;

    virtual Q3DStudio::CPresentation *GetPresentationById(const char8_t *inId) = 0;

    virtual QList<Q3DStudio::CPresentation *> GetPresentationList() = 0;

    // Update all the presentations and render them.  Called exactly once per frame.
    virtual void UpdateAndRender() = 0;

    virtual bool IsApplicationDirty() = 0;

    virtual void MarkApplicationDirty() = 0;

    virtual Q3DStudio::IAudioPlayer &GetAudioPlayer() = 0;

    virtual bool createSuccessful() = 0;

    virtual DataInputMap &dataInputMap() = 0;
    virtual DataOutputMap &dataOutputMap() = 0;

    virtual QList<QString> dataInputs() const = 0;
    virtual QList<QString> dataOutputs() const = 0;

    virtual float dataInputMax(const QString &name) const = 0;

    virtual float dataInputMin(const QString &name) const = 0;

    virtual void setPresentationId(const QString &id) = 0;

    virtual void preloadSlide(const QString &slide) = 0;
    virtual void unloadSlide(const QString &slide) = 0;
    virtual void setDelayedLoading(bool enable) = 0;

    // threadsafe call.
    virtual void QueueForMainThread(IAppRunnable &inRunnable) = 0;

    // The directory that contains the executable and the root resource path
    virtual CRegisteredString GetApplicationDirectory() const = 0;
    // Directory that contained the UIA file.
    virtual CRegisteredString GetProjectDirectory() const = 0;
    // Directory where we will copy shared object files to before we load them.
    // This is specifically for android and the case where the place where the project exists
    // is not always the place where we can load the project.
    virtual CRegisteredString GetDllDir() const = 0;
    virtual void SetDllDir(const char *inDllDir) = 0;
    virtual Q3DStudio::THashValue HashString(const char *inStr) = 0;
    virtual const char *ReverseHash(Q3DStudio::THashValue theValue) = 0;

    virtual Q3DStudio::IRuntimeMetaData &GetMetaData() = 0;
    // Element handles are unique across all presentations.
    virtual Q3DStudio::TElement *GetElementByHandle(Q3DStudio::UINT32 inHandle) = 0;
    // Passing in NULL gets you zero as the return handle.
    virtual Q3DStudio::UINT32 GetHandleForElement(Q3DStudio::TElement *inElement) = 0;

    virtual Q3DStudio::IRuntimeFactoryCore &GetRuntimeFactoryCore() = 0;

    virtual IActivityZoneManager &GetActivityZoneManager() = 0;
    virtual IElementAllocator &GetElementAllocator() = 0;

    // nonblocking call to begin loading, loads uia file alone and returns.
    virtual bool BeginLoad(const QString &sourcePath, const QStringList &variantList) = 0;
    // blocking call to end all loading threads and such/wait till finished
    virtual void EndLoad() = 0;
    // Will EndLoad cause nontrivial blocking.
    // Runs any queued runnables.
    virtual bool HasCompletedLoading() = 0;

    virtual void setAssetVisitor(qt3ds::Qt3DSAssetVisitor *) = 0;

    virtual void ComponentSlideEntered(Q3DStudio::CPresentation *presentation,
                                       Q3DStudio::TElement *component,
                                       const QString &elementPath, int slideIndex,
                                       const QString &slideName) = 0;
    virtual void ComponentSlideExited(Q3DStudio::CPresentation *presentation,
                                      Q3DStudio::TElement *component,
                                      const QString &elementPath, int slideIndex,
                                      const QString &slideName) = 0;

    // will force loading to end if endLoad hasn't been called yet.  Will fire off loading
    // of resources that need to be uploaded to opengl.  Maintains reference to runtime factory
    virtual IApplication &CreateApplication(Q3DStudio::CInputEngine &inInputEngine,
                                            Q3DStudio::IAudioPlayer *inAudioPlayer,
                                            Q3DStudio::IRuntimeFactory &inFactory) = 0;

    // maintains reference to runtime factory core.  AppDir is where the executable is located;
    // the system will expect res directory
    // next to executable.
    static IApplication &CreateApplicationCore(Q3DStudio::IRuntimeFactoryCore &inFactory,
                                               const char8_t *inApplicationDirectory);
    static bool isPickingEvent(Q3DStudio::TEventCommandHash event);
};

bool isImagePath(const QString &path);
}
}

#endif