mirror of https://github.com/qt/qt3d.git
Class QLogicComponent changes
Task-number: QTBUG-51448 Change-Id: I1359cbfe61dbef291859d15b16bda61639493432 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
This commit is contained in:
parent
55e681ac6c
commit
c4d7ad6b1e
|
|
@ -160,8 +160,8 @@ Entity {
|
|||
] // axes
|
||||
},
|
||||
|
||||
LogicComponent {
|
||||
onFrameUpdate: {
|
||||
FrameAction {
|
||||
onTriggered: {
|
||||
// The time difference since the last frame is passed in as the
|
||||
// argument dt. It is a floating point value in units of seconds.
|
||||
root.camera.translate(Qt.vector3d(d.vx, d.vy, d.vz).times(dt))
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
#include <Qt3DInput/QKeyboardController>
|
||||
#include <Qt3DInput/QMouseDevice>
|
||||
#include <Qt3DInput/QMouseEvent>
|
||||
#include <Qt3DLogic/QLogicComponent>
|
||||
#include <Qt3DLogic/QFrameAction>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ QFirstPersonCameraControllerPrivate::QFirstPersonCameraControllerPrivate()
|
|||
, m_keyboardController(new QKeyboardController())
|
||||
, m_mouseDevice(new QMouseDevice())
|
||||
, m_logicalDevice(new QLogicalDevice())
|
||||
, m_logicComponent(new Qt3DLogic::QLogicComponent())
|
||||
, m_frameAction(new Qt3DLogic::QFrameAction())
|
||||
, m_linearSpeed(10.0f)
|
||||
, m_lookSpeed(180.0f)
|
||||
, m_firstPersonUp(QVector3D(0.0f, 1.0f, 0.0f))
|
||||
|
|
@ -168,16 +168,16 @@ void QFirstPersonCameraControllerPrivate::init()
|
|||
m_logicalDevice->addAxis(m_tzAxis);
|
||||
|
||||
Q_Q(QFirstPersonCameraController);
|
||||
//// LogicComponent
|
||||
//// FrameAction
|
||||
|
||||
QObject::connect(m_logicComponent, SIGNAL(frameUpdate(float)),
|
||||
q, SLOT(_q_onFrameUpdate(float)));
|
||||
QObject::connect(m_frameAction, SIGNAL(triggered(float)),
|
||||
q, SLOT(_q_onTriggered(float)));
|
||||
|
||||
q->addComponent(m_logicComponent);
|
||||
q->addComponent(m_frameAction);
|
||||
q->addComponent(m_logicalDevice);
|
||||
}
|
||||
|
||||
void QFirstPersonCameraControllerPrivate::_q_onFrameUpdate(float dt)
|
||||
void QFirstPersonCameraControllerPrivate::_q_onTriggered(float dt)
|
||||
{
|
||||
if (m_camera != Q_NULLPTR) {
|
||||
m_camera->translate(QVector3D(m_txAxis->value() * m_linearSpeed,
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ Q_SIGNALS:
|
|||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE(QFirstPersonCameraController)
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_onFrameUpdate(float))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_onTriggered(float))
|
||||
};
|
||||
|
||||
} // Qt3DInput
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class QCamera;
|
|||
}
|
||||
|
||||
namespace Qt3DLogic {
|
||||
class QLogicComponent;
|
||||
class QFrameAction;
|
||||
}
|
||||
|
||||
namespace Qt3DInput {
|
||||
|
|
@ -111,13 +111,13 @@ public:
|
|||
|
||||
QLogicalDevice *m_logicalDevice;
|
||||
|
||||
Qt3DLogic::QLogicComponent *m_logicComponent;
|
||||
Qt3DLogic::QFrameAction *m_frameAction;
|
||||
|
||||
float m_linearSpeed;
|
||||
float m_lookSpeed;
|
||||
QVector3D m_firstPersonUp;
|
||||
|
||||
void _q_onFrameUpdate(float);
|
||||
void _q_onTriggered(float);
|
||||
|
||||
Q_DECLARE_PUBLIC(QFirstPersonCameraController)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -115,8 +115,8 @@ Entity {
|
|||
property real actualScale
|
||||
|
||||
// Animate solar system with LogicComponent
|
||||
LogicComponent {
|
||||
onFrameUpdate: {
|
||||
FrameAction {
|
||||
onTriggered: {
|
||||
frames++
|
||||
animate(focusedPlanet)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,8 +272,8 @@ Entity {
|
|||
}
|
||||
},
|
||||
|
||||
LogicComponent {
|
||||
onFrameUpdate: {
|
||||
FrameAction {
|
||||
onTriggered: {
|
||||
// The time difference since the last frame is passed in as the
|
||||
// argument dt. It is a floating point value in units of seconds.
|
||||
root.camera.translate(Qt.vector3d(d.vx, d.vy, d.vz).times(dt))
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "executor_p.h"
|
||||
#include <Qt3DLogic/qlogiccomponent.h>
|
||||
#include <Qt3DLogic/qframeaction.h>
|
||||
#include <Qt3DCore/qnode.h>
|
||||
#include <Qt3DCore/private/qscene_p.h>
|
||||
#include <QtCore/qsemaphore.h>
|
||||
|
|
@ -93,9 +93,9 @@ void Executor::processLogicFrameUpdates(float dt)
|
|||
Q_ASSERT(m_semaphore);
|
||||
const QVector<QNode *> nodes = m_scene->lookupNodes(m_nodeIds);
|
||||
for (QNode *node : nodes) {
|
||||
QLogicComponent *logicComponent = qobject_cast<QLogicComponent *>(node);
|
||||
if (logicComponent)
|
||||
logicComponent->onFrameUpdate(dt);
|
||||
QFrameAction *frameAction = qobject_cast<QFrameAction *>(node);
|
||||
if (frameAction)
|
||||
frameAction->onTriggered(dt);
|
||||
}
|
||||
|
||||
// Release the semaphore so the calling Manager can continue
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ HEADERS += \
|
|||
$$PWD/qt3dlogic_global.h \
|
||||
$$PWD/qlogicaspect.h \
|
||||
$$PWD/qlogicaspect_p.h \
|
||||
$$PWD/qlogiccomponent.h \
|
||||
$$PWD/qframeaction.h \
|
||||
$$PWD/handle_types_p.h \
|
||||
$$PWD/qlogiccomponent_p.h \
|
||||
$$PWD/qframeaction_p.h \
|
||||
$$PWD/callbackjob_p.h \
|
||||
$$PWD/executor_p.h \
|
||||
$$PWD/handler_p.h \
|
||||
|
|
@ -15,7 +15,7 @@ HEADERS += \
|
|||
|
||||
SOURCES += \
|
||||
$$PWD/qlogicaspect.cpp \
|
||||
$$PWD/qlogiccomponent.cpp \
|
||||
$$PWD/qframeaction.cpp \
|
||||
$$PWD/manager.cpp \
|
||||
$$PWD/handler.cpp \
|
||||
$$PWD/executor.cpp \
|
||||
|
|
|
|||
|
|
@ -37,59 +37,59 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qlogiccomponent.h"
|
||||
#include "qlogiccomponent_p.h"
|
||||
#include "qframeaction.h"
|
||||
#include "qframeaction_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
namespace Qt3DLogic {
|
||||
|
||||
QLogicComponentPrivate::QLogicComponentPrivate()
|
||||
QFrameActionPrivate::QFrameActionPrivate()
|
||||
: QComponentPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\class Qt3DLogic::QLogicComponent
|
||||
\class Qt3DLogic::QFrameAction
|
||||
\inmodule Qt3DLogic
|
||||
\since 5.5
|
||||
\brief Provides a way to have a synchronous function executed each frame.
|
||||
|
||||
The QLogicComponent provides a way to perform tasks each frame in
|
||||
The QFrameAction provides a way to perform tasks each frame in
|
||||
synchronized with the Qt3D backend. This is useful to implement some
|
||||
aspects of application logic and to prototype functionality that can later
|
||||
be folded into an additional Qt3D aspect.
|
||||
|
||||
For example, the QLogicComponent can be used to animate a property in sync
|
||||
For example, the QFrameAction can be used to animate a property in sync
|
||||
with the Qt3D engine where a Qt Quick animation element is not perfectly
|
||||
synchronized and may lead to stutters in some cases.
|
||||
|
||||
To execute your own code each frame override the onFrameUpdate function.
|
||||
To execute your own code each frame override the onTriggered function.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\qmltype LogicComponent
|
||||
\qmltype FrameAction
|
||||
\inqmlmodule Qt3D.Logic
|
||||
\instantiates Qt3DLogic::QLogicComponent
|
||||
\instantiates Qt3DLogic::QFrameAction
|
||||
\inherits Component3D
|
||||
\since 5.5
|
||||
*/
|
||||
|
||||
/*!
|
||||
Constructs a new QLogicComponent instance with parent \a parent.
|
||||
Constructs a new QFrameAction instance with parent \a parent.
|
||||
*/
|
||||
QLogicComponent::QLogicComponent(QNode *parent)
|
||||
: QComponent(*new QLogicComponentPrivate, parent)
|
||||
QFrameAction::QFrameAction(QNode *parent)
|
||||
: QComponent(*new QFrameActionPrivate, parent)
|
||||
{
|
||||
}
|
||||
|
||||
/*! \internal */
|
||||
QLogicComponent::QLogicComponent(QLogicComponentPrivate &dd, QNode *parent)
|
||||
QFrameAction::QFrameAction(QFrameActionPrivate &dd, QNode *parent)
|
||||
: QComponent(dd, parent)
|
||||
{
|
||||
}
|
||||
|
||||
QLogicComponent::~QLogicComponent()
|
||||
QFrameAction::~QFrameAction()
|
||||
{
|
||||
QNode::cleanup();
|
||||
}
|
||||
|
|
@ -98,11 +98,11 @@ QLogicComponent::~QLogicComponent()
|
|||
This virtual function will be called in a synchronous manner once each frame by
|
||||
the Logic aspect.
|
||||
*/
|
||||
void QLogicComponent::onFrameUpdate(float dt)
|
||||
void QFrameAction::onTriggered(float dt)
|
||||
{
|
||||
// Emit signal so that QML instances get the onFrameUpdate() signal
|
||||
// Emit signal so that QML instances get the onTriggered() signal
|
||||
// handler called
|
||||
emit frameUpdate(dt);
|
||||
emit triggered(dt);
|
||||
}
|
||||
|
||||
} // namespace Qt3DLogic
|
||||
|
|
@ -37,8 +37,8 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QT3DLOGIC_QLOGICCOMPONENT_H
|
||||
#define QT3DLOGIC_QLOGICCOMPONENT_H
|
||||
#ifndef QT3DLOGIC_QFRAMEACTION_H
|
||||
#define QT3DLOGIC_QFRAMEACTION_H
|
||||
|
||||
#include <Qt3DCore/qcomponent.h>
|
||||
#include <Qt3DLogic/qt3dlogic_global.h>
|
||||
|
|
@ -48,31 +48,31 @@ QT_BEGIN_NAMESPACE
|
|||
namespace Qt3DLogic {
|
||||
|
||||
class QLogicAspect;
|
||||
class QLogicComponentPrivate;
|
||||
class QFrameActionPrivate;
|
||||
|
||||
namespace Logic {
|
||||
class Executor;
|
||||
}
|
||||
|
||||
class QT3DLOGICSHARED_EXPORT QLogicComponent : public Qt3DCore::QComponent
|
||||
class QT3DLOGICSHARED_EXPORT QFrameAction : public Qt3DCore::QComponent
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QLogicComponent(Qt3DCore::QNode *parent = 0);
|
||||
~QLogicComponent();
|
||||
explicit QFrameAction(Qt3DCore::QNode *parent = 0);
|
||||
~QFrameAction();
|
||||
|
||||
protected:
|
||||
QLogicComponent(QLogicComponentPrivate &dd, QNode *parent = 0);
|
||||
QFrameAction(QFrameActionPrivate &dd, QNode *parent = 0);
|
||||
|
||||
Q_SIGNALS:
|
||||
void frameUpdate(float dt);
|
||||
void triggered(float dt);
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE(QLogicComponent)
|
||||
QT3D_CLONEABLE(QLogicComponent)
|
||||
Q_DECLARE_PRIVATE(QFrameAction)
|
||||
QT3D_CLONEABLE(QFrameAction)
|
||||
|
||||
virtual void onFrameUpdate(float dt);
|
||||
virtual void onTriggered(float dt);
|
||||
|
||||
friend class Logic::Executor;
|
||||
};
|
||||
|
|
@ -81,4 +81,4 @@ private:
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT3DLOGIC_QLOGICCOMPONENT_H
|
||||
#endif // QT3DLOGIC_QFRAMEACTION_H
|
||||
|
|
@ -37,8 +37,8 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QT3DLOGIC_QLOGICCOMPONENT_P_H
|
||||
#define QT3DLOGIC_QLOGICCOMPONENT_P_H
|
||||
#ifndef QT3DLOGIC_QFRAMEACTION_P_H
|
||||
#define QT3DLOGIC_QFRAMEACTION_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
|
|
@ -57,18 +57,18 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
namespace Qt3DLogic {
|
||||
|
||||
class QLogicComponent;
|
||||
class QFrameAction;
|
||||
|
||||
class QLogicComponentPrivate : public Qt3DCore::QComponentPrivate
|
||||
class QFrameActionPrivate : public Qt3DCore::QComponentPrivate
|
||||
{
|
||||
public:
|
||||
QLogicComponentPrivate();
|
||||
QFrameActionPrivate();
|
||||
|
||||
Q_DECLARE_PUBLIC(QLogicComponent)
|
||||
Q_DECLARE_PUBLIC(QFrameAction)
|
||||
};
|
||||
|
||||
} // namespace Qt3DLogic
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT3DLOGIC_QLOGICCOMPONENT_P_H
|
||||
#endif // QT3DLOGIC_QFRAMEACTION_P_H
|
||||
|
|
@ -42,7 +42,7 @@
|
|||
#include "executor_p.h"
|
||||
#include "handler_p.h"
|
||||
#include "manager_p.h"
|
||||
#include "qlogiccomponent.h"
|
||||
#include "qframeaction.h"
|
||||
|
||||
#include <Qt3DCore/qnode.h>
|
||||
#include <Qt3DCore/private/qchangearbiter_p.h>
|
||||
|
|
@ -87,7 +87,7 @@ QLogicAspect::QLogicAspect(QLogicAspectPrivate &dd, QObject *parent)
|
|||
|
||||
void QLogicAspect::registerBackendTypes()
|
||||
{
|
||||
registerBackendType<QLogicComponent>(QBackendNodeMapperPtr(new Logic::HandlerFunctor(d_func()->m_manager.data())));
|
||||
registerBackendType<QFrameAction>(QBackendNodeMapperPtr(new Logic::HandlerFunctor(d_func()->m_manager.data())));
|
||||
}
|
||||
|
||||
QVector<QAspectJobPtr> QLogicAspect::jobsToExecute(qint64 time)
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <QtQml>
|
||||
#include <Qt3DLogic/qlogiccomponent.h>
|
||||
#include <Qt3DLogic/qframeaction.h>
|
||||
#include "qt3dquick3dlogicplugin.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
void Qt3DQuick3DLogicPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
qmlRegisterType<Qt3DLogic::QLogicComponent>(uri, 2, 0, "LogicComponent");
|
||||
qmlRegisterType<Qt3DLogic::QFrameAction>(uri, 2, 0, "FrameAction");
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue