2004-07-27 23:00:53 +02:00
|
|
|
#ifndef _GameView_H
|
|
|
|
#define _GameView_H
|
|
|
|
|
2005-10-19 19:16:34 +02:00
|
|
|
// needed by minimap
|
|
|
|
extern float g_MaxZoomHeight; //note: Max terrain height is this minus YMinOffset
|
|
|
|
extern float g_YMinOffset;
|
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
#include "Camera.h"
|
2005-12-06 07:58:30 +01:00
|
|
|
#include "CinemaTrack.h"
|
|
|
|
#include "ModelDef.h"
|
2004-07-31 17:57:18 +02:00
|
|
|
#include "Vector3D.h"
|
2006-02-15 01:45:16 +01:00
|
|
|
#include "LightEnv.h"
|
2005-05-18 07:32:09 +02:00
|
|
|
#include "scripting/ScriptableObject.h"
|
|
|
|
|
2005-10-20 19:44:56 +02:00
|
|
|
#include "lib/input.h"
|
2005-08-15 01:34:37 +02:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
class CGame;
|
|
|
|
class CGameAttributes;
|
|
|
|
class CWorld;
|
|
|
|
class CTerrain;
|
|
|
|
class CUnitManager;
|
2005-05-10 09:13:25 +02:00
|
|
|
class CProjectileManager;
|
2004-07-27 23:00:53 +02:00
|
|
|
class CModel;
|
2005-12-06 21:16:50 +01:00
|
|
|
class CEntity;
|
2004-07-27 23:00:53 +02:00
|
|
|
|
2005-05-18 07:32:09 +02:00
|
|
|
class CGameView: public CJSObject<CGameView>
|
2004-07-27 23:00:53 +02:00
|
|
|
{
|
2006-03-21 21:55:45 +01:00
|
|
|
public:
|
|
|
|
static const float defaultFOV, defaultNear, defaultFar;
|
|
|
|
|
|
|
|
private:
|
2004-07-27 23:00:53 +02:00
|
|
|
CGame *m_pGame;
|
|
|
|
CWorld *m_pWorld;
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2006-01-22 20:12:30 +01:00
|
|
|
/**
|
|
|
|
* m_ViewCamera: this camera controls the eye position when rendering
|
|
|
|
*/
|
|
|
|
CCamera m_ViewCamera;
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2006-01-22 20:12:30 +01:00
|
|
|
/**
|
|
|
|
* m_CullCamera: this camera controls the frustum that is used for culling
|
|
|
|
* and shadow calculations
|
2006-02-15 01:45:16 +01:00
|
|
|
*
|
2006-01-22 20:12:30 +01:00
|
|
|
* Note that all code that works with camera movements should only change
|
|
|
|
* m_ViewCamera. The render functions automatically sync the cull camera to
|
|
|
|
* the view camera depending on the value of m_LockCullCamera.
|
|
|
|
*/
|
|
|
|
CCamera m_CullCamera;
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2006-01-22 20:12:30 +01:00
|
|
|
/**
|
|
|
|
* m_LockCullCamera: When @c true, the cull camera is locked in place.
|
|
|
|
* When @c false, the cull camera follows the view camera.
|
2006-02-15 01:45:16 +01:00
|
|
|
*
|
2006-01-22 20:12:30 +01:00
|
|
|
* Exposed to JS as gameView.lockCullCamera
|
|
|
|
*/
|
|
|
|
bool m_LockCullCamera;
|
2006-02-15 01:45:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* m_cachedLightEnv: Cache global lighting environment. This is used to check whether the
|
|
|
|
* environment has changed during the last frame, so that vertex data can be updated etc.
|
|
|
|
*/
|
|
|
|
CLightEnv m_cachedLightEnv;
|
|
|
|
|
2005-12-06 07:58:30 +01:00
|
|
|
CCinemaManager m_TrackManager;
|
2006-02-05 03:51:02 +01:00
|
|
|
CCinemaTrack m_TestTrack;
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Settings
|
|
|
|
float m_ViewScrollSpeed;
|
|
|
|
float m_ViewRotateSensitivity;
|
2004-11-11 08:09:32 +01:00
|
|
|
float m_ViewRotateSensitivityKeyboard;
|
2004-07-31 17:57:18 +02:00
|
|
|
float m_ViewRotateAboutTargetSensitivity;
|
2004-11-11 08:09:32 +01:00
|
|
|
float m_ViewRotateAboutTargetSensitivityKeyboard;
|
2004-07-31 17:57:18 +02:00
|
|
|
float m_ViewDragSensitivity;
|
|
|
|
float m_ViewZoomSensitivityWheel;
|
|
|
|
float m_ViewZoomSensitivity;
|
|
|
|
float m_ViewZoomSmoothness; // 0.0 = instantaneous zooming, 1.0 = so slow it never moves
|
|
|
|
float m_ViewSnapSmoothness; // Just the same.
|
|
|
|
|
2005-09-28 05:49:11 +02:00
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Camera Controls State
|
|
|
|
CVector3D m_CameraDelta;
|
|
|
|
CVector3D m_CameraPivot;
|
2005-12-06 07:58:30 +01:00
|
|
|
|
|
|
|
CEntity* m_UnitView;
|
2005-12-06 21:16:50 +01:00
|
|
|
CModel* m_UnitViewProp;
|
2005-12-06 07:58:30 +01:00
|
|
|
CEntity* m_UnitAttach;
|
2004-07-31 17:57:18 +02:00
|
|
|
//float m_CameraZoom;
|
|
|
|
std::vector<CVector3D> m_CameraTargets;
|
|
|
|
|
2005-09-29 01:57:55 +02:00
|
|
|
// Accumulate zooming changes across frames for smoothness
|
|
|
|
float m_ZoomDelta;
|
2006-02-15 01:45:16 +01:00
|
|
|
|
|
|
|
// Check whether lighting environment has changed and update vertex data if necessary
|
|
|
|
void CheckLightEnv();
|
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
// RenderTerrain: iterate through all terrain patches and submit all patches
|
2005-10-09 05:43:03 +02:00
|
|
|
// in viewing frustum to the renderer, for terrain, water and LOS painting
|
2004-07-27 23:00:53 +02:00
|
|
|
void RenderTerrain(CTerrain *pTerrain);
|
2005-09-18 05:47:15 +02:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
// RenderModels: iterate through model list and submit all models in viewing
|
|
|
|
// frustum to the Renderer
|
2005-05-10 09:13:25 +02:00
|
|
|
void RenderModels(CUnitManager *pUnitMan, CProjectileManager *pProjectileManager);
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
// SubmitModelRecursive: recurse down given model, submitting it and all its
|
|
|
|
// descendents to the renderer
|
|
|
|
void SubmitModelRecursive(CModel *pModel);
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
// InitResources(): Load all graphics resources (textures, actor objects and
|
|
|
|
// alpha maps) required by the game
|
2005-10-31 19:57:03 +01:00
|
|
|
//void InitResources();
|
2004-12-16 13:41:54 +01:00
|
|
|
|
|
|
|
// UnloadResources(): Unload all graphics resources loaded by InitResources
|
|
|
|
void UnloadResources();
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2005-05-18 07:32:09 +02:00
|
|
|
// JS Interface
|
|
|
|
bool JSI_StartCustomSelection(JSContext *cx, uintN argc, jsval *argv);
|
|
|
|
bool JSI_EndCustomSelection(JSContext *cx, uintN argc, jsval *argv);
|
|
|
|
|
|
|
|
static void ScriptingInit();
|
2004-12-16 13:41:54 +01:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
public:
|
|
|
|
CGameView(CGame *pGame);
|
2004-12-16 13:41:54 +01:00
|
|
|
~CGameView();
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2005-03-22 03:17:55 +01:00
|
|
|
void RegisterInit(CGameAttributes *pAttribs);
|
2005-05-03 23:36:57 +02:00
|
|
|
int Initialize(CGameAttributes *pGameAttributes);
|
2005-03-22 03:17:55 +01:00
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
// Update: Update all the view information (i.e. rotate camera, scroll,
|
2004-07-31 17:57:18 +02:00
|
|
|
// whatever). This will *not* change any World information - only the
|
|
|
|
// *presentation*
|
|
|
|
void Update(float DeltaTime);
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
// Render: Render the World
|
2004-07-27 23:00:53 +02:00
|
|
|
void Render();
|
2005-09-28 05:49:11 +02:00
|
|
|
|
2005-10-20 17:27:39 +02:00
|
|
|
InReaction HandleEvent(const SDL_Event* ev);
|
2005-09-29 01:57:55 +02:00
|
|
|
|
2005-09-28 05:49:11 +02:00
|
|
|
//Keep the camera in between boundaries/smooth camera scrolling/translating
|
|
|
|
//Should call this whenever moving (translating) the camera
|
|
|
|
void CameraLock(CVector3D Trans, bool smooth=true);
|
|
|
|
void CameraLock(float x, float y, float z, bool smooth=true);
|
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
// RenderNoCull: render absolutely everything to a blank frame to force
|
|
|
|
// renderer to load required assets
|
|
|
|
void RenderNoCull();
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
// Camera Control Functions (used by input handler)
|
|
|
|
void ResetCamera();
|
2004-08-03 01:14:54 +02:00
|
|
|
void ResetCameraOrientation();
|
2004-07-31 17:57:18 +02:00
|
|
|
void RotateAboutTarget();
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2004-07-31 17:57:18 +02:00
|
|
|
void PushCameraTarget( const CVector3D& target );
|
|
|
|
void SetCameraTarget( const CVector3D& target );
|
|
|
|
void PopCameraTarget();
|
2005-12-06 07:58:30 +01:00
|
|
|
|
|
|
|
//First person camera attachment (through the eyes of the unit)
|
2005-12-06 21:16:50 +01:00
|
|
|
void ToUnitView(CEntity* target, CModel* prop);
|
2005-12-06 07:58:30 +01:00
|
|
|
//Keep view the same but follow the unit
|
|
|
|
void AttachToUnit(CEntity* target) { m_UnitAttach = target; }
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2005-12-06 07:58:30 +01:00
|
|
|
bool IsAttached () { if( m_UnitAttach ) { return true; } return false; }
|
|
|
|
bool IsUnitView () { if( m_UnitView ) { return true; } return false; }
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
inline CCamera *GetCamera()
|
2006-01-22 20:12:30 +01:00
|
|
|
{ return &m_ViewCamera; }
|
2004-07-27 23:00:53 +02:00
|
|
|
};
|
2005-10-20 17:27:39 +02:00
|
|
|
extern InReaction game_view_handler(const SDL_Event* ev);
|
2005-08-15 01:34:37 +02:00
|
|
|
|
2004-07-27 23:00:53 +02:00
|
|
|
#endif
|