Skip to content

Commit

Permalink
hook version to ui. reset static memory on widget hide
Browse files Browse the repository at this point in the history
  • Loading branch information
IlgarLunin committed Mar 10, 2020
1 parent 00acaf7 commit ec1b55e
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 24 deletions.
8 changes: 8 additions & 0 deletions src/animations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ void _Animations::setSceneScale(float scale)
_sceneScale = scale;
}

void _Animations::reset()
{
propsMap.clear();
trackersMap.clear();
actorsMap.clear();
facesMap.clear();
}

void _Animations::animatePropOrTracker(QJsonObject obj, const MDagPath &dagPath)
{
// bool isLive = obj["isLive"].toBool();
Expand Down
1 change: 1 addition & 0 deletions src/animations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class _Animations
float sceneScale() { return _sceneScale; }
float timestamp;
float playbackTimestamp;
void reset();
private:
float _sceneScale = 1.0;
// prop id - json
Expand Down
2 changes: 1 addition & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static const int DEFAULT_RS_PORT = 14043;
static const int DEFAULT_RS_API_PORT = 14053;

static const int VERSION_MAJOR = 0;
static const int VERSION_MINOR = 1;
static const int VERSION_MINOR = 2;
static const int VERSION_PATCH = 0;

static const int RECEIVER_FPS = 30;
Expand Down
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ui/rootwidget.h"
#include "constants.h"
#include "mapping.h"
#include "utils.h"

#include <QPointer>
#include <QScrollArea>
Expand Down Expand Up @@ -56,6 +56,7 @@ MStatus uninitializePlugin(MObject plugin)
rsmlScrollArea.clear();
}

Mapping::get()->resetCallbacks();
Utils::RSLMShutdown();

return result;
}
38 changes: 25 additions & 13 deletions src/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,7 @@ _Mapping::_Mapping()
studioTPose["rightFoot"] = MQuaternion(-0.000, 0.707, -0.707, 0.000);
studioTPose["rightToe"] = MQuaternion(0.000, 0.707, -0.707, 0.000);

// register callbacks
MCallbackId beforeNewId = MSceneMessage::addCheckCallback(MSceneMessage::kBeforeNewCheck, [](bool* recCode, void* clientData) {
Q_UNUSED(clientData)
Mapping::get()->clear();
*recCode = true;
});
MCallbackId beforeOpenId = MSceneMessage::addCheckCallback(MSceneMessage::kBeforeOpenCheck, [](bool* recCode, void* clientData) {
Q_UNUSED(clientData)
Mapping::get()->clear();
*recCode = true;
});
callbacks.append(beforeNewId);
callbacks.append(beforeOpenId);
installCallbacks();

faceShapeNames << "eyeBlinkLeft"
<< "eyeLookDownLeft"
Expand Down Expand Up @@ -681,11 +669,35 @@ void _Mapping::clear()
objectsMap.clear();
}

void _Mapping::reset()
{
clear();
resetCallbacks();
}

void _Mapping::installCallbacks()
{
// register callbacks
MCallbackId beforeNewId = MSceneMessage::addCheckCallback(MSceneMessage::kBeforeNewCheck, [](bool* recCode, void* clientData) {
Q_UNUSED(clientData)
Mapping::get()->clear();
*recCode = true;
});
MCallbackId beforeOpenId = MSceneMessage::addCheckCallback(MSceneMessage::kBeforeOpenCheck, [](bool* recCode, void* clientData) {
Q_UNUSED(clientData)
Mapping::get()->clear();
*recCode = true;
});
callbacks.append(beforeNewId);
callbacks.append(beforeOpenId);
}

void _Mapping::resetCallbacks()
{
for(MCallbackId id : callbacks) {
MSceneMessage::removeCallback(id);
}
callbacks.clear();
}

const QMultiMap<QString, MObject> &_Mapping::getObjectMapping()
Expand Down
3 changes: 3 additions & 0 deletions src/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class _Mapping
void unmapAllFaces(QString rsId);

void clear();

void reset();
void installCallbacks();
void resetCallbacks();

const QMultiMap<QString, MObject> &getObjectMapping();
Expand Down
5 changes: 5 additions & 0 deletions src/receiverworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ DataReceivingWorker::DataReceivingWorker(QObject* parent)
hearbeat.start();
}

DataReceivingWorker::~DataReceivingWorker()
{

}

void DataReceivingWorker::pause() {
socket->abort();
}
Expand Down
1 change: 1 addition & 0 deletions src/receiverworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DataReceivingWorker : public QObject
Q_OBJECT
public:
DataReceivingWorker(QObject* parent=nullptr);
~DataReceivingWorker();
public slots:
void start(int port=DEFAULT_RS_PORT);
void pause();
Expand Down
5 changes: 5 additions & 0 deletions src/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ QList<float> _Recorder::sortedTimeStamps()
std::sort(timestamps.begin(), timestamps.end());
return timestamps;
}

void _Recorder::reset()
{
recordedData.clear();
}
1 change: 1 addition & 0 deletions src/recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _Recorder
float recordingStartTime() {return mRecordingStartTime ;}

