Model preview: AVA2 render-target window on a Vulkan colour target
Port of AVA2's CRenderTarget / GrpRenderTargetTexture / renderTarget module. The host gains an RGBA8 offscreen colour pass for D3D colour render targets; mt_preview shows wearable items on every allowed race and monsters with motions, reached by X+click in the inventory and shop and from the wiki. Player races are created as TYPE_PC so their parts exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
32372c2a73
commit
84404cf1f1
@@ -0,0 +1,324 @@
|
||||
#include "StdAfx.h"
|
||||
#include "CRenderTarget.h"
|
||||
#include "InstanceBase.h"
|
||||
|
||||
#include "../EterLib/Camera.h"
|
||||
#include "../EterLib/GrpImageInstance.h"
|
||||
#include "../EterLib/ResourceManager.h"
|
||||
#include "../EterLib/StateManager.h"
|
||||
#include "../EterPythonLib/PythonGraphic.h"
|
||||
|
||||
CRenderTarget::~CRenderTarget() {}
|
||||
|
||||
CRenderTarget::CRenderTarget(const DWORD width, const DWORD height) :
|
||||
m_pModel(nullptr),
|
||||
m_background(nullptr),
|
||||
m_modelRotation(0),
|
||||
m_pmodelRotationActive(true),
|
||||
m_visible(false),
|
||||
m_bShowModel(true),
|
||||
m_bScale(1.0),
|
||||
m_v3AngularVelocity(0.0f, 0.0f, 0.0f),
|
||||
m_v3Eye(0.0f, 0.0f, 0.0f),
|
||||
m_v3Target(0.0f, 0.0f, 0.0f),
|
||||
m_v3Up(0.0f, 0.0f, 1.0f)
|
||||
{
|
||||
auto pTex = std::make_unique<CGraphicRenderTargetTexture>();
|
||||
if (!pTex->Create(width, height, D3DFMT_X8R8G8B8, D3DFMT_D16))
|
||||
{
|
||||
TraceError("CRenderTarget::CRenderTarget: Could not create CGraphicRenderTargetTexture %dx%d", width, height);
|
||||
throw std::runtime_error("CRenderTarget::CRenderTarget: Could not create CGraphicRenderTargetTexture");
|
||||
}
|
||||
|
||||
m_renderTargetTexture = std::move(pTex);
|
||||
}
|
||||
|
||||
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::ResetModel()
|
||||
{
|
||||
// PORT: AVA2 also cleared its wiki affects here; the port has none.
|
||||
m_pModel.reset();
|
||||
}
|
||||
|
||||
void CRenderTarget::SetScale(float fScale)
|
||||
{
|
||||
m_bScale = fScale;
|
||||
if (IsReady())
|
||||
SelectModel(m_pModel->GetRace(), true);
|
||||
}
|
||||
|
||||
void CRenderTarget::SelectModel(const int index, bool isFromScale)
|
||||
{
|
||||
if (m_pModel && !isFromScale && m_pModel->GetRace() == index)
|
||||
return;
|
||||
|
||||
if (isFromScale && m_pModel)
|
||||
m_pModel.reset();
|
||||
|
||||
CInstanceBase::SCreateData kCreateData{};
|
||||
// PORT: AVA2 created every model as TYPE_NPC. Here CActorInstance reserves the armor/weapon/hair parts for
|
||||
// TYPE_PC only, so a player race created as an NPC crashes on the first ChangeArmor.
|
||||
kCreateData.m_bType = index < NRaceData::JOB_MAX_NUM * 2 ? CActorInstance::TYPE_PC : CActorInstance::TYPE_NPC;
|
||||
kCreateData.m_dwRace = index;
|
||||
auto model = std::make_unique<CInstanceBase>();
|
||||
if (!model->Create(kCreateData))
|
||||
{
|
||||
ResetModel();
|
||||
return;
|
||||
}
|
||||
m_pModel = std::move(model);
|
||||
// PORT: the preview has no name; the empty text tail Create attaches would follow the world origin.
|
||||
m_pModel->DetachTextTail();
|
||||
m_pModel->NEW_SetPixelPosition(TPixelPosition(0, 0, 0));
|
||||
m_pModel->SetRotation(0.0f);
|
||||
|
||||
float fTargetHeight = 110.0f;
|
||||
|
||||
m_v3Eye.x = 0.0f;
|
||||
m_v3Eye.y = -1000.0f;
|
||||
m_v3Eye.z = 600.0f;
|
||||
|
||||
m_v3Target.x = 0.0f;
|
||||
m_v3Target.y = 0.0f;
|
||||
m_v3Target.z = 95.0f;
|
||||
|
||||
if (index > (NRaceData::JOB_MAX_NUM * 2))
|
||||
{
|
||||
const auto ptrGraphicInstance = m_pModel->GetGraphicThingInstancePtr();
|
||||
if (ptrGraphicInstance) {
|
||||
const float fRaceHeight = (ptrGraphicInstance->GetHeight()/m_bScale);
|
||||
fTargetHeight = fRaceHeight / 2.0f;
|
||||
m_v3Eye.y = -(fRaceHeight * 8.9f);
|
||||
m_v3Eye.z = 0.0f;
|
||||
m_v3Target.z = fRaceHeight / 2.0f;
|
||||
}
|
||||
}
|
||||
|
||||
auto& camera_manager = CCameraManager::instance();
|
||||
camera_manager.SetCurrentCamera(CCameraManager::DEFAULT_ORTHO_CAMERA);
|
||||
camera_manager.GetCurrentCamera()->SetTargetHeight(fTargetHeight);
|
||||
camera_manager.ResetToPreviousCamera();
|
||||
m_modelRotation = 0.0f;
|
||||
m_v3AngularVelocity = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
// PORT: AVA2 drew its background in a pass of its own through CGraphicImageInstance::Render. The port's image
|
||||
// instance goes to the UI command list, not the device, so RenderModel draws the background into the target
|
||||
// itself: one textured quad that fills it under a target-sized ortho.
|
||||
void CRenderTarget::RenderBackground() const
|
||||
{
|
||||
if (!m_background || m_background->IsEmpty())
|
||||
return;
|
||||
CGraphicTexture* texture = m_background->GetTexturePointer();
|
||||
if (!texture)
|
||||
return;
|
||||
|
||||
const auto& rectRender = *m_renderTargetTexture->GetRenderingRect();
|
||||
const auto width = static_cast<float>(rectRender.right - rectRender.left);
|
||||
const auto height = static_cast<float>(rectRender.bottom - rectRender.top);
|
||||
|
||||
auto& python_graphic = CPythonGraphic::Instance();
|
||||
python_graphic.PushState();
|
||||
STATEMANAGER.SaveTransform(D3DTS_WORLD, &CGraphicBase::GetIdentityMatrix());
|
||||
STATEMANAGER.SetTransform(D3DTS_VIEW, &CGraphicBase::GetIdentityMatrix());
|
||||
python_graphic.SetOrtho2D(width, height, 1.0f);
|
||||
|
||||
STATEMANAGER.SaveRenderState(D3DRS_ZENABLE, FALSE);
|
||||
STATEMANAGER.SaveRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
||||
STATEMANAGER.SaveRenderState(D3DRS_LIGHTING, FALSE);
|
||||
STATEMANAGER.SaveRenderState(D3DRS_FOGENABLE, FALSE);
|
||||
STATEMANAGER.SaveRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
|
||||
STATEMANAGER.SaveRenderState(D3DRS_ALPHATESTENABLE, FALSE);
|
||||
STATEMANAGER.SaveRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
STATEMANAGER.SaveTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_NONE);
|
||||
STATEMANAGER.SaveTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
|
||||
TPDTVertex vertices[4];
|
||||
const float x[4] = { 0.0f, width, 0.0f, width };
|
||||
const float y[4] = { 0.0f, 0.0f, height, height };
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
vertices[i].position = TPosition(x[i], y[i], 0.0f);
|
||||
vertices[i].texCoord = TTextureCoordinate(x[i] / width, y[i] / height);
|
||||
vertices[i].diffuse = 0xffffffff;
|
||||
}
|
||||
STATEMANAGER.SetTexture(0, texture->GetD3DTexture());
|
||||
STATEMANAGER.SetTexture(1, nullptr);
|
||||
STATEMANAGER.SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_DIFFUSE);
|
||||
STATEMANAGER.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(TPDTVertex));
|
||||
|
||||
STATEMANAGER.RestoreTextureStageState(1, D3DTSS_COLOROP);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MIPFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MAGFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_MINFILTER);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_ALPHAOP);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLOROP);
|
||||
STATEMANAGER.RestoreTextureStageState(0, D3DTSS_COLORARG1);
|
||||
STATEMANAGER.RestoreRenderState(D3DRS_CULLMODE);
|
||||
STATEMANAGER.RestoreRenderState(D3DRS_ALPHATESTENABLE);
|
||||
STATEMANAGER.RestoreRenderState(D3DRS_ALPHABLENDENABLE);
|
||||
STATEMANAGER.RestoreRenderState(D3DRS_FOGENABLE);
|
||||
STATEMANAGER.RestoreRenderState(D3DRS_LIGHTING);
|
||||
STATEMANAGER.RestoreRenderState(D3DRS_ZWRITEENABLE);
|
||||
STATEMANAGER.RestoreRenderState(D3DRS_ZENABLE);
|
||||
STATEMANAGER.RestoreTransform(D3DTS_WORLD);
|
||||
python_graphic.PopState();
|
||||
}
|
||||
|
||||
void CRenderTarget::UpdateModel()
|
||||
{
|
||||
if (!IsReady())
|
||||
return;
|
||||
|
||||
if (m_pmodelRotationActive && m_bShowModel)
|
||||
{
|
||||
if (m_modelRotation < 360.0f)
|
||||
m_modelRotation += 1.0f / 60 * 60.0f;
|
||||
else
|
||||
m_modelRotation = 0.0f / 60 * 60.0f;
|
||||
|
||||
m_pModel->SetRotation(m_modelRotation);
|
||||
}
|
||||
else
|
||||
m_pModel->SetRotation(0.0f);
|
||||
m_pModel->Transform();
|
||||
if(m_pmodelRotationActive)
|
||||
m_pModel->GetGraphicThingInstanceRef().RotationProcess();
|
||||
}
|
||||
|
||||
void CRenderTarget::DeformModel()
|
||||
{
|
||||
if (!IsReady())
|
||||
return;
|
||||
// PORT: stands in for AVA2's SetAlwaysRender. The model sits at the world origin, so the culling pass hides it.
|
||||
m_pModel->GetGraphicThingInstanceRef().Show();
|
||||
m_pModel->Deform();
|
||||
}
|
||||
|
||||
void CRenderTarget::RenderModel()
|
||||
{
|
||||
if (!IsReady())
|
||||
return;
|
||||
|
||||
auto& python_graphic = CPythonGraphic::Instance();
|
||||
auto& camera_manager = CCameraManager::instance();
|
||||
auto& state_manager = CStateManager::Instance();
|
||||
auto& rectRender = *m_renderTargetTexture->GetRenderingRect();
|
||||
|
||||
const auto width = static_cast<float>(rectRender.right - rectRender.left);
|
||||
const auto height = static_cast<float>(rectRender.bottom - rectRender.top);
|
||||
// PORT: nothing to draw before the window has given its rect.
|
||||
if (width <= 0.0f || height <= 0.0f)
|
||||
return;
|
||||
|
||||
m_renderTargetTexture->SetRenderTarget();
|
||||
m_renderTargetTexture->Clear();
|
||||
python_graphic.SetViewport(0.0f, 0.0f, width, height);
|
||||
RenderBackground();
|
||||
|
||||
python_graphic.ClearDepthBuffer();
|
||||
|
||||
const auto fov = python_graphic.GetFOV();
|
||||
const auto aspect = python_graphic.GetAspect();
|
||||
float near_y, far_y;
|
||||
python_graphic.GetClipPlane(&near_y, &far_y);
|
||||
|
||||
state_manager.SetRenderState(D3DRS_FOGENABLE, FALSE);
|
||||
|
||||
python_graphic.PushState();
|
||||
|
||||
camera_manager.SetCurrentCamera(CCameraManager::DEFAULT_ORTHO_CAMERA);
|
||||
camera_manager.GetCurrentCamera()->SetViewParams(m_v3Eye, m_v3Target, m_v3Up);
|
||||
camera_manager.GetCurrentCamera()->RotateEyeAroundTarget(m_v3AngularVelocity.z, m_v3AngularVelocity.x);
|
||||
|
||||
python_graphic.UpdateViewMatrix();
|
||||
python_graphic.SetPerspective(10.0f, width / height, 100.0f, 15000.0f);
|
||||
|
||||
if (m_bShowModel)
|
||||
{
|
||||
m_pModel->GetGraphicThingInstanceRef().Show();
|
||||
m_pModel->Update();
|
||||
m_pModel->Render();
|
||||
}
|
||||
// PORT: AVA2's RenderAllAttachingEffectWiki (attached effects) is not ported.
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void CRenderTarget::SetModelV3Eye(float x, float y, float z)
|
||||
{
|
||||
m_v3Eye.x = x;
|
||||
m_v3Eye.y = y;
|
||||
m_v3Eye.z = z;
|
||||
}
|
||||
|
||||
void CRenderTarget::SetModelV3Target(float x, float y, float z)
|
||||
{
|
||||
m_v3Target.x = x;
|
||||
m_v3Target.y = y;
|
||||
m_v3Target.z = z;
|
||||
}
|
||||
|
||||
void CRenderTarget::RotateEyeAroundTarget(float fPitchDegree, float fRollDegree)
|
||||
{
|
||||
m_v3AngularVelocity.x = fRollDegree;
|
||||
m_v3AngularVelocity.z = fPitchDegree;
|
||||
}
|
||||
|
||||
void CRenderTarget::Zoom(float fRatio)
|
||||
{
|
||||
if (fRatio == 1.0f)
|
||||
return;
|
||||
D3DXVECTOR3 v3Temp = m_v3Eye - m_v3Target;
|
||||
v3Temp *= fRatio;
|
||||
m_v3Eye = v3Temp + m_v3Target;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
// PORT: AVA2 CRenderTarget (EterLib/CRenderTarget.h): one model drawn into its own colour render target, which
|
||||
// a UI window then shows. It lives here, not in EterLib, because it owns a CInstanceBase.
|
||||
#include <memory>
|
||||
#include "../EterLib/GrpRenderTargetTexture.h"
|
||||
|
||||
class CInstanceBase;
|
||||
class CGraphicImageInstance;
|
||||
|
||||
class CRenderTarget
|
||||
{
|
||||
public:
|
||||
CRenderTarget(DWORD width, DWORD height);
|
||||
~CRenderTarget();
|
||||
|
||||
void SetVisibility(bool isShow){ m_visible = isShow; }
|
||||
void SetRotation(bool bRot) { m_pmodelRotationActive = bRot; }
|
||||
bool IsReady() { return (m_visible && m_pModel); }
|
||||
std::unique_ptr<CInstanceBase>& GetModel() { return m_pModel; }
|
||||
|
||||
void RotateEyeAroundTarget(float fPitchDegree, float fRollDegree);
|
||||
void Zoom(float fRatio);
|
||||
|
||||
void SelectModel(int index, bool isFromScale= false);
|
||||
void ResetModel();
|
||||
|
||||
void UpdateModel();
|
||||
void DeformModel();
|
||||
void RenderModel();
|
||||
void SetRenderingRect(RECT* rect) const;
|
||||
|
||||
void CreateTextures() const;
|
||||
void ReleaseTextures() const;
|
||||
void RenderTexture() const;
|
||||
|
||||
bool CreateBackground(const char* imgPath, DWORD width, DWORD height);
|
||||
void RenderBackground() const;
|
||||
|
||||
void SetModelV3Eye(float x, float y, float z);
|
||||
void SetModelV3Target(float x, float y, float z);
|
||||
|
||||
void SetModelStatus(bool bStatus) { m_bShowModel = bStatus; }
|
||||
|
||||
float GetScale() { return m_bScale; }
|
||||
void SetScale(float fScale);
|
||||
|
||||
bool IsShow() { return m_visible; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<CInstanceBase> m_pModel;
|
||||
std::unique_ptr<CGraphicImageInstance> m_background;
|
||||
std::unique_ptr<CGraphicRenderTargetTexture> m_renderTargetTexture;
|
||||
float m_modelRotation;
|
||||
bool m_pmodelRotationActive;
|
||||
bool m_visible;
|
||||
bool m_bShowModel;
|
||||
float m_bScale;
|
||||
D3DXVECTOR3 m_v3AngularVelocity;
|
||||
D3DXVECTOR3 m_v3Eye;
|
||||
D3DXVECTOR3 m_v3Target;
|
||||
D3DXVECTOR3 m_v3Up;
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
#include "StdAfx.h"
|
||||
#include "CRenderTargetManager.h"
|
||||
#include "../EterBase/Stl.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();
|
||||
}
|
||||
// PORT: the background is drawn into the target by RenderModel (CRenderTarget::RenderBackground).
|
||||
void CRenderTargetManager::RenderBackgrounds()
|
||||
{
|
||||
}
|
||||
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 int index, const int width, const int height)
|
||||
{
|
||||
// PORT: the size check guards the recording device, which allocates the target's bytes up front.
|
||||
if (index < 1 || GetRenderTarget(index) || width < 1 || height < 1 || width > 2048 || height > 2048)
|
||||
return false;
|
||||
try
|
||||
{
|
||||
m_renderTargets.emplace(index, std::make_shared<CRenderTarget>(width, height));
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void CRenderTargetManager::RemoveRenderTarget(const int index)
|
||||
{
|
||||
const auto it = m_renderTargets.find(index);
|
||||
if (it != m_renderTargets.end())
|
||||
{
|
||||
it->second->ResetModel();
|
||||
m_renderTargets.erase(index);
|
||||
}
|
||||
}
|
||||
std::shared_ptr<CRenderTarget> CRenderTargetManager::GetRenderTarget(const int index)
|
||||
{
|
||||
const auto it = m_renderTargets.find(index);
|
||||
if (it != m_renderTargets.end())
|
||||
return it->second;
|
||||
return nullptr;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
// PORT: AVA2 CRenderTargetManager (EterLib/CRenderTargetManager.h).
|
||||
#include <unordered_map>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../EterBase/Singleton.h"
|
||||
#include <memory>
|
||||
#include "CRenderTarget.h"
|
||||
|
||||
class CRenderTargetManager : public CSingleton<CRenderTargetManager>
|
||||
{
|
||||
public:
|
||||
CRenderTargetManager();
|
||||
virtual ~CRenderTargetManager();
|
||||
|
||||
std::shared_ptr<CRenderTarget> GetRenderTarget(int index);
|
||||
bool CreateRenderTarget(int index, int width, int height);
|
||||
|
||||
void CreateRenderTargetTextures();
|
||||
void ReleaseRenderTargetTextures();
|
||||
|
||||
void RemoveRenderTarget(const int index);
|
||||
void Destroy();
|
||||
void DeformModels();
|
||||
void UpdateModels();
|
||||
void RenderBackgrounds();
|
||||
void RenderModels();
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, std::shared_ptr<CRenderTarget>> m_renderTargets;
|
||||
};
|
||||
@@ -0,0 +1,282 @@
|
||||
// PORT: AVA2 CPythonRenderTargetModule (module renderTarget), the subset the model preview uses. AVA2's window
|
||||
// manager created the target for a registered window and drew it; here Create and RenderTexture do that, called
|
||||
// from the script's own window (ScriptLib/ModelPreviewScript.inc).
|
||||
#include "StdAfx.h"
|
||||
#include "CRenderTargetManager.h"
|
||||
#include "InstanceBase.h"
|
||||
#include "../GameLib/ItemManager.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
// The default of CPythonApplication's camera zoom speed (PythonApplicationCamera.cpp), which AVA2 read.
|
||||
const float c_fRenderTargetZoomSpeed = 0.05f;
|
||||
|
||||
std::shared_ptr<CRenderTarget> Target(PyObject* poArgs)
|
||||
{
|
||||
int iIndex;
|
||||
if (!PyTuple_GetInteger(poArgs, 0, &iIndex))
|
||||
return nullptr;
|
||||
return CRenderTargetManager::Instance().GetRenderTarget(iIndex);
|
||||
}
|
||||
|
||||
bool Integer(PyObject* poArgs, int pos, int* value)
|
||||
{
|
||||
return PyTuple_GetInteger(poArgs, pos, value);
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* renderTargetCreate(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iIndex, iWidth, iHeight;
|
||||
if (!Integer(poArgs, 0, &iIndex) || !Integer(poArgs, 1, &iWidth) || !Integer(poArgs, 2, &iHeight))
|
||||
return Py_BadArgument();
|
||||
return Py_BuildValue("i", CRenderTargetManager::Instance().CreateRenderTarget(iIndex, iWidth, iHeight) ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject* renderTargetRemove(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iIndex;
|
||||
if (!Integer(poArgs, 0, &iIndex))
|
||||
return Py_BadArgument();
|
||||
CRenderTargetManager::Instance().RemoveRenderTarget(iIndex);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetExists(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iIndex;
|
||||
if (!Integer(poArgs, 0, &iIndex))
|
||||
return Py_BadArgument();
|
||||
return Py_BuildValue("i", CRenderTargetManager::Instance().GetRenderTarget(iIndex) ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject* renderTargetRenderTexture(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int l, t, r, b;
|
||||
if (!Integer(poArgs, 1, &l) || !Integer(poArgs, 2, &t) || !Integer(poArgs, 3, &r) || !Integer(poArgs, 4, &b))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target && target->IsShow())
|
||||
{
|
||||
RECT rect = { l, t, r, b };
|
||||
target->SetRenderingRect(&rect);
|
||||
target->RenderTexture();
|
||||
}
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSelectModel(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int modelIndex;
|
||||
if (!Integer(poArgs, 1, &modelIndex))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target)
|
||||
target->SelectModel(modelIndex);
|
||||
return Py_BuildValue("i", target && target->GetModel() ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetArmor(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iItemVnum;
|
||||
if (!Integer(poArgs, 1, &iItemVnum))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target && target->IsReady())
|
||||
target->GetModel()->ChangeArmor(iItemVnum);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetWeapon(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iItemVnum;
|
||||
if (!Integer(poArgs, 1, &iItemVnum))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target && target->IsReady())
|
||||
target->GetModel()->ChangeWeapon(iItemVnum);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetHair(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iItemVnum;
|
||||
if (!Integer(poArgs, 1, &iItemVnum))
|
||||
return Py_BadArgument();
|
||||
bool isValue = false;
|
||||
const auto target = Target(poArgs);
|
||||
if (target)
|
||||
{
|
||||
PyTuple_GetBoolean(poArgs, 2, &isValue);
|
||||
if (!isValue)
|
||||
{
|
||||
CItemData* pItemData;
|
||||
if (!CItemManager::Instance().GetItemDataPointer(iItemVnum, &pItemData))
|
||||
return Py_BuildNone();
|
||||
iItemVnum = pItemData->GetValue(3);
|
||||
}
|
||||
if (target->IsReady())
|
||||
target->GetModel()->SetHair(iItemVnum);
|
||||
}
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetMount(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iRace;
|
||||
if (!Integer(poArgs, 1, &iRace))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target && target->IsReady())
|
||||
target->GetModel()->MountHorse(iRace);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetRotation(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
bool bRot;
|
||||
if (!PyTuple_GetBoolean(poArgs, 1, &bRot))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target)
|
||||
target->SetRotation(bRot);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetVisibility(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
bool isShow;
|
||||
if (!PyTuple_GetBoolean(poArgs, 1, &isShow))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target)
|
||||
target->SetVisibility(isShow);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetBackground(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
char* szPathName;
|
||||
if (!PyTuple_GetString(poArgs, 1, &szPathName))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
// PORT: the background is stretched over the target when drawn, so the sizes AVA2 passed are unused.
|
||||
return Py_BuildValue("i", target && target->CreateBackground(szPathName, 0, 0) ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject* renderTargetResetModel(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
const auto target = Target(poArgs);
|
||||
if (target)
|
||||
target->ResetModel();
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetDestroy(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
CRenderTargetManager::Instance().Destroy();
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetModelV3Eye(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
float x, y, z;
|
||||
if (!PyTuple_GetFloat(poArgs, 1, &x) || !PyTuple_GetFloat(poArgs, 2, &y) || !PyTuple_GetFloat(poArgs, 3, &z))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target)
|
||||
target->SetModelV3Eye(x, y, z);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetModelV3Target(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
float x, y, z;
|
||||
if (!PyTuple_GetFloat(poArgs, 1, &x) || !PyTuple_GetFloat(poArgs, 2, &y) || !PyTuple_GetFloat(poArgs, 3, &z))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target)
|
||||
target->SetModelV3Target(x, y, z);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetZoom(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iDirection;
|
||||
if (!Integer(poArgs, 1, &iDirection))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target && target->IsReady())
|
||||
target->Zoom(1.0f + c_fRenderTargetZoomSpeed * float(iDirection));
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetRotateEyeAroundTarget(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
float fPitch, fRoll;
|
||||
if (!PyTuple_GetFloat(poArgs, 1, &fPitch) || !PyTuple_GetFloat(poArgs, 2, &fRoll))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target && target->IsReady())
|
||||
target->RotateEyeAroundTarget(fPitch, fRoll);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetScale(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
float fScale;
|
||||
if (!PyTuple_GetFloat(poArgs, 1, &fScale))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target)
|
||||
target->SetScale(fScale);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* renderTargetIsShow(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
const auto target = Target(poArgs);
|
||||
return Py_BuildValue("i", target ? target->IsShow() : 0);
|
||||
}
|
||||
|
||||
PyObject* renderTargetSetMotionIndex(PyObject* poSelf, PyObject* poArgs)
|
||||
{
|
||||
int iMotionIndex;
|
||||
if (!Integer(poArgs, 1, &iMotionIndex))
|
||||
return Py_BadArgument();
|
||||
const auto target = Target(poArgs);
|
||||
if (target && target->IsReady())
|
||||
return Py_BuildValue("i", target->GetModel()->GetGraphicThingInstanceRef().InterceptOnceMotion(iMotionIndex) ? 1 : 0);
|
||||
return Py_BuildValue("i", 0);
|
||||
}
|
||||
|
||||
void initRenderTarget()
|
||||
{
|
||||
static PyMethodDef s_methods[] =
|
||||
{
|
||||
{ "Create", renderTargetCreate, METH_VARARGS },
|
||||
{ "Remove", renderTargetRemove, METH_VARARGS },
|
||||
{ "Exists", renderTargetExists, METH_VARARGS },
|
||||
{ "RenderTexture", renderTargetRenderTexture, METH_VARARGS },
|
||||
{ "SelectModel", renderTargetSelectModel, METH_VARARGS },
|
||||
{ "SetVisibility", renderTargetSetVisibility, METH_VARARGS },
|
||||
{ "SetBackground", renderTargetSetBackground, METH_VARARGS },
|
||||
{ "SetArmor", renderTargetSetArmor, METH_VARARGS },
|
||||
{ "SetWeapon", renderTargetSetWeapon, METH_VARARGS },
|
||||
{ "SetHair", renderTargetSetHair, METH_VARARGS },
|
||||
{ "SetMount", renderTargetSetMount, METH_VARARGS },
|
||||
{ "SetRotation", renderTargetSetRotation, METH_VARARGS },
|
||||
{ "ResetModel", renderTargetResetModel, METH_VARARGS },
|
||||
{ "Destroy", renderTargetDestroy, METH_VARARGS },
|
||||
{ "SetModelV3Eye", renderTargetSetModelV3Eye, METH_VARARGS },
|
||||
{ "SetModelV3Target", renderTargetSetModelV3Target, METH_VARARGS },
|
||||
{ "Zoom", renderTargetZoom, METH_VARARGS },
|
||||
{ "RotateEyeAroundTarget", renderTargetRotateEyeAroundTarget, METH_VARARGS },
|
||||
{ "SetScale", renderTargetSetScale, METH_VARARGS },
|
||||
{ "IsShow", renderTargetIsShow, METH_VARARGS },
|
||||
{ "SetMotionIndex", renderTargetSetMotionIndex, METH_VARARGS },
|
||||
{ NULL, NULL, 0 },
|
||||
};
|
||||
|
||||
Py_InitModule("renderTarget", s_methods);
|
||||
}
|
||||
@@ -70,6 +70,7 @@ void initMessenger();
|
||||
void initsafebox();
|
||||
void initguild();
|
||||
void initServerStateChecker();
|
||||
void initRenderTarget(); // PORT: AVA2 CPythonRenderTargetModule
|
||||
|
||||
extern const std::string& ApplicationStringTable_GetString(DWORD dwID);
|
||||
extern const std::string& ApplicationStringTable_GetString(DWORD dwID, LPCSTR szKey);
|
||||
|
||||
Reference in New Issue
Block a user