Added Game Mode in the World Editor

This commit is contained in:
parax0 2015-11-26 02:05:26 -07:00
parent 2e5678e863
commit 7a69346ff3
17 changed files with 123 additions and 17 deletions

View File

@ -219,7 +219,7 @@ void CSceneManager::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& Vi
{ {
ERenderOptions Options = pRenderer->RenderOptions(); ERenderOptions Options = pRenderer->RenderOptions();
if (Options & eDrawWorld) if (Options & eDrawWorld || ViewInfo.GameMode)
{ {
for (u32 n = 0; n < mModelNodes.size(); n++) for (u32 n = 0; n < mModelNodes.size(); n++)
if (mModelNodes[n]->IsVisible()) if (mModelNodes[n]->IsVisible())
@ -230,21 +230,21 @@ void CSceneManager::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& Vi
mStaticNodes[n]->AddToRenderer(pRenderer, ViewInfo); mStaticNodes[n]->AddToRenderer(pRenderer, ViewInfo);
} }
if (Options & eDrawWorldCollision) if (Options & eDrawWorldCollision && !ViewInfo.GameMode)
{ {
for (u32 n = 0; n < mCollisionNodes.size(); n++) for (u32 n = 0; n < mCollisionNodes.size(); n++)
if (mCollisionNodes[n]->IsVisible()) if (mCollisionNodes[n]->IsVisible())
mCollisionNodes[n]->AddToRenderer(pRenderer, ViewInfo); mCollisionNodes[n]->AddToRenderer(pRenderer, ViewInfo);
} }
if (Options & eDrawLights) if (Options & eDrawLights && !ViewInfo.GameMode)
{ {
for (u32 n = 0; n < mLightNodes.size(); n++) for (u32 n = 0; n < mLightNodes.size(); n++)
if (mLightNodes[n]->IsVisible()) if (mLightNodes[n]->IsVisible())
mLightNodes[n]->AddToRenderer(pRenderer, ViewInfo); 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++) for (u32 n = 0; n < mScriptNodes.size(); n++)
if (mScriptNodes[n]->IsVisible()) 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) ((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 // Less hacky stuff
CRayCollisionTester Tester(Ray); CRayCollisionTester Tester(Ray);

View File

@ -11,6 +11,7 @@ struct SViewInfo
class CRenderer *pRenderer; class CRenderer *pRenderer;
class CCamera *pCamera; class CCamera *pCamera;
bool GameMode;
CFrustumPlanes ViewFrustum; CFrustumPlanes ViewFrustum;
CMatrix4f RotationOnlyViewMatrix; CMatrix4f RotationOnlyViewMatrix;
}; };

View File

@ -12,6 +12,7 @@ CScriptObject::CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemp
mpDisplayModel = nullptr; mpDisplayModel = nullptr;
mpBillboard = nullptr; mpBillboard = nullptr;
mpCollision = nullptr; mpCollision = nullptr;
mHasInGameModel = false;
} }
CScriptObject::~CScriptObject() CScriptObject::~CScriptObject()
@ -36,6 +37,7 @@ void CScriptObject::EvaluateProperties()
mpScale = mpTemplate->FindScale(mpProperties); mpScale = mpTemplate->FindScale(mpProperties);
mpActive = mpTemplate->FindActive(mpProperties); mpActive = mpTemplate->FindActive(mpProperties);
mpLightParameters = mpTemplate->FindLightParameters(mpProperties); mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
mHasInGameModel = mpTemplate->HasInGameModel(mpProperties);
mVolumeShape = mpTemplate->VolumeShape(this); mVolumeShape = mpTemplate->VolumeShape(this);
EvaluateDisplayModel(); EvaluateDisplayModel();
EvaluateBillboard(); EvaluateBillboard();
@ -168,7 +170,12 @@ bool CScriptObject::IsActive() const
if (mpActive) if (mpActive)
return mpActive->Get(); return mpActive->Get();
else else
return true; return false;
}
bool CScriptObject::HasInGameModel() const
{
return mHasInGameModel;
} }
void CScriptObject::SetPosition(const CVector3f& newPos) void CScriptObject::SetPosition(const CVector3f& newPos)

View File

@ -37,6 +37,8 @@ class CScriptObject
CToken mModelToken; CToken mModelToken;
CToken mBillboardToken; CToken mBillboardToken;
CToken mCollisionToken; CToken mCollisionToken;
bool mHasInGameModel;
EVolumeShape mVolumeShape; EVolumeShape mVolumeShape;
public: public:
@ -69,6 +71,7 @@ public:
CVector3f Scale() const; CVector3f Scale() const;
TString InstanceName() const; TString InstanceName() const;
bool IsActive() const; bool IsActive() const;
bool HasInGameModel() const;
void SetPosition(const CVector3f& newPos); void SetPosition(const CVector3f& newPos);
void SetRotation(const CVector3f& newRot); void SetRotation(const CVector3f& newRot);
void SetScale(const CVector3f& newScale); void SetScale(const CVector3f& newScale);

