/*=========================================================================
* InitEng.c : Contain all engine initialized functions
* This is a part of the Game project.
*
* Version              1.0
* Creation date        20/08/96
* Revision date
*
* That file needs to be compatible for all platforms.
*
* (c) Ubi Studios 1996
*=======================================================================*/
/*
*=======================================================================
Modifications: New LST_M_??? Macros / Michaël / 070297
*=======================================================================*/
 
#include "Options/Options.h"
#define D_Micro_StructureDefine
#define D_StdGame_StructureDefine
 
#if defined (GAM_USE_SCRIPT)
#define AI_USE_SCRIPT
#endif /* GAM_USE_SCRIPT*/
 
#include "ToolsCPA.h"
 
#include "AI/AIBase/ReadRule.h"
 
#include "AI/AIBase/WPWayPt.h"
 
#include "Options/Opt_Info.h"
#include "Macros.h"
 
#include "actions\MS_micro.h"
 
#include "Actions/AllActs.h"
 
#include "Structur/3DOSLkTb.h"
#include "Structur/EngMode.h"
#include "Structur/ErrGame.h"
#include "Structur/MemGame.h"
#include "Structur/Input_S.h"
#include "structur/Objects.h"
#include "Structur/StdObjSt.h"
#include "Structur/GameScpt.h"
#include "Structur/State.h"
 
 
#include "Main.h"
 
#include "Always.h"
#include "Basic.h"
#include "Clock.h"
#include "DspFix.h"
#include "Family.h"
#include "GameEng.h"
#include "GamOpt.h"
#include "GamSave.h"
/*#include "GamExtra.h"*/
#include "InitEng.h"
#include "Input.h"
#include "LoadAni.h"
 
#define C_A3BOFF "CPA_A3BOFF"
 
/*#include "LoadBin.h"*/
 
#include "LoadGame.h"
#include "LoadLvl.h"
#include "MainChar.h"
#include "ObjInit.h"
#include "ObjType.h"
#include "ZdxStuff.h"
#include "ZeMem.h"
#include "Toolcam.h"
#include "Effect.h"
 
#include "Micros.h"
 
#include "PlayAnim/PlayAnim.h"
#include "TBLLoad.h"
#include "CHLLoad.h"
 
#include "Typecam.h"
 
#include "Structur/Anim_s.h"
/*#include "LoadA3b.h"*/
 
/*XB980824*/
#ifndef D_THROW_MGT
#include "MGT.h"
#endif /* D_THROW_MGT */
/*End XB*/
 
/* 007*/
#include "GLD.h"
#ifdef GAM_USE_SNA
#include "SNA.h"
 
#define D_IPT_Input_StructureDefine
#ifdef USE_IPT_DX5
#include "INO_DX5.h"
#include "IPT_DX5.h" /* InPuT (absolutely before GAM.h)*/
#include "ipt_dx5\ipt_kdef.h"
#include "ipt_dx5\ipt_str.h"
#else /* USE_IPT_WIN */
#include "INO.h"
#include "IPT.h" /* InPuT (absolutely before GAM.h)*/
#include "ipt\ipt_kdef.h"
#include "ipt\ipt_str.h"
#endif /* USE_IPT_WIN */
#undef D_IPT_Input_StructureDefine
#include "PlayAnim/Interpol/a3x_mem.h"
#include "PlayAnim/Interpol/a3x_glob.h"
 
#include "locale\fonfont.h"
 
#endif /* GAM_USE_SNA */
#if (!defined(U64))
#include "tex.h"
#endif /* !U64 */
#include "ia_dnm.h"
 
#include "Actions/AllActs.h"
#include "structur/Objects.h"
 
#include "textfrmt.h"
 
#include "LSMem.h"
#include "LipsSync.h"
#include "LoadLSyn.h"
#ifdef GAM_USE_SNA
#include "sna\SNAsyn.h"
#endif /* GAM_USE_SNA */
 
#ifdef ACTIVE_EDITOR
/* use SAI save with editors */
ACP_tdxBool g_bUseSAIWithEditor=FALSE; 
#endif /* ACTIVE_EDITOR */ 
 
#include "AGO.h"
 
#include "PRF.h"
#if (defined(USE_PROFILER) && !defined(PRESS_DEMO) && !defined(U64))
extern void GAM_fn_vRasterDisplayInit ();
extern void GAM_fn_vRasterDumpInit ();
extern void GAM_fn_vRasterDumpReset ();
extern void GAM_fn_vRasterDumpDesInit ();
#endif /* USE_PROFILER && PRESS_DEMO && !U64 */
 
/* XB 23/06/99 */
#ifdef U64
#include "ldd.h"
#endif /* U64 */
/* XB 23/06/99 */
 
 
/* XB 05/05/99 */
extern void GAM_fn_vLoadInitialAnimations(void);
extern void CAM_fn_vForceBestPosition(HIE_tdxHandleToSuperObject _hCamera);
#ifdef U64
#include "..\..\TempGrp\INO\Specif\u_demo.h"
#endif /* U64 */
/* End XB */

#ifndef U64
#include "PTC.h"
#endif

extern struct tdstIndexMicrosList_ g_stIndexMicrosList;
 
extern HIE_tdxHandleToSuperObject g_hCharacterLauchingSoundEvents;
 
#ifdef RETAIL

#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC 04/06/99 */
struct tdst_EntryActions_ st_Tmp_3DOS_EntryActions;
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC 04/06/99 */

#endif /* RETAIL */


#ifdef GAM_VIGNETTE
extern struct VIG_tdstVignetteStructure_ *VIG_g_aDEF_pstVignetteTable[VIG_C_lVignetteMaxNb];
extern ACP_tdxIndex VIG_g_xVignetteNb;
#endif /* GAM_VIGNETTE */
 
extern GEO_tdxHandleToMatrix HIE_g_a_hMatrixStack[HIE_C_lMaxMatrixInStack];
extern long HIE_g_lNbMatrixInStack ;
extern struct VIG_tdstVignetteStructure_ *p_stBackGround;
 
extern ACP_tdxHandleOfMaterial     g_hShadowPolygonVisualMaterial;
extern GMT_tdxHandleToGameMaterial g_hShadowPolygonGameMaterialInit;
extern GMT_tdxHandleToGameMaterial g_hShadowPolygonGameMaterial;
extern GLI_tdstTexture             *g_p_stTextureOfTextureShadow;
 
extern ACP_tdxHandleOfElement      g_p_hHandleOfElementForShadow[SHW_C_xNbMaxOfShadows];
extern ACP_tdxHandleOfObject       p_hHandleOfGeometricShadowObject[SHW_C_xNbMaxOfShadows];
 
