Added Game Mode in the World Editor
This commit is contained in:
parent
2e5678e863
commit
7a69346ff3
|
@ -219,7 +219,7 @@ void CSceneManager::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& Vi
|
|||
{
|
||||
ERenderOptions Options = pRenderer->RenderOptions();
|
||||
|
||||
if (Options & eDrawWorld)
|
||||
if (Options & eDrawWorld || ViewInfo.GameMode)
|
||||
{
|
||||
for (u32 n = 0; n < mModelNodes.size(); n++)
|
||||
if (mModelNodes[n]->IsVisible())
|
||||
|
@ -230,21 +230,21 @@ void CSceneManager::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& Vi
|
|||
mStaticNodes[n]->AddToRenderer(pRenderer, ViewInfo);
|
||||
}
|
||||
|
||||
if (Options & eDrawWorldCollision)
|
||||
if (Options & eDrawWorldCollision && !ViewInfo.GameMode)
|
||||
{
|
||||
for (u32 n = 0; n < mCollisionNodes.size(); n++)
|
||||
if (mCollisionNodes[n]->IsVisible())
|
||||
mCollisionNodes[n]->AddToRenderer(pRenderer, ViewInfo);
|
||||
}
|
||||
|
||||
if (Options & eDrawLights)
|
||||
if (Options & eDrawLights && !ViewInfo.GameMode)
|
||||
{
|
||||
for (u32 n = 0; n < mLightNodes.size(); n++)
|
||||
if (mLightNodes[n]->IsVisible())
|
||||
mLightNodes[n]->AddToRenderer(pRenderer, ViewInfo);
|
||||
}
|
||||
|
||||
if ((Options & eDrawObjects) || (Options & eDrawObjectCollision))
|
||||
if ((Options & eDrawObjects) || (Options & eDrawObjectCollision) || ViewInfo.GameMode)
|
||||
{
|
||||
for (u32 n = 0; n < mScriptNodes.size(); n++)
|
||||
if (mScriptNodes[n]->IsVisible())
|
||||
|
@ -271,6 +271,16 @@ SRayIntersection CSceneManager::SceneRayCast(const CRay& Ray, const SViewInfo& V
|
|||
((renderOptions & ((ERenderOptions) (eDrawObjects | eDrawObjectCollision))) != 0), ((renderOptions & eDrawLights) != 0)
|
||||
};
|
||||
|
||||
// Override visibility for game mode
|
||||
if (ViewInfo.GameMode)
|
||||
{
|
||||
NodesVisible[0] = false;
|
||||
NodesVisible[1] = true;
|
||||
NodesVisible[2] = false;
|
||||
NodesVisible[3] = true;
|
||||
NodesVisible[4] = false;
|
||||
}
|
||||
|
||||
// Less hacky stuff
|
||||
CRayCollisionTester Tester(Ray);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ struct SViewInfo
|
|||
class CRenderer *pRenderer;
|
||||
|
||||
class CCamera *pCamera;
|
||||
bool GameMode;
|
||||
CFrustumPlanes ViewFrustum;
|
||||
CMatrix4f RotationOnlyViewMatrix;
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@ CScriptObject::CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemp
|
|||
mpDisplayModel = nullptr;
|
||||
mpBillboard = nullptr;
|
||||
mpCollision = nullptr;
|
||||
mHasInGameModel = false;
|
||||
}
|
||||
|
||||
CScriptObject::~CScriptObject()
|
||||
|
@ -36,6 +37,7 @@ void CScriptObject::EvaluateProperties()
|
|||
mpScale = mpTemplate->FindScale(mpProperties);
|
||||
mpActive = mpTemplate->FindActive(mpProperties);
|
||||
mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
|
||||
mHasInGameModel = mpTemplate->HasInGameModel(mpProperties);
|
||||
mVolumeShape = mpTemplate->VolumeShape(this);
|
||||
EvaluateDisplayModel();
|
||||
EvaluateBillboard();
|
||||
|
@ -168,7 +170,12 @@ bool CScriptObject::IsActive() const
|
|||
if (mpActive)
|
||||
return mpActive->Get();
|
||||
else
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CScriptObject::HasInGameModel() const
|
||||
{
|
||||
return mHasInGameModel;
|
||||
}
|
||||
|
||||
void CScriptObject::SetPosition(const CVector3f& newPos)
|
||||
|
|
|
@ -37,6 +37,8 @@ class CScriptObject
|
|||
CToken mModelToken;
|
||||
CToken mBillboardToken;
|
||||
CToken mCollisionToken;
|
||||
bool mHasInGameModel;
|
||||
|
||||
EVolumeShape mVolumeShape;
|
||||
|
||||
public:
|
||||
|
@ -69,6 +71,7 @@ public:
|
|||
CVector3f Scale() const;
|
||||
TString InstanceName() const;
|
||||
bool IsActive() const;
|
||||
bool HasInGameModel() const;
|
||||
void SetPosition(const CVector3f& newPos);
|
||||
void SetRotation(const CVector3f& newRot);
|
||||
void SetScale(const CVector3f& newScale);
|
||||
|
|
|
@ -210,7 +210,7 @@ CPropertyStruct* CScriptTemplate::FindLightParameters(CPropertyStruct *pProperti
|
|||
return TFetchProperty<CPropertyStruct*, eStructProperty>(pProperties, mLightParametersIDString);
|
||||
}
|
||||
|
||||
// todo: merge these three functions, they have near-identical code
|
||||
// todo: merge these four functions, they have near-identical code
|
||||
CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties)
|
||||
{
|
||||
for (auto it = mAssets.begin(); it != mAssets.end(); it++)
|
||||
|
@ -319,6 +319,36 @@ CCollisionMeshGroup* CScriptTemplate::FindCollision(CPropertyStruct *pProperties
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool CScriptTemplate::HasInGameModel(CPropertyStruct *pProperties)
|
||||
{
|
||||
for (auto it = mAssets.begin(); it != mAssets.end(); it++)
|
||||
{
|
||||
if ((it->AssetType != SEditorAsset::eModel) && (it->AssetType != SEditorAsset::eAnimParams)) continue;
|
||||
if (it->AssetSource == SEditorAsset::eFile) continue;
|
||||
CResource *pRes = nullptr;
|
||||
|
||||
CPropertyBase *pProp = pProperties->PropertyByIDString(it->AssetLocation);
|
||||
|
||||
if (pProp->Type() == eFileProperty)
|
||||
{
|
||||
CFileProperty *pFile = static_cast<CFileProperty*>(pProp);
|
||||
pRes = pFile->Get();
|
||||
}
|
||||
|
||||
else if (pProp->Type() == eAnimParamsProperty)
|
||||
{
|
||||
CAnimParamsProperty *pParams = static_cast<CAnimParamsProperty*>(pProp);
|
||||
pRes = pParams->Get().GetCurrentModel(it->ForceNodeIndex);
|
||||
}
|
||||
|
||||
// Verify resource exists + is correct type
|
||||
if (pRes && (pRes->Type() == eModel))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CScriptTemplate::HasPosition()
|
||||
{
|
||||
return (!mPositionIDString.IsEmpty());
|
||||
|
|
|
@ -117,6 +117,7 @@ public:
|
|||
CModel* FindDisplayModel(CPropertyStruct *pProperties);
|
||||
CTexture* FindBillboardTexture(CPropertyStruct *pProperties);
|
||||
CCollisionMeshGroup* FindCollision(CPropertyStruct *pProperties);
|
||||
bool HasInGameModel(CPropertyStruct *pProperties);
|
||||
bool HasPosition();
|
||||
|
||||
// Object Tracking
|
||||
|
|
|
@ -19,6 +19,7 @@ void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewIn
|
|||
{
|
||||
if (!mpCollision) return;
|
||||
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
if (ViewInfo.GameMode) return;
|
||||
|
||||
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ ENodeType CLightNode::NodeType()
|
|||
void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
||||
{
|
||||
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
if (ViewInfo.GameMode) return;
|
||||
|
||||
pRenderer->AddOpaqueMesh(this, 0, CAABox(mPosition + 0.5f, mPosition - 0.5f), eDrawMesh);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
|||
{
|
||||
if (!mpModel) return;
|
||||
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
|
||||
if (ViewInfo.GameMode) return;
|
||||
|
||||
if (!mpModel->HasTransparency(mActiveMatSet))
|
||||
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh);
|
||||
|
|
|
@ -105,12 +105,20 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
|||
{
|
||||
if (!mpInstance) return;
|
||||
|
||||
// If we're in game mode, then override other visibility settings.
|
||||
if (ViewInfo.GameMode)
|
||||
{
|
||||
if (!mpInstance->IsActive() || !mpInstance->HasInGameModel())
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, we proceed as normal
|
||||
ERenderOptions options = pRenderer->RenderOptions();
|
||||
|
||||
if (options & eDrawObjectCollision)
|
||||
if ((options & eDrawObjectCollision) && (!ViewInfo.GameMode))
|
||||
mpCollisionNode->AddToRenderer(pRenderer, ViewInfo);
|
||||
|
||||
if (options & eDrawObjects)
|
||||
if (options & eDrawObjects || ViewInfo.GameMode)
|
||||
{
|
||||
if (ViewInfo.ViewFrustum.BoxInFrustum(AABox()))
|
||||
{
|
||||
|
@ -145,7 +153,7 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
|||
}
|
||||
}
|
||||
|
||||
if (IsSelected())
|
||||
if (IsSelected() && !ViewInfo.GameMode)
|
||||
{
|
||||
// Script nodes always draw their selections regardless of frustum planes
|
||||
// in order to ensure that script connection lines don't get improperly culled.
|
||||
|
@ -286,7 +294,17 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID,
|
|||
out.pNode = this;
|
||||
out.AssetIndex = AssetID;
|
||||
|
||||
if (options & eDrawObjects)
|
||||
// If we're in game mode, then check whether we're visible before proceeding with the ray test.
|
||||
if (ViewInfo.GameMode)
|
||||
{
|
||||
if (!mpInstance->IsActive() || !mpInstance->HasInGameModel())
|
||||
{
|
||||
out.Hit = false;
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
if (options & eDrawObjects || ViewInfo.GameMode)
|
||||
{
|
||||
// Model test
|
||||
if (mpActiveModel || !mpBillboard)
|
||||
|
|
|
@ -38,7 +38,7 @@ void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
|
|||
}
|
||||
}
|
||||
|
||||
if (mSelected)
|
||||
if (mSelected && !ViewInfo.GameMode)
|
||||
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ CBasicViewport::CBasicViewport(QWidget *pParent) :
|
|||
setMouseTracking(true);
|
||||
mCamera.SetAspectRatio((float) width() / height());
|
||||
mViewInfo.pCamera = &mCamera;
|
||||
mViewInfo.GameMode = false;
|
||||
}
|
||||
|
||||
CBasicViewport::~CBasicViewport()
|
||||
|
@ -56,7 +57,8 @@ void CBasicViewport::paintGL()
|
|||
Paint();
|
||||
|
||||
// Finally, draw XYZ axes in the corner
|
||||
DrawAxes();
|
||||
if (!mViewInfo.GameMode)
|
||||
DrawAxes();
|
||||
}
|
||||
|
||||
void CBasicViewport::resizeGL(int w, int h)
|
||||
|
@ -163,6 +165,11 @@ void CBasicViewport::contextMenuEvent(QContextMenuEvent *pEvent)
|
|||
ContextMenu(pEvent);
|
||||
}
|
||||
|
||||
void CBasicViewport::SetGameMode(bool Enabled)
|
||||
{
|
||||
mViewInfo.GameMode = Enabled;
|
||||
}
|
||||
|
||||
void CBasicViewport::SetCursorState(const QCursor &Cursor)
|
||||
{
|
||||
mCursorState = Cursor;
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
void focusOutEvent(QFocusEvent *pEvent);
|
||||
void contextMenuEvent(QContextMenuEvent *pEvent);
|
||||
|
||||
void SetGameMode(bool Enabled);
|
||||
void SetCursorState(const QCursor& Cursor);
|
||||
void SetCursorVisible(bool visible);
|
||||
bool IsCursorVisible();
|
||||
|
|
|
@ -132,15 +132,21 @@ void CSceneViewport::keyReleaseEvent(QKeyEvent* pEvent)
|
|||
// ************ PROTECTED SLOTS ************
|
||||
void CSceneViewport::CheckUserInput()
|
||||
{
|
||||
if (!underMouse() || IsMouseInputActive())
|
||||
bool MouseActive = (underMouse() && !IsMouseInputActive());
|
||||
|
||||
if (!MouseActive || mViewInfo.GameMode)
|
||||
{
|
||||
ResetHover();
|
||||
mGizmoHovering = false;
|
||||
return;
|
||||
|
||||
if (!MouseActive)
|
||||
return;
|
||||
}
|
||||
|
||||
CRay ray = CastRay();
|
||||
CheckGizmoInput(ray);
|
||||
|
||||
if (!mViewInfo.GameMode)
|
||||
CheckGizmoInput(ray);
|
||||
|
||||
if (!mpEditor->Gizmo()->IsTransforming())
|
||||
SceneRayCast(ray);
|
||||
|
@ -152,7 +158,7 @@ void CSceneViewport::Paint()
|
|||
|
||||
mpRenderer->BeginFrame();
|
||||
|
||||
if (mDrawSky)
|
||||
if (mDrawSky || mViewInfo.GameMode)
|
||||
{
|
||||
CModel *pSky = mpScene->GetActiveSkybox();
|
||||
if (pSky) mpRenderer->RenderSky(pSky, mViewInfo);
|
||||
|
@ -163,7 +169,7 @@ void CSceneViewport::Paint()
|
|||
mpRenderer->RenderBuckets(mViewInfo);
|
||||
mpRenderer->RenderBloom();
|
||||
|
||||
if (mpEditor->IsGizmoVisible())
|
||||
if (mpEditor->IsGizmoVisible() && !mViewInfo.GameMode)
|
||||
{
|
||||
CGizmo *pGizmo = mpEditor->Gizmo();
|
||||
mCamera.LoadMatrices();
|
||||
|
|
|
@ -467,3 +467,8 @@ void CWorldEditor::on_ActionDrawObjectCollision_triggered()
|
|||
{
|
||||
ui->MainViewport->Renderer()->ToggleObjectCollision(ui->ActionDrawObjectCollision->isChecked());
|
||||
}
|
||||
|
||||
void CWorldEditor::on_ActionGameMode_triggered()
|
||||
{
|
||||
ui->MainViewport->SetGameMode(ui->ActionGameMode->isChecked());
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ private slots:
|
|||
void on_ActionIncrementGizmo_triggered();
|
||||
void on_ActionDecrementGizmo_triggered();
|
||||
void on_ActionDrawObjectCollision_triggered();
|
||||
void on_ActionGameMode_triggered();
|
||||
};
|
||||
|
||||
#endif // CWORLDEDITOR_H
|
||||
|
|
|
@ -267,6 +267,8 @@
|
|||
<addaction name="ActionFakeBloom"/>
|
||||
<addaction name="ActionBloom"/>
|
||||
</widget>
|
||||
<addaction name="ActionGameMode"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="ActionDrawWorld"/>
|
||||
<addaction name="ActionDrawObjects"/>
|
||||
<addaction name="ActionDrawCollision"/>
|
||||
|
@ -715,6 +717,17 @@
|
|||
<string>4</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="ActionGameMode">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Game Mode</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>G</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
Loading…
Reference in New Issue