mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 03:57:17 +02:00
extend macros to take return value if necessary
This commit is contained in:
parent
6a8f131a83
commit
ddcee763ca
1 changed files with 26 additions and 26 deletions
|
@ -69,13 +69,13 @@ static NodeProcessFunc animNodeTypeToProcessFunc(AnimNode::Type type) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define READ_STRING(NAME, JSON_OBJ, ID, URL) \
|
#define READ_STRING(NAME, JSON_OBJ, ID, URL, ERROR_RETURN) \
|
||||||
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
||||||
if (!NAME##_VAL.isString()) { \
|
if (!NAME##_VAL.isString()) { \
|
||||||
qCCritical(animation) << "AnimNodeLoader, error reading string" \
|
qCCritical(animation) << "AnimNodeLoader, error reading string" \
|
||||||
<< #NAME << ", id =" << ID \
|
<< #NAME << ", id =" << ID \
|
||||||
<< ", url =" << URL.toDisplayString(); \
|
<< ", url =" << URL.toDisplayString(); \
|
||||||
return (bool) nullptr; \
|
return ERROR_RETURN; \
|
||||||
} \
|
} \
|
||||||
QString NAME = NAME##_VAL.toString()
|
QString NAME = NAME##_VAL.toString()
|
||||||
|
|
||||||
|
@ -86,23 +86,23 @@ static NodeProcessFunc animNodeTypeToProcessFunc(AnimNode::Type type) {
|
||||||
NAME = NAME##_VAL.toString(); \
|
NAME = NAME##_VAL.toString(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define READ_BOOL(NAME, JSON_OBJ, ID, URL) \
|
#define READ_BOOL(NAME, JSON_OBJ, ID, URL, ERROR_RETURN) \
|
||||||
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
||||||
if (!NAME##_VAL.isBool()) { \
|
if (!NAME##_VAL.isBool()) { \
|
||||||
qCCritical(animation) << "AnimNodeLoader, error reading bool" \
|
qCCritical(animation) << "AnimNodeLoader, error reading bool" \
|
||||||
<< #NAME << ", id =" << ID \
|
<< #NAME << ", id =" << ID \
|
||||||
<< ", url =" << URL.toDisplayString(); \
|
<< ", url =" << URL.toDisplayString(); \
|
||||||
return nullptr; \
|
return ERROR_RETURN; \
|
||||||
} \
|
} \
|
||||||
bool NAME = NAME##_VAL.toBool()
|
bool NAME = NAME##_VAL.toBool()
|
||||||
|
|
||||||
#define READ_FLOAT(NAME, JSON_OBJ, ID, URL) \
|
#define READ_FLOAT(NAME, JSON_OBJ, ID, URL, ERROR_RETURN) \
|
||||||
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
auto NAME##_VAL = JSON_OBJ.value(#NAME); \
|
||||||
if (!NAME##_VAL.isDouble()) { \
|
if (!NAME##_VAL.isDouble()) { \
|
||||||
qCCritical(animation) << "AnimNodeLoader, error reading double" \
|
qCCritical(animation) << "AnimNodeLoader, error reading double" \
|
||||||
<< #NAME << "id =" << ID \
|
<< #NAME << "id =" << ID \
|
||||||
<< ", url =" << URL.toDisplayString(); \
|
<< ", url =" << URL.toDisplayString(); \
|
||||||
return (bool) nullptr; \
|
return ERROR_RETURN; \
|
||||||
} \
|
} \
|
||||||
float NAME = (float)NAME##_VAL.toDouble()
|
float NAME = (float)NAME##_VAL.toDouble()
|
||||||
|
|
||||||
|
@ -171,11 +171,11 @@ static AnimNode::Pointer loadNode(const QJsonObject& jsonObj, const QUrl& jsonUr
|
||||||
|
|
||||||
static AnimNode::Pointer loadClipNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
static AnimNode::Pointer loadClipNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||||
|
|
||||||
READ_STRING(url, jsonObj, id, jsonUrl);
|
READ_STRING(url, jsonObj, id, jsonUrl, nullptr);
|
||||||
READ_FLOAT(startFrame, jsonObj, id, jsonUrl);
|
READ_FLOAT(startFrame, jsonObj, id, jsonUrl, nullptr);
|
||||||
READ_FLOAT(endFrame, jsonObj, id, jsonUrl);
|
READ_FLOAT(endFrame, jsonObj, id, jsonUrl, nullptr);
|
||||||
READ_FLOAT(timeScale, jsonObj, id, jsonUrl);
|
READ_FLOAT(timeScale, jsonObj, id, jsonUrl, nullptr);
|
||||||
READ_BOOL(loopFlag, jsonObj, id, jsonUrl);
|
READ_BOOL(loopFlag, jsonObj, id, jsonUrl, nullptr);
|
||||||
|
|
||||||
READ_OPTIONAL_STRING(startFrameVar, jsonObj);
|
READ_OPTIONAL_STRING(startFrameVar, jsonObj);
|
||||||
READ_OPTIONAL_STRING(endFrameVar, jsonObj);
|
READ_OPTIONAL_STRING(endFrameVar, jsonObj);
|
||||||
|
@ -202,7 +202,7 @@ static AnimNode::Pointer loadClipNode(const QJsonObject& jsonObj, const QString&
|
||||||
|
|
||||||
static AnimNode::Pointer loadBlendLinearNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
static AnimNode::Pointer loadBlendLinearNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||||
|
|
||||||
READ_FLOAT(alpha, jsonObj, id, jsonUrl);
|
READ_FLOAT(alpha, jsonObj, id, jsonUrl, nullptr);
|
||||||
|
|
||||||
READ_OPTIONAL_STRING(alphaVar, jsonObj);
|
READ_OPTIONAL_STRING(alphaVar, jsonObj);
|
||||||
|
|
||||||
|
@ -239,8 +239,8 @@ static AnimOverlay::BoneSet stringToBoneSetEnum(const QString& str) {
|
||||||
|
|
||||||
static AnimNode::Pointer loadOverlayNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
static AnimNode::Pointer loadOverlayNode(const QJsonObject& jsonObj, const QString& id, const QUrl& jsonUrl) {
|
||||||
|
|
||||||
READ_STRING(boneSet, jsonObj, id, jsonUrl);
|
READ_STRING(boneSet, jsonObj, id, jsonUrl, nullptr);
|
||||||
READ_FLOAT(alpha, jsonObj, id, jsonUrl);
|
READ_FLOAT(alpha, jsonObj, id, jsonUrl, nullptr);
|
||||||
|
|
||||||
auto boneSetEnum = stringToBoneSetEnum(boneSet);
|
auto boneSetEnum = stringToBoneSetEnum(boneSet);
|
||||||
if (boneSetEnum == AnimOverlay::NumBoneSets) {
|
if (boneSetEnum == AnimOverlay::NumBoneSets) {
|
||||||
|
@ -278,12 +278,12 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
||||||
auto smNode = std::static_pointer_cast<AnimStateMachine>(node);
|
auto smNode = std::static_pointer_cast<AnimStateMachine>(node);
|
||||||
assert(smNode);
|
assert(smNode);
|
||||||
|
|
||||||
READ_STRING(currentState, jsonObj, nodeId, jsonUrl);
|
READ_STRING(currentState, jsonObj, nodeId, jsonUrl, false);
|
||||||
|
|
||||||
auto statesValue = jsonObj.value("states");
|
auto statesValue = jsonObj.value("states");
|
||||||
if (!statesValue.isArray()) {
|
if (!statesValue.isArray()) {
|
||||||
qCCritical(animation) << "AnimNodeLoader, bad array \"states\" in stateMachine node, id =" << nodeId << ", url =" << jsonUrl.toDisplayString();
|
qCCritical(animation) << "AnimNodeLoader, bad array \"states\" in stateMachine node, id =" << nodeId << ", url =" << jsonUrl.toDisplayString();
|
||||||
return (bool) nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// build a map for all children by name.
|
// build a map for all children by name.
|
||||||
|
@ -302,13 +302,13 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
||||||
for (const auto& stateValue : statesArray) {
|
for (const auto& stateValue : statesArray) {
|
||||||
if (!stateValue.isObject()) {
|
if (!stateValue.isObject()) {
|
||||||
qCCritical(animation) << "AnimNodeLoader, bad state object in \"states\", id =" << nodeId << ", url =" << jsonUrl.toDisplayString();
|
qCCritical(animation) << "AnimNodeLoader, bad state object in \"states\", id =" << nodeId << ", url =" << jsonUrl.toDisplayString();
|
||||||
return (bool) nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
auto stateObj = stateValue.toObject();
|
auto stateObj = stateValue.toObject();
|
||||||
|
|
||||||
READ_STRING(id, stateObj, nodeId, jsonUrl);
|
READ_STRING(id, stateObj, nodeId, jsonUrl, false);
|
||||||
READ_FLOAT(interpTarget, stateObj, nodeId, jsonUrl);
|
READ_FLOAT(interpTarget, stateObj, nodeId, jsonUrl, false);
|
||||||
READ_FLOAT(interpDuration, stateObj, nodeId, jsonUrl);
|
READ_FLOAT(interpDuration, stateObj, nodeId, jsonUrl, false);
|
||||||
|
|
||||||
READ_OPTIONAL_STRING(interpTargetVar, stateObj);
|
READ_OPTIONAL_STRING(interpTargetVar, stateObj);
|
||||||
READ_OPTIONAL_STRING(interpDurationVar, stateObj);
|
READ_OPTIONAL_STRING(interpDurationVar, stateObj);
|
||||||
|
@ -318,7 +318,7 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
||||||
auto iter = childMap.find(stdId);
|
auto iter = childMap.find(stdId);
|
||||||
if (iter == childMap.end()) {
|
if (iter == childMap.end()) {
|
||||||
qCCritical(animation) << "AnimNodeLoader, could not find stateMachine child (state) with nodeId =" << nodeId << "stateId =" << id << "url =" << jsonUrl.toDisplayString();
|
qCCritical(animation) << "AnimNodeLoader, could not find stateMachine child (state) with nodeId =" << nodeId << "stateId =" << id << "url =" << jsonUrl.toDisplayString();
|
||||||
return (bool) nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto statePtr = std::make_shared<AnimStateMachine::State>(stdId, iter->second, interpTarget, interpDuration);
|
auto statePtr = std::make_shared<AnimStateMachine::State>(stdId, iter->second, interpTarget, interpDuration);
|
||||||
|
@ -337,19 +337,19 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
||||||
auto transitionsValue = stateObj.value("transitions");
|
auto transitionsValue = stateObj.value("transitions");
|
||||||
if (!transitionsValue.isArray()) {
|
if (!transitionsValue.isArray()) {
|
||||||
qCritical(animation) << "AnimNodeLoader, bad array \"transitions\" in stateMachine node, stateId =" << id << "nodeId =" << nodeId << "url =" << jsonUrl.toDisplayString();
|
qCritical(animation) << "AnimNodeLoader, bad array \"transitions\" in stateMachine node, stateId =" << id << "nodeId =" << nodeId << "url =" << jsonUrl.toDisplayString();
|
||||||
return (bool) nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto transitionsArray = transitionsValue.toArray();
|
auto transitionsArray = transitionsValue.toArray();
|
||||||
for (const auto& transitionValue : transitionsArray) {
|
for (const auto& transitionValue : transitionsArray) {
|
||||||
if (!transitionValue.isObject()) {
|
if (!transitionValue.isObject()) {
|
||||||
qCritical(animation) << "AnimNodeLoader, bad transition object in \"transtions\", stateId =" << id << "nodeId =" << nodeId << "url =" << jsonUrl.toDisplayString();
|
qCritical(animation) << "AnimNodeLoader, bad transition object in \"transtions\", stateId =" << id << "nodeId =" << nodeId << "url =" << jsonUrl.toDisplayString();
|
||||||
return (bool) nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
auto transitionObj = transitionValue.toObject();
|
auto transitionObj = transitionValue.toObject();
|
||||||
|
|
||||||
READ_STRING(var, transitionObj, nodeId, jsonUrl);
|
READ_STRING(var, transitionObj, nodeId, jsonUrl, false);
|
||||||
READ_STRING(state, transitionObj, nodeId, jsonUrl);
|
READ_STRING(state, transitionObj, nodeId, jsonUrl, false);
|
||||||
|
|
||||||
transitionMap.insert(TransitionMap::value_type(statePtr, StringPair(var.toStdString(), state.toStdString())));
|
transitionMap.insert(TransitionMap::value_type(statePtr, StringPair(var.toStdString(), state.toStdString())));
|
||||||
}
|
}
|
||||||
|
@ -363,7 +363,7 @@ bool processStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj,
|
||||||
srcState->addTransition(AnimStateMachine::State::Transition(transition.second.first, iter->second));
|
srcState->addTransition(AnimStateMachine::State::Transition(transition.second.first, iter->second));
|
||||||
} else {
|
} else {
|
||||||
qCCritical(animation) << "AnimNodeLoader, bad state machine transtion from srcState =" << srcState->_id.c_str() << "dstState =" << transition.second.second.c_str() << "nodeId =" << nodeId << "url = " << jsonUrl.toDisplayString();
|
qCCritical(animation) << "AnimNodeLoader, bad state machine transtion from srcState =" << srcState->_id.c_str() << "dstState =" << transition.second.second.c_str() << "nodeId =" << nodeId << "url = " << jsonUrl.toDisplayString();
|
||||||
return (bool) nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue