This commit is contained in:
romkazvo
2023-08-07 19:29:24 +08:00
commit 34d6c5d489
4832 changed files with 1389451 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
// CryEntityDLL.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#if !defined(_XBOX) && !defined(LINUX)
#include <windows.h>
#else
#if !defined(LINUX)
#include <xtl.h>
#endif
#endif
#include <IEntitySystem.h>
#include "EntitySystem.h"
#if defined(_DEBUG) && !defined(LINUX)
static char THIS_FILE[] = __FILE__;
#define DEBUG_CLIENTBLOCK new( _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define new DEBUG_CLIENTBLOCK
#endif
//////////////////////////////////////////////////////////////////////////
// Pointer to Global ISystem.
static ISystem* gISystem = 0;
ISystem* GetISystem()
{
return gISystem;
}
// Local var to turn on/off profiler.
bool g_bProfilerEnabled = false;
//////////////////////////////////////////////////////////////////////////
#if !defined(_XBOX)
_ACCESS_POOL;
#if !defined(LINUX)
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
#endif
#endif
#if !defined(_XBOX) && !defined(LINUX) && !defined(PS2)
CRYENTITYDLL_API struct IEntitySystem * CreateEntitySystem(ISystem *pISystem)
#else
struct IEntitySystem * CreateEntitySystem(ISystem *pISystem)
#endif
{
gISystem = pISystem;
CEntitySystem *pEntitySystem= new CEntitySystem(pISystem);
if(!pEntitySystem->Init(pISystem))
{
pEntitySystem->Release();
return NULL;
}
return pEntitySystem;
}
//////////////////////////////////////////////////////////////////////////
#ifdef GERMAN_GORE_CHECK
#if !defined(_XBOX) && !defined(LINUX) && !defined(PS2)
CRYENTITYDLL_API struct IEntitySystem * CreateMainEntitySystem(ISystem *pISystem)
#else
struct IEntitySystem * CreateMainEntitySystem(ISystem *pISystem)
#endif
{
gISystem = pISystem;
return (IEntitySystem *) gISystem;
}
#endif
//////////////////////////////////////////////////////////////////////////
#include <CrtDebugStats.h>

View File

@@ -0,0 +1,480 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="CryEntitySystem"
ProjectGUID="{ED25E8E5-3A18-4236-9FE2-06E706380C5C}"
SccProjectName="Perforce Project"
SccAuxPath=""
SccLocalPath="."
SccProvider="MSSCCI:Perforce SCM">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="D:\Games\FC\Bin32"
IntermediateDirectory=".\Debug"
ConfigurationType="2"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
OptimizeForProcessor="0"
AdditionalIncludeDirectories=".\,..\XIsle,..\CryCommon"
PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;_USRDLL;CRYENTITYDLL_EXPORTS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
BufferSecurityCheck="TRUE"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Debug/CryEntitySystem.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ImportLibrary="$(IntDir)/$(TargetName).lib"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Debug/CryEntitySystem.tlb"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="D:\Games\FC\Bin32"
IntermediateDirectory="Release"
ConfigurationType="2"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="3"
GlobalOptimizations="TRUE"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="2"
OmitFramePointers="TRUE"
EnableFiberSafeOptimizations="FALSE"
OptimizeForProcessor="2"
AdditionalIncludeDirectories=".\,..\,..\CryCommon,..\XIsle,..\Cry3DEngine,..\CryPhysics"
PreprocessorDefinitions="_RELEASE;NDEBUG;WIN32;_WINDOWS;_USRDLL;CRYENTITYDLL_EXPORTS"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
EnableFunctionLevelLinking="FALSE"
EnableEnhancedInstructionSet="0"
UsePrecompiledHeader="3"
PrecompiledHeaderFile=".\Release/CryEntitySystem.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
OutputFile=".\Release/CryEntitySystem.dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
ProgramDatabaseFile=".\Release/CryEntitySystem.pdb"
ImportLibrary="$(IntDir)/$(TargetName).lib"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Release/CryEntitySystem.tlb"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Profile|Win32"
OutputDirectory="D:\Games\FC\Bin32"
IntermediateDirectory="Profile"
ConfigurationType="2"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="3"
GlobalOptimizations="TRUE"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="2"
OmitFramePointers="TRUE"
EnableFiberSafeOptimizations="FALSE"
OptimizeForProcessor="2"
AdditionalIncludeDirectories=".\,..\,..\CryCommon,..\XIsle,..\Cry3DEngine,..\CryPhysics"
PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;_USRDLL;CRYENTITYDLL_EXPORTS"
StringPooling="TRUE"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
EnableFunctionLevelLinking="FALSE"
EnableEnhancedInstructionSet="0"
UsePrecompiledHeader="3"
PrecompiledHeaderFile=".\Profile/CryEntitySystem.pch"
AssemblerListingLocation=".\Profile/"
ObjectFile=".\Profile/"
ProgramDataBaseFileName=".\Profile/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="3"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
BaseAddress="0x32000000"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName="C:\MasterCD/CryEntitySystem.tlb"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug64|Win32"
OutputDirectory="D:\Games\FC\Bin32"
IntermediateDirectory="Debug64"
ConfigurationType="2"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\,..\XIsle,..\CryCommon"
PreprocessorDefinitions="_DEBUG;WIN64;_WINDOWS;_USRDLL;CRYENTITYDLL_EXPORTS"
BasicRuntimeChecks="0"
RuntimeLibrary="1"
BufferSecurityCheck="FALSE"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile="$(IntDir)/$(ProjectName).pch"
AssemblerListingLocation="$(IntDir)/"
ObjectFile="$(IntDir)/"
ProgramDataBaseFileName="$(IntDir)/$(ProjectName).pdb"
WarningLevel="3"
SuppressStartupBanner="TRUE"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:AMD64"
AdditionalDependencies="../CryCommon/fSinCos64.lib"
OutputFile="$(OutDir)/$(ProjectName).dll"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
LargeAddressAware="2"
SupportUnloadOfDelayLoadedDLL="FALSE"
ImportLibrary="$(OutDir)/$(ProjectName).lib"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Debug/CryEntitySystem.tlb"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release64|Win32"
OutputDirectory="D:\Games\FC\Bin32"
IntermediateDirectory="Release64"
ConfigurationType="2"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2"
WholeProgramOptimization="TRUE">
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/fp:fast
/GL"
Optimization="2"
GlobalOptimizations="TRUE"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="TRUE"
AdditionalIncludeDirectories=".\,..\XIsle,..\CryCommon"
PreprocessorDefinitions="_RELEASE;NDEBUG;WIN64;WIN32;_AMD64_;_WINDOWS;_USRDLL;CRYENTITYDLL_EXPORTS"
BasicRuntimeChecks="0"
RuntimeLibrary="2"
BufferSecurityCheck="FALSE"
UsePrecompiledHeader="3"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile="$(IntDir)/$(ProjectName).pch"
AssemblerListingLocation="$(IntDir)/"
ObjectFile="$(IntDir)/"
ProgramDataBaseFileName="$(IntDir)/$(ProjectName).pdb"
WarningLevel="3"
SuppressStartupBanner="TRUE"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="../CryCommon/fSinCos64.lib"
OutputFile="$(OutDir)/$(ProjectName).dll"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/$(ProjectName).pdb"
LargeAddressAware="2"
SupportUnloadOfDelayLoadedDLL="FALSE"
ImportLibrary="$(OutDir)/$(ProjectName).lib"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Debug/CryEntitySystem.tlb"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath=".\CryEntityDLL.cpp">
</File>
<File
RelativePath=".\Entity.cpp">
</File>
<File
RelativePath=".\EntityCamera.cpp">
</File>
<File
RelativePath=".\EntityCreation.cpp">
</File>
<File
RelativePath=".\EntityIt.cpp">
</File>
<File
RelativePath=".\EntityPesistence.cpp">
</File>
<File
RelativePath=".\EntityRender.cpp">
</File>
<File
RelativePath=".\EntitySystem.cpp">
</File>
<File
RelativePath=".\IDGenerator.cpp">
</File>
<File
RelativePath=".\stdafx.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Profile|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Debug64|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release64|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
<Filter
Name="Lip Sync"
Filter="">
<File
RelativePath=".\LipSync.cpp">
</File>
<File
RelativePath=".\LipSync.h">
</File>
<File
RelativePath=".\RandomExprLoadSink.cpp">
</File>
<File
RelativePath=".\RandomExprLoadSink.h">
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath=".\Entity.h">
</File>
<File
RelativePath=".\EntityCamera.h">
</File>
<File
RelativePath=".\EntityIt.h">
</File>
<File
RelativePath=".\EntitySystem.h">
</File>
<File
RelativePath=".\IDGenerator.h">
</File>
<File
RelativePath=".\stdafx.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = "file:F:\\Crytek\\CryEntitySystem\\CryEntitySystem.vcproj"
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
}

View File

@@ -0,0 +1,207 @@
<?xml version="1.0" encoding = "windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Name="CryEntitySystem_XBox"
SccProjectName="&quot;$/Game01/CryEntitySystem&quot;, HFRAAAAA"
SccAuxPath=""
SccLocalPath="."
SccProvider="MSSCCI:Microsoft Visual SourceSafe">
<Platforms>
<Platform
Name="Xbox"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Xbox"
OutputDirectory="Debug_XBox"
IntermediateDirectory="Debug_XBox"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\,..\CryCommon"
PreprocessorDefinitions="_DEBUG;_XBOX;_LIB"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
BufferSecurityCheck="TRUE"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdafx.h"
PrecompiledHeaderFile=".\Debug_XBox/CryEntitySystem.pch"
AssemblerListingLocation=".\Debug_XBox/"
ObjectFile=".\Debug_XBox/"
ProgramDataBaseFileName=".\Debug_XBox/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)/CryEntitySystem.lib"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
</Configuration>
<Configuration
Name="Release|Xbox"
OutputDirectory="Release_XBox"
IntermediateDirectory="Release_XBox"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
GlobalOptimizations="TRUE"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
AdditionalIncludeDirectories=".\,..\,..\CryCommon,..\XIsle,..\Cry3DEngine,..\CryPhysics"
PreprocessorDefinitions="_RELEASE;NDEBUG;_XBOX;_LIB"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="2"
PrecompiledHeaderFile="$(IntDir)/CryEntitySystem.pch"
AssemblerListingLocation="$(IntDir)/"
ObjectFile="$(IntDir)/"
ProgramDataBaseFileName="$(IntDir)/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="2"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)/CryEntitySystem.lib"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
</Configuration>
<Configuration
Name="Profile|Xbox"
OutputDirectory="Profile"
IntermediateDirectory="Profile"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
GlobalOptimizations="TRUE"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="TRUE"
FavorSizeOrSpeed="1"
OmitFramePointers="TRUE"
OptimizeForProcessor="2"
AdditionalIncludeDirectories=".\,..\,..\CryCommon,..\XIsle,..\Cry3DEngine,..\CryPhysics"
PreprocessorDefinitions="NDEBUG;_XBOX;_LIB"
StringPooling="TRUE"
BufferSecurityCheck="FALSE"
UsePrecompiledHeader="3"
PrecompiledHeaderFile=".\Profile/CryEntitySystem.pch"
AssemblerListingLocation=".\Profile/"
ObjectFile=".\Profile/"
ProgramDataBaseFileName=".\Profile/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="3"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)/CryEntitySystem.lib"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
</Configuration>
</Configurations>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath=".\CryEntityDLL.cpp">
</File>
<File
RelativePath=".\Entity.cpp">
</File>
<File
RelativePath=".\EntityCamera.cpp">
</File>
<File
RelativePath=".\EntityCreation.cpp">
</File>
<File
RelativePath=".\EntityIt.cpp">
</File>
<File
RelativePath=".\EntityPesistence.cpp">
</File>
<File
RelativePath=".\EntityRender.cpp">
</File>
<File
RelativePath=".\EntitySystem.cpp">
</File>
<File
RelativePath=".\IDGenerator.cpp">
</File>
<File
RelativePath=".\stdafx.cpp">
<FileConfiguration
Name="Profile|Xbox">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath=".\Entity.h">
</File>
<File
RelativePath=".\EntityCamera.h">
</File>
<File
RelativePath=".\EntityIt.h">
</File>
<File
RelativePath=".\EntitySystem.h">
</File>
<File
RelativePath=".\IDGenerator.h">
</File>
<File
RelativePath=".\stdafx.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = "file:F:\\Crytek\\CryEntitySystem\\CryEntitySystem_XBox.vcproj"
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
}

3897
CryEntitySystem/Entity.cpp Normal file

File diff suppressed because it is too large Load Diff