QList<float> sortedTimeStamps();
void reset();
private:
// timestamp - set keyframe function
QHash<float, QList<std::function<void(int)>>> recordedData;
Expand Down
4 changes: 3 additions & 1 deletion src/ui/infocontent.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "constants.h"
#include "utils.h"
#include "infocontent.h"
#include <QDesktopServices>
Expand Down Expand Up @@ -25,7 +26,8 @@ InfoContent::InfoContent(QWidget* parent) : QWidget(parent)

QLabel* infoLabel = new QLabel(this);
infoLabel->setWordWrap(true);
infoLabel->setText("Rokoko Studio Live for Maya v1.0.0\n\nDeveloped by Rokoko Electronics Aps");
QString infoText = QString("Rokoko Studio Live for Maya v%1.%2.%3\n\nDeveloped by Rokoko Electronics Aps").arg(VERSION_MAJOR).arg(VERSION_MINOR).arg(VERSION_PATCH);
infoLabel->setText(infoText);
infoLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
mainLayout->addLayout(infoLayout);

Expand Down
16 changes: 10 additions & 6 deletions src/ui/receivercontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ ReceiverContent::ReceiverContent(QWidget* parent) : QWidget(parent)
formLayout->addRow("Scene scale:", sceneScaleBox);
mainLayout->addLayout(formLayout);

// reset scene on stop option
QCheckBox* cbResetSceneOnStop = new QCheckBox("Reset Scene on Stop", this);
mainLayout->addWidget(cbResetSceneOnStop);
if(false)
{
// reset scene on stop option
QCheckBox* cbResetSceneOnStop = new QCheckBox("Reset Scene on Stop", this);
mainLayout->addWidget(cbResetSceneOnStop);

// hide meshes during play
QCheckBox* cbHideMeshesDuringPlay = new QCheckBox("Hide Meshes during Play", this);
mainLayout->addWidget(cbHideMeshesDuringPlay);
// hide meshes during play
QCheckBox* cbHideMeshesDuringPlay = new QCheckBox("Hide Meshes during Play", this);
mainLayout->addWidget(cbHideMeshesDuringPlay);
}

// start receiver button
ButtonParams receiverBtnParams;
Expand Down Expand Up @@ -141,6 +144,7 @@ ReceiverContent::~ReceiverContent()
for(MCallbackId id : callbacks) {
MSceneMessage::removeCallback(id);
}
callbacks.clear();
}


Expand Down
3 changes: 2 additions & 1 deletion src/ui/receivercontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ReceiverContent : public QWidget
public:
ReceiverContent(QWidget* parent=nullptr);
~ReceiverContent();

void reset();
private:
void onReceiverToggled(bool);
QSpinBox* portBox=nullptr;
Expand All @@ -29,7 +31,6 @@ class ReceiverContent : public QWidget
void recordingToggled(bool checked);
void populateTree();
void clearTreeWidget();
void reset();

MCallbackIdArray callbacks;
};
Expand Down
26 changes: 26 additions & 0 deletions src/ui/rootwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <maya/MGlobal.h>

#include "mapping.h"
#include "utils.h"

#include "ui/rootwidget.h"
#include "ui/categoryheader.h"
#include "ui/infocontent.h"
Expand Down Expand Up @@ -78,3 +81,26 @@ RootWidget::~RootWidget()
{

}

void RootWidget::closeEvent(QCloseEvent *event)
{
QWidget::closeEvent(event);

}

void RootWidget::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);

Utils::RSLMInit();
}

void RootWidget::hideEvent(QHideEvent *event)
{
QWidget::hideEvent(event);

receiverContent->reset();

Utils::RSLMShutdown();

}
4 changes: 4 additions & 0 deletions src/ui/rootwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class RootWidget : public QWidget
public:
RootWidget(QWidget *parent = nullptr);
~RootWidget();
protected:
void closeEvent(QCloseEvent *event) override;
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
private:
ReceiverContent* receiverContent=nullptr;
};
Expand Down
17 changes: 17 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "utils.h"

#include "mapping.h"
#include "animations.h"
#include "recorder.h"

#include <QString>
#include <QHash>

Expand Down Expand Up @@ -49,3 +53,16 @@ void Utils::fillFaceWeightsMap(const MFnBlendShapeDeformer &bsFn, QHash<QString,
printf("Failed to find weight attribute!!");
}
}

void Utils::RSLMInit()
{
Mapping::get()->installCallbacks();
Mapping::get()->syncMapping();
}

void Utils::RSLMShutdown()
{
Recorder::get()->reset();
Mapping::get()->reset();
Animations::get()->reset();
}
2 changes: 2 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Utils {
static MVector rsToMaya(MVector);
static MQuaternion rsToMaya(MQuaternion);
static void fillFaceWeightsMap(const MFnBlendShapeDeformer &bsFn, QHash<QString, MPlug> &map);
static void RSLMInit();
static void RSLMShutdown();
};


Expand Down

0 comments on commit ec1b55e

Please sign in to comment.