/* ANNECY AV DEMO {*/
#ifndef U64
    #include "Specif/Demos.h"
    extern DEMO_tdxHandleToDemoSOList  g_hDemoSOList;
	extern DEMO_tdxHandleToDemoGMTList g_hDemoGMTFixList;
	extern DEMO_tdxHandleToDemoGMTList g_hDemoGMTLevelList;
#endif
/* END ANNECY AV }*/
 
#ifndef _FIRE_DEADCODE_U64_
ACP_tdxBool g_xA3bOff=FALSE;
#endif /* _FIRE_DEADCODE_U64_ */
 
/*extern ACP_tdxBool g_bUseBinaryData;*/
 
/*extern HIE_tdxHandleToSuperObject g_hLoadedSuperObjectRoot;*/
#ifndef U64
HIE_tdxHandleToSuperObject g_hLoadedSuperObjectRoot=NULL;
#endif
 
BOOL bFirst=TRUE;
 
ACP_tdxBool g_bBeginMapSoundEventFlag=FALSE; /* for sound*/
extern void MOR_fn_vRemoveAllMorphedObjects (void);
 

#if !defined(U64) && defined(_DEBUG)
extern unsigned char g_ucSlowDownEngine;
extern unsigned char g_ucSlowDownTime;
#endif /* !U64 && _DEBUG */

extern POS_tdstCompletePosition	*POS_g_p_stIdentityMatrix;
 
#ifndef _FIRE_DEADCODE_U64_
 
#if defined(GAM_USE_SNA)
 
/**
 * GuS (14/09/98)
 * Init all objects in the fix.
 * This is normally done later by InitAllObjectWhenMapJustLoaded() 
 * but we need to do the init BEFORE saving those objets.
 */
void fn_vInitObjectsInTheFix()
{
	unsigned long ulI;
 
	for( ulI=0; ulI<SNA_g_stFixInfo.ulNbObject; ulI++ )
	{
		fn_vInitOneObject(SNA_g_stFixInfo.a20_stObjects[ulI],OTI_WhenGameStart);
		fn_vAllSecondPassAreDone( SNA_g_stFixInfo.a20_stObjects[ulI]->h_StandardGame );
	}
}
 
void fn_vSaveFix(BOOL bFixLevel)
{
	
	int i;
	
	char szFileName[255];
	char szLevelSnapshotFilename[_MAX_PATH];
	
	SNA_fn_vSetSaveLoadFix();
 
	/* FIX.SNA : binary data for the fix*/
	sprintf(szLevelSnapshotFilename,"%s\\Fix.sna",fn_szGetLevelsDataPath());
	if (bFixLevel)
	{
		GLI_vEndofGeometricLoad();
		 /*	Save the blocks defined in the array "ucModuleBlocToAvoidFixGlide" in SNA\Snammg.c*/
		SNA_fn_vWriteAllMemoryBlocks(szLevelSnapshotFilename);
	}
	{
		/* Fix.ptx: file of the global pointers used in GLI for the textures*/
		sprintf(szLevelSnapshotFilename,"%s\\Fix.ptx",fn_szGetLevelsDataPath());
		TEX_SetNameOfBinaryFile((unsigned char *)szLevelSnapshotFilename);
		
		/* Fix.gpt: file of the global pointers */
		sprintf(szFileName,"%s\\Fix.gpt",fn_szGetLevelsDataPath());	
		SNA_fn_xWriteOpenGlobalPointersFile(szFileName);
		
		/* Save the address of the identity matrix in Fix.gpt*/
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long)POS_g_p_stIdentityMatrix);
		
		 /* Save the content of the matrix stack and the number of matrix in the stack*/
		for (i=0;i<HIE_C_lMaxMatrixInStack;i++)
			SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) HIE_g_a_hMatrixStack[i]);
		SNA_fn_vWriteStructureInGlobalPointersFile((unsigned long *)&HIE_g_lNbMatrixInStack,4);
		
		/* Save two global pointers used in Collision */
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long)g_hCollisionGeoObj);
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long)g_hStaticCollisionGeoObj);
 
		/* Gus 13/08/98 : Ecriture structure IPT (touches de cheat & de tests)*/
		/* Sans doute a enlever dans la version finale.(touches de test & de cheats)*/
		/* Save the IPT struct used for the cheat codes */
		SNA_fn_vWriteStructureInGlobalPointersFile( &g_st_3DOS_EntryActions, sizeof(g_st_3DOS_EntryActions) );
 
		/* Save the address of the structur sed for the defination of key and pad buttons */
		SNA_fn_vWritePointerInGlobalPointersFile( (unsigned long)IPT_gd_hKeyAndPadDefine );
		/* Save the IPT struct used for the defination of key and pad buttons */
		SNA_fn_vWriteStructureInGlobalPointersFile( &IPT_g_hInputStructure, sizeof( struct IPT_tdstInput_ ) );
		SNA_fn_vWritePointerInGlobalPointersFile( (unsigned long)IPT_g_hInputStructure.d_stEntryElementArray );
 
		/* GuS 14/08/98 : Texts*/
		/* Save the FON struct that contains all texts*/
		SNA_fn_vWriteStructureInGlobalPointersFile( &FON_g_stGeneral, sizeof( struct FON_tdstGeneral_ ) );
 
		/* Save stack infos for all stacks in anim player.*/
		SNA_fn_vWriteArrayWithoutPointerInGlobalPointersFile( tdstStacks, eStackNbMax, sizeof(tdstStackInfos) );
		/* Save stack pointers for anims.*/
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stA3dGENERAL );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_a3_xVectors );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_a4_xQuaternions );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stHierarchies );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stNTTO );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stOnlyFrames );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stChannels );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stFrames );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stFramesKF );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stKeyFrames );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stEvents );
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) p_stMorphData );
 
		/* Save the position of the last always in the fix in the always model list.*/
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) SNA_g_stFixInfo.h_LastAlwaysInTheFix );

		/* Save DEMO GMT List */
		SNA_fn_vWritePointerInGlobalPointersFile((unsigned long) g_hDemoGMTFixList);

		/* Close Fix.snd*/
		SNA_fn_vCloseSoundTableFile();
		/* Close Fix.sna*/
		SNA_fn_vCloseGlobalPointersFile();
	
	}
	
}
 
extern SNA_fn_vInitBigFile();