View File

@ -210,7 +210,7 @@ CPropertyStruct* CScriptTemplate::FindLightParameters(CPropertyStruct *pProperti
return TFetchProperty<CPropertyStruct*, eStructProperty>(pProperties, mLightParametersIDString); 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) CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties)
{ {
for (auto it = mAssets.begin(); it != mAssets.end(); it++) for (auto it = mAssets.begin(); it != mAssets.end(); it++)
@ -319,6 +319,36 @@ CCollisionMeshGroup* CScriptTemplate::FindCollision(CPropertyStruct *pProperties
return nullptr; 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() bool CScriptTemplate::HasPosition()
{ {
return (!mPositionIDString.IsEmpty()); return (!mPositionIDString.IsEmpty());

View File

@ -117,6 +117,7 @@ public:
CModel* FindDisplayModel(CPropertyStruct *pProperties); CModel* FindDisplayModel(CPropertyStruct *pProperties);
CTexture* FindBillboardTexture(CPropertyStruct *pProperties); CTexture* FindBillboardTexture(CPropertyStruct *pProperties);
CCollisionMeshGroup* FindCollision(CPropertyStruct *pProperties); CCollisionMeshGroup* FindCollision(CPropertyStruct *pProperties);
bool HasInGameModel(CPropertyStruct *pProperties);
bool HasPosition(); bool HasPosition();
// Object Tracking // Object Tracking

View File

@ -19,6 +19,7 @@ void CCollisionNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewIn
{ {
if (!mpCollision) return; if (!mpCollision) return;
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
if (ViewInfo.GameMode) return;
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh); pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh);

View File

@ -28,6 +28,7 @@ ENodeType CLightNode::NodeType()
void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) void CLightNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
{ {
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
if (ViewInfo.GameMode) return;
pRenderer->AddOpaqueMesh(this, 0, CAABox(mPosition + 0.5f, mPosition - 0.5f), eDrawMesh); pRenderer->AddOpaqueMesh(this, 0, CAABox(mPosition + 0.5f, mPosition - 0.5f), eDrawMesh);
} }

View File

@ -20,6 +20,7 @@ void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
{ {
if (!mpModel) return; if (!mpModel) return;
if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return; if (!ViewInfo.ViewFrustum.BoxInFrustum(AABox())) return;
if (ViewInfo.GameMode) return;
if (!mpModel->HasTransparency(mActiveMatSet)) if (!mpModel->HasTransparency(mActiveMatSet))
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh); pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawMesh);

View File

@ -105,12 +105,20 @@ void CScriptNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
{ {
if (!mpInstance) return; 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(); ERenderOptions options = pRenderer->RenderOptions();
if (options & eDrawObjectCollision) if ((options & eDrawObjectCollision) && (!ViewInfo.GameMode))
mpCollisionNode->AddToRenderer(pRenderer, ViewInfo); mpCollisionNode->AddToRenderer(pRenderer, ViewInfo);
if (options & eDrawObjects) if (options & eDrawObjects || ViewInfo.GameMode)
{ {
if (ViewInfo.ViewFrustum.BoxInFrustum(AABox())) 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 // Script nodes always draw their selections regardless of frustum planes
// in order to ensure that script connection lines don't get improperly culled. // 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.pNode = this;
out.AssetIndex = AssetID; 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 // Model test
if (mpActiveModel || !mpBillboard) if (mpActiveModel || !mpBillboard)

View File

@ -38,7 +38,7 @@ void CStaticNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)
} }
} }
if (mSelected) if (mSelected && !ViewInfo.GameMode)
pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection); pRenderer->AddOpaqueMesh(this, 0, AABox(), eDrawSelection);
} }

View File

