Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UTMultiTeam.UTMT_GameReplicationInfo


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
//-----------------------------------------------------------
// Copyright 2007, Infinity Impossible
//-----------------------------------------------------------
class UTMT_GameReplicationInfo extends UTGameReplicationInfo;


var bool bUseOriginalRedAndBlueArmSkins;
var class<UTCustomChar_Data> CustomCharDataClass;


/**
 * For players not on the red or blue teams, checks that a blue mesh exists
 * that may be transformed, to avoid regression to the default character.
 */
simulated function UTPlayerReplicationInfo FindExistingMeshForFamily(string FamilyID, byte TeamNum, UTPlayerReplicationInfo CurrentPRI)
{
	local int i;
	local UTPlayerReplicationInfo UTPRI;

	// Check family, gender and team are the same - and don't allow sharing local player mesh (they can change team)
	// in story mode, require exact match for red team - people need to be the right meshes (or fallback is ok)
	for(i=0; i<PRIArray.length; i++)
	{
		UTPRI = UTPlayerReplicationInfo( PRIArray[i] );
		if( UTPRI != None &&
			UTPRI != CurrentPRI &&
			((bStoryMode && TeamNum == 0) ? (UTPRI.CharacterData == CurrentPRI.CharacterData) : (UTPRI.CharacterData.FamilyID == FamilyID)) &&
			UTPRI.CharacterMesh != None &&
			UTPRI.CharPortrait != None &&
			(UTPRI.GetTeamNum() == TeamNum || (UTPRI.GetTeamNum() > 0 && TeamNum > 0)) &&
			!UTPRI.IsLocalPlayerPRI() )
		{
			return UTPRI;
		}
	}

	return None;
}


/**
 * Changed logic to work on more than two teams.
 */
simulated protected function GetArmMeshAndMaterialNames(
	bool bForceFallbackarms,
	UTPlayerReplicationInfo PRI,
	out string ArmMeshName,
	out string ArmMaterialName )
{
	local string LoadFamily;
	local class<UTFamilyInfo> FamilyInfoClass;

	LoadFamily = PRI.CharacterData.FamilyID;

	if(bForceFallbackArms || LoadFamily == "" || LoadFamily == "NONE")
	{
		ArmMeshName = CustomCharDataClass.default.DefaultArmMeshName;
		if (PRI.Team != None)
		{
			if (PRI.Team.TeamIndex == 0 && bUseOriginalRedAndBlueArmSkins)
				ArmMaterialName = CustomCharDataClass.default.DefaultRedArmSkinName;
			else if (PRI.Team.TeamIndex < Teams.Length)
				ArmMaterialName = CustomCharDataClass.default.DefaultBlueArmSkinName;
		}
	}
	else
	{
		FamilyInfoClass = CustomCharDataClass.static.FindFamilyInfo(PRI.CharacterData.FamilyID);
		ArmMeshName = FamilyInfoClass.default.ArmMeshName;
		if (PRI.Team != None)
		{
			if (PRI.Team.TeamIndex == 0 && bUseOriginalRedAndBlueArmSkins)
				ArmMaterialName = FamilyInfoClass.default.RedArmSkinName;
			else if (PRI.Team.TeamIndex < Teams.Length)
				ArmMaterialName = FamilyInfoClass.default.BlueArmSkinName;
		}
	}
}


/**
 * Copied from UTGameReplicationInfo. Ideally, this function should be
 * chunked up modularly. The method for loading arm meshes has been modified
 * such that the new team materials can be applied to it.
 */