void fn_vLoadFix()
{
/* Load the binary data in the same order as they are saved in fn_vSaveFix*/
	char                         szFileName[_MAX_PATH],szLevelSnapshotFilename[_MAX_PATH];
	int                          i;
	FIL_tdxHandleToFileNameList  hLevelNameList;
#ifdef USE_IPT_DX5
	void *p_vDummy , *p_vDummy2 , *p_vDummy3;
	unsigned char ucDummy , ucDummy2 ;
#endif /* USE_IPT_DX5 */
 
	hLevelNameList=g_stEngineStructure.hLevelNameList;

	SNA_fn_vInitBigFile();
/* ANNECY OA - 12/07/99 { */
	/* Load dummy datas : for protections */
	SNA_M_LoadUnusedRelocationTable();	
/* END ANNECY OA } */

	sprintf(szLevelSnapshotFilename,"%s\\Fix.sna",fn_szGetLevelsDataPath());
 
	SNA_M_vSetNextRelocationFileToLoad( 255, SNA_C_ucSNARelocationTable );
	SNA_fn_bReadAllMemoryBlocks(szLevelSnapshotFilename);

/* ANNECY OA - 12/07/99 { */
	/* Load dummy datas : for protections */
	SNA_M_LoadUnusedRelocationTable();	
/* END ANNECY OA } */	

	SNA_M_vSetNextRelocationFileToLoad( 255, SNA_C_ucGlobalPointersRelocationTable );
	sprintf(szFileName,"%s\\Fix.gpt",fn_szGetLevelsDataPath());
	SNA_fn_xReadOpenGlobalPointersFile(szFileName);

	POS_g_p_stIdentityMatrix=(POS_tdstCompletePosition *)SNA_fn_vReadPointerFromGlobalPointersFile();
	POS_g_p_stIdentityMatrix->ulType = POS_C_ulIdentityMatrixFlag;
	MTH3D_M_vNullVector(&(POS_g_p_stIdentityMatrix->stTranslationVector));
	MTH3D_M_vSetIdentityMatrix(&(POS_g_p_stIdentityMatrix->stRotationMatrix));
	MTH3D_M_vSetIdentityMatrix(&(POS_g_p_stIdentityMatrix->stTransformMatrix));
 
	for (i=0;i<HIE_C_lMaxMatrixInStack;i++)
		HIE_g_a_hMatrixStack[i]=(GEO_tdxHandleToMatrix)SNA_fn_vReadPointerFromGlobalPointersFile();
	SNA_fn_vReadStructureFromGlobalPointersFile((unsigned long *)&HIE_g_lNbMatrixInStack,4);
	
	g_hCollisionGeoObj=(ACP_tdxHandleOfObject)SNA_fn_vReadPointerFromGlobalPointersFile();
	g_hStaticCollisionGeoObj=(ACP_tdxHandleOfObject)SNA_fn_vReadPointerFromGlobalPointersFile();
	
	/* Sans doute a enlever dans la version finale.(touches de test & de cheats)*/
#ifdef RETAIL
	/* tout à fait */
	SNA_fn_vReadStructureFromGlobalPointersFile( (unsigned long *)&st_Tmp_3DOS_EntryActions, sizeof(g_st_3DOS_EntryActions) );
#else /* RETAIL */
	SNA_fn_vReadStructureFromGlobalPointersFile( (unsigned long *)&g_st_3DOS_EntryActions, sizeof(g_st_3DOS_EntryActions) );
#endif /* RETAIL */ 

#ifdef USE_IPT_DX5
	/* Gus 13/08/98 : Lecture structures IPT */
	p_vDummy = IPT_g_hInputStructure.hEventHistoric ;
	p_vDummy2 = alloca(sizeof(IPT_g_hInputStructure.hDeviceHandle));
	p_vDummy3 = alloca(sizeof(IPT_g_hInputStructure.p_ucValideAndActiveDevice));
	ucDummy = IPT_g_hInputStructure.ucKeyboardType ;
	ucDummy2 = IPT_g_hInputStructure.ucOnePadActivate ;
	memcpy(p_vDummy2,IPT_g_hInputStructure.hDeviceHandle,sizeof(IPT_g_hInputStructure.hDeviceHandle));
	memcpy(p_vDummy3,IPT_g_hInputStructure.p_ucValideAndActiveDevice,sizeof(IPT_g_hInputStructure.p_ucValideAndActiveDevice));
	IPT_gd_hKeyAndPadDefine  = (struct IPT_tdstKeyAndPadDefine_ *)SNA_fn_vReadPointerFromGlobalPointersFile( );
	SNA_fn_vReadStructureFromGlobalPointersFile( (unsigned long *)&IPT_g_hInputStructure, sizeof( struct IPT_tdstInput_ ) );
	IPT_g_hInputStructure.d_stEntryElementArray =  (struct IPT_tdstEntryElement_ *)SNA_fn_vReadPointerFromGlobalPointersFile( );
	IPT_g_hInputStructure.hEventHistoric = p_vDummy ;
	memcpy(IPT_g_hInputStructure.hDeviceHandle,p_vDummy2,sizeof(IPT_g_hInputStructure.hDeviceHandle));
	memcpy(IPT_g_hInputStructure.p_ucValideAndActiveDevice,p_vDummy3,sizeof(IPT_g_hInputStructure.p_ucValideAndActiveDevice));
	IPT_g_hInputStructure.ucKeyboardType = ucDummy ;
	IPT_g_hInputStructure.ucOnePadActivate = ucDummy2 ;
#else /* USE_IPT_WIN */
	/* Gus 13/08/98 : Lecture structures IPT */
	IPT_gd_hKeyAndPadDefine  = (struct IPT_tdstKeyAndPadDefine_ *)SNA_fn_vReadPointerFromGlobalPointersFile( );
	SNA_fn_vReadStructureFromGlobalPointersFile( (unsigned long *)&IPT_g_hInputStructure, sizeof( struct IPT_tdstInput_ ) );
	IPT_g_hInputStructure.d_stEntryElementArray =  (struct IPT_tdstEntryElement_ *)SNA_fn_vReadPointerFromGlobalPointersFile( );

	/* L'init est faite apres becoz elle met a jour les structures lues dans le fichier SNA*/
	/* (ie: si elle etait faite avant, les valeurs seraient ecrasees...)*/
	/* Special initialization of the Input when we load binary data*/
	IPT_fn_vInitInputWhenLoadSnapshot( fn_hGetApplicationInstance(),fn_hGetApplicationWindow() );

#endif /* USE_IPT_WIN */


	/* GuS 14/08/98 : lecture structure texts*/
	SNA_fn_vReadStructureFromGlobalPointersFile( (unsigned long *)&FON_g_stGeneral, sizeof( struct FON_tdstGeneral_ ) );

	/* Retrieve stack infos for all stacks in anim player.*/
	SNA_fn_vReadArrayWithoutPointerFromGlobalPointersFile( tdstStacks, eStackNbMax, sizeof(tdstStackInfos) );
	/* Load stack pointers for anims.*/
	p_stA3dGENERAL = (tdstA3dGENERAL *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_a3_xVectors = (tdxVector3 *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_a4_xQuaternions = (tdxSShortQuater4 *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stHierarchies = (tdstHierarchy *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stNTTO = (tdstNTTO *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stOnlyFrames = (tdstOnlyFrame *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stChannels = (tdstChannel *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stFrames = (tdstFrame *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stFramesKF = (tdstFrameKF *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stKeyFrames = (tdstKeyFrame *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stEvents = (tdstEvent *)SNA_fn_vReadPointerFromGlobalPointersFile();
	p_stMorphData = (tdstMorphData *)SNA_fn_vReadPointerFromGlobalPointersFile();
 
	/* Read the position of the last always in the fix in the always model list.*/
	SNA_g_stFixInfo.h_LastAlwaysInTheFix = (ALW_tdxHandleToModelList)SNA_fn_vReadPointerFromGlobalPointersFile();

	/* Read DEMO GMT List */
	g_hDemoGMTFixList = (DEMO_tdxHandleToDemoGMTList)SNA_fn_vReadPointerFromGlobalPointersFile();

	SNA_fn_vCloseGlobalPointersFile();
 
/* ANNECY OA - 12/07/99 { */
	/* Load dummy datas : for protections */
	SNA_M_LoadUnusedRelocationTable();	
/* END ANNECY OA } */

	sprintf(szLevelSnapshotFilename,"%s\\Fix.ptx",fn_szGetLevelsDataPath());
	TEX_SetNameOfBinaryFile((unsigned char *)szLevelSnapshotFilename);
 
	SNA_M_vSetNextRelocationFileToLoad( 255, SNA_C_ucTexturesRelocationTable );
	GLI_vEndofGeometricLoad();
	
	g_stEngineStructure.hLevelNameList=hLevelNameList;

	SNA_M_vSetNextRelocationFileToLoad( 255, SNA_C_ucSoundRelocationTable );
	sprintf(szFileName,"%s\\Fix.snd",fn_szGetLevelsDataPath());
	SNA_fn_xReadOpenSoundTableFile(szFileName);
	SNA_fn_vReadAndUpdateSoundPointers(szFileName);

/* ANNECY OA - 12/07/99 { */
	/* Load dummy datas : for protections */
	SNA_M_LoadUnusedRelocationTable();	
/* END ANNECY OA } */

}
#endif /* GAM_USE_SNA */
 
#endif /* _FIRE_DEADCODE_U64_ */
 
/*-----------------------------------------------------------------------------
*  Description :   It is the last desinitialization of the engine
*-----------------------------------------------------------------------------
*  Input :
*  Output :
*-----------------------------------------------------------------------------
*  Creation date : 20/08/96            Author : Francois
*-----------------------------------------------------------------------------
*  Modification date :                 Modification Author :
*  Modifications :
*---------------------------------------------------------------------------*/
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
void fn_vLastDesinitEngine()
{
	GAM_fn_vSetEngineInFixMode();
	fn_bSaveCurrentGameOptions();
	
	GAM_fn_vDestroyGameDeviceAndViewPorts();
	
	GLI_vCloseGli();
	
	/**** desinitialize input devices ****/
#if defined(GAM_USE_SNA)
	if (SNA_fn_ucGetLoadType()==SNA_LOAD_SNAPSHOT)
		IPT_fn_vDesinitInputWhenLoadSnapshot();
	else
#endif /* GAM_USE_SNA */
		IPT_fn_vDesinitInput();
	/**** desinitialize random devices ****/
	RND_fn_vDesinitRandom();
	
#if defined(GAM_USE_SNA)
	if (SNA_fn_ucGetLoadType()==SNA_SAVE_SNAPSHOT)
		GAM_fn_vSetEngineInFixMode();
#endif /* GAM_USE_SNA */
	
	/**** Vignette desinit ****/
#if defined(GAM_VIGNETTE)
	VIG_fn_vCloseBigFileVignette();
#endif /* GAM_VIGNETTE */
	
	/***** Desinit SON*/
	SND_fn_vDesInitSound();
	SIF_fn_bDesInitSoundInfos();
	
	/**** Desinit all object's type structure ****/
	fn_vLastDesinitObjectTypeStructure();
	/**** Desinit all Family's structures ****/
#if defined(GAM_USE_SNA)
	if (SNA_fn_ucGetLoadType()!=SNA_LOAD_SNAPSHOT)
#endif /* GAM_USE_SNA */
		fn_vLastDesinitFamilyStructure();

#ifndef U64
	DEMO_fn_vDesInitGame ();
#endif /* U64 */
	/**** desinitialize the memory ****/
	fn_vLastDesinitGameMemory();

/* GuS : Moved in fn_vDesinitEngineWhenLeaveApplication
    MMG_fn_vDesinitMemoryRasterDeclaration ();
*/
 
#ifndef U64
 FON_fn_vDesInitFonts();
#endif
}
#endif /* _FIRE_DEADCODE_U64_ /* Added by RUC */
 
/*-----------------------------------------------------------------------------
 
  *  Description :   It is the initialization of the engine when the game started
  *-----------------------------------------------------------------------------
  *  Input :
  *  Output :
  *-----------------------------------------------------------------------------
  *  Creation date : 27/08/96            Author : Francois
  *-----------------------------------------------------------------------------
  *  Modification date :                 Modification Author :
  *  Modifications :
*---------------------------------------------------------------------------*/
void fn_vInitGameLoop()
{
  tdeEngineMode eCallingMode = g_stEngineStructure.eEngineMode;
 
	/*XB move in fn_vLoadTheMap*/
	/*fn_vFirstInitMorphTaskList();*/
	/*End XB*/

/* XB 23/06/99 */
#ifdef U64
	LDD_fn_vLoadLDDCode();
#endif /* U64 */
/* End XB 23/06/99 */

	GAM_fn_vSetEngineInLevelMode();
	
	fn_bSaveCurrentGameOptions();
	/**** Initialize the game timer ****/
	fn_vReinitEngineClock();
	HIE_fn_vInitGlobalMatrixFrameCounter(0);
	
	/**** Load all module that used in all the game, ****/
	if (fn_bIsNextLevelNameValid())
	{
		fn_vSetLevelName(fn_p_szGetNextLevelName());
		fn_vFreeNextLevelName();
	}
	else
		fn_vSetLevelName(fn_p_szGetFirstLevelName());
	
	fn_vInitAllObjectsWhenNewGameStart();
	SAI_fn_bInitAllWhen(SAI_eInitWhenNewGameStart);
	
	/*if (  !stricmp(fn_p_szGetLevelName(),g_stEngineStructure.szCreditsLevelName)
		||!fn_bLoadPlayerSaveGameBeforeLoadLevel())
	{
		if (fn_bIsAValidCurrentExtraGame())
			fn_vSetLevelName(fn_p_szGetLevelNameOfCurrentExtra());
	}*/
	
	/* to make sure that everything goes fine*/
	fn_vChangeEngineMode(EM_ModeEnterLevel);
	/**** Initialize the Level loop members ****/
	fn_vInitLevelLoop();
 
	fn_vChangeEngineMode(eCallingMode); /* restore the mode we were in*/
	
	/* For AI_UnusedComport.log*/
	fn_vTestUnusedComport();
 
/*
#if !defined(ACTIVE_EDITOR)
	if ( g_stEngineStructure.eEngineMode == EM_ModeEnterGame
		&&fn_bLoadPlayerSaveGameAfterLoadLevel())
	{
		SAI_fn_bInitAllWhen(SAI_eInitWhenPlayerGameSavedLoaded);
		fn_vInitAllObjectsWhenSavedGameJustLoaded();
	}
#endif // ACTIVE_EDITOR 
*/
 
    TFMT_vInitTextAfficheStructure();
}
 
/*-----------------------------------------------------------------------------
*  Description :   It is the desinitialization of the engine when the game started
*-----------------------------------------------------------------------------
*  Input :
*  Output :
*-----------------------------------------------------------------------------
*  Creation date : 27/08/96            Author : Francois
*-----------------------------------------------------------------------------
*  Modification date :                 Modification Author :
*  Modifications :
*---------------------------------------------------------------------------*/

#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC 04/06/99 */
void fn_vDesInitGameLoop()
{
	/**** DesInitialize the Level loop members ****/
	fn_vDesInitLevelLoop();
	
	GAM_fn_vSetEngineInFixMode();
	
	/**** Initialize the game timer ****/
	fn_vRedesinitEngineClock();
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC 04/06/99 */
 
/*-----------------------------------------------------------------------------
*  Description :   It is the initialization of the engine when map just loaded
*-----------------------------------------------------------------------------
*  Input :
*  Output :
*-----------------------------------------------------------------------------
*  Creation date : 27/08/96            Author : Francois
*-----------------------------------------------------------------------------
*  Modification date :                 Modification Author :
*  Modifications :
*---------------------------------------------------------------------------*/
/*-------------------------------------------*/
void fn_vStandardInitLevelLoop()
{
	/**************************/
	/**** Init before load ****/
	/**************************/
	fn_vSetDisplayFlag(edmDisplayModeAll,1);
	
	COL_fn_vOctreeGlobalInit();
 
/* ANNECY AV DEMO {*/
#ifndef U64
    DEMO_fn_vInitSOList ();
	DEMO_fn_vInitGMTLevelList ();
#endif
/* END ANNECY AV }*/

	/**** Load all module that used in all the game, ****/
	fn_vLoadLevel(fn_p_szGetLevelName(),fn_lGetSubMapNumber());
 
#if (defined(USE_PROFILER) && !defined(PRESS_DEMO) && !defined(U64))
	GAM_fn_vRasterDumpInit ();
#endif
 
	fn_vFirstInitAlwaysStructure();
	fn_vInitMindForAlways();
#if defined(GAM_USE_SCRIPT)
	fn_vWaypointSecondPass();
#endif /* GAM_USE_SCRIPT */
/*XB980824*/
#ifndef D_THROW_MGT
	MGT_fn_vFirstInitMagnet();
#endif /* D_THROW_MGT */
/*End XB*/
	
	/**** Init all object when the player enter the map ****/
	fn_vInitAllObjectsWhenMapJustLoaded();
	
	/* camera's management */
	CAM_fn_vInitCameras();
	
/* XB 16/06/99 */
#if !defined(ACTIVE_EDITOR) && !defined(U64)
	fn_vDeleteAllLevelReUsableSections();
#endif /* !defined(ACTIVE_EDITOR) && !defined(U64) */
/* End XB 16/06/99 */
	
/* XB 23/06/99 */
#ifndef U64
	/*bart990105 :*/
	if (fn_bIsEngineInPause())
		fn_vChangeWindowTitle("Rayman II - pause");
	else
		fn_vChangeWindowTitle("Rayman II");
	
	fn_vSetEngineWorldForITF(gp_stActualWorld);
#endif /* U64 */
/* End XB 23/06/99 */
	
	SAI_fn_bInitAllWhen(SAI_eInitWhenMapLoaded);
	/**** Initialize the Dead loop members ****/
	fn_vInitDeadLoop();
	
#ifdef ACTIVE_EDITOR
	if (g_bUseSAIWithEditor) {
#endif /* ACTIVE_EDITOR */
 
		if ( g_stEngineStructure.eEngineMode==EM_ModeEnterLevel )
		{
			char cDoInit = 0;
			if( fn_bLoadLevelSaveGameAfterLoadLevel() )
			{
				SAI_fn_bInitAllWhen(SAI_eInitWhenLevelGameSavedLoaded);
				cDoInit = 1;
			}
			if( fn_bLoadPlayerSaveGameAfterLoadLevel() )
			{
				SAI_fn_bInitAllWhen(SAI_eInitWhenPlayerGameSavedLoaded);
				cDoInit = 1;
			}
 
			if( cDoInit )
				fn_vInitAllObjectsWhenSavedGameJustLoaded();
		}
 
#ifdef ACTIVE_EDITOR
	}
#endif /* ACTIVE_EDITOR */
 
 
	
#ifdef U64
 /*AR9806 Load the init animations of each perso */
 GAM_fn_vLoadInitialAnimations();
#endif /*U64*/
	
/* ANNECY MT - 28/06/99 { */
	/**** Start the timer ****/
/*	fn_vStartEngineClock(); */
/* END ANNECY MT } */

#ifdef ACTIVE_EDITOR
	{
		unsigned long i, ulAllocatedSize = 1000;
		ALW_tdxHandleToModelList	h_AlwaysModelChild;
		char *p_szTxt = (char *) malloc(ulAllocatedSize);
		ACP_tdxBool bFoundSome = FALSE;

		strcpy(p_szTxt, "Les always chargés suivants ne sont pas référencés dans le niveau courant:\n\n");
		LST2_M_DynamicForEachElementOf(&(g_stAlways.ALW_h_LstAlwaysModel),h_AlwaysModelChild,i)
		if ( h_AlwaysModelChild && !g_stAlways.d_bIsReferencedInLevel[i] )
		{
			SCR_tdst_Link_Value   *p_stLinkValue = SCR_fnp_st_Link_SearchValue(&g_st3DOSLinkTable.stCharacter, (unsigned long) h_AlwaysModelChild->p_stAlwaysObject);
			if ( p_stLinkValue )
			{
				char szSectionName[SCR_CV_ui_Cfg_MaxLenName],szAction[SCR_CV_ui_Cfg_MaxLenName],szId[SCR_CV_ui_Cfg_MaxLenName];

				// construct section name (hack: szSectionName is here as an anti-bug for ...Split...
				SCR_fn_v_RdL0_SplitSectionName(SCR_M_p_sz_Link_GetKey(p_stLinkValue), szSectionName, szAction, szId);
				bFoundSome = TRUE;
				if ( strlen(p_szTxt)  + strlen(szId) + 3 >= ulAllocatedSize ) /* both strings, the tab, the CR/LF, and the terminator */
				{
					ulAllocatedSize += strlen(szId) * 3;
					p_szTxt = realloc(p_szTxt, ulAllocatedSize);
				}
				strcat(p_szTxt, "\t");
				strcat(p_szTxt, szId);
				strcat(p_szTxt, "\n");
			}
		}
		if ( bFoundSome )
		{
			MessageBox(NULL, p_szTxt, "Pour info", MB_OK|MB_ICONWARNING);
		}
		free(p_szTxt);
	}
#endif /* ACTIVE_EDITOR */

#ifdef U64
	fn_vForceReinitAllObjects();
#endif
}
 
void SPO_ReinitSuperimposedArray (void) ;
 
/*-----------------------------------------------------------------------------
*  Description :   It is the initialization of the engine when Game just dead
*-----------------------------------------------------------------------------
*  Input :
*  Output :
*-----------------------------------------------------------------------------
*  Creation date : 27/08/96            Author : Francois
*-----------------------------------------------------------------------------
*  Modification date :                 Modification Author :
*  Modifications :
*---------------------------------------------------------------------------*/
void fn_vInitDeadLoop()
{
	SND_tduRefEvt	uSoundEvent;
	/**** Trame counter ****/
	g_stEngineStructure.stEngineTimer.ulTrameNumber = 0;
  g_stEngineStructure.bEngineFrozen	= 0; /* by default all characters are handled normally*/
/* Begin Shaitan ModeLook*/
  g_stEngineStructure.cCameraMode	= C_CamModeNormal; /* by default the mode is normal*/
/* End Shaitan ModeLook*/
 
#ifdef U64	
  	/* FQ FADE*/
	/*fn_vFadeIn();*/
	/*////////////*/
#endif
 
	fn_vStartEngineClock();
	fn_vReinitTheStaticHierarchie(SECT_hFatherSector);
	CAM_fn_vActualizeAViewport(CAM_e_MainViewport);
	
	if
		(
		g_stEngineStructure.eEngineMode!=EM_ModeEnterLevel &&
		g_stEngineStructure.eEngineMode!=EM_ModeEnterGame
		)
	{
/* ANNECY MT - 28/08/98 {*/
		HIE_tdxHandleToSuperObject hMaincharacter = MC_fn_hGetCharacterInMainCharacterNode( MC_fn_hGetFirstMainCharNode() );
 
		/**** DFM 12/02/98*/
		/* if the main character has 0 hitpoints left, we reinit the map as if it was just loaded */
		if ( fn_ucStandardGameGetHitPoints ( M_GetMSHandle(hMaincharacter, StandardGame) ) > 0 )
		{
			SAI_fn_bInitAllWhen(SAI_eInitWhenPlayerDead) ;
			fn_vInitAllObjectsWhenPlayerDead();
			/*
			 * reactivate all IPT entries that might have been deactivated by the AI of some characters
			 * since it is also called by fn_vReinitTheMap(), it is useless to do this when we call it, like just below
			 */
			IPT_fn_vActivateAllEntryElements ( ) ;
		}
		else
		{
			fn_vReinitTheMap() ;
			/*SAI_fn_bInitAllWhen(SAI_eInitWhenMapLoaded) ;
			fn_vInitAllObjectsWhenMapJustLoaded();*/
		}
		if(g_stEngineStructure.bResurection)
		{
			/* restore main character initial position*/
			if(hMaincharacter)
			{
				POS_fn_vCopyMatrix
				(
					fn_p_st3dDataGetMatrixInit(M_GetMSHandle(hMaincharacter,3dData)),
					&g_stEngineStructure.stMainCharacterPosition
				);
			}
			/* restore main camera initial position*/
			if(g_stEngineStructure.h_StdCamCaracter)
			{
				POS_fn_vCopyMatrix
				(					
					fn_p_st3dDataGetMatrixInit(M_GetMSHandle(g_stEngineStructure.h_StdCamCaracter,3dData)),
					&g_stEngineStructure.stMainCameraPosition
				);
			}
		}
		g_stEngineStructure.bResurection = FALSE;
/* END ANNECY MT }*/
		g_hSOCurrentMainSector = NULL;

 
		/*
		* Reinit Fog and sinus effect
		*/
		GLI_cGlobalFogIsOn = 0;
		GLI_vInitWaterplaneModule();
	}
/* Oliv' - ??? - E3*/
	fn_vReputCharacterSuperObjectAtTheWorld(MC_fn_hGetCharacterInMainCharacterNode( MC_fn_hGetFirstMainCharNode()));
 
/* Oliv' - 18/11/1998 - C'est trop tard ici car les objets dans le tableau n'existent plus*/
/* -> voir fn_vDesInitLevelLoop() dans Initeng.cxx*/
/*	SPO_ReinitSuperimposedArray();*/
 
	/*////////////////////////////////*/
	/* FQ OVR :*/
#ifdef U64
#ifndef _FIRE_DEADCODE_U64_ /* Added by XB */
	// Desinit the Memory Holes List
	MMG_fn_vReinit_FreeMemoryBlocks();
	M_PrintfN64(( "MMG_fn_vReinit_FreeMemoryBlocks() called !\n" ));
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by XB */
//XB
//SHW_fn_vReInitShadowForMapChange is now called in LoadLevel not in InitDeadLoop
	// Reinit for shadows	
//	SHW_fn_vReInitShadowForMapChange();
//End XB
#endif /* U64 */
	/* END FQ OVR*/
	/*////////////////////////////////*/
	if( g_stEngineStructure.eEngineMode==EM_ModeDeadLoop && g_bBeginMapSoundEventFlag )
	{
		uSoundEvent.pstPtr = GAM_p_stGetBlockEventSlotMemory(0);
		SND_fn_lSendRequestSound(SND_C_OBJET_FANTOME,g_lSoundObjectTypeMusic,uSoundEvent,0,NULL);
	}
}

/*-----------------------------------------------------------------------------
*  Description :   It is the desinitialization of the engine when Game just dead
*-----------------------------------------------------------------------------
*  Input :
*  Output :
*-----------------------------------------------------------------------------
*  Creation date : 27/08/96            Author : Francois
*-----------------------------------------------------------------------------
*  Modification date :                 Modification Author :
*  Modifications :
*---------------------------------------------------------------------------*/
void fn_vDesInitDeadLoop()
{
 
/* fbolefeysot - 25/08/98*/
/* replace the link reinit . before, it was done only for Raymond, now, it is made for all actors*/
/*	fn_vReputCharacterSuperObjectAtTheWorld(MC_fn_hGetCharacterInMainCharacterNode(MC_fn_hGetFirstMainCharNode()));*/
	fn_vDestructAllFatherSonLinks();
/*END fbolefeysot}*/
 
	fn_vKillAllAlways();
	AGO_vInit();
 
#if (defined(USE_PROFILER) && !defined(PRESS_DEMO) && !defined(U64))
	GAM_fn_vRasterDumpReset ();
#endif
}
/**************************************************************************/

#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC 04/06/99 */
void fn_vInitAllLinkTables(void)
{
#if defined(GAM_USE_SCRIPT)
	/**** Those link-tables are for the editors and for the engine ****/
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stACZ);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stAnimation);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stCharacter);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stState);
	
	SCR_fn_v_Link_InitTable(&g_stComportLinkTable);
	
	SCR_fn_v_Link_InitTable(CHL_fn_p_stGetLinkTable());
	SCR_fn_v_Link_InitTable(TBL_fn_p_stGetLinkTable());
	
	/**** Those link-tables are only used by the editors ****/
	
#if defined(ACTIVE_EDITOR)/*||defined(BIN_SaveBin)*/
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stACZList);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stCharacterZone);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stLipsSynchroList);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stZDXList);
	
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stPrtGenLinkTable);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stPrtSrcLinkTable);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stPrtSysLinkTable);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stPrtSysSpriteLinkTable);
	SCR_fn_v_Link_InitTable(&g_st3DOSLinkTable.stPrtEnvLinkTable);
