1
0
forked from 0ad/0ad

Cleanup Camera related code and uses constant references where possible.

Commented By: elexis
Differential Revision: https://code.wildfiregames.com/D2350
This was SVN commit r23033.
This commit is contained in:
Vladislav Belov 2019-10-03 12:58:47 +00:00
parent 7f38bef8e1
commit a19b14aeb7
9 changed files with 23 additions and 33 deletions

View File

@ -102,7 +102,7 @@ CCameraController::CCameraController(CCamera& camera)
m_Camera.UpdateFrustum();
}
void CCameraController::Initialize()
void CCameraController::LoadConfig()
{
CFG_GET_VAL("view.scroll.speed", m_ViewScrollSpeed);
CFG_GET_VAL("view.scroll.speed.modifier", m_ViewScrollSpeedModifier);
@ -516,7 +516,7 @@ void CCameraController::ResetCameraTarget(const CVector3D& target)
m_FollowEntity = INVALID_ENTITY;
}
void CCameraController::CameraFollow(entity_id_t entity, bool firstPerson)
void CCameraController::FollowEntity(entity_id_t entity, bool firstPerson)
{
m_FollowEntity = entity;
m_FollowFirstPerson = firstPerson;

View File

@ -30,7 +30,7 @@ class CCameraController
public:
CCameraController(CCamera& camera);
void Initialize();
void LoadConfig();
InReaction HandleEvent(const SDL_Event_* ev);
@ -42,12 +42,9 @@ public:
void SetCamera(const CVector3D& pos, float rotX, float rotY, float zoom);
void MoveCameraTarget(const CVector3D& target);
void ResetCameraTarget(const CVector3D& target);
void CameraFollow(entity_id_t entity, bool firstPerson);
void FollowEntity(entity_id_t entity, bool firstPerson);
entity_id_t GetFollowedEntity();
// Set projection of current camera using near, far, and FOV values
void SetCameraProjection();
void Update(const float deltaRealTime);
void SetViewport(const SViewPort& vp);
@ -69,6 +66,11 @@ private:
void SetupCameraMatrixNonSmooth(CMatrix3D* orientation);
void FocusHeight(bool smooth);
/**
* Set projection of current camera using near, far, and FOV values
*/
void SetCameraProjection();
CCamera& m_Camera;
/**

View File

@ -206,7 +206,7 @@ CTerritoryTexture& CGameView::GetTerritoryTexture()
int CGameView::Initialize()
{
m->CameraController.Initialize();
m->CameraController.LoadConfig();
return 0;
}
@ -351,9 +351,9 @@ void CGameView::ResetCameraTarget(const CVector3D& target)
m->CameraController.ResetCameraTarget(target);
}
void CGameView::CameraFollow(entity_id_t entity, bool firstPerson)
void CGameView::FollowEntity(entity_id_t entity, bool firstPerson)
{
m->CameraController.CameraFollow(entity, firstPerson);
m->CameraController.FollowEntity(entity, firstPerson);
}
entity_id_t CGameView::GetFollowedEntity()
@ -361,11 +361,6 @@ entity_id_t CGameView::GetFollowedEntity()
return m->CameraController.GetFollowedEntity();
}
void CGameView::SetCameraProjection()
{
m->CameraController.SetCameraProjection();
}
InReaction game_view_handler(const SDL_Event_* ev)
{
// put any events that must be processed even if inactive here

View File

@ -65,12 +65,9 @@ public:
void SetCamera(const CVector3D& pos, float rotX, float rotY, float zoom);
void MoveCameraTarget(const CVector3D& target);
void ResetCameraTarget(const CVector3D& target);
void CameraFollow(entity_id_t entity, bool firstPerson);
void FollowEntity(entity_id_t entity, bool firstPerson);
entity_id_t GetFollowedEntity();
// Set projection of current camera using near, far, and FOV values
void SetCameraProjection();
#define DECLARE_BOOLEAN_SETTING(NAME) \
bool Get##NAME##Enabled() const; \
void Set##NAME##Enabled(bool Enabled);

View File

@ -141,7 +141,7 @@ void JSI_GameView::CameraFollow(ScriptInterface::CxPrivate* UNUSED(pCxPrivate),
if (!g_Game || !g_Game->GetView())
return;
g_Game->GetView()->CameraFollow(entityid, false);
g_Game->GetView()->FollowEntity(entityid, false);
}
/**
@ -153,7 +153,7 @@ void JSI_GameView::CameraFollowFPS(ScriptInterface::CxPrivate* UNUSED(pCxPrivate
if (!g_Game || !g_Game->GetView())
return;
g_Game->GetView()->CameraFollow(entityid, true);
g_Game->GetView()->FollowEntity(entityid, true);
}
entity_id_t JSI_GameView::GetFollowedEntity(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -128,7 +128,7 @@ void CTouchInput::OnFingerMotion(int id, int x, int y)
{
m_State = STATE_PANNING;
CCamera& camera = *(g_Game->GetView()->GetCamera());
const CCamera& camera = *(g_Game->GetView()->GetCamera());
m_PanFocus = camera.GetWorldCoordinates(m_FirstTouchPos.X, m_FirstTouchPos.Y, true);
m_PanDist = (m_PanFocus - camera.GetOrientation().GetTranslation()).Y;
}

View File

@ -346,8 +346,7 @@ void WriteBigScreenshot(const VfsPath& extension, int tiles)
{
g_Renderer.Resize(tile_w, tile_h);
SViewPort vp = { 0, 0, tile_w, tile_h };
g_Game->GetView()->GetCamera()->SetViewPort(vp);
g_Game->GetView()->SetCameraProjection();
g_Game->GetView()->SetViewport(vp);
}
#if !CONFIG2_GLES
@ -404,8 +403,7 @@ void WriteBigScreenshot(const VfsPath& extension, int tiles)
{
g_Renderer.Resize(g_xres, g_yres);
SViewPort vp = { 0, 0, g_xres, g_yres };
g_Game->GetView()->GetCamera()->SetViewPort(vp);
g_Game->GetView()->SetCameraProjection();
g_Game->GetView()->SetViewport(vp);
g_Game->GetView()->GetCamera()->SetPerspectiveProjectionTile(1, 0, 0);
}

View File

@ -1253,7 +1253,7 @@ void CPatchRData::RenderSides(CShaderProgramPtr& shader)
void CPatchRData::RenderPriorities(CTextRenderer& textRenderer)
{
CTerrain* terrain = m_Patch->m_Parent;
CCamera* camera = g_Game->GetView()->GetCamera();
const CCamera& camera = *(g_Game->GetView()->GetCamera());
for (ssize_t j = 0; j < PATCH_SIZE; ++j)
{
@ -1270,7 +1270,7 @@ void CPatchRData::RenderPriorities(CTextRenderer& textRenderer)
pos.Z += TERRAIN_TILE_SIZE/4.f;
float x, y;
camera->GetScreenCoordinates(pos, x, y);
camera.GetScreenCoordinates(pos, x, y);
textRenderer.PrintfAt(x, y, L"%d", m_Patch->m_MiniPatches[j][i].Priority);
}

View File

@ -62,8 +62,7 @@ QUERYHANDLER(CinemaRecord)
{
g_Renderer.Resize(w, h);
SViewPort vp = { 0, 0, w, h };
g_Game->GetView()->GetCamera()->SetViewPort(vp);
g_Game->GetView()->SetCameraProjection();
g_Game->GetView()->SetViewport(vp);
}
unsigned char* img = new unsigned char [w*h*3];
@ -114,8 +113,7 @@ QUERYHANDLER(CinemaRecord)
{
g_Renderer.Resize(g_xres, g_yres);
SViewPort vp = { 0, 0, g_xres, g_yres };
g_Game->GetView()->GetCamera()->SetViewPort(vp);
g_Game->GetView()->SetCameraProjection();
g_Game->GetView()->SetViewport(vp);
}
}