1051
CryEntitySystem/Entity.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,365 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: EntityCamera.cpp
// Version: v1.00
// Created: 14/8/2001 by Timur.
// Compilers: Visual C++ 6.0
// Description: Entity Camera implementation.
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "EntityCamera.h"
#include "Entity.h"
#include <ISystem.h>
#ifdef _DEBUG
static char THIS_FILE[] = __FILE__;
#define DEBUG_CLIENTBLOCK new( _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define new DEBUG_CLIENTBLOCK
#endif
void CEntityCamera::Init(IPhysicalWorld * pIPhysWorld, UINT iWidth, UINT iHeight, IConsole *pConsole)
{
m_camera.Init(iWidth, iHeight);
m_pIPhysWorld = pIPhysWorld;
// m_sParam.m_cam_kstiffness = 150;
m_sParam.m_cam_kstiffness = 15;
m_sParam.m_cam_kdamping = 2*(float)(cry_sqrtf(m_sParam.m_cam_kstiffness));
// m_sParam.m_cam_dir(0,17.0f,0.1f);
// m_sParam.m_cam_dir(0,2,0.5);
m_sParam.m_cam_dir(0,1,0.1f);
m_sParam.m_cam_dir.Normalize();
m_sParam.m_cam_dist = 1.5f;
m_sParam.m_cur_cam_dist = m_sParam.m_cur_cam_dangle = 0;
m_sParam.m_cam_angle_flags = 5;
m_sParam.m_cam_angle_kstiffness = 20;
m_sParam.m_cam_angle_kdamping = 2*(float)(cry_sqrtf(m_sParam.m_cam_angle_kstiffness));
m_sParam.m_cur_cam_dangle_vel = m_sParam.m_cur_cam_vel = 0;
m_sParam.m_1pcam_butt_pos(0,0,0); m_sParam.m_1pcam_eye_pos(0,0,0);
m_sParam.m_camoffset(0,0,0);
m_sParam.m_viewoffset = 0;
m_pConsole = pConsole;
/*
m_pOne = pConsole->CreateVariable("zed","0",0);
m_pTwo = pConsole->CreateVariable("why","0",0);
m_pThree = pConsole->CreateVariable("eks","0",0);
*/
m_fTimeIdle = 10.0f;
m_fDeltaDist = 0.0f;
}
void CEntityCamera::SetThirdPersonMode( const Vec3d &center,const Vec3d &angles0,int mode,float frameTime,float range,int dangleAmmount,
IPhysicalEntity *physic, IPhysicalEntity *physicMore,
I3DEngine* p3DEngine, float safeRange)
{
ICVar *pVar = m_pConsole->GetCVar("es_PiercingCamera");
int bPiercing = pVar && pVar->GetIVal();
if (mode == CAMERA_3DPERSON1)
{
//remove this after vehicle camera tweaking is done
// put the final value in constructor
pVar = m_pConsole->GetCVar("ThirdPersonAngle");
float dirZ = pVar->GetFVal();
m_sParam.m_cam_dir(0,1,dirZ);
m_sParam.m_cam_dir.Normalize();
vectorf tview, dir, camdir, rotax,camdiry, campos;
tview.x=center.x;
tview.y=center.y;
tview.z=center.z;
camdir.x=m_sParam.m_cam_dir.x;
camdir.y=m_sParam.m_cam_dir.y;
camdir.z=m_sParam.m_cam_dir.z;
float cam_dist, cam_kstiffness,cam_kdamping,cam_angle_kstiffness,cam_angle_kdamping;
matrix3x3bf mtx;
int b1p=0;
if (range<3 && GetLengthSquared((m_sParam.m_1pcam_eye_pos-m_sParam.m_1pcam_butt_pos))>0) {
//note: order of angles is flipped!
//quaternionf qobj = quaternionf(angles.z*(PI/180.0f),angles.y*(PI/180.0f),angles.x*(PI/180.0f));
quaternionf qobj=GetRotationXYZ<float>( angles0*(gf_PI/180.0f) );
//Q2M_IVO
//qobj.getmatrix(mtx);
mtx=matrix3x3f(qobj);
tview += mtx*vectorf(m_sParam.m_1pcam_butt_pos);
camdir = mtx*vectorf(m_sParam.m_1pcam_eye_pos-m_sParam.m_1pcam_butt_pos);
cam_dist = camdir.len();
camdir /= cam_dist;
cam_kstiffness=cam_kdamping=0;
cam_angle_kstiffness=cam_angle_kdamping=0;
b1p = 1;
} else {
pe_status_living status;
if (physic && physic->GetStatus(&status))
tview += status.camOffset;
camdir = m_sParam.m_cam_dir;
cam_dist = range;//m_cam_dist;
cam_kstiffness=m_sParam.m_cam_kstiffness; cam_kdamping=m_sParam.m_cam_kdamping;
cam_angle_kstiffness=m_sParam.m_cam_angle_kstiffness; cam_angle_kdamping=m_sParam.m_cam_angle_kdamping;
}
dir=vectorf(GetPos())-tview;
Quat q(1, 0,0,0);
Vec3 angles = angles0;
if (m_sParam.m_cam_angle_flags & 4) q = GetRotationAA(angles.x*(gf_PI/180.0f),vectorf(1,0,0));
if (m_sParam.m_cam_angle_flags & 2) q = GetRotationAA(angles.y*(gf_PI/180.0f),vectorf(0,1,0))*q;
ray_hit hit;
if (!b1p && safeRange>0)
{
static float g_fYawFixups[] = { 0,180,90,-90,0 };
Quat qYaw;
int i=0;
do
{
qYaw = GetRotationAA((angles0.z+g_fYawFixups[i])*(gf_PI/180.0f),vectorf(0,0,1));
}
while (m_pIPhysWorld->RayWorldIntersection(tview,qYaw*q*camdir*safeRange, ent_all&~ent_independent, rwi_stop_at_pierceable,&hit,1, physic, physicMore) &&
++i<sizeof(g_fYawFixups)/sizeof(g_fYawFixups[0])-1);
angles.z = angles0.z + g_fYawFixups[i];
}
if (m_sParam.m_cam_angle_flags & 1) q = GetRotationAA(angles.z*(gf_PI/180.0f),vectorf(0,0,1))*q;
float dt=frameTime, dist=dir.len(), dangle;//a,newdist;
float e,v0,C1,C2;
if (dt>0.1f) dt=0.1f;
if (dist<0.001f) dist=0.001f,dir(0,0,1);
else dir/=dist;
if (!b1p) {
//Q2M_IVO
//q.getmatrix(mtx);
mtx=matrix3x3f(q);
camdir = mtx*vectorf(m_sParam.m_cam_dir);
}
rotax = (camdir^dir).normalize(); camdiry = rotax^camdir;
dangle = cry_acosf(min(1.0f,max(-1.0f,camdir*dir)));
Vec3 camdirTmp = camdir*(float)(cry_cosf(dangle))+camdiry*(float)(cry_sinf(dangle));
Vec3 camposTmp = tview+camdirTmp*dist;
if (!b1p) {
// dir = (camposTmp-tview).normalize()*0.5; camposTmp += dir;
if (!bPiercing && m_pIPhysWorld->RayWorldIntersection(tview,camposTmp-tview,
ent_static | ent_sleeping_rigid | ent_rigid | ent_terrain,
// rwi_stop_at_pierceable,
rwi_ignore_noncolliding,
&hit,1, physic, physicMore))
{
if(cam_dist<hit.dist)
m_fTimeIdle = 0.0f;
m_fDeltaDist = dist - hit.dist;
dist = hit.dist;
// m_sParam.m_cur_cam_vel = 20.0f;
// campos = hit.pt;
}
else
m_fDeltaDist = 0.0f;
// if ((campos-tview).len2()>sqr(0.75))
// campos -= dir;
}
if (dangle>gf_PI/2)
dangle = gf_PI/2;
if (cam_angle_kdamping==0)
dangle = 0;
else {
e = (float) cry_expf(-cam_angle_kdamping*0.5f*dt);
v0 = m_sParam.m_cur_cam_dangle_vel;// + (dangle-m_sParam.m_cur_cam_dangle)/dt;
C1 = dangle;
C2 = v0 + C1*cam_angle_kdamping*0.5f;
m_sParam.m_cur_cam_dangle = dangle = C1*e + C2*dt*e;
m_sParam.m_cur_cam_dangle_vel = -C1*cam_angle_kdamping*0.5f*e + C2*(e-cam_angle_kdamping*0.5f*dt*e);
}
m_fTimeIdle += dt;
if (cam_kstiffness==0 || dist>50)
dist = cam_dist;
else {
if(m_fDeltaDist>2.0f)
m_sParam.m_cur_cam_vel = 20.0f;
C1 = dist-cam_dist;
if(m_fTimeIdle>1.5f || m_fDeltaDist>.1f || C1>2.0f)
{
e = (float) cry_expf(-cam_kdamping*0.5f*dt);
v0 = m_sParam.m_cur_cam_vel;// - (dist-m_sParam.m_cur_cam_dist)/dt;
// C1 = dist-cam_dist;
C2 = v0 + C1*cam_kdamping*0.5f;
m_sParam.m_cur_cam_dist = dist = cam_dist + C1*e + C2*dt*e;
m_sParam.m_cur_cam_vel = -C1*cam_kdamping*0.5f*e + C2*(e-cam_kdamping*0.5f*dt*e);
}
else
{
cam_dist = dist;
}
}
camdir = camdir*(float)(cry_cosf(dangle))+camdiry*(float)(cry_sinf(dangle));
campos = tview+camdir*dist;
//*
if (!b1p && m_fDeltaDist==0.0f) {
dir = (campos-tview).normalize()*0.5; campos += dir;
if (!bPiercing && m_pIPhysWorld->RayWorldIntersection(tview,campos-tview,
ent_static | ent_sleeping_rigid | ent_rigid | ent_terrain,
// rwi_stop_at_pierceable,
rwi_ignore_noncolliding,
&hit,1, physic, physicMore))
{
m_fTimeIdle = 0.0f;
campos = hit.pt;
}
if ((campos-tview).len2()>sqr(0.75))
campos -= dir;
}
//*/
SetPos((Vec3d) campos);
// m_camera.m_OldPosition = campos;
Vec3d cam_angles;
if (b1p) {
cam_angles.z = angles.z-180;
cam_angles.x = -angles.x;
cam_angles.y = -angles.y;
} else {
cam_angles.z = (float)(-cry_atan2f(camdir.x,camdir.y));
cam_angles.x = (float)(cry_atan2f(camdir.z,cry_sqrtf(sqr(camdir.x)+sqr(camdir.y))));
cam_angles.y = 0;
cam_angles *= 180.0f/gf_PI;
}
SetAngles(cam_angles);
}
else
if (mode == CAMERA_3DPERSON2)
{
CryError( "<EntitySystem> Camera in CAMERA_3DPERSON2 mode" );
Vec3d tview=center;
pe_status_living status;
if (physic && physic->GetStatus(&status))
tview += (Vec3d)status.camOffset;
Vec3d ang = GetAngles();
int dangle = dangleAmmount;
dangle = 90*(dangle-1&3); if (dangle>180) dangle-=360;
tview.x+= - range*cry_sinf(DEG2RAD(ang[ROLL]+dangle));
tview.y+= range*cry_cosf(DEG2RAD(ang[ROLL]+dangle));
tview.z+=1.0f;
ang.z=angles0.z+90;
SetAngles(ang);
SetPos(tview);
}
else
{
//center is where we want to look
// angles is where our target looks
Vec3d mycenter=center;
mycenter.z+=1.7f;
Vec3d offset;
Vec3d myangles;
//Matrix44 mtx;
//mtx.Identity();
//mtx=GetTranslationMat(center)*mtx;
//mtx=GetRotationZYX44(-gf_DEGTORAD*angles)*mtx; //NOTE: angles in radians and negated
//OPTIMISED_BY_IVO
Matrix44 mtx=Matrix34::CreateRotationXYZ( Deg2Rad(angles0),center);
mtx=GetTransposed44(mtx); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
Vec3d vBpos=mtx.TransformPointOLD(offset);
vectorf start, end;
ray_hit hit;
// so this pos is where we want to be
// lets move toward it slowly
Vec3d currpos = GetPos();
start.Set(mycenter.x,mycenter.y,mycenter.z);
end.Set(vBpos.x,vBpos.y,vBpos.z);
if (!bPiercing && m_pIPhysWorld->RayWorldIntersection(start,end-start,ent_terrain|ent_static, rwi_stop_at_pierceable,&hit,1, physic))
vBpos = (Vec3d)hit.pt;
Vec3d finalpos;
finalpos = currpos + (vBpos - currpos)*0.1f;
SetPos(finalpos);
myangles = mycenter - finalpos;
myangles=ConvertVectorToCameraAngles(myangles);
SetAngles(myangles);
}
}
void CEntityCamera::SetCameraMode(const Vec3d &lookat, const Vec3d &lookat_angles, IPhysicalEntity *physic)
{
Vec3d mycenter=lookat;
mycenter.z+=1.7f;
Vec3d offset = m_vCameraOffset;
Vec3d myangles;
//Matrix44 mtx;
//mtx.Identity();
//mtx=GetTranslationMat(lookat)*mtx;
//mtx=GetRotationZYX44(-gf_DEGTORAD*lookat_angles)*mtx; //NOTE: angles in radians and negated
//OPTIMISED_BY_IVO
Matrix44 mtx=Matrix34::CreateRotationXYZ( Deg2Rad(lookat_angles),lookat);
mtx=GetTransposed44(mtx); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
Vec3d vBpos=mtx.TransformPointOLD(offset);
vectorf start, end;
ray_hit hit;
// so this pos is where we want to be
// lets move toward it slowly
Vec3d currpos = GetPos();
start.Set(mycenter.x,mycenter.y,mycenter.z);
end.Set(vBpos.x,vBpos.y,vBpos.z);
if (m_pIPhysWorld->RayWorldIntersection(start,end-start,ent_terrain | ent_static, rwi_stop_at_pierceable,&hit,1, physic))
vBpos = (Vec3d)hit.pt + (mycenter - ((Vec3d)hit.pt))*0.1f;
Vec3d finalpos;
finalpos = currpos + (vBpos - currpos)*0.1f;
SetPos(finalpos);
myangles = mycenter - finalpos;
myangles=ConvertVectorToCameraAngles(myangles);
SetAngles(myangles);
}

View File

@@ -0,0 +1,96 @@
////////////////////////////////////////////////////////////////////////////
//
// Crytek Engine Source File.
// Copyright (C), Crytek Studios, 2001.
// -------------------------------------------------------------------------
// File name: EntityCamera.h
// Version: v1.00
// Created: 14/8/2001 by Timur.
// Compilers: Visual C++ 6.0
// Description: Wraps Camera attached to the Entity.
// -------------------------------------------------------------------------
// History:
//
////////////////////////////////////////////////////////////////////////////
#ifndef __EntityCamera_h__
#define __EntityCamera_h__
#if _MSC_VER > 1000
#pragma once
#endif
#include <Cry_Camera.h>
#include <IEntitySystem.h>
#include <IConsole.h>
#include <IPhysics.h>
struct IEntity;
class CEntityCamera :
public IEntityCamera
{
public:
void SetCameraMode(const Vec3d &lookat, const Vec3d &lookat_angles, IPhysicalEntity *physic);
void Release() { delete this; };
//! Set/Get camera position.
void SetPos( const Vec3d &p ) { if (!(GetLengthSquared(p)>=0)) return; m_camera.SetPos(p); };
Vec3d GetPos() const { return m_camera.GetPos(); };
//! Set/Get camera angles.
void SetAngles( const Vec3d &p ) { m_camera.SetAngle(p); };
Vec3d GetAngles() const { return m_camera.GetAngles(); };
//! Set/Get camera FOV.
void SetFov( const float &f, const unsigned int iWidth, const unsigned int iHeight ) {
m_camera.SetFov(f);
m_camera.Init(iWidth,iHeight, f);
m_camera.Update();
};
float GetFov() const { return m_camera.GetFov(); };
//! Set/Get Matrix.
// void SetMatrix( const Matrix44 &m ) { m_camera.SetVCMatrix(m); };
Matrix44 GetMatrix() const { return m_camera.GetVCMatrixD3D9(); };
void Update() { m_camera.Update(); }
//! Access to wraped camera.
CCamera& GetCamera() { return m_camera; }
void SetCamera( const CCamera &cam ) { m_camera = cam; }
void SetThirdPersonMode( const Vec3d &pos,const Vec3d &angles,int mode,float frameTime,float range,int dangleAmmount,
IPhysicalEntity *physic, IPhysicalEntity *physicMore,
I3DEngine* p3DEngine, float safe_range=0.0f);
void SetViewOffset(float f) { m_sParam.m_viewoffset = f; };
float GetViewOffset() { return m_sParam.m_viewoffset; };
void SetCamOffset(Vec3d v) {
m_sParam.m_camoffset = m_camera.m_vOffset = v;
};
Vec3d& GetCamOffset() { return m_sParam.m_camoffset; };
void Init(IPhysicalWorld *pIPhysWorld, UINT iWidth, UINT iHeight, IConsole *pConsole);
void SetParameters(const EntityCameraParam *pParam) { memcpy(&m_sParam, pParam, sizeof(EntityCameraParam)); };
void GetParameters(EntityCameraParam *pParam) { memcpy(pParam, &m_sParam, sizeof(EntityCameraParam)); };
void SetCameraOffset(const Vec3d &offset) { m_vCameraOffset=m_camera.m_vOffset=offset; }
void GetCameraOffset(Vec3d &offset) {offset = m_vCameraOffset; }
private:
IConsole *m_pConsole;
CCamera m_camera;
EntityCameraParam m_sParam;
IPhysicalWorld *m_pIPhysWorld;
Vec3d m_vCameraOffset;
float m_fTimeIdle;
float m_fDeltaDist;
};
#endif // __EntityCamera_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
// EntityIt.cpp: implementation of the CEntityIt class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "EntityIt.h"
#ifdef _DEBUG
static char THIS_FILE[] = __FILE__;
#define DEBUG_CLIENTBLOCK new( _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define new DEBUG_CLIENTBLOCK
#endif

View File

@@ -0,0 +1,63 @@
// EntityIt.h: interface for the CEntityIt class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ENTITYIT_H__95AE38A4_7F15_4069_A97A_2F3A1F06F670__INCLUDED_)
#define AFX_ENTITYIT_H__95AE38A4_7F15_4069_A97A_2F3A1F06F670__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CEntity;
struct IEntity;
#include "EntitySystem.h"
class CEntityItMap : public IEntityIt
{
public:
CEntityItMap(EntityMap *pMap)
{
m_nRefCount=0;
m_pEntityMap = pMap;
MoveFirst();
};
bool IsEnd() { return (m_itEntityMap == m_pEntityMap->end()); };
IEntity * Next() { return IsEnd() ? NULL : (IEntity *) (* m_itEntityMap++).second; };
void MoveFirst() { m_itEntityMap = m_pEntityMap->begin(); };
void AddRef(){m_nRefCount++;}
void Release() { --m_nRefCount; if(m_nRefCount<=0){delete this;} };
protected:
int m_nRefCount;
EntityMap *m_pEntityMap;
EntityMapItor m_itEntityMap;
};
class CEntityItVec : public IEntityIt
{
public:
CEntityItVec(EntityVector *pVec)
{
m_nRefCount=0;
m_pEntityVec = pVec;
MoveFirst();
};
bool IsEnd() { return (m_itEntityVec == m_pEntityVec->end()); };
IEntity * Next() { return IsEnd() ? NULL : (*m_itEntityVec++); };
void MoveFirst() { m_itEntityVec = m_pEntityVec->begin(); };
void AddRef(){m_nRefCount++;}
void Release() { --m_nRefCount; if(m_nRefCount<=0){delete this;} };
protected:
int m_nRefCount;
EntityVector *m_pEntityVec;
EntityVectorItor m_itEntityVec;
};
#endif // !defined(AFX_ENTITYIT_H__95AE38A4_7F15_4069_A97A_2F3A1F06F670__INCLUDED_)

View File