#endif /* ACTIVE_EDITOR */
	
	/**** Those link-tables are not already defined (editors and/or engine) ****/
	SCR_fn_v_Link_InitTable(CS_fn_p_stGetLinkTable());
	SCR_fn_v_Link_InitTable(DNM_fn_p_stGetLinkTableOfMecMatCharacteristics());
	SCR_fn_v_Link_InitTable(DNM_fn_p_stGetLinkTableOfIdCard());
	/* SCR_fn_v_Link_InitTable(GLI_p_stGetLinkTableOfGeometric()); // already initialized*/
	SCR_fn_v_Link_InitTable(GLI_p_stGetLinkTableOfVisualMaterial());
	SCR_fn_v_Link_InitTable(GMT_fn_p_stGetLinkTable());
	SCR_fn_v_Link_InitTable(GMT_fn_p_stGetZoneLinkTable());
	SCR_fn_v_Link_InitTable(HIE_fn_p_stGetSuperObjectLinkTable());
	SCR_fn_v_Link_InitTable(HIE_fn_p_stGetLinkedObjectLinkTable());
	SCR_fn_v_Link_InitTable(IPO_fn_p_stGetLinkTable());
	SCR_fn_v_Link_InitTable(ISI_fn_pGetLinkTable());
	SCR_fn_v_Link_InitTable(LGT_fn_p_stGetLightLinkTable());
	SCR_fn_v_Link_InitTable(PO_fn_p_stGetLinkTable());
	/* Shaitan Clean Env {*/
	/* SCR_fn_v_Link_InitTable(SRF_GetSurfaceLinkTable());*/
	/* End Shaitan Clan Env }*/
	SCR_fn_v_Link_InitTable(VS_fn_p_stGetLinkTable());
	SCR_fn_v_Link_InitTable(WP_fnp_WayPoint_GetLinkTable());