simulated function TickCharacterMeshCreation()
{
	local int i, NextCharIndex;
	local UTCharFamilyAssetStore ActiveAssetStore;
	local bool bMergePending, bMergeWasPending;
	local SkeletalMesh NewMesh, ArmMesh;
	local string TeamString, LoadFamily, ArmMeshName, ArmMaterialName;
	local CustomCharTextureRes TexRes;
	local class<UTFamilyInfo> FamilyInfoClass;
	local MaterialInterface ArmMaterial;
	local CharPortraitSetup PortraitSetup;
	local UTPlayerReplicationInfo PRI, ReplacementUTPRI;

	// To speed up streaming parts - disable level streaming.
	SetNoStreamWorldTextureForFrames(100000);

	// First, clear out and reset any entries with a NULL PRI (that is, someone disconnected)
	for(i=CharStatus.Length-1; i>=0; i--)
	{
		if (CharStatus[i].PRI == None || CharStatus[i].PRI.bDeleteMe)
		{
			//`log("PRI NULL - Removing.");
			ResetCharMerge(i);
			CharStatus.Remove(i,1);
		}
	}

	// Invariant: At this point all PRI's are valid

	// Now look to see if one is at phase 2 (that is, streaming textures).
	for(i=CharStatus.Length-1; i>=0; i--)
	{
		if(CharStatus[i].MergeState.bMergeInProgress)
		{
			bMergeWasPending = true;

			// Should never be trying to merge without an AssetStore, or with AssetStore not finished loading.
			assert(CharStatus[i].AssetStore != None);
			assert(CharStatus[i].AssetStore.NumPendingPackages == 0);
			// Should only ever have one in this state at a time!
			assert(bMergePending == false);
			// Set flag to indicate there is currently a merge pending
			bMergePending = true;

			//`log("PRI Merge Pending:"@CharStatus[i].PRI);

			// See if we can create skeletal mesh
			NewMesh = FinishCharMerge(i);
			if(!CharStatus[i].MergeState.bMergeInProgress)
			{
				// Merge is done
				LogInternal("CUSTOMCHAR Complete:"@CharStatus[i].PRI@"  (Tex stream:"@(WorldInfo.RealTimeSeconds - CharStatus[i].StartMergeTime)@"Secs)");

				if(NewMesh != None)
				{
					// If this was a construction for the other team skin - save that
					if(CharStatus[i].bOtherTeamSkin)
					{
						CharStatus[i].PRI.SetOtherTeamSkin(NewMesh);
					}
					else
					{
						// Save newly created mesh into PRI.
						CharStatus[i].PRI.SetCharacterMesh(NewMesh);

						// Add an offset specific to the family.
						PortraitSetup = class'UTCustomChar_Data'.default.PortraitSetup;
						FamilyInfoClass = class'UTCustomChar_Data'.static.FindFamilyInfo(CharStatus[i].PRI.CharacterData.FamilyID);
						PortraitSetup.MeshOffset += FamilyInfoClass.default.PortraitExtraOffset;

						// Render the portrait texture.
						CharStatus[i].PRI.CharPortrait = class'UTCustomChar_Data'.static.MakeCharPortraitTexture (NewMesh, PortraitSetup, class'UTCustomChar_Data'.default.PortraitBackgroundMesh);
					}
				}
				else
				{
					CharStatus[i].PRI.SetCharacterMesh(None);
				}

				// If this is a local player, we have some extra steps - make skin for other team, and store a pointer to the first-person arm mesh.

				if(CharStatus[i].PRI.IsLocalPlayerPRI())
				{
					if( WorldInfo.GetGameClass().default.bTeamGame && // Only need other team skin for team games
						!CharStatus[i].bOtherTeamSkin && // Make sure we didn't just try and do this (avoids infinite loop)
						(CharStatus[i].PRI.GetTeamNum() < Teams.Length) && // check they are on a team (not spectator)
						(CharStatus[i].PRI.BlueHeadMIC == None || CharStatus[i].PRI.RedHeadMIC == None) ) // Are missing a skin
					{
						TeamString = CharStatus[i].PRI.GetCustomCharOtherTeamString();

						LogInternal("PRI Other Merge Start:" @ CharStatus[i].PRI @ CharStatus[i].PRI.PlayerName @ TeamString);

						// Choose texture res based on whether you are the local player
						TexRes = (CharStatus[i].PRI.IsLocalPlayerPRI()) ? CCTR_Self : CCTR_Normal;
						CharStatus[i].MergeState = class'UTCustomChar_Data'.static.StartCustomCharMerge(CharStatus[i].PRI.CharacterData, TeamString, None, TexRes);
						CharStatus[i].StartMergeTime = WorldInfo.RealTimeSeconds;
						CharStatus[i].bOtherTeamSkin = TRUE;
						bMergePending = true;
					}
					else
					{
						CharStatus[i].bNeedsArms = TRUE;
						CharStatus[i].AssetStore = None;
						bMergePending = false;
					}
				}
				else
				{
					// We are done! Remove this entry from the array. This will let the AssetStore go away next GC.
					CharStatus.Remove(i,1);

					// No merges pending any more
					bMergePending = false;
				}
			}
			// See if merge is invalid, or we have taken too long waiting for textures to stream in.
			else if(CharStatus[i].MergeState.bInvalidChar || (WorldInfo.RealTimeSeconds - CharStatus[i].StartMergeTime) > class'UTCustomChar_Data'.default.CustomCharTextureStreamTimeout)
			{
				LogInternal("TIMEOUT: Streaming Textures for custom char."@CharStatus[i].PRI);
				ResetCharMerge(i);
				CharStatus[i].PRI.SetCharacterMesh(None);

				// Even though we timed out while streaming, we still try to load the FP arm mesh.
				if(CharStatus[i].PRI.IsLocalPlayerPRI())
				{
					CharStatus[i].bNeedsArms = TRUE;
				}
				else
				{
					// We are done! Remove this entry from the array. This will let the AssetStore go away next GC.
					CharStatus.Remove(i,1);
				}

				bMergePending = false;
			}
		}
	}

	// If no merge going, but still PRIs left to process, get the next one going
	if(!bMergePending && CharStatus.length > 0)
	{
		// Look to see if any are at phase 1 (that is, loading assets from disk - has an AssetStore)
		for(i=0; i<CharStatus.Length && !bMergePending; i++)
		{
			// This entry has an asset store
			if(CharStatus[i].AssetStore != None)
			{
				// Make sure it matches the PRI's character setup data
				assert(CharStatus[i].AssetStore.FamilyID == CharStatus[i].PRI.CharacterData.FamilyID);

				// If this is the first entry with a store, remember it
				if(ActiveAssetStore == None)
				{
					ActiveAssetStore = CharStatus[i].AssetStore;
				}
				// If not the first - make sure all AssetStores are the same. Only want one 'in flight' at a time.
				else
				{
					assert(CharStatus[i].AssetStore == ActiveAssetStore);
				}

				// If all assets are loaded, we can start a merge.
				if(CharStatus[i].AssetStore.NumPendingPackages == 0)
				{
					TeamString = CharStatus[i].PRI.GetCustomCharTeamString();

					LogInternal("CUSTOMCHAR Start:" @ CharStatus[i].PRI @ CharStatus[i].PRI.PlayerName @ TeamString);

					// Choose texture res based on whether you are the local player
					TexRes = (CharStatus[i].PRI.IsLocalPlayerPRI()) ? CCTR_Self : CCTR_Normal;
					CharStatus[i].MergeState = class'UTCustomChar_Data'.static.StartCustomCharMerge(CharStatus[i].PRI.CharacterData, TeamString, None, TexRes);
					CharStatus[i].StartMergeTime = WorldInfo.RealTimeSeconds;
					bMergePending = true;
				}
			}
			// If its an arm-loading case
			else if(CharStatus[i].ArmAssetStore != None)
			{
				assert((CharStatus[i].ArmAssetStore.FamilyID == CharStatus[i].PRI.CharacterData.FamilyID) || CharStatus[i].bForceFallbackArms);

				ActiveAssetStore = CharStatus[i].ArmAssetStore;

				// If we've finished loading packages containing arms
				if(CharStatus[i].ArmAssetStore.NumPendingPackages == 0)
				{
					GetArmMeshAndMaterialNames(CharStatus[i].bForceFallbackArms, CharStatus[i].PRI, ArmMeshName, ArmMaterialName);

					// Find arm material by name (if we want one)
					if(ArmMaterialName != "")
					{
						ArmMaterial = MaterialInterface(FindObject(ArmMaterialName, class'MaterialInterface'));
						if(ArmMaterial == None)
						{
							LogInternal("WARNING: Could not find ArmMaterial:"@ArmMaterialName);
						}
					}

					// Find arm mesh by name
					ArmMesh = SkeletalMesh(FindObject(ArmMeshName, class'SkeletalMesh'));
					if(ArmMesh == None)
					{
						LogInternal("WARNING: Could not find ArmMesh:"@ArmMeshName);
					}

					// Apply mesh/material to character
					CharStatus[i].PRI.SetFirstPersonArmInfo(ArmMesh, ArmMaterial);

					// Done with this char now! Remove from array.
					CharStatus.Remove(i,1);
					i--;
				}
			}
		}

		// If none have an asset store - create one now and start getting assets loaded
		if(ActiveAssetStore == None)
		{
			// Force garbage collection if merge was pending and hold off kicking off more async loading for a frame so the GC can occur.
			if( bMergeWasPending )
			{
				WorldInfo.ForceGarbageCollection();
			}
			else
			{
				// Look for the next character that isn't needing arms.
				// We also set bNeedsArms on any chars that just need arms.
				NextCharIndex = INDEX_NONE;
				for(i=0; i<CharStatus.length; i++)
				{
					if(!CharStatus[i].bNeedsArms)
					{
						// Any characters with bogus FamilyInfo, we just want to load default arms.
						// This should ONLY be for local PRIs (see ).
						LoadFamily = CharStatus[i].PRI.CharacterData.FamilyID;
						if(LoadFamily == "" || LoadFamily == "NONE")
						{
							assert(CharStatus[i].PRI.IsLocalPlayerPRI());
							CharStatus[i].bNeedsArms = TRUE;
						}
						else
						{
							NextCharIndex = i;
							break;
						}
					}
				}

				// We found a non-arms mesh (needs store for parts)
				if(NextCharIndex != INDEX_NONE)
				{
					LoadFamily = CharStatus[NextCharIndex].PRI.CharacterData.FamilyID;
					LogInternal("CustomChar - Load Assets:"@LoadFamily);

					// During initial character creation, block on loading character packages
					if(!bProcessedInitialCharacters)
					{
						WorldInfo.bRequestedBlockOnAsyncLoading = true;
					}

					CharStatus[NextCharIndex].AssetStore = class'UTCustomChar_Data'.static.LoadFamilyAssets(LoadFamily, FALSE, FALSE);

					if(CharStatus[NextCharIndex].AssetStore != None)
					{
						// Look for others using the same family, and assign same asset
						for(i=0; i<CharStatus.length; i++)
						{
							if((i != NextCharIndex) && CharStatus[i].PRI.CharacterData.FamilyID == LoadFamily)
							{
								CharStatus[i].AssetStore = CharStatus[NextCharIndex].AssetStore;
							}
						}
					}
					else
					{
						// We failed to find any parts, remove this character from the processing set.
						LogInternal("Error loading parts for:"@LoadFamily@" - Aborting.");

						if(CharStatus[NextCharIndex].PRI.IsLocalPlayerPRI())
						{
							CharStatus[NextCharIndex].bNeedsArms = TRUE;
						}
						else
						{
							CharStatus.Remove(NextCharIndex, 1);
						}
					}
				}
				// Arms loading case
				else
				{
					// Invariant : The only thing left in CharStatus now is PRIs in need of arms.

					LoadFamily = CharStatus[0].PRI.CharacterData.FamilyID;
					LogInternal("CustomChar - Load Arms:"@LoadFamily);

					if(!bProcessedInitialCharacters)
					{
						WorldInfo.bRequestedBlockOnAsyncLoading = true;
					}

					// Try loading packages for arms
					CharStatus[0].ArmAssetStore = class'UTCustomChar_Data'.static.LoadFamilyAssets(LoadFamily, FALSE, TRUE);

					// If that failed, load the default arm package
					if(CharStatus[0].ArmAssetStore == None)
					{
						CharStatus[0].ArmAssetStore = class'UTCustomChar_Data'.static.LoadFamilyAssets("", FALSE, TRUE);
						CharStatus[0].bForceFallbackArms = TRUE;
					}
					// If we found the arm package we were looking, look for others using the same family, and assign same asset
					else
					{
						for(i=1; i<CharStatus.length; i++)
						{
							if(CharStatus[i].PRI.CharacterData.FamilyID == LoadFamily)
							{
								CharStatus[i].ArmAssetStore = CharStatus[NextCharIndex].ArmAssetStore;
							}
						}
					}
				}
			}
		}
	}

	// if we're done, clear the timer and tell local PCs
	if (!IsProcessingCharacterData())
	{
		if (bMergeWasPending)
		{
			// do a final GC before we officially finish
			WorldInfo.ForceGarbageCollection();
		}
		else
		{
			ClearTimer('TickCharacterMeshCreation');
			SendCharacterProcessingNotification(false);

			LogInternal("Finished creating custom characters in "$(WorldInfo.RealTimeSeconds - StartCreateCharTime)$" seconds");

			// see if there are any characters that we skipped that we can fill in with the newly created meshes
			if (!bForceDefaultCharacter)
			{
				for (i = 0; i < PRIArray.length; i++)
				{
					PRI = UTPlayerReplicationInfo(PRIArray[i]);
					if ( PRI != None && PRI.CharacterMesh == None && PRI.CharacterData.FamilyID != "" &&
						PRI.CharacterData.FamilyID != "NONE" && !PRI.IsLocalPlayerPRI() )
					{
						ReplacementUTPRI = FindExistingMeshForFamily(PRI.CharacterData.FamilyID, PRI.GetTeamNum(), PRI);
						if (ReplacementUTPRI != None)
						{
							PRI.SetCharacterMesh(ReplacementUTPRI.CharacterMesh, true);
							PRI.CharPortrait = ReplacementUTPRI.CharPortrait;
						}
					}
				}
			}
		}
	}
}

defaultproperties
{
   bUseOriginalRedAndBlueArmSkins=True
   CustomCharDataClass=Class'UTGame.UTCustomChar_Data'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Mon 20/12/2010 19:04:12.000 - Creation time: Fri 23/12/2011 20:31:26.548 - Created with UnCodeX