port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
#include "stdafx.h"
#include "Engine.h"
#include "../ResourceFactory/ResourceFactory.h"
#include "../CommonObjectFactory/CommonObjectFactory.h"
#include "../FileSystem/FileSystem.h"
#include "../Timeline/Timeline.h"
#include "../AnimationManager/AnimationManager.h"
Engine::Engine()
: m_DX10Device(NULL)
, m_DXGIFactory(NULL)
, m_ResourceFactory(NULL)
, m_CommonObjectFactory(NULL)
, m_DeviceEnumeration(NULL)
, m_FileSystem(NULL)
, m_DriverType(D3D10_DRIVER_TYPE_NULL)
, m_Timeline(NULL)
, m_AnimationManager(NULL)
{
ZeroMemory(&m_EngineStates, sizeof(EngineStates));
}
Engine::~Engine()
{
this->Uninitialize();
}
void Engine::Initialize(IDisplayAdapter* ar_Adapter_)
{
std::wcout << std::green << "Initializing engine." << std::white << std::endl;
HRESULT result = S_OK;
if (m_DeviceEnumeration == NULL)
m_DeviceEnumeration = new DeviceEnumerator();
if (m_DX10Device != NULL)
this->Uninitialize();
if (ar_Adapter_ == NULL)
{
if (!m_DeviceEnumeration->get_HasEnumerated())
m_DeviceEnumeration->TryEnumerate(0, 0, 0, DataFormat::R8G8B8A8_UnsignedNormalized);
ar_Adapter_ = m_DeviceEnumeration->FindBestAdapter();
m_DeviceEnumeration->Verbose();
}
if (ar_Adapter_ == NULL)
{
std::wcout << std::red << "No capable adapter found, ensure DX10 compatible system." << std::white << std::endl;
this->Uninitialize();
return;
}
// create a functional device, first try a hardware accelerated one, then fallback to software
D3D10_DRIVER_TYPE driverTypes[] =
{
D3D10_DRIVER_TYPE_HARDWARE,
D3D10_DRIVER_TYPE_REFERENCE,
};
uint32 deviceFlags = 0;
#ifdef _DEBUG
// we want debug informations when we run a debug build
deviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
std::wcout << std::yellow << "Using debug device." << std::white << std::endl;
#endif
// lets create the device now
uint32 driverTypesCount = sizeof(driverTypes) / sizeof(driverTypes[0]);
for(uint32 driverTypeIndex = 0; driverTypeIndex < driverTypesCount; ++driverTypeIndex)
{
// store the driver type, we will need this for later statistics, eg.
m_DriverType = driverTypes[driverTypeIndex];
result = ::D3D10CreateDevice(ar_Adapter_->get_Adapter(), m_DriverType, NULL, deviceFlags, D3D10_SDK_VERSION, &m_DX10Device);
if( SUCCEEDED( result ) )
break;
}
if (result != S_OK)
{
std::wcout << std::red << "Failed to create device." << std::white << std::endl;
this->Uninitialize();
return;
}
result = ::CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&m_DXGIFactory);
if (result != S_OK)
{
std::wcout << std::red << "Failed to create GI factory." << std::white << std::endl;
this->Uninitialize();
return;
}
m_ResourceFactory = new ResourceFactory(*this);
m_CommonObjectFactory = new CommonObjectFactory(*this);
m_FileSystem = new FileSystem(this);
m_Timeline = new Timeline(*this);
m_AnimationManager = new AnimationManager(*this);
std::wcout << std::green << "Finished initializing engine." << std::white << std::endl << std::endl;
}
void Engine::Uninitialize()
{
std::wcout << std::endl << std::green << "Uninitializing engine." << std::white << std::endl;
delete m_ResourceFactory;
m_ResourceFactory = NULL;
delete m_CommonObjectFactory;
m_CommonObjectFactory = NULL;
delete m_DeviceEnumeration;
m_DeviceEnumeration = NULL;
delete m_FileSystem;
m_FileSystem = NULL;
delete m_Timeline;
m_Timeline = NULL;
delete m_AnimationManager;
m_AnimationManager = NULL;
if (m_DX10Device != NULL)
{
m_DX10Device->ClearState();
m_DX10Device->Release();
m_DX10Device = NULL;
}
if (m_DXGIFactory != NULL)
m_DXGIFactory->Release();
m_DXGIFactory = NULL;
ZeroMemory(&m_EngineStates, sizeof(EngineStates));
}