/* ANNECY MT - 16/09/98 {*/
	SCR_fn_v_Link_InitTable(WPG_fnp_Graph_GetLinkTable());
/* END ANNECY MT }*/
	
	/**** Those link-tables are used in the level ****/
	SCR_fn_v_Link_InitTable(SECT_fn_pGetLinkTable());
#endif /* GAM_USE_SCRIPT */
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC 04/06/99 */
 
 
/**************************************************************************/
/*-----------------------------------------------------------------------------
*  Description : This reinit all variables for a map (and characters)
*-----------------------------------------------------------------------------
*  Input :
*  Output :
*-----------------------------------------------------------------------------
*  Creation date : 27/08/96            Author : Francois
*-----------------------------------------------------------------------------
*  Modification date :                 Modification Author :
*  Modifications :
*---------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"
{
#endif
extern int iNumLoop; /*declared in the AI module*/
#ifdef __cplusplus
}
#endif
 
#ifdef U64
extern char GLI_cGlobalForceFogIsOn;
#endif
 
void fn_vReinitTheMap(void)
{
/* XB 23/06/99 */
#ifndef U64
	GLD_bSetBackgroundColorForDevice(fn_hGetGLDDevice(0), RGB(0,0,0));
#else /* U64 */
	GLD_bSetBackgroundColorForDevice(NULL, RGB(0,0,0));
#endif /* U64 */
/* End XB 23/06/99 */
	
	fn_vStartEngineClock();
	
	/* Just killing Anims and voices sounds*/
	SND_fn_vKillAllObjectTypeSound( g_lSoundObjectTypeAnim );
#ifdef D_USE_LIPSYNC
	SND_fn_vKillAllObjectTypeSound( g_lSoundObjectTypeLipsSynchro );
#endif
	
/* ANNECY MT - 28/08/98 {*/
	POS_fn_vSetIdentityMatrix(&g_stEngineStructure.stMainCharacterPosition);
	POS_fn_vSetIdentityMatrix(&g_stEngineStructure.stMainCameraPosition);
	g_stEngineStructure.bResurection = FALSE;	
/* END ANNECY MT }*/
	fn_vKillAllAlways();
	fn_vDestructAllFatherSonLinks();
	SAI_fn_bInitAllWhen(SAI_eInitWhenReinitTheMap);
	fn_vForceReinitAllObjects();
 
/*HP 031298 {*/
/* define main caracter position for demo mode */
#ifdef U64

	/* FQ IA FOG ! */
	GLI_cGlobalForceFogIsOn=0;
	/* FQ */

	if(g_stEngineStructure.xDemoMode==TRUE)
	{
		MTH3D_tdstVector	*p_stMainCharTranslation;
		HIE_tdxHandleToSuperObject hMaincharacter = MC_fn_hGetCharacterInMainCharacterNode( MC_fn_hGetFirstMainCharNode() );
 
		p_stMainCharTranslation = POS_fn_p_stGetTranslationVector(HIE_fn_hGetSuperObjectGlobalMatrix (hMaincharacter));
		INO_fn_vU64PutMainCharForDemoPlay(p_stMainCharTranslation);
		HIE_fn_vComputeNewRelativeMatrix (hMaincharacter);
		/* update dynamics*/
		MEC_fn_vImposeActorMatrix (hMaincharacter);
		/* compute camera position*/
		CAM_fn_vForceBestPosition(g_stEngineStructure.h_StdCamCaracter);	
	}
#endif
/* }HP*/
	fn_vReinitTheStaticHierarchie(SECT_hFatherSector);
	CAM_fn_vActualizeAViewport(CAM_e_MainViewport);
	/*
	* réinitialisation variable pour WaterPlane + sinus effect
	*/
	GLI_vInitWaterplaneModule();
	
 
	if( g_bBeginMapSoundEventFlag )
/*		SND_fn_lSendRequestSound(SND_C_OBJET_FANTOME,g_lSoundObjectTypeMusic,g_stBeginMapSoundEvent,0,NULL);*/
		GAM_fn_lSaveBlockEventSlotMemory(g_stBeginMapSoundEvent.pstPtr,0);
 
 
	MOR_fn_vRemoveAllMorphedObjects ();
/*XB980824*/
#ifndef D_THROW_MGT
	MGT_fn_vLastDesInitMagnet();
#endif /* D_THROW_MGT */
/*End XB*/
	GLI_cGlobalFogIsOn = 0;
	
	SPO_ReinitSuperimposedArray () ;
	
	PRF_fn_vReinitAllChrono ();
 
	g_hSOCurrentMainSector = NULL;
	iNumLoop = 0; /* clear the AI loop depth counter!*/

	/* reactivate all IPT entries that may have been deactivated by the AI of some character */
	IPT_fn_vActivateAllEntryElements ( ) ;

    TFMT_vInitTextAfficheStructure();
 
#if (defined(USE_PROFILER) && !defined(PRESS_DEMO) && !defined(U64))
	GAM_fn_vRasterDumpReset ();
#endif
 
/* ANNECY MT - 12/02/99 {*/
	AGO_vInit() ;
/* END ANNECY MT }*/
}
 
