summaryrefslogtreecommitdiff
path: root/app/legion/worldmanager.cpp
blob: abd5d963f34c02d7c687f6dbb30fd47d4fe614be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Contains all world state--the main game database
//
// $Revision: $
// $NoKeywords: $
//===========================================================================//

#include "worldmanager.h"
#include "legion.h"
#include "heightfield.h"
#include "rendermanager.h"

//-----------------------------------------------------------------------------
// Singleton accessor
//-----------------------------------------------------------------------------
static CWorldManager s_WorldManager;
extern CWorldManager *g_pWorldManager = &s_WorldManager;


//-----------------------------------------------------------------------------
// ConVars
//-----------------------------------------------------------------------------
static ConVar cam_forwardspeed( "cam_forwardspeed", "100", FCVAR_CHEAT, "Sets the camera forward speed" );
static ConVar cam_backwardspeed( "cam_backwardspeed", "100", FCVAR_CHEAT, "Sets the camera backward speed" );


//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
CWorldManager::CWorldManager()
{
	m_pHeightField = NULL;
}

CWorldManager::~CWorldManager()
{
	Assert( m_pHeightField == NULL );
}


//-----------------------------------------------------------------------------
// Level init, shutdown
//-----------------------------------------------------------------------------
LevelRetVal_t CWorldManager::LevelInit( bool bFirstCall )
{
	if ( !bFirstCall )
		return FINISHED;

	Assert( !m_pHeightField );
	m_pHeightField = new CHeightField( 6, 6, 4 );
	if ( !m_pHeightField->LoadHeightFromFile( "maps/testheight.psd" ) )
		return FAILED;

	CreateEntities();
	SetInitialLocalPlayerPosition();
	return FINISHED;
}

LevelRetVal_t CWorldManager::LevelShutdown( bool bFirstCall )
{
	if ( !bFirstCall )
		return FINISHED;

	DestroyEntities();

	if ( m_pHeightField )
	{
		delete m_pHeightField;
		m_pHeightField = NULL;
	}
	return FINISHED;
}


//-----------------------------------------------------------------------------
// Create/ destroy entities
//-----------------------------------------------------------------------------
void CWorldManager::CreateEntities()
{
	m_PlayerEntity.m_pCameraProperty = g_pRenderManager->CreateCameraProperty();
}

void CWorldManager::DestroyEntities()
{
	g_pRenderManager->DestroyCameraProperty( m_PlayerEntity.m_pCameraProperty );
}


//-----------------------------------------------------------------------------
// Gets the camera to world matrix
//-----------------------------------------------------------------------------
CPlayerEntity* CWorldManager::GetLocalPlayer()
{
	return &m_PlayerEntity;
}


//-----------------------------------------------------------------------------
// Sets the initial camera position
//-----------------------------------------------------------------------------
void CWorldManager::SetInitialLocalPlayerPosition()
{
	float flDistance = 1024.0;
	Vector vecCameraDirection( 1.0f, 1.0f, -0.5f );
	VectorNormalize( vecCameraDirection );

	VectorMA( Vector( 512, 512, 0 ), -flDistance, vecCameraDirection, m_PlayerEntity.m_pCameraProperty->m_Origin );

	QAngle angles;
	VectorAngles( vecCameraDirection, m_PlayerEntity.m_pCameraProperty->m_Angles );

}


//-----------------------------------------------------------------------------
// Draws the UI
//-----------------------------------------------------------------------------
void CWorldManager::DrawWorld()
{
	m_pHeightField->Draw( );
}


//-----------------------------------------------------------------------------
// Commands
//-----------------------------------------------------------------------------
void CWorldManager::ForwardStart( const CCommand &args )
{
	CCameraProperty *pCamera = m_PlayerEntity.m_pCameraProperty;
	
	Vector vecForward;
	pCamera->GetForward( &vecForward );
	
	VectorMA( pCamera->m_Velocity, cam_forwardspeed.GetFloat(), vecForward, pCamera->m_Velocity );
}

void CWorldManager::ForwardStop( const CCommand &args )
{
	CCameraProperty *pCamera = m_PlayerEntity.m_pCameraProperty;

	Vector vecForward;
	pCamera->GetForward( &vecForward );

	VectorMA( pCamera->m_Velocity, -cam_forwardspeed.GetFloat(), vecForward, pCamera->m_Velocity );
}

void CWorldManager::BackwardStart( const CCommand &args )
{
	CCameraProperty *pCamera = m_PlayerEntity.m_pCameraProperty;

	Vector vecForward;
	pCamera->GetForward( &vecForward );

	VectorMA( pCamera->m_Velocity, -cam_backwardspeed.GetFloat(), vecForward, pCamera->m_Velocity );
}

void CWorldManager::BackwardStop( const CCommand &args )
{
	CCameraProperty *pCamera = m_PlayerEntity.m_pCameraProperty;

	Vector vecForward;
	pCamera->GetForward( &vecForward );

	VectorMA( pCamera->m_Velocity, cam_backwardspeed.GetFloat(), vecForward, pCamera->m_Velocity );
}