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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#include "stdafx.h"
#include "hammer_mathlib.h"
#include "MainFrm.h"
#include "ObjectProperties.h"
#include "Box3D.h"
#include "BSPFile.h"
#include "const.h"
#include "MapDefs.h" // dvs: For COORD_NOTINIT
#include "MapEntity.h"
#include "MapInstance.h"
#include "Manifest.h"
#include "Render2D.h"
#include "Render3D.h"
#include "MapView2D.h"
#include "MapView3D.h"
#include "hammer.h"
#include "Texture.h"
#include "TextureSystem.h"
#include "materialsystem/imesh.h"
#include "Material.h"
#include "Options.h"
#include "camera.h"
#include "MapWorld.h"
#include "mapview.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
IMPLEMENT_MAPCLASS(CMapInstance)
char CMapInstance::m_InstancePath[ MAX_PATH ] = "";
//-----------------------------------------------------------------------------
// Purpose: Factory function. Used for creating a CMapInstance.
// Input : pHelperInfo - Pointer to helper info class which gives us information
// about how to create the class.
// pParent - the owning entity ( func_instance )
// Output : Returns a pointer to the class, NULL if an error occurs.
//-----------------------------------------------------------------------------
CMapClass *CMapInstance::Create( CHelperInfo *pHelperInfo, CMapEntity *pParent )
{
char FileName[ MAX_PATH ];
const char *FileNameKey = pParent->GetKeyValue( "file" );
CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
if ( FileNameKey )
{
V_strcpy_safe( FileName, pParent->GetKeyValue( "file" ) );
}
else
{
FileName[ 0 ] = 0;
}
CMapInstance *pInstance = new CMapInstance( pDoc->GetPathName(), FileName );
return pInstance;
}
//-----------------------------------------------------------------------------
// Purpose: this function will set a secondary lookup path for instances.
// Input : pszInstancePath - the secondary lookup path
//-----------------------------------------------------------------------------
void CMapInstance::SetInstancePath( const char *pszInstancePath )
{
strcpy( m_InstancePath, pszInstancePath );
V_strlower( m_InstancePath );
V_FixSlashes( m_InstancePath );
}
//-----------------------------------------------------------------------------
// Purpose: This function will attempt to find a full path given the base and relative names.
// Input : pszBaseFileName - the base file that referenced this instance
// pszInstanceFileName - the relative file name of this instance
// Output : Returns true if it was able to locate the file
// pszOutFileName - the full path to the file name if located
//-----------------------------------------------------------------------------
bool CMapInstance::DeterminePath( const char *pszBaseFileName, const char *pszInstanceFileName, char *pszOutFileName )
{
char szInstanceFileNameFixed[ MAX_PATH ];
const char *pszMapPath = "\\maps\\";
strcpy( szInstanceFileNameFixed, pszInstanceFileName );
V_SetExtension( szInstanceFileNameFixed, ".vmf", sizeof( szInstanceFileNameFixed ) );
V_FixSlashes( szInstanceFileNameFixed );
// first, try to find a relative location based upon the Base file name
strcpy( pszOutFileName, pszBaseFileName );
V_StripFilename( pszOutFileName );
strcat( pszOutFileName, "\\" );
strcat( pszOutFileName, szInstanceFileNameFixed );
if ( g_pFullFileSystem->FileExists( pszOutFileName ) )
{
return true;
}
// second, try to find the master 'maps' directory and make it relative from that
strcpy( pszOutFileName, pszBaseFileName );
V_StripFilename( pszOutFileName );
V_RemoveDotSlashes( pszOutFileName );
V_FixDoubleSlashes( pszOutFileName );
V_strlower( pszOutFileName );
strcat( pszOutFileName, "\\" );
char *pos = strstr( pszOutFileName, pszMapPath );
if ( pos )
{
pos += strlen( pszMapPath );
*pos = 0;
strcat( pszOutFileName, szInstanceFileNameFixed );
if ( g_pFullFileSystem->FileExists( pszOutFileName ) )
{
return true;
}
}
if ( m_InstancePath[ 0 ] != 0 )
{
sprintf( szInstanceFileNameFixed, "%s%s", m_InstancePath, pszInstanceFileName );
if ( g_pFullFileSystem->FileExists( szInstanceFileNameFixed, "GAME" ) )
{
char FullPath[ MAX_PATH ];
g_pFullFileSystem->RelativePathToFullPath( szInstanceFileNameFixed, "GAME", FullPath, sizeof( FullPath ) );
strcpy( pszOutFileName, FullPath );
return true;
}
}
pszOutFileName[ 0 ] = 0;
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Constructor.
//-----------------------------------------------------------------------------
CMapInstance::CMapInstance( void )
{
Initialize();
}
//-----------------------------------------------------------------------------
// Purpose: Constructor.
// Input : pszBaseFileName - the root path of where the instance will be loaded from.
// pszInstanceFileName - the relative name of the instance to be loaded.
// Output :
//-----------------------------------------------------------------------------
CMapInstance::CMapInstance( const char *pszBaseFileName, const char *pszInstanceFileName )
{
Initialize();
if ( pszInstanceFileName[ 0 ] && DeterminePath( pszBaseFileName, pszInstanceFileName, m_FileName ) )
{
bool bSaveVisible = CHammer::IsNewDocumentVisible();
CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
CHammer::SetIsNewDocumentVisible( false );
m_pInstancedMap = ( CMapDoc * )APP()->OpenDocumentFile( m_FileName );
if ( m_pInstancedMap )
{
m_pInstancedMap->AddReference();
m_pInstancedMap->Update();
}
CMapDoc::SetActiveMapDoc( activeDoc );
CHammer::SetIsNewDocumentVisible( bSaveVisible );
}
}
//-----------------------------------------------------------------------------
// Purpose: Destructor.
//-----------------------------------------------------------------------------
CMapInstance::~CMapInstance(void)
{
if ( m_pInstancedMap )
{
m_pInstancedMap->RemoveReference();
m_pInstancedMap = NULL;
}
}
GDIV_TYPE CMapInstance::GetFieldType( const char *pInstanceValue )
{
CMapEntityList entityList;
GDinputvariable TempVar;
m_pInstancedMap->FindEntitiesByClassName( entityList, "func_instance_parms", false );
if ( entityList.Count() != 1 )
{
return ivBadType;
}
CMapEntity *pInstanceParmsEntity = entityList.Element( 0 );
const char *InstancePos = strchr( pInstanceValue, ' ' );
if ( InstancePos == NULL )
{
return ivBadType;
}
int len = InstancePos - pInstanceValue;
for ( int i = pInstanceParmsEntity->GetFirstKeyValue(); i != pInstanceParmsEntity->GetInvalidKeyValue(); i = pInstanceParmsEntity->GetNextKeyValue( i ) )
{
LPCTSTR pKey = pInstanceParmsEntity->GetKey( i );
LPCTSTR pValue = pInstanceParmsEntity->GetKeyValue( i );
if ( strnicmp( pKey, "parm", strlen( "parm" ) ) == 0 )
{
const char *InstanceParmsPos = strchr( pValue, ' ' );
if ( InstanceParmsPos == NULL )
{
continue;
}
if ( strnicmp( pInstanceValue, pValue, len ) == 0 )
{
return TempVar.GetTypeFromToken( InstanceParmsPos + 1 );
}
}
}
return ivBadType;
}
void CMapInstance::FindTargetNames( CUtlVector< const char * > &Names )
{
CMapEntity *pEntity = dynamic_cast< CMapEntity * >( GetParent() );
for ( int j = pEntity->GetFirstKeyValue(); j != pEntity->GetInvalidKeyValue(); j = pEntity->GetNextKeyValue( j ) )
{
LPCTSTR pInstanceKey = pEntity->GetKey( j );
LPCTSTR pInstanceValue = pEntity->GetKeyValue( j );
if ( strnicmp( pInstanceKey, "replace", strlen( "replace" ) ) == 0 )
{
GDIV_TYPE FieldType = GetFieldType( pInstanceValue );
if ( FieldType == ivTargetDest ||
FieldType == ivTargetNameOrClass ||
FieldType == ivTargetSrc )
{
const char *pszInstancePos = strchr( pInstanceValue, ' ' );
if ( pszInstancePos )
{
pszInstancePos++;
char *temp = new char[ strlen( pszInstancePos ) + 1 ];
strcpy( temp, pszInstancePos );
Names.AddToTail( temp );
}
}
}
}
}
void CMapInstance::ReplaceTargetname( const char *szOldName, const char *szNewName )
{
BaseClass::ReplaceTargetname( szOldName, szNewName );
CMapEntity *pEntity = dynamic_cast< CMapEntity * >( GetParent() );
for ( int j = pEntity->GetFirstKeyValue(); j != pEntity->GetInvalidKeyValue(); j = pEntity->GetNextKeyValue( j ) )
{
LPCTSTR pInstanceKey = pEntity->GetKey( j );
LPCTSTR pInstanceValue = pEntity->GetKeyValue( j );
if ( strnicmp( pInstanceKey, "replace", strlen( "replace" ) ) == 0 )
{
const char *InstancePos = strchr( pInstanceValue, ' ' );
if ( InstancePos == NULL )
{
continue;
}
int nLen = InstancePos - pInstanceValue;
if ( strcmp( szOldName, InstancePos + 1 ) == 0 )
{
nLen++;
char *pszResult = ( char * )stackalloc( nLen + strlen( szNewName ) + 1 );
strncpy( pszResult, pInstanceValue, nLen );
strcpy( &pszResult[ nLen ], szNewName );
pEntity->SetKeyValue( pInstanceKey, pszResult );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: This function is called when the owning entity's Key/Value pairs have
// been updated. This will attempt to load a new instance if the map has
// been changed.
// Input : none.
// Output : none.
//-----------------------------------------------------------------------------
bool CMapInstance::OnApply( void )
{
CString MapFileName;
char FileName[ MAX_PATH ];
CMapDoc *activeDoc = CMapDoc::GetActiveMapDoc();
MapFileName = activeDoc->GetPathName();
CMapEntity *ent = dynamic_cast< CMapEntity * >( GetParent() );
if ( m_pInstancedMap )
{
m_pInstancedMap->RemoveReference();
}
if ( ent && ent->GetKeyValue( "file" ) )
{
DeterminePath( MapFileName, ent->GetKeyValue( "file" ), FileName );
if ( strcmpi( FileName, m_FileName ) != 0 )
{
bool bSaveVisible = CHammer::IsNewDocumentVisible();
CHammer::SetIsNewDocumentVisible( false );
strcpy( m_FileName, FileName );
m_pInstancedMap = ( CMapDoc * )APP()->OpenDocumentFile( m_FileName );
CHammer::SetIsNewDocumentVisible( bSaveVisible );
}
}
else
{
m_pInstancedMap = NULL;
}
if ( m_pInstancedMap == NULL )
{
m_FileName[ 0 ] = 0;
}
else
{
m_pInstancedMap->AddReference();
m_pInstancedMap->Update();
}
GetMainWnd()->pObjectProperties->MarkDataDirty();
// loading this instance will bring it forward in the MDI - we want to show the original map though
CMapDoc::ActivateMapDoc( activeDoc );
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Calculates our bounding box based on instance map's dimensions.
// Input : bFullUpdate - Whether we should recalculate our children's bounds.
// Output : none.
//-----------------------------------------------------------------------------
void CMapInstance::CalcBounds(BOOL bFullUpdate)
{
CMapClass::CalcBounds(bFullUpdate);
//
// Build our bounds for frustum culling in the 3D view.
//
if ( m_pInstancedMap && GetParent() && m_pInstancedMap->GetMapWorld() )
{
Vector vecMins, vecMaxs, vecExpandedMins, vecExpandedMaxs;
matrix3x4_t Instance3x4Matrix;
CMapClass *pParent = GetParent();
pParent->GetOrigin( m_Origin );
AngleMatrix( m_Angles, m_Origin, Instance3x4Matrix );
m_pInstancedMap->GetMapWorld()->CalcBounds( true );
#if 0
m_pInstancedMap->GetMapWorld()->GetCullBox( vecMins, vecMaxs );
TransformAABB( Instance3x4Matrix, vecMins, vecMaxs, vecExpandedMins, vecExpandedMaxs );
m_CullBox.UpdateBounds( vecExpandedMins, vecExpandedMaxs );
#endif
m_pInstancedMap->GetMapWorld()->GetBoundingBox( vecMins, vecMaxs );
TransformAABB( Instance3x4Matrix, vecMins, vecMaxs, vecExpandedMins, vecExpandedMaxs );
m_CullBox.UpdateBounds( vecExpandedMins, vecExpandedMaxs );
m_BoundingBox.UpdateBounds( vecExpandedMins, vecExpandedMaxs );
m_Render2DBox.UpdateBounds( vecExpandedMins, vecExpandedMaxs );
}
else
{
Vector vecExpandedMins, vecExpandedMaxs;
vecExpandedMins.Init( -32.0f, -32.0f, -32.0f );
vecExpandedMins += m_Origin;
vecExpandedMaxs.Init( 32.0f, 32.0f, 32.0f );
vecExpandedMaxs += m_Origin;
m_CullBox.UpdateBounds( vecExpandedMins, vecExpandedMaxs );
m_BoundingBox.UpdateBounds( vecExpandedMins, vecExpandedMaxs );
m_Render2DBox.UpdateBounds( vecExpandedMins, vecExpandedMaxs );
}
}
//-----------------------------------------------------------------------------
// Purpose: Will calculate the bounding box of the instance as a child has changed
// Input : pChild - Pointer to the object that changed.
//-----------------------------------------------------------------------------
void CMapInstance::UpdateChild(CMapClass *pChild)
{
CalcBounds( TRUE );
}
//-----------------------------------------------------------------------------
// Purpose: this function will attempt to find a child inside of the instance. If the bool and matrix
// are supplied, the localized matrix will be built.
// Input : key - the key field to lookup
// value - the value to find
// Output : returns the entity found
// bIsInInstance - optional parameter to indicate if the found entity is inside of an instance
// InstanceMatrix - optional parameter to set the localized matrix of the instance stack
//-----------------------------------------------------------------------------
CMapEntity *CMapInstance::FindChildByKeyValue( const char* key, const char* value, bool *bIsInInstance, VMatrix *InstanceMatrix )
{
if ( m_pInstancedMap && bIsInInstance )
{
CMapEntity *result = m_pInstancedMap->GetMapWorld()->FindChildByKeyValue( key, value );
if ( result )
{
if ( ( *bIsInInstance ) == false )
{
*bIsInInstance = true;
if ( InstanceMatrix )
{
InstanceMatrix->Identity();
}
}
if ( InstanceMatrix )
{
VMatrix LocalInstanceMatrix, Result;
LocalInstanceMatrix.SetupMatrixOrgAngles( m_Origin, m_Angles );
Result = ( *InstanceMatrix ) * LocalInstanceMatrix;
*InstanceMatrix = Result;
}
}
return result;
}
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose: this function is called for when an instance has moved
//-----------------------------------------------------------------------------
void CMapInstance::InstanceMoved( void )
{
if ( m_pInstancedMap )
{
m_pInstancedMap->InstanceMoved();
}
}
//-----------------------------------------------------------------------------
// Purpose: Returns a copy of this object.
// Output : Pointer to the new object.
//-----------------------------------------------------------------------------
CMapClass *CMapInstance::Copy(bool bUpdateDependencies)
{
CMapInstance *pCopy = new CMapInstance;
if (pCopy != NULL)
{
pCopy->CopyFrom(this, bUpdateDependencies);
}
return(pCopy);
}
//-----------------------------------------------------------------------------
// Purpose: Turns this into a duplicate of the given object.
// Input : pObject - Pointer to the object to copy from.
// Output : Returns a pointer to this object.
//-----------------------------------------------------------------------------
CMapClass *CMapInstance::CopyFrom(CMapClass *pObject, bool bUpdateDependencies)
{
CMapInstance *pFrom = dynamic_cast<CMapInstance *>(pObject);
Assert(pObject != NULL);
if (pObject != NULL)
{
CMapClass::CopyFrom(pObject, bUpdateDependencies);
m_Angles = pFrom->m_Angles;
strcpy( m_FileName, pFrom->m_FileName );
m_pInstancedMap = pFrom->m_pInstancedMap;
if ( m_pInstancedMap )
{
m_pInstancedMap->AddReference();
m_pInstancedMap->Update();
}
}
return(this);
}
//-----------------------------------------------------------------------------
// Purpose: Set's the map instance's angles
// Input : Angles - the angles to set to
//-----------------------------------------------------------------------------
void CMapInstance::GetAngles(QAngle &Angles)
{
Angles = m_Angles;
}
//-----------------------------------------------------------------------------
// Purpose: Initialized the map instance
//-----------------------------------------------------------------------------
void CMapInstance::Initialize(void)
{
m_Angles.Init();
m_pInstancedMap = NULL;
m_FileName[ 0 ] = 0;
m_pManifestMap = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Sets the manifest that loaded this instance
// Input : pManifestMap - the manifest
//-----------------------------------------------------------------------------
void CMapInstance::SetManifest( CManifestMap *pManifestMap )
{
Initialize();
m_pManifestMap = pManifestMap;
m_pInstancedMap = m_pManifestMap->m_Map;
strcpy( m_FileName, m_pManifestMap->m_AbsoluteMapFileName );
}
//-----------------------------------------------------------------------------
// Purpose: This will render the map instance into the 3d view.
// Input : pRender - the 3d render
//-----------------------------------------------------------------------------
void CMapInstance::Render3D(CRender3D *pRender)
{
if ( m_pInstancedMap )
{
pRender->RenderInstanceMapClass( this, m_pInstancedMap->GetMapWorld(), m_Origin, m_Angles );
}
}
//-----------------------------------------------------------------------------
// Purpose: this function will display an instance map window. it will also set the
// views to the approx same camera position.
//-----------------------------------------------------------------------------
void CMapInstance::SwitchTo( void )
{
if ( !m_pInstancedMap )
{
return;
}
CMapDoc *pCurrentDoc = CMapDoc::GetActiveMapDoc();
m_pInstancedMap->ShowWindow( true );
CMapDoc::ActivateMapDoc( m_pInstancedMap );
POSITION PositionCurrentView = pCurrentDoc->GetFirstViewPosition();
POSITION PositionNewView = m_pInstancedMap->GetFirstViewPosition();
while ( PositionCurrentView && PositionNewView )
{
CMapView *pViewCurrent = dynamic_cast< CMapView * >( pCurrentDoc->GetNextView( PositionCurrentView ) );
CMapView2D *pViewCurrent2D = dynamic_cast< CMapView2D * >( pViewCurrent );
CMapView3D *pViewCurrent3D = dynamic_cast< CMapView3D * >( pViewCurrent );
CMapView *pViewNew = dynamic_cast< CMapView * >( m_pInstancedMap->GetNextView( PositionNewView ) );
CMapView2D *pViewNew2D = dynamic_cast< CMapView2D * >( pViewNew );
CMapView3D *pViewNew3D = dynamic_cast< CMapView3D * >( pViewNew );
if ( ( !pViewCurrent2D || !pViewNew2D ) && ( !pViewCurrent3D || !pViewNew3D ) )
{
continue;
}
Vector CameraVector;
CCamera *CurrentCamera;
CurrentCamera = pViewCurrent->GetCamera();
CurrentCamera->GetViewPoint( CameraVector );
if ( pViewCurrent2D )
{
CameraVector = CameraVector - m_Origin;
pViewNew2D->GetCamera()->SetViewPoint( CameraVector );
pViewNew2D->GetCamera()->SetZoom( pViewCurrent2D->GetZoom() );
}
else
{
matrix3x4_t Camera3x4Matrix, InstanceMatrix, InstanceInverseMatrix;
matrix3x4_t ResultMatrix;
QAngle InstanceAngles, CameraAngles;
CameraAngles.Init( CurrentCamera->GetPitch(), CurrentCamera->GetYaw(), CurrentCamera->GetRoll() );
InstanceAngles = m_Angles;
InstanceAngles.x = 0;
InstanceAngles.z = 0;
AngleMatrix( InstanceAngles, m_Origin, InstanceMatrix );
MatrixInvert( InstanceMatrix, InstanceInverseMatrix );
AngleMatrix( CameraAngles, CameraVector, Camera3x4Matrix );
MatrixMultiply( InstanceInverseMatrix, Camera3x4Matrix, ResultMatrix );
MatrixPosition( ResultMatrix, CameraVector );
MatrixMultiply( InstanceMatrix, Camera3x4Matrix, ResultMatrix );
MatrixAngles( ResultMatrix, CameraAngles );
pViewNew3D->GetCamera()->SetViewPoint( CameraVector );
pViewNew3D->GetCamera()->SetPitch( CameraAngles.x );
pViewNew3D->GetCamera()->SetYaw( CameraAngles.y );
// pViewNew3D->GetCamera()->SetRoll( CameraAngles.z ); we probably don't want to set this!
}
pViewNew->UpdateView( MAPVIEW_OPTIONS_CHANGED );
}
}
//-----------------------------------------------------------------------------
// Purpose: we do not want to serialize this
// Input : &File -
// bRMF -
// Output : int
//-----------------------------------------------------------------------------
int CMapInstance::SerializeRMF(std::fstream &File, BOOL bRMF)
{
return(0);
}
//-----------------------------------------------------------------------------
// Purpose: we do not want to serialize this
// Input : &File -
// bRMF -
// Output : int
//-----------------------------------------------------------------------------
int CMapInstance::SerializeMAP(std::fstream &File, BOOL bRMF)
{
return(0);
}
//-----------------------------------------------------------------------------
// Purpose: Canculate angles based upon the transform
// Input : pTransBox -
//-----------------------------------------------------------------------------
void CMapInstance::DoTransform(const VMatrix &matrix)
{
CMapClass *pParent = GetParent();
pParent->GetOrigin( m_Origin );
// BaseClass::DoTransform(matrix);
matrix3x4_t fCurrentMatrix,fMatrixNew;
AngleMatrix(m_Angles, fCurrentMatrix);
ConcatTransforms(matrix.As3x4(), fCurrentMatrix, fMatrixNew);
MatrixAngles(fMatrixNew, m_Angles);
CMapEntity *pEntity = dynamic_cast< CMapEntity * >( m_pParent );
if (pEntity != NULL)
{
char szValue[ 80 ];
sprintf( szValue, "%g %g %g", m_Angles[ 0 ], m_Angles[ 1 ], m_Angles[ 2 ] );
pEntity->NotifyChildKeyChanged( this, "angles", szValue );
}
InstanceMoved();
}
//-----------------------------------------------------------------------------
// Purpose: Notifies that this object's parent entity has had a key value change.
// Input : szKey - The key that changed.
// szValue - The new value of the key.
//-----------------------------------------------------------------------------
void CMapInstance::OnParentKeyChanged(const char* szKey, const char* szValue)
{
if (!stricmp(szKey, "angles"))
{
sscanf(szValue, "%f %f %f", &m_Angles[PITCH], &m_Angles[YAW], &m_Angles[ROLL]);
PostUpdate(Notify_Changed);
}
}
//-----------------------------------------------------------------------------
// Purpose: indicates that we should not render last
// Output : returns false.
//-----------------------------------------------------------------------------
bool CMapInstance::ShouldRenderLast(void)
{
return( false );
}
//-----------------------------------------------------------------------------
// Purpose: This will render the map instance into the 2d view as well as a
// bounding box.
// Input : pRender - the 2d render
//-----------------------------------------------------------------------------
void CMapInstance::Render2D(CRender2D *pRender)
{
CMapView2D *pView = ( CMapView2D * )pRender->GetView();
if ( m_pInstancedMap )
{
pView->RenderInstance( this, m_pInstancedMap->GetMapWorld(), m_Origin, m_Angles );
}
if ( m_pManifestMap )
{
return;
}
Vector vecMins;
Vector vecMaxs;
GetRender2DBox(vecMins, vecMaxs);
Vector2D pt,pt2;
pRender->TransformPoint(pt, vecMins);
pRender->TransformPoint(pt2, vecMaxs);
if (!IsSelected())
{
pRender->SetDrawColor( r, g, b );
pRender->SetHandleColor( r, g, b );
}
else
{
pRender->SetDrawColor( GetRValue(Options.colors.clrSelection), GetGValue(Options.colors.clrSelection), GetBValue(Options.colors.clrSelection) );
pRender->SetHandleColor( GetRValue(Options.colors.clrSelection), GetGValue(Options.colors.clrSelection), GetBValue(Options.colors.clrSelection) );
}
// Draw the bounding box.
pRender->DrawBox( vecMins, vecMaxs );
//
// Draw center handle.
//
if ( pRender->IsActiveView() )
{
int sizex = abs(pt.x - pt2.x)+1;
int sizey = abs(pt.y - pt2.y)+1;
// dont draw handle if object is too small
if ( sizex > 6 && sizey > 6 )
{
pRender->SetHandleStyle( HANDLE_RADIUS, CRender::HANDLE_CROSS );
pRender->DrawHandle( (vecMins+vecMaxs)/2 );
}
}
}
//-----------------------------------------------------------------------------
// Called by entity code to render sprites
//-----------------------------------------------------------------------------
void CMapInstance::RenderLogicalAt(CRender2D *pRender, const Vector2D &vecMins, const Vector2D &vecMaxs )
{
}
//-----------------------------------------------------------------------------
// Purpose: Returns if this instance is editable. A pure instance is not editable.
// If it is part of a manifest, it must be the primary map of the manifest
// in order for it to be editable.
//-----------------------------------------------------------------------------
bool CMapInstance::IsEditable( void )
{
if ( m_pManifestMap )
{
return m_pManifestMap->IsEditable();
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose: this function checks to see if the instance is visible.
// Output : returns true if the instance is visible.
//-----------------------------------------------------------------------------
bool CMapInstance::IsInstanceVisible( void )
{
if ( IsInstance() )
{
if ( CMapDoc::GetActiveMapDoc() && CMapDoc::GetActiveMapDoc()->GetShowInstance() == INSTANCES_HIDE )
{
return false;
}
}
else
{
if ( GetManifestMap() && GetManifestMap()->m_bVisible == false )
{
return false;
}
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose: this function will recalculate its bounds because map has changed
//-----------------------------------------------------------------------------
void CMapInstance::UpdateInstanceMap( void )
{
CalcBounds();
}
|