/*-----------------------------------------------------------------------------
*  Description : Reinit The static hierarchie
*-----------------------------------------------------------------------------
*  Input : SO
*  Output :
*-----------------------------------------------------------------------------
*  Creation date : 22/05/97            Author : Francois
*-----------------------------------------------------------------------------
*  Modification date :                 Modification Author :
*  Modifications :
*---------------------------------------------------------------------------*/
void fn_vReinitTheStaticHierarchie(HIE_tdxHandleToSuperObject hSuperObject)
{
	HIE_tdxHandleToSuperObject hChild;
	unsigned long i;
	
	HIE_fn_vSetSuperObjectDrawMask(hSuperObject,HIE_fn_lGetSuperObjectDrawMask(hSuperObject) |  ~GLI_C_lHasNoMirror );
	HIE_M_ForEachChildOf(hSuperObject,hChild,i)
	{
		fn_vReinitTheStaticHierarchie(hChild);
	}
/* fbolefeysot - 01/10/98*/
/* remove init values in GMT{*/
/*	if (HIE_fn_ulGetSuperObjectType(hSuperObject)==C_ucGeometric)
		GLI_p_stRecursiveReinitGameMaterialOfVisualsets((struct GEO_tdstVisualSet_*)HIE_fn_hGetSuperObjectObject(hSuperObject));
*/
/*END fbolefeysot}*/
	/* Shaitan Clean Env {*/
	/*
	if( HIE_fn_lGetSuperObjectType(hSuperObject)==C_ucSector )
	fn_vSectInfoReInitAllSurfacesInSector(hSuperObject);
	*/
	/* End Shaitan Clan Env }*/
}
 
