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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "DmeVMFEntity.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "toolframework/itoolentity.h"
#include "materialsystem/imesh.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialsystem.h"
#include "engine/iclientleafsystem.h"
#include "toolutils/enginetools_int.h"
#include "vcdblocktool.h"
#include "tier1/KeyValues.h"
// for tracing
#include "cmodel.h"
#include "engine/ienginetrace.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define SPHERE_RADIUS 16
//-----------------------------------------------------------------------------
// Expose this class to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeVMFEntity, CDmeVMFEntity );
//-----------------------------------------------------------------------------
// Used to store the next unique entity id;
//-----------------------------------------------------------------------------
int CDmeVMFEntity::s_nNextEntityId;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CDmeVMFEntity::OnConstruction()
{
m_ClassName.Init( this, "classname", FATTRIB_HAS_CALLBACK );
m_TargetName.Init( this, "targetname" );
m_bIsPlaceholder.InitAndSet( this, "_placeholder", false, FATTRIB_DONTSAVE );
m_vecLocalOrigin.Init( this, "origin" );
m_vecLocalAngles.Init( this, "angles" );
m_bIsDeleted.Init( this, "deleted" );
if ( m_Name.Length() == 0 )
{
// Assign a unique ID to the name
char pNameString[128];
Q_snprintf( pNameString, sizeof(pNameString), "%d", GetNextEntityId() );
m_Name = pNameString;
}
// See if we need to bump the unique id up
int nEntityId = GetEntityId();
if ( s_nNextEntityId <= nEntityId )
{
s_nNextEntityId = nEntityId + 1;
}
// Get called back when the name changes
m_Name.GetAttribute()->AddFlag( FATTRIB_HAS_CALLBACK );
// Used to make sure these aren't saved if they aren't changed
//m_TargetName.GetAttribute()->AddFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
//m_vecLocalAngles.GetAttribute()->AddFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
m_bIsDirty = false;
m_bInfoTarget = false;
m_hEngineEntity = HTOOLHANDLE_INVALID;
m_Wireframe.Init( "debug/debugwireframevertexcolor", "editor" );
// FIXME: Need to abstract out rendering into a separate class
// based on information parsed from the FGD
KeyValues *pVMTKeyValues = new KeyValues( "UnlitGeneric" );
pVMTKeyValues->SetString( "$basetexture", "editor/info_target" );
pVMTKeyValues->SetInt( "$nocull", 1 );
pVMTKeyValues->SetInt( "$vertexcolor", 1 );
pVMTKeyValues->SetInt( "$vertexalpha", 1 );
pVMTKeyValues->SetInt( "$no_fullbright", 1 );
pVMTKeyValues->SetInt( "$translucent", 1 );
m_InfoTargetSprite.Init( "__vcdblock_info_target", pVMTKeyValues );
pVMTKeyValues = new KeyValues( "UnlitGeneric" );
pVMTKeyValues->SetInt( "$nocull", 1 );
pVMTKeyValues->SetString( "$color", "{64 64 64}" );
pVMTKeyValues->SetInt( "$vertexalpha", 1 );
pVMTKeyValues->SetInt( "$no_fullbright", 1 );
pVMTKeyValues->SetInt( "$additive", 1 );
m_SelectedInfoTarget.Init( "__selected_vcdblock_info_target", pVMTKeyValues );
}
void CDmeVMFEntity::OnDestruction()
{
// Unhook it from the engine
AttachToEngineEntity( false );
m_Wireframe.Shutdown();
m_SelectedInfoTarget.Shutdown();
m_InfoTargetSprite.Shutdown();
}
//-----------------------------------------------------------------------------
// Called whem attributes change
//-----------------------------------------------------------------------------
void CDmeVMFEntity::OnAttributeChanged( CDmAttribute *pAttribute )
{
BaseClass::OnAttributeChanged( pAttribute );
// Once these have changed, then save them out, and don't bother calling back
if ( pAttribute == m_TargetName.GetAttribute() ||
pAttribute == m_vecLocalAngles.GetAttribute() )
{
pAttribute->RemoveFlag( FATTRIB_DONTSAVE | FATTRIB_HAS_CALLBACK );
return;
}
if ( pAttribute == m_ClassName.GetAttribute() )
{
m_bInfoTarget = !Q_strncmp( m_ClassName, "info_target", 11 );
// FIXME: Change the model based on the current class
SetModelName( NULL );
return;
}
// Make sure we have unique ids for all entities
if ( pAttribute == m_Name.GetAttribute() )
{
int nEntityId = GetEntityId();
if ( s_nNextEntityId <= nEntityId )
{
s_nNextEntityId = nEntityId + 1;
}
}
}
//-----------------------------------------------------------------------------
// Returns the entity ID
//-----------------------------------------------------------------------------
int CDmeVMFEntity::GetEntityId() const
{
return atoi( GetName() );
}
//-----------------------------------------------------------------------------
// Returns the next available entity id
//-----------------------------------------------------------------------------
int CDmeVMFEntity::GetNextEntityId()
{
return s_nNextEntityId;
}
void CDmeVMFEntity::SetNextEntityId( int nEntityId )
{
s_nNextEntityId = nEntityId;
}
//-----------------------------------------------------------------------------
// Mark the entity as being dirty
//-----------------------------------------------------------------------------
void CDmeVMFEntity::MarkDirty( bool bDirty )
{
m_bIsDirty = bDirty;
// FIXME: this is doing two operations!!
CopyToServer();
}
//-----------------------------------------------------------------------------
// Is the renderable transparent?
//-----------------------------------------------------------------------------
bool CDmeVMFEntity::IsTransparent( void )
{
return m_bIsDirty || m_bInfoTarget || BaseClass::IsTransparent();
}
//-----------------------------------------------------------------------------
// Entity Key iteration
//-----------------------------------------------------------------------------
bool CDmeVMFEntity::IsEntityKey( CDmAttribute *pEntityKey )
{
return pEntityKey->IsFlagSet( FATTRIB_USERDEFINED );
}
CDmAttribute *CDmeVMFEntity::FirstEntityKey()
{
for ( CDmAttribute *pAttribute = FirstAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
{
if ( IsEntityKey( pAttribute ) )
return pAttribute;
}
return NULL;
}
CDmAttribute *CDmeVMFEntity::NextEntityKey( CDmAttribute *pEntityKey )
{
if ( !pEntityKey )
return NULL;
for ( CDmAttribute *pAttribute = pEntityKey->NextAttribute(); pAttribute; pAttribute = pAttribute->NextAttribute() )
{
if ( IsEntityKey( pAttribute ) )
return pAttribute;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Attach/detach from an engine entity with the same editor index
//-----------------------------------------------------------------------------
void CDmeVMFEntity::AttachToEngineEntity( HTOOLHANDLE hToolHandle )
{
if ( m_hEngineEntity != HTOOLHANDLE_INVALID )
{
clienttools->SetEnabled( m_hEngineEntity, true );
}
m_hEngineEntity = hToolHandle;
if ( m_hEngineEntity != HTOOLHANDLE_INVALID )
{
clienttools->SetEnabled( m_hEngineEntity, false );
}
}
//-----------------------------------------------------------------------------
// Position and bounds for the model
//-----------------------------------------------------------------------------
const Vector &CDmeVMFEntity::GetRenderOrigin( void )
{
return m_vecLocalOrigin;
}
const QAngle &CDmeVMFEntity::GetRenderAngles( void )
{
return *(QAngle *)(&m_vecLocalAngles);
}
void CDmeVMFEntity::GetRenderBounds( Vector& mins, Vector& maxs )
{
if ( !m_bInfoTarget )
{
BaseClass::GetRenderBounds( mins, maxs );
return;
}
mins.Init( -SPHERE_RADIUS, -SPHERE_RADIUS, -SPHERE_RADIUS );
maxs.Init( SPHERE_RADIUS, SPHERE_RADIUS, SPHERE_RADIUS );
}
//-----------------------------------------------------------------------------
// Update renderable position
//-----------------------------------------------------------------------------
void CDmeVMFEntity::SetRenderOrigin( const Vector &vecOrigin )
{
m_vecLocalOrigin = vecOrigin;
clienttools->MarkClientRenderableDirty( this );
}
void CDmeVMFEntity::SetRenderAngles( const QAngle &angles )
{
m_vecLocalAngles.Set( Vector( angles.x, angles.y, angles.z ) ); // FIXME: angles is a vector due to the vmf "angles" having a problem parsing...
clienttools->MarkClientRenderableDirty( this );
}
//-----------------------------------------------------------------------------
// Draws the helper for the entity
//-----------------------------------------------------------------------------
void CDmeVMFEntity::DrawSprite( IMaterial *pMaterial )
{
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
pRenderContext->Bind( pMaterial );
IMesh* pMesh = pRenderContext->GetDynamicMesh();
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_TRIANGLE_STRIP, 4, 4 );
unsigned char nBaseR = 255;
unsigned char nBaseG = 255;
unsigned char nBaseB = 255;
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
meshBuilder.Position3f( -SPHERE_RADIUS, -SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
meshBuilder.BoneWeight( 0, 1.0f );
meshBuilder.BoneMatrix( 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( SPHERE_RADIUS, -SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
meshBuilder.BoneWeight( 0, 1.0f );
meshBuilder.BoneMatrix( 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( SPHERE_RADIUS, SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
meshBuilder.BoneWeight( 0, 1.0f );
meshBuilder.BoneMatrix( 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( -SPHERE_RADIUS, SPHERE_RADIUS, 0.0f );
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
meshBuilder.BoneWeight( 0, 1.0f );
meshBuilder.BoneMatrix( 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.FastIndex( 0 );
meshBuilder.FastIndex( 1 );
meshBuilder.FastIndex( 3 );
meshBuilder.FastIndex( 2 );
meshBuilder.End();
pMesh->Draw();
}
//-----------------------------------------------------------------------------
// Draws the helper for the entity
//-----------------------------------------------------------------------------
void CDmeVMFEntity::DrawDragHelpers( IMaterial *pMaterial )
{
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
VMatrix worldToCamera;
// pRenderContext->GetMatrix( MATERIAL_VIEW, &worldToCamera );
worldToCamera.Identity();
worldToCamera.SetTranslation( m_vecLocalOrigin );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PushMatrix();
pRenderContext->LoadMatrix( worldToCamera );
pRenderContext->FogMode( MATERIAL_FOG_NONE );
pRenderContext->SetNumBoneWeights( 0 );
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
pRenderContext->Bind( pMaterial );
IMesh* pMesh = pRenderContext->GetDynamicMesh();
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
unsigned char nBaseR = 255;
unsigned char nBaseG = 255;
unsigned char nBaseB = 255;
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( SPHERE_RADIUS * 10, 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( 0, SPHERE_RADIUS * 10, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( 0, 0, SPHERE_RADIUS * 10 );
meshBuilder.AdvanceVertex();
meshBuilder.End();
pMesh->Draw();
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PopMatrix();
}
//-----------------------------------------------------------------------------
// Draws the helper for the entity
//-----------------------------------------------------------------------------
void CDmeVMFEntity::DrawFloorTarget( IMaterial *pMaterial )
{
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
// test movement
Ray_t ray;
CTraceFilterWorldAndPropsOnly traceFilter;
CBaseTrace tr;
ray.Init( m_vecLocalOrigin.Get()+ Vector( 0, 0, 10 ), m_vecLocalOrigin.Get() + Vector( 0,0, -128 ), Vector( -13, -13, 0 ), Vector( 13, 13, 10 ) );
enginetools->TraceRayServer( ray, MASK_OPAQUE, &traceFilter, &tr );
VMatrix worldToCamera;
// pRenderContext->GetMatrix( MATERIAL_VIEW, &worldToCamera );
worldToCamera.Identity();
worldToCamera.SetTranslation( tr.endpos );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PushMatrix();
pRenderContext->LoadMatrix( worldToCamera );
pRenderContext->FogMode( MATERIAL_FOG_NONE );
pRenderContext->SetNumBoneWeights( 0 );
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
pRenderContext->Bind( pMaterial );
IMesh* pMesh = pRenderContext->GetDynamicMesh();
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
unsigned char nBaseR = 255;
unsigned char nBaseG = 255;
unsigned char nBaseB = 0;
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
float block[4][2][3] = {
{ { -13, -13, 0 }, { -13, -13, 10 } },
{ { 13, -13, 0 }, { 13, -13, 10 } },
{ { 13, 13, 0 }, { 13, 13, 10 } },
{ { -13, 13, 0 }, { -13, 13, 10 } } };
for (int i = 0; i < 4; i++)
{
int j = (i + 1) % 4;
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( block[i][0][0], block[i][0][1], block[i][0][2] );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( block[i][1][0], block[i][1][1], block[i][1][2] );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( block[i][0][0], block[i][0][1], block[i][0][2] );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( block[j][0][0], block[j][0][1], block[j][0][2] );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( block[i][1][0], block[i][1][1], block[i][1][2] );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( nBaseR, nBaseG, nBaseB, nAlpha );
meshBuilder.Position3f( block[j][1][0], block[j][1][1], block[j][1][2] );
meshBuilder.AdvanceVertex();
}
// positive X
meshBuilder.Color4ub( 255, 0, 0, nAlpha );
meshBuilder.Position3f( 0, 0, 10 );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( 255, 0, 0, nAlpha );
meshBuilder.Position3f( 10, 0, 10 );
meshBuilder.AdvanceVertex();
// positive Y
meshBuilder.Color4ub( 0, 255, 0, nAlpha );
meshBuilder.Position3f( 0, 0, 10 );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( 0, 255, 0, nAlpha );
meshBuilder.Position3f( 0, 10, 10 );
meshBuilder.AdvanceVertex();
// just Z
meshBuilder.Color4ub( 255, 255, 255, nAlpha );
meshBuilder.Position3f( 0, 0, 10 );
meshBuilder.AdvanceVertex();
meshBuilder.Color4ub( 255, 255, 255, nAlpha );
meshBuilder.Position3f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.End();
pMesh->Draw();
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PopMatrix();
}
//-----------------------------------------------------------------------------
// Draws the helper for the entity
//-----------------------------------------------------------------------------
int CDmeVMFEntity::DrawModel( int flags )
{
CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
bool bSelected = ( g_pVcdBlockTool->GetCurrentEntity().Get() == this );
if ( !m_bInfoTarget )
{
// If we have a visible engine entity, we don't need to draw it here
// info targets always draw though, because they have no visible model.
CDisableUndoScopeGuard guard;
float t = 0.5f * sin( Plat_FloatTime() * M_PI / 1.0f ) + 0.5f;
unsigned char nAlpha = m_bIsDirty ? (unsigned char)(255 * t) : 255;
if ( bSelected )
{
GetMDL()->m_Color.SetColor( 255, 64, 64, nAlpha );
}
else
{
GetMDL()->m_Color.SetColor( 255, 255, 255, nAlpha );
}
return BaseClass::DrawModel( flags );
}
Assert( IsDrawingInEngine() );
matrix3x4_t mat;
VMatrix worldToCamera, cameraToWorld;
pRenderContext->GetMatrix( MATERIAL_VIEW, &worldToCamera );
MatrixInverseTR( worldToCamera, cameraToWorld );
MatrixCopy( cameraToWorld.As3x4(), mat );
MatrixSetColumn( m_vecLocalOrigin, 3, mat );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PushMatrix();
pRenderContext->LoadMatrix( mat );
pRenderContext->FogMode( MATERIAL_FOG_NONE );
pRenderContext->SetNumBoneWeights( 0 );
pRenderContext->CullMode( MATERIAL_CULLMODE_CW );
DrawSprite( m_InfoTargetSprite );
if ( bSelected )
{
DrawSprite( m_SelectedInfoTarget );
DrawFloorTarget( m_Wireframe );
if (g_pVcdBlockTool->IsInNodeDrag())
{
DrawDragHelpers( m_Wireframe );
}
// DrawLine( Vector( 0, 0, 0 ), Vector( 10, 0, 0 ), 0, 255, 255, 255 );
}
pRenderContext->CullMode( MATERIAL_CULLMODE_CCW );
pRenderContext->MatrixMode( MATERIAL_MODEL );
pRenderContext->PopMatrix();
return 1;
}
bool CDmeVMFEntity::CopyFromServer( CBaseEntity *pServerEnt )
{
CopyFromServer( pServerEnt, "targetname" );
CopyFromServer( pServerEnt, "classname" );
CopyFromServer( pServerEnt, "origin" );
CopyFromServer( pServerEnt, "angles" );
return true;
}
bool CDmeVMFEntity::CopyFromServer( CBaseEntity *pServerEnt, const char *szField )
{
return CopyFromServer( pServerEnt, szField, szField );
}
bool CDmeVMFEntity::CopyFromServer( CBaseEntity *pServerEnt, const char *szSrcField, const char *szDstField )
{
char text[256];
if ( servertools->GetKeyValue( pServerEnt, szSrcField, text, sizeof( text ) ) )
{
SetValueFromString( szDstField, text );
return true;
}
return false;
}
bool CDmeVMFEntity::CopyToServer( void )
{
if (GetEntityId() != 0)
{
CBaseEntity *pServerEntity = servertools->FindEntityByHammerID( GetEntityId() );
if (pServerEntity != NULL)
{
servertools->SetKeyValue( pServerEntity, "origin", m_vecLocalOrigin.Get() );
// FIXME: isn't there a string to vector conversion?
Vector tmp( m_vecLocalAngles.Get().x, m_vecLocalAngles.Get().y, m_vecLocalAngles.Get().z );
servertools->SetKeyValue( pServerEntity, "angles", tmp );
return true;
}
else
{
// FIXME: does one need to be spawned?
}
}
return false;
}
bool CDmeVMFEntity::IsSameOnServer( CBaseEntity *pServerEntity )
{
char text[256];
if (!pServerEntity)
{
return false;
}
// FIXME: check targetname? Can it be edited?
Vector mapOrigin;
servertools->GetKeyValue( pServerEntity, "origin", text, sizeof( text ) );
sscanf( text, "%f %f %f", &mapOrigin.x, &mapOrigin.y, &mapOrigin.z );
Vector mapAngles;
servertools->GetKeyValue( pServerEntity, "angles", text, sizeof( text ) );
sscanf( text, "%f %f %f", &mapAngles.x, &mapAngles.y, &mapAngles.z );
return ( mapOrigin == m_vecLocalOrigin.Get() && mapAngles == m_vecLocalAngles.Get() );
}
bool CDmeVMFEntity::CreateOnServer( void )
{
CBaseEntity *pServerEntity = servertools->CreateEntityByName( m_ClassName.Get() );
if (pServerEntity)
{
// test movement
Ray_t ray;
CTraceFilterWorldAndPropsOnly traceFilter;
CBaseTrace tr;
ray.Init( m_vecLocalOrigin.Get()+ Vector( 0, 0, 10 ), m_vecLocalOrigin.Get() + Vector( 0,0, -1000 ) );
enginetools->TraceRayServer( ray, MASK_OPAQUE, &traceFilter, &tr );
m_vecLocalOrigin.Set( tr.endpos );
servertools->SetKeyValue( pServerEntity, "hammerid", GetEntityId() );
servertools->SetKeyValue( pServerEntity, "targetname", m_TargetName.Get() );
servertools->SetKeyValue( pServerEntity, "origin", m_vecLocalOrigin.Get() );
servertools->SetKeyValue( pServerEntity, "angles", m_vecLocalAngles.Get() );
servertools->DispatchSpawn( pServerEntity );
return true;
}
return false;
}
|