aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/scratchpad_gamedll_helpers.cpp
blob: 153bdba8099ecc7fa09cdca40514ae8661333fd4 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "cbase.h"
#include "scratchpad_gamedll_helpers.h"
#include "iscratchpad3d.h"
#include "player.h"
#include "collisionproperty.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

void ScratchPad_DrawWorldToScratchPad(
	IScratchPad3D *pPad,
	unsigned long flags )
{
	pPad->SetRenderState( IScratchPad3D::RS_FillMode, IScratchPad3D::FillMode_Wireframe );

	if ( flags & SPDRAWWORLD_DRAW_WORLD )
	{
		engine->DrawMapToScratchPad( pPad, 0 );
	}

	if ( flags & (SPDRAWWORLD_DRAW_PLAYERS | SPDRAWWORLD_DRAW_ENTITIES) )
	{
		CBaseEntity *pCur = gEntList.FirstEnt();
		while ( pCur )
		{
			bool bPlayer = ( dynamic_cast< CBasePlayer* >( pCur ) != 0 );
			if ( (bPlayer && !( flags & SPDRAWWORLD_DRAW_PLAYERS )) ||
				(!bPlayer && !( flags & SPDRAWWORLD_DRAW_ENTITIES )) )
			{
				pCur = gEntList.NextEnt( pCur );
				continue;
			}

			ScratchPad_DrawEntityToScratchPad( 
				pPad, 
				flags,
				pCur, 
				bPlayer ? Vector( 1.0, 0.5, 0 ) : Vector( 0.3, 0.3, 1.0 )
				);

			pCur = gEntList.NextEnt( pCur );
		}
	}
}


void ScratchPad_DrawEntityToScratchPad(
	IScratchPad3D *pPad,
	unsigned long flags,
	CBaseEntity *pEnt,
	const Vector &vColor )
{
	// Draw the entity's bbox [todo: draw OBBs here too].
	Vector mins, maxs;
	pEnt->CollisionProp()->WorldSpaceAABB( &mins, &maxs );

	pPad->DrawWireframeBox( mins, maxs, vColor );

	// Draw the edict's index or class?
	char str[512];
	str[0] = 0;
	if ( flags & SPDRAWWORLD_DRAW_EDICT_INDICES )
	{
		char tempStr[512];
		Q_snprintf( tempStr, sizeof( tempStr ), "edict: %d", pEnt->entindex() );
		Q_strncat( str, tempStr, sizeof( str ), COPY_ALL_CHARACTERS );
	}

	if ( flags & SPDRAWWORLD_DRAW_ENTITY_CLASSNAMES )
	{
		if ( str[0] != 0 )
			Q_strncat( str, ", ", sizeof( str ), COPY_ALL_CHARACTERS );

		char tempStr[512];
		Q_snprintf( tempStr, sizeof( tempStr ), "class: %s", pEnt->GetClassname() );
		Q_strncat( str, tempStr, sizeof( str ), COPY_ALL_CHARACTERS );
	}

	if ( str[0] != 0 )
	{
		CTextParams params;
		params.m_vPos = (mins + maxs) * 0.5f;
		params.m_bCentered = true;
		params.m_flLetterWidth = 2;
		pPad->DrawText( str, params );
	}
}