/*-----------------------------------------------------------------------------
*  Description :   Verify integrity of some variables
*-----------------------------------------------------------------------------
*  Input :         void
*  Output :        void
*-----------------------------------------------------------------------------
*  Creation date : 30/08/96            Author : Francois
*-----------------------------------------------------------------------------
*  Modification date :                 Modification Author :
*  Modifications :
*---------------------------------------------------------------------------*/
void fn_vVerifySomeProgramVariables()
{
	/**** Verify the size of Object's structure and Handle functions array ****/
	if (  (g_a_stStructureHandleFunction[(long)(sizeof(tdstEngineObject)/sizeof(void*))].p_fn_vCopyCloneMSFunction!=(tdfn_vCopyCloneMSFunction *)0x00000001)
		||(g_a_stStructureHandleFunction[(long)(sizeof(tdstEngineObject)/sizeof(void*))].p_fn_ulSizeOfFunction!=(tdfn_ulSizeofHandleFunction *)0x00000002)
		||(g_a_stStructureHandleFunction[(long)(sizeof(tdstEngineObject)/sizeof(void*))].p_fn_vAllocFunction!=(tdfn_vAllocHandleFunction *)0x00000003)
		||(g_a_stStructureHandleFunction[(long)(sizeof(tdstEngineObject)/sizeof(void*))].p_fn_vFreeFunction!=(tdfn_vAllocHandleFunction *)0x00000004)
		||(g_a_stStructureHandleFunction[(long)(sizeof(tdstEngineObject)/sizeof(void*))].p_fn_vInitFunction!=(tdfn_vInitHandleFunction *)0x00000005)
		||(g_a_stStructureHandleFunction[(long)(sizeof(tdstEngineObject)/sizeof(void*))].p_fn_vDesinitFunction!=(tdfn_vInitHandleFunction *)0x00000006)
		)
	{
		M_GameFatalError(E_uwGameVerifySomeProgramVariableHandleFunction);
	}
}
 
 
 
 
#include "Specif\Initeng.cxx"