@ -15,6 +15,7 @@ CBasicViewport::CBasicViewport(QWidget *pParent) :
setMouseTracking(true); setMouseTracking(true);
mCamera.SetAspectRatio((float) width() / height()); mCamera.SetAspectRatio((float) width() / height());
mViewInfo.pCamera = &mCamera; mViewInfo.pCamera = &mCamera;
mViewInfo.GameMode = false;
} }
CBasicViewport::~CBasicViewport() CBasicViewport::~CBasicViewport()
@ -56,7 +57,8 @@ void CBasicViewport::paintGL()
Paint(); Paint();
// Finally, draw XYZ axes in the corner // Finally, draw XYZ axes in the corner
DrawAxes(); if (!mViewInfo.GameMode)
DrawAxes();
} }
void CBasicViewport::resizeGL(int w, int h) void CBasicViewport::resizeGL(int w, int h)
@ -163,6 +165,11 @@ void CBasicViewport::contextMenuEvent(QContextMenuEvent *pEvent)
ContextMenu(pEvent); ContextMenu(pEvent);
} }
void CBasicViewport::SetGameMode(bool Enabled)
{
mViewInfo.GameMode = Enabled;
}
void CBasicViewport::SetCursorState(const QCursor &Cursor) void CBasicViewport::SetCursorState(const QCursor &Cursor)
{ {
mCursorState = Cursor; mCursorState = Cursor;

View File

@ -52,6 +52,7 @@ public:
void focusOutEvent(QFocusEvent *pEvent); void focusOutEvent(QFocusEvent *pEvent);
void contextMenuEvent(QContextMenuEvent *pEvent); void contextMenuEvent(QContextMenuEvent *pEvent);
void SetGameMode(bool Enabled);
void SetCursorState(const QCursor& Cursor); void SetCursorState(const QCursor& Cursor);
void SetCursorVisible(bool visible); void SetCursorVisible(bool visible);
bool IsCursorVisible(); bool IsCursorVisible();

View File

@ -132,15 +132,21 @@ void CSceneViewport::keyReleaseEvent(QKeyEvent* pEvent)
// ************ PROTECTED SLOTS ************ // ************ PROTECTED SLOTS ************
void CSceneViewport::CheckUserInput() void CSceneViewport::CheckUserInput()
{ {
if (!underMouse() || IsMouseInputActive()) bool MouseActive = (underMouse() && !IsMouseInputActive());
if (!MouseActive || mViewInfo.GameMode)
{ {
ResetHover(); ResetHover();
mGizmoHovering = false; mGizmoHovering = false;
return;
if (!MouseActive)
return;
} }
CRay ray = CastRay(); CRay ray = CastRay();
CheckGizmoInput(ray);
if (!mViewInfo.GameMode)
CheckGizmoInput(ray);
if (!mpEditor->Gizmo()->IsTransforming()) if (!mpEditor->Gizmo()->IsTransforming())
SceneRayCast(ray); SceneRayCast(ray);
@ -152,7 +158,7 @@ void CSceneViewport::Paint()
mpRenderer->BeginFrame(); mpRenderer->BeginFrame();
if (mDrawSky) if (mDrawSky || mViewInfo.GameMode)
{ {
CModel *pSky = mpScene->GetActiveSkybox(); CModel *pSky = mpScene->GetActiveSkybox();
if (pSky) mpRenderer->RenderSky(pSky, mViewInfo); if (pSky) mpRenderer->RenderSky(pSky, mViewInfo);
@ -163,7 +169,7 @@ void CSceneViewport::Paint()
mpRenderer->RenderBuckets(mViewInfo); mpRenderer->RenderBuckets(mViewInfo);
mpRenderer->RenderBloom(); mpRenderer->RenderBloom();
if (mpEditor->IsGizmoVisible()) if (mpEditor->IsGizmoVisible() && !mViewInfo.GameMode)
{ {
CGizmo *pGizmo = mpEditor->Gizmo(); CGizmo *pGizmo = mpEditor->Gizmo();
mCamera.LoadMatrices(); mCamera.LoadMatrices();

View File

@ -467,3 +467,8 @@ void CWorldEditor::on_ActionDrawObjectCollision_triggered()
{ {
ui->MainViewport->Renderer()->ToggleObjectCollision(ui->ActionDrawObjectCollision->isChecked()); ui->MainViewport->Renderer()->ToggleObjectCollision(ui->ActionDrawObjectCollision->isChecked());
} }
void CWorldEditor::on_ActionGameMode_triggered()
{
ui->MainViewport->SetGameMode(ui->ActionGameMode->isChecked());
}

View File

@ -76,6 +76,7 @@ private slots:
void on_ActionIncrementGizmo_triggered(); void on_ActionIncrementGizmo_triggered();
void on_ActionDecrementGizmo_triggered(); void on_ActionDecrementGizmo_triggered();
void on_ActionDrawObjectCollision_triggered(); void on_ActionDrawObjectCollision_triggered();
void on_ActionGameMode_triggered();
}; };
#endif // CWORLDEDITOR_H #endif // CWORLDEDITOR_H

View File

@ -267,6 +267,8 @@
<addaction name="ActionFakeBloom"/> <addaction name="ActionFakeBloom"/>
<addaction name="ActionBloom"/> <addaction name="ActionBloom"/>
</widget> </widget>
<addaction name="ActionGameMode"/>
<addaction name="separator"/>
<addaction name="ActionDrawWorld"/> <addaction name="ActionDrawWorld"/>
<addaction name="ActionDrawObjects"/> <addaction name="ActionDrawObjects"/>
<addaction name="ActionDrawCollision"/> <addaction name="ActionDrawCollision"/>
@ -715,6 +717,17 @@
<string>4</string> <string>4</string>
</property> </property>
</action> </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> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>