AVA2 cross-platform client parity baseline

This commit is contained in:
shen
2026-10-06 00:53:42 -07:00
commit 9f748eb05a
3271 changed files with 1275528 additions and 0 deletions
@@ -0,0 +1,74 @@
#include "StdAfx.h"
#include "CRenderTargetManager.h"
#include "../EterBase/Stl.h"
//#include "GrpBase.h"
#include <memory>
CRenderTargetManager::CRenderTargetManager()
{
}
CRenderTargetManager::~CRenderTargetManager()
{
Destroy();
}
void CRenderTargetManager::Destroy()
{
m_renderTargets.clear();
}
void CRenderTargetManager::DeformModels()
{
for (const auto& elem : m_renderTargets)
elem.second->DeformModel();
}
void CRenderTargetManager::UpdateModels()
{
for (auto& elem : m_renderTargets)
elem.second->UpdateModel();
}
void CRenderTargetManager::RenderBackgrounds()
{
for (const auto& elem : m_renderTargets)
elem.second->RenderBackground();
}
void CRenderTargetManager::RenderModels()
{
for (const auto& elem : m_renderTargets)
elem.second->RenderModel();
}
void CRenderTargetManager::CreateRenderTargetTextures()
{
for (const auto& elem : m_renderTargets)
elem.second->CreateTextures();
}
void CRenderTargetManager::ReleaseRenderTargetTextures()
{
for (const auto& elem : m_renderTargets)
elem.second->ReleaseTextures();
}
bool CRenderTargetManager::CreateRenderTarget(const uint8_t index, const int width, const int height)
{
if (index < 1 || GetRenderTarget(index))
return false;
m_renderTargets.emplace(index, std::make_shared<CRenderTarget>(width, height));
return true;
}
std::shared_ptr<CRenderTarget> CRenderTargetManager::GetRenderTarget(const uint8_t index)
{
const auto it = m_renderTargets.find(index);
if (it != m_renderTargets.end())
return it->second;
return nullptr;
}
@@ -0,0 +1,32 @@
#pragma once
#include <unordered_map>
#include <cstdint>
//#include "GrpBase.h"
//#include "GrpScreen.h"
#include "../EterBase/Singleton.h"
#include <memory>
#include "CRenderTarget.h"
class CRenderTargetManager : public CSingleton<CRenderTargetManager>
{
public:
CRenderTargetManager();
virtual ~CRenderTargetManager();
std::shared_ptr<CRenderTarget> GetRenderTarget(uint8_t index);
bool CreateRenderTarget(uint8_t index, int width, int height);
void CreateRenderTargetTextures();
void ReleaseRenderTargetTextures();
void Destroy();
void DeformModels();
void UpdateModels();
void RenderBackgrounds();
void RenderModels();
protected:
std::unordered_map<uint8_t, std::shared_ptr<CRenderTarget>> m_renderTargets;
};
@@ -0,0 +1,319 @@
#include "StdAfx.h"
#include "CRenderTarget.h"
#include "../EterLib/Camera.h"
#include "../EterLib/CRenderTargetManager.h"
#include "../EterPythonLib/PythonGraphic.h"
#include "../EterBase/CRC32.h"
#include "../GameLib/GameType.h"
#include "../GameLib/MapType.h"
#include "../GameLib/ItemData.h"
#include "../GameLib/ActorInstance.h"
#include "../UserInterface/InstanceBase.h"
#include "ResourceManager.h"
CRenderTarget::CRenderTarget(const DWORD width, const DWORD height) : m_pModel(nullptr),
m_background(nullptr),
m_modelRotation(90.0f),
m_visible(false) ,
m_modelZoom(1500.0f),
m_modelPosition(0.0f)
{
auto pTex = new CGraphicRenderTargetTexture;
if (!pTex->Create(width, height, D3DFMT_X8R8G8B8, D3DFMT_D16)) {
delete pTex;
TraceError("CRenderTarget::CRenderTarget: Could not create CGraphicRenderTargetTexture %dx%d", width, height);
throw std::runtime_error("CRenderTarget::CRenderTarget: Could not create CGraphicRenderTargetTexture");
}
m_renderTargetTexture = std::unique_ptr<CGraphicRenderTargetTexture>(pTex);
}
CRenderTarget::~CRenderTarget()
{
}
void CRenderTarget::SetVisibility(bool isShow)
{
m_visible = isShow;
}
void CRenderTarget::SetZoom(float zoom)
{
m_modelZoom = zoom;
}
void CRenderTarget::SetPosition(float position)
{
m_modelPosition = position;
}
void CRenderTarget::RenderTexture() const
{
m_renderTargetTexture->Render();
}
void CRenderTarget::SetRenderingRect(RECT* rect) const
{
m_renderTargetTexture->SetRenderingRect(rect);
}
void CRenderTarget::CreateTextures() const
{
m_renderTargetTexture->CreateTextures();
}
void CRenderTarget::ReleaseTextures() const
{
m_renderTargetTexture->ReleaseTextures();
}
void CRenderTarget::SelectModel(const DWORD index)
{
/*
if (index == 0)
{
//delete m_pModel;
m_pModel.reset();
return;
}*/
CInstanceBase::SCreateData kCreateData{};
kCreateData.m_bType = CActorInstance::TYPE_PC; // Dynamic Type
kCreateData.m_dwRace = index;
auto model = std::make_unique<CInstanceBase>();
if (!model->Create(kCreateData))
{
if (m_pModel)
{
m_pModel.reset();
}
return;
}
m_pModel = std::move(model);
m_pModel->NEW_SetPixelPosition(TPixelPosition(0,0,0));
m_pModel->GetGraphicThingInstancePtr()->SetSkipLod(true);
m_pModel->GetGraphicThingInstancePtr()->ClearAttachingEffect();
m_modelRotation = 90.0f;
m_modelZoom = 1500.0f;
m_modelPosition = 0.0f;
m_pModel->Refresh(CRaceMotionData::NAME_WAIT, true);
m_pModel->SetLoopMotion(CRaceMotionData::NAME_WAIT);
m_pModel->SetAlwaysRender(true);
m_pModel->SetRotation(0.0f);
auto& camera_manager = CCameraManager::instance();
camera_manager.SetCurrentCamera(CCameraManager::SHOPDECO_CAMERA);
camera_manager.GetCurrentCamera()->SetTargetHeight(110.0);
camera_manager.ResetToPreviousCamera();
}
bool CRenderTarget::CreateBackground(const char* imgPath, const DWORD width, const DWORD height)
{
if (m_background)
return false;
m_background = std::make_unique<CGraphicImageInstance>();
const auto graphic_image = dynamic_cast<CGraphicImage*>(CResourceManager::instance().GetResourcePointer(imgPath));
if (!graphic_image)
{
m_background.reset();
return false;
}
m_background->SetImagePointer(graphic_image);
m_background->SetScale(static_cast<float>(width) / graphic_image->GetWidth(), static_cast<float>(height) / graphic_image->GetHeight());
return true;
}
void CRenderTarget::SetLoopMotion(WORD wMotion)
{
if (!m_visible || !m_pModel)
return;
m_pModel->Refresh(wMotion, true);
m_pModel->SetLoopMotion(wMotion);
}
void CRenderTarget::ChangeWeapon(DWORD Weapon)
{
if (!m_visible || !m_pModel)
return;
m_pModel->SetWeapon(Weapon);
}
void CRenderTarget::ChangeArmor(DWORD Armor)
{
if (!m_visible || !m_pModel)
return;
m_pModel->SetArmor(Armor);
}
void CRenderTarget::ChangeHair(DWORD Hair)
{
if (!m_visible || !m_pModel)
return;
m_pModel->SetHair(Hair);
}
void CRenderTarget::ChangeAcce(DWORD Acce)
{
if (!m_visible || !m_pModel)
return;
m_pModel->SetSash(Acce);
}
void CRenderTarget::SetShiningWeapon(DWORD Shining)
{
if (!m_visible || !m_pModel)
return;
m_pModel->SetShining(0, Shining);
}
void CRenderTarget::SetShiningArmor(DWORD Shining)
{
if (!m_visible || !m_pModel)
return;
m_pModel->SetShining(1, Shining);
}
void CRenderTarget::RenderBackground() const
{
if (!m_visible)
return;
if (!m_background)
return;
auto& rectRender = *m_renderTargetTexture->GetRenderingRect();
m_renderTargetTexture->SetRenderTarget();
CGraphicRenderTargetTexture::Clear();
CPythonGraphic::Instance().SetInterfaceRenderState();
const auto width = static_cast<float>(rectRender.right - rectRender.left);
const auto height = static_cast<float>(rectRender.bottom - rectRender.top);
CPythonGraphic::Instance().SetViewport(0.0f, 0.0f, width, height);
m_background->Render();
m_renderTargetTexture->ResetRenderTarget();
CPythonGraphic::Instance().RestoreViewport();
}
void CRenderTarget::UpdateModel()
{
if (!m_visible || !m_pModel)
return;
if (m_modelRotation < 360.0f)
m_modelRotation += 1.0f;
else
m_modelRotation = 0.0f;
m_pModel->SetRotation(m_modelRotation);
m_pModel->Transform();
m_pModel->GetGraphicThingInstanceRef().RotationProcess();
}
void CRenderTarget::DeformModel() const
{
if (!m_visible)
return;
if (m_pModel)
m_pModel->Deform();
}
void CRenderTarget::RenderModel() const
{
if (!m_visible)
{
return;
}
auto& python_graphic = CPythonGraphic::Instance();
auto& camera_manager = CCameraManager::instance();
auto& state_manager = CStateManager::Instance();
auto& rectRender = *m_renderTargetTexture->GetRenderingRect();
if (!m_pModel)
{
return;
}
m_renderTargetTexture->SetRenderTarget();
if (!m_background)
{
m_renderTargetTexture->Clear();
}
python_graphic.ClearDepthBuffer();
const auto fov = python_graphic.GetFOV();
const auto aspect = python_graphic.GetAspect();
const auto near_y = python_graphic.GetNear();
const auto far_y = python_graphic.GetFar();
const auto width = static_cast<float>(rectRender.right - rectRender.left);
const auto height = static_cast<float>(rectRender.bottom - rectRender.top);
state_manager.SetRenderState(D3DRS_FOGENABLE, TRUE);
python_graphic.SetViewport(0.0f, 0.0f, width, height);
python_graphic.PushState();
//1500.0f
D3DXVECTOR3 v3Eye(0.0f, m_modelZoom, 300.0f);
D3DXVECTOR3 v3Target( 0.0f, m_modelPosition, 95.0f);
D3DXVECTOR3 v3Up(0.0f, 0.0f, 1.0f);
camera_manager.SetCurrentCamera(CCameraManager::SHOPDECO_CAMERA);
camera_manager.GetCurrentCamera()->SetViewParams(
v3Eye,
D3DXVECTOR3{ 0.0f, m_modelPosition, 95.0f },
D3DXVECTOR3{0.0f, 0.0f, 1.0f}
);
python_graphic.UpdateViewMatrix();
python_graphic.SetPerspective(10.0f, width / height, 100.0f, 3000.0f);
m_pModel->Render();
m_pModel->GetGraphicThingInstanceRef().RenderAllAttachingEffect();
camera_manager.ResetToPreviousCamera();
python_graphic.RestoreViewport();
python_graphic.PopState();
python_graphic.SetPerspective(fov, aspect, near_y, far_y);
m_renderTargetTexture->ResetRenderTarget();
state_manager.SetRenderState(D3DRS_FOGENABLE, TRUE);
}
@@ -0,0 +1,54 @@
#pragma once
#include <memory>
#include "GrpRenderTargetTexture.h"
class CInstanceBase;
class CGraphicImageInstance;
class CRenderTarget
{
using TCharacterInstanceMap = std::map<DWORD, CInstanceBase*>;
public:
CRenderTarget(DWORD width, DWORD height);
~CRenderTarget();
void SetVisibility(bool isShow);
void RenderTexture() const;
void SetRenderingRect(RECT* rect) const;
void SelectModel(DWORD index);
bool CreateBackground(const char* imgPath, DWORD width, DWORD height);
void RenderBackground() const;
void UpdateModel();
void DeformModel() const;
void RenderModel() const;
void CreateTextures() const;
void ReleaseTextures() const;
void ChangeWeapon(DWORD Weapon);
void ChangeArmor(DWORD Armor);
void ChangeHair(DWORD Hair);
void ChangeAcce(DWORD Acce);
void SetLoopMotion(WORD wMotion);
void SetShiningWeapon(DWORD Shining);
void SetShiningArmor(DWORD Shining);
void SetZoom(float zoom);
void SetPosition(float position);
private:
std::unique_ptr<CInstanceBase> m_pModel;
std::unique_ptr<CGraphicImageInstance> m_background;
std::unique_ptr<CGraphicRenderTargetTexture> m_renderTargetTexture;
float m_modelRotation;
bool m_visible;
float m_modelZoom;
float m_modelPosition;
};
@@ -0,0 +1,170 @@
#include "StdAfx.h"
#include "../EterBase/Stl.h"
#include "GrpRenderTargetTexture.h"
#include "StateManager.h"
CGraphicRenderTargetTexture::CGraphicRenderTargetTexture()
: m_d3dFormat{D3DFMT_UNKNOWN}, m_depthStencilFormat{D3DFMT_UNKNOWN}
{
Initialize();
m_renderRect.left = 0;
m_renderRect.top = 0;
m_renderRect.right = 0;
m_renderRect.bottom = 0;
}
CGraphicRenderTargetTexture::~CGraphicRenderTargetTexture()
{
Reset();
}
void CGraphicRenderTargetTexture::ReleaseTextures()
{
safe_release(m_lpd3dRenderTexture);
safe_release(m_lpd3dRenderTargetSurface);
safe_release(m_lpd3dDepthSurface);
safe_release(m_lpd3dDepthSurface);
safe_release(m_lpd3dOriginalRenderTarget);
safe_release(m_lpd3dOldDepthBufferSurface);
m_renderRect.left = 0;
m_renderRect.top = 0;
m_renderRect.right = 0;
m_renderRect.bottom = 0;
}
bool CGraphicRenderTargetTexture::Create(const int width, const int height, const D3DFORMAT texFormat, const D3DFORMAT depthFormat)
{
Reset();
m_height = height;
m_width = width;
if (!CreateRenderTexture(width, height, texFormat))
return false;
if (!CreateRenderDepthStencil(width, height, depthFormat))
return false;
return true;
}
void CGraphicRenderTargetTexture::CreateTextures()
{
if (CreateRenderTexture(m_width, m_height, m_d3dFormat))
{
CreateRenderDepthStencil(m_width, m_height, m_depthStencilFormat);
}
}
bool CGraphicRenderTargetTexture::CreateRenderTexture(const int width, const int height, const D3DFORMAT format)
{
m_d3dFormat = format;
if (FAILED(ms_lpd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, m_d3dFormat, D3DPOOL_DEFAULT, &m_lpd3dRenderTexture)))
return false;
if (FAILED(m_lpd3dRenderTexture->GetSurfaceLevel(0, &m_lpd3dRenderTargetSurface)))
return false;
return true;
}
bool CGraphicRenderTargetTexture::CreateRenderDepthStencil(const int width, const int height, const D3DFORMAT format)
{
m_depthStencilFormat = format;
return (ms_lpd3dDevice->CreateDepthStencilSurface(width, height, m_depthStencilFormat, D3DMULTISAMPLE_NONE, &m_lpd3dDepthSurface)) == D3D_OK;
}
void CGraphicRenderTargetTexture::SetRenderTarget()
{
ms_lpd3dDevice->GetRenderTarget(&m_lpd3dOriginalRenderTarget);
ms_lpd3dDevice->GetDepthStencilSurface(&m_lpd3dOldDepthBufferSurface);
ms_lpd3dDevice->SetRenderTarget(m_lpd3dRenderTargetSurface, m_lpd3dDepthSurface);
}
void CGraphicRenderTargetTexture::ResetRenderTarget()
{
ms_lpd3dDevice->SetRenderTarget(m_lpd3dOriginalRenderTarget, m_lpd3dOldDepthBufferSurface);
safe_release(m_lpd3dOriginalRenderTarget);
safe_release(m_lpd3dOldDepthBufferSurface);
}
void CGraphicRenderTargetTexture::Clear()
{
ms_lpd3dDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
}
void CGraphicRenderTargetTexture::SetRenderingRect(RECT* rect)
{
m_renderRect = *rect;
}
RECT* CGraphicRenderTargetTexture::GetRenderingRect()
{
return &m_renderRect;
}
LPDIRECT3DTEXTURE8 CGraphicRenderTargetTexture::GetRenderTargetTexture() const
{
return m_lpd3dRenderTexture;
}
void CGraphicRenderTargetTexture::Render() const
{
D3DSURFACE_DESC desc;
m_lpd3dRenderTargetSurface->GetDesc(&desc);
const auto imgWidth = static_cast<float>(m_renderRect.right - m_renderRect.left);
const auto imgHeight = static_cast<float>(m_renderRect.bottom - m_renderRect.top);
const auto su = 0.0f;
const auto sv = 0.0f;
const auto eu = imgWidth / static_cast<float>(desc.Width);
const auto ev = imgHeight / static_cast<float>(desc.Height);
TPDTVertex pVertices[4];
pVertices[0].position = TPosition(m_renderRect.left - 0.5f, m_renderRect.top - 0.5f, 0.0f);
pVertices[0].texCoord = TTextureCoordinate(su, sv);
pVertices[0].diffuse = 0xffffffff;
pVertices[1].position = TPosition(m_renderRect.right - 0.5f, m_renderRect.top - 0.5f, 0.0f);
pVertices[1].texCoord = TTextureCoordinate(eu, sv);
pVertices[1].diffuse = 0xffffffff;
pVertices[2].position = TPosition(m_renderRect.left - 0.5f, m_renderRect.bottom - 0.5f, 0.0f);
pVertices[2].texCoord = TTextureCoordinate(su, ev);
pVertices[2].diffuse = 0xffffffff;
pVertices[3].position = TPosition(m_renderRect.right - 0.5f, m_renderRect.bottom - 0.5f, 0.0f);
pVertices[3].texCoord = TTextureCoordinate(eu, ev);
pVertices[3].diffuse = 0xffffffff;
if (SetPDTStream(pVertices, 4))
{
SetDefaultIndexBuffer(DEFAULT_IB_FILL_RECT);
STATEMANAGER.SetTexture(0, GetRenderTargetTexture());
STATEMANAGER.SetTexture(1, nullptr);
STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_DIFFUSE);
STATEMANAGER.DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
}
}
void CGraphicRenderTargetTexture::Reset()
{
Destroy();
ReleaseTextures();
m_d3dFormat = D3DFMT_UNKNOWN;
m_depthStencilFormat = D3DFMT_UNKNOWN;
}
@@ -0,0 +1,36 @@
#pragma once
#include "GrpBase.h"
#include "GrpTexture.h"
class CGraphicRenderTargetTexture : public CGraphicTexture
{
public:
CGraphicRenderTargetTexture();
virtual ~CGraphicRenderTargetTexture();
public:
bool Create(int width, int height, D3DFORMAT texFormat, D3DFORMAT depthFormat);
void CreateTextures();
bool CreateRenderTexture(int width, int height, D3DFORMAT format);
bool CreateRenderDepthStencil(int width, int height, D3DFORMAT format);
void SetRenderTarget();
void ResetRenderTarget();
void SetRenderingRect(RECT* rect);
RECT* GetRenderingRect();
LPDIRECT3DTEXTURE8 GetRenderTargetTexture() const;
void ReleaseTextures();
static void Clear();
void Render() const;
protected:
void Reset();
LPDIRECT3DTEXTURE8 m_lpd3dRenderTexture{};
LPDIRECT3DSURFACE8 m_lpd3dRenderTargetSurface{};
LPDIRECT3DSURFACE8 m_lpd3dDepthSurface{};
LPDIRECT3DSURFACE8 m_lpd3dOriginalRenderTarget{};
LPDIRECT3DSURFACE8 m_lpd3dOldDepthBufferSurface{};
D3DFORMAT m_d3dFormat;
D3DFORMAT m_depthStencilFormat;
RECT m_renderRect{};
};