@@ -0,0 +1,704 @@
#include "stdafx.h"
#include "Entity.h"
#include "EntitySystem.h"
#include <stream.h>
#include <IScriptSystem.h>
#include <ITimer.h>
#include <ILog.h>
#include "StreamData.h" // CStreamData_WorldPos
#ifdef _DEBUG
static char THIS_FILE[] = __FILE__;
#define DEBUG_CLIENTBLOCK new( _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define new DEBUG_CLIENTBLOCK
#endif
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//PHYSIC or POS if change the pos
//ANGLES if change
//CONTAINER stuff
//
//
bool CEntity::Write(CStream& stm,EntityCloneState *cs)
{
static CFrameProfiler profiler_EntityNetworkTraffic(GetISystem(),"Entity",PROFILE_NETWORK_TRAFFIC );
static CFrameProfiler profiler_ContainerNetworkTraffic(GetISystem(),"Container",PROFILE_NETWORK_TRAFFIC );
static CFrameProfiler profiler_PhysicsNetworkTraffic(GetISystem(),"Physics",PROFILE_NETWORK_TRAFFIC );
int nSavedBytes = 0;
int nStartBytes = stm.GetSize();
CCustomProfilerSection netTrafficEntity(&profiler_EntityNetworkTraffic,&nSavedBytes);
static CStream stmPhys;
//////////////////////////////////////
//PHYSIC OR POS
//////////////////////////////////////
bool bNeedAngles=true;
bool bAngles=false;
bool bSyncYAngle=true;
WRITE_COOKIE_NO(stm,0x55);
if (m_bIsBound)
{
stm.Write(true); // bound
stm.Write(m_idBoundTo);
stm.Write(m_cBind);
//[kirill] need to sync angles of bound entities - they can rotate around parents
Vec3d v3Angles=GetAngles( 1 );
bAngles=true;
if(cs)
{
bSyncYAngle=cs->m_bSyncYAngle;
bAngles=cs->m_bSyncAngles;
if(bAngles)
{
// if(!IsEquivalent(cs->m_v3Angles,v3Angles))
cs->m_v3Angles=v3Angles;
// else
// bAngles=false;
}
}
else
{
bAngles=true;
}
////////////////////////////////////
if(bAngles)
{
_VERIFY(stm.Write(true));
// x
stm.Write((unsigned short)((v3Angles.x*0xFFFF)*(1.f/360.f)));
// y
stm.Write(bSyncYAngle);
if(bSyncYAngle)
stm.Write((unsigned short)((v3Angles.y*0xFFFF)*(1.f/360.f))); // this component can be skipped for players
// z
stm.Write((unsigned short)((v3Angles.z*0xFFFF)*(1.f/360.f)));
}
else
{
//_VERIFY(stm.Write(false));
if (!stm.Write(false))
{
CryError("ENTITY %s (Type=%d)",GetName()?GetName():"UNNAMEDENTITY",(int)GetClassId());
}
}
}
else // not bound
{
stm.Write(false); // not bound
bool bSyncPosition=true;
if(cs)
bSyncPosition=cs->m_bSyncPosition;
bool bPhysics = HavePhysics()
&& m_physicEnabled
&& GetPhysics()->GetType()!=PE_STATIC
// [kirill] to enable DeadBodys saving - bug 429
// && GetPhysics()->GetType()!=PE_ARTICULATED
&& !IsBound();
if (bPhysics && GetPhysics()->GetType()==PE_LIVING)
{
pe_player_dynamics pd;
GetPhysics()->GetParams(&pd);
if (!pd.bActive)
{
bPhysics = false;
bSyncPosition = false;
}
}
_VERIFY(stm.Write(bPhysics));
if (bPhysics)
{
CDefaultStreamAllocator sa;
CStream stmPhys(1024, &sa);
int nSavedPhysicsBytes = 0;
int nStartPhysicsBytes = stm.GetSize();
CCustomProfilerSection netTrafficPhysics(&profiler_PhysicsNetworkTraffic,&nSavedPhysicsBytes);
float fStepBack=0.0f;
//all physical entities except the LIVING ENTITY(players) store
//the angles into the physical snapshot
if(GetPhysics()->GetType()!=PE_LIVING)
{
bNeedAngles=false;
}
if(cs && cs->m_bLocalplayer)
{
stm.Write(true);
fStepBack=cs->m_fWriteStepBack;
}
else
stm.Write(false);
stmPhys.Reset();
int nSize;
if (GetPhysics()->GetStateSnapshot(stmPhys,fStepBack,!cs || cs->m_bOffSync ? 0:ssf_checksum_only))
{
nSize = stmPhys.GetSize();
stm.WritePkd(nSize);
stm.Write(stmPhys);
}
else
stm.WritePkd(0);
//int a = stm.GetSize();
//TRACE("PHYSICS WRITE SIZE=%d %s", stm.GetSize()-a, GetName());
#ifdef DEBUG_BONES_SYNC
if (m_pCryCharInstance[0] && m_pCryCharInstance[0]->GetCharacterPhysics())
m_pCryCharInstance[0]->GetCharacterPhysics()->GetStateSnapshot(stm,0,0);
#endif
nSavedPhysicsBytes = stm.GetSize() - nStartPhysicsBytes;
}
else
{
stm.Write(bSyncPosition);
if (bSyncPosition)
{
Vec3d vPos = GetPos( false );
_VERIFY(stm.WritePkd(CStreamData_WorldPos(vPos)));
}
}
// if the entity has no physics, character might still have physics that needs to be saved (read: ropes)
if (!GetPhysics())
{
IPhysicalEntity *pCharEnt;
for (int iSlot=0; iSlot<m_nMaxCharNum; iSlot++) if (m_pCryCharInstance[iSlot])
for(int iAuxPhys=0; pCharEnt=m_pCryCharInstance[iSlot]->GetCharacterPhysics(iAuxPhys); iAuxPhys++)
pCharEnt->GetStateSnapshot(stm);
}
//////////////////////////////////////
//ANGLES
//////////////////////////////////////
WRITE_COOKIE_NO(stm,0x21);
Vec3d v3Angles=GetAngles( 1 );
if(bNeedAngles)
{
bAngles=true;
if(cs)
{
bSyncYAngle=cs->m_bSyncYAngle;
bAngles=cs->m_bSyncAngles;
if(bAngles)
{
// if(!IsEquivalent(cs->m_v3Angles,v3Angles))
cs->m_v3Angles=v3Angles;
// else
// bAngles=false;
}
}
else
{
bAngles=true;
}
}
////////////////////////////////////
if(bAngles)
{
_VERIFY(stm.Write(true)); // angles on
// x
stm.Write((unsigned short)((v3Angles.x*0xFFFF)*(1.f/360.f)));
// y
stm.Write(bSyncYAngle);
if(bSyncYAngle)
stm.Write((unsigned short)((v3Angles.y*0xFFFF)*(1.f/360.f))); // this component can be skipped for players
// z
stm.Write((unsigned short)((v3Angles.z*0xFFFF)*(1.f/360.f)));
}
else
{
_VERIFY(stm.Write(false)); // angles off
}
}
WRITE_COOKIE_NO(stm,0x90);
//////////////////////////////////////
//CONTAINER
//////////////////////////////////////
bool bContainer=false;
if (m_pContainer && m_pContainer->IsSaveable())
bContainer=true;
_VERIFY(stm.Write(bContainer));
if (bContainer)
{
int nSavedContainerBytes = 0;
int nStartContainerBytes = stm.GetSize();
CCustomProfilerSection netTrafficContainer(&profiler_ContainerNetworkTraffic,&nSavedContainerBytes);
_VERIFY(m_pContainer->Write(stm,cs));
nSavedContainerBytes = stm.GetSize() - nStartContainerBytes;
}
WRITE_COOKIE_NO(stm,0x91);
nSavedBytes = stm.GetSize() - nStartBytes;
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
bool CEntity::Read(CStream& stm,bool bNoUpdate)
{
bool bPhysics, bContainer,bBound,bSyncPosition;
// pe_type pt;
IPhysicalEntity *pPE=NULL;
IEntity *pEntBound;
//////////////////////////////////////
//PHYSIC OR POS
//////////////////////////////////////
VERIFY_ENTITY_COOKIE_NO(stm,0x55)
stm.Read(bBound);
if (bBound)
{
EntityId idBoundTo;
unsigned char cBind;
stm.Read(idBoundTo);
stm.Read(cBind);
if (!bNoUpdate)
{
if (m_bIsBound && m_idBoundTo!=idBoundTo)
{
pEntBound = m_pEntitySystem->GetEntity(m_idBoundTo);
if (pEntBound)
pEntBound->Unbind(GetId(),m_cBind);
}
if (!m_bIsBound)
{
/*
pEntBound = m_pEntitySystem->GetEntity(idBoundTo);
if (pEntBound)
{
Vec3 pos = GetPos();
// need to set position before OnBind is called (it can set some other position)
pEntBound->Bind(GetId(),cBind, false, true);
//[kirill] this is not needed - when we load bound people, relative positions will be set in OnBind
// SetPos( pos, false );
}
else
//[kirill] if parent not spown yet - do bind on PostLoad
*/
//[kirill] let's do all the bindings on PostLoad
{
m_idBoundTo = idBoundTo;
m_cBind = cBind;
}
}
}
//[kirill] read angles for bound entity
//////////////////////////////////////
//ANGLES
//////////////////////////////////////
bool bAngles;
stm.Read(bAngles);
if(bAngles)
{
Vec3d vec;
//_VERIFY(stm.Read(vec));
bool bSyncYAngle;
unsigned short x;
unsigned short y=0;
unsigned short z;
stm.Read(x);
stm.Read(bSyncYAngle);
if(bSyncYAngle)
{
stm.Read(y);
}
stm.Read(z);
vec.x=((float)x*360)*(1.f/0xFFFF);
vec.y=((float)y*360)*(1.f/0xFFFF); // this component can be skipped for players
vec.z=((float)z*360)*(1.f/0xFFFF);
// My player entity should not accept angles from network.
if (!bNoUpdate)
SetAngles(vec, false,(pPE?(pPE->GetType()==PE_LIVING?false:true):false) );
}
VERIFY_ENTITY_COOKIE_NO(stm,0x90)
}
else
{
if (m_bIsBound && !bNoUpdate)
{
pEntBound = m_pEntitySystem->GetEntity(m_idBoundTo);
if (pEntBound)
pEntBound->Unbind(GetId(),m_cBind);
}
stm.Read(bPhysics);
if (bPhysics)
{
// [anton] removed setting m_physicsEnabled, since static entities don't save physics, but they
// still have physics enabled; plus, just setting m_physicsEnabled to true or false will not actually enable/disable physics
//m_physicEnabled = true;
int nRet=0,nSize;
long nPos;
///int a = stm.GetSize();
pPE=GetPhysics();
/*if(!pPE)
{
m_pISystem->GetILog()->LogError("ENTITY %s (Type=%d) was saved with physics state, but it doesnt have one",
GetName() ? GetName():"UNNAMEDENTITY", (int)GetClassId());
if (!m_pISystem->GetIGame()->IsMultiplayer())
{
CryError("Error: ENTITY %s (Type=%d) was saved with physics state, but it doesnt have one",GetName()?GetName():"UNNAMEDENTITY",(int)GetClassId());
}
return false;
}*/
bool bHostEntity;
stm.Read(bHostEntity);
stm.ReadPkd(nSize);
nPos = stm.GetReadPos()+nSize;
if (nSize && pPE)
nRet = pPE->SetStateFromSnapshot(stm,(bHostEntity ? ssf_compensate_time_diff:0) | (bNoUpdate ? ssf_no_update:0));
stm.Seek(nPos);
if (bHostEntity && !bNoUpdate)
{
pe_params_flags pf;
pf.flagsAND = ~pef_update;
pPE->SetParams(&pf);
}
if (!nRet)
{
m_pISystem->GetILog()->LogWarning("ENTITY %s (Type=%d) has incorrect physical entity", GetName() ? GetName():"UNNAMEDENTITY", (int)GetClassId());
/*if (!m_pISystem->GetIGame()->IsMultiplayer())
{
CryError("ENTITY %s (Type=%d) has incorrect physical entity", GetName() ? GetName():"UNNAMEDENTITY", GetType());
}
return false;*/
}
#ifdef DEBUG_BONES_SYNC
if (m_pCryCharInstance[0] && m_pCryCharInstance[0]->GetCharacterPhysics())
{
pe_params_articulated_body pab;
pab.pHost = 0;
m_pCryCharInstance[0]->GetCharacterPhysics()->SetParams(&pab);
m_pCryCharInstance[0]->GetCharacterPhysics()->SetStateFromSnapshot(stm,bNoUpdate ? ssf_no_update:0);
}
#endif
//TRACE("PHYSICS READ SIZE=%d %s", stm.GetSize()-a, GetName());
}
else
{
//m_physicEnabled = false;
stm.Read(bSyncPosition);
if (bSyncPosition)
{
Vec3d vPos;
// _VERIFY(stm.Read(vPos));
#if defined(LINUX)
_VERIFY(stm.ReadPkd(*(IStreamData*)(&CStreamData_WorldPos(vPos))));
#else
_VERIFY(stm.ReadPkd(CStreamData_WorldPos(vPos)));
#endif
if (!bNoUpdate)
SetPos(vPos, false);
}
}
// if the entity has no physics, character might still have physics that needs to be saved (read: ropes)
if (!GetPhysics())
{
IPhysicalEntity *pCharEnt;
for (int iSlot=0; iSlot<m_nMaxCharNum; iSlot++) if (m_pCryCharInstance[iSlot])
for(int iAuxPhys=0; pCharEnt=m_pCryCharInstance[iSlot]->GetCharacterPhysics(iAuxPhys); iAuxPhys++)
pCharEnt->SetStateFromSnapshot(stm,bNoUpdate ? ssf_no_update:0);
}
//////////////////////////////////////
//ANGLES
//////////////////////////////////////
VERIFY_ENTITY_COOKIE_NO(stm,0x21)
bool bAngles;
stm.Read(bAngles);
if(bAngles)
{
Vec3d vec;
//_VERIFY(stm.Read(vec));
bool bSyncYAngle;
unsigned short x;
unsigned short y=0;
unsigned short z;
stm.Read(x);
stm.Read(bSyncYAngle);
if(bSyncYAngle)
{
stm.Read(y);
}
stm.Read(z);
vec.x=((float)x*360)*(1.f/0xFFFF);
vec.y=((float)y*360)*(1.f/0xFFFF); // this component can be skipped for players
vec.z=((float)z*360)*(1.f/0xFFFF);
// My player entity should not accept angles from network.
if (!bNoUpdate)
SetAngles(vec, false,(pPE?(pPE->GetType()==PE_LIVING?false:true):false) );
VERIFY_ENTITY_COOKIE_NO(stm,0x90)
}
else
{
VERIFY_ENTITY_COOKIE_NO(stm,0x90)
}
}
//////////////////////////////////////
//CONTAINER
//////////////////////////////////////
_VERIFY(stm.Read(bContainer));
if (bContainer)
{
if (!m_pContainer)
{
// since there is no check at all for errors during saving/loading,
// at least print some information if it crashes
m_pISystem->GetILog()->LogError("NO CONTAINER FOR ENTITY %s (Type=%d)",GetName()?GetName():"UNNAMEDENTITY",(int)GetClassId());
if (!m_pISystem->GetIGame()->GetModuleState(EGameMultiplayer))
{
CryError("ERROR, NO CONTAINER FOR ENTITY %s (Type=%d)",GetName()?GetName():"UNNAMEDENTITY",(int)GetClassId());
}
return false;
}
_VERIFY(m_pContainer);
_VERIFY(m_pContainer->Read(stm));
}
VERIFY_ENTITY_COOKIE_NO(stm,0x91)
for (int iSlot=0; iSlot<m_nMaxCharNum; iSlot++) if (m_pCryCharInstance[iSlot])
m_pCryCharInstance[iSlot]->ForceReskin();
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
bool CEntity::Save(CStream& stream , IScriptObject *pStream)
{
if (!Write(stream))
return false;
/*[marco] must be done before, to be consistent
with loadlevel!
Vec3d vPos;
Vec3d vAng;
if( IsBound() ) // save relative position if bound
{
vPos = GetPos(false);
vAng = GetAngles(1);
}
else
{
vPos = GetPos();
vAng = GetAngles();
}
_VERIFY(stream.Write(vPos));
_VERIFY(stream.Write(vAng));
*/
//<<add here>> for other C++ stuff to save(see what is already in Write)
//Timur[2/1/2002] Both OnSave and OnLoad must be implemented.
if (pStream && m_pSaveFunc && m_pLoadFunc)
{
m_pScriptSystem->BeginCall( m_pSaveFunc );
m_pScriptSystem->PushFuncParam(m_pScriptObject);
m_pScriptSystem->PushFuncParam(pStream);
m_pScriptSystem->EndCall();
}
// [marco] save/load state after loading/saving custom entity props from
// onload and onsave
int nState=GetStateIdx();
_VERIFY(stream.Write(nState));
return (true);
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
bool CEntity::Load(CStream& stream , IScriptObject *pStream)
{
if (!Read(stream))
return false;
/* [marco] must be done before spawnetity, to be consistent
with loadlevel!
Vec3d vPos;
SetPos(Vec3d(0,0,0));
_VERIFY(stream.Read(vPos));
SetPos(vPos);
SetAngles(Vec3d(0,0,0));
_VERIFY(stream.Read(vPos));
SetAngles(vPos);
*/
//<<add here>> for other C++ stuff to save(see what is already in Read)
//Timur[2/1/2002] Both OnSave and OnLoad must be implemented.
if (pStream && m_pSaveFunc && m_pLoadFunc)
{
m_pScriptSystem->BeginCall( m_pLoadFunc );
m_pScriptSystem->PushFuncParam(m_pScriptObject);
m_pScriptSystem->PushFuncParam(pStream);
m_pScriptSystem->EndCall();
}
// [marco] save/load state after loading/saving custom entity props from
// onload and onsave
int nState;
_VERIFY(stream.Read(nState));
GotoState(nState);
m_awakeCounter = 4; // give entity a chance to fetch the updated physics state
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
bool CEntity::LoadPATCH1(CStream& stream , IScriptObject *pStream)
{
if (!Read(stream))
return false;
/* [marco] must be done before spawnetity, to be consistent
with loadlevel!
Vec3d vPos;
SetPos(Vec3d(0,0,0));
_VERIFY(stream.Read(vPos));
SetPos(vPos);
SetAngles(Vec3d(0,0,0));
_VERIFY(stream.Read(vPos));
SetAngles(vPos);
*/
//<<add here>> for other C++ stuff to save(see what is already in Read)
//Timur[2/1/2002] Both OnSave and OnLoad must be implemented.
if (pStream && m_pSaveFunc && m_pLoadFunc)
{
//[kirill] we need to support prev version saves
//[kirill] we need to support prev version saves
if(m_pLoadPATCH1Func)
m_pScriptSystem->BeginCall( m_pLoadPATCH1Func );
else if(m_pLoadRELEASEFunc)
m_pScriptSystem->BeginCall( m_pLoadRELEASEFunc );
else
m_pScriptSystem->BeginCall( m_pLoadFunc );
m_pScriptSystem->PushFuncParam(m_pScriptObject);
m_pScriptSystem->PushFuncParam(pStream);
m_pScriptSystem->EndCall();
}
// [marco] save/load state after loading/saving custom entity props from
// onload and onsave
int nState;
_VERIFY(stream.Read(nState));
GotoState(nState);
m_awakeCounter = 4; // give entity a chance to fetch the updated physics state
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
bool CEntity::LoadRELEASE(CStream& stream , IScriptObject *pStream)
{
if (!Read(stream))
return false;
/* [marco] must be done before spawnetity, to be consistent
with loadlevel!
Vec3d vPos;
SetPos(Vec3d(0,0,0));
_VERIFY(stream.Read(vPos));
SetPos(vPos);
SetAngles(Vec3d(0,0,0));
_VERIFY(stream.Read(vPos));
SetAngles(vPos);
*/
//<<add here>> for other C++ stuff to save(see what is already in Read)
//Timur[2/1/2002] Both OnSave and OnLoad must be implemented.
if (pStream && m_pSaveFunc && m_pLoadFunc)
{
//[kirill] we need to support prev version saves
if(m_pLoadRELEASEFunc)
m_pScriptSystem->BeginCall( m_pLoadRELEASEFunc );
else
m_pScriptSystem->BeginCall( m_pLoadFunc );
m_pScriptSystem->PushFuncParam(m_pScriptObject);
m_pScriptSystem->PushFuncParam(pStream);
m_pScriptSystem->EndCall();
}
// [marco] save/load state after loading/saving custom entity props from
// onload and onsave
int nState;
_VERIFY(stream.Read(nState));
GotoState(nState);
m_awakeCounter = 4; // give entity a chance to fetch the updated physics state
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
bool CEntity::PostLoad()
{
//[kirill] bind it all now
if (!m_bIsBound && m_idBoundTo!=0)
{
IEntity *pEntBound;
pEntBound = m_pEntitySystem->GetEntity(m_idBoundTo);
if (pEntBound)
{
Vec3 pos = GetPos();
pEntBound->Bind( GetId(), m_cBind, false, true);
// SetPos( pos, false );
}
}
if (m_physic)
m_physic->PostSetStateFromSnapshot();
return true;
}

View File

@@ -0,0 +1,856 @@
//////////////////////////////////////////////////////////////////////
//
// Crytek CryENGINE Source code
//
// File:EntityRender.cpp
// Description: rendering of the entity and other relatated to visials stuff
//
// History:
// 14.04.2001:Created by Vladimir Kajalin
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <IRenderer.h>
#include "Entity.h"
#include "EntitySystem.h"
#include <ISystem.h>
#include <I3DEngine.h>
#include <ILog.h>
#include <IRenderer.h>
#include "itimer.h"
//#include "list2.h"
#if defined(_DEBUG) && !defined(LINUX)
static char THIS_FILE[] = __FILE__;
#define DEBUG_CLIENTBLOCK new( _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define new DEBUG_CLIENTBLOCK
#endif
bool CEntity::DrawEntity(const SRendParams & _EntDrawParams)
{
FUNCTION_PROFILER( m_pISystem,PROFILE_3DENGINE );
int nRecursionLevel = (int)m_pISystem->GetIRenderer()->EF_Query(EFQ_RecurseLevel) - 1;
if(nRecursionLevel==0)
{ // movement detection (if no recursion)
m_vPrevDrawCenter = m_center;
m_vPrevDrawAngles = m_angles;
m_fPrevDrawScale = m_fScale;
}
if (m_bHidden)
return 0;
if(!GetRadius())
return 0;
// to check is something was really drawn
bool bSomethingWasDrawn = false;
// some parameters will be modified
SRendParams rParms = _EntDrawParams;
// enable lightmaps if alowed
/* if(GetRndFlags()&ERF_USELIGHTMAPS && HasLightmap())
{
rParms.pLightMapInfo = GetLightmap();
rParms.m_pLMTCBuffer = GetLightmapTexCoord();
}
else*/
{
rParms.pLightMapInfo = 0;
rParms.pLMTCBuffer = 0;
}
if (!gPrecacheResourcesMode)
{
// remember last rendered frames
if(nRecursionLevel>=0 && nRecursionLevel<=1)
SetDrawFrame( m_pISystem->GetIRenderer()->GetFrameID(), nRecursionLevel );
// If entity is drawn and it is set to be update only when visible, awake it for few frames.
if (m_eUpdateVisLevel == eUT_PhysicsVisible || m_eUpdateVisLevel == eUT_Visible)
{
m_awakeCounter = 2;
}
}
// gometry bbox test
if(!(GetRndFlags()&ERF_DONOTCHECKVIS))
if(!rParms.pShadowVolumeLightSource && !(rParms.dwFObjFlags & FOB_RENDER_INTO_SHADOWMAP))
{
AABB abEntityBBox(m_vBoxMin + m_center, m_vBoxMax + m_center);
if(m_bForceBBox)
{ // if bbox was forced - make it bigger for frustum culling
Vec3d vSize = m_vBoxMax - m_vBoxMin;
abEntityBBox = AABB(m_vBoxMin - vSize + m_center, m_vBoxMax + vSize + m_center);
}
if(!m_pISystem->GetViewCamera().IsAABBVisibleFast( abEntityBBox ))
return false;
}
// entity do not cast shadows from it own light
if((m_pDynLight && !GetContainer() && rParms.pShadowVolumeLightSource) || (m_pDynLight && m_pDynLight == rParms.pShadowVolumeLightSource))
return false;
if (!gPrecacheResourcesMode)
{
// [PETAR] We need to remember the last frame id when this entity was rendered
m_nLastVisibleFrameID = m_pISystem->GetIRenderer()->GetFrameID();
// Awake entity on the first time it is seen.
if (m_bSleeping)
SetSleep(false);
}
// set entity params
rParms.fScale = GetScale();
if(!(rParms.dwFObjFlags & FOB_RENDER_INTO_SHADOWMAP))
rParms.vPos = GetPos();
rParms.vAngles = GetAngles();
//[Timur][22/3/2003]
/*
// set custom materials
if(m_lstMaterials.Count())
rParms.pMaterials = &m_lstMaterials;*/
IMatInfo * pPrevMaterial = rParms.pMaterial;
rParms.pMaterial = m_pMaterial;
if(m_bHasEnvLighting)
rParms.dwFObjFlags |= FOB_ENVLIGHTING;
if(m_arrShaderParams.Num())
rParms.pShaderParams = &m_arrShaderParams;
// calculate entity matrix once for all entity objects
Matrix44 EntityMatrix;
if(rParms.dwFObjFlags & FOB_RENDER_INTO_SHADOWMAP)
{
//EntityMatrix.Identity();
//EntityMatrix.SetTranslation(rParms.vPos);
//EntityMatrix = GetRotationZYX44(-gf_DEGTORAD*rParms.vAngles)*EntityMatrix; //NOTE: angles in radians and negated
//EntityMatrix = GetScale33( Vec3d(rParms.fScale,rParms.fScale,rParms.fScale) )*EntityMatrix;
//OPTIMISED_BY_IVO
Matrix33diag diag = Vec3(rParms.fScale,rParms.fScale,rParms.fScale); //use diag-matrix for scaling
Matrix34 rt34 = Matrix34::CreateRotationXYZ( Deg2Rad(rParms.vAngles),rParms.vPos ); //set scaling and translation in one function call
EntityMatrix = rt34*diag; //optimised concatenation: m34*t*diag
}
else
{
//EntityMatrix.Identity();
//EntityMatrix = GetTranslationMat(GetPos())*EntityMatrix;
//EntityMatrix = GetRotationZYX44(-gf_DEGTORAD*rParms.vAngles)*EntityMatrix; //NOTE: angles in radians and negated
//EntityMatrix = GetScale33( Vec3d(rParms.fScale,rParms.fScale,rParms.fScale) )*EntityMatrix;
//OPTIMISED_BY_IVO
Matrix33diag diag = Vec3(rParms.fScale,rParms.fScale,rParms.fScale); //use diag-matrix for scaling
Matrix34 rt34 = Matrix34::CreateRotationXYZ( Deg2Rad(rParms.vAngles),GetPos() ); //set scaling and translation in one function call
EntityMatrix = rt34*diag; //optimised concatenation: m34*t*diag
}
EntityMatrix = GetTransposed44(EntityMatrix); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
// lod depends on distance and size and entity settings
int nLod = max(0,(int)(rParms.fDistance*GetLodRatioNormilized()/(m_pISystem->GetI3DEngine()->GetObjectsLODRatio()*GetRadius())));
// disable scissoring for entities inside portals
if(m_pVisArea && ((IVisArea*)m_pVisArea)->IsPortal())
rParms.dwFObjFlags |= FOB_NOSCISSOR;
// draw static components
for (unsigned int k=0; k<m_objects.size(); k++)
{
CEntityObject *cb = &m_objects[k];
IStatObj * obj = cb->object;
if (!obj || !(cb->flags & ETY_OBJ_INFO_DRAW))
continue;
// render
if (cb->flags & ETY_OBJ_USE_MATRIX)
{
rParms.pMatrix = &cb->mtx;
if (!rParms.pShadowVolumeLightSource)
obj->Render(rParms,Vec3(zero), nLod);
else if(GetRndFlags()&ERF_CASTSHADOWVOLUME)
obj->RenderShadowVolumes(&rParms);
}
else
{
if (rParms.pShadowVolumeLightSource)
{
rParms.pMatrix = &cb->mtx; // use matrix calculated on prev z/ambient pass
rParms.vPos(0,0,0);
rParms.vAngles(0,0,0);
if (GetRndFlags()&ERF_CASTSHADOWVOLUME)
obj->RenderShadowVolumes(&rParms);
}
else
{
//Matrix44 mat;
//mat.Identity();
//mat=GetTranslationMat(cb->pos)*mat;
//mat=GetRotationZYX44(-gf_DEGTORAD*cb->angles)*mat; //NOTE: angles in radians and negated
//OPTIMISED_BY_IVO
Matrix44 mat=Matrix34::CreateRotationXYZ( Deg2Rad(cb->angles),cb->pos);
mat=GetTransposed44(mat); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
mat = mat*EntityMatrix;
rParms.pMatrix = &mat;
obj->Render(rParms,Vec3(zero), nLod);
// cache for shadow volumes and decals
cb->mtx = mat;
}
}
bSomethingWasDrawn = true;
}
//[Timur] Always draw container if its present.
if (m_pContainer)
{
m_pContainer->OnDraw( rParms );
bSomethingWasDrawn = true;
}
// draw animated component
for (int i=0; i<MAX_ANIMATED_MODELS; i++)
{
ICryCharInstance * cmodel = m_pCryCharInstance[i];
if (cmodel && (cmodel->GetFlags() & CS_FLAG_DRAW_MODEL))
{
if (m_pContainer)
{
//[Timur] Container Is not used Only to draw characters. This is a general modification of entity.
//[Timur] m_pContainer->OnDraw( rParms );
}
else
{
SRendParams RenderParams = rParms;
//RenderParams.vAngles = m_physic && m_physic->GetType()==PE_ARTICULATED ? Vec3d(0,0,0) : m_angles;
//RenderParams.vAngles = m_angles;
if (rParms.pShadowVolumeLightSource)
{
if(GetRndFlags()&ERF_CASTSHADOWVOLUME)
cmodel->RenderShadowVolumes(&RenderParams, (GetRndFlags()&ERF_SELFSHADOW) ? 0 : 10);
}
else
cmodel->Draw(RenderParams,Vec3(123,123,123));
}
bSomethingWasDrawn = true;
}
}
DrawEntityDebugInfo(rParms);
// restore material to original.
rParms.pMaterial = pPrevMaterial;
return bSomethingWasDrawn;
}
void CEntity::DrawEntityDebugInfo(const SRendParams & rParms)
{
// debug
if(m_pEntitySystem->m_pEntityBBoxes->GetIVal())
if (!rParms.pShadowVolumeLightSource)
{
Vec3d mins,maxs;
GetBBox(mins,maxs);
m_pISystem->GetIRenderer()->Draw3dBBox(mins,maxs);
/*for (unsigned int k=0;k<m_objects.size();k++)
{
CEntityObject *cb = &m_objects[k];
IStatObj * obj = cb->object;
if (!obj)
continue;
maxs = obj->GetBoxMax() * m_fScale;
mins = obj->GetBoxMin() * m_fScale;
m_pISystem->GetIRenderer()->Draw3dBBox(m_center+mins,m_center+maxs);
}*/
}
// debug
if(m_pEntitySystem->m_pEntityHelpers->GetIVal())
if (!m_objects.empty())
{
std::vector < CEntityObject>::iterator oi;
for (oi = m_objects.begin(); oi != m_objects.end(); oi++)
{
CEntityObject eo =(*oi);
if (!eo.object)
continue;
{
CStatObj *so = (CStatObj*)eo.object;
Vec3d pos;
//CryQuat qRot;
int idx=0;
char* name;
while( name=(char*)eo.object->GetHelperById(idx++, pos) )
{
Vec3d hSize = Vec3d( .5f, .5f, .5f );
//Matrix44 mtx;
//mtx.Identity();
//mtx=GetTranslationMat(m_center)*mtx;
//mtx=GetRotationZYX44(-gf_DEGTORAD*m_angles)*mtx; //NOTE: angles in radians and negated
//OPTIMISED_BY_IVO
Matrix44 mtx = Matrix34::CreateRotationXYZ( Deg2Rad(m_angles),m_center);
mtx=GetTransposed44(mtx); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
pos = mtx.TransformPointOLD(pos);
Vec3d mins,maxs;
mins = pos - hSize;
maxs = pos + hSize;
m_pISystem->GetIRenderer()->Draw3dBBox(mins,maxs);
m_pISystem->GetIRenderer()->DrawLabel(pos, .73f, name);
}
}
}
}
}
// set bEntityHasLights flag if there are any light sources in entity objects
void CEntity::CheckEntityLightSourcesInEntityObjects()
{
m_bEntityHasLights = false;
// Static objects
for (unsigned int k=0; k<m_objects.size(); k++)
{
CEntityObject *cb = &m_objects[k];
IStatObj * obj = cb->object;
if (!obj)// || !(cb->flags & ETY_OBJ_INFO_DRAW))
continue;
if(obj->GetLightSources(0))
m_bEntityHasLights = true;
}
// Animated components
for (int i=0;i <MAX_ANIMATED_MODELS; i++)
{
ICryCharInstance * cmodel = m_pCryCharInstance[i];
if (cmodel && cmodel->GetBoundLight(0))
m_bEntityHasLights = true;
}
}
void CEntity::ProcessEntityLightSources()
{
//prepare entity matrix
//Matrix44 EntityMatrix;
//EntityMatrix.Identity();
//EntityMatrix=GetTranslationMat(m_center)*EntityMatrix;
//EntityMatrix=GetRotationZYX44(-gf_DEGTORAD*m_angles)*EntityMatrix; //NOTE: angles in radians and negated
//EntityMatrix=GetScale33( Vec3d(m_fScale,m_fScale,m_fScale) )*EntityMatrix;
FUNCTION_PROFILER( m_pISystem,PROFILE_ENTITY );
if (!m_pEntitySystem->m_pUpdateCoocooEgg->GetIVal())
return;
Matrix33diag diag = Vec3d(m_fScale,m_fScale,m_fScale); //use diag-matrix for scaling
Matrix34 rt34 = Matrix34::CreateRotationXYZ(Deg2Rad(m_angles),m_center); //set rotation and translation in one function call
Matrix44 EntityMatrix = rt34*diag; //optimised concatenation: m34*diag
EntityMatrix = GetTransposed44(EntityMatrix); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
// entity light id
int nLightId=0;
// Static objects
for (unsigned int k=0;k<m_objects.size();k++)
{
CEntityObject *cb = &m_objects[k];
IStatObj * obj = cb->object;
if (!obj || !(cb->flags & ETY_OBJ_INFO_DRAW))
continue;
if (cb->flags & ETY_OBJ_USE_MATRIX)
{
for(int i=0; obj->GetLightSources(i); i++)
m_pISystem->GetI3DEngine()->AddDynamicLightSource(*obj->GetLightSources(i),this,nLightId++,&cb->mtx);
}
else
{
//Matrix44 mat;
//mat.Identity();
//mat=GetTranslationMat(cb->pos)*mat;
//mat=GetRotationZYX44(-gf_DEGTORAD*cb->angles)*mat; //NOTE: angles in radians and negated
//OPTIMISED_BY_IVO
Matrix44 mat = Matrix34::CreateRotationXYZ( Deg2Rad(cb->angles),cb->pos);
mat=GetTransposed44(mat); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
mat = EntityMatrix*mat;
for(int i=0; obj->GetLightSources(i); i++)
m_pISystem->GetI3DEngine()->AddDynamicLightSource(*obj->GetLightSources(i),this,nLightId++,&mat);
}
}
// Animated objects
for (int i=0;i<MAX_ANIMATED_MODELS;i++)
{
ICryCharInstance * cmodel = m_pCryCharInstance[i];
if (cmodel && (cmodel->GetFlags() & CS_FLAG_DRAW_MODEL) && cmodel->GetBoundLight(0))
{
assert(!IsStatic());
Matrix44 LightMatrix;
if (m_pContainer)
{ // use character angles and entity pos
//LightMatrix.Identity();
//LightMatrix=GetTranslationMat(m_center)*LightMatrix;
//LightMatrix=GetRotationZYX44(-gf_DEGTORAD*GetAngles())*LightMatrix; //NOTE: angles in radians and negated
//OPTIMISED_BY_IVO
LightMatrix = Matrix34::CreateRotationXYZ( Deg2Rad(GetAngles()),m_center);
LightMatrix=GetTransposed44(LightMatrix); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
}
else
LightMatrix = EntityMatrix;
for(int i=0; cmodel->GetBoundLight(i); i++)
m_pISystem->GetI3DEngine()->AddDynamicLightSource(*cmodel->GetBoundLight(i),this,nLightId++,&LightMatrix);
}
}
}
void CEntity::SetEntityStatObj( unsigned int nSlot, IStatObj * pStatObj, Matrix44 * pMatrix )
{
if(nSlot>=0 /*&& nSlot<m_objects.size()*/) //PETAR: changed to be able to SET entity objects, not just replace them
{
if (nSlot >= m_objects.size())
m_objects.resize(nSlot+1);
if(pMatrix)
{
m_objects[nSlot].mtx = *pMatrix;
m_objects[nSlot].flags |=ETY_OBJ_USE_MATRIX;
}
else
m_objects[nSlot].flags &=~ETY_OBJ_USE_MATRIX;
// Release previous object.
if (m_objects[nSlot].object != pStatObj && m_objects[nSlot].object != NULL)
m_pISystem->GetI3DEngine()->ReleaseObject(m_objects[nSlot].object);
m_objects[nSlot].object = pStatObj;
}
}
IStatObj * CEntity::GetEntityStatObj( unsigned int nSlot, Matrix44* pMatrix, bool bReturnOnlyVisible)
{
if(nSlot>=0 && nSlot<m_objects.size() && (!bReturnOnlyVisible || m_objects[nSlot].flags & ETY_OBJ_INFO_DRAW))
{
if(pMatrix)
{
if(m_objects[nSlot].flags & ETY_OBJ_USE_MATRIX)
*pMatrix = m_objects[nSlot].mtx;
else
{
//OPTIMISED_BY_IVO
// make object matrix
Matrix33diag diag = Vec3(GetScale(),GetScale(),GetScale());
Matrix34 rt34 = Matrix34::CreateRotationXYZ( Deg2Rad(GetAngles()),GetPos() );
Matrix44 EntityMatrix = rt34*diag;
EntityMatrix = GetTransposed44(EntityMatrix);
Matrix44 ObjMatrix = Matrix34::CreateRotationXYZ( Deg2Rad(m_objects[nSlot].angles),m_objects[nSlot].pos);
ObjMatrix = GetTransposed44(ObjMatrix); //TODO: remove this after E3 and use Matrix34 instead of Matrix44
*pMatrix = ObjMatrix*EntityMatrix;
}
}
return m_objects[nSlot].object;
}
return 0;
}
ICryCharInstance* CEntity::GetEntityCharacter( unsigned int nSlot, Matrix44* pMatrix )
{
if(nSlot>=0 && nSlot<MAX_ANIMATED_MODELS)
{
if(pMatrix)
assert(0); // todo: entity should have matrix calculated once in entity Update()
return m_pCryCharInstance[nSlot];
}
return 0;
}
void CEntity::InitEntityRenderState()
{
if(!m_pEntityRenderState)
{
m_pEntityRenderState = m_pISystem->GetI3DEngine()->MakeEntityRenderState();
CheckEntityLightSourcesInEntityObjects();
}
}
bool CEntity::IsEntityHasSomethingToRender()
{
bool bItHas = false;
// test static component
for (unsigned int k=0; k<m_objects.size(); k++)
{
CEntityObject *cb = &m_objects[k];
IStatObj * obj = cb->object;
if (!obj || !(cb->flags & ETY_OBJ_INFO_DRAW))
continue;
bItHas = true;
break;
}
// test animated component
for (int i=0; i<MAX_ANIMATED_MODELS; i++)
{
ICryCharInstance * cmodel = m_pCryCharInstance[i];
if (cmodel && (cmodel->GetFlags() & CS_FLAG_DRAW_MODEL))
{
bItHas = true;
break;
}
}
return bItHas;
}
//////////////////////////////////////////////////////////////////////////
void CEntity::PlayParticleSoundEffects( IParticleEffect *pEffect )
{
}
// vlad's todo: move ParticleEmitter into 3dengine
int CEntity::CreateEntityParticleEmitter(int nSlotId, const ParticleParams & PartParams,
float fSpawnPeriod,Vec3d vOffSet,Vec3d vDir,
IParticleEffect *pEffect,float fScale)
{
if(nSlotId>16)
{
m_pISystem->GetILog()->Log("Error: CEntity::CreateEntityParticleEmitter: nSlotId=%d is out of range", nSlotId);
return -1;
}
if (!m_pParticleEmitters)
m_pParticleEmitters = new PatricleEmitters;
m_bUpdateEmitters = true;
if ((int)m_pParticleEmitters->size() <= nSlotId)
{
m_pParticleEmitters->resize(nSlotId+1);
}
EntPartEmitter &emitter = (*m_pParticleEmitters)[nSlotId];
emitter.pEmitter = m_pISystem->GetI3DEngine()->CreateParticleEmitter();
if (!pEffect)
{
emitter.pEmitter->SetParams( PartParams );
}
else
{
emitter.pEmitter->SetEffect( pEffect );
}
emitter.fScale = fScale;
emitter.vOffset = vOffSet;
emitter.vDir = vDir;
emitter.fSpawnPeriod = fSpawnPeriod;
emitter.pEffect = pEffect;
// Override spawn period.
emitter.pEmitter->SetSpawnPeriod( fSpawnPeriod );
emitter.pEmitter->SetUnlimitedLife(); // Unlimited lifetime.
emitter.pEmitter->SetEntity( this );
// Assign material only if entity doesnt contain any geometry.
if (GetNumObjects() == 0 && m_nMaxCharNum == 0)
emitter.pEmitter->SetMaterial( m_pMaterial );
InitEntityRenderState();
return nSlotId;
}
//////////////////////////////////////////////////////////////////////////
void CEntity::DeleteParticleEmitter(int nId)
{
if(m_pParticleEmitters && nId >= 0 && nId < (int)m_pParticleEmitters->size())
{
EntPartEmitter &emitter = (*m_pParticleEmitters)[nId];
if (emitter.pEmitter)
m_pISystem->GetI3DEngine()->DeleteParticleEmitter( emitter.pEmitter );
emitter.pEmitter = 0;
emitter.pEffect = 0;
}
}
//////////////////////////////////////////////////////////////////////////
void CEntity::UpdateParticleEmitters( SEntityUpdateContext &ctx )
{
if(!m_pParticleEmitters)
return;
FUNCTION_PROFILER( m_pISystem,PROFILE_ENTITY );
//[Timur]
//@FIXME !!!! this must not be here.
//@HACK
m_pISystem->GetI3DEngine()->RegisterEntity(this);
// if(GetEntityVisArea() && !IsEntityAreasVisible())
// return;
//float fDist = GetDistance(m_pISystem->GetViewCamera().GetPos(), GetPos());
float fCurrTime = ctx.fCurrTime;
// Keep emitters alive.
for (int i=0; i < (int)m_pParticleEmitters->size(); i++)
{
EntPartEmitter &emitter = (*m_pParticleEmitters)[i];
if (emitter.pEmitter)
{
// calculate entity rotation matrix
Matrix44 EntityMatrix;
EntityMatrix.SetIdentity();
//EntityMatrix.RotateMatrix_fix(GetAngles());
EntityMatrix=Matrix44::CreateRotationZYX(-gf_DEGTORAD*GetAngles())*EntityMatrix; //NOTE: angles in radians and negated
Vec3 pos = GetPos() + EntityMatrix.TransformVectorOLD( emitter.vOffset );
Vec3 dir = EntityMatrix.TransformVectorOLD( emitter.vDir );
//
emitter.pEmitter->SetPos( pos,dir,emitter.fScale );
// Assign material only if entity doesnt contain any geometry.
if (GetNumObjects() == 0 && m_nMaxCharNum == 0)
{
if (m_pMaterial)
emitter.pEmitter->SetMaterial( m_pMaterial );
else
emitter.pEmitter->SetMaterial( NULL );
}
}
}
//[kirill] this vould stop some entities with eUT_Always from being updated - so commented it out
// on first succesfull update - enable potential visibility check
// SetUpdateVisLevel(eUT_PotVisible);
}
bool CEntity::IsEntityAreasVisible()
{
if(!GetEntityRS())
return false;
IVisArea * pArea = (IVisArea *)m_pVisArea;
// test area vis
if(pArea && pArea->GetVisFrameId() == m_pISystem->GetIRenderer()->GetFrameID())
return true; // visible
if(m_pDynLight && !(m_pDynLight->m_Flags & DLF_THIS_AREA_ONLY)) // tmp hack, should be set from the script
{ // test neighbours
IVisArea * Areas[64];
int nCount = pArea->GetVisAreaConnections(Areas,64);
for (int i=0; i<nCount; i++)
if(Areas[i]->GetVisFrameId() == m_pISystem->GetIRenderer()->GetFrameID())
return true; // visible
}
return false; // not visible
}
bool CEntity::CheckUpdateVisLevel( SEntityUpdateContext &ctx,EEntityUpdateVisLevel eUpdateVisLevel )
{
switch(eUpdateVisLevel)
{
case eUT_Always: // always update
return true;
case eUT_InViewRange: // update if distance is less than camera view distance
{
bool bVisible = false;
if (ctx.nFrameID - GetDrawFrame() < MAX_FRAME_ID_STEP_PER_FRAME)
bVisible = true; // visible
float fDistSquared = GetLengthSquared( ctx.vCameraPos - GetPos() );
if (m_fUpdateRadius > 0)
{
// Within update radius.
if (fDistSquared < m_fUpdateRadius*m_fUpdateRadius)
return bVisible; // Update, because it is visible and within update radius.
else
return false; // Never update entity outside update radius.
}
return bVisible || fDistSquared < ctx.fMaxViewDistSquared;
}
case eUT_PotVisible: // update if entity visarea or terrain sector is visible
{
if (m_fUpdateRadius > 0)
{
// Within update radius.
float fDistSquared = GetLengthSquared( ctx.vCameraPos - GetPos() );
if (fDistSquared > m_fUpdateRadius*m_fUpdateRadius)
return false; // Out of update radius.
}
if (ctx.nFrameID - GetDrawFrame() < MAX_FRAME_ID_STEP_PER_FRAME)
return true; // visible
float fDistSquared = GetLengthSquared( ctx.vCameraPos - GetPos() );
if (fDistSquared > ctx.fMaxViewDistSquared)
return false; // not visible
float fAddRadius = m_fUpdateRadius;
// tmp hack for lights, will be removed when static light concept will be used
if (m_pDynLight && !(m_pDynLight->m_Flags & DLF_THIS_AREA_ONLY) && m_pDynLight->m_Origin!=Vec3d(0,0,0))
fAddRadius += 8;
return m_pISystem->GetI3DEngine()->IsPotentiallyVisible(this,fAddRadius);
}
case eUT_Visible: // update if visible
if (ctx.nFrameID - GetDrawFrame() < MAX_FRAME_ID_STEP_PER_FRAME)
{
if (m_fUpdateRadius > 0)
{
float fDistSquared = GetLengthSquared( ctx.vCameraPos - GetPos() );
// Within update radius.
if (fDistSquared < m_fUpdateRadius*m_fUpdateRadius)
return true; // Update, because it is visible and within update radius.
}
else
return true; // Update, because it is visible and no update radius specified.
}
break;
case eUT_Never: // newer update
return false;
case eUT_Physics: // Only update due to physics.
case eUT_PhysicsVisible:
case eUT_Unconditional:
return true;
}
// Not update.
return false;
}
//////////////////////////////////////////////////////////////////////////
void CEntity::SetMaterial( IMatInfo *pMatInfo )
{
m_pMaterial = pMatInfo;
if(m_pMaterial)
m_pMaterial->SetFlags(m_pMaterial->GetFlags()|MIF_WASUSED);
}
//////////////////////////////////////////////////////////////////////////
IMatInfo* CEntity::GetMaterial() const
{
return m_pMaterial;
}
//////////////////////////////////////////////////////////////////////////
void CEntity::PreloadInstanceResources(Vec3d vPrevPortalPos, float fPrevPortalDistance, float fTime)
{
if(!GetEntityStatObj(0) || !GetEntityStatObj(0)->GetLeafBuffer())
return;
float fDistance = fPrevPortalDistance + GetPos().GetDistance(vPrevPortalPos);
float fMaxViewDist = GetMaxViewDist();
if(fDistance<fMaxViewDist && fDistance<m_pISystem->GetViewCamera().GetZMax())
{
for (unsigned int k=0; k<m_objects.size(); k++)
{
CEntityObject *cb = &m_objects[k];
IStatObj * obj = cb->object;
if (obj && (cb->flags & ETY_OBJ_INFO_DRAW))
obj->PreloadResources(fDistance,fTime,0);
}
for (int i=0; i<MAX_ANIMATED_MODELS; i++)
{
ICryCharInstance * cmodel = m_pCryCharInstance[i];
if (cmodel && (cmodel->GetFlags() & CS_FLAG_DRAW_MODEL))
cmodel->PreloadResources ( fDistance, 1.f, 0 );
}
}
}
float CEntity::GetMaxViewDist()
{
I3DEngine * p3DEngine = m_pISystem->GetI3DEngine();
return max(p3DEngine->GetObjectsMinViewDist(),
GetRenderRadius()*p3DEngine->GetObjectsViewDistRatio()*GetViewDistRatioNormilized());
}
void CEntity::SetShaderFloat(const char *Name, float Val)
{
char name[128];
int i;
strcpy(name, Name);
strlwr(name);
for (i=0; i<m_arrShaderParams.Num(); i++)
{
if (!strcmp(name, m_arrShaderParams[i].m_Name))
break;
}
if (i == m_arrShaderParams.Num())
{
SShaderParam pr;
strncpy(pr.m_Name, name, 32);
m_arrShaderParams.AddElem(pr);
}
m_arrShaderParams[i].m_Type = eType_FLOAT;
m_arrShaderParams[i].m_Value.m_Float = Val;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,254 @@
//////////////////////////////////////////////////////////////////////
//
// Crytek CryENGINE Source code
//
// File:EntitySystem.h
//
// History:
// -March 07,2001:Originally created by Marco Corbetta
// -: modified by everyone
//
//
//////////////////////////////////////////////////////////////////////
#ifndef ENTITYSYSTEM_H
#define ENTITYSYSTEM_H
#if _MSC_VER > 1000
# pragma once
#endif
#include <map>
#include <set>
#include <vector>
#include <IEntitySystem.h>
#include "Entity.h"
#include "EntityCamera.h"
#include "IDGenerator.h"
#include <ISystem.h>
//#include "EntityIt.h"
class CEntity;
class CStaticObject;
class CStatObjInfo;
class CEntityClonesMgr;
#ifdef WIN64
// workaround for Amd64 compiler
#include <map>
#define hash_map map
#else
#if defined(LINUX)
#include <ext/hash_map>
#include "ientityrenderstate.h"
#else
#include <hash_map>
#endif
#endif
#if defined(LINUX)
typedef __gnu_cxx::hash_map<EntityId,CEntity*> EntityMap;
typedef __gnu_cxx::hash_map<EntityId,CEntity*>::iterator EntityMapItor;
#else
typedef std::hash_map<EntityId,CEntity*> EntityMap;
typedef EntityMap::iterator EntityMapItor;
#endif
typedef std::vector<CEntity*> EntityVector;
typedef EntityVector::iterator EntityVectorItor;
typedef std::set<int> EntityIdSet;
typedef EntityIdSet::iterator EntityIdSetItor;
typedef std::list<CEntityObject*> EntityObjectList;
typedef std::list<IEntitySystemSink *> SinkList;
//typedef std::set<CEntityClonesMgr *> EntityClonesMgrSet;
//typedef EntityClonesMgrSet::iterator EntityClonesMgrSetItor;
/*
struct near_info_struct
{
near_info_struct() {model=0;}
ICryCharInstance * model;
Vec3d pos, angles;
list2<CStaticObject> * _stat_objects;
list2<CStaticObject> * _stat_shadows;
list2<CStaticObject> * _stat_shadows_plus;
IEntity * o;
float ent_distance;
};*/
//////////////////////////////////////////////////////////////////////////
struct SEntityTimerEvent
{
int entityId;
int timerId;
};
//////////////////////////////////////////////////////////////////////
class CEntitySystem : public IEntitySystem
{
void InsertEntity( EntityId id,CEntity *pEntity );
// void GenerateUniqId( CEntityDesc &ed ) { ed.id = m_LastId++; }
void DeleteEntity( IEntity *entity );
// void GarbageCollectorCycle();
public:
CEntitySystem(ISystem *pSystem);
~CEntitySystem();
bool Init(ISystem *pSystem);
void Release(); // Close entity system, free resources.
void Reset(); // Reset whole entity system, and destroy all entities.
void SetSink( IEntitySystemSink *pSink );
void RemoveSink( IEntitySystemSink *pSink );
void OnBind(EntityId id,EntityId child,unsigned char param);
void OnUnbind(EntityId id,EntityId child,unsigned char param);
//void SetMyPlayer(unsigned short id ){ m_wPlayerID = id;}
//unsigned short GetMyPlayer() const {return m_wPlayerID;}
IScriptSystem *GetScriptSystem() { return m_pScriptSystem; }
IEntity* SpawnEntity( CEntityDesc &ed,bool bAutoInit=true );
bool InitEntity( IEntity* pEntity,CEntityDesc &ed );
// Safely remove entity; Call to this function will not immediatly remove entity;
// Entity will only be removed after update call unless bRemoveNow set.
void RemoveEntity( EntityId entity,bool bRemoveNow );
IEntityCamera * CreateEntityCamera();
// near_info_struct * GetWeaponInfo() { return &m_WeaponInfo; };
IEntity* GetEntity( EntityId id ); // Get entity from id.
IEntity* GetEntity(const char *sEntityName);
EntityId FindEntity( const char *name ) const; // Find first entity with given name.
int GetNumEntities() const;
//void GetEntities( std::vector<IEntity*> &entities ) const;
IEntityIt * GetEntityIterator();
IEntityIt * GetEntityInFrustrumIterator( bool bFromPrevFrame=false );
void GetEntitiesInRadius( const Vec3d &origin,float radius,std::vector<IEntity*> &entities,int physFlags ) const;
void Update();
void UpdateTimers();
// Sets new entity timer event.
void PauseTimers(bool bPause,bool bResume=false);
void RemoveTimerEvent( EntityId id );
void AddTimerEvent( int delayTimeMillis,SEntityTimerEvent &event );
void EnableClient(bool bEnable)
{
m_bClient=bEnable;
}
void EnableServer(bool bEnable)
{
m_bServer=bEnable;
}
inline bool ClientEnabled(){return m_bClient;}
inline bool ServerEnabled(){return m_bServer;}
void GetMemoryStatistics(ICrySizer *pSizer);
virtual bool IsIDUsed(EntityId nID);
void ReleaseMark(unsigned int id);
void ResetEntities(void);
virtual void SetDynamicEntityIdMode( const bool bActivate );
void SetDefaultEntityUpdateLevel( EEntityUpdateVisLevel eDefault) { m_eDefaultUpdateLevel = eDefault;}
// near_info_struct m_WeaponInfo;
void SetPrecacheResourcesMode( bool bPrecaching );
// CIDGenerator* GetIDGenerator() { return &m_EntityIDGenerator; }
bool IsDynamicEntityId( EntityId id ) { return m_EntityIDGenerator.IsDynamicEntityId( id ); }
void MarkId( EntityId id ) { m_EntityIDGenerator.Mark( id ); }
void ClearId( EntityId id ) { m_EntityIDGenerator.Remove( id ); }
private:
// Return true if updated.
void UpdateEntity(CEntity *ce,SEntityUpdateContext &ctx);
//////////////////////////////////////////////////////////////////////////
// Variables.
//////////////////////////////////////////////////////////////////////////
bool m_bDynamicEntityIdMode; //!< default=false (editor), true=game mode
CIDGenerator m_EntityIDGenerator;
ISystem * m_pISystem;
EEntityUpdateVisLevel m_eDefaultUpdateLevel;
SinkList m_lstSinks;
EntityMap m_mapEntities;
EntityVector m_vEntitiesInFrustrum;
//[kirill] - need this one to get visible entities on update of some entity - so we don't depend on update's order
EntityVector m_vEntitiesInFrustrumPrevFrame;
// unsigned short m_wPlayerID;
IScriptSystem * m_pScriptSystem;
//////////////////////////////////////////////////////////////////////////
// Entity timers.
//////////////////////////////////////////////////////////////////////////
typedef std::multimap<int,SEntityTimerEvent> EntityTimersMap;
EntityTimersMap m_timersMap;
std::vector<SEntityTimerEvent> m_currentTriggers;
bool m_bTimersPause;
int m_nStartPause;
//////////////////////////////////////////////////////////////////////////
public:
struct ITimer *m_pTimer;
ICVar *m_pCharacterIK;
ICVar *m_pShowEntityBBox;
ICVar *m_pShowHelpers;
ICVar *m_pProfileEntities;
ICVar *m_pUpdateInvisibleCharacter;
ICVar *m_pUpdateBonePositions;
ICVar *m_pUpdateScript;
ICVar *m_pUpdateTimer;
ICVar *m_pDebugTimer;
ICVar *m_pUpdateCamera;
ICVar *m_pUpdatePhysics;
ICVar *m_pUpdateAI;
ICVar *m_pUpdateEntities;
ICVar *m_pUpdateCollision;
ICVar *m_pUpdateCollisionScript;
ICVar *m_pUpdateContainer;
ICVar *m_pUpdateCoocooEgg;
ICVar *m_pPiercingCamera;
ICVar *m_pVisCheckForUpdate;
ICVar *m_pEntityBBoxes;
ICVar *m_pEntityHelpers;
ICVar *m_pOnDemandPhysics;
ICVar *m_pMinImpulseVel;
ICVar *m_pImpulseScale;
ICVar *m_pMaxImpulseAdjMass;
ICVar *m_pSplashThreshold;
ICVar *m_pSplashTimeout;
ICVar *m_pHitCharacters;
ICVar *m_pHitDeadBodies;
ICVar *m_pEnableCloth;
ICVar *m_pCharZOffsetSpeed;
bool m_bClient;
bool m_bServer;
int m_nGetEntityCounter;
// EntityClonesMgrSet m_setEntityClonesMgrs;
};
//////////////////////////////////////////////////////////////////////////
// Precache resources mode state.
//////////////////////////////////////////////////////////////////////////
extern bool gPrecacheResourcesMode;
#endif //Entitysystem.h

View File

@@ -0,0 +1,98 @@
//////////////////////////////////////////////////////////////////////
//
// Game Source Code
//
// File: IDGenerator.cpp
// Description: ID Generator class.
//
// History:
// - 08/06/2001: Created by Alberto Demichelis
// - 12/03/2003: Martin Mittring made distinction between static and dynamic ids
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "IDGenerator.h"
#ifdef _DEBUG
static char THIS_FILE[] = __FILE__;
#define DEBUG_CLIENTBLOCK new( _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define new DEBUG_CLIENTBLOCK
#endif
///////////////////////////////////////////////
CIDGenerator::CIDGenerator()
{
m_vUsedIDs.resize(0xFFFF+1,false);
Reset();
}
///////////////////////////////////////////////
CIDGenerator::~CIDGenerator()
{
}
///////////////////////////////////////////////
void CIDGenerator::Reset()
{
BitVectorItor itor=m_vUsedIDs.begin();
int nSize=m_vUsedIDs.size();
int n=0;
while(n<nSize)
{
m_vUsedIDs[n] = false;
n++;
}
//memset(m_vUsedIDs,0,sizeof(m_vUsedIDs));
m_vUsedIDs[0] = true;
}
///////////////////////////////////////////////
WORD CIDGenerator::GetNewDynamic()
{
WORD i = 0xffff; // to be able to have different ID range for dynamically generated entities
while (m_vUsedIDs[i])
--i; // WORD is cycling through the whole buffer
m_vUsedIDs[i] = true;
return i;
}
bool CIDGenerator::IsDynamicEntityId( WORD nID )
{
return (nID&0x8000)!=0;
}
///////////////////////////////////////////////
WORD CIDGenerator::GetNewStatic()
{
WORD i = 0; // to be able to have different ID range for dynamically generated entities
while(m_vUsedIDs[i])
++i; // WORD is cycling through the whole buffer
m_vUsedIDs[i] = true;
return i;
}
///////////////////////////////////////////////
void CIDGenerator::Remove(WORD nID)
{
assert(m_vUsedIDs[nID]==true);
m_vUsedIDs[nID] = false;
}
////////////////////////////////////////////
void CIDGenerator::Mark(WORD nID)
{
assert(m_vUsedIDs[nID]==false);
m_vUsedIDs[nID] = true;
}
bool CIDGenerator::IsUsed(WORD nID)
{
return m_vUsedIDs[nID];
}

View File

@@ -0,0 +1,57 @@
//////////////////////////////////////////////////////////////////////
//
// Game Source Code
//
// File: IDGenerator.h
// Description: ID Generator class.
//
// History:
// - August 6, 2001: Created by Alberto Demichelis
//
//////////////////////////////////////////////////////////////////////
#ifndef GAME_IDGENERATOR_H
#define GAME_IDGENERATOR_H
#if _MSC_VER > 1000
# pragma once
#endif
#include <vector>
typedef std::vector<bool> BitVector; // depending on STL implementation this might be a bit vector or a byte vector
typedef BitVector::iterator BitVectorItor;
class CIDGenerator
{
public:
//! constructor
CIDGenerator();
//! destructor
virtual ~CIDGenerator();
//!
void Reset();
//! just a different range, might return a static id if there is no dynamic left (very unlikely)
WORD GetNewDynamic();
//! just a different range, might return a static id if there is no dynamic left (very unlikely)
WORD GetNewStatic();
//!
void Remove(WORD nID);
//!
void Mark(WORD nID);
//!
unsigned sizeofThis()const
{
return sizeof(*this) + sizeof(m_vUsedIDs[0]) * m_vUsedIDs.size();
}
//!
bool IsUsed(WORD nID);
//!
static bool IsDynamicEntityId( WORD nID );
private: // ------------------------------------------------------------
BitVector m_vUsedIDs; //!<
};
#endif // GAME_IDGENERATOR_H

750
CryEntitySystem/LipSync.cpp Normal file
View File

@@ -0,0 +1,750 @@
//////////////////////////////////////////////////////////////////////
//
// Game Source Code
//
// File: LipSync.cpp
// Description: Class to manage and compute all LipSync- and FacialExpression-Features.
//
// History:
// - December 6, 2001: Created by Lennert Schneider
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <ISound.h>
#include <ITimer.h>
#include <CryCharMorphParams.h>
#include <ICryPak.h>
#include "LipSync.h"
#include "RandomExprLoadSink.h"
#include <StringUtils.h> // for strnstr
#include <IScriptSystem.h>
#include <IXGame.h>
#define MAGPIE_SUPPORT
#define LIPSYNC_PLAYAHEAD 0
#define LIPSYNC_AMP 0.7f
#define LIPSYNC_FADEIN 0.2f
#define LIPSYNC_FADEOUT 0.2f
#define LIPSYNC_CROSSFADE 0.2f
//////////////////////////////////////////////////////////////////////////
//! Reports a Game Warning to validator with WARNING severity.
inline void GameWarning( const char *format,... )
{
if (!format)
return;
char buffer[MAX_WARNING_LENGTH];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
CryWarning( VALIDATOR_MODULE_GAME,VALIDATOR_WARNING,buffer );
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLipSync::CLipSync()
{
m_pSystem=NULL;
m_pSoundSystem=NULL;
m_pScriptSystem=NULL;
m_pStreamEngine=NULL;
m_pLog=NULL;
m_pPak=NULL;
m_pTimer=NULL;
m_pSound=NULL;
m_pEntity=NULL;
m_pCharInst=NULL;
m_pSink=NULL;
m_bUnload=false;
m_pAITable=NULL;
}
CLipSync::~CLipSync()
{
if (m_pSound)
m_pSound->RemoveEventListener(this);
//if(m_pLog) // if Init wasn't successful m_pLog might be 0
// m_pLog->LogToFile("\006~CLipSync(%p)(stream %p)", this, (IReadStream*)m_pReadStream);
}
bool CLipSync::Init(ISystem *pSystem, IEntity *pEntity)
{
UnloadDialog();
m_pSystem=pSystem;
if (!m_pSystem)
return false;
m_pSoundSystem=pSystem->GetISoundSystem();
if (!m_pSoundSystem)
return false;
m_pScriptSystem=pSystem->GetIScriptSystem();
if (!m_pScriptSystem)
return false;
m_pStreamEngine=pSystem->GetStreamEngine();
if (!m_pStreamEngine)
return false;
m_pLog=pSystem->GetILog();
if (!m_pLog)
return false;
m_pTimer=pSystem->GetITimer();
if (!m_pTimer)
return false;
m_pPak=pSystem->GetIPak();
if (!m_pPak)
return false;
m_pSound=NULL;
m_pEntity=pEntity;
if (!m_pEntity)
return false;
IEntityCharacter *pEntChar=m_pEntity->GetCharInterface();
if (!pEntChar)
return false;
m_pCharInst=pEntChar->GetCharacter(0);
if (!m_pCharInst)
return false;
return true;
}
void CLipSync::Release()
{
UnloadRandomExpressions();
UnloadDialog();
delete this;
}
bool CLipSync::LoadRandomExpressions(const char *pszExprScript, bool bRaiseError)
{
if ((!m_pScriptSystem) || (!m_pSoundSystem) || (!m_pCharInst))
return false; // not initialized
if (!pszExprScript)
return false;
// Check if this expression is already loaded.
if (m_loadedExpression == pszExprScript)
return true;
// unloacd all expressions.
UnloadRandomExpressions();
if (!strlen(pszExprScript))
return true;
ICryCharModel *pModel=m_pCharInst->GetModel();
assert(pModel);
IAnimationSet *pAnimSet=pModel->GetAnimationSet();
assert(pAnimSet);
// parse random-expressions
if (m_pScriptSystem->ExecuteFile(pszExprScript, true, false))
{
m_loadedExpression = pszExprScript;
// Get only filename from path. use it as global key to expressions table.
char filename[_MAX_FNAME];
_splitpath( pszExprScript,NULL,NULL,filename,NULL );
_SmartScriptObject pObj(m_pScriptSystem, true);
if (m_pScriptSystem->GetGlobalValue( filename,pObj ))
{
CRandomExprLoadSink LoadSink(bRaiseError, m_pScriptSystem, &pObj, pAnimSet, &m_vecExprPatterns);
pObj->Dump(&LoadSink);
}
else
{
GameWarning( "LipSync expression script %s does not contain table %s",pszExprScript,filename );
}
}
else
{
GameWarning( "LipSync expression script %s filed to load",pszExprScript );
}
return true;
}
bool CLipSync::UnloadRandomExpressions()
{
m_vecExprPatterns.clear();
return true;
}
void CLipSync::RemoveExtension(char *pszFilename)
{
char *pDot=strstr(pszFilename, ".");
if (!pDot)
return; // no extension...
pszFilename[pDot-pszFilename]=0;
}
void CLipSync::AddExtension(char *pszFilename, const char *pszExtension)
{
strcat(pszFilename, pszExtension);
}
void CLipSync::CheckIfDialogLoaded()
{
if (m_bSoundFileLoaded && m_bSyncFileLoaded)
{
if (m_pSink)
m_pSink->OnDialogLoaded(this);
TRACE("DIALOG LOADING SUCEEDED");
}
}
void CLipSync::LoadFailed()
{
if (m_pSink)
m_pSink->OnDialogFailed(this);
TRACE("DIALOG LOADING FAILED");
}
//////////////////////////////////////////////////////////////////////////
void CLipSync::OnSoundEvent( ESoundCallbackEvent event,ISound *pSound )
{
switch(event)
{
case SOUND_EVENT_ON_LOADED:
m_pSound->RemoveEventListener(this);
m_bSoundFileLoaded=true;
CheckIfDialogLoaded();
break;
case SOUND_EVENT_ON_LOAD_FAILED:
m_pSound->RemoveEventListener(this);
m_bUnload=true;
break;
}
}
void CLipSync::SyncFileLoaded()
{
//m_pLog->LogToFile("\006CLipSync(%p)::SyncFileLoaded", this);
m_pReadStream=NULL;
m_bSyncFileLoaded=true;
CheckIfDialogLoaded();
}
void CLipSync::SyncFileLoadFailed()
{
//m_pLog->LogToFile("\006CLipSync(%p)::SyncFileLoadFailed", this);
m_pReadStream=NULL;
// for now we also want the dialog to succeed without lip-syncing so regardless if the sync-load fails or not... we proceed
m_bSyncFileLoaded=true;
CheckIfDialogLoaded();
//LoadFailed();
//UnloadDialog();
}
void CLipSync::AbortLoading()
{
#if !defined(LINUX64)
if (m_pReadStream!=NULL)
#else
if (m_pReadStream!=0)
#endif
{
//m_pLog->LogToFile("\006CLipSync(%p)::AbortLoading", this);
m_pReadStream->Abort();
m_pReadStream=NULL;
LoadFailed();
}
}
#define PUSH_DATA(_nIdx) \
{ \
if (Data[_nIdx].fAmp) \
{ \
Data[_nIdx].nLen=(int)fLen[_nIdx]; \
m_vecData[_nIdx].push_back(Data[_nIdx]); \
Data[_nIdx].fAmp=0.0f; \
} \
fLen[_nIdx]=0.0f; \
}
using namespace CryStringUtils; // for strnstr
//////////////////////////////////////////////////////////////////////////
void CLipSync::StreamOnComplete(IReadStream *pStream, unsigned nError)
{
//m_pLog->LogToFile("\006 CLypSync stream on complete");
FUNCTION_PROFILER(m_pSystem, PROFILE_GAME);
if (nError)
{
SyncFileLoadFailed();
return;
}
ICryCharModel *pModel=m_pCharInst->GetModel();
assert(pModel);
IAnimationSet *pAnimSet=pModel->GetAnimationSet();
assert(pAnimSet);
const char *pBuffer=(char*)pStream->GetBuffer();
int nBufferSize=pStream->GetBytesRead();
const char *pEndBuffer=pBuffer+nBufferSize;
if (pBuffer)
{
#ifdef MAGPIE_SUPPORT
const float fFramesPerSecond=30.0f;
const float fFramesPerSecondRecp=1.0f/fFramesPerSecond;
//m_pPak->FGets(sBuffer, nBufferSize, pFile); // Frame#,Phonemes
TNameToIdMap mapNameId;
m_vecPatterns.clear();
for (int i=0;i<MAX_LIPSYNC_TRACKS;i++)
m_vecData[i].clear();
float fLen[MAX_LIPSYNC_TRACKS];
memset(fLen, 0, sizeof(fLen));
SSyncData Data[MAX_LIPSYNC_TRACKS];
memset(Data, 0, sizeof(Data));
int nBytesRead=0;
bool bReadHeader=true;
m_nLipSyncTracks=0;
while ((nBytesRead<nBufferSize) && pBuffer && (pBuffer[0]!=0)) //!m_pPak->FEof(pFile))
{
for (int i=0;i<MAX_LIPSYNC_TRACKS;i++)
fLen[i]+=fFramesPerSecondRecp*1000.0f;
int nFrame;
//m_pPak->FGets(sBuffer, nBufferSize, pFile); //"%d,%s", &nFrame, sBuffer);
const char *pNewBuffer=strnstr(pBuffer, "\n",pEndBuffer-pBuffer);
if (pNewBuffer)
{
nBytesRead+=(pNewBuffer-pBuffer)+1;
if (nBytesRead>nBufferSize)
{
m_pLog->Log("\001 error during CLypSync:stream on complete (error1)");
break;
}
if (bReadHeader)
{
const char *pCheckBuffer=pBuffer;
const char *pLastCheckBuffer=pCheckBuffer;
while (((pCheckBuffer=strnstr(pLastCheckBuffer, ",",pEndBuffer-pLastCheckBuffer))!=NULL) && (pCheckBuffer<strnstr(pLastCheckBuffer, "\n",pEndBuffer-pLastCheckBuffer)))
{
m_nLipSyncTracks++;
pLastCheckBuffer=pCheckBuffer+1;
}
bReadHeader=false;
if (m_nLipSyncTracks>MAX_LIPSYNC_TRACKS)
{
m_pLog->Log("Error: LipSync-file has more than %d expression tracks. Skipping.", MAX_LIPSYNC_TRACKS);
break;
}
}
pBuffer=pNewBuffer+1;
}
else
{
/*for (int i=0;i<MAX_LIPSYNC_TRACKS;i++)
{
PUSH_DATA(i)
}*/
break;
}
int nRet=0; //sscanf(pBuffer, "%d,%s\n", &nFrame, sBuffer);
char sTempBuf[256];
const char *pScanBuffer;
const char *pLastScanBuffer=pBuffer;
const char *pScanBufferComma;
const char *pScanBufferBreak;
while (((pScanBufferComma=strnstr(pLastScanBuffer, ",",pEndBuffer-pLastScanBuffer))!=NULL) || ((pScanBufferBreak=strnstr(pLastScanBuffer, "\n",pEndBuffer-pLastScanBuffer))!=NULL))
{
pScanBufferComma=strnstr(pLastScanBuffer, ",",pEndBuffer-pLastScanBuffer);
pScanBufferBreak=strnstr(pLastScanBuffer, "\n",pEndBuffer-pLastScanBuffer);
if ((!pScanBufferComma) && (!pScanBufferBreak))
break;
if (!pScanBufferComma)
pScanBufferComma=(char*)-1;
if (!pScanBufferBreak)
pScanBufferBreak=(char*)-1;
else
pScanBufferBreak--;
bool bLastItem=pScanBufferComma>pScanBufferBreak;
pScanBuffer=(!bLastItem) ? pScanBufferComma : pScanBufferBreak;
int nTokenLength=pScanBuffer-pLastScanBuffer;
if (nTokenLength>=sizeof(sTempBuf))
{
nTokenLength=sizeof(sTempBuf)-1;
m_pLog->Log("Error: LipSync-file has more too long token. Truncating.");
}
strncpy(sTempBuf, pLastScanBuffer, nTokenLength);
sTempBuf[nTokenLength]=0;
if (nRet==0) // frame id
{
nFrame=atoi(sTempBuf);
}else
{
if (strcmp(sTempBuf, "<none>")!=0)
{
if (strnicmp(sTempBuf, "<base", 5)==0)
{
PUSH_DATA(nRet-1);
}else
{
int nPatternId=-1;
TNameToIdMapIt It=mapNameId.find(string(sTempBuf));
if (It==mapNameId.end())
{
SSyncPattern Pattern;
Pattern.sName=sTempBuf;
string sAnimName=(Pattern.sName[0]=='#') ? (Pattern.sName) : (string("#phoneme_")+Pattern.sName);
Pattern.nMorphTargetId=pAnimSet->FindMorphTarget(sAnimName.c_str());
if (Pattern.nMorphTargetId==-1)
GameWarning("Morph-Target '%s' not found. Lip-syncing will not or only partially work !", sAnimName.c_str());
else
{
nPatternId=m_vecPatterns.size();
mapNameId.insert(TNameToIdMapIt::value_type(Pattern.sName, nPatternId));
m_vecPatterns.push_back(Pattern);
}
}else
{
nPatternId=It->second;
}
if (nPatternId!=-1)
{
PUSH_DATA(nRet-1)
Data[nRet-1].fAmp=LIPSYNC_AMP;
Data[nRet-1].nPat=nPatternId;
Data[nRet-1].nOfs=(int)((float)nFrame*fFramesPerSecondRecp*1000.0f);
}
}
}
}
nRet++;
pLastScanBuffer=pScanBuffer+1;
if (bLastItem)
break;
}
if (nRet!=(m_nLipSyncTracks+1)) // we might have reached the end, lets bail...
{
/* for (int i=0;i<MAX_LIPSYNC_TRACKS;i++)
{
PUSH_DATA(i)
}*/
break;
}
}
for (int i=0;i<MAX_LIPSYNC_TRACKS;i++)
{
PUSH_DATA(i)
}
#else
// reading header
int nPatterns;
m_pPak->FRead(&nPatterns, 4, 1, pFile);
m_vecPatterns.resize(nPatterns);
for (int i=0;i<nPatterns;i++)
{
SSyncPattern &Pattern=m_vecPatterns[i];
unsigned char c;
m_pPak->FRead(&c, 1, 1, pFile);
Pattern.sName.resize(c+1);
m_pPak->FRead(&(Pattern.sName[0]), c, 1, pFile);
Pattern.sName[c]=0;
string sAnimName=string("#phoneme_")+Pattern.sName;
Pattern.nMorphTargetId=pAnimSet->FindMorphTarget(sAnimName.c_str());
if (Pattern.nMorphTargetId==-1)
GameWarning("Morph-Target '%s' not found. Lip-syncing will not or only partially work !", sAnimName.c_str());
}
// reading data
int nDataSize;
m_pPak->FRead(&nDataSize, 4, 1, pFile);
if (nDataSize>0)
{
m_vecData.resize(nDataSize);
for (int i=0;i<nDataSize;i++)
{
SSyncData &Data=m_vecData[i];
m_pPak->FRead(&(Data.nOfs), 4, 1, pFile);
m_pPak->FRead(&(Data.nPat), 4, 1, pFile);
m_pPak->FRead(&(Data.fAmp), 4, 1, pFile);
}
}
#endif
}
SyncFileLoaded();
}
bool CLipSync::LoadDialog(const char *pszFilename, int nSoundVolume, float fMinSoundRadius, float fMaxSoundRadius, float fClipDist, int nSoundFlags,IScriptObject *pAITable)
{
if ((!m_pScriptSystem) || (!m_pSoundSystem) || (!m_pCharInst))
return false; // not initialized
FUNCTION_PROFILER(m_pSystem, PROFILE_GAME);
{
FRAME_PROFILER("LoadDialog: Unload previous dialog", m_pSystem, PROFILE_GAME);
UnloadDialog();
}
m_bUnloadWhenDone=false;
m_pAITable=pAITable;
char sSoundFilename[MAX_PATH];
strncpy(sSoundFilename, pszFilename, MAX_PATH);
sSoundFilename[MAX_PATH-1]=0;
char sSyncFilename[MAX_PATH];
strncpy(sSyncFilename, pszFilename, MAX_PATH);
sSyncFilename[MAX_PATH-1]=0;
RemoveExtension(sSyncFilename);
#ifdef MAGPIE_SUPPORT
AddExtension(sSyncFilename, ".txt");
#else
AddExtension(sSyncFilename, ".lsf");
#endif
{
FRAME_PROFILER("LoadDialog: Loading sound", m_pSystem, PROFILE_GAME);
if (m_pSound)
m_pSound->RemoveEventListener( this );
m_pSound=m_pSoundSystem->LoadSound(sSoundFilename, FLAG_SOUND_3D | nSoundFlags); // FLAG_SOUND_STREAM
}
if (!m_pSound)
return false;
m_pSound->AddEventListener( this );
m_pSound->SetVolume(nSoundVolume);
m_pSound->SetMinMaxDistance(fMinSoundRadius, fMaxSoundRadius*0.5f);
m_pSound->SetLoopMode(false);
// ATTENTION,PlayDialog may be already called here.
m_pSound->Preload(); // this will force starting to load ansynchronously
m_pReadStream=m_pStreamEngine->StartRead("LipSync", sSyncFilename, this);
if (m_pReadStream->IsFinished())
{
//m_pLog->LogToFile("\006io:CLipSync(%p)::LoadDialog IsFinished", this);
m_pReadStream=NULL;
}
return true;
}
bool CLipSync::UnloadDialog()
{
AbortLoading();
m_bSoundFileLoaded=false;
m_bSyncFileLoaded=false;
m_vecPatterns.clear();
for (int i=0;i<MAX_LIPSYNC_TRACKS;i++)
m_vecData[i].clear();
m_nLipSyncTracks=0;
if (m_pSound)
{
TRACE("DIALOG UNLOADED !!!");
m_pSound->RemoveEventListener(this);
}
m_pSound=NULL;
m_bUnload=false;
return true;
}
//////////////////////////////////////////////////////////////////////////
bool CLipSync::PlayDialog(bool bUnloadWhenDone)
{
if (!m_pSound)
return false;
if (m_pReadStream)
{
TRACE("WARNING: Waiting to complete load of lipsync data !");
m_pReadStream->Wait();
}
for (int i=0;i<MAX_LIPSYNC_TRACKS;i++)
{
m_nLastDataIdx[i]=-1;
}
m_bUnloadWhenDone=bUnloadWhenDone;
if (m_pSound->IsPlaying())
StopDialog();
m_pSound->SetPosition(m_pEntity->GetPos());
m_pSound->Play();
// if there is an AI conversation table, set timer for the next conversation
if (m_pAITable!=NULL)
{
m_pSystem->GetILog()->Log("\002 Now adding a conversation timer at time %d for the duration of %d seconds",(unsigned long)(m_pTimer->GetCurrTime()*1000),(unsigned long)(m_pSound->GetLengthMs()));
// Far Cry specific code...
#ifndef _ISNOTFARCRY
GetIXGame( m_pSystem->GetIGame() )->AddTimer(m_pAITable,(unsigned long)(m_pTimer->GetCurrTime()*1000),(unsigned long)(m_pSound->GetLengthMs()),NULL,false);
#endif
m_pAITable=NULL;
}
#ifndef PS2
srand(GetTickCount());
#endif
TRACE("PLAYING DIALOG !!!");
return true;
}
bool CLipSync::StopDialog()
{
if (!m_pSound)
return false;
if (m_pSound->IsPlaying())
m_pSound->Stop();
TRACE("STOPPING DIALOG !!!");
return true;
}
bool CLipSync::DoExpression(const char *pszMorphTarget, CryCharMorphParams &MorphParams, bool bAnim)
{
if (!m_pCharInst)
return false; // not initialized
ICryCharModel *pModel=m_pCharInst->GetModel();
assert(pModel);
IAnimationSet *pAnimSet=pModel->GetAnimationSet();
assert(pAnimSet);
int nMorphTargetId=pAnimSet->FindMorphTarget(pszMorphTarget);
if (nMorphTargetId==-1)
return false; // no such morph-target
// try to set time first in case it is already playing
// if (!m_pCharInst->SetMorphTime(nMorphTargetId, MorphParams.fStartTime))
m_pCharInst->StartMorph(nMorphTargetId, MorphParams);
if (!bAnim)
m_pCharInst->SetMorphSpeed(nMorphTargetId, 0.0f);
return true;
}
bool CLipSync::StopExpression(const char *pszMorphTarget)
{
if (!m_pCharInst)
return false; // not initialized
ICryCharModel *pModel=m_pCharInst->GetModel();
assert(pModel);
IAnimationSet *pAnimSet=pModel->GetAnimationSet();
assert(pAnimSet);
int nMorphTargetId=pAnimSet->FindMorphTarget(pszMorphTarget);
if (nMorphTargetId==-1)
return false; // no such morph-target
return m_pCharInst->StopMorph(nMorphTargetId);
}
bool CLipSync::UpdateRandomExpressions(float fFrameTime, bool bAnimate)
{
if (!bAnimate)
return true;
if (m_vecExprPatterns.empty())
return true; // no expr-patterns loaded
for (int i=0;i<(int)m_vecExprPatterns.size();i++)
{
SExprPattern &Expr=m_vecExprPatterns[i];
if (!Expr.fNextIntervalTime)
Expr.fNextIntervalTime=Expr.fOffset+Expr.fInterval+2.0f*(((float)rand()/(float)RAND_MAX)*Expr.fIntervalRandom)-Expr.fIntervalRandom;
Expr.fCurrIntervalTime+=fFrameTime;
if (Expr.fCurrIntervalTime<Expr.fNextIntervalTime)
continue;
CryCharMorphParams MorphParams;
MorphParams.fAmplitude=Expr.fAmp+((float)rand()/(float)RAND_MAX)*Expr.fAmpRandom;
MorphParams.fBlendIn=Expr.fBlendIn;
MorphParams.fBlendOut=Expr.fBlendOut;
MorphParams.fLength=Expr.fHold;
MorphParams.fStartTime=Expr.fCurrIntervalTime-Expr.fNextIntervalTime;
if (Expr.nMorphTargetId!=-1)
{
m_pCharInst->StartMorph(Expr.nMorphTargetId, MorphParams);
// TRACE("Start morph %s (rnd-expr) - Amp: %1.2f; In: %3.2f; Out: %3.2f; Ofs: %1.2f", Expr.sName.c_str(), MorphParams.fAmplitude, MorphParams.fBlendIn, MorphParams.fBlendOut, MorphParams.fStartTime);
}
Expr.fCurrIntervalTime=0.0f;
Expr.fNextIntervalTime=0.0f;
}
return true;
}
bool CLipSync::UpdateLipSync(float fFrameTime, bool bAnimate)
{
if (m_bUnload)
{
UnloadDialog();
return true;
}
if ((!m_pCharInst) || (!m_pSound))
return true; // sound not playing
if (!m_pSound->IsPlaying())
{
if (m_bUnloadWhenDone)
UnloadDialog();
return true;
}
// sync sound-pos
m_pSound->SetPosition(m_pEntity->GetPos());
// TRACE("SoundPos: %4.1f, %4.1f, %4.1f", m_pEntity->GetPos().x, m_pEntity->GetPos().y, m_pEntity->GetPos().z);
if (!bAnimate)
return true;
if (!m_nLipSyncTracks)
return true; // no data loaded
if (m_vecPatterns.empty())
return true; // no patterns loaded
// get offset in speech
#ifdef MAGPIE_SUPPORT
int nCurrSmp=(int)m_pSound->GetCurrentSamplePos(true);
#else
int nCurrSmp=(int)m_pSound->GetCurrentSamplePos()-LIPSYNC_PLAYAHEAD; // this adjustment is needed for compensating the smoothing, so we are not too much ahead..
#endif
if (nCurrSmp<0)
return true;
for (int i=0;i<m_nLipSyncTracks;i++)
{
if (m_vecData[i].empty())
continue;
// get current and next (for interpolation) syncing-data...
int nThisDataIdx=GetDataIdx(i, nCurrSmp, 0, m_vecData[i].size()-1);
if (nThisDataIdx<=m_nLastDataIdx[i])
continue; // no new event so far...
// int nNextDataIdx=nThisDataIdx+1;
// if (nNextDataIdx==m_vecData.size())
// nNextDataIdx=nThisDataIdx;
SSyncData &ThisData=m_vecData[i][nThisDataIdx];
if (nCurrSmp<ThisData.nOfs)
continue;
// SSyncData &NextData=m_vecData[nNextDataIdx];
if ((ThisData.nPat>=0) && (ThisData.nPat<(int)m_vecPatterns.size()))
{
#ifdef MAGPIE_SUPPORT
float fOfsDiffTotal=(float)ThisData.nLen*(1.0f/1000.0f);// (float)(NextData.nOfs-ThisData.nOfs)*(1.0f/1000.0f);
#else
float fOfsDiffTotal=(float)(NextData.nOfs-ThisData.nOfs)*(1.0f/44100.0f);
#endif
SSyncPattern &ThisPattern=m_vecPatterns[ThisData.nPat];
CryCharMorphParams MorphParams;
MorphParams.fAmplitude=ThisData.fAmp;
MorphParams.fBlendIn=fOfsDiffTotal*LIPSYNC_FADEIN;//fOfsDiffTotal*0.5f;
MorphParams.fBlendOut=fOfsDiffTotal*LIPSYNC_FADEOUT+LIPSYNC_CROSSFADE;//fOfsDiffTotal*0.5f;
MorphParams.fLength=fOfsDiffTotal*(1.0f-LIPSYNC_FADEIN-LIPSYNC_FADEOUT);//0.0f;
#ifdef MAGPIE_SUPPORT
MorphParams.fStartTime=(float)(nCurrSmp-ThisData.nOfs)*(1.0f/1000.0f);
#else
MorphParams.fStartTime=(float)(nCurrSmp-ThisData.nOfs)*(1.0f/44100.0f);
#endif
#if !defined(LINUX)
TRACE("Morping: %s (%d of %d)", ThisPattern.sName.c_str(), nThisDataIdx, m_vecData[i].size());
#endif
if (ThisPattern.nMorphTargetId!=-1)
m_pCharInst->StartMorph(ThisPattern.nMorphTargetId, MorphParams);
//TRACE("Start morph %s (lip-sync) - Amp: %1.2f; In: %3.2f; Out: %3.2f; Ofs: %1.2f", ThisPattern.sName.c_str(), MorphParams.fAmplitude, MorphParams.fBlendIn, MorphParams.fBlendOut, MorphParams.fStartTime);
}
m_nLastDataIdx[i]=nThisDataIdx;
}
return true;
}
bool CLipSync::Update(bool bAnimate)
{
if (!m_pCharInst)
return true; // not loaded
float fFrameTime=m_pTimer->GetFrameTime();
UpdateRandomExpressions(fFrameTime, bAnimate);
UpdateLipSync(fFrameTime, bAnimate);
return true;
}
//////////////////////////////////////////////////////////////////////////
// Binary search for the current sync-data.
int CLipSync::GetDataIdx(int nChannel, int nSmp, int nLo, int nHi)
{
int nMid=((nHi-nLo)>>1)+nLo;
if (nMid==nLo)
return nMid;
if (m_vecData[nChannel][nMid].nOfs>nSmp)
return GetDataIdx(nChannel, nSmp, nLo, nMid);
else
return GetDataIdx(nChannel, nSmp, nMid, nHi);
}

143
CryEntitySystem/LipSync.h Normal file
View File

@@ -0,0 +1,143 @@
//////////////////////////////////////////////////////////////////////
//
// Game Source Code
//
// File: LipSync.h
// Description: Class to manage and compute all LipSync- and FacialExpression-Features.
//
// History:
// - December 6, 2001: Created by Lennert Schneider
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_LIPSYNC_H__93A3FF8F_9950_4F4E_A719_48B376E471D5__INCLUDED_)
#define AFX_LIPSYNC_H__93A3FF8F_9950_4F4E_A719_48B376E471D5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <ILipSync.h>
#include <ISound.h>
#include <IStreamEngine.h>
struct ISoundSystem;
struct IScriptSystem;
struct ISound;
struct ICryCharInstance;
/*
#define LIPSYNC_MAXSMOOTH 10000
#define LIPSYNC_PREAMP 1.2f
#define LIPSYNC_RNDEXPRFREQ 5000
#define LIPSYNC_RNDEXPRATTACK 4410
#define LIPSYNC_RNDEXPRSUSTAIN 4410
#define LIPSYNC_RNDEXPRRELEASE 8820
*/
#define MAX_LIPSYNC_TRACKS 3
struct SSyncData
{
int nOfs;
int nLen;
signed char nPat;
float fAmp;
};
struct SSyncPattern
{
string sName;
int nMorphTargetId;
};
struct SExprPattern
{
SExprPattern()
{
fCurrIntervalTime=0.0f;
fNextIntervalTime=0.0f;
}
string sName;
int nMorphTargetId;
float fOffset;
float fInterval;
float fIntervalRandom;
float fAmp;
float fAmpRandom;
float fBlendIn;
float fHold;
float fBlendOut;
// internal
float fCurrIntervalTime;
float fNextIntervalTime;
};
typedef std::map<string,int> TNameToIdMap;
typedef TNameToIdMap::iterator TNameToIdMapIt;
typedef std::vector<SSyncData> TSyncDataVec;
typedef std::vector<SSyncPattern> TSyncPatternVec;
typedef std::vector<SExprPattern> TExprPatternVec;
class CLipSync : public ILipSync, ISoundEventListener, IStreamCallback
{
private:
// needed interfaces
ISystem *m_pSystem;
ISoundSystem *m_pSoundSystem;
IScriptSystem *m_pScriptSystem;
IStreamEngine *m_pStreamEngine;
ILog *m_pLog;
ITimer *m_pTimer;
ICryPak *m_pPak;
_smart_ptr<ISound> m_pSound;
IEntity *m_pEntity;
ICryCharInstance *m_pCharInst;
IDialogLoadSink *m_pSink;
IReadStreamPtr m_pReadStream;
string m_loadedExpression;
bool m_bSoundFileLoaded;
bool m_bSyncFileLoaded;
bool m_bUnload;
// data
bool m_bUnloadWhenDone;
int m_nLipSyncTracks;
TSyncDataVec m_vecData[MAX_LIPSYNC_TRACKS];
TSyncPatternVec m_vecPatterns;
TExprPatternVec m_vecExprPatterns;
// state
int m_nLastDataIdx[MAX_LIPSYNC_TRACKS];
IScriptObject *m_pAITable;
private:
virtual ~CLipSync();
int GetDataIdx(int nChannel, int nSmp, int nLo, int nHi);
bool UpdateRandomExpressions(float fFrameTime, bool bAnimate);
bool UpdateLipSync(float fFrameTime, bool bAnimate);
void RemoveExtension(char *pszFilename);
void AddExtension(char *pszFilename, const char *pszExtension);
void CheckIfDialogLoaded();
void LoadFailed();
void OnSoundEvent( ESoundCallbackEvent event,ISound *pSound );
void SyncFileLoaded();
void SyncFileLoadFailed();
void AbortLoading();
virtual void StreamOnComplete(IReadStream *pStream, unsigned nError);
public:
CLipSync();
bool Init(ISystem *pSystem, IEntity *pEntity); // initializes and prepares the character for lip-synching
void Release(); // releases all resources and deletes itself
bool LoadRandomExpressions(const char *pszExprScript, bool bRaiseError=true); // load expressions from script
bool UnloadRandomExpressions(); // release expressions
// loads a dialog for later playback
bool LoadDialog(const char *pszFilename, int nSoundVolume, float fMinSoundRadius, float fMaxSoundRadius, float fClipDist, int nSoundFlags=0,IScriptObject *pAITable=NULL);
bool UnloadDialog(); // releases all resources
bool PlayDialog(bool bUnloadWhenDone=true); // plays a loaded dialog
bool StopDialog(); // stops (aborts) a dialog
bool DoExpression(const char *pszMorphTarget, CryCharMorphParams &MorphParams, bool bAnim=true); // do a specific expression
bool StopExpression(const char *pszMorphTarget); // stop animating the specified expression
bool Update(bool bAnimate=true); // updates animation & stuff
void SetCallbackSink(IDialogLoadSink *pSink) { m_pSink=pSink; }
};
#endif // !defined(AFX_LIPSYNC_H__93A3FF8F_9950_4F4E_A719_48B376E471D5__INCLUDED_)

View File

@@ -0,0 +1,5 @@
SCC = This is a source code control file
[CryEntitySystem.vcproj]
SCC_Aux_Path = "P4SCC#perforce:1666##marcoc_code##PC018"
SCC_Project_Name = Perforce Project

View File

@@ -0,0 +1,87 @@
//////////////////////////////////////////////////////////////////////
//
// Crytek Source code
// Copyright (c) Crytek 2001-2004
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RandomExprLoadSink.h"
//////////////////////////////////////////////////////////////////////////
//! Reports a Game Warning to validator with WARNING severity.
inline void GameWarning( const char *format,... )
{
if (!format)
return;
char buffer[MAX_WARNING_LENGTH];
va_list args;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
CryWarning( VALIDATOR_MODULE_GAME,VALIDATOR_WARNING,buffer );
}
CRandomExprLoadSink::CRandomExprLoadSink(bool bRaiseError, IScriptSystem *pScriptSystem, _SmartScriptObject *pObj, IAnimationSet *pAnimSet, TExprPatternVec *pvecExprPatterns, int nMode)
{
m_bRaiseError=bRaiseError;
m_pScriptSystem=pScriptSystem;
m_pObj=pObj;
m_pAnimSet=pAnimSet;
m_pvecExprPatterns=pvecExprPatterns;
m_nMode=nMode;
}
CRandomExprLoadSink::~CRandomExprLoadSink()
{
}
void CRandomExprLoadSink::OnElementFound(const char *sName, ScriptVarType type)
{
switch (type)
{
case svtObject:
{
_SmartScriptObject pObj(m_pScriptSystem, true);
if (!(*m_pObj)->GetValue(sName, pObj))
break;
switch (m_nMode)
{
case EXPRLOAD_MODE_BASE:
{
SExprPattern ExprPattern;
ExprPattern.sName=sName;
string sAnimName=string("#")+ExprPattern.sName;
ExprPattern.nMorphTargetId=m_pAnimSet->FindMorphTarget(sAnimName.c_str());
if (ExprPattern.nMorphTargetId==-1)
{
if (m_bRaiseError)
GameWarning("Morph-Target '%s' (random expression) not found. Lip-syncing will only partially work !", sAnimName.c_str());
break;
}
if (!pObj->GetValue("Offset", ExprPattern.fOffset))
ExprPattern.fOffset=0.0f;
if (!pObj->GetValue("Interval", ExprPattern.fInterval))
ExprPattern.fInterval=5.0f;
if (!pObj->GetValue("IntervalRandom", ExprPattern.fIntervalRandom))
ExprPattern.fIntervalRandom=0.0f;
if (!pObj->GetValue("Amp", ExprPattern.fAmp))
ExprPattern.fAmp=1.0f;
if (!pObj->GetValue("AmpRandom", ExprPattern.fAmpRandom))
ExprPattern.fAmpRandom=0.0f;
if (!pObj->GetValue("BlendIn", ExprPattern.fBlendIn))
ExprPattern.fBlendIn=0.5f;
if (!pObj->GetValue("Hold", ExprPattern.fHold))
ExprPattern.fHold=0.0f;
if (!pObj->GetValue("BlendOut", ExprPattern.fBlendOut))
ExprPattern.fBlendOut=0.5f;
m_pvecExprPatterns->push_back(ExprPattern);
break;
}
}
break;
}
}
}

View File

@@ -0,0 +1,30 @@
//////////////////////////////////////////////////////////////////////
//
// Crytek Source code
// Copyright (c) Crytek 2001-2004
//
//////////////////////////////////////////////////////////////////////
#pragma once
#include <IScriptSystem.h>
#include "LipSync.h"
#define EXPRLOAD_MODE_BASE 1
class CRandomExprLoadSink : public IScriptObjectDumpSink
{
private:
bool m_bRaiseError;
IScriptSystem *m_pScriptSystem;
_SmartScriptObject *m_pObj;
IAnimationSet *m_pAnimSet;
TExprPatternVec *m_pvecExprPatterns;
int m_nMode;
public:
CRandomExprLoadSink(bool bRaiseError, IScriptSystem *pScriptSystem, _SmartScriptObject *pObj, IAnimationSet *pAnimSet, TExprPatternVec *pvecExprPatterns, int nMode=EXPRLOAD_MODE_BASE);
~CRandomExprLoadSink();
void OnElementFound(const char *sName, ScriptVarType type);
void OnElementFound(int nIdx, ScriptVarType type) {}
};

View File

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// CryEntityDLL.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

206
CryEntitySystem/stdafx.h Normal file
View File

@@ -0,0 +1,206 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__2E966576_9327_4B66_9CFD_329F604BE709__INCLUDED_)
#define AFX_STDAFX_H__2E966576_9327_4B66_9CFD_329F604BE709__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//////////////////////////////////////////////////////////////////////////
// THIS MUST BE AT THE VERY BEGINING OF STDAFX.H FILE.
// Disable STL threading support, (makes STL faster)
//////////////////////////////////////////////////////////////////////////
#define _NOTHREADS
#define _STLP_NO_THREADS
//////////////////////////////////////////////////////////////////////////
#include "Cry_Math.h"
#include "Cry_XOptimise.h"
#ifndef _XBOX
#ifdef WIN32
#include <windows.h>
#endif
#else
#include <xtl.h>
#endif
//#define USE_MEM_POOL
#define USE_NEWPOOL
#include <CryMemoryManager.h>
#include <CrySizer.h>
#include <platform.h>
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
extern bool g_bProfilerEnabled;
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
#ifdef PS2
#ifndef DISABLE_VERIFY
#define _VERIFY(a) \
{ \
if(!(a)) \
{ \
FORCE_EXIT(); \
DEBUG_BREAK; \
} \
}
#else
#define VERIFY(a) a;
#endif
#else
#ifndef DISABLE_VERIFY
#define _VERIFY(a) \
{ \
if(!(a)) \
{ \
assert (0); \
} \
}
#else
#define VERIFY(a) a;
#endif
#endif //PS2
// Windows defines
#if !defined(LINUX)
typedef unsigned long DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef float FLOAT;
typedef int INT;
typedef unsigned int UINT;
#ifndef uchar
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned short ushort;
#endif
#endif
#ifndef PS2
#include <memory.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#if !defined(LINUX)
#include <assert.h>
#endif
/*#ifdef USE_MEM_POOL
#undef malloc
#define malloc(_size) _CryMalloc(g_PoolCtx,_size)
#undef free
#define free(_size) _CryFree(g_PoolCtx,_size)
#undef realloc
#define realloc(_ptr,_size) _CryRealloc(g_PoolCtx,_ptr,_size)
#endif*/
#pragma warning (disable : 4768)
#include <vector>
#include <list>
#include <iterator>
#include <algorithm>
#include <map>
#include "EntityDesc.h"
#include <IEntitySystem.h>
#ifndef ____TRACE
#define ____TRACE
#ifdef PS2
_inline void ___TRACE(const char *sFormat, ... )
{
va_list vl;
static char sTraceString[500];
va_start(vl, sFormat);
vsprintf(sTraceString, sFormat, vl);
va_end(vl);
cout << sTraceString << "\n";
}
#else
_inline void __cdecl ___TRACE(const char *sFormat, ... )
{
va_list vl;
static char sTraceString[500];
va_start(vl, sFormat);
vsprintf(sTraceString, sFormat, vl);
va_end(vl);
::OutputDebugString(sTraceString);
}
#endif
#define _TRACE ___TRACE
#endif //____TRACE
#ifdef _DEBUG
//@FIXME this function should not be inline.
_inline void __cdecl __CRYTEKDLL_TRACE(const char *sFormat, ... )
{
va_list vl;
static char sTraceString[1024];
va_start(vl, sFormat);
vsprintf(sTraceString, sFormat, vl);
va_end(vl);
strcat(sTraceString, "\n");
#ifdef WIN32
::OutputDebugString(sTraceString);
#endif
#ifdef GAMECUBE
OSReport(sTraceString);
#endif
}
#define TRACE __CRYTEKDLL_TRACE
#else
#define TRACE(str) ;
#endif
#if defined(_DEBUG) && !defined(LINUX)
#include <crtdbg.h>
#endif
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__2E966576_9327_4B66_9CFD_329F604BE709__INCLUDED_)