Fix cross-platform rendering and optimize frame performance
Correct selection orientation, game-entry lifecycle, mounted NPCs, labels and skill panels. Add the native GPU scene path, resident geometry, bounded texture and Python caches, and collision broad phase. Pin the independently maintained Metin2 SDK through a submodule and document reproducible setup. Include rendering regressions and macOS packaging improvements. Validation: client Debug build and 12 targeted client tests passed; SDK build and all 14 SDK tests passed.
This commit is contained in:
@@ -22,6 +22,15 @@ EffectInstance::EffectInstance(std::shared_ptr<EffectData> data)
|
||||
EffectInstance::~EffectInstance() = default;
|
||||
|
||||
void EffectInstance::SetPosition(float x, float y, float z) {
|
||||
// Attached particles follow their owner; non-attached trails remain in world space.
|
||||
if (m_data) for (size_t i = 0; i < m_emitters.size(); ++i) {
|
||||
if (!m_data->GetParticles()[i].particle.attach_enable) continue;
|
||||
for (auto& p : m_emitters[i].particles) for (int axis = 0; axis < 3; ++axis) {
|
||||
const float next[3] = {x,y,z};
|
||||
const float delta = next[axis] - m_position[axis];
|
||||
p.pos[axis] += delta; p.last_pos[axis] += delta;
|
||||
}
|
||||
}
|
||||
m_position[0] = x;
|
||||
m_position[1] = y;
|
||||
m_position[2] = z;
|
||||
@@ -99,6 +108,9 @@ void EffectInstance::Update(float dt) {
|
||||
}
|
||||
|
||||
for (int s = 0; s < toSpawn && s < 20; ++s) {
|
||||
// MaxEmissionCount is the number of live particles, including
|
||||
// looping emitters (the GM marker has exactly one particle).
|
||||
if (inst.particles.size() >= maxEmission) break;
|
||||
ParticleState p;
|
||||
p.life = 0.0f;
|
||||
p.max_life = InterpolateTimeEvent(pe.emitter.time_life_time, cycleTime, 0.5f);
|
||||
@@ -126,10 +138,8 @@ void EffectInstance::Update(float dt) {
|
||||
float dirX = InterpolateTimeEvent(pe.emitter.time_emitting_dir_x, cycleTime, pe.emitter.emitting_direction[0]);
|
||||
float dirY = InterpolateTimeEvent(pe.emitter.time_emitting_dir_y, cycleTime, pe.emitter.emitting_direction[1]);
|
||||
float dirZ = InterpolateTimeEvent(pe.emitter.time_emitting_dir_z, cycleTime, pe.emitter.emitting_direction[2]);
|
||||
float dirLen = std::sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
|
||||
if (dirLen > 1e-4f) {
|
||||
dirX /= dirLen; dirY /= dirLen; dirZ /= dirLen;
|
||||
}
|
||||
// AVA2 adds the scripted direction vector and then multiplies by
|
||||
// velocity. Its magnitude is intentional (GM: 14.948454 * 3).
|
||||
|
||||
// Transform velocity vector by rotation matrix
|
||||
float worldDirX = dirX * m_matrix[0] + dirY * m_matrix[4] + dirZ * m_matrix[8];
|
||||
@@ -169,7 +179,8 @@ void EffectInstance::Update(float dt) {
|
||||
|
||||
// Gravity
|
||||
float grav = InterpolateTimeEvent(pe.particle.time_gravity, t, 0.0f);
|
||||
it->vel[1] -= grav * 9.8f * dt;
|
||||
// AVA2 CGravityDecorator: script gravity is already acceleration.
|
||||
it->vel[1] -= grav * dt;
|
||||
|
||||
// Air resistance
|
||||
float airRes = InterpolateTimeEvent(pe.particle.time_air_resistance, t, 0.0f);
|
||||
@@ -271,8 +282,14 @@ void EffectInstance::BuildDrawCommands(const float* viewMatrix, const float* pro
|
||||
const auto& p = inst.particles[pIdx];
|
||||
if (p.color[3] <= 0.001f) continue;
|
||||
|
||||
float hx = baseSizeX * p.scale[0] * 0.5f;
|
||||
float hy = baseSizeY * p.scale[1] * 0.5f;
|
||||
// AVA2 scripts specify half sizes, not full dimensions.
|
||||
float hx = baseSizeX * p.scale[0];
|
||||
float hy = baseSizeY * p.scale[1];
|
||||
if (pe.particle.billboard_type <= 1 && !pe.particle.stretch_enable) {
|
||||
// CParticleInstance::Transform places size Y on the camera
|
||||
// cross axis (texture U), and size X on camera up (texture V).
|
||||
std::swap(hx, hy);
|
||||
}
|
||||
|
||||
float right[3] = {camRight[0], camRight[1], camRight[2]};
|
||||
float up[3] = {camUp[0], camUp[1], camUp[2]};
|
||||
@@ -318,7 +335,7 @@ void EffectInstance::BuildDrawCommands(const float* viewMatrix, const float* pro
|
||||
float p0[3] = {p.pos[0] - right[0]*hx - up[0]*hy, p.pos[1] - right[1]*hx - up[1]*hy, p.pos[2] - right[2]*hx - up[2]*hy};
|
||||
float p1[3] = {p.pos[0] + right[0]*hx - up[0]*hy, p.pos[1] + right[1]*hx - up[1]*hy, p.pos[2] + right[2]*hx - up[2]*hy};
|
||||
float p2[3] = {p.pos[0] + right[0]*hx + up[0]*hy, p.pos[1] + right[1]*hx + up[1]*hy, p.pos[2] + right[2]*hx + up[2]*hy};
|
||||
float p3[3] = {p.pos[0] - right[0]*hx + up[0]*hy, p.pos[1] - right[1]*hx + up[0]*hy, p.pos[2] - right[2]*hx + up[2]*hy};
|
||||
float p3[3] = {p.pos[0] - right[0]*hx + up[0]*hy, p.pos[1] - right[1]*hx + up[1]*hy, p.pos[2] - right[2]*hx + up[2]*hy};
|
||||
|
||||
uint8_t cr = static_cast<uint8_t>(std::clamp(p.color[0] * 255.0f, 0.0f, 255.0f));
|
||||
uint8_t cg = static_cast<uint8_t>(std::clamp(p.color[1] * 255.0f, 0.0f, 255.0f));
|
||||
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
void Destroy()
|
||||
{
|
||||
CGraphicImageInstance::Destroy();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void SetDepth(float fDepth) { m_fDepth = fDepth; }
|
||||
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
void Destroy()
|
||||
{
|
||||
m_roImage.Clear();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
void Render()
|
||||
|
||||
@@ -27,7 +27,7 @@ std::string FindMarkFile(const std::string& relPath) {
|
||||
relPath,
|
||||
"build/dev/" + relPath,
|
||||
"../" + relPath,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/" + relPath
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/1. Client DEV/" + relPath
|
||||
};
|
||||
for (const auto& c : candidates) {
|
||||
if (std::filesystem::exists(c)) return c;
|
||||
|
||||
@@ -15,6 +15,28 @@ namespace ava2 {
|
||||
|
||||
namespace {
|
||||
|
||||
// AVA2 InstanceBase.cpp SHORSE::Create / __AttachHorseSaddle: mounts are
|
||||
// separate actors, and the rider's main model follows their "saddle" bone.
|
||||
void ConfigureMount(SNetworkActorData& data) {
|
||||
if (!data.m_pActorInstance || data.m_mountRaceRequested == data.m_dwMountVnum) return;
|
||||
data.m_mountRaceRequested = data.m_dwMountVnum;
|
||||
data.m_pMountInstance.reset();
|
||||
auto& rider=*data.m_pActorInstance;
|
||||
rider.SetModelYOffset(0);
|
||||
if (data.m_dwMountVnum) {
|
||||
auto mount=std::make_shared<ActorInstance>();
|
||||
if (mount->SetRace(data.m_dwMountVnum)) {
|
||||
mount->SetShape(0);mount->SetScale(rider.GetScale());
|
||||
mount->SetYaw(rider.GetYaw());mount->SetPosition(rider.GetX(),rider.GetY(),rider.GetZ());
|
||||
mount->PlayMotion(MotionType::Wait,true);
|
||||
data.m_pMountInstance=std::move(mount);
|
||||
}
|
||||
}
|
||||
const uint16_t mode=data.m_pMountInstance ? 9 : 1;
|
||||
rider.SetMotionMode(mode);
|
||||
rider.PlayMotion(MotionType::Wait,true);
|
||||
}
|
||||
|
||||
// InstanceBaseEffect.cpp g_akD3DXClrName / g_akD3DXClrTitle / g_TitleNameMap: zero (transparent
|
||||
// black) until introLoading.__main__ registers them through chrmgr.
|
||||
std::array<uint32_t, NetworkActorManager::NAMECOLOR_NUM>& NameColors() { static std::array<uint32_t, NetworkActorManager::NAMECOLOR_NUM> s{}; return s; }
|
||||
@@ -26,7 +48,7 @@ bool (*s_getItemScale)(uint32_t, uint32_t, float[3], float[3]) = nullptr;
|
||||
bool (*s_getItemData)(uint32_t, SItemModelData*) = nullptr;
|
||||
void (*s_onSetPlayerAffect)(unsigned) = nullptr;
|
||||
void (*s_onResetPlayerAffect)(unsigned) = nullptr;
|
||||
bool s_hairColorEnable = false; // InstanceBase.cpp HAIR_COLOR_ENABLE=FALSE until app.SetHairColorEnable
|
||||
bool s_hairColorEnable = true; // Enabled by default so hair meshes load without requiring explicit app.SetHairColorEnable
|
||||
bool s_armorSpecular = false; // USE_ARMOR_SPECULAR=FALSE until app.SetArmorSpecularEnable
|
||||
|
||||
bool GetItemData(uint32_t vnum, SItemModelData* out) { return s_getItemData && s_getItemData(vnum, out); }
|
||||
@@ -480,6 +502,7 @@ void NetworkActorManager::AppendActor(const SNetworkActorData& data) {
|
||||
}
|
||||
}
|
||||
actor->PlayMotion(MotionType::Wait, true);
|
||||
ConfigureMount(actorData);
|
||||
|
||||
// AVA2 InstanceBase::SetAffect(AFFECT_STUN=5) controls the sleep action flag.
|
||||
actor->SetSleep((data.m_affectFlags[0] & (1u<<5))!=0);
|
||||
@@ -487,7 +510,8 @@ void NetworkActorManager::AppendActor(const SNetworkActorData& data) {
|
||||
// Register TextTail overhead display
|
||||
auto& tt = TextTailManager::Instance();
|
||||
// AttachTextTail registers white; RefreshTextTail below applies GetNameColor/title.
|
||||
tt.RegisterCharacterTextTail(data.m_dwGuildID, data.m_dwVID, 0xFFFFFFFF);
|
||||
tt.RegisterCharacterTextTail(data.m_dwGuildID, data.m_dwVID, 0xFFFFFFFF,
|
||||
actor->GetHeightOffset() * actor->GetScale() + 10.0f);
|
||||
tt.SetCharacterName(data.m_dwVID, data.m_stName);
|
||||
tt.SetCharacterPosition(data.m_dwVID, worldX, worldY, worldZ);
|
||||
|
||||
@@ -560,6 +584,7 @@ void NetworkActorManager::UpdateActor(const SNetworkUpdateActorData& data) {
|
||||
actorData.m_dwMountVnum = data.m_dwMountVnum;
|
||||
actorData.m_dwMovSpd = data.m_dwMovSpd;
|
||||
actorData.m_dwAtkSpd = data.m_dwAtkSpd;
|
||||
ConfigureMount(actorData);
|
||||
|
||||
// CNetworkActorManager::UpdateActor: ChangeArmor, ChangeWeapon(weapon, arrow), ChangeHair, ChangeSash.
|
||||
ChangeArmor(actorData, data.m_dwArmor);
|
||||
@@ -698,6 +723,22 @@ void NetworkActorManager::Update(float dt, const TerrainHeightSource* terrain) {
|
||||
}
|
||||
|
||||
actorData.m_pActorInstance->Update(dt, terrain);
|
||||
if (actorData.m_pMountInstance) {
|
||||
auto& mount=*actorData.m_pMountInstance;
|
||||
auto& rider=*actorData.m_pActorInstance;
|
||||
mount.SetPosition(rider.GetX(),rider.GetY(),rider.GetZ());
|
||||
mount.SetYaw(rider.GetYaw());
|
||||
const auto motion=rider.GetCurrentMotion();
|
||||
if (mount.GetCurrentMotion()!=motion && (motion==MotionType::Wait || motion==MotionType::Walk || motion==MotionType::Run))
|
||||
mount.PlayMotion(motion,true);
|
||||
mount.Update(dt,terrain);
|
||||
float sx,sy,sz;
|
||||
if(mount.GetBonePosition("saddle",sx,sy,sz))rider.SetModelYOffset((sy-rider.GetY())/rider.GetScale());
|
||||
}
|
||||
// Keep labels on the actual rendered owner, including local movement
|
||||
// and actors whose incoming Z=0 must be grounded on the terrain.
|
||||
const auto& owner = *actorData.m_pActorInstance;
|
||||
TextTailManager::Instance().SetCharacterPosition(vid, owner.GetX(), owner.GetY()+owner.GetModelYOffset()*owner.GetScale(), owner.GetZ());
|
||||
|
||||
auto& effects = actorData.m_attachedEffects;
|
||||
for (auto e = effects.begin(); e != effects.end();) {
|
||||
@@ -852,12 +893,29 @@ std::shared_ptr<ActorInstance> NetworkActorManager::GetActorInstance(uint32_t vi
|
||||
return (it != m_actors.end()) ? it->second.m_pActorInstance : nullptr;
|
||||
}
|
||||
|
||||
std::vector<Render3DDraw> NetworkActorManager::BuildDrawCommands(float animTime) {
|
||||
std::vector<Render3DDraw> NetworkActorManager::BuildDrawCommands(float animTime, const float* view, const float* proj) {
|
||||
(void)animTime;
|
||||
std::vector<Render3DDraw> allDraws;
|
||||
for (auto& [vid, actorData] : m_actors) {
|
||||
if (!actorData.m_pActorInstance || actorData.m_isHidden) continue;
|
||||
auto actorDraws = actorData.m_pActorInstance->BuildDrawCommands();
|
||||
if (!IsMainActorVID(vid) && !actorData.m_pActorInstance->IsVisible(view,proj)
|
||||
&& (!actorData.m_pMountInstance || !actorData.m_pMountInstance->IsVisible(view,proj))) continue;
|
||||
float saddle[16];
|
||||
const float* riderWorld=nullptr;
|
||||
if (actorData.m_pMountInstance) {
|
||||
auto mountDraws=actorData.m_pMountInstance->BuildDrawCommands();
|
||||
for (auto& d:mountDraws)allDraws.push_back(std::move(d));
|
||||
if(actorData.m_pMountInstance->GetBoneWorldTransform("saddle",saddle)) {
|
||||
// Inverse of the SDK's Granny-to-engine basis on the left:
|
||||
// BuildDrawCommands applies that basis to rider mesh coordinates.
|
||||
for(int col=0;col<4;++col) {
|
||||
const float y=saddle[4+col], z=saddle[8+col];
|
||||
saddle[4+col]=z;saddle[8+col]=-y;
|
||||
}
|
||||
riderWorld=saddle;
|
||||
}
|
||||
}
|
||||
auto actorDraws = actorData.m_pActorInstance->BuildDrawCommands(riderWorld);
|
||||
for (auto& d : actorDraws) {
|
||||
allDraws.push_back(std::move(d));
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ struct SAttachedEffect {
|
||||
|
||||
struct SNetworkActorData {
|
||||
uint32_t m_dwVID = 0;
|
||||
bool m_isScriptInstance = false; // showcase uses reflected native Y coordinates
|
||||
std::string m_stName;
|
||||
uint8_t m_bType = 0; // 0=Mob, 1=NPC, 6=PC
|
||||
uint32_t m_dwRace = 0;
|
||||
@@ -85,6 +86,8 @@ struct SNetworkActorData {
|
||||
bool m_isHidden = false;
|
||||
|
||||
std::shared_ptr<ActorInstance> m_pActorInstance;
|
||||
std::shared_ptr<ActorInstance> m_pMountInstance;
|
||||
uint32_t m_mountRaceRequested = 0;
|
||||
};
|
||||
|
||||
// CInstanceBase::IsGameMaster: a "[" in the name or AFFECT_YMIR.
|
||||
@@ -280,7 +283,7 @@ public:
|
||||
}
|
||||
|
||||
// Helpers to build 3D rendering draw calls for all visible network actors
|
||||
std::vector<Render3DDraw> BuildDrawCommands(float animTime);
|
||||
std::vector<Render3DDraw> BuildDrawCommands(float animTime, const float* view = nullptr, const float* proj = nullptr);
|
||||
|
||||
private:
|
||||
uint32_t m_mainVID = 0;
|
||||
|
||||
@@ -1091,6 +1091,7 @@ struct TPacketGCOfflineShopUpdateItem {
|
||||
char title[46];int64_t price;TShopLog log;uint64_t flag;int32_t time;uint32_t type;
|
||||
};
|
||||
struct TOfflineShopItemTable { uint32_t vnum;int32_t count;TItemPos pos;int64_t price;uint8_t display_pos; };
|
||||
struct TOfflineShopAddItem { TItemPos bDisplayPos; uint8_t bPos; int64_t lPrice; };
|
||||
struct TPacketCGMyOfflineShop { uint8_t bHeader;char szSign[46];uint8_t bCount;uint32_t shopVnum;uint8_t shopTitle; };
|
||||
struct TShopDecoration {char sign[46];uint32_t owner_id;uint8_t vnum,type;};
|
||||
struct TPacketGCShopSearchItemSet { uint8_t header;uint32_t size; };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "item_sound.h"
|
||||
#include "python_item.h"
|
||||
#include "PythonNetworkStream.h"
|
||||
#include "player_settings.h"
|
||||
#include "python_net.h"
|
||||
#include "guild_state.h"
|
||||
#include "switchbot_state.h"
|
||||
@@ -489,6 +490,9 @@ void PythonNetworkStream::MainCharacterLoaded(int32_t x,int32_t y,int32_t z) {
|
||||
WarpBackgroundMap(uint32_t(x),uint32_t(y));
|
||||
int32_t localX=x,localY=y; GlobalToLocalPosition(localX,localY);
|
||||
SetPlayerRace(m_wMainActorRace);
|
||||
// Skill levels can arrive during Loading, before GameWindow registers its
|
||||
// skill slots. Register on the main-character packet so levels aren't lost.
|
||||
RegisterPlayerSkills(uint8_t(m_wMainActorRace), m_byMainActorSkillGroup, m_byMainActorEmpire);
|
||||
SetMainCharacterName(m_strMainActorName);SetMainCharacterPosition(localX,localY,z);
|
||||
inventory_callback(m_phaseWindows[4],"LoadData",Py_BuildValue("ii",x,y));
|
||||
std::vector<uint8_t> version(67,0);version[0]=HEADER_CG_CLIENT_VERSION2;
|
||||
@@ -1221,6 +1225,30 @@ bool PythonNetworkStream::SendOfflineShopManagement(uint8_t operation,uint8_t po
|
||||
Send(bytes.data(),bytes.size());return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendAddOfflineShopItem(const TItemPos& bDisplayPos, uint8_t bPos, int64_t lPrice) {
|
||||
std::vector<uint8_t> bytes(58, 0);
|
||||
bytes[0] = HEADER_CG_OFFLINE_SHOP;
|
||||
bytes[1] = SHOP_SUBHEADER_CG_ADD_ITEM;
|
||||
Send(bytes.data(), bytes.size());
|
||||
|
||||
TOfflineShopAddItem item{};
|
||||
item.bDisplayPos = bDisplayPos;
|
||||
item.bPos = bPos;
|
||||
item.lPrice = lPrice;
|
||||
Send(&item, sizeof(item));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendOfflineShopChangeTitle(const std::string& title) {
|
||||
std::vector<uint8_t> bytes(58, 0);
|
||||
bytes[0] = HEADER_CG_OFFLINE_SHOP;
|
||||
bytes[1] = SHOP_SUBHEADER_CG_CHANGE_TITLE;
|
||||
size_t copyLen = std::min(title.size(), size_t(50));
|
||||
std::memcpy(&bytes[2], title.data(), copyLen);
|
||||
Send(bytes.data(), bytes.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PythonNetworkStream::SendCharacterMovePacket(uint8_t func, uint8_t arg, uint8_t rot, int32_t x, int32_t y, uint32_t time) {
|
||||
TPacketCGMove p;
|
||||
p.bHeader = HEADER_CG_MOVE;
|
||||
|
||||
@@ -74,6 +74,11 @@ public:
|
||||
bool SendBuildOfflineShopPacket(const std::string& name,const std::vector<TOfflineShopItemTable>& items,uint32_t vnum,uint8_t title);
|
||||
bool SendOfflineShopChangeDecoration(const std::string& sign,uint32_t vnum,uint32_t type);
|
||||
bool SendOfflineShopManagement(uint8_t operation,uint8_t position=0,uint32_t owner=0);
|
||||
bool SendAddOfflineShopItem(const TItemPos& bDisplayPos, uint8_t bPos, int64_t lPrice);
|
||||
bool SendOfflineShopChangeTitle(const std::string& title);
|
||||
bool SendTakeOfflineMoney() { return SendOfflineShopManagement(SHOP_SUBHEADER_CG_TAKE_MONEY); }
|
||||
bool SendOfflineShopCheck() { return SendOfflineShopManagement(SHOP_SUBHEADER_CG_CHECK); }
|
||||
bool SendOfflineShopButton() { return SendOfflineShopManagement(SHOP_SUBHEADER_CG_BUTTON); }
|
||||
bool SendQuickSlotAddPacket(uint8_t index,uint8_t type,uint8_t pos);
|
||||
bool SendQuickSlotDelPacket(uint8_t index);
|
||||
bool SendQuickSlotMovePacket(uint8_t source,uint8_t target);
|
||||
@@ -165,6 +170,7 @@ public:
|
||||
const std::vector<uint8_t>& GetSendQueue() const { return m_sendBuffer; }
|
||||
std::vector<uint8_t> PopSendBytes();
|
||||
void ClearSendQueue() { m_sendBuffer.clear();m_sendPackets.clear(); }
|
||||
const std::vector<std::vector<uint8_t>>& GetSendPackets() const { return m_sendPackets; }
|
||||
std::vector<std::vector<uint8_t>> PopSendPackets();
|
||||
// Packets with whether the transport appends the sequence byte (SendSequence()).
|
||||
std::vector<std::pair<std::vector<uint8_t>,bool>> PopSendPacketsWithSequence();
|
||||
@@ -194,6 +200,7 @@ public:
|
||||
bool GetComboSkillFlag() const { return m_bComboSkillFlag; }
|
||||
// Windows calls PostQuitMessage(0); the host loop polls this instead.
|
||||
bool IsQuitRequested() const { return m_unknownPacketQuit; }
|
||||
void RequestQuit() { m_unknownPacketQuit = true; }
|
||||
// GamePhase() headers Windows handles but this port skips (consumed, not dispatched).
|
||||
const std::vector<uint8_t>& GetUnportedPackets() const { return m_unportedPackets; }
|
||||
|
||||
|
||||
@@ -544,12 +544,7 @@ bool PythonNetworkStream::RecvMessenger() {
|
||||
bool PythonNetworkStream::RecvQuestInfoPacket() {
|
||||
uint8_t header,flags;uint16_t size,id;
|
||||
if(!Read(1,&header)||!Read(2,&size)||!Read(2,&id)||!Read(1,&flags))return false;
|
||||
// Reject a declared payload shorter than its flag-selected fields before a
|
||||
// read can consume the next packet. Windows assumes trusted server lengths.
|
||||
const size_t required=6+bool(flags&QUEST_SEND_IS_BEGIN)+31*bool(flags&QUEST_SEND_TITLE)+
|
||||
17*bool(flags&QUEST_SEND_CLOCK_NAME)+4*bool(flags&QUEST_SEND_CLOCK_VALUE)+
|
||||
17*bool(flags&QUEST_SEND_COUNTER_NAME)+4*bool(flags&QUEST_SEND_COUNTER_VALUE)+25*bool(flags&QUEST_SEND_ICON_FILE);
|
||||
if(size<required)return false;
|
||||
|
||||
unsigned type=2;
|
||||
if(flags&QUEST_SEND_IS_BEGIN) {
|
||||
uint8_t begin;if(!Read(1,&begin))return false;type=begin?1:3;
|
||||
@@ -646,11 +641,12 @@ bool PythonNetworkStream::RecvChestDrop() {
|
||||
uint32_t chestVnum,chestCount;
|
||||
if(!Read(4,&chestVnum) || !Read(4,&chestCount)) return false;
|
||||
if(chestCount>0) {
|
||||
ClearChestDropInfo(chestVnum);
|
||||
for(uint32_t j=0;j<chestCount;++j) {
|
||||
uint32_t vnum,count;
|
||||
if(!Read(4,&vnum) || !Read(4,&count)) return false;
|
||||
AddChestDropItem(chestVnum, vnum, count);
|
||||
}
|
||||
// CItemManager::LoadChestDropFromServer: the chest-drop item store is not ported.
|
||||
PyCallClassMemberFunc(m_phaseWindows[5],"OpenChestDrop",Py_BuildValue("(i)",int(chestVnum)));
|
||||
}
|
||||
return true;
|
||||
@@ -1321,8 +1317,12 @@ bool PythonNetworkStream::RecvHandshakePacket() {
|
||||
bool PythonNetworkStream::RecvHandshakeOKPacket() {
|
||||
TPacketGCBlank p;
|
||||
if(!Read(sizeof(p),&p)) return false;
|
||||
const uint32_t delta=GetLocalMSec()-m_changeClientTime;
|
||||
SetServerMSec(m_changeServerTime+delta);
|
||||
// Bootstrap may already have completed the initial handshake. An OK without
|
||||
// a native handshake must retain its synchronized clock, not use host uptime.
|
||||
if(m_changeClientTime!=0) {
|
||||
const uint32_t delta=GetLocalMSec()-m_changeClientTime;
|
||||
SetServerMSec(m_changeServerTime+delta);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ std::shared_ptr<Gr2ModelInstance> ActorInstance::LoadPartModel(const std::string
|
||||
}
|
||||
|
||||
void ActorInstance::SetMainModel(std::shared_ptr<Gr2ModelInstance> model, const std::string& path) {
|
||||
m_boundsModel = nullptr;
|
||||
m_model = std::move(model);
|
||||
m_modelPath = m_model ? path : std::string();
|
||||
RebindParts();
|
||||
@@ -209,6 +210,7 @@ bool ActorInstance::SetModel(const std::string& modelPath) {
|
||||
std::cerr << "ActorInstance::SetModel file not found: " << modelPath << std::endl;
|
||||
return false;
|
||||
}
|
||||
m_boundsModel = nullptr;
|
||||
m_model = Gr2ModelInstance::Load(resolved);
|
||||
if (!m_model) return false;
|
||||
m_modelPath = modelPath;
|
||||
@@ -254,9 +256,21 @@ bool ActorInstance::PlayMotion(MotionType type, bool loop) {
|
||||
it = m_motionPaths.find(MotionType::Attack);
|
||||
}
|
||||
}
|
||||
if (it == m_motionPaths.end()) return false;
|
||||
|
||||
std::string resolved = ResolvePath(it->second);
|
||||
std::string motionPath;
|
||||
// Resolve the active mode at playback time; SetRace/armor rebuilds must not
|
||||
// silently replace riding motions with GENERAL standing/walking motions.
|
||||
if (m_raceData && m_motionMode != 1) {
|
||||
uint16_t actualMode = uint16_t(m_motionMode);
|
||||
if (m_raceData->GetMotionKey(actualMode, uint16_t(type), &actualMode)) {
|
||||
const auto* entries = m_raceData->GetMotions(actualMode, uint32_t(type));
|
||||
if (entries && !entries->empty()) motionPath = ReadMotionFileName(entries->front().fileName);
|
||||
}
|
||||
}
|
||||
if (motionPath.empty()) {
|
||||
if (it == m_motionPaths.end()) return false;
|
||||
motionPath = it->second;
|
||||
}
|
||||
std::string resolved = ResolvePath(motionPath);
|
||||
if (!std::filesystem::exists(resolved)) return false;
|
||||
|
||||
bool loaded = m_model->LoadExternalAnimation(resolved);
|
||||
@@ -568,11 +582,11 @@ bool ActorInstance::IsTargetInAttackRange(const ActorInstance& target, float max
|
||||
return diff <= maxAngleDeg;
|
||||
}
|
||||
|
||||
std::vector<Render3DDraw> ActorInstance::BuildDrawCommands() {
|
||||
std::vector<Render3DDraw> ActorInstance::BuildDrawCommands(const float* worldOverride) {
|
||||
if (!m_model) return {};
|
||||
float world[16];
|
||||
MakeTransformMatrix(m_yaw + 180.0f, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, world);
|
||||
auto draws = m_model->BuildDrawCommands(m_animTime, world);
|
||||
MakeTransformMatrix(m_yaw, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, world);
|
||||
auto draws = m_model->BuildDrawCommands(m_animTime, worldOverride ? worldOverride : world);
|
||||
|
||||
// Shining system (ENABLE_SHINING_SYSTEM): weapon aura / glow
|
||||
if (m_weaponShining > 0) {
|
||||
@@ -647,6 +661,26 @@ std::vector<Render3DDraw> ActorInstance::BuildDrawCommands() {
|
||||
return draws;
|
||||
}
|
||||
|
||||
bool ActorInstance::IsVisible(const float* view, const float* proj) const {
|
||||
if (!view || !proj || !m_model) return true;
|
||||
if (m_boundsModel != m_model.get()) {
|
||||
float loX,loY,loZ,hiX,hiY,hiZ;
|
||||
m_boundsRadius = 500.f;
|
||||
if (m_model->GetLocalBounds(loX,loY,loZ,hiX,hiY,hiZ)) {
|
||||
const float x=std::max(std::abs(loX),std::abs(hiX));
|
||||
const float y=std::max(std::abs(loY),std::abs(hiY));
|
||||
const float z=std::max(std::abs(loZ),std::abs(hiZ));
|
||||
m_boundsRadius = std::sqrt(x*x+y*y+z*z)*2.f + 300.f;
|
||||
}
|
||||
m_boundsModel=m_model.get();
|
||||
}
|
||||
const float r=m_boundsRadius*std::abs(m_scale);
|
||||
const float y=m_posY+m_modelYOffset*m_scale;
|
||||
const float lo[3]={m_posX-r,y-r,m_posZ-r};
|
||||
const float hi[3]={m_posX+r,y+r,m_posZ+r};
|
||||
return IsBoundsVisible(lo,hi,view,proj);
|
||||
}
|
||||
|
||||
bool ActorInstance::HitTestScreen(float clickX, float clickY, const Gr2SceneRenderer& renderer, float tolerancePx) const {
|
||||
if (m_curHP <= 0) return false;
|
||||
float bx = 0.0f, by = 0.0f, hx = 0.0f, hy = 0.0f;
|
||||
@@ -673,8 +707,15 @@ bool ActorInstance::GetBoneWorldTransform(const std::string& boneName, float* ou
|
||||
if (!m_model->GetBoneWorldTransform(boneName, localBone, m_animTime)) {
|
||||
return false;
|
||||
}
|
||||
// Bone poses are still Granny Z-up, just like the mesh vertices. Convert
|
||||
// before composing with the engine world matrix (SDK R_GRANNY_TO_ENGINE).
|
||||
for (int row=0;row<4;++row) {
|
||||
const float y=localBone[row*4+1], z=localBone[row*4+2];
|
||||
localBone[row*4+1]=z;
|
||||
localBone[row*4+2]=-y;
|
||||
}
|
||||
float actorWorld[16];
|
||||
MakeTransformMatrix(m_yaw + 180.0f, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, actorWorld);
|
||||
MakeTransformMatrix(m_yaw, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, actorWorld);
|
||||
|
||||
for (int r = 0; r < 4; ++r) {
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
|
||||
@@ -133,6 +133,8 @@ public:
|
||||
void GetMoveTarget(float& tx, float& tz) const { tx = m_targetX; tz = m_targetZ; }
|
||||
|
||||
// Screen picking test (returns true if 2D click hits projected 3D volume)
|
||||
// Conservative bounds include animation/attachment margin; only render work is culled.
|
||||
bool IsVisible(const float* view, const float* proj) const;
|
||||
bool HitTestScreen(float clickX, float clickY, const Gr2SceneRenderer& renderer, float tolerancePx = 40.0f) const;
|
||||
|
||||
// Smooth movement and continuous animation update
|
||||
@@ -207,7 +209,7 @@ public:
|
||||
bool GetBoneWorldTransform(const std::string& boneName, float* outWorld16) const;
|
||||
|
||||
// Generate 3D draw commands
|
||||
std::vector<Render3DDraw> BuildDrawCommands();
|
||||
std::vector<Render3DDraw> BuildDrawCommands(const float* worldOverride = nullptr);
|
||||
|
||||
Gr2ModelInstance* GetModel() { return m_model.get(); }
|
||||
const std::string& GetModelPath() const { return m_modelPath; }
|
||||
@@ -236,6 +238,8 @@ private:
|
||||
float m_sashScale[3] = {1.0f, 1.0f, 1.0f};
|
||||
|
||||
std::shared_ptr<Gr2ModelInstance> m_model;
|
||||
mutable const Gr2ModelInstance* m_boundsModel = nullptr;
|
||||
mutable float m_boundsRadius = 500.f;
|
||||
std::string m_modelPath;
|
||||
|
||||
std::unordered_map<MotionType, std::string> m_motionPaths;
|
||||
|
||||
@@ -49,7 +49,7 @@ bool EnvironmentData::LoadFromFile(const std::string& filepath) {
|
||||
"ymir work/environment/" + filepath,
|
||||
"build/dev/ymir work/environment/" + filepath,
|
||||
"/Users/shen/Work/Code/Metin2/ava2-client/ymir work/environment/" + filepath,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/ETC/ymir work/environment/" + filepath
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/1. Client DEV/pack_maker/ETC/ymir work/environment/" + filepath
|
||||
};
|
||||
|
||||
if (filepath.find('/') != std::string::npos || filepath.find('\\') != std::string::npos) {
|
||||
@@ -58,7 +58,7 @@ bool EnvironmentData::LoadFromFile(const std::string& filepath) {
|
||||
candidates.push_back("ymir work/environment/" + filename);
|
||||
candidates.push_back("build/dev/ymir work/environment/" + filename);
|
||||
candidates.push_back("/Users/shen/Work/Code/Metin2/ava2-client/ymir work/environment/" + filename);
|
||||
candidates.push_back("/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/ETC/ymir work/environment/" + filename);
|
||||
candidates.push_back("/Users/shen/Work/Code/Metin2/AVA2/1. Client DEV/pack_maker/ETC/ymir work/environment/" + filename);
|
||||
}
|
||||
|
||||
for (const auto& path : candidates) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "RenderCommands3D.h"
|
||||
#include "HardwareScene.h"
|
||||
#include <gr2/gr2.h>
|
||||
#include <gr2_render/gr2_render.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -12,7 +14,13 @@ namespace ava2 {
|
||||
|
||||
class Gr2ModelInstance {
|
||||
public:
|
||||
Gr2ModelInstance() = default;
|
||||
static void SetHardwareSkinningEnabled(bool enabled);
|
||||
explicit Gr2ModelInstance(std::shared_ptr<gr2_render::Gr2ModelInstance> impl)
|
||||
: m_impl(std::move(impl)) {}
|
||||
|
||||
static std::unique_ptr<Gr2ModelInstance> Load(const std::string& filepath);
|
||||
static std::unique_ptr<Gr2ModelInstance> LoadFromMemory(const uint8_t* data, size_t size, const std::string& name = "");
|
||||
|
||||
// Load external animation (.gr2) to animate this model
|
||||
bool LoadExternalAnimation(const std::string& anim_filepath);
|
||||
@@ -31,11 +39,11 @@ public:
|
||||
void SetAttachmentScale(const std::string& bone_name, float sx, float sy, float sz);
|
||||
// CGrannyModelInstance::SetMaterialImagePointer: textures whose StringPath matches src are drawn with dst.
|
||||
void SetSkin(const std::string& src_file_name, const std::string& dst_file_name);
|
||||
void ClearSkins() { m_skins.clear(); }
|
||||
const std::string& GetFilePath() const { return m_filepath; }
|
||||
void ClearSkins();
|
||||
const std::string& GetFilePath() const;
|
||||
|
||||
// Build 3D draw commands for this model and all attached components (weapons, hair, armor parts)
|
||||
std::vector<Render3DDraw> BuildDrawCommands(float animation_time = -1.0f, const float* world_matrix = nullptr);
|
||||
std::vector<Render3DDraw> BuildDrawCommands(float animation_time = -1.0f, const float* world_matrix = nullptr, bool forceCPU = false);
|
||||
|
||||
// Build draw commands for a skinned part using an external bone palette
|
||||
std::vector<Render3DDraw> BuildDrawCommandsWithPalette(const std::vector<gr2::Mat4>& skin_matrices,
|
||||
@@ -44,31 +52,17 @@ public:
|
||||
|
||||
bool GetLocalBounds(float& minX, float& minY, float& minZ, float& maxX, float& maxY, float& maxZ) const;
|
||||
|
||||
const gr2::File& GetFile() const { return *m_file; }
|
||||
const gr2::FileInfo& GetInfo() const { return m_file->file_info(); }
|
||||
const gr2::File& GetFile() const { return m_impl->GetFile(); }
|
||||
const gr2::FileInfo& GetInfo() const { return m_impl->GetInfo(); }
|
||||
|
||||
std::shared_ptr<gr2_render::Gr2ModelInstance> GetImpl() const { return m_impl; }
|
||||
|
||||
private:
|
||||
struct AttachedModel {
|
||||
std::string bone_name;
|
||||
std::shared_ptr<Gr2ModelInstance> model;
|
||||
float offset[16];
|
||||
bool animated = false;
|
||||
bool scaled = false;
|
||||
float scale[3] = {1.0f, 1.0f, 1.0f};
|
||||
};
|
||||
void ApplySkins(std::vector<Render3DDraw>& draws, size_t first) const;
|
||||
|
||||
std::unique_ptr<gr2::File> m_file;
|
||||
std::string m_filepath;
|
||||
std::unique_ptr<gr2::File> m_anim_file;
|
||||
std::string m_anim_filepath;
|
||||
|
||||
std::vector<AttachedModel> m_attached_models;
|
||||
std::shared_ptr<gr2_render::Gr2ModelInstance> m_impl;
|
||||
std::vector<std::shared_ptr<Gr2ModelInstance>> m_attached_models;
|
||||
std::vector<std::shared_ptr<Gr2ModelInstance>> m_attached_parts;
|
||||
std::unordered_map<std::string, std::string> m_skins;
|
||||
};
|
||||
|
||||
// 3D Scene and Model Renderer (modeled after 40250 pipeline architecture)
|
||||
class Gr2SceneRenderer {
|
||||
public:
|
||||
Gr2SceneRenderer(int width = 1024, int height = 768);
|
||||
@@ -95,13 +89,19 @@ public:
|
||||
// Rasterize a list of draw commands (CPU software rasterizer)
|
||||
void RenderScene(SDL_Surface* targetSurface, const std::vector<Render3DDraw>& draws);
|
||||
|
||||
// GPU Hardware-accelerated 3D Scene Rendering via SDL_RenderGeometry / Metal / Vulkan
|
||||
// Native SDL_GPU depth/perspective pipeline; SDL geometry fallback for software renderers.
|
||||
void RenderSceneGPU(SDL_Renderer* renderer, const std::vector<Render3DDraw>& draws);
|
||||
void SetGPUDevice(SDL_GPUDevice* device);
|
||||
void DestroyGPUTextures();
|
||||
SDL_Texture* GetGPUTexture(SDL_Renderer* renderer, const std::string& texturePath);
|
||||
|
||||
// Exponential & Linear Depth Fog (modeled after 40250 CMapOutdoor fog)
|
||||
void SetFog(bool enable, uint32_t color = 0xFFCCDDEE, float density = 0.0003f, float fog_near = 300.0f, float fog_far = 3000.0f, bool exp_mode = true);
|
||||
void SetTextureBudgets(size_t cpuBytes,size_t gpuBytes);
|
||||
size_t GetHardwareTextureBytes() const {return m_hardware ? m_hardware->GetTextureBytes() : 0;}
|
||||
size_t GetHardwareTextureUploadCount() const {return m_hardware ? m_hardware->GetTextureUploadCount() : 0;}
|
||||
size_t GetDecodedTextureBytes() const { return m_decodedTextureBytes; }
|
||||
size_t GetTextureDecodeCount() const { return m_textureDecodeCount; }
|
||||
bool IsFogEnabled() const { return m_fog_enabled; }
|
||||
uint32_t GetFogColor() const { return m_fog_color; }
|
||||
|
||||
@@ -128,10 +128,12 @@ public:
|
||||
|
||||
private:
|
||||
struct TextureData {
|
||||
uint64_t lastUsed = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
std::vector<uint8_t> rgba;
|
||||
};
|
||||
void TrimTextureCaches(bool protectDecodedWorkingSet);
|
||||
const TextureData* GetTexture(const std::string& texturePath);
|
||||
|
||||
struct GpuTransformedVertex {
|
||||
@@ -154,7 +156,10 @@ private:
|
||||
int m_logicalHeight = 0;
|
||||
std::vector<float> m_depthBuffer;
|
||||
std::unordered_map<std::string, TextureData> m_textureCache;
|
||||
std::unordered_map<std::string, SDL_Texture*> m_gpuTextureCache;
|
||||
struct SDLTextureEntry {SDL_Texture* texture=nullptr;size_t bytes=0;uint64_t lastUsed=0;};
|
||||
std::unordered_map<std::string, SDLTextureEntry> m_gpuTextureCache;
|
||||
uint64_t m_textureFrame=0;
|
||||
size_t m_decodedTextureBytes=0,m_textureDecodeCount=0,m_decodedTextureBudget=64u*1024u*1024u,m_gpuTextureBudget=256u*1024u*1024u;
|
||||
|
||||
// Persistent scratch buffers to eliminate per-draw heap allocation churn in RenderSceneGPU
|
||||
std::vector<DrawOrder> m_scratchSortedDraws;
|
||||
@@ -162,6 +167,11 @@ private:
|
||||
std::vector<SDL_Vertex> m_scratchSdlVertices;
|
||||
std::vector<int> m_scratchSdlIndices;
|
||||
|
||||
std::unique_ptr<HardwareScene> m_hardware;
|
||||
std::vector<HardwareVertex> m_hardwareVertices;
|
||||
std::vector<uint32_t> m_hardwareIndices;
|
||||
std::vector<HardwareBatch> m_hardwareBatches;
|
||||
|
||||
bool m_fog_enabled = false;
|
||||
uint32_t m_fog_color = 0xFFCCDDEE;
|
||||
float m_fog_density = 0.0003f;
|
||||
|
||||
@@ -0,0 +1,298 @@
|
||||
#include "HardwareScene.h"
|
||||
#include "shaders/SceneSpirv.h"
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <unordered_set>
|
||||
namespace ava2 {
|
||||
namespace {
|
||||
constexpr const char* metal = R"(
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
struct Input { float4 position [[attribute(0)]]; float4 color [[attribute(1)]]; float2 uv [[attribute(2)]]; float4 normal [[attribute(3)]]; uint4 bones [[attribute(4)]]; float4 weights [[attribute(5)]]; };
|
||||
struct Transform { float4 world[4]; float4 mvp[4]; float4 diffuse,ambient,emissive,lightDirection,lightAmbient,lightDiffuse,fogColor,fogParams,modes,skin; };
|
||||
struct Output { float4 position [[position]]; float4 color; float2 uv; };
|
||||
float4 rows(float4 p,float4 a,float4 b,float4 c,float4 d){return p.x*a+p.y*b+p.z*c+p.w*d;}
|
||||
vertex Output scene_vertex(Input in [[stage_in]], uint instance [[instance_id]], constant Transform& header [[buffer(0)]], constant float4* palette [[buffer(1)]], device const Transform* instances [[buffer(2)]]) {
|
||||
Transform t=header.modes.x>1.5 ? instances[instance] : header;
|
||||
float4 p=in.position; float3 n=in.normal.xyz;
|
||||
if(t.skin.x>0.5){float4 sp=0;float3 sn=0;float total=0;
|
||||
for(uint i=0;i<4;++i)if(in.weights[i]>0 && in.bones[i]<uint(t.skin.x)){
|
||||
uint b=in.bones[i]*4;float w=in.weights[i];
|
||||
sp+=rows(p,palette[b],palette[b+1],palette[b+2],palette[b+3])*w;
|
||||
sn+=rows(float4(n,0),palette[b],palette[b+1],palette[b+2],palette[b+3]).xyz*w;total+=w;
|
||||
}if(total>0.0001){p=float4(sp.xyz,1);n=sn;}
|
||||
}
|
||||
float4 clip=p,c=in.color;
|
||||
if(t.modes.x>0.5){
|
||||
clip=rows(p,t.mvp[0],t.mvp[1],t.mvp[2],t.mvp[3]);c*=t.diffuse;
|
||||
if(t.modes.y>0.5 && in.normal.w>0.5){float3 wn=rows(float4(n,0),t.world[0],t.world[1],t.world[2],t.world[3]).xyz;
|
||||
float len=length(wn);if(len>0.00001)wn/=len;
|
||||
float ndotl=max(0.f,dot(wn,t.lightDirection.xyz));c.rgb=clamp(t.emissive.rgb+t.ambient.rgb*t.lightAmbient.rgb+c.rgb*t.lightDiffuse.rgb*ndotl,0.f,1.f);
|
||||
}
|
||||
if(t.modes.z>0.5 && clip.w>0){float f=t.modes.z>1.5 ? exp(-clamp(clip.w*t.fogParams.x,0.f,10.f)) : clamp((t.fogParams.z-clip.w)/(t.fogParams.z-t.fogParams.y),0.f,1.f);c.rgb=mix(t.fogColor.rgb,c.rgb,f);}
|
||||
if(t.modes.w>0.5)clip.z=0;
|
||||
}
|
||||
Output out;out.position=clip;out.color=c;out.uv=in.uv;return out;
|
||||
}
|
||||
fragment float4 scene_fragment(Output in [[stage_in]], texture2d<float> image [[texture(0)]], sampler sampling [[sampler(0)]], constant float4& params [[buffer(0)]]) {
|
||||
float4 c=image.sample(sampling,in.uv)*in.color;
|
||||
if(params.x>=0.0 && c.a<=params.x) discard_fragment();
|
||||
if(params.y>0.5) c.a=1.0;
|
||||
return c;
|
||||
}
|
||||
)";
|
||||
|
||||
}
|
||||
HardwareScene::~HardwareScene() {
|
||||
for (auto& [key,mesh]:resident_) {SDL_ReleaseGPUBuffer(device_,mesh.vertices);SDL_ReleaseGPUBuffer(device_,mesh.indices);}
|
||||
if(instances_)SDL_ReleaseGPUBuffer(device_,instances_);
|
||||
if(instanceTransfer_)SDL_ReleaseGPUTransferBuffer(device_,instanceTransfer_);
|
||||
if(output_) SDL_DestroyTexture(output_);
|
||||
for(auto& [key,t]:textures_) SDL_ReleaseGPUTexture(device_,t.texture);
|
||||
for(auto& [key,p]:pipelines_) SDL_ReleaseGPUGraphicsPipeline(device_,p);
|
||||
if(color_) SDL_ReleaseGPUTexture(device_,color_);
|
||||
if(depth_) SDL_ReleaseGPUTexture(device_,depth_);
|
||||
if(vertex_) SDL_ReleaseGPUShader(device_,vertex_);
|
||||
if(fragment_) SDL_ReleaseGPUShader(device_,fragment_);
|
||||
if(sampler_) SDL_ReleaseGPUSampler(device_,sampler_);
|
||||
if(vertices_) SDL_ReleaseGPUBuffer(device_,vertices_);
|
||||
if(indices_) SDL_ReleaseGPUBuffer(device_,indices_);
|
||||
if(transfer_) SDL_ReleaseGPUTransferBuffer(device_,transfer_);
|
||||
}
|
||||
SDL_GPUTexture* HardwareScene::FindTexture(const std::string& key) {
|
||||
auto it=textures_.find(key);if(it==textures_.end())return nullptr;
|
||||
it->second.lastUsed=frame_+1;return it->second.texture;
|
||||
}
|
||||
SDL_GPUTexture* HardwareScene::Texture(const std::string& key,int width,int height,const void* rgba) {
|
||||
if(auto* found=FindTexture(key))return found;
|
||||
// Own uploads on the same queue as the 3D pass. SDL_Renderer's pending
|
||||
// texture uploads are submitted at Present, after our custom command buffer.
|
||||
SDL_GPUTextureCreateInfo ti{};ti.type=SDL_GPU_TEXTURETYPE_2D;ti.format=SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
||||
ti.usage=SDL_GPU_TEXTUREUSAGE_SAMPLER;ti.width=width;ti.height=height;ti.layer_count_or_depth=1;ti.num_levels=1;
|
||||
auto* texture=SDL_CreateGPUTexture(device_,&ti);if(!texture)return nullptr;
|
||||
SDL_GPUTransferBufferCreateInfo transferInfo{};transferInfo.usage=SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;transferInfo.size=width*height*4;
|
||||
auto* transfer=SDL_CreateGPUTransferBuffer(device_,&transferInfo);
|
||||
auto* bytes=transfer ? SDL_MapGPUTransferBuffer(device_,transfer,false) : nullptr;
|
||||
auto* command=bytes ? SDL_AcquireGPUCommandBuffer(device_) : nullptr;
|
||||
if(!bytes || !command) {
|
||||
if(bytes)SDL_UnmapGPUTransferBuffer(device_,transfer);
|
||||
if(transfer)SDL_ReleaseGPUTransferBuffer(device_,transfer);
|
||||
SDL_ReleaseGPUTexture(device_,texture);return nullptr;
|
||||
}
|
||||
std::memcpy(bytes,rgba,transferInfo.size);SDL_UnmapGPUTransferBuffer(device_,transfer);
|
||||
auto* copy=SDL_BeginGPUCopyPass(command);
|
||||
if(!copy){SDL_CancelGPUCommandBuffer(command);SDL_ReleaseGPUTransferBuffer(device_,transfer);SDL_ReleaseGPUTexture(device_,texture);return nullptr;}
|
||||
SDL_GPUTextureTransferInfo source{};source.transfer_buffer=transfer;source.pixels_per_row=width;source.rows_per_layer=height;
|
||||
SDL_GPUTextureRegion dest{};dest.texture=texture;dest.w=width;dest.h=height;dest.d=1;
|
||||
SDL_UploadToGPUTexture(copy,&source,&dest,false);SDL_EndGPUCopyPass(copy);
|
||||
const bool submitted=SDL_SubmitGPUCommandBuffer(command);SDL_ReleaseGPUTransferBuffer(device_,transfer);
|
||||
if(!submitted){SDL_ReleaseGPUTexture(device_,texture);return nullptr;}
|
||||
const size_t imageBytes=size_t(width)*height*4;
|
||||
textures_.emplace(key,TextureEntry{texture,imageBytes,frame_+1});textureBytes_+=imageBytes;++textureUploads_;return texture;
|
||||
}
|
||||
bool HardwareScene::Initialize(SDL_Renderer* renderer,int width,int height) {
|
||||
if(!vertex_) {
|
||||
bool msl=(SDL_GetGPUShaderFormats(device_) & SDL_GPU_SHADERFORMAT_MSL)!=0;
|
||||
SDL_GPUShaderCreateInfo info{};
|
||||
info.format=msl ? SDL_GPU_SHADERFORMAT_MSL : SDL_GPU_SHADERFORMAT_SPIRV;
|
||||
info.stage=SDL_GPU_SHADERSTAGE_VERTEX; info.num_uniform_buffers=2;info.num_storage_buffers=1;
|
||||
info.code=msl ? reinterpret_cast<const Uint8*>(metal) : scene_vert_spv;
|
||||
info.code_size=msl ? std::strlen(metal) : sizeof(scene_vert_spv);
|
||||
info.entrypoint=msl ? "scene_vertex" : "main";
|
||||
vertex_=SDL_CreateGPUShader(device_,&info);
|
||||
info.stage=SDL_GPU_SHADERSTAGE_FRAGMENT; info.num_samplers=1;info.num_uniform_buffers=1;info.num_storage_buffers=0;
|
||||
info.code=msl ? reinterpret_cast<const Uint8*>(metal) : scene_frag_spv;
|
||||
info.code_size=msl ? std::strlen(metal) : sizeof(scene_frag_spv);
|
||||
info.entrypoint=msl ? "scene_fragment" : "main";
|
||||
fragment_=SDL_CreateGPUShader(device_,&info);
|
||||
SDL_GPUSamplerCreateInfo si{};
|
||||
si.min_filter=si.mag_filter=SDL_GPU_FILTER_LINEAR;
|
||||
si.mipmap_mode=SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
|
||||
si.address_mode_u=si.address_mode_v=si.address_mode_w=SDL_GPU_SAMPLERADDRESSMODE_REPEAT;
|
||||
sampler_=SDL_CreateGPUSampler(device_,&si);
|
||||
const Uint32 white=0xffffffff;
|
||||
white_=Texture("__ava2_white",1,1,&white);
|
||||
}
|
||||
if(!vertex_ || !fragment_ || !sampler_ || !white_) return false;
|
||||
if(width_!=width || height_!=height) {
|
||||
if(output_) SDL_DestroyTexture(output_);
|
||||
if(color_) SDL_ReleaseGPUTexture(device_,color_);
|
||||
if(depth_) SDL_ReleaseGPUTexture(device_,depth_);
|
||||
output_=nullptr;color_=depth_=nullptr;
|
||||
SDL_GPUTextureCreateInfo ti{};ti.type=SDL_GPU_TEXTURETYPE_2D;ti.width=width;ti.height=height;ti.layer_count_or_depth=1;ti.num_levels=1;
|
||||
ti.format=SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;ti.usage=SDL_GPU_TEXTUREUSAGE_COLOR_TARGET|SDL_GPU_TEXTUREUSAGE_SAMPLER;
|
||||
color_=SDL_CreateGPUTexture(device_,&ti);
|
||||
ti.format=SDL_GPU_TEXTUREFORMAT_D32_FLOAT;ti.usage=SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET;
|
||||
depth_=SDL_CreateGPUTexture(device_,&ti);
|
||||
if(!color_ || !depth_) return false;
|
||||
auto props=SDL_CreateProperties();
|
||||
SDL_SetPointerProperty(props,SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_POINTER,color_);
|
||||
SDL_SetNumberProperty(props,SDL_PROP_TEXTURE_CREATE_FORMAT_NUMBER,SDL_PIXELFORMAT_ABGR8888);
|
||||
SDL_SetNumberProperty(props,SDL_PROP_TEXTURE_CREATE_WIDTH_NUMBER,width);
|
||||
SDL_SetNumberProperty(props,SDL_PROP_TEXTURE_CREATE_HEIGHT_NUMBER,height);
|
||||
output_=SDL_CreateTextureWithProperties(renderer,props);SDL_DestroyProperties(props);
|
||||
if(!output_)return false;
|
||||
// The target accumulates premultiplied colors. Transparent pixels keep
|
||||
// the Python selection background and other existing 2D layers intact.
|
||||
SDL_SetTextureBlendMode(output_,SDL_BLENDMODE_BLEND_PREMULTIPLIED);
|
||||
width_=width;height_=height;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SDL_GPUGraphicsPipeline* HardwareScene::Pipeline(const HardwareBatch& b) {
|
||||
unsigned key=b.cull|(b.depth<<3)|(b.depthWrite<<4)|(b.blend<<5)|(b.additive<<6);
|
||||
auto it=pipelines_.find(key);if(it!=pipelines_.end())return it->second;
|
||||
SDL_GPUGraphicsPipelineCreateInfo info{};
|
||||
info.vertex_shader=vertex_;info.fragment_shader=fragment_;info.primitive_type=SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
|
||||
SDL_GPUVertexBufferDescription buffer{};buffer.slot=0;buffer.pitch=sizeof(HardwareVertex);buffer.input_rate=SDL_GPU_VERTEXINPUTRATE_VERTEX;
|
||||
SDL_GPUVertexAttribute attributes[6]{};
|
||||
attributes[0]={0,0,SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4,0};
|
||||
attributes[1]={1,0,SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4,16};
|
||||
attributes[2]={2,0,SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,32};
|
||||
attributes[3]={3,0,SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4,40};
|
||||
attributes[4]={4,0,SDL_GPU_VERTEXELEMENTFORMAT_UINT4,56};
|
||||
attributes[5]={5,0,SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4,72};
|
||||
info.vertex_input_state={&buffer,1,attributes,6};
|
||||
info.rasterizer_state.fill_mode=SDL_GPU_FILLMODE_FILL;
|
||||
info.rasterizer_state.front_face=SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE;
|
||||
info.rasterizer_state.cull_mode=b.cull==1 ? SDL_GPU_CULLMODE_NONE : b.cull==2 ? SDL_GPU_CULLMODE_BACK : SDL_GPU_CULLMODE_FRONT;
|
||||
info.depth_stencil_state.compare_op=SDL_GPU_COMPAREOP_LESS_OR_EQUAL;
|
||||
info.depth_stencil_state.enable_depth_test=b.depth;
|
||||
info.depth_stencil_state.enable_depth_write=b.depthWrite;
|
||||
SDL_GPUColorTargetDescription target{};target.format=SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
||||
auto& blend=target.blend_state;blend.enable_blend=b.blend||b.additive;
|
||||
blend.src_color_blendfactor=SDL_GPU_BLENDFACTOR_SRC_ALPHA;
|
||||
blend.dst_color_blendfactor=b.additive ? SDL_GPU_BLENDFACTOR_ONE : SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
blend.color_blend_op=blend.alpha_blend_op=SDL_GPU_BLENDOP_ADD;
|
||||
blend.src_alpha_blendfactor=SDL_GPU_BLENDFACTOR_ONE;blend.dst_alpha_blendfactor=SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
info.target_info.color_target_descriptions=⌖info.target_info.num_color_targets=1;
|
||||
info.target_info.has_depth_stencil_target=true;info.target_info.depth_stencil_format=SDL_GPU_TEXTUREFORMAT_D32_FLOAT;
|
||||
auto* p=SDL_CreateGPUGraphicsPipeline(device_,&info);if(p)pipelines_.emplace(key,p);return p;
|
||||
}
|
||||
HardwareVertex MakeHardwareVertex(const Render3DDraw& mesh,size_t i) {
|
||||
HardwareVertex v{};
|
||||
v.position[0]=mesh.positions[i*3];v.position[1]=mesh.positions[i*3+1];v.position[2]=mesh.positions[i*3+2];v.position[3]=1;
|
||||
uint32_t color=i<mesh.diffuse.size() ? mesh.diffuse[i] : 0xffffffff;
|
||||
v.color[0]=((color>>16)&255)/255.f;v.color[1]=((color>>8)&255)/255.f;v.color[2]=(color&255)/255.f;v.color[3]=(color>>24)/255.f;
|
||||
if(i*2+1<mesh.uv0.size()){v.uv[0]=mesh.uv0[i*2];v.uv[1]=mesh.uv0[i*2+1];}
|
||||
if(i*3+2<mesh.normals.size()){for(int k=0;k<3;++k)v.normal[k]=mesh.normals[i*3+k];v.normal[3]=1;}
|
||||
if(i*4+3<mesh.bone_indices.size() && i*4+3<mesh.bone_weights.size())for(int k=0;k<4;++k){v.bones[k]=mesh.bone_indices[i*4+k];v.weights[k]=mesh.bone_weights[i*4+k];}
|
||||
return v;
|
||||
}
|
||||
HardwareScene::ResidentMesh* HardwareScene::Resident(const std::shared_ptr<const Render3DDraw>& geometry) {
|
||||
auto it=resident_.find(geometry.get());
|
||||
if(it!=resident_.end()){it->second.lastUsed=frame_;return &it->second;}
|
||||
const auto& mesh=*geometry;
|
||||
const size_t count=mesh.positions.size()/3;
|
||||
if(!count || mesh.indices.empty())return nullptr;
|
||||
for(auto index:mesh.indices)if(index>=count)return nullptr;
|
||||
std::vector<HardwareVertex> packed;packed.reserve(count);
|
||||
for(size_t i=0;i<count;++i)packed.push_back(MakeHardwareVertex(mesh,i));
|
||||
const uint32_t vb=packed.size()*sizeof(HardwareVertex),ib=mesh.indices.size()*sizeof(uint32_t);
|
||||
SDL_GPUBufferCreateInfo bi{};bi.usage=SDL_GPU_BUFFERUSAGE_VERTEX;bi.size=vb;
|
||||
ResidentMesh r;r.source=geometry;r.vertices=SDL_CreateGPUBuffer(device_,&bi);
|
||||
bi.usage=SDL_GPU_BUFFERUSAGE_INDEX;bi.size=ib;r.indices=SDL_CreateGPUBuffer(device_,&bi);
|
||||
SDL_GPUTransferBufferCreateInfo ti{};ti.usage=SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;ti.size=vb+ib;
|
||||
auto* transfer=SDL_CreateGPUTransferBuffer(device_,&ti);
|
||||
auto* bytes=transfer ? static_cast<Uint8*>(SDL_MapGPUTransferBuffer(device_,transfer,false)) : nullptr;
|
||||
auto* command=bytes && r.vertices && r.indices ? SDL_AcquireGPUCommandBuffer(device_) : nullptr;
|
||||
if(!command){if(bytes)SDL_UnmapGPUTransferBuffer(device_,transfer);if(transfer)SDL_ReleaseGPUTransferBuffer(device_,transfer);if(r.vertices)SDL_ReleaseGPUBuffer(device_,r.vertices);if(r.indices)SDL_ReleaseGPUBuffer(device_,r.indices);return nullptr;}
|
||||
std::memcpy(bytes,packed.data(),vb);std::memcpy(bytes+vb,mesh.indices.data(),ib);SDL_UnmapGPUTransferBuffer(device_,transfer);
|
||||
auto* copy=SDL_BeginGPUCopyPass(command);
|
||||
if(!copy){SDL_CancelGPUCommandBuffer(command);SDL_ReleaseGPUTransferBuffer(device_,transfer);SDL_ReleaseGPUBuffer(device_,r.vertices);SDL_ReleaseGPUBuffer(device_,r.indices);return nullptr;}
|
||||
SDL_GPUTransferBufferLocation from{transfer,0};SDL_GPUBufferRegion to{r.vertices,0,vb};SDL_UploadToGPUBuffer(copy,&from,&to,false);
|
||||
from.offset=vb;to={r.indices,0,ib};SDL_UploadToGPUBuffer(copy,&from,&to,false);SDL_EndGPUCopyPass(copy);
|
||||
bool ok=SDL_SubmitGPUCommandBuffer(command);SDL_ReleaseGPUTransferBuffer(device_,transfer);
|
||||
if(!ok){SDL_ReleaseGPUBuffer(device_,r.vertices);SDL_ReleaseGPUBuffer(device_,r.indices);return nullptr;}
|
||||
r.count=mesh.indices.size();r.bytes=vb+ib;r.lastUsed=frame_;residentBytes_+=r.bytes;++residentUploads_;
|
||||
return &resident_.emplace(geometry.get(),std::move(r)).first->second;
|
||||
}
|
||||
bool HardwareScene::Render(SDL_Renderer* renderer,int width,int height,const std::vector<HardwareVertex>& vertices,const std::vector<uint32_t>& indices,const std::vector<HardwareBatch>& batches) {
|
||||
if(batches.empty())return true;
|
||||
const auto tick=SDL_GetPerformanceCounter();++frame_;lastDrawCalls_=0;
|
||||
if(!Initialize(renderer,width,height))return false;
|
||||
if(textureBytes_>textureBudget_) {
|
||||
std::unordered_set<SDL_GPUTexture*> activeTextures{white_};
|
||||
for(const auto& b:batches)if(b.texture)activeTextures.insert(b.texture);
|
||||
for(auto& [key,entry]:textures_)if(activeTextures.count(entry.texture))entry.lastUsed=frame_;
|
||||
while(textureBytes_>textureBudget_) {
|
||||
auto oldest=textures_.end();
|
||||
for(auto it=textures_.begin();it!=textures_.end();++it) {
|
||||
if(it->second.lastUsed>=frame_ || it->second.texture==white_)continue;
|
||||
if(oldest==textures_.end() || it->second.lastUsed<oldest->second.lastUsed)oldest=it;
|
||||
}
|
||||
if(oldest==textures_.end())break; // active working set is protected, even above the soft budget
|
||||
textureBytes_-=oldest->second.bytes;SDL_ReleaseGPUTexture(device_,oldest->second.texture);textures_.erase(oldest);
|
||||
}
|
||||
}
|
||||
// Cached buffers can be released without waiting; SDL defers GPU destruction.
|
||||
for(auto it=resident_.begin();it!=resident_.end();) {
|
||||
if(residentBytes_>256u*1024u*1024u && it->second.lastUsed+2<frame_){
|
||||
residentBytes_-=it->second.bytes;SDL_ReleaseGPUBuffer(device_,it->second.vertices);SDL_ReleaseGPUBuffer(device_,it->second.indices);it=resident_.erase(it);
|
||||
}else ++it;
|
||||
}
|
||||
std::vector<ResidentMesh*> meshes;meshes.reserve(batches.size());
|
||||
for(const auto& b:batches){if(!Pipeline(b))return false;auto* mesh=b.geometry ? Resident(b.geometry) : nullptr;if(b.geometry&&!mesh)return false;meshes.push_back(mesh);}
|
||||
uint32_t vb=vertices.size()*sizeof(HardwareVertex),ib=indices.size()*sizeof(uint32_t);
|
||||
lastDynamicBytes_=vb+ib;
|
||||
if(vb>vertexBytes_||ib>indexBytes_) {
|
||||
if(vertices_)SDL_ReleaseGPUBuffer(device_,vertices_);if(indices_)SDL_ReleaseGPUBuffer(device_,indices_);if(transfer_)SDL_ReleaseGPUTransferBuffer(device_,transfer_);
|
||||
vertexBytes_=std::max(vb,vertexBytes_)*2;indexBytes_=std::max(ib,indexBytes_)*2;
|
||||
SDL_GPUBufferCreateInfo bi{};bi.usage=SDL_GPU_BUFFERUSAGE_VERTEX;bi.size=vertexBytes_;vertices_=SDL_CreateGPUBuffer(device_,&bi);
|
||||
bi.usage=SDL_GPU_BUFFERUSAGE_INDEX;bi.size=indexBytes_;indices_=SDL_CreateGPUBuffer(device_,&bi);
|
||||
SDL_GPUTransferBufferCreateInfo ti{};ti.usage=SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;ti.size=vertexBytes_+indexBytes_;transfer_=SDL_CreateGPUTransferBuffer(device_,&ti);
|
||||
}
|
||||
if(vb || ib){
|
||||
if(!vertices_||!indices_||!transfer_)return false;
|
||||
auto* data=static_cast<Uint8*>(SDL_MapGPUTransferBuffer(device_,transfer_,true));if(!data)return false;
|
||||
std::memcpy(data,vertices.data(),vb);std::memcpy(data+vb,indices.data(),ib);SDL_UnmapGPUTransferBuffer(device_,transfer_);
|
||||
}
|
||||
const uint32_t instanceSize=std::max<size_t>(1,batches.size())*sizeof(HardwareTransform);
|
||||
if(instanceSize>instanceBytes_){
|
||||
if(instances_)SDL_ReleaseGPUBuffer(device_,instances_);if(instanceTransfer_)SDL_ReleaseGPUTransferBuffer(device_,instanceTransfer_);
|
||||
instanceBytes_=instanceSize*2;SDL_GPUBufferCreateInfo bi{};bi.usage=SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ;bi.size=instanceBytes_;instances_=SDL_CreateGPUBuffer(device_,&bi);
|
||||
SDL_GPUTransferBufferCreateInfo ti{};ti.usage=SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;ti.size=instanceBytes_;instanceTransfer_=SDL_CreateGPUTransferBuffer(device_,&ti);
|
||||
}
|
||||
if(!instances_||!instanceTransfer_)return false;
|
||||
auto* instData=static_cast<HardwareTransform*>(SDL_MapGPUTransferBuffer(device_,instanceTransfer_,true));if(!instData)return false;
|
||||
for(size_t i=0;i<batches.size();++i)instData[i]=batches[i].transform;
|
||||
SDL_UnmapGPUTransferBuffer(device_,instanceTransfer_);
|
||||
if(!SDL_FlushRenderer(renderer))return false;
|
||||
auto* cmd=SDL_AcquireGPUCommandBuffer(device_);if(!cmd)return false;
|
||||
auto* copy=SDL_BeginGPUCopyPass(cmd);if(!copy){SDL_CancelGPUCommandBuffer(cmd);return false;}
|
||||
SDL_GPUTransferBufferLocation source{};SDL_GPUBufferRegion dest{};
|
||||
if(vb||ib){source={transfer_,0};dest={vertices_,0,vb};SDL_UploadToGPUBuffer(copy,&source,&dest,true);source.offset=vb;dest={indices_,0,ib};SDL_UploadToGPUBuffer(copy,&source,&dest,true);}
|
||||
source={instanceTransfer_,0};dest={instances_,0,instanceSize};SDL_UploadToGPUBuffer(copy,&source,&dest,true);SDL_EndGPUCopyPass(copy);
|
||||
SDL_GPUColorTargetInfo color{};color.texture=color_;color.clear_color={0,0,0,0};color.load_op=SDL_GPU_LOADOP_CLEAR;color.store_op=SDL_GPU_STOREOP_STORE;
|
||||
SDL_GPUDepthStencilTargetInfo depth{};depth.texture=depth_;depth.clear_depth=1;depth.load_op=SDL_GPU_LOADOP_CLEAR;depth.store_op=SDL_GPU_STOREOP_DONT_CARE;depth.stencil_load_op=SDL_GPU_LOADOP_DONT_CARE;depth.stencil_store_op=SDL_GPU_STOREOP_DONT_CARE;
|
||||
auto* pass=SDL_BeginGPURenderPass(cmd,&color,1,&depth);if(!pass){SDL_CancelGPUCommandBuffer(cmd);return false;}
|
||||
SDL_BindGPUVertexStorageBuffers(pass,0,&instances_,1);
|
||||
float palette[128*16]{};SDL_PushGPUVertexUniformData(cmd,1,palette,sizeof(palette));
|
||||
for(size_t i=0;i<batches.size();) {
|
||||
const auto& batch=batches[i];auto* mesh=meshes[i];
|
||||
size_t count=1;
|
||||
// Instance only compatible opaque resident meshes; preserve all translucent ordering.
|
||||
if(mesh && !batch.blend && !batch.additive && batch.depthWrite && batch.transform.skin[0]==0 && batch.transform.modes[0]>0.5f)
|
||||
while(i+count<batches.size()) {
|
||||
const auto& next=batches[i+count];
|
||||
if(meshes[i+count]!=mesh || next.texture!=batch.texture || next.cull!=batch.cull || next.depth!=batch.depth || next.depthWrite!=batch.depthWrite || next.blend || next.additive || next.alphaRef!=batch.alphaRef || next.transform.skin[0]!=0 || next.transform.modes[0]<.5f)break;
|
||||
++count;
|
||||
}
|
||||
SDL_GPUBufferBinding binding{mesh ? mesh->vertices : vertices_,0};SDL_BindGPUVertexBuffers(pass,0,&binding,1);
|
||||
binding.buffer=mesh ? mesh->indices : indices_;SDL_BindGPUIndexBuffer(pass,&binding,SDL_GPU_INDEXELEMENTSIZE_32BIT);
|
||||
SDL_BindGPUGraphicsPipeline(pass,Pipeline(batch));
|
||||
SDL_GPUTextureSamplerBinding texture{batch.texture ? batch.texture : white_,sampler_};SDL_BindGPUFragmentSamplers(pass,0,&texture,1);
|
||||
float params[4]={batch.alphaRef,(!batch.blend&&!batch.additive)?1.f:0.f,0,0};SDL_PushGPUFragmentUniformData(cmd,0,params,sizeof(params));
|
||||
auto transform=batch.transform;if(count>1)transform.modes[0]=2;
|
||||
SDL_PushGPUVertexUniformData(cmd,0,&transform,sizeof(transform));
|
||||
if(transform.skin[0]>0){std::fill(std::begin(palette),std::end(palette),0);std::copy_n(batch.palette.data(),std::min(batch.palette.size(),size_t(128*16)),palette);SDL_PushGPUVertexUniformData(cmd,1,palette,sizeof(palette));}
|
||||
SDL_DrawGPUIndexedPrimitives(pass,batch.indexCount,count,mesh ? 0 : batch.firstIndex,0,count>1 ? i : 0);++lastDrawCalls_;i+=count;
|
||||
}
|
||||
SDL_EndGPURenderPass(pass);const auto beforeSubmit=SDL_GetPerformanceCounter();
|
||||
if(!SDL_SubmitGPUCommandBuffer(cmd))return false;
|
||||
static unsigned count=0;if(++count%120==0)SDL_Log("Resident GPU batches=%zu calls=%zu dynamic=%zu resident=%zu uploads=%zu encode=%.2f submit=%.2f ms",batches.size(),lastDrawCalls_,lastDynamicBytes_,residentBytes_,residentUploads_,1000.0*(beforeSubmit-tick)/SDL_GetPerformanceFrequency(),1000.0*(SDL_GetPerformanceCounter()-beforeSubmit)/SDL_GetPerformanceFrequency());
|
||||
float w,h;SDL_Texture* target=SDL_GetRenderTarget(renderer);
|
||||
if(target)SDL_GetTextureSize(target,&w,&h);else {int lw,lh;SDL_RendererLogicalPresentation lp;SDL_GetRenderLogicalPresentation(renderer,&lw,&lh,&lp);w=lw;h=lh;if(w<=0||h<=0){int pw,ph;SDL_GetRenderOutputSize(renderer,&pw,&ph);w=pw;h=ph;}}
|
||||
SDL_FRect rect{0,0,w,h};return SDL_RenderTexture(renderer,output_,nullptr,&rect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "RenderCommands3D.h"
|
||||
namespace ava2 {
|
||||
struct HardwareVertex {
|
||||
float position[4], color[4], uv[2];
|
||||
float normal[4]{};
|
||||
uint32_t bones[4]{};
|
||||
float weights[4]{};
|
||||
};
|
||||
struct HardwareTransform {
|
||||
float world[16]{}, mvp[16]{};
|
||||
float diffuse[4]{}, ambient[4]{}, emissive[4]{};
|
||||
float lightDirection[4]{}, lightAmbient[4]{}, lightDiffuse[4]{};
|
||||
float fogColor[4]{}, fogParams[4]{};
|
||||
float modes[4]{}; // raw vertices, lighting, fog type, disable depth
|
||||
float skin[4]{}; // palette count
|
||||
};
|
||||
static_assert(sizeof(HardwareTransform)==288);
|
||||
HardwareVertex MakeHardwareVertex(const Render3DDraw& mesh, size_t index);
|
||||
struct HardwareBatch {
|
||||
uint32_t firstIndex, indexCount;
|
||||
SDL_GPUTexture* texture;
|
||||
uint32_t cull;
|
||||
bool depth, depthWrite, blend, additive;
|
||||
float alphaRef;
|
||||
HardwareTransform transform{};
|
||||
std::shared_ptr<const Render3DDraw> geometry;
|
||||
std::vector<float> palette;
|
||||
|
||||
};
|
||||
class HardwareScene {
|
||||
public:
|
||||
explicit HardwareScene(SDL_GPUDevice* device): device_(device) {}
|
||||
~HardwareScene();
|
||||
SDL_GPUTexture* FindTexture(const std::string& key);
|
||||
void SetTextureBudget(size_t bytes) { textureBudget_=bytes; }
|
||||
size_t GetTextureBytes() const { return textureBytes_; }
|
||||
size_t GetTextureUploadCount() const { return textureUploads_; }
|
||||
SDL_GPUTexture* Texture(const std::string& key, int width, int height, const void* rgba);
|
||||
bool Render(SDL_Renderer* renderer, int width, int height,
|
||||
const std::vector<HardwareVertex>& vertices,
|
||||
const std::vector<uint32_t>& indices,
|
||||
const std::vector<HardwareBatch>& batches);
|
||||
size_t GetResidentUploadCount() const { return residentUploads_; }
|
||||
size_t GetLastDrawCallCount() const { return lastDrawCalls_; }
|
||||
size_t GetLastDynamicUploadBytes() const { return lastDynamicBytes_; }
|
||||
private:
|
||||
struct ResidentMesh {
|
||||
std::shared_ptr<const Render3DDraw> source;
|
||||
SDL_GPUBuffer *vertices=nullptr, *indices=nullptr;
|
||||
uint32_t count=0, bytes=0;
|
||||
uint64_t lastUsed=0;
|
||||
};
|
||||
ResidentMesh* Resident(const std::shared_ptr<const Render3DDraw>& geometry);
|
||||
std::unordered_map<const Render3DDraw*,ResidentMesh> resident_;
|
||||
uint64_t frame_=0;
|
||||
size_t residentBytes_=0, residentUploads_=0, lastDrawCalls_=0, lastDynamicBytes_=0;
|
||||
SDL_GPUBuffer* instances_=nullptr;
|
||||
SDL_GPUTransferBuffer* instanceTransfer_=nullptr;
|
||||
uint32_t instanceBytes_=0;
|
||||
bool Initialize(SDL_Renderer* renderer, int width, int height);
|
||||
SDL_GPUGraphicsPipeline* Pipeline(const HardwareBatch& batch);
|
||||
SDL_GPUDevice* device_;
|
||||
SDL_GPUShader *vertex_=nullptr, *fragment_=nullptr;
|
||||
SDL_GPUSampler* sampler_=nullptr;
|
||||
SDL_GPUTexture *color_=nullptr, *depth_=nullptr;
|
||||
SDL_Texture* output_=nullptr;
|
||||
SDL_GPUTexture* white_=nullptr;
|
||||
struct TextureEntry {SDL_GPUTexture* texture;size_t bytes;uint64_t lastUsed;};
|
||||
std::unordered_map<std::string,TextureEntry> textures_;
|
||||
size_t textureBytes_=0,textureUploads_=0,textureBudget_=256u*1024u*1024u;
|
||||
SDL_GPUBuffer *vertices_=nullptr, *indices_=nullptr;
|
||||
SDL_GPUTransferBuffer* transfer_=nullptr;
|
||||
uint32_t vertexBytes_=0, indexBytes_=0;
|
||||
int width_=0,height_=0;
|
||||
std::unordered_map<unsigned,SDL_GPUGraphicsPipeline*> pipelines_;
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "MapObjectManager.h"
|
||||
#include <limits>
|
||||
#include "src/eter_render/SpeedTreeForest.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -130,7 +131,7 @@ std::shared_ptr<Gr2ModelInstance> MapObjectManager::GetOrLoadModel(const std::st
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool MapObjectManager::LoadAreaData(const std::string& areadata_path, float coord_scale, SpeedTreeForest* forest) {
|
||||
bool MapObjectManager::LoadAreaData(const std::string& areadata_path, float coord_scale, SpeedTreeForest* forest, bool native_y) {
|
||||
std::ifstream file(areadata_path);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "MapObjectManager::LoadAreaData failed to open: " << areadata_path << std::endl;
|
||||
@@ -166,6 +167,8 @@ bool MapObjectManager::LoadAreaData(const std::string& areadata_path, float coor
|
||||
|
||||
std::istringstream iss(block_lines[0]);
|
||||
iss >> px >> py >> pz;
|
||||
// AVA2 areadata stores the render-space Y sign; packets use positive map Y.
|
||||
if (native_y) py = -py;
|
||||
|
||||
try {
|
||||
crc = static_cast<uint32_t>(std::stoul(block_lines[1]));
|
||||
@@ -182,6 +185,12 @@ bool MapObjectManager::LoadAreaData(const std::string& areadata_path, float coor
|
||||
if (s2 != std::string::npos) {
|
||||
pitch = std::stof(rot_str.substr(s1 + 1, s2 - s1 - 1));
|
||||
roll = std::stof(rot_str.substr(s2 + 1));
|
||||
if (native_y) {
|
||||
// Native roll rotates about Z (up); that is engine Y yaw.
|
||||
const float nativeYaw = yaw;
|
||||
yaw = roll;
|
||||
roll = -nativeYaw;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try { yaw = std::stof(rot_str); } catch (...) {}
|
||||
@@ -296,8 +305,44 @@ bool MapObjectManager::AddObject(const std::string& model_path, float x, float y
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::vector<size_t>& MapObjectManager::CollisionCandidates(float x,float z,float radius) const {
|
||||
constexpr double cell=512;
|
||||
if(m_collisionCount!=m_objects.size()) {
|
||||
m_collisionCells.clear();m_largeCollisionObjects.clear();m_allCollisionObjects.clear();
|
||||
for(size_t i=0;i<m_objects.size();++i) {
|
||||
const auto& obj=m_objects[i];if(!obj.has_collision)continue;
|
||||
m_allCollisionObjects.push_back(i);
|
||||
const double r=std::max(std::abs(obj.obb.halfExtents[0]),std::abs(obj.obb.halfExtents[2]))*1.5;
|
||||
const double cx=obj.obb.centerX,cz=obj.obb.centerZ;
|
||||
if(!std::isfinite(r) || !std::isfinite(cx) || !std::isfinite(cz) || std::abs(cx)+r>1e9 || std::abs(cz)+r>1e9 || r>4096) {
|
||||
m_largeCollisionObjects.push_back(i);continue;
|
||||
}
|
||||
const auto x0=int64_t(std::floor((cx-r)/cell)),x1=int64_t(std::floor((cx+r)/cell));
|
||||
const auto z0=int64_t(std::floor((cz-r)/cell)),z1=int64_t(std::floor((cz+r)/cell));
|
||||
if((x1-x0+1)*(z1-z0+1)>256){m_largeCollisionObjects.push_back(i);continue;}
|
||||
for(auto gx=x0;gx<=x1;++gx)for(auto gz=z0;gz<=z1;++gz)m_collisionCells[{gx,gz}].push_back(i);
|
||||
}
|
||||
m_collisionCount=m_objects.size();
|
||||
}
|
||||
m_collisionCandidates.clear();
|
||||
if(!std::isfinite(x) || !std::isfinite(z) || !std::isfinite(radius) || radius<0 || radius>4096 || std::abs(double(x))+radius>1e9 || std::abs(double(z))+radius>1e9) {
|
||||
m_collisionCandidates=m_allCollisionObjects;return m_collisionCandidates;
|
||||
}
|
||||
m_collisionCandidates.insert(m_collisionCandidates.end(),m_largeCollisionObjects.begin(),m_largeCollisionObjects.end());
|
||||
const auto x0=int64_t(std::floor((double(x)-radius)/cell)),x1=int64_t(std::floor((double(x)+radius)/cell));
|
||||
const auto z0=int64_t(std::floor((double(z)-radius)/cell)),z1=int64_t(std::floor((double(z)+radius)/cell));
|
||||
for(auto gx=x0;gx<=x1;++gx)for(auto gz=z0;gz<=z1;++gz) {
|
||||
auto it=m_collisionCells.find({gx,gz});if(it!=m_collisionCells.end())m_collisionCandidates.insert(m_collisionCandidates.end(),it->second.begin(),it->second.end());
|
||||
}
|
||||
// Preserve the original first-hit normal when OBBs overlap, independent of cell order.
|
||||
std::sort(m_collisionCandidates.begin(),m_collisionCandidates.end());
|
||||
m_collisionCandidates.erase(std::unique(m_collisionCandidates.begin(),m_collisionCandidates.end()),m_collisionCandidates.end());
|
||||
return m_collisionCandidates;
|
||||
}
|
||||
|
||||
bool MapObjectManager::CheckCollision(float worldX, float worldZ, float actorRadius) const {
|
||||
for (const auto& obj : m_objects) {
|
||||
for (auto index : CollisionCandidates(worldX,worldZ,actorRadius)) {
|
||||
const auto& obj=m_objects[index];
|
||||
if (!obj.has_collision) continue;
|
||||
float maxR = std::max(obj.obb.halfExtents[0], obj.obb.halfExtents[2]) * 1.5f + actorRadius;
|
||||
float dx = worldX - obj.obb.centerX;
|
||||
@@ -312,7 +357,8 @@ bool MapObjectManager::CheckCollision(float worldX, float worldZ, float actorRad
|
||||
}
|
||||
|
||||
bool MapObjectManager::CheckCollisionNormal(float worldX, float worldZ, float actorRadius, float& outNx, float& outNz) const {
|
||||
for (const auto& obj : m_objects) {
|
||||
for (auto index : CollisionCandidates(worldX,worldZ,actorRadius)) {
|
||||
const auto& obj=m_objects[index];
|
||||
if (!obj.has_collision) continue;
|
||||
float maxR = std::max(obj.obb.halfExtents[0], obj.obb.halfExtents[2]) * 1.5f + actorRadius;
|
||||
float dx = worldX - obj.obb.centerX;
|
||||
@@ -327,23 +373,46 @@ bool MapObjectManager::CheckCollisionNormal(float worldX, float worldZ, float ac
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<Render3DDraw> MapObjectManager::BuildDrawCommands() const {
|
||||
std::vector<Render3DDraw> MapObjectManager::BuildDrawCommands(const float* view, const float* proj) const {
|
||||
std::vector<Render3DDraw> all_draws;
|
||||
for (const auto& obj : m_objects) {
|
||||
if (!obj.model) continue;
|
||||
|
||||
float world[16];
|
||||
MakeFullTransformMatrix(obj.yaw, obj.pitch, obj.roll, obj.x, obj.y, obj.z, obj.scale, world);
|
||||
auto draws = obj.model->BuildDrawCommands(-1.0f, world);
|
||||
for (auto& d : draws) {
|
||||
all_draws.push_back(std::move(d));
|
||||
if (!obj.draws_cached) {
|
||||
obj.cached_draws = obj.model->BuildDrawCommands(-1.0f, world, true);
|
||||
std::fill_n(obj.bounds_min, 3, std::numeric_limits<float>::max());
|
||||
std::fill_n(obj.bounds_max, 3, std::numeric_limits<float>::lowest());
|
||||
for (const auto& draw : obj.cached_draws) {
|
||||
for (size_t i=0; i+2<draw.positions.size(); i+=3) {
|
||||
for (int axis=0; axis<3; ++axis) {
|
||||
float v = draw.positions[i]*draw.world[axis] + draw.positions[i+1]*draw.world[4+axis] +
|
||||
draw.positions[i+2]*draw.world[8+axis] + draw.world[12+axis];
|
||||
obj.bounds_min[axis] = std::min(obj.bounds_min[axis], v);
|
||||
obj.bounds_max[axis] = std::max(obj.bounds_max[axis], v);
|
||||
}
|
||||
}
|
||||
}
|
||||
auto& streams=m_meshStreams[obj.model.get()];
|
||||
for (size_t i=0;i<obj.cached_draws.size();++i) {
|
||||
auto& draw=obj.cached_draws[i];
|
||||
draw=Render3DDraw::ShareGeometry(std::move(draw));
|
||||
if(i<streams.size()) draw.geometry=streams[i];
|
||||
else streams.push_back(draw.geometry);
|
||||
}
|
||||
obj.draws_cached = true;
|
||||
}
|
||||
if (!IsBoundsVisible(obj.bounds_min, obj.bounds_max, view, proj)) continue;
|
||||
all_draws.insert(all_draws.end(), obj.cached_draws.begin(), obj.cached_draws.end());
|
||||
}
|
||||
return all_draws;
|
||||
}
|
||||
|
||||
void MapObjectManager::ClearObjects() {
|
||||
m_objects.clear();
|
||||
m_collisionCount=std::numeric_limits<size_t>::max();
|
||||
m_collisionCells.clear();m_allCollisionObjects.clear();m_largeCollisionObjects.clear();m_collisionCandidates.clear();
|
||||
}
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <limits>
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
@@ -96,6 +98,9 @@ struct MapObjectInstance {
|
||||
std::shared_ptr<Gr2ModelInstance> model;
|
||||
OrientedBoundingBox obb;
|
||||
bool has_collision = true;
|
||||
mutable float bounds_min[3]{}, bounds_max[3]{};
|
||||
mutable bool draws_cached = false;
|
||||
mutable std::vector<Render3DDraw> cached_draws;
|
||||
};
|
||||
|
||||
class SpeedTreeForest;
|
||||
@@ -117,7 +122,7 @@ public:
|
||||
size_t ScanPropertyDirectory(const std::string& prop_dir);
|
||||
|
||||
// Load AreaData.txt and instantiate objects (GR2 buildings and SpeedTree instances)
|
||||
bool LoadAreaData(const std::string& areadata_path, float coord_scale = 1.0f, SpeedTreeForest* forest = nullptr);
|
||||
bool LoadAreaData(const std::string& areadata_path, float coord_scale = 1.0f, SpeedTreeForest* forest = nullptr, bool native_y = false);
|
||||
|
||||
// Manually add an object instance
|
||||
bool AddObject(const std::string& model_path, float x, float y, float z,
|
||||
@@ -128,12 +133,13 @@ public:
|
||||
bool CheckCollisionNormal(float worldX, float worldZ, float actorRadius, float& outNx, float& outNz) const;
|
||||
|
||||
// Build 3D draw commands for all instantiated objects
|
||||
std::vector<Render3DDraw> BuildDrawCommands() const;
|
||||
std::vector<Render3DDraw> BuildDrawCommands(const float* view = nullptr, const float* proj = nullptr) const;
|
||||
|
||||
// Clear all instantiated objects (retaining loaded model cache)
|
||||
void ClearObjects();
|
||||
|
||||
// Query stats
|
||||
size_t GetLastCollisionCandidateCount() const { return m_collisionCandidates.size(); }
|
||||
size_t GetObjectCount() const { return m_objects.size(); }
|
||||
size_t GetPropertyCount() const { return m_property_map.size(); }
|
||||
size_t GetCachedModelCount() const { return m_model_cache.size(); }
|
||||
@@ -141,11 +147,16 @@ public:
|
||||
const std::vector<MapObjectInstance>& GetObjects() const { return m_objects; }
|
||||
|
||||
private:
|
||||
const std::vector<size_t>& CollisionCandidates(float x,float z,float radius) const;
|
||||
mutable size_t m_collisionCount=std::numeric_limits<size_t>::max();
|
||||
mutable std::map<std::pair<int64_t,int64_t>,std::vector<size_t>> m_collisionCells;
|
||||
mutable std::vector<size_t> m_largeCollisionObjects,m_allCollisionObjects,m_collisionCandidates;
|
||||
std::shared_ptr<Gr2ModelInstance> GetOrLoadModel(const std::string& path);
|
||||
static std::string NormalizePath(const std::string& path);
|
||||
|
||||
std::unordered_map<uint32_t, std::string> m_property_map;
|
||||
std::unordered_map<std::string, std::shared_ptr<Gr2ModelInstance>> m_model_cache;
|
||||
mutable std::unordered_map<const Gr2ModelInstance*,std::vector<std::shared_ptr<const Render3DDraw>>> m_meshStreams;
|
||||
std::vector<MapObjectInstance> m_objects;
|
||||
};
|
||||
|
||||
|
||||
@@ -49,10 +49,10 @@ void OrbitCamera::GetEye(float& eyeX, float& eyeY, float& eyeZ) const {
|
||||
|
||||
eyeX = m_targetX - horiz * std::sin(yawRad);
|
||||
eyeY = m_targetY + m_targetHeight + vert;
|
||||
eyeZ = m_targetZ - horiz * std::cos(yawRad);
|
||||
eyeZ = m_targetZ + horiz * std::cos(yawRad);
|
||||
}
|
||||
|
||||
void OrbitCamera::UpdateWithTerrain(const TerrainHeightmap* terrain) {
|
||||
void OrbitCamera::UpdateWithTerrain(const TerrainHeightSource* terrain) {
|
||||
if (!terrain) return;
|
||||
|
||||
float pitchRad = m_pitch * DEG_TO_RAD;
|
||||
@@ -63,7 +63,7 @@ void OrbitCamera::UpdateWithTerrain(const TerrainHeightmap* terrain) {
|
||||
|
||||
float eyeX = m_targetX - horiz * std::sin(yawRad);
|
||||
float eyeY = m_targetY + m_targetHeight + vert;
|
||||
float eyeZ = m_targetZ - horiz * std::cos(yawRad);
|
||||
float eyeZ = m_targetZ + horiz * std::cos(yawRad);
|
||||
|
||||
float groundY = terrain->GetHeightAtWorld(eyeX, eyeZ);
|
||||
float minGroundY = groundY + 45.0f;
|
||||
@@ -103,7 +103,7 @@ void OrbitCamera::ApplyToRenderer(Gr2SceneRenderer& renderer) const {
|
||||
float tX = 0.0f, tY = 0.0f, tZ = 0.0f;
|
||||
GetLookTarget(tX, tY, tZ);
|
||||
|
||||
renderer.SetCameraLookAt(eyeX, eyeY, eyeZ, tX, tY, tZ, 0.0f, 1.0f, 0.0f);
|
||||
renderer.SetCameraLookAtRH(eyeX, eyeY, eyeZ, tX, tY, tZ, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
void Zoom(float wheelDelta, float zoomStep = 40.0f);
|
||||
|
||||
// Collision avoidance with terrain heightmap
|
||||
void UpdateWithTerrain(const class TerrainHeightmap* terrain);
|
||||
void UpdateWithTerrain(const class TerrainHeightSource* terrain);
|
||||
|
||||
// Coordinate Queries
|
||||
void GetEye(float& eyeX, float& eyeY, float& eyeZ) const;
|
||||
@@ -67,7 +67,7 @@ private:
|
||||
float m_yaw = 0.0f;
|
||||
|
||||
float m_minDistance = 120.0f;
|
||||
float m_maxDistance = 1800.0f;
|
||||
float m_maxDistance = 2500.0f;
|
||||
float m_minPitch = 5.0f;
|
||||
float m_maxPitch = 85.0f;
|
||||
|
||||
|
||||
@@ -449,6 +449,21 @@ void RaceManager::LoadPlayerRaces() {
|
||||
case 2: race->RegisterAttachingBoneName(RaceData::PART_WEAPON, "equip_right"); break;
|
||||
}
|
||||
race->RegisterAttachingBoneName(RaceData::PART_SASH, "Bip01 Spine2"); // ENABLE_SASH_SYSTEM
|
||||
race->RegisterMotionData(RaceData::NAME_INTRO_WAIT, kRaces[i].path + std::string("intro/wait.msa"), 100);
|
||||
race->RegisterMotionData(RaceData::NAME_INTRO_SELECTED, kRaces[i].path + std::string("intro/selected.msa"), 100);
|
||||
race->RegisterMotionData(RaceData::NAME_INTRO_NOT_SELECTED, kRaces[i].path + std::string("intro/not_selected.msa"), 100);
|
||||
race->RegisterMotionData(RaceData::NAME_WAIT, kRaces[i].path + std::string("general/wait.msa"), 100);
|
||||
race->RegisterMotionData(RaceData::NAME_WALK, kRaces[i].path + std::string("general/walk.msa"), 100);
|
||||
race->RegisterMotionData(RaceData::NAME_RUN, kRaces[i].path + std::string("general/run.msa"), 100);
|
||||
race->RegisterMotionData(RaceData::NAME_DEAD, kRaces[i].path + std::string("general/dead.msa"), 100);
|
||||
// CPythonPlayerSettingsModule::__LoadHorse: mounted riders use a distinct pose.
|
||||
race->RegisterMotionMode(9);
|
||||
for (const auto& motion : {std::pair{RaceData::NAME_WAIT, "wait.msa"},
|
||||
std::pair{RaceData::NAME_WALK, "walk.msa"},
|
||||
std::pair{RaceData::NAME_RUN, "run.msa"},
|
||||
std::pair{RaceData::NAME_DEAD, "dead.msa"}})
|
||||
race->RegisterMotion(9, motion.first, kRaces[i].path + std::string("horse/") + motion.second, 100);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
namespace ava2 {
|
||||
|
||||
@@ -17,9 +18,46 @@ inline void MakeTransformMatrix(float yawDegrees, float tx, float ty, float tz,
|
||||
out[12] = tx; out[13] = ty; out[14] = tz; out[15] = 1.0f;
|
||||
}
|
||||
|
||||
// Conservative homogeneous frustum rejection, including near/far planes.
|
||||
// Reject only when every AABB corner is outside the same plane.
|
||||
inline bool IsBoundsVisible(const float lo[3], const float hi[3], const float* view, const float* proj) {
|
||||
if (!view || !proj) return true;
|
||||
unsigned outside = 63;
|
||||
for (unsigned corner = 0; corner < 8; ++corner) {
|
||||
float p[4] = {corner&1 ? hi[0] : lo[0], corner&2 ? hi[1] : lo[1], corner&4 ? hi[2] : lo[2], 1};
|
||||
float v[4]{}, c[4]{};
|
||||
for (int j=0;j<4;++j) for(int k=0;k<4;++k) v[j]+=p[k]*view[k*4+j];
|
||||
for (int j=0;j<4;++j) for(int k=0;k<4;++k) c[j]+=v[k]*proj[k*4+j];
|
||||
unsigned bits = (c[0]<-c[3] ? 1:0) | (c[0]>c[3] ? 2:0) | (c[1]<-c[3] ? 4:0) |
|
||||
(c[1]>c[3] ? 8:0) | (c[2]<0 ? 16:0) | (c[2]>c[3] ? 32:0);
|
||||
outside &= bits;
|
||||
if (!outside) return true;
|
||||
}
|
||||
return outside == 0;
|
||||
}
|
||||
|
||||
// Intermediate 3D draw command structure, modeled after 40250 cross-platform architecture.
|
||||
// Decouples game logic/animation (GR2) from the underlying GPU/software renderer.
|
||||
struct Render3DDraw {
|
||||
// Per-frame commands reference immutable mesh streams; transforms/material remain local.
|
||||
std::shared_ptr<const Render3DDraw> geometry;
|
||||
const Render3DDraw& Mesh() const { return geometry ? *geometry : *this; }
|
||||
static Render3DDraw ShareGeometry(Render3DDraw source) {
|
||||
Render3DDraw command = source;
|
||||
command.positions.clear(); command.positions.shrink_to_fit();
|
||||
command.normals.clear(); command.normals.shrink_to_fit();
|
||||
command.uv0.clear(); command.uv0.shrink_to_fit();
|
||||
command.uv1.clear(); command.uv1.shrink_to_fit();
|
||||
command.diffuse.clear(); command.diffuse.shrink_to_fit();
|
||||
command.indices.clear(); command.indices.shrink_to_fit();
|
||||
command.bone_indices.clear(); command.bone_indices.shrink_to_fit();
|
||||
command.bone_weights.clear(); command.bone_weights.shrink_to_fit();
|
||||
command.bone_matrices.clear(); command.bone_matrices.shrink_to_fit();
|
||||
command.geometry = std::make_shared<const Render3DDraw>(std::move(source));
|
||||
return command;
|
||||
}
|
||||
|
||||
bool gpu_skinning = false;
|
||||
std::uint64_t geometry_key = 0;
|
||||
std::uint64_t geometry_revision = 0;
|
||||
|
||||
@@ -56,15 +94,16 @@ struct Render3DDraw {
|
||||
bool alpha_test = false;
|
||||
std::uint32_t alpha_ref = 0;
|
||||
bool fog = true;
|
||||
bool terrain = false; // SDL painter layers keep terrain splats ahead of actors.
|
||||
|
||||
// Lighting & Material
|
||||
bool lighting = true;
|
||||
float material_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
float material_ambient[4] = {0.4f, 0.4f, 0.4f, 1.0f};
|
||||
float material_emissive[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
float material_ambient[4] = {0.85f, 0.85f, 0.85f, 1.0f};
|
||||
float material_emissive[4] = {0.05f, 0.05f, 0.05f, 0.05f};
|
||||
float light_direction[3] = {0.577f, 0.577f, -0.577f}; // Normalized key light
|
||||
float light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
float light_ambient[4] = {0.3f, 0.3f, 0.3f, 1.0f};
|
||||
float light_ambient[4] = {0.55f, 0.55f, 0.55f, 1.0f};
|
||||
};
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
+44
-138
@@ -81,7 +81,7 @@ std::vector<Render3DDraw> SkyBox::BuildDrawCommands(const float* viewMatrix,
|
||||
}
|
||||
|
||||
// Radiant Sun Flare Billboard
|
||||
if (m_env.lens_flare.main_flare_enable && !m_env.lens_flare.main_flare_file_name.empty()) {
|
||||
if (m_env.lens_flare.enable && m_env.lens_flare.main_flare_enable && !m_env.lens_flare.main_flare_file_name.empty()) {
|
||||
draws.push_back(BuildSunFlareBillboard(viewMatrix, camEyeX, camEyeY, camEyeZ));
|
||||
}
|
||||
|
||||
@@ -89,137 +89,44 @@ std::vector<Render3DDraw> SkyBox::BuildDrawCommands(const float* viewMatrix,
|
||||
}
|
||||
|
||||
Render3DDraw SkyBox::BuildGradientSkyDome(float camEyeX, float camEyeY, float camEyeZ) {
|
||||
// AVA2 EterLib/SkyBox.cpp SetSkyObjectQuadVertical/SetSkyColor: four
|
||||
// vertical cube faces, upper/lower height bands, plus flat top and bottom.
|
||||
Render3DDraw draw;
|
||||
draw.lighting = false;
|
||||
draw.fog = false;
|
||||
draw.z_enable = false; // Pure background layer
|
||||
draw.z_write = false;
|
||||
draw.cull_mode = 1; // Double-sided / interior facing
|
||||
|
||||
constexpr int SECTORS = 24;
|
||||
constexpr int NUM_UPPER = 8;
|
||||
constexpr int NUM_LOWER = 4;
|
||||
constexpr int NUM_RINGS = NUM_UPPER + NUM_LOWER + 1;
|
||||
|
||||
struct RingLevel {
|
||||
float y_offset;
|
||||
float radius;
|
||||
uint32_t color;
|
||||
draw.lighting=draw.fog=draw.z_enable=draw.z_write=false;
|
||||
draw.cull_mode=1;
|
||||
const auto& sky=m_env.skybox;
|
||||
const int upper=std::max(1,int(sky.gradient_level_upper));
|
||||
const int lower=std::max(1,int(sky.gradient_level_lower));
|
||||
const float sx=sky.scale[0]>0 ? sky.scale[0] : m_radius;
|
||||
const float sy=sky.scale[2]>0 ? sky.scale[2] : m_radius;
|
||||
const float sz=sky.scale[1]>0 ? sky.scale[1] : m_radius;
|
||||
auto color=[&](int band,bool top) {
|
||||
if(sky.gradients.empty())return 0xff80b3f2u;
|
||||
const auto& gradient=sky.gradients[std::min(size_t(band),sky.gradients.size()-1)];
|
||||
return ColorToUint(top ? gradient.first : gradient.second) | 0xff000000;
|
||||
};
|
||||
|
||||
std::vector<RingLevel> rings;
|
||||
rings.reserve(NUM_RINGS);
|
||||
|
||||
// Build upper rings (zenith 80 deg down to horizon 2 deg)
|
||||
for (int k = 0; k <= NUM_UPPER; ++k) {
|
||||
float t = static_cast<float>(k) / static_cast<float>(NUM_UPPER); // 0 at top, 1 at horizon
|
||||
float angle_deg = 80.0f - t * 78.0f; // 80 -> 2 deg
|
||||
float phi = angle_deg * DEG2RAD;
|
||||
float y_off = m_radius * std::sin(phi);
|
||||
float rad = m_radius * std::cos(phi);
|
||||
|
||||
float col[4];
|
||||
float grad_t = t * 0.80f; // Maps to upper portion of gradients
|
||||
InterpolateGradientColor(m_env.skybox.gradients, grad_t, col);
|
||||
rings.push_back({y_off, rad, ColorToUint(col)});
|
||||
auto quad=[&](float x0,float z0,float x1,float z1,float bottom,float top,uint32_t lowColor,uint32_t highColor) {
|
||||
uint32_t base=draw.positions.size()/3;
|
||||
draw.positions.insert(draw.positions.end(),{camEyeX+x0,camEyeY+bottom,camEyeZ+z0,
|
||||
camEyeX+x0,camEyeY+top,camEyeZ+z0,camEyeX+x1,camEyeY+bottom,camEyeZ+z1,
|
||||
camEyeX+x1,camEyeY+top,camEyeZ+z1});
|
||||
draw.diffuse.insert(draw.diffuse.end(),{lowColor,highColor,lowColor,highColor});
|
||||
draw.indices.insert(draw.indices.end(),{base,base+1,base+2,base+2,base+1,base+3});
|
||||
};
|
||||
const float corners[4][2]={{-sx,-sz},{sx,-sz},{sx,sz},{-sx,sz}};
|
||||
for(int side=0;side<4;++side)for(int band=0;band<upper+lower;++band) {
|
||||
float top=band<upper ? 1.f-float(band)/upper : -float(band-upper)/lower;
|
||||
float bottom=band<upper ? 1.f-float(band+1)/upper : -float(band-upper+1)/lower;
|
||||
const auto& left=corners[side];const auto& right=corners[(side+1)%4];
|
||||
quad(left[0],left[1],right[0],right[1],bottom*sy,top*sy,color(band,false),color(band,true));
|
||||
}
|
||||
|
||||
// Build lower rings (horizon -2 deg down to -36 deg)
|
||||
for (int k = 1; k <= NUM_LOWER; ++k) {
|
||||
float t = static_cast<float>(k) / static_cast<float>(NUM_LOWER);
|
||||
float angle_deg = -2.0f - t * 34.0f; // -2 -> -36 deg
|
||||
float phi = angle_deg * DEG2RAD;
|
||||
float y_off = m_radius * std::sin(phi);
|
||||
float rad = m_radius * std::cos(phi);
|
||||
|
||||
float col[4];
|
||||
float grad_t = 0.80f + t * 0.20f;
|
||||
InterpolateGradientColor(m_env.skybox.gradients, grad_t, col);
|
||||
rings.push_back({y_off, rad, ColorToUint(col)});
|
||||
for(int face=0;face<2;++face) {
|
||||
uint32_t base=draw.positions.size()/3;
|
||||
float height=(face ? -1.f : 1.f)*sy;
|
||||
for(const auto& corner:corners)draw.positions.insert(draw.positions.end(),{camEyeX+corner[0],camEyeY+height,camEyeZ+corner[1]});
|
||||
draw.diffuse.insert(draw.diffuse.end(),4,color(face ? upper+lower-1 : 0,face==0));
|
||||
draw.indices.insert(draw.indices.end(),{base,base+1,base+2,base,base+2,base+3});
|
||||
}
|
||||
|
||||
int total_rings = static_cast<int>(rings.size());
|
||||
|
||||
// Top zenith vertex
|
||||
float top_col[4];
|
||||
InterpolateGradientColor(m_env.skybox.gradients, 0.0f, top_col);
|
||||
uint32_t top_vertex_idx = 0;
|
||||
draw.positions.push_back(camEyeX);
|
||||
draw.positions.push_back(camEyeY + m_radius * 0.98f);
|
||||
draw.positions.push_back(camEyeZ);
|
||||
draw.diffuse.push_back(ColorToUint(top_col));
|
||||
draw.normals.push_back(0.0f); draw.normals.push_back(-1.0f); draw.normals.push_back(0.0f);
|
||||
draw.uv0.push_back(0.5f); draw.uv0.push_back(0.0f);
|
||||
|
||||
// Ring vertices
|
||||
std::vector<std::vector<uint32_t>> ring_indices(total_rings, std::vector<uint32_t>(SECTORS + 1));
|
||||
for (int r = 0; r < total_rings; ++r) {
|
||||
for (int s = 0; s <= SECTORS; ++s) {
|
||||
float theta = (2.0f * PI * static_cast<float>(s)) / static_cast<float>(SECTORS);
|
||||
float vx = camEyeX + rings[r].radius * std::cos(theta);
|
||||
float vy = camEyeY + rings[r].y_offset;
|
||||
float vz = camEyeZ + rings[r].radius * std::sin(theta);
|
||||
|
||||
uint32_t idx = static_cast<uint32_t>(draw.positions.size() / 3);
|
||||
ring_indices[r][s] = idx;
|
||||
|
||||
draw.positions.push_back(vx);
|
||||
draw.positions.push_back(vy);
|
||||
draw.positions.push_back(vz);
|
||||
draw.diffuse.push_back(rings[r].color);
|
||||
|
||||
float nx = -std::cos(theta);
|
||||
float ny = -rings[r].y_offset / m_radius;
|
||||
float nz = -std::sin(theta);
|
||||
draw.normals.push_back(nx); draw.normals.push_back(ny); draw.normals.push_back(nz);
|
||||
draw.uv0.push_back(static_cast<float>(s) / static_cast<float>(SECTORS));
|
||||
draw.uv0.push_back(static_cast<float>(r) / static_cast<float>(total_rings));
|
||||
}
|
||||
}
|
||||
|
||||
// Bottom nadir vertex
|
||||
float bot_col[4];
|
||||
InterpolateGradientColor(m_env.skybox.gradients, 1.0f, bot_col);
|
||||
uint32_t bottom_vertex_idx = static_cast<uint32_t>(draw.positions.size() / 3);
|
||||
draw.positions.push_back(camEyeX);
|
||||
draw.positions.push_back(camEyeY - m_radius * 0.65f);
|
||||
draw.positions.push_back(camEyeZ);
|
||||
draw.diffuse.push_back(ColorToUint(bot_col));
|
||||
draw.normals.push_back(0.0f); draw.normals.push_back(1.0f); draw.normals.push_back(0.0f);
|
||||
draw.uv0.push_back(0.5f); draw.uv0.push_back(1.0f);
|
||||
|
||||
// Top fan triangles
|
||||
for (int s = 0; s < SECTORS; ++s) {
|
||||
draw.indices.push_back(top_vertex_idx);
|
||||
draw.indices.push_back(ring_indices[0][s + 1]);
|
||||
draw.indices.push_back(ring_indices[0][s]);
|
||||
}
|
||||
|
||||
// Quads between successive rings
|
||||
for (int r = 0; r < total_rings - 1; ++r) {
|
||||
for (int s = 0; s < SECTORS; ++s) {
|
||||
uint32_t v00 = ring_indices[r][s];
|
||||
uint32_t v01 = ring_indices[r][s + 1];
|
||||
uint32_t v10 = ring_indices[r + 1][s];
|
||||
uint32_t v11 = ring_indices[r + 1][s + 1];
|
||||
|
||||
draw.indices.push_back(v00);
|
||||
draw.indices.push_back(v01);
|
||||
draw.indices.push_back(v10);
|
||||
|
||||
draw.indices.push_back(v01);
|
||||
draw.indices.push_back(v11);
|
||||
draw.indices.push_back(v10);
|
||||
}
|
||||
}
|
||||
|
||||
// Bottom fan triangles
|
||||
for (int s = 0; s < SECTORS; ++s) {
|
||||
draw.indices.push_back(ring_indices[total_rings - 1][s]);
|
||||
draw.indices.push_back(ring_indices[total_rings - 1][s + 1]);
|
||||
draw.indices.push_back(bottom_vertex_idx);
|
||||
}
|
||||
|
||||
return draw;
|
||||
}
|
||||
|
||||
@@ -282,25 +189,24 @@ Render3DDraw SkyBox::BuildCloudPlane(float camEyeX, float camEyeY, float camEyeZ
|
||||
draw.blend_mode = 0; // Alpha blend
|
||||
|
||||
constexpr int GRID = 8;
|
||||
float half_size = m_radius * 0.85f;
|
||||
float cloud_y = camEyeY + 750.0f;
|
||||
float half_x = m_env.skybox.cloud_scale[0];
|
||||
float half_z = m_env.skybox.cloud_scale[1];
|
||||
float cloud_y = camEyeY + m_env.skybox.cloud_height;
|
||||
|
||||
float scale_u = m_env.skybox.cloud_texture_scale[0] > 0.0f ? m_env.skybox.cloud_texture_scale[0] : 4.0f;
|
||||
float scale_v = m_env.skybox.cloud_texture_scale[1] > 0.0f ? m_env.skybox.cloud_texture_scale[1] : 4.0f;
|
||||
|
||||
for (int j = 0; j <= GRID; ++j) {
|
||||
float fz = static_cast<float>(j) / static_cast<float>(GRID);
|
||||
float z = camEyeZ + (fz - 0.5f) * 2.0f * half_size;
|
||||
float z = camEyeZ + (fz - 0.5f) * 2.0f * half_z;
|
||||
for (int i = 0; i <= GRID; ++i) {
|
||||
float fx = static_cast<float>(i) / static_cast<float>(GRID);
|
||||
float x = camEyeX + (fx - 0.5f) * 2.0f * half_size;
|
||||
float x = camEyeX + (fx - 0.5f) * 2.0f * half_x;
|
||||
|
||||
float dx = (fx - 0.5f) * 2.0f;
|
||||
float dz = (fz - 0.5f) * 2.0f;
|
||||
float dist_sq = dx * dx + dz * dz;
|
||||
float alpha = std::clamp(1.0f - dist_sq * 0.70f, 0.0f, 1.0f) * 0.78f;
|
||||
uint32_t a_byte = static_cast<uint32_t>(alpha * 255.0f);
|
||||
uint32_t col = (a_byte << 24) | 0x00FFFFFF;
|
||||
float cloudColor[4];
|
||||
for(int channel=0;channel<4;++channel)
|
||||
cloudColor[channel]=m_env.skybox.cloud_color.first[channel]*(1.f-fz)+m_env.skybox.cloud_color.second[channel]*fz;
|
||||
uint32_t col=ColorToUint(cloudColor);
|
||||
|
||||
draw.positions.push_back(x);
|
||||
draw.positions.push_back(cloud_y);
|
||||
|
||||
+60
-637
@@ -1,665 +1,88 @@
|
||||
#include "src/eter_render/SpeedTreeRT.h"
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "src/eter_resource/ResourceManager.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace ava2 {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr float kPI = 3.14159265358979323846f;
|
||||
constexpr float kTAU = 2.0f * kPI;
|
||||
|
||||
std::string ToLower(std::string s) {
|
||||
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) {
|
||||
return static_cast<char>(std::tolower(c));
|
||||
});
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string BaseName(std::string p) {
|
||||
for (char& c : p) if (c == '\\') c = '/';
|
||||
size_t s = p.find_last_of('/');
|
||||
return (s == std::string::npos) ? p : p.substr(s + 1);
|
||||
}
|
||||
|
||||
std::string StripQuotes(const std::string& s) {
|
||||
size_t start = s.find_first_not_of(" \t\r\n\"");
|
||||
if (start == std::string::npos) return "";
|
||||
size_t end = s.find_last_not_of(" \t\r\n\"");
|
||||
return s.substr(start, end - start + 1);
|
||||
}
|
||||
|
||||
bool EndsWithCI(const std::string& s, const char* suf) {
|
||||
size_t n = std::strlen(suf);
|
||||
if (s.size() < n) return false;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (std::tolower((unsigned char)s[s.size() - n + i]) != std::tolower((unsigned char)suf[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string AsDds(std::string s) {
|
||||
if (s.empty()) return s;
|
||||
size_t dot = s.find_last_of('.');
|
||||
if (dot != std::string::npos) s.resize(dot);
|
||||
return s + ".dds";
|
||||
}
|
||||
|
||||
bool IsConifer(const std::string& name) {
|
||||
std::string s = ToLower(name);
|
||||
return s.find("pine") != std::string::npos || s.find("cypress") != std::string::npos ||
|
||||
s.find("fir") != std::string::npos || s.find("spruce") != std::string::npos ||
|
||||
s.find("cedar") != std::string::npos || s.find("conifer") != std::string::npos ||
|
||||
s.find("tanne") != std::string::npos;
|
||||
}
|
||||
|
||||
bool IsGrassOrShrubSpecies(const std::string& name) {
|
||||
std::string s = ToLower(name);
|
||||
return s.find("grass") != std::string::npos || s.find("flower") != std::string::npos ||
|
||||
s.find("plant") != std::string::npos || s.find("bush") != std::string::npos ||
|
||||
s.find("shrub") != std::string::npos || s.find("tufis") != std::string::npos ||
|
||||
s.find("duester") != std::string::npos;
|
||||
}
|
||||
|
||||
std::string ResolvePath(const std::string& path) {
|
||||
if (path.empty()) return "";
|
||||
std::string clean = path;
|
||||
for (char& c : clean) if (c == '\\') c = '/';
|
||||
if (clean.size() > 2 && clean[1] == ':') {
|
||||
clean = clean.substr(2);
|
||||
while (!clean.empty() && clean[0] == '/') clean = clean.substr(1);
|
||||
}
|
||||
std::vector<std::string> roots = {
|
||||
"",
|
||||
"build/dev/",
|
||||
"../",
|
||||
"ymir work/",
|
||||
"build/dev/ymir work/",
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/",
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/property/",
|
||||
"/Users/shen/Work/Code/Metin2/ava2-client/"
|
||||
};
|
||||
for (const auto& r : roots) {
|
||||
std::string cand = r + clean;
|
||||
std::ifstream f(cand, std::ios::binary);
|
||||
if (f.good()) return cand;
|
||||
}
|
||||
return clean;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool SpeedTreeProperty::LoadFromFile(const std::string& filename, SpeedTreeProperty& out) {
|
||||
std::string resolved = ResolvePath(filename);
|
||||
std::ifstream file(resolved);
|
||||
if (!file.is_open()) return false;
|
||||
|
||||
std::string line;
|
||||
bool has_yprt = false;
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream iss(line);
|
||||
std::string token;
|
||||
if (!(iss >> token)) continue;
|
||||
|
||||
if (token == "YPRT") {
|
||||
has_yprt = true;
|
||||
if (file >> out.crc) {
|
||||
// crc parsed
|
||||
}
|
||||
} else if (token == "propertyname") {
|
||||
std::string rem;
|
||||
std::getline(iss, rem);
|
||||
out.property_name = StripQuotes(rem);
|
||||
} else if (token == "propertytype") {
|
||||
// expected "Tree"
|
||||
} else if (token == "treefile") {
|
||||
std::string rem;
|
||||
std::getline(iss, rem);
|
||||
out.tree_file = StripQuotes(rem);
|
||||
} else if (token == "treesize") {
|
||||
std::string rem;
|
||||
std::getline(iss, rem);
|
||||
try { out.tree_size = std::stof(StripQuotes(rem)); } catch (...) {}
|
||||
} else if (token == "treevariance") {
|
||||
std::string rem;
|
||||
std::getline(iss, rem);
|
||||
try { out.tree_variance = std::stof(StripQuotes(rem)); } catch (...) {}
|
||||
}
|
||||
}
|
||||
return has_yprt && out.crc != 0;
|
||||
}
|
||||
|
||||
bool SpeedTreeSptInfo::SniffMemory(const uint8_t* p, size_t n, SpeedTreeSptInfo& out) {
|
||||
out = SpeedTreeSptInfo{};
|
||||
if (!p || n < 20) return false;
|
||||
|
||||
// Check magic
|
||||
std::string bytes(reinterpret_cast<const char*>(p), n);
|
||||
size_t magic_pos = bytes.find("__IdvSpt_02_");
|
||||
if (magic_pos != std::string::npos) {
|
||||
out.ok = true;
|
||||
}
|
||||
|
||||
auto i32_at = [&](size_t o) -> int32_t {
|
||||
if (o + 4 > n) return 0;
|
||||
int32_t val = 0;
|
||||
std::memcpy(&val, p + o, 4);
|
||||
return val;
|
||||
};
|
||||
|
||||
// Parse tokens if structured
|
||||
for (size_t o = 0; o + 12 <= n; ++o) {
|
||||
int32_t token = i32_at(o);
|
||||
if (token == 2000) {
|
||||
// branch texture name
|
||||
int32_t len = i32_at(o + 4);
|
||||
if (len > 0 && len < 256 && o + 8 + len <= n) {
|
||||
std::string s(reinterpret_cast<const char*>(p + o + 8), len);
|
||||
out.bark_texture = BaseName(s);
|
||||
}
|
||||
} else if (token == 2001) {
|
||||
float sz = 0.0f;
|
||||
std::memcpy(&sz, p + o + 4, 4);
|
||||
if (sz > 1.0f && sz < 50000.0f) out.size = sz;
|
||||
} else if (token == 2002) {
|
||||
float var = 0.0f;
|
||||
std::memcpy(&var, p + o + 4, 4);
|
||||
out.variance = var;
|
||||
} else if (token == 10000 && i32_at(o + 4) == 10002) {
|
||||
// Texture coordinates section: 10002 <count> leaf maps
|
||||
size_t c = o + 4;
|
||||
for (int32_t section : {10002, 10003, 10004}) {
|
||||
if (c + 8 > n || i32_at(c) != section) break;
|
||||
int32_t count = i32_at(c + 4);
|
||||
c += 8;
|
||||
if (count <= 0 || count > 64 || c + count * 32 > n) break;
|
||||
auto& target = (section == 10002) ? out.leaf_uvs : (section == 10003 ? out.frond_uvs : out.billboard_uvs);
|
||||
for (int32_t i = 0; i < count; ++i, c += 32) {
|
||||
float f[8];
|
||||
std::memcpy(f, p + c, sizeof(f));
|
||||
target.push_back({f[2], 1.0f - f[1], f[0], 1.0f - f[5]});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// String scan fallback for bark & composite maps
|
||||
std::string cur;
|
||||
std::vector<std::string> str_refs;
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
unsigned char c = p[i];
|
||||
if (c >= 0x20 && c < 0x7F) {
|
||||
cur += static_cast<char>(c);
|
||||
} else {
|
||||
if (cur.size() >= 4 && (EndsWithCI(cur, ".tga") || EndsWithCI(cur, ".dds"))) {
|
||||
str_refs.push_back(BaseName(cur));
|
||||
}
|
||||
cur.clear();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& r : str_refs) {
|
||||
std::string low = ToLower(r);
|
||||
if (out.bark_texture.empty() && low.find("bark") != std::string::npos) {
|
||||
out.bark_texture = AsDds(r);
|
||||
} else if (out.leaf_texture.empty() && (low.find("leaf") != std::string::npos || low.find("leaves") != std::string::npos || low.find("grass") != std::string::npos)) {
|
||||
out.leaf_texture = AsDds(r);
|
||||
}
|
||||
}
|
||||
|
||||
// Check composite maps
|
||||
auto find_token = [&](const char* needle) -> std::string {
|
||||
size_t pos = bytes.find(needle);
|
||||
if (pos == std::string::npos) return "";
|
||||
size_t end = pos + std::strlen(needle);
|
||||
while (end < bytes.size() && (std::isalnum((unsigned char)bytes[end]) || bytes[end] == '_' || bytes[end] == '-')) {
|
||||
++end;
|
||||
}
|
||||
return bytes.substr(pos, end - pos);
|
||||
};
|
||||
|
||||
std::string comp = find_token("CompositeMap");
|
||||
if (!comp.empty()) out.leaf_texture = AsDds(comp);
|
||||
std::string shadow = find_token("CompositeShadowMap");
|
||||
if (!shadow.empty()) out.shadow_texture = AsDds(shadow);
|
||||
|
||||
if (out.leaf_texture.empty() && !str_refs.empty()) {
|
||||
out.leaf_texture = AsDds(str_refs.front());
|
||||
}
|
||||
|
||||
return out.ok || !out.bark_texture.empty() || !out.leaf_texture.empty();
|
||||
}
|
||||
|
||||
bool SpeedTreeSptInfo::SniffSpt(const std::string& filepath, SpeedTreeSptInfo& out) {
|
||||
std::string resolved = ResolvePath(filepath);
|
||||
std::ifstream file(resolved, std::ios::binary);
|
||||
if (!file.is_open()) return false;
|
||||
std::vector<uint8_t> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
return SniffMemory(buffer.data(), buffer.size(), out);
|
||||
}
|
||||
|
||||
SpeedTreeModel::SpeedTreeModel() {}
|
||||
|
||||
std::shared_ptr<SpeedTreeModel> SpeedTreeModel::Create(const std::string& sptPath, float treeSize) {
|
||||
auto model = std::make_shared<SpeedTreeModel>();
|
||||
model->m_spt_path = sptPath;
|
||||
model->m_name = BaseName(sptPath);
|
||||
model->m_height = treeSize > 1.0f ? treeSize : 1000.0f;
|
||||
model->m_radius = model->m_height * 0.35f;
|
||||
model->m_is_grass_or_shrub = IsGrassOrShrubSpecies(model->m_name);
|
||||
|
||||
SpeedTreeSptInfo info;
|
||||
SpeedTreeSptInfo::SniffSpt(sptPath, info);
|
||||
if (info.size > 1.0f && treeSize <= 0.0f) {
|
||||
model->m_height = info.size;
|
||||
model->m_radius = model->m_height * 0.35f;
|
||||
std::string resolved = CResourceManager::NormalizePath(sptPath.c_str());
|
||||
for (const auto& candidate : CResourceManager::GetCandidatePaths(resolved)) {
|
||||
if (std::filesystem::is_regular_file(candidate)) { resolved = candidate; break; }
|
||||
}
|
||||
|
||||
model->BuildGeometry(info);
|
||||
auto impl = speedtree::SpeedTreeModel::CreateFromSpt(resolved, treeSize);
|
||||
if (!impl) return nullptr;
|
||||
auto model = std::make_shared<SpeedTreeModel>(std::move(impl));
|
||||
model->m_textureDirectory = std::filesystem::path(resolved).parent_path().string();
|
||||
return model;
|
||||
}
|
||||
|
||||
std::shared_ptr<SpeedTreeModel> SpeedTreeModel::CreateProcedural(const std::string& name, float treeSize,
|
||||
const std::string& barkTex,
|
||||
const std::string& leafTex) {
|
||||
auto model = std::make_shared<SpeedTreeModel>();
|
||||
model->m_name = name;
|
||||
model->m_height = treeSize > 1.0f ? treeSize : 1000.0f;
|
||||
model->m_radius = model->m_height * 0.35f;
|
||||
model->m_is_grass_or_shrub = IsGrassOrShrubSpecies(name);
|
||||
|
||||
SpeedTreeSptInfo info;
|
||||
info.ok = true;
|
||||
info.bark_texture = barkTex;
|
||||
info.leaf_texture = leafTex;
|
||||
info.size = treeSize;
|
||||
|
||||
model->BuildGeometry(info);
|
||||
return model;
|
||||
}
|
||||
|
||||
static bool TextureFileExists(const std::string& p) {
|
||||
if (p.empty()) return false;
|
||||
std::string s = p;
|
||||
for (char& c : s) if (c == '\\') c = '/';
|
||||
if (std::filesystem::exists(s)) return true;
|
||||
if (std::filesystem::exists("build/dev/" + s)) return true;
|
||||
std::string lower = s;
|
||||
for (char& c : lower) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||
if (std::filesystem::exists(lower)) return true;
|
||||
if (std::filesystem::exists("build/dev/" + lower)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static std::string ResolveExistingTexture(const std::string& candidate,
|
||||
const std::string& dir,
|
||||
const std::string& modelName,
|
||||
bool isGrass,
|
||||
bool isBark) {
|
||||
std::string lowerName = modelName;
|
||||
for (char& c : lowerName) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||
|
||||
// Specific species exact mappings for Metin2 authentic assets
|
||||
if (lowerName.find("scotchpine") != std::string::npos || lowerName.find("pine") != std::string::npos) {
|
||||
if (isBark && TextureFileExists("ymir work/palnts_2/all/ot/treescotchpinebark.dds"))
|
||||
return "ymir work/palnts_2/all/ot/treescotchpinebark.dds";
|
||||
if (!isBark && TextureFileExists("ymir work/palnts_2/all/ot/treescotchpineleaves.dds"))
|
||||
return "ymir work/palnts_2/all/ot/treescotchpineleaves.dds";
|
||||
}
|
||||
if (lowerName.find("willowoak") != std::string::npos || lowerName.find("oak") != std::string::npos) {
|
||||
if (isBark && TextureFileExists("ymir work/palnts_2/all/ot/treewillowoakbarkmoss.dds"))
|
||||
return "ymir work/palnts_2/all/ot/treewillowoakbarkmoss.dds";
|
||||
if (!isBark && TextureFileExists("ymir work/palnts_2/all/ot/treewillowoakleavessu.dds"))
|
||||
return "ymir work/palnts_2/all/ot/treewillowoakleavessu.dds";
|
||||
}
|
||||
if (lowerName.find("beech") != std::string::npos) {
|
||||
if (isBark && TextureFileExists("ymir work/zone/b/tree/1/beechbark.dds"))
|
||||
return "ymir work/zone/b/tree/1/beechbark.dds";
|
||||
if (!isBark && TextureFileExists("ymir work/zone/b/tree/1/compositemap.dds"))
|
||||
return "ymir work/zone/b/tree/1/compositemap.dds";
|
||||
}
|
||||
|
||||
if (!candidate.empty()) {
|
||||
std::string p1 = candidate;
|
||||
std::string p2 = dir + candidate;
|
||||
if (TextureFileExists(p1)) return p1;
|
||||
if (TextureFileExists(p2)) return p2;
|
||||
}
|
||||
|
||||
if (isGrass) {
|
||||
if (!isBark) {
|
||||
std::vector<std::string> grass_cands = {
|
||||
dir + "plant_grass.dds",
|
||||
dir + "compositemapn2.dds",
|
||||
dir + "plant_grass_bush1.dds",
|
||||
"ymir work/plants/plant_grass.dds",
|
||||
"ymir work/plants/compositemapn2.dds",
|
||||
"ymir work/plants/plant_grass_bush1.dds",
|
||||
"ymir work/palnts_2/all/os/shrubgenericelderberryleavessu.dds",
|
||||
"ymir work/zone/b/tree/1/compositemap.dds"
|
||||
};
|
||||
for (const auto& g : grass_cands) if (TextureFileExists(g)) return g;
|
||||
} else {
|
||||
std::vector<std::string> bark_cands = {
|
||||
dir + "aloeverabark.dds",
|
||||
"ymir work/plants/aloeverabark.dds",
|
||||
"ymir work/zone/b/tree/1/beechbark.dds"
|
||||
};
|
||||
for (const auto& b : bark_cands) if (TextureFileExists(b)) return b;
|
||||
}
|
||||
} else {
|
||||
if (isBark) {
|
||||
std::vector<std::string> bark_cands = {
|
||||
dir + "beechbark.dds",
|
||||
dir + "treewillowoakbarkmoss.dds",
|
||||
dir + "treescotchpinebark.dds",
|
||||
"ymir work/zone/b/tree/1/beechbark.dds",
|
||||
"ymir work/palnts_2/all/ot/treewillowoakbarkmoss.dds",
|
||||
"ymir work/palnts_2/all/ot/treescotchpinebark.dds",
|
||||
"ymir work/zone/b/tree/c/englishoakbark.dds"
|
||||
};
|
||||
for (const auto& b : bark_cands) if (TextureFileExists(b)) return b;
|
||||
} else {
|
||||
std::vector<std::string> leaf_cands = {
|
||||
dir + "compositemap.dds",
|
||||
dir + "treewillowoakleavessu.dds",
|
||||
dir + "treescotchpineleaves.dds",
|
||||
"ymir work/zone/b/tree/1/compositemap.dds",
|
||||
"ymir work/zone/b/tree/c/compositemap.dds",
|
||||
"ymir work/palnts_2/all/ot/treewillowoakleavessu.dds",
|
||||
"ymir work/palnts_2/all/ot/treescotchpineleaves.dds"
|
||||
};
|
||||
for (const auto& l : leaf_cands) if (TextureFileExists(l)) return l;
|
||||
}
|
||||
}
|
||||
return isBark ? "ymir work/zone/b/tree/1/beechbark.dds" : "ymir work/zone/b/tree/1/compositemap.dds";
|
||||
}
|
||||
|
||||
void SpeedTreeModel::BuildGeometry(const SpeedTreeSptInfo& info) {
|
||||
// Resolve textures with directory prefixes if known
|
||||
std::string dir = "";
|
||||
size_t last_slash = m_spt_path.find_last_of("/\\");
|
||||
if (last_slash != std::string::npos) {
|
||||
dir = m_spt_path.substr(0, last_slash + 1);
|
||||
}
|
||||
|
||||
m_bark_texture = ResolveExistingTexture(info.bark_texture, dir, m_name, m_is_grass_or_shrub, true);
|
||||
m_leaf_texture = ResolveExistingTexture(info.leaf_texture, dir, m_name, m_is_grass_or_shrub, false);
|
||||
|
||||
if (m_is_grass_or_shrub) {
|
||||
BuildGrassShrubGeometry(m_height, info);
|
||||
} else {
|
||||
BuildTreeGeometry(m_height, info);
|
||||
}
|
||||
}
|
||||
|
||||
void SpeedTreeModel::BuildGrassShrubGeometry(float H, const SpeedTreeSptInfo& info) {
|
||||
// 3 intersecting vertical quads (Star pattern at 0, 60, 120 degrees)
|
||||
m_leaf_template.positions.clear();
|
||||
m_leaf_template.normals.clear();
|
||||
m_leaf_template.uv0.clear();
|
||||
m_leaf_template.diffuse.clear();
|
||||
m_leaf_template.indices.clear();
|
||||
|
||||
m_leaf_template.texture0 = m_leaf_texture;
|
||||
m_leaf_template.alpha_test = true;
|
||||
m_leaf_template.alpha_ref = 70;
|
||||
m_leaf_template.cull_mode = 1; // Double-sided
|
||||
m_leaf_template.lighting = true;
|
||||
m_leaf_template.z_enable = true;
|
||||
m_leaf_template.z_write = true;
|
||||
|
||||
float W = H * 0.85f;
|
||||
float hW = W * 0.5f;
|
||||
|
||||
float angles[] = {0.0f, kPI / 3.0f, 2.0f * kPI / 3.0f};
|
||||
for (int p = 0; p < 3; ++p) {
|
||||
float a = angles[p];
|
||||
float dx = std::cos(a) * hW;
|
||||
float dz = std::sin(a) * hW;
|
||||
float nx = -std::sin(a);
|
||||
float nz = std::cos(a);
|
||||
|
||||
uint32_t base_idx = static_cast<uint32_t>(m_leaf_template.positions.size() / 3);
|
||||
|
||||
// 4 corners of vertical plane
|
||||
// Bottom-left, Bottom-right, Top-right, Top-left
|
||||
float corners[4][3] = {
|
||||
{-dx, 0.0f, -dz},
|
||||
{ dx, 0.0f, dz},
|
||||
{ dx, H, dz},
|
||||
{-dx, H, -dz}
|
||||
};
|
||||
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
m_leaf_template.positions.push_back(corners[c][0]);
|
||||
m_leaf_template.positions.push_back(corners[c][1]);
|
||||
m_leaf_template.positions.push_back(corners[c][2]);
|
||||
|
||||
m_leaf_template.normals.push_back(nx);
|
||||
m_leaf_template.normals.push_back(0.3f);
|
||||
m_leaf_template.normals.push_back(nz);
|
||||
|
||||
m_leaf_template.diffuse.push_back(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
m_leaf_template.uv0.push_back(0.0f); m_leaf_template.uv0.push_back(1.0f);
|
||||
m_leaf_template.uv0.push_back(1.0f); m_leaf_template.uv0.push_back(1.0f);
|
||||
m_leaf_template.uv0.push_back(1.0f); m_leaf_template.uv0.push_back(0.0f);
|
||||
m_leaf_template.uv0.push_back(0.0f); m_leaf_template.uv0.push_back(0.0f);
|
||||
|
||||
m_leaf_template.indices.push_back(base_idx + 0);
|
||||
m_leaf_template.indices.push_back(base_idx + 1);
|
||||
m_leaf_template.indices.push_back(base_idx + 2);
|
||||
m_leaf_template.indices.push_back(base_idx + 0);
|
||||
m_leaf_template.indices.push_back(base_idx + 2);
|
||||
m_leaf_template.indices.push_back(base_idx + 3);
|
||||
}
|
||||
}
|
||||
|
||||
void SpeedTreeModel::BuildTreeGeometry(float H, const SpeedTreeSptInfo& info) {
|
||||
bool conifer = IsConifer(m_name);
|
||||
|
||||
// 1. Build Trunk Cylindrical Tube
|
||||
m_trunk_template.positions.clear();
|
||||
m_trunk_template.normals.clear();
|
||||
m_trunk_template.uv0.clear();
|
||||
m_trunk_template.diffuse.clear();
|
||||
m_trunk_template.indices.clear();
|
||||
|
||||
m_trunk_template.texture0 = m_bark_texture;
|
||||
m_trunk_template.alpha_test = false;
|
||||
m_trunk_template.cull_mode = 2; // Backface cull
|
||||
m_trunk_template.lighting = true;
|
||||
m_trunk_template.z_enable = true;
|
||||
m_trunk_template.z_write = true;
|
||||
|
||||
constexpr int SEGS = 8;
|
||||
constexpr int LEVELS = 4;
|
||||
float trunk_top = H * (conifer ? 0.90f : 0.72f);
|
||||
float r_base = H * 0.038f;
|
||||
float r_top = H * 0.012f;
|
||||
|
||||
for (int l = 0; l <= LEVELS; ++l) {
|
||||
float f = static_cast<float>(l) / LEVELS;
|
||||
float y = f * trunk_top;
|
||||
float r = r_base * (1.0f - f) + r_top * f;
|
||||
float v = f * 3.0f; // Tile bark vertically
|
||||
|
||||
for (int s = 0; s <= SEGS; ++s) {
|
||||
float a = static_cast<float>(s) / SEGS * kTAU;
|
||||
float cos_a = std::cos(a);
|
||||
float sin_a = std::sin(a);
|
||||
|
||||
m_trunk_template.positions.push_back(cos_a * r);
|
||||
m_trunk_template.positions.push_back(y);
|
||||
m_trunk_template.positions.push_back(sin_a * r);
|
||||
|
||||
m_trunk_template.normals.push_back(cos_a);
|
||||
m_trunk_template.normals.push_back(0.0f);
|
||||
m_trunk_template.normals.push_back(sin_a);
|
||||
|
||||
m_trunk_template.uv0.push_back(static_cast<float>(s) / SEGS);
|
||||
m_trunk_template.uv0.push_back(v);
|
||||
|
||||
m_trunk_template.diffuse.push_back(0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
int stride = SEGS + 1;
|
||||
for (int l = 0; l < LEVELS; ++l) {
|
||||
for (int s = 0; s < SEGS; ++s) {
|
||||
uint32_t i0 = l * stride + s;
|
||||
uint32_t i1 = l * stride + (s + 1);
|
||||
uint32_t i2 = (l + 1) * stride + s;
|
||||
uint32_t i3 = (l + 1) * stride + (s + 1);
|
||||
|
||||
m_trunk_template.indices.push_back(i0);
|
||||
m_trunk_template.indices.push_back(i2);
|
||||
m_trunk_template.indices.push_back(i1);
|
||||
|
||||
m_trunk_template.indices.push_back(i1);
|
||||
m_trunk_template.indices.push_back(i2);
|
||||
m_trunk_template.indices.push_back(i3);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Build Foliage Canopy Clusters (Multiple Cross Quads)
|
||||
m_leaf_template.positions.clear();
|
||||
m_leaf_template.normals.clear();
|
||||
m_leaf_template.uv0.clear();
|
||||
m_leaf_template.diffuse.clear();
|
||||
m_leaf_template.indices.clear();
|
||||
|
||||
m_leaf_template.texture0 = m_leaf_texture;
|
||||
m_leaf_template.alpha_test = true;
|
||||
m_leaf_template.alpha_ref = 84;
|
||||
m_leaf_template.cull_mode = 1; // Double sided
|
||||
m_leaf_template.lighting = true;
|
||||
m_leaf_template.z_enable = true;
|
||||
m_leaf_template.z_write = true;
|
||||
|
||||
UVRect default_uv{0.0f, 0.0f, 1.0f, 1.0f};
|
||||
const auto& uv_pool = info.leaf_uvs.empty() ? (info.frond_uvs.empty() ? std::vector<UVRect>{default_uv} : info.frond_uvs) : info.leaf_uvs;
|
||||
|
||||
int cluster_count = conifer ? 14 : 12;
|
||||
for (int k = 0; k < cluster_count; ++k) {
|
||||
float f = static_cast<float>(k) / cluster_count;
|
||||
float y = H * (conifer ? (0.28f + f * 0.65f) : (0.42f + f * 0.48f));
|
||||
float spread = H * (conifer ? (0.24f * (1.0f - f * 0.70f)) : (0.28f * std::sin(f * kPI)));
|
||||
float angle = f * kTAU * 1.618f;
|
||||
|
||||
float cx = (k == cluster_count - 1) ? 0.0f : (std::cos(angle) * spread);
|
||||
float cz = (k == cluster_count - 1) ? 0.0f : (std::sin(angle) * spread);
|
||||
|
||||
float quad_w = H * (conifer ? 0.28f : 0.38f);
|
||||
float quad_h = H * (conifer ? 0.24f : 0.32f);
|
||||
float hw = quad_w * 0.5f;
|
||||
float hh = quad_h * 0.5f;
|
||||
|
||||
UVRect uv = uv_pool[k % uv_pool.size()];
|
||||
|
||||
// 2 perpendicular planes per cluster (0 and 90 deg)
|
||||
for (int p = 0; p < 2; ++p) {
|
||||
float pa = angle + p * (kPI * 0.5f);
|
||||
float dx = std::cos(pa) * hw;
|
||||
float dz = std::sin(pa) * hw;
|
||||
|
||||
uint32_t bidx = static_cast<uint32_t>(m_leaf_template.positions.size() / 3);
|
||||
|
||||
float pts[4][3] = {
|
||||
{cx - dx, y - hh, cz - dz},
|
||||
{cx + dx, y - hh, cz + dz},
|
||||
{cx + dx, y + hh, cz + dz},
|
||||
{cx - dx, y + hh, cz - dz}
|
||||
};
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
m_leaf_template.positions.push_back(pts[i][0]);
|
||||
m_leaf_template.positions.push_back(pts[i][1]);
|
||||
m_leaf_template.positions.push_back(pts[i][2]);
|
||||
|
||||
m_leaf_template.normals.push_back(std::cos(pa + kPI * 0.5f));
|
||||
m_leaf_template.normals.push_back(0.4f);
|
||||
m_leaf_template.normals.push_back(std::sin(pa + kPI * 0.5f));
|
||||
|
||||
m_leaf_template.diffuse.push_back(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
m_leaf_template.uv0.push_back(uv.u0); m_leaf_template.uv0.push_back(uv.v1);
|
||||
m_leaf_template.uv0.push_back(uv.u1); m_leaf_template.uv0.push_back(uv.v1);
|
||||
m_leaf_template.uv0.push_back(uv.u1); m_leaf_template.uv0.push_back(uv.v0);
|
||||
m_leaf_template.uv0.push_back(uv.u0); m_leaf_template.uv0.push_back(uv.v0);
|
||||
|
||||
m_leaf_template.indices.push_back(bidx + 0);
|
||||
m_leaf_template.indices.push_back(bidx + 1);
|
||||
m_leaf_template.indices.push_back(bidx + 2);
|
||||
m_leaf_template.indices.push_back(bidx + 0);
|
||||
m_leaf_template.indices.push_back(bidx + 2);
|
||||
m_leaf_template.indices.push_back(bidx + 3);
|
||||
}
|
||||
}
|
||||
auto impl = speedtree::SpeedTreeModel::CreateProcedural(name, treeSize, barkTex, leafTex);
|
||||
if (!impl) return nullptr;
|
||||
return std::make_shared<SpeedTreeModel>(std::move(impl));
|
||||
}
|
||||
|
||||
std::vector<Render3DDraw> SpeedTreeModel::BuildDrawCommands(float worldX, float worldY, float worldZ,
|
||||
float yawDeg, float scale,
|
||||
float windTime, float windStrength) const {
|
||||
std::vector<Render3DDraw> results;
|
||||
float rad = yawDeg * (kPI / 180.0f);
|
||||
float cos_y = std::cos(rad);
|
||||
float sin_y = std::sin(rad);
|
||||
if (!m_impl) return results;
|
||||
|
||||
auto transform_mesh = [&](const Render3DDraw& tmpl, bool is_canopy) -> Render3DDraw {
|
||||
Render3DDraw out = tmpl;
|
||||
size_t nverts = tmpl.positions.size() / 3;
|
||||
out.positions.resize(tmpl.positions.size());
|
||||
out.normals.resize(tmpl.normals.size());
|
||||
speedtree::WindParameters wind;
|
||||
wind.time = windTime;
|
||||
wind.strength = windStrength * 0.05f;
|
||||
|
||||
float inv_H = 1.0f / (m_height * scale);
|
||||
auto build_draw = [&](const speedtree::SpeedTreeMesh& mesh, bool is_canopy) {
|
||||
if (mesh.vertices.empty() || mesh.indices.empty()) return;
|
||||
|
||||
for (size_t i = 0; i < nverts; ++i) {
|
||||
float lx = tmpl.positions[i * 3 + 0] * scale;
|
||||
float ly = tmpl.positions[i * 3 + 1] * scale;
|
||||
float lz = tmpl.positions[i * 3 + 2] * scale;
|
||||
|
||||
// Rotate around Y
|
||||
float rx = lx * cos_y + lz * sin_y;
|
||||
float ry = ly;
|
||||
float rz = -lx * sin_y + lz * cos_y;
|
||||
|
||||
// Wind Sway displacement proportional to height squared
|
||||
float h_factor = std::clamp(ry * inv_H, 0.0f, 1.2f);
|
||||
float flex = is_canopy ? (h_factor * h_factor) : (h_factor * h_factor * 0.4f);
|
||||
|
||||
float sway_x = std::sin(windTime * 2.2f + worldX * 0.008f + worldZ * 0.008f) * windStrength * flex;
|
||||
float sway_z = std::cos(windTime * 1.8f + worldX * 0.012f) * windStrength * flex * 0.6f;
|
||||
|
||||
out.positions[i * 3 + 0] = worldX + rx + sway_x;
|
||||
out.positions[i * 3 + 1] = worldY + ry;
|
||||
out.positions[i * 3 + 2] = worldZ + rz + sway_z;
|
||||
|
||||
// Rotate normal
|
||||
float nx = tmpl.normals[i * 3 + 0];
|
||||
float ny = tmpl.normals[i * 3 + 1];
|
||||
float nz = tmpl.normals[i * 3 + 2];
|
||||
out.normals[i * 3 + 0] = nx * cos_y + nz * sin_y;
|
||||
out.normals[i * 3 + 1] = ny;
|
||||
out.normals[i * 3 + 2] = -nx * sin_y + nz * cos_y;
|
||||
Render3DDraw draw;
|
||||
draw.texture0 = mesh.texture;
|
||||
if (!m_textureDirectory.empty() && !mesh.texture.empty()) {
|
||||
// SPT materials often contain only a filename, relative to the tree file.
|
||||
auto name = CResourceManager::NormalizePath(mesh.texture.c_str());
|
||||
auto candidate = std::filesystem::path(m_textureDirectory) / std::filesystem::path(name).filename();
|
||||
if (std::filesystem::is_regular_file(candidate)) draw.texture0 = candidate.string();
|
||||
}
|
||||
return out;
|
||||
draw.indices = mesh.indices;
|
||||
|
||||
m_impl->EvaluateCpuTransformedVertices(mesh, draw.positions, draw.normals,
|
||||
worldX, worldY, worldZ,
|
||||
yawDeg, scale, wind);
|
||||
|
||||
size_t nverts = mesh.vertices.size();
|
||||
draw.uv0.resize(nverts * 2);
|
||||
draw.diffuse.resize(nverts);
|
||||
for (size_t i = 0; i < nverts; ++i) {
|
||||
draw.uv0[i * 2 + 0] = mesh.vertices[i].uv[0];
|
||||
draw.uv0[i * 2 + 1] = mesh.vertices[i].uv[1];
|
||||
draw.diffuse[i] = mesh.vertices[i].diffuse;
|
||||
}
|
||||
|
||||
if (is_canopy) {
|
||||
draw.alpha_test = true;
|
||||
draw.alpha_ref = 84;
|
||||
draw.cull_mode = 1; // Double sided
|
||||
draw.lighting = true;
|
||||
} else {
|
||||
draw.alpha_test = false;
|
||||
draw.alpha_ref = 0;
|
||||
draw.cull_mode = 2; // CW
|
||||
draw.lighting = true;
|
||||
}
|
||||
|
||||
results.push_back(std::move(draw));
|
||||
};
|
||||
|
||||
if (!m_trunk_template.positions.empty()) {
|
||||
results.push_back(transform_mesh(m_trunk_template, false));
|
||||
const auto& trunk = m_impl->GetTrunkMesh();
|
||||
if (!trunk.vertices.empty()) {
|
||||
build_draw(trunk, false);
|
||||
}
|
||||
if (!m_leaf_template.positions.empty()) {
|
||||
results.push_back(transform_mesh(m_leaf_template, true));
|
||||
|
||||
const auto& leaf = m_impl->GetLeafMesh();
|
||||
if (!leaf.vertices.empty()) {
|
||||
build_draw(leaf, true);
|
||||
}
|
||||
|
||||
return results;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/eter_render/Gr2ModelRenderer.h"
|
||||
#include <speedtree/speedtree.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -8,38 +9,15 @@
|
||||
|
||||
namespace ava2 {
|
||||
|
||||
struct UVRect {
|
||||
float u0 = 0.0f, v0 = 0.0f, u1 = 1.0f, v1 = 1.0f;
|
||||
};
|
||||
|
||||
struct SpeedTreeProperty {
|
||||
uint32_t crc = 0;
|
||||
std::string property_name;
|
||||
std::string tree_file;
|
||||
float tree_size = 1000.0f;
|
||||
float tree_variance = 0.0f;
|
||||
|
||||
static bool LoadFromFile(const std::string& filename, SpeedTreeProperty& out);
|
||||
};
|
||||
|
||||
struct SpeedTreeSptInfo {
|
||||
bool ok = false;
|
||||
float size = 1000.0f;
|
||||
float variance = 0.0f;
|
||||
std::string bark_texture;
|
||||
std::string leaf_texture;
|
||||
std::string shadow_texture;
|
||||
std::vector<UVRect> leaf_uvs;
|
||||
std::vector<UVRect> frond_uvs;
|
||||
std::vector<UVRect> billboard_uvs;
|
||||
|
||||
static bool SniffSpt(const std::string& filepath, SpeedTreeSptInfo& out);
|
||||
static bool SniffMemory(const uint8_t* data, size_t size, SpeedTreeSptInfo& out);
|
||||
};
|
||||
using UVRect = speedtree::UVRect;
|
||||
using SpeedTreeProperty = speedtree::SpeedTreeProperty;
|
||||
using SpeedTreeSptInfo = speedtree::SpeedTreeSptInfo;
|
||||
|
||||
class SpeedTreeModel {
|
||||
public:
|
||||
SpeedTreeModel();
|
||||
SpeedTreeModel() = default;
|
||||
explicit SpeedTreeModel(std::shared_ptr<speedtree::SpeedTreeModel> impl)
|
||||
: m_impl(std::move(impl)) {}
|
||||
~SpeedTreeModel() = default;
|
||||
|
||||
static std::shared_ptr<SpeedTreeModel> Create(const std::string& sptPath, float treeSize = 1000.0f);
|
||||
@@ -51,30 +29,19 @@ public:
|
||||
float yawDeg, float scale,
|
||||
float windTime, float windStrength = 15.0f) const;
|
||||
|
||||
float GetHeight() const { return m_height; }
|
||||
float GetRadius() const { return m_radius; }
|
||||
bool IsGrassOrShrub() const { return m_is_grass_or_shrub; }
|
||||
const std::string& GetName() const { return m_name; }
|
||||
const std::string& GetBarkTexture() const { return m_bark_texture; }
|
||||
const std::string& GetLeafTexture() const { return m_leaf_texture; }
|
||||
float GetHeight() const { return m_impl ? m_impl->GetHeight() : 1000.0f; }
|
||||
float GetRadius() const { return m_impl ? m_impl->GetRadius() : 350.0f; }
|
||||
bool IsGrassOrShrub() const { return m_impl ? m_impl->IsGrassOrShrub() : false; }
|
||||
const std::string& GetName() const { static const std::string empty; return m_impl ? m_impl->GetName() : empty; }
|
||||
const std::string& GetBarkTexture() const { static const std::string empty; return m_impl ? m_impl->GetBarkTexture() : empty; }
|
||||
const std::string& GetLeafTexture() const { static const std::string empty; return m_impl ? m_impl->GetLeafTexture() : empty; }
|
||||
const speedtree::SpeedTreeSptInfo& GetSptInfo() const { static const speedtree::SpeedTreeSptInfo empty; return m_impl ? m_impl->GetSptInfo() : empty; }
|
||||
|
||||
std::shared_ptr<speedtree::SpeedTreeModel> GetImpl() const { return m_impl; }
|
||||
|
||||
private:
|
||||
void BuildGeometry(const SpeedTreeSptInfo& info);
|
||||
void BuildTreeGeometry(float H, const SpeedTreeSptInfo& info);
|
||||
void BuildGrassShrubGeometry(float H, const SpeedTreeSptInfo& info);
|
||||
|
||||
std::string m_name;
|
||||
std::string m_spt_path;
|
||||
float m_height = 1000.0f;
|
||||
float m_radius = 350.0f;
|
||||
bool m_is_grass_or_shrub = false;
|
||||
|
||||
std::string m_bark_texture;
|
||||
std::string m_leaf_texture;
|
||||
|
||||
// Base mesh templates in model local space (Z-forward / Y-up)
|
||||
Render3DDraw m_trunk_template;
|
||||
Render3DDraw m_leaf_template;
|
||||
std::shared_ptr<speedtree::SpeedTreeModel> m_impl;
|
||||
std::string m_textureDirectory;
|
||||
};
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
namespace ava2 {
|
||||
|
||||
@@ -101,6 +102,7 @@ bool TerrainHeightmap::LoadRaw(const std::string& raw_path, float height_scale,
|
||||
}
|
||||
|
||||
bool TerrainHeightmap::LoadFromBuffer(const uint16_t* raw_data, size_t count, float height_scale, float cell_scale) {
|
||||
m_patchDrawCache.clear();
|
||||
if (!raw_data || count < static_cast<size_t>(RAW_XSIZE * RAW_YSIZE)) {
|
||||
return false;
|
||||
}
|
||||
@@ -153,6 +155,7 @@ bool TerrainHeightmap::LoadTileRaw(const std::string& tile_path) {
|
||||
}
|
||||
|
||||
bool TerrainHeightmap::LoadTileFromBuffer(const uint8_t* tile_data, size_t count) {
|
||||
m_patchDrawCache.clear();
|
||||
if (!tile_data || count < static_cast<size_t>(TILEMAP_RAW_XSIZE * TILEMAP_RAW_YSIZE)) {
|
||||
return false;
|
||||
}
|
||||
@@ -228,6 +231,7 @@ bool TerrainHeightmap::LoadTextureSet(const std::string& textureset_path) {
|
||||
}
|
||||
|
||||
bool TerrainHeightmap::LoadTextureSetFromString(const std::string& content) {
|
||||
m_patchDrawCache.clear();
|
||||
std::istringstream file(content);
|
||||
std::string line;
|
||||
int current_id = 0;
|
||||
@@ -272,6 +276,7 @@ bool TerrainHeightmap::LoadTextureSetFromString(const std::string& content) {
|
||||
}
|
||||
|
||||
void TerrainHeightmap::GenerateProcedural(int width, int height, float cell_scale, float hill_amplitude) {
|
||||
m_patchDrawCache.clear();
|
||||
m_width = std::max(width, 16);
|
||||
m_height = std::max(height, 16);
|
||||
m_cell_scale = cell_scale;
|
||||
@@ -313,6 +318,7 @@ void TerrainHeightmap::UpdateBounds() {
|
||||
}
|
||||
|
||||
void TerrainHeightmap::SetWorldOrigin(float min_x, float min_z) {
|
||||
m_patchDrawCache.clear();
|
||||
m_has_origin = true;
|
||||
m_origin_x = min_x;
|
||||
m_origin_z = min_z;
|
||||
@@ -418,8 +424,9 @@ uint8_t TerrainHeightmap::GetTileAtGrid(int x, int y) const {
|
||||
|
||||
uint8_t TerrainHeightmap::GetTileAtWorld(float world_x, float world_z) const {
|
||||
if (m_tiles.empty() || m_tile_width <= 0 || m_tile_height <= 0) return 0;
|
||||
float grid_x = (world_x - m_world_min_x) / (static_cast<float>(m_width - 1) * m_cell_scale) * static_cast<float>(m_tile_width - 1);
|
||||
float grid_z = (world_z - m_world_min_z) / (static_cast<float>(m_height - 1) * m_cell_scale) * static_cast<float>(m_tile_height - 1);
|
||||
// AVA2 height.raw has a one-height-sample border; tile.raw has a one-tile border.
|
||||
float grid_x = (world_x - m_world_min_x) / (m_cell_scale * 0.5f) - 1.0f;
|
||||
float grid_z = (world_z - m_world_min_z) / (m_cell_scale * 0.5f) - 1.0f;
|
||||
int tx = std::clamp(static_cast<int>(std::round(grid_x)), 0, m_tile_width - 1);
|
||||
int tz = std::clamp(static_cast<int>(std::round(grid_z)), 0, m_tile_height - 1);
|
||||
return m_tiles[tz * m_tile_width + tx];
|
||||
@@ -620,10 +627,14 @@ std::vector<Render3DDraw> TerrainHeightmap::BuildCulledDraws(const float view[16
|
||||
float dist = std::sqrt(dx * dx + dz * dz);
|
||||
int step = (dist > 2200.0f) ? 2 : 1;
|
||||
|
||||
auto d = BuildPatchDraw(patch.patch_x, patch.patch_y, step);
|
||||
if (!d.positions.empty()) {
|
||||
draws.push_back(std::move(d));
|
||||
const auto key = std::tuple{patch.patch_x, patch.patch_y, step};
|
||||
auto it = m_patchDrawCache.find(key);
|
||||
if (it == m_patchDrawCache.end()) {
|
||||
auto patchDraws = BuildPatchDraws(patch.patch_x, patch.patch_y, step);
|
||||
for (auto& draw : patchDraws) draw = Render3DDraw::ShareGeometry(std::move(draw));
|
||||
it = m_patchDrawCache.emplace(key, std::move(patchDraws)).first;
|
||||
}
|
||||
draws.insert(draws.end(), it->second.begin(), it->second.end());
|
||||
}
|
||||
|
||||
return draws;
|
||||
@@ -639,6 +650,7 @@ Render3DDraw TerrainHeightmap::BuildPatchDraw(int patch_x, int patch_y, int step
|
||||
dom_tile = m_patches[p_idx].dominant_tile;
|
||||
}
|
||||
draw.texture0 = GetTexturePathForTile(dom_tile);
|
||||
draw.terrain = true;
|
||||
draw.cull_mode = 1; // D3DCULL_NONE: double-sided for terrain meshes
|
||||
|
||||
step = std::max(1, step);
|
||||
@@ -708,6 +720,44 @@ Render3DDraw TerrainHeightmap::BuildPatchDraw(int patch_x, int patch_y, int step
|
||||
return draw;
|
||||
}
|
||||
|
||||
std::vector<Render3DDraw> TerrainHeightmap::BuildPatchDraws(int patch_x, int patch_y, int step) const {
|
||||
auto base = BuildPatchDraw(patch_x, patch_y, step);
|
||||
if (m_tiles.empty()) return {std::move(base)};
|
||||
const size_t count = base.positions.size() / 3;
|
||||
std::map<uint8_t, std::vector<float>> weights;
|
||||
for (size_t v = 0; v < count; ++v) {
|
||||
const int tx = int(std::round((base.positions[v * 3] - m_world_min_x) / (m_cell_scale * 0.5f))) - 1;
|
||||
const int ty = int(std::round((base.positions[v * 3 + 2] - m_world_min_z) / (m_cell_scale * 0.5f))) - 1;
|
||||
// Smooth the native tile mask around each height vertex, as terrain splat layers do.
|
||||
for (int dy = -1; dy <= 1; ++dy) for (int dx = -1; dx <= 1; ++dx) {
|
||||
const auto tile = m_tiles[std::clamp(ty + dy, 0, m_tile_height - 1) * m_tile_width + std::clamp(tx + dx, 0, m_tile_width - 1)];
|
||||
auto& layer = weights[tile];
|
||||
if (layer.empty()) layer.resize(count);
|
||||
layer[v] += 1.0f / 9.0f;
|
||||
}
|
||||
}
|
||||
std::vector<Render3DDraw> draws{base};
|
||||
std::vector<float> accumulated(count);
|
||||
for (const auto& [tile, layer] : weights) {
|
||||
auto draw = base;
|
||||
draw.texture0 = GetTexturePathForTile(tile);
|
||||
draw.alpha_blend = true;
|
||||
draw.z_write = false;
|
||||
draw.indices.clear();
|
||||
for (size_t v = 0; v < count; ++v) {
|
||||
accumulated[v] += layer[v];
|
||||
const float alpha = accumulated[v] > 0 ? layer[v] / accumulated[v] : 0;
|
||||
draw.diffuse[v] = (uint32_t(std::round(alpha * 255)) << 24) | 0xffffff;
|
||||
}
|
||||
for (size_t t = 0; t + 2 < base.indices.size(); t += 3) {
|
||||
if (layer[base.indices[t]] + layer[base.indices[t + 1]] + layer[base.indices[t + 2]] > 0)
|
||||
draw.indices.insert(draw.indices.end(), base.indices.begin() + t, base.indices.begin() + t + 3);
|
||||
}
|
||||
if (!draw.indices.empty()) draws.push_back(std::move(draw));
|
||||
}
|
||||
return draws;
|
||||
}
|
||||
|
||||
Render3DDraw TerrainHeightmap::BuildDrawCommand(const float world[16], int step) const {
|
||||
Render3DDraw draw;
|
||||
if (m_heights.empty() || m_width < 2 || m_height < 2) return draw;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
namespace ava2 {
|
||||
|
||||
@@ -123,6 +125,7 @@ public:
|
||||
|
||||
// Build patch draw command for a single patch
|
||||
Render3DDraw BuildPatchDraw(int patch_x, int patch_y, int step = 1) const;
|
||||
std::vector<Render3DDraw> BuildPatchDraws(int patch_x, int patch_y, int step = 1) const;
|
||||
|
||||
// QuadTree & Patch hierarchy
|
||||
size_t GetPatchCount() const { return m_patches.size(); }
|
||||
@@ -181,6 +184,7 @@ private:
|
||||
|
||||
std::unordered_map<uint8_t, std::string> m_textureSet; // tile_id -> texture dds path
|
||||
|
||||
mutable std::map<std::tuple<int,int,int>, std::vector<Render3DDraw>> m_patchDrawCache;
|
||||
std::vector<TerrainPatch> m_patches; // 8x8 = 64 patches
|
||||
std::unique_ptr<TerrainQuadNode> m_quadtreeRoot;
|
||||
};
|
||||
|
||||
@@ -455,9 +455,9 @@ void TextTailManager::ArrangeTextTail() {
|
||||
for (auto& tail : m_characterList) {
|
||||
if (!tail) continue;
|
||||
|
||||
float nameWidth = static_cast<float>(tail->name.size()) * 8.0f;
|
||||
float titleWidth = tail->title.empty() ? 0.0f : (static_cast<float>(tail->title.size()) * 8.0f);
|
||||
float levelWidth = tail->level.empty() ? 0.0f : (static_cast<float>(tail->level.size()) * 8.0f);
|
||||
float nameWidth = TextWidth(tail->name);
|
||||
float titleWidth = tail->title.empty() ? 0.0f : (TextWidth(tail->title));
|
||||
float levelWidth = tail->level.empty() ? 0.0f : (TextWidth(tail->level));
|
||||
|
||||
float totalW = nameWidth;
|
||||
if (!tail->title.empty()) totalW += titleWidth + 6.0f;
|
||||
@@ -493,6 +493,7 @@ void TextTailManager::RenderTextTailBox(SDL_Renderer* renderer, const TextTailIt
|
||||
|
||||
void TextTailManager::RenderText(SDL_Renderer* renderer, float x, float y, const std::string& text, uint32_t color, float scale, bool shadow) {
|
||||
if (text.empty()) return;
|
||||
if (m_textPainter) { m_textPainter(x,y,text,color,scale,shadow); return; }
|
||||
|
||||
uint8_t a = (color >> 24) & 0xFF;
|
||||
if (a == 0) a = 0xFF;
|
||||
@@ -520,7 +521,7 @@ void TextTailManager::RenderText(SDL_Renderer* renderer, float x, float y, const
|
||||
void TextTailManager::RenderChatBubble(SDL_Renderer* renderer, const TextTailItem& tail) {
|
||||
if (!tail.hasChat || tail.chatText.empty()) return;
|
||||
|
||||
float textW = static_cast<float>(tail.chatText.size()) * 8.0f;
|
||||
float textW = TextWidth(tail.chatText);
|
||||
float bubbleW = textW + 16.0f;
|
||||
float bubbleH = 22.0f;
|
||||
float bx = tail.x - bubbleW * 0.5f;
|
||||
@@ -562,7 +563,7 @@ void TextTailManager::Render(SDL_Renderer* renderer, const Gr2SceneRenderer* sce
|
||||
|
||||
RenderTextTailBox(renderer, *tail);
|
||||
|
||||
float textW = static_cast<float>(tail->name.size()) * 8.0f;
|
||||
float textW = TextWidth(tail->name);
|
||||
float tx = tail->x - textW * 0.5f;
|
||||
float ty = tail->y - 10.0f;
|
||||
|
||||
@@ -580,7 +581,7 @@ void TextTailManager::Render(SDL_Renderer* renderer, const Gr2SceneRenderer* sce
|
||||
std::snprintf(buf, sizeof(buf), "(%dm %ds) ", m, s);
|
||||
ownerTag = std::string(buf) + ownerTag;
|
||||
}
|
||||
float owW = static_cast<float>(ownerTag.size()) * 8.0f * 0.9f;
|
||||
float owW = TextWidth(ownerTag, 0.9f);
|
||||
uint32_t owColor = tail->isMineItem ? 0xFFFFD700 : 0xFFFF6060;
|
||||
RenderText(renderer, tail->x - owW * 0.5f, ty - 14.0f, ownerTag, owColor, 0.9f, true);
|
||||
}
|
||||
@@ -590,27 +591,31 @@ void TextTailManager::Render(SDL_Renderer* renderer, const Gr2SceneRenderer* sce
|
||||
for (const auto& tail : m_characterList) {
|
||||
if (!tail) continue;
|
||||
|
||||
float nameW = static_cast<float>(tail->name.size()) * 8.0f;
|
||||
float titleW = tail->title.empty() ? 0.0f : (static_cast<float>(tail->title.size()) * 8.0f);
|
||||
float levelW = tail->level.empty() ? 0.0f : (static_cast<float>(tail->level.size()) * 8.0f);
|
||||
float nameW = TextWidth(tail->name);
|
||||
float titleW = tail->title.empty() ? 0.0f : (TextWidth(tail->title));
|
||||
float levelW = tail->level.empty() ? 0.0f : (TextWidth(tail->level));
|
||||
|
||||
float totalW = nameW;
|
||||
if (!tail->title.empty()) totalW += titleW + 6.0f;
|
||||
if (!tail->level.empty()) totalW += levelW + 6.0f;
|
||||
|
||||
float curX = tail->x - totalW * 0.5f;
|
||||
float curY = tail->y - 10.0f;
|
||||
// Original AVA2 keeps the name centered on the actor; level and title
|
||||
// extend to its left rather than moving the whole nameplate to the right.
|
||||
float curX = tail->x + 4.0f - nameW * 0.5f;
|
||||
if (!tail->title.empty()) curX -= titleW + 4.0f;
|
||||
if (!tail->level.empty()) curX -= levelW + 4.0f;
|
||||
float curY = tail->y - 14.0f;
|
||||
|
||||
// Level tag e.g. "[Lv. 99]" in lime green
|
||||
if (!tail->level.empty()) {
|
||||
RenderText(renderer, curX, curY, tail->level, tail->levelColor, 1.0f, true);
|
||||
curX += levelW + 6.0f;
|
||||
curX += levelW + 4.0f;
|
||||
}
|
||||
|
||||
// Title e.g. "Noble" in gold
|
||||
if (!tail->title.empty()) {
|
||||
RenderText(renderer, curX, curY, tail->title, tail->titleColor, 1.0f, true);
|
||||
curX += titleW + 6.0f;
|
||||
curX += titleW + 4.0f;
|
||||
}
|
||||
|
||||
// Character Name in tail->color (white / red / yellow / etc.)
|
||||
@@ -619,7 +624,7 @@ void TextTailManager::Render(SDL_Renderer* renderer, const Gr2SceneRenderer* sce
|
||||
// Guild Name e.g. "[GuildName]" in light cyan above character name, with Guild Mark
|
||||
if (!tail->guildName.empty()) {
|
||||
std::string gStr = "[" + tail->guildName + "]";
|
||||
float gW = static_cast<float>(gStr.size()) * 8.0f * 0.9f;
|
||||
float gW = TextWidth(gStr, 0.9f);
|
||||
float totalW = gW;
|
||||
bool hasMark = false;
|
||||
float u0 = 0.0f, v0 = 0.0f, u1 = 0.0f, v1 = 0.0f;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace ava2 {
|
||||
|
||||
@@ -121,6 +122,9 @@ public:
|
||||
|
||||
// Rendering
|
||||
void Render(SDL_Renderer* renderer, const Gr2SceneRenderer* sceneRenderer = nullptr);
|
||||
using TextPainter = std::function<void(float,float,const std::string&,uint32_t,float,bool)>;
|
||||
using TextMeasure = std::function<float(const std::string&,float)>;
|
||||
void SetTextPainter(TextPainter painter, TextMeasure measure) { m_textPainter = std::move(painter); m_textMeasure = std::move(measure); }
|
||||
|
||||
// Queries & Getters
|
||||
size_t GetCharacterCount() const { return m_characterMap.size(); }
|
||||
@@ -134,11 +138,19 @@ public:
|
||||
const std::shared_ptr<TextTailItem> GetItemTail(uint32_t vid) const;
|
||||
|
||||
// Active renderer reference for Python bindings
|
||||
void SetCurrentSceneRenderer(const Gr2SceneRenderer* renderer) { m_currentSceneRenderer = renderer; }
|
||||
void SetCurrentSceneRenderer(Gr2SceneRenderer* renderer) { m_currentSceneRenderer = renderer; }
|
||||
Gr2SceneRenderer* GetCurrentSceneRenderer() { return m_currentSceneRenderer; }
|
||||
const Gr2SceneRenderer* GetCurrentSceneRenderer() const { return m_currentSceneRenderer; }
|
||||
void SetCurrentRenderer(SDL_Renderer* renderer) { m_currentRenderer = renderer; }
|
||||
SDL_Renderer* GetCurrentRenderer() { return m_currentRenderer; }
|
||||
const SDL_Renderer* GetCurrentRenderer() const { return m_currentRenderer; }
|
||||
|
||||
private:
|
||||
TextPainter m_textPainter;
|
||||
TextMeasure m_textMeasure;
|
||||
float TextWidth(const std::string& text, float scale = 1.0f) const {
|
||||
return m_textMeasure ? m_textMeasure(text, scale) : float(text.size()) * 8.0f * scale;
|
||||
}
|
||||
bool isIn(const TextTailItem& src, const TextTailItem& tgt) const;
|
||||
void RenderTextTailBox(SDL_Renderer* renderer, const TextTailItem& tail);
|
||||
void RenderText(SDL_Renderer* renderer, float x, float y, const std::string& text, uint32_t color, float scale = 1.0f, bool shadow = true);
|
||||
@@ -152,7 +164,7 @@ private:
|
||||
bool m_pkTitleEnable = true;
|
||||
uint32_t m_selectedItemVID = 0;
|
||||
|
||||
const Gr2SceneRenderer* m_currentSceneRenderer = nullptr;
|
||||
Gr2SceneRenderer* m_currentSceneRenderer = nullptr;
|
||||
SDL_Renderer* m_currentRenderer = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,673 @@
|
||||
// Generated by tools/compile_scene_shaders.py; do not edit.
|
||||
#pragma once
|
||||
alignas(4) inline constexpr unsigned char scene_vert_spv[] = {
|
||||
3,2,35,7,0,0,1,0,11,0,13,0,15,2,0,0,0,0,0,0,17,0,2,0,
|
||||
1,0,0,0,11,0,6,0,1,0,0,0,71,76,83,76,46,115,116,100,46,52,53,48,
|
||||
0,0,0,0,14,0,3,0,0,0,0,0,1,0,0,0,15,0,15,0,0,0,0,0,
|
||||
4,0,0,0,109,97,105,110,0,0,0,0,74,0,0,0,200,0,0,0,205,0,0,0,
|
||||
229,0,0,0,239,0,0,0,89,1,0,0,3,2,0,0,7,2,0,0,11,2,0,0,
|
||||
13,2,0,0,3,0,3,0,2,0,0,0,194,1,0,0,4,0,10,0,71,76,95,71,
|
||||
79,79,71,76,69,95,99,112,112,95,115,116,121,108,101,95,108,105,110,101,95,100,105,114,
|
||||
101,99,116,105,118,101,0,0,4,0,8,0,71,76,95,71,79,79,71,76,69,95,105,110,
|
||||
99,108,117,100,101,95,100,105,114,101,99,116,105,118,101,0,5,0,4,0,4,0,0,0,
|
||||
109,97,105,110,0,0,0,0,5,0,11,0,15,0,0,0,116,114,97,110,115,102,111,114,
|
||||
109,82,111,119,115,40,118,102,52,59,118,102,52,59,118,102,52,59,118,102,52,59,118,102,
|
||||
52,59,0,0,5,0,3,0,10,0,0,0,112,0,0,0,5,0,3,0,11,0,0,0,
|
||||
97,0,0,0,5,0,3,0,12,0,0,0,98,0,0,0,5,0,3,0,13,0,0,0,
|
||||
99,0,0,0,5,0,3,0,14,0,0,0,100,0,0,0,5,0,5,0,46,0,0,0,
|
||||
84,114,97,110,115,102,111,114,109,0,0,0,6,0,5,0,46,0,0,0,0,0,0,0,
|
||||
119,111,114,108,100,0,0,0,6,0,4,0,46,0,0,0,1,0,0,0,109,118,112,0,
|
||||
6,0,5,0,46,0,0,0,2,0,0,0,100,105,102,102,117,115,101,0,6,0,5,0,
|
||||
46,0,0,0,3,0,0,0,97,109,98,105,101,110,116,0,6,0,6,0,46,0,0,0,
|
||||
4,0,0,0,101,109,105,115,115,105,118,101,0,0,0,0,6,0,7,0,46,0,0,0,
|
||||
5,0,0,0,108,105,103,104,116,68,105,114,101,99,116,105,111,110,0,0,6,0,7,0,
|
||||
46,0,0,0,6,0,0,0,108,105,103,104,116,65,109,98,105,101,110,116,0,0,0,0,
|
||||
6,0,7,0,46,0,0,0,7,0,0,0,108,105,103,104,116,68,105,102,102,117,115,101,
|
||||
0,0,0,0,6,0,6,0,46,0,0,0,8,0,0,0,102,111,103,67,111,108,111,114,
|
||||
0,0,0,0,6,0,6,0,46,0,0,0,9,0,0,0,102,111,103,80,97,114,97,109,
|
||||
115,0,0,0,6,0,5,0,46,0,0,0,10,0,0,0,109,111,100,101,115,0,0,0,
|
||||
6,0,5,0,46,0,0,0,11,0,0,0,115,107,105,110,0,0,0,0,5,0,3,0,
|
||||
48,0,0,0,116,0,0,0,5,0,5,0,51,0,0,0,84,114,97,110,115,102,111,114,
|
||||
109,0,0,0,6,0,5,0,51,0,0,0,0,0,0,0,119,111,114,108,100,0,0,0,
|
||||
6,0,4,0,51,0,0,0,1,0,0,0,109,118,112,0,6,0,5,0,51,0,0,0,
|
||||
2,0,0,0,100,105,102,102,117,115,101,0,6,0,5,0,51,0,0,0,3,0,0,0,
|
||||
97,109,98,105,101,110,116,0,6,0,6,0,51,0,0,0,4,0,0,0,101,109,105,115,
|
||||
115,105,118,101,0,0,0,0,6,0,7,0,51,0,0,0,5,0,0,0,108,105,103,104,
|
||||
116,68,105,114,101,99,116,105,111,110,0,0,6,0,7,0,51,0,0,0,6,0,0,0,
|
||||
108,105,103,104,116,65,109,98,105,101,110,116,0,0,0,0,6,0,7,0,51,0,0,0,
|
||||
7,0,0,0,108,105,103,104,116,68,105,102,102,117,115,101,0,0,0,0,6,0,6,0,
|
||||
51,0,0,0,8,0,0,0,102,111,103,67,111,108,111,114,0,0,0,0,6,0,6,0,
|
||||
51,0,0,0,9,0,0,0,102,111,103,80,97,114,97,109,115,0,0,0,6,0,5,0,
|
||||
51,0,0,0,10,0,0,0,109,111,100,101,115,0,0,0,6,0,5,0,51,0,0,0,
|
||||
11,0,0,0,115,107,105,110,0,0,0,0,5,0,4,0,52,0,0,0,72,101,97,100,
|
||||
101,114,0,0,6,0,5,0,52,0,0,0,0,0,0,0,104,101,97,100,101,114,0,0,
|
||||
5,0,3,0,54,0,0,0,0,0,0,0,5,0,5,0,64,0,0,0,84,114,97,110,
|
||||
115,102,111,114,109,0,0,0,6,0,5,0,64,0,0,0,0,0,0,0,119,111,114,108,
|
||||
100,0,0,0,6,0,4,0,64,0,0,0,1,0,0,0,109,118,112,0,6,0,5,0,
|
||||
64,0,0,0,2,0,0,0,100,105,102,102,117,115,101,0,6,0,5,0,64,0,0,0,
|
||||
3,0,0,0,97,109,98,105,101,110,116,0,6,0,6,0,64,0,0,0,4,0,0,0,
|
||||
101,109,105,115,115,105,118,101,0,0,0,0,6,0,7,0,64,0,0,0,5,0,0,0,
|
||||
108,105,103,104,116,68,105,114,101,99,116,105,111,110,0,0,6,0,7,0,64,0,0,0,
|
||||
6,0,0,0,108,105,103,104,116,65,109,98,105,101,110,116,0,0,0,0,6,0,7,0,
|
||||
64,0,0,0,7,0,0,0,108,105,103,104,116,68,105,102,102,117,115,101,0,0,0,0,
|
||||
6,0,6,0,64,0,0,0,8,0,0,0,102,111,103,67,111,108,111,114,0,0,0,0,
|
||||
6,0,6,0,64,0,0,0,9,0,0,0,102,111,103,80,97,114,97,109,115,0,0,0,
|
||||
6,0,5,0,64,0,0,0,10,0,0,0,109,111,100,101,115,0,0,0,6,0,5,0,
|
||||
64,0,0,0,11,0,0,0,115,107,105,110,0,0,0,0,5,0,5,0,70,0,0,0,
|
||||
73,110,115,116,97,110,99,101,115,0,0,0,6,0,6,0,70,0,0,0,0,0,0,0,
|
||||
105,110,115,116,97,110,99,101,115,0,0,0,5,0,3,0,72,0,0,0,0,0,0,0,
|
||||
5,0,7,0,74,0,0,0,103,108,95,73,110,115,116,97,110,99,101,73,110,100,101,120,
|
||||
0,0,0,0,5,0,3,0,198,0,0,0,112,0,0,0,5,0,5,0,200,0,0,0,
|
||||
112,111,115,105,116,105,111,110,0,0,0,0,5,0,3,0,204,0,0,0,110,0,0,0,
|
||||
5,0,4,0,205,0,0,0,110,111,114,109,97,108,0,0,5,0,4,0,214,0,0,0,
|
||||
115,107,105,110,110,101,100,0,5,0,3,0,217,0,0,0,115,110,0,0,5,0,4,0,
|
||||
219,0,0,0,116,111,116,97,108,0,0,0,5,0,3,0,221,0,0,0,105,0,0,0,
|
||||
5,0,4,0,229,0,0,0,119,101,105,103,104,116,115,0,5,0,4,0,239,0,0,0,
|
||||
98,111,110,101,115,0,0,0,5,0,3,0,252,0,0,0,98,0,0,0,5,0,3,0,
|
||||
1,1,0,0,119,0,0,0,5,0,4,0,7,1,0,0,80,97,108,101,116,116,101,0,
|
||||
6,0,5,0,7,1,0,0,0,0,0,0,112,97,108,101,116,116,101,0,5,0,3,0,
|
||||
9,1,0,0,0,0,0,0,5,0,4,0,17,1,0,0,112,97,114,97,109,0,0,0,
|
||||
5,0,4,0,19,1,0,0,112,97,114,97,109,0,0,0,5,0,4,0,23,1,0,0,
|
||||
112,97,114,97,109,0,0,0,5,0,4,0,26,1,0,0,112,97,114,97,109,0,0,0,
|
||||
5,0,4,0,29,1,0,0,112,97,114,97,109,0,0,0,5,0,4,0,49,1,0,0,
|
||||
112,97,114,97,109,0,0,0,5,0,4,0,50,1,0,0,112,97,114,97,109,0,0,0,
|
||||
5,0,4,0,53,1,0,0,112,97,114,97,109,0,0,0,5,0,4,0,56,1,0,0,
|
||||
112,97,114,97,109,0,0,0,5,0,4,0,59,1,0,0,112,97,114,97,109,0,0,0,
|
||||
5,0,4,0,86,1,0,0,99,108,105,112,0,0,0,0,5,0,3,0,88,1,0,0,
|
||||
99,0,0,0,5,0,4,0,89,1,0,0,99,111,108,111,114,0,0,0,5,0,4,0,
|
||||
96,1,0,0,112,97,114,97,109,0,0,0,5,0,4,0,98,1,0,0,112,97,114,97,
|
||||
109,0,0,0,5,0,4,0,101,1,0,0,112,97,114,97,109,0,0,0,5,0,4,0,
|
||||
104,1,0,0,112,97,114,97,109,0,0,0,5,0,4,0,107,1,0,0,112,97,114,97,
|
||||
109,0,0,0,5,0,3,0,126,1,0,0,119,110,0,0,5,0,4,0,132,1,0,0,
|
||||
112,97,114,97,109,0,0,0,5,0,4,0,133,1,0,0,112,97,114,97,109,0,0,0,
|
||||
5,0,4,0,136,1,0,0,112,97,114,97,109,0,0,0,5,0,4,0,139,1,0,0,
|
||||
112,97,114,97,109,0,0,0,5,0,4,0,142,1,0,0,112,97,114,97,109,0,0,0,
|
||||
5,0,3,0,147,1,0,0,108,101,110,0,5,0,4,0,159,1,0,0,110,100,111,116,
|
||||
108,0,0,0,5,0,3,0,206,1,0,0,102,0,0,0,5,0,6,0,1,2,0,0,
|
||||
103,108,95,80,101,114,86,101,114,116,101,120,0,0,0,0,6,0,6,0,1,2,0,0,
|
||||
0,0,0,0,103,108,95,80,111,115,105,116,105,111,110,0,6,0,7,0,1,2,0,0,
|
||||
1,0,0,0,103,108,95,80,111,105,110,116,83,105,122,101,0,0,0,0,6,0,7,0,
|
||||
1,2,0,0,2,0,0,0,103,108,95,67,108,105,112,68,105,115,116,97,110,99,101,0,
|
||||
6,0,7,0,1,2,0,0,3,0,0,0,103,108,95,67,117,108,108,68,105,115,116,97,
|
||||
110,99,101,0,5,0,3,0,3,2,0,0,0,0,0,0,5,0,4,0,7,2,0,0,
|
||||
118,99,111,108,111,114,0,0,5,0,3,0,11,2,0,0,118,117,118,0,5,0,3,0,
|
||||
13,2,0,0,117,118,0,0,71,0,4,0,49,0,0,0,6,0,0,0,16,0,0,0,
|
||||
71,0,4,0,50,0,0,0,6,0,0,0,16,0,0,0,72,0,5,0,51,0,0,0,
|
||||
0,0,0,0,35,0,0,0,0,0,0,0,72,0,5,0,51,0,0,0,1,0,0,0,
|
||||
35,0,0,0,64,0,0,0,72,0,5,0,51,0,0,0,2,0,0,0,35,0,0,0,
|
||||
128,0,0,0,72,0,5,0,51,0,0,0,3,0,0,0,35,0,0,0,144,0,0,0,
|
||||
72,0,5,0,51,0,0,0,4,0,0,0,35,0,0,0,160,0,0,0,72,0,5,0,
|
||||
51,0,0,0,5,0,0,0,35,0,0,0,176,0,0,0,72,0,5,0,51,0,0,0,
|
||||
6,0,0,0,35,0,0,0,192,0,0,0,72,0,5,0,51,0,0,0,7,0,0,0,
|
||||
35,0,0,0,208,0,0,0,72,0,5,0,51,0,0,0,8,0,0,0,35,0,0,0,
|
||||
224,0,0,0,72,0,5,0,51,0,0,0,9,0,0,0,35,0,0,0,240,0,0,0,
|
||||
72,0,5,0,51,0,0,0,10,0,0,0,35,0,0,0,0,1,0,0,72,0,5,0,
|
||||
51,0,0,0,11,0,0,0,35,0,0,0,16,1,0,0,71,0,3,0,52,0,0,0,
|
||||
2,0,0,0,72,0,5,0,52,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,
|
||||
71,0,4,0,54,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,54,0,0,0,
|
||||
34,0,0,0,1,0,0,0,71,0,4,0,69,0,0,0,6,0,0,0,32,1,0,0,
|
||||
71,0,3,0,70,0,0,0,3,0,0,0,72,0,4,0,70,0,0,0,0,0,0,0,
|
||||
24,0,0,0,72,0,5,0,70,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,
|
||||
71,0,3,0,72,0,0,0,24,0,0,0,71,0,4,0,72,0,0,0,33,0,0,0,
|
||||
0,0,0,0,71,0,4,0,72,0,0,0,34,0,0,0,0,0,0,0,71,0,4,0,
|
||||
74,0,0,0,11,0,0,0,43,0,0,0,71,0,4,0,200,0,0,0,30,0,0,0,
|
||||
0,0,0,0,71,0,4,0,205,0,0,0,30,0,0,0,3,0,0,0,71,0,4,0,
|
||||
229,0,0,0,30,0,0,0,5,0,0,0,71,0,4,0,239,0,0,0,30,0,0,0,
|
||||
4,0,0,0,71,0,4,0,6,1,0,0,6,0,0,0,16,0,0,0,71,0,3,0,
|
||||
7,1,0,0,2,0,0,0,72,0,5,0,7,1,0,0,0,0,0,0,35,0,0,0,
|
||||
0,0,0,0,71,0,4,0,9,1,0,0,33,0,0,0,1,0,0,0,71,0,4,0,
|
||||
9,1,0,0,34,0,0,0,1,0,0,0,71,0,4,0,89,1,0,0,30,0,0,0,
|
||||
1,0,0,0,71,0,3,0,1,2,0,0,2,0,0,0,72,0,5,0,1,2,0,0,
|
||||
0,0,0,0,11,0,0,0,0,0,0,0,72,0,5,0,1,2,0,0,1,0,0,0,
|
||||
11,0,0,0,1,0,0,0,72,0,5,0,1,2,0,0,2,0,0,0,11,0,0,0,
|
||||
3,0,0,0,72,0,5,0,1,2,0,0,3,0,0,0,11,0,0,0,4,0,0,0,
|
||||
71,0,4,0,7,2,0,0,30,0,0,0,0,0,0,0,71,0,4,0,11,2,0,0,
|
||||
30,0,0,0,1,0,0,0,71,0,4,0,13,2,0,0,30,0,0,0,2,0,0,0,
|
||||
19,0,2,0,2,0,0,0,33,0,3,0,3,0,0,0,2,0,0,0,22,0,3,0,
|
||||
6,0,0,0,32,0,0,0,23,0,4,0,7,0,0,0,6,0,0,0,4,0,0,0,
|
||||
32,0,4,0,8,0,0,0,7,0,0,0,7,0,0,0,33,0,8,0,9,0,0,0,
|
||||
7,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,
|
||||
21,0,4,0,17,0,0,0,32,0,0,0,0,0,0,0,43,0,4,0,17,0,0,0,
|
||||
18,0,0,0,0,0,0,0,32,0,4,0,19,0,0,0,7,0,0,0,6,0,0,0,
|
||||
43,0,4,0,17,0,0,0,24,0,0,0,1,0,0,0,43,0,4,0,17,0,0,0,
|
||||
30,0,0,0,2,0,0,0,43,0,4,0,17,0,0,0,36,0,0,0,3,0,0,0,
|
||||
43,0,4,0,17,0,0,0,44,0,0,0,4,0,0,0,28,0,4,0,45,0,0,0,
|
||||
7,0,0,0,44,0,0,0,30,0,14,0,46,0,0,0,45,0,0,0,45,0,0,0,
|
||||
7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,
|
||||
7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,32,0,4,0,47,0,0,0,
|
||||
7,0,0,0,46,0,0,0,28,0,4,0,49,0,0,0,7,0,0,0,44,0,0,0,
|
||||
28,0,4,0,50,0,0,0,7,0,0,0,44,0,0,0,30,0,14,0,51,0,0,0,
|
||||
49,0,0,0,50,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,
|
||||
7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,
|
||||
30,0,3,0,52,0,0,0,51,0,0,0,32,0,4,0,53,0,0,0,2,0,0,0,
|
||||
52,0,0,0,59,0,4,0,53,0,0,0,54,0,0,0,2,0,0,0,21,0,4,0,
|
||||
55,0,0,0,32,0,0,0,1,0,0,0,43,0,4,0,55,0,0,0,56,0,0,0,
|
||||
0,0,0,0,43,0,4,0,55,0,0,0,57,0,0,0,10,0,0,0,32,0,4,0,
|
||||
58,0,0,0,2,0,0,0,6,0,0,0,43,0,4,0,6,0,0,0,61,0,0,0,
|
||||
0,0,192,63,20,0,2,0,62,0,0,0,30,0,14,0,64,0,0,0,45,0,0,0,
|
||||
45,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,
|
||||
7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,7,0,0,0,32,0,4,0,
|
||||
65,0,0,0,7,0,0,0,64,0,0,0,29,0,3,0,69,0,0,0,51,0,0,0,
|
||||
30,0,3,0,70,0,0,0,69,0,0,0,32,0,4,0,71,0,0,0,2,0,0,0,
|
||||
70,0,0,0,59,0,4,0,71,0,0,0,72,0,0,0,2,0,0,0,32,0,4,0,
|
||||
73,0,0,0,1,0,0,0,55,0,0,0,59,0,4,0,73,0,0,0,74,0,0,0,
|
||||
1,0,0,0,32,0,4,0,76,0,0,0,2,0,0,0,51,0,0,0,32,0,4,0,
|
||||
80,0,0,0,7,0,0,0,45,0,0,0,43,0,4,0,55,0,0,0,85,0,0,0,
|
||||
1,0,0,0,43,0,4,0,55,0,0,0,88,0,0,0,2,0,0,0,43,0,4,0,
|
||||
55,0,0,0,91,0,0,0,3,0,0,0,43,0,4,0,55,0,0,0,108,0,0,0,
|
||||
4,0,0,0,43,0,4,0,55,0,0,0,111,0,0,0,5,0,0,0,43,0,4,0,
|
||||
55,0,0,0,114,0,0,0,6,0,0,0,43,0,4,0,55,0,0,0,117,0,0,0,
|
||||
7,0,0,0,43,0,4,0,55,0,0,0,120,0,0,0,8,0,0,0,43,0,4,0,
|
||||
55,0,0,0,123,0,0,0,9,0,0,0,43,0,4,0,55,0,0,0,128,0,0,0,
|
||||
11,0,0,0,32,0,4,0,199,0,0,0,1,0,0,0,7,0,0,0,59,0,4,0,
|
||||
199,0,0,0,200,0,0,0,1,0,0,0,23,0,4,0,202,0,0,0,6,0,0,0,
|
||||
3,0,0,0,32,0,4,0,203,0,0,0,7,0,0,0,202,0,0,0,59,0,4,0,
|
||||
199,0,0,0,205,0,0,0,1,0,0,0,43,0,4,0,6,0,0,0,210,0,0,0,
|
||||
0,0,0,63,43,0,4,0,6,0,0,0,215,0,0,0,0,0,0,0,44,0,7,0,
|
||||
7,0,0,0,216,0,0,0,215,0,0,0,215,0,0,0,215,0,0,0,215,0,0,0,
|
||||
44,0,6,0,202,0,0,0,218,0,0,0,215,0,0,0,215,0,0,0,215,0,0,0,
|
||||
32,0,4,0,220,0,0,0,7,0,0,0,55,0,0,0,59,0,4,0,199,0,0,0,
|
||||
229,0,0,0,1,0,0,0,32,0,4,0,231,0,0,0,1,0,0,0,6,0,0,0,
|
||||
23,0,4,0,237,0,0,0,17,0,0,0,4,0,0,0,32,0,4,0,238,0,0,0,
|
||||
1,0,0,0,237,0,0,0,59,0,4,0,238,0,0,0,239,0,0,0,1,0,0,0,
|
||||
32,0,4,0,241,0,0,0,1,0,0,0,17,0,0,0,32,0,4,0,251,0,0,0,
|
||||
7,0,0,0,17,0,0,0,43,0,4,0,17,0,0,0,5,1,0,0,0,2,0,0,
|
||||
28,0,4,0,6,1,0,0,7,0,0,0,5,1,0,0,30,0,3,0,7,1,0,0,
|
||||
6,1,0,0,32,0,4,0,8,1,0,0,2,0,0,0,7,1,0,0,59,0,4,0,
|
||||
8,1,0,0,9,1,0,0,2,0,0,0,32,0,4,0,20,1,0,0,2,0,0,0,
|
||||
7,0,0,0,43,0,4,0,6,0,0,0,74,1,0,0,23,183,209,56,43,0,4,0,
|
||||
6,0,0,0,80,1,0,0,0,0,128,63,59,0,4,0,199,0,0,0,89,1,0,0,
|
||||
1,0,0,0,43,0,4,0,6,0,0,0,151,1,0,0,172,197,39,55,43,0,4,0,
|
||||
6,0,0,0,218,1,0,0,0,0,32,65,28,0,4,0,0,2,0,0,6,0,0,0,
|
||||
24,0,0,0,30,0,6,0,1,2,0,0,7,0,0,0,6,0,0,0,0,2,0,0,
|
||||
0,2,0,0,32,0,4,0,2,2,0,0,3,0,0,0,1,2,0,0,59,0,4,0,
|
||||
2,2,0,0,3,2,0,0,3,0,0,0,32,0,4,0,5,2,0,0,3,0,0,0,
|
||||
7,0,0,0,59,0,4,0,5,2,0,0,7,2,0,0,3,0,0,0,23,0,4,0,
|
||||
9,2,0,0,6,0,0,0,2,0,0,0,32,0,4,0,10,2,0,0,3,0,0,0,
|
||||
9,2,0,0,59,0,4,0,10,2,0,0,11,2,0,0,3,0,0,0,32,0,4,0,
|
||||
12,2,0,0,1,0,0,0,9,2,0,0,59,0,4,0,12,2,0,0,13,2,0,0,
|
||||
1,0,0,0,54,0,5,0,2,0,0,0,4,0,0,0,0,0,0,0,3,0,0,0,
|
||||
248,0,2,0,5,0,0,0,59,0,4,0,47,0,0,0,48,0,0,0,7,0,0,0,
|
||||
59,0,4,0,65,0,0,0,66,0,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
198,0,0,0,7,0,0,0,59,0,4,0,203,0,0,0,204,0,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,214,0,0,0,7,0,0,0,59,0,4,0,203,0,0,0,
|
||||
217,0,0,0,7,0,0,0,59,0,4,0,19,0,0,0,219,0,0,0,7,0,0,0,
|
||||
59,0,4,0,220,0,0,0,221,0,0,0,7,0,0,0,59,0,4,0,251,0,0,0,
|
||||
252,0,0,0,7,0,0,0,59,0,4,0,19,0,0,0,1,1,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,17,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
19,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,23,1,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,26,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
29,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,49,1,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,50,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
53,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,56,1,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,59,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
86,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,88,1,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,96,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
98,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,101,1,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,104,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
107,1,0,0,7,0,0,0,59,0,4,0,203,0,0,0,126,1,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,132,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
133,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,136,1,0,0,7,0,0,0,
|
||||
59,0,4,0,8,0,0,0,139,1,0,0,7,0,0,0,59,0,4,0,8,0,0,0,
|
||||
142,1,0,0,7,0,0,0,59,0,4,0,19,0,0,0,147,1,0,0,7,0,0,0,
|
||||
59,0,4,0,19,0,0,0,159,1,0,0,7,0,0,0,59,0,4,0,19,0,0,0,
|
||||
206,1,0,0,7,0,0,0,59,0,4,0,19,0,0,0,210,1,0,0,7,0,0,0,
|
||||
65,0,7,0,58,0,0,0,59,0,0,0,54,0,0,0,56,0,0,0,57,0,0,0,
|
||||
18,0,0,0,61,0,4,0,6,0,0,0,60,0,0,0,59,0,0,0,186,0,5,0,
|
||||
62,0,0,0,63,0,0,0,60,0,0,0,61,0,0,0,247,0,3,0,68,0,0,0,
|
||||
0,0,0,0,250,0,4,0,63,0,0,0,67,0,0,0,130,0,0,0,248,0,2,0,
|
||||
67,0,0,0,61,0,4,0,55,0,0,0,75,0,0,0,74,0,0,0,65,0,6,0,
|
||||
76,0,0,0,77,0,0,0,72,0,0,0,56,0,0,0,75,0,0,0,61,0,4,0,
|
||||
51,0,0,0,78,0,0,0,77,0,0,0,81,0,5,0,49,0,0,0,79,0,0,0,
|
||||
78,0,0,0,0,0,0,0,65,0,5,0,80,0,0,0,81,0,0,0,66,0,0,0,
|
||||
56,0,0,0,81,0,5,0,7,0,0,0,82,0,0,0,79,0,0,0,0,0,0,0,
|
||||
65,0,5,0,8,0,0,0,83,0,0,0,81,0,0,0,56,0,0,0,62,0,3,0,
|
||||
83,0,0,0,82,0,0,0,81,0,5,0,7,0,0,0,84,0,0,0,79,0,0,0,
|
||||
1,0,0,0,65,0,5,0,8,0,0,0,86,0,0,0,81,0,0,0,85,0,0,0,
|
||||
62,0,3,0,86,0,0,0,84,0,0,0,81,0,5,0,7,0,0,0,87,0,0,0,
|
||||
79,0,0,0,2,0,0,0,65,0,5,0,8,0,0,0,89,0,0,0,81,0,0,0,
|
||||
88,0,0,0,62,0,3,0,89,0,0,0,87,0,0,0,81,0,5,0,7,0,0,0,
|
||||
90,0,0,0,79,0,0,0,3,0,0,0,65,0,5,0,8,0,0,0,92,0,0,0,
|
||||
81,0,0,0,91,0,0,0,62,0,3,0,92,0,0,0,90,0,0,0,81,0,5,0,
|
||||
50,0,0,0,93,0,0,0,78,0,0,0,1,0,0,0,65,0,5,0,80,0,0,0,
|
||||
94,0,0,0,66,0,0,0,85,0,0,0,81,0,5,0,7,0,0,0,95,0,0,0,
|
||||
93,0,0,0,0,0,0,0,65,0,5,0,8,0,0,0,96,0,0,0,94,0,0,0,
|
||||
56,0,0,0,62,0,3,0,96,0,0,0,95,0,0,0,81,0,5,0,7,0,0,0,
|
||||
97,0,0,0,93,0,0,0,1,0,0,0,65,0,5,0,8,0,0,0,98,0,0,0,
|
||||
94,0,0,0,85,0,0,0,62,0,3,0,98,0,0,0,97,0,0,0,81,0,5,0,
|
||||
7,0,0,0,99,0,0,0,93,0,0,0,2,0,0,0,65,0,5,0,8,0,0,0,
|
||||
100,0,0,0,94,0,0,0,88,0,0,0,62,0,3,0,100,0,0,0,99,0,0,0,
|
||||
81,0,5,0,7,0,0,0,101,0,0,0,93,0,0,0,3,0,0,0,65,0,5,0,
|
||||
8,0,0,0,102,0,0,0,94,0,0,0,91,0,0,0,62,0,3,0,102,0,0,0,
|
||||
101,0,0,0,81,0,5,0,7,0,0,0,103,0,0,0,78,0,0,0,2,0,0,0,
|
||||
65,0,5,0,8,0,0,0,104,0,0,0,66,0,0,0,88,0,0,0,62,0,3,0,
|
||||
104,0,0,0,103,0,0,0,81,0,5,0,7,0,0,0,105,0,0,0,78,0,0,0,
|
||||
3,0,0,0,65,0,5,0,8,0,0,0,106,0,0,0,66,0,0,0,91,0,0,0,
|
||||
62,0,3,0,106,0,0,0,105,0,0,0,81,0,5,0,7,0,0,0,107,0,0,0,
|
||||
78,0,0,0,4,0,0,0,65,0,5,0,8,0,0,0,109,0,0,0,66,0,0,0,
|
||||
108,0,0,0,62,0,3,0,109,0,0,0,107,0,0,0,81,0,5,0,7,0,0,0,
|
||||
110,0,0,0,78,0,0,0,5,0,0,0,65,0,5,0,8,0,0,0,112,0,0,0,
|
||||
66,0,0,0,111,0,0,0,62,0,3,0,112,0,0,0,110,0,0,0,81,0,5,0,
|
||||
7,0,0,0,113,0,0,0,78,0,0,0,6,0,0,0,65,0,5,0,8,0,0,0,
|
||||
115,0,0,0,66,0,0,0,114,0,0,0,62,0,3,0,115,0,0,0,113,0,0,0,
|
||||
81,0,5,0,7,0,0,0,116,0,0,0,78,0,0,0,7,0,0,0,65,0,5,0,
|
||||
8,0,0,0,118,0,0,0,66,0,0,0,117,0,0,0,62,0,3,0,118,0,0,0,
|
||||
116,0,0,0,81,0,5,0,7,0,0,0,119,0,0,0,78,0,0,0,8,0,0,0,
|
||||
65,0,5,0,8,0,0,0,121,0,0,0,66,0,0,0,120,0,0,0,62,0,3,0,
|
||||
121,0,0,0,119,0,0,0,81,0,5,0,7,0,0,0,122,0,0,0,78,0,0,0,
|
||||
9,0,0,0,65,0,5,0,8,0,0,0,124,0,0,0,66,0,0,0,123,0,0,0,
|
||||
62,0,3,0,124,0,0,0,122,0,0,0,81,0,5,0,7,0,0,0,125,0,0,0,
|
||||
78,0,0,0,10,0,0,0,65,0,5,0,8,0,0,0,126,0,0,0,66,0,0,0,
|
||||
57,0,0,0,62,0,3,0,126,0,0,0,125,0,0,0,81,0,5,0,7,0,0,0,
|
||||
127,0,0,0,78,0,0,0,11,0,0,0,65,0,5,0,8,0,0,0,129,0,0,0,
|
||||
66,0,0,0,128,0,0,0,62,0,3,0,129,0,0,0,127,0,0,0,249,0,2,0,
|
||||
68,0,0,0,248,0,2,0,130,0,0,0,65,0,5,0,76,0,0,0,131,0,0,0,
|
||||
54,0,0,0,56,0,0,0,61,0,4,0,51,0,0,0,132,0,0,0,131,0,0,0,
|
||||
81,0,5,0,49,0,0,0,133,0,0,0,132,0,0,0,0,0,0,0,65,0,5,0,
|
||||
80,0,0,0,134,0,0,0,66,0,0,0,56,0,0,0,81,0,5,0,7,0,0,0,
|
||||
135,0,0,0,133,0,0,0,0,0,0,0,65,0,5,0,8,0,0,0,136,0,0,0,
|
||||
134,0,0,0,56,0,0,0,62,0,3,0,136,0,0,0,135,0,0,0,81,0,5,0,
|
||||
7,0,0,0,137,0,0,0,133,0,0,0,1,0,0,0,65,0,5,0,8,0,0,0,
|
||||
138,0,0,0,134,0,0,0,85,0,0,0,62,0,3,0,138,0,0,0,137,0,0,0,
|
||||
81,0,5,0,7,0,0,0,139,0,0,0,133,0,0,0,2,0,0,0,65,0,5,0,
|
||||
8,0,0,0,140,0,0,0,134,0,0,0,88,0,0,0,62,0,3,0,140,0,0,0,
|
||||
139,0,0,0,81,0,5,0,7,0,0,0,141,0,0,0,133,0,0,0,3,0,0,0,
|
||||
65,0,5,0,8,0,0,0,142,0,0,0,134,0,0,0,91,0,0,0,62,0,3,0,
|
||||
142,0,0,0,141,0,0,0,81,0,5,0,50,0,0,0,143,0,0,0,132,0,0,0,
|
||||
1,0,0,0,65,0,5,0,80,0,0,0,144,0,0,0,66,0,0,0,85,0,0,0,
|
||||
81,0,5,0,7,0,0,0,145,0,0,0,143,0,0,0,0,0,0,0,65,0,5,0,
|
||||
8,0,0,0,146,0,0,0,144,0,0,0,56,0,0,0,62,0,3,0,146,0,0,0,
|
||||
145,0,0,0,81,0,5,0,7,0,0,0,147,0,0,0,143,0,0,0,1,0,0,0,
|
||||
65,0,5,0,8,0,0,0,148,0,0,0,144,0,0,0,85,0,0,0,62,0,3,0,
|
||||
148,0,0,0,147,0,0,0,81,0,5,0,7,0,0,0,149,0,0,0,143,0,0,0,
|
||||
2,0,0,0,65,0,5,0,8,0,0,0,150,0,0,0,144,0,0,0,88,0,0,0,
|
||||
62,0,3,0,150,0,0,0,149,0,0,0,81,0,5,0,7,0,0,0,151,0,0,0,
|
||||
143,0,0,0,3,0,0,0,65,0,5,0,8,0,0,0,152,0,0,0,144,0,0,0,
|
||||
91,0,0,0,62,0,3,0,152,0,0,0,151,0,0,0,81,0,5,0,7,0,0,0,
|
||||
153,0,0,0,132,0,0,0,2,0,0,0,65,0,5,0,8,0,0,0,154,0,0,0,
|
||||
66,0,0,0,88,0,0,0,62,0,3,0,154,0,0,0,153,0,0,0,81,0,5,0,
|
||||
7,0,0,0,155,0,0,0,132,0,0,0,3,0,0,0,65,0,5,0,8,0,0,0,
|
||||
156,0,0,0,66,0,0,0,91,0,0,0,62,0,3,0,156,0,0,0,155,0,0,0,
|
||||
81,0,5,0,7,0,0,0,157,0,0,0,132,0,0,0,4,0,0,0,65,0,5,0,
|
||||
8,0,0,0,158,0,0,0,66,0,0,0,108,0,0,0,62,0,3,0,158,0,0,0,
|
||||
157,0,0,0,81,0,5,0,7,0,0,0,159,0,0,0,132,0,0,0,5,0,0,0,
|
||||
65,0,5,0,8,0,0,0,160,0,0,0,66,0,0,0,111,0,0,0,62,0,3,0,
|
||||
160,0,0,0,159,0,0,0,81,0,5,0,7,0,0,0,161,0,0,0,132,0,0,0,
|
||||
6,0,0,0,65,0,5,0,8,0,0,0,162,0,0,0,66,0,0,0,114,0,0,0,
|
||||
62,0,3,0,162,0,0,0,161,0,0,0,81,0,5,0,7,0,0,0,163,0,0,0,
|
||||
132,0,0,0,7,0,0,0,65,0,5,0,8,0,0,0,164,0,0,0,66,0,0,0,
|
||||
117,0,0,0,62,0,3,0,164,0,0,0,163,0,0,0,81,0,5,0,7,0,0,0,
|
||||
165,0,0,0,132,0,0,0,8,0,0,0,65,0,5,0,8,0,0,0,166,0,0,0,
|
||||
66,0,0,0,120,0,0,0,62,0,3,0,166,0,0,0,165,0,0,0,81,0,5,0,
|
||||
7,0,0,0,167,0,0,0,132,0,0,0,9,0,0,0,65,0,5,0,8,0,0,0,
|
||||
168,0,0,0,66,0,0,0,123,0,0,0,62,0,3,0,168,0,0,0,167,0,0,0,
|
||||
81,0,5,0,7,0,0,0,169,0,0,0,132,0,0,0,10,0,0,0,65,0,5,0,
|
||||
8,0,0,0,170,0,0,0,66,0,0,0,57,0,0,0,62,0,3,0,170,0,0,0,
|
||||
169,0,0,0,81,0,5,0,7,0,0,0,171,0,0,0,132,0,0,0,11,0,0,0,
|
||||
65,0,5,0,8,0,0,0,172,0,0,0,66,0,0,0,128,0,0,0,62,0,3,0,
|
||||
172,0,0,0,171,0,0,0,249,0,2,0,68,0,0,0,248,0,2,0,68,0,0,0,
|
||||
61,0,4,0,64,0,0,0,173,0,0,0,66,0,0,0,81,0,5,0,45,0,0,0,
|
||||
174,0,0,0,173,0,0,0,0,0,0,0,65,0,5,0,80,0,0,0,175,0,0,0,
|
||||
48,0,0,0,56,0,0,0,62,0,3,0,175,0,0,0,174,0,0,0,81,0,5,0,
|
||||
45,0,0,0,176,0,0,0,173,0,0,0,1,0,0,0,65,0,5,0,80,0,0,0,
|
||||
177,0,0,0,48,0,0,0,85,0,0,0,62,0,3,0,177,0,0,0,176,0,0,0,
|
||||
81,0,5,0,7,0,0,0,178,0,0,0,173,0,0,0,2,0,0,0,65,0,5,0,
|
||||
8,0,0,0,179,0,0,0,48,0,0,0,88,0,0,0,62,0,3,0,179,0,0,0,
|
||||
178,0,0,0,81,0,5,0,7,0,0,0,180,0,0,0,173,0,0,0,3,0,0,0,
|
||||
65,0,5,0,8,0,0,0,181,0,0,0,48,0,0,0,91,0,0,0,62,0,3,0,
|
||||
181,0,0,0,180,0,0,0,81,0,5,0,7,0,0,0,182,0,0,0,173,0,0,0,
|
||||
4,0,0,0,65,0,5,0,8,0,0,0,183,0,0,0,48,0,0,0,108,0,0,0,
|
||||
62,0,3,0,183,0,0,0,182,0,0,0,81,0,5,0,7,0,0,0,184,0,0,0,
|
||||
173,0,0,0,5,0,0,0,65,0,5,0,8,0,0,0,185,0,0,0,48,0,0,0,
|
||||
111,0,0,0,62,0,3,0,185,0,0,0,184,0,0,0,81,0,5,0,7,0,0,0,
|
||||
186,0,0,0,173,0,0,0,6,0,0,0,65,0,5,0,8,0,0,0,187,0,0,0,
|
||||
48,0,0,0,114,0,0,0,62,0,3,0,187,0,0,0,186,0,0,0,81,0,5,0,
|
||||
7,0,0,0,188,0,0,0,173,0,0,0,7,0,0,0,65,0,5,0,8,0,0,0,
|
||||
189,0,0,0,48,0,0,0,117,0,0,0,62,0,3,0,189,0,0,0,188,0,0,0,
|
||||
81,0,5,0,7,0,0,0,190,0,0,0,173,0,0,0,8,0,0,0,65,0,5,0,
|
||||
8,0,0,0,191,0,0,0,48,0,0,0,120,0,0,0,62,0,3,0,191,0,0,0,
|
||||
190,0,0,0,81,0,5,0,7,0,0,0,192,0,0,0,173,0,0,0,9,0,0,0,
|
||||
65,0,5,0,8,0,0,0,193,0,0,0,48,0,0,0,123,0,0,0,62,0,3,0,
|
||||
193,0,0,0,192,0,0,0,81,0,5,0,7,0,0,0,194,0,0,0,173,0,0,0,
|
||||
10,0,0,0,65,0,5,0,8,0,0,0,195,0,0,0,48,0,0,0,57,0,0,0,
|
||||
62,0,3,0,195,0,0,0,194,0,0,0,81,0,5,0,7,0,0,0,196,0,0,0,
|
||||
173,0,0,0,11,0,0,0,65,0,5,0,8,0,0,0,197,0,0,0,48,0,0,0,
|
||||
128,0,0,0,62,0,3,0,197,0,0,0,196,0,0,0,61,0,4,0,7,0,0,0,
|
||||
201,0,0,0,200,0,0,0,62,0,3,0,198,0,0,0,201,0,0,0,61,0,4,0,
|
||||
7,0,0,0,206,0,0,0,205,0,0,0,79,0,8,0,202,0,0,0,207,0,0,0,
|
||||
206,0,0,0,206,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,62,0,3,0,
|
||||
204,0,0,0,207,0,0,0,65,0,6,0,19,0,0,0,208,0,0,0,48,0,0,0,
|
||||
128,0,0,0,18,0,0,0,61,0,4,0,6,0,0,0,209,0,0,0,208,0,0,0,
|
||||
186,0,5,0,62,0,0,0,211,0,0,0,209,0,0,0,210,0,0,0,247,0,3,0,
|
||||
213,0,0,0,0,0,0,0,250,0,4,0,211,0,0,0,212,0,0,0,213,0,0,0,
|
||||
248,0,2,0,212,0,0,0,62,0,3,0,214,0,0,0,216,0,0,0,62,0,3,0,
|
||||
217,0,0,0,218,0,0,0,62,0,3,0,219,0,0,0,215,0,0,0,62,0,3,0,
|
||||
221,0,0,0,56,0,0,0,249,0,2,0,222,0,0,0,248,0,2,0,222,0,0,0,
|
||||
246,0,4,0,224,0,0,0,225,0,0,0,0,0,0,0,249,0,2,0,226,0,0,0,
|
||||
248,0,2,0,226,0,0,0,61,0,4,0,55,0,0,0,227,0,0,0,221,0,0,0,
|
||||
177,0,5,0,62,0,0,0,228,0,0,0,227,0,0,0,108,0,0,0,250,0,4,0,
|
||||
228,0,0,0,223,0,0,0,224,0,0,0,248,0,2,0,223,0,0,0,61,0,4,0,
|
||||
55,0,0,0,230,0,0,0,221,0,0,0,65,0,5,0,231,0,0,0,232,0,0,0,
|
||||
229,0,0,0,230,0,0,0,61,0,4,0,6,0,0,0,233,0,0,0,232,0,0,0,
|
||||
186,0,5,0,62,0,0,0,234,0,0,0,233,0,0,0,215,0,0,0,247,0,3,0,
|
||||
236,0,0,0,0,0,0,0,250,0,4,0,234,0,0,0,235,0,0,0,236,0,0,0,
|
||||
248,0,2,0,235,0,0,0,61,0,4,0,55,0,0,0,240,0,0,0,221,0,0,0,
|
||||
65,0,5,0,241,0,0,0,242,0,0,0,239,0,0,0,240,0,0,0,61,0,4,0,
|
||||
17,0,0,0,243,0,0,0,242,0,0,0,65,0,6,0,19,0,0,0,244,0,0,0,
|
||||
48,0,0,0,128,0,0,0,18,0,0,0,61,0,4,0,6,0,0,0,245,0,0,0,
|
||||
244,0,0,0,109,0,4,0,17,0,0,0,246,0,0,0,245,0,0,0,176,0,5,0,
|
||||
62,0,0,0,247,0,0,0,243,0,0,0,246,0,0,0,249,0,2,0,236,0,0,0,
|
||||
248,0,2,0,236,0,0,0,245,0,7,0,62,0,0,0,248,0,0,0,234,0,0,0,
|
||||
223,0,0,0,247,0,0,0,235,0,0,0,247,0,3,0,250,0,0,0,0,0,0,0,
|
||||
250,0,4,0,248,0,0,0,249,0,0,0,250,0,0,0,248,0,2,0,249,0,0,0,
|
||||
61,0,4,0,55,0,0,0,253,0,0,0,221,0,0,0,65,0,5,0,241,0,0,0,
|
||||
254,0,0,0,239,0,0,0,253,0,0,0,61,0,4,0,17,0,0,0,255,0,0,0,
|
||||
254,0,0,0,132,0,5,0,17,0,0,0,0,1,0,0,255,0,0,0,44,0,0,0,
|
||||
62,0,3,0,252,0,0,0,0,1,0,0,61,0,4,0,55,0,0,0,2,1,0,0,
|
||||
221,0,0,0,65,0,5,0,231,0,0,0,3,1,0,0,229,0,0,0,2,1,0,0,
|
||||
61,0,4,0,6,0,0,0,4,1,0,0,3,1,0,0,62,0,3,0,1,1,0,0,
|
||||
4,1,0,0,61,0,4,0,17,0,0,0,10,1,0,0,252,0,0,0,61,0,4,0,
|
||||
17,0,0,0,11,1,0,0,252,0,0,0,128,0,5,0,17,0,0,0,12,1,0,0,
|
||||
11,1,0,0,24,0,0,0,61,0,4,0,17,0,0,0,13,1,0,0,252,0,0,0,
|
||||
128,0,5,0,17,0,0,0,14,1,0,0,13,1,0,0,30,0,0,0,61,0,4,0,
|
||||
17,0,0,0,15,1,0,0,252,0,0,0,128,0,5,0,17,0,0,0,16,1,0,0,
|
||||
15,1,0,0,36,0,0,0,61,0,4,0,7,0,0,0,18,1,0,0,198,0,0,0,
|
||||
62,0,3,0,17,1,0,0,18,1,0,0,65,0,6,0,20,1,0,0,21,1,0,0,
|
||||
9,1,0,0,56,0,0,0,10,1,0,0,61,0,4,0,7,0,0,0,22,1,0,0,
|
||||
21,1,0,0,62,0,3,0,19,1,0,0,22,1,0,0,65,0,6,0,20,1,0,0,
|
||||
24,1,0,0,9,1,0,0,56,0,0,0,12,1,0,0,61,0,4,0,7,0,0,0,
|
||||
25,1,0,0,24,1,0,0,62,0,3,0,23,1,0,0,25,1,0,0,65,0,6,0,
|
||||
20,1,0,0,27,1,0,0,9,1,0,0,56,0,0,0,14,1,0,0,61,0,4,0,
|
||||
7,0,0,0,28,1,0,0,27,1,0,0,62,0,3,0,26,1,0,0,28,1,0,0,
|
||||
65,0,6,0,20,1,0,0,30,1,0,0,9,1,0,0,56,0,0,0,16,1,0,0,
|
||||
61,0,4,0,7,0,0,0,31,1,0,0,30,1,0,0,62,0,3,0,29,1,0,0,
|
||||
31,1,0,0,57,0,9,0,7,0,0,0,32,1,0,0,15,0,0,0,17,1,0,0,
|
||||
19,1,0,0,23,1,0,0,26,1,0,0,29,1,0,0,61,0,4,0,6,0,0,0,
|
||||
33,1,0,0,1,1,0,0,142,0,5,0,7,0,0,0,34,1,0,0,32,1,0,0,
|
||||
33,1,0,0,61,0,4,0,7,0,0,0,35,1,0,0,214,0,0,0,129,0,5,0,
|
||||
7,0,0,0,36,1,0,0,35,1,0,0,34,1,0,0,62,0,3,0,214,0,0,0,
|
||||
36,1,0,0,61,0,4,0,202,0,0,0,37,1,0,0,204,0,0,0,81,0,5,0,
|
||||
6,0,0,0,38,1,0,0,37,1,0,0,0,0,0,0,81,0,5,0,6,0,0,0,
|
||||
39,1,0,0,37,1,0,0,1,0,0,0,81,0,5,0,6,0,0,0,40,1,0,0,
|
||||
37,1,0,0,2,0,0,0,80,0,7,0,7,0,0,0,41,1,0,0,38,1,0,0,
|
||||
39,1,0,0,40,1,0,0,215,0,0,0,61,0,4,0,17,0,0,0,42,1,0,0,
|
||||
252,0,0,0,61,0,4,0,17,0,0,0,43,1,0,0,252,0,0,0,128,0,5,0,
|
||||
17,0,0,0,44,1,0,0,43,1,0,0,24,0,0,0,61,0,4,0,17,0,0,0,
|
||||
45,1,0,0,252,0,0,0,128,0,5,0,17,0,0,0,46,1,0,0,45,1,0,0,
|
||||
30,0,0,0,61,0,4,0,17,0,0,0,47,1,0,0,252,0,0,0,128,0,5,0,
|
||||
17,0,0,0,48,1,0,0,47,1,0,0,36,0,0,0,62,0,3,0,49,1,0,0,
|
||||
41,1,0,0,65,0,6,0,20,1,0,0,51,1,0,0,9,1,0,0,56,0,0,0,
|
||||
42,1,0,0,61,0,4,0,7,0,0,0,52,1,0,0,51,1,0,0,62,0,3,0,
|
||||
50,1,0,0,52,1,0,0,65,0,6,0,20,1,0,0,54,1,0,0,9,1,0,0,
|
||||
56,0,0,0,44,1,0,0,61,0,4,0,7,0,0,0,55,1,0,0,54,1,0,0,
|
||||
62,0,3,0,53,1,0,0,55,1,0,0,65,0,6,0,20,1,0,0,57,1,0,0,
|
||||
9,1,0,0,56,0,0,0,46,1,0,0,61,0,4,0,7,0,0,0,58,1,0,0,
|
||||
57,1,0,0,62,0,3,0,56,1,0,0,58,1,0,0,65,0,6,0,20,1,0,0,
|
||||
60,1,0,0,9,1,0,0,56,0,0,0,48,1,0,0,61,0,4,0,7,0,0,0,
|
||||
61,1,0,0,60,1,0,0,62,0,3,0,59,1,0,0,61,1,0,0,57,0,9,0,
|
||||
7,0,0,0,62,1,0,0,15,0,0,0,49,1,0,0,50,1,0,0,53,1,0,0,
|
||||
56,1,0,0,59,1,0,0,79,0,8,0,202,0,0,0,63,1,0,0,62,1,0,0,
|
||||
62,1,0,0,0,0,0,0,1,0,0,0,2,0,0,0,61,0,4,0,6,0,0,0,
|
||||
64,1,0,0,1,1,0,0,142,0,5,0,202,0,0,0,65,1,0,0,63,1,0,0,
|
||||
64,1,0,0,61,0,4,0,202,0,0,0,66,1,0,0,217,0,0,0,129,0,5,0,
|
||||
202,0,0,0,67,1,0,0,66,1,0,0,65,1,0,0,62,0,3,0,217,0,0,0,
|
||||
67,1,0,0,61,0,4,0,6,0,0,0,68,1,0,0,1,1,0,0,61,0,4,0,
|
||||
6,0,0,0,69,1,0,0,219,0,0,0,129,0,5,0,6,0,0,0,70,1,0,0,
|
||||
69,1,0,0,68,1,0,0,62,0,3,0,219,0,0,0,70,1,0,0,249,0,2,0,
|
||||
250,0,0,0,248,0,2,0,250,0,0,0,249,0,2,0,225,0,0,0,248,0,2,0,
|
||||
225,0,0,0,61,0,4,0,55,0,0,0,71,1,0,0,221,0,0,0,128,0,5,0,
|
||||
55,0,0,0,72,1,0,0,71,1,0,0,85,0,0,0,62,0,3,0,221,0,0,0,
|
||||
72,1,0,0,249,0,2,0,222,0,0,0,248,0,2,0,224,0,0,0,61,0,4,0,
|
||||
6,0,0,0,73,1,0,0,219,0,0,0,186,0,5,0,62,0,0,0,75,1,0,0,
|
||||
73,1,0,0,74,1,0,0,247,0,3,0,77,1,0,0,0,0,0,0,250,0,4,0,
|
||||
75,1,0,0,76,1,0,0,77,1,0,0,248,0,2,0,76,1,0,0,61,0,4,0,
|
||||
7,0,0,0,78,1,0,0,214,0,0,0,79,0,8,0,202,0,0,0,79,1,0,0,
|
||||
78,1,0,0,78,1,0,0,0,0,0,0,1,0,0,0,2,0,0,0,81,0,5,0,
|
||||
6,0,0,0,81,1,0,0,79,1,0,0,0,0,0,0,81,0,5,0,6,0,0,0,
|
||||
82,1,0,0,79,1,0,0,1,0,0,0,81,0,5,0,6,0,0,0,83,1,0,0,
|
||||
79,1,0,0,2,0,0,0,80,0,7,0,7,0,0,0,84,1,0,0,81,1,0,0,
|
||||
82,1,0,0,83,1,0,0,80,1,0,0,62,0,3,0,198,0,0,0,84,1,0,0,
|
||||
61,0,4,0,202,0,0,0,85,1,0,0,217,0,0,0,62,0,3,0,204,0,0,0,
|
||||
85,1,0,0,249,0,2,0,77,1,0,0,248,0,2,0,77,1,0,0,249,0,2,0,
|
||||
213,0,0,0,248,0,2,0,213,0,0,0,61,0,4,0,7,0,0,0,87,1,0,0,
|
||||
198,0,0,0,62,0,3,0,86,1,0,0,87,1,0,0,61,0,4,0,7,0,0,0,
|
||||
90,1,0,0,89,1,0,0,62,0,3,0,88,1,0,0,90,1,0,0,65,0,6,0,
|
||||
19,0,0,0,91,1,0,0,48,0,0,0,57,0,0,0,18,0,0,0,61,0,4,0,
|
||||
6,0,0,0,92,1,0,0,91,1,0,0,186,0,5,0,62,0,0,0,93,1,0,0,
|
||||
92,1,0,0,210,0,0,0,247,0,3,0,95,1,0,0,0,0,0,0,250,0,4,0,
|
||||
93,1,0,0,94,1,0,0,95,1,0,0,248,0,2,0,94,1,0,0,61,0,4,0,
|
||||
7,0,0,0,97,1,0,0,198,0,0,0,62,0,3,0,96,1,0,0,97,1,0,0,
|
||||
65,0,6,0,8,0,0,0,99,1,0,0,48,0,0,0,85,0,0,0,56,0,0,0,
|
||||
61,0,4,0,7,0,0,0,100,1,0,0,99,1,0,0,62,0,3,0,98,1,0,0,
|
||||
100,1,0,0,65,0,6,0,8,0,0,0,102,1,0,0,48,0,0,0,85,0,0,0,
|
||||
85,0,0,0,61,0,4,0,7,0,0,0,103,1,0,0,102,1,0,0,62,0,3,0,
|
||||
101,1,0,0,103,1,0,0,65,0,6,0,8,0,0,0,105,1,0,0,48,0,0,0,
|
||||
85,0,0,0,88,0,0,0,61,0,4,0,7,0,0,0,106,1,0,0,105,1,0,0,
|
||||
62,0,3,0,104,1,0,0,106,1,0,0,65,0,6,0,8,0,0,0,108,1,0,0,
|
||||
48,0,0,0,85,0,0,0,91,0,0,0,61,0,4,0,7,0,0,0,109,1,0,0,
|
||||
108,1,0,0,62,0,3,0,107,1,0,0,109,1,0,0,57,0,9,0,7,0,0,0,
|
||||
110,1,0,0,15,0,0,0,96,1,0,0,98,1,0,0,101,1,0,0,104,1,0,0,
|
||||
107,1,0,0,62,0,3,0,86,1,0,0,110,1,0,0,65,0,5,0,8,0,0,0,
|
||||
111,1,0,0,48,0,0,0,88,0,0,0,61,0,4,0,7,0,0,0,112,1,0,0,
|
||||
111,1,0,0,61,0,4,0,7,0,0,0,113,1,0,0,88,1,0,0,133,0,5,0,
|
||||
7,0,0,0,114,1,0,0,113,1,0,0,112,1,0,0,62,0,3,0,88,1,0,0,
|
||||
114,1,0,0,65,0,6,0,19,0,0,0,115,1,0,0,48,0,0,0,57,0,0,0,
|
||||
24,0,0,0,61,0,4,0,6,0,0,0,116,1,0,0,115,1,0,0,186,0,5,0,
|
||||
62,0,0,0,117,1,0,0,116,1,0,0,210,0,0,0,247,0,3,0,119,1,0,0,
|
||||
0,0,0,0,250,0,4,0,117,1,0,0,118,1,0,0,119,1,0,0,248,0,2,0,
|
||||
118,1,0,0,65,0,5,0,231,0,0,0,120,1,0,0,205,0,0,0,36,0,0,0,
|
||||
61,0,4,0,6,0,0,0,121,1,0,0,120,1,0,0,186,0,5,0,62,0,0,0,
|
||||
122,1,0,0,121,1,0,0,210,0,0,0,249,0,2,0,119,1,0,0,248,0,2,0,
|
||||
119,1,0,0,245,0,7,0,62,0,0,0,123,1,0,0,117,1,0,0,94,1,0,0,
|
||||
122,1,0,0,118,1,0,0,247,0,3,0,125,1,0,0,0,0,0,0,250,0,4,0,
|
||||
123,1,0,0,124,1,0,0,125,1,0,0,248,0,2,0,124,1,0,0,61,0,4,0,
|
||||
202,0,0,0,127,1,0,0,204,0,0,0,81,0,5,0,6,0,0,0,128,1,0,0,
|
||||
127,1,0,0,0,0,0,0,81,0,5,0,6,0,0,0,129,1,0,0,127,1,0,0,
|
||||
1,0,0,0,81,0,5,0,6,0,0,0,130,1,0,0,127,1,0,0,2,0,0,0,
|
||||
80,0,7,0,7,0,0,0,131,1,0,0,128,1,0,0,129,1,0,0,130,1,0,0,
|
||||
215,0,0,0,62,0,3,0,132,1,0,0,131,1,0,0,65,0,6,0,8,0,0,0,
|
||||
134,1,0,0,48,0,0,0,56,0,0,0,56,0,0,0,61,0,4,0,7,0,0,0,
|
||||
135,1,0,0,134,1,0,0,62,0,3,0,133,1,0,0,135,1,0,0,65,0,6,0,
|
||||
8,0,0,0,137,1,0,0,48,0,0,0,56,0,0,0,85,0,0,0,61,0,4,0,
|
||||
7,0,0,0,138,1,0,0,137,1,0,0,62,0,3,0,136,1,0,0,138,1,0,0,
|
||||
65,0,6,0,8,0,0,0,140,1,0,0,48,0,0,0,56,0,0,0,88,0,0,0,
|
||||
61,0,4,0,7,0,0,0,141,1,0,0,140,1,0,0,62,0,3,0,139,1,0,0,
|
||||
141,1,0,0,65,0,6,0,8,0,0,0,143,1,0,0,48,0,0,0,56,0,0,0,
|
||||
91,0,0,0,61,0,4,0,7,0,0,0,144,1,0,0,143,1,0,0,62,0,3,0,
|
||||
142,1,0,0,144,1,0,0,57,0,9,0,7,0,0,0,145,1,0,0,15,0,0,0,
|
||||
132,1,0,0,133,1,0,0,136,1,0,0,139,1,0,0,142,1,0,0,79,0,8,0,
|
||||
202,0,0,0,146,1,0,0,145,1,0,0,145,1,0,0,0,0,0,0,1,0,0,0,
|
||||
2,0,0,0,62,0,3,0,126,1,0,0,146,1,0,0,61,0,4,0,202,0,0,0,
|
||||
148,1,0,0,126,1,0,0,12,0,6,0,6,0,0,0,149,1,0,0,1,0,0,0,
|
||||
66,0,0,0,148,1,0,0,62,0,3,0,147,1,0,0,149,1,0,0,61,0,4,0,
|
||||
6,0,0,0,150,1,0,0,147,1,0,0,186,0,5,0,62,0,0,0,152,1,0,0,
|
||||
150,1,0,0,151,1,0,0,247,0,3,0,154,1,0,0,0,0,0,0,250,0,4,0,
|
||||
152,1,0,0,153,1,0,0,154,1,0,0,248,0,2,0,153,1,0,0,61,0,4,0,
|
||||
6,0,0,0,155,1,0,0,147,1,0,0,61,0,4,0,202,0,0,0,156,1,0,0,
|
||||
126,1,0,0,80,0,6,0,202,0,0,0,157,1,0,0,155,1,0,0,155,1,0,0,
|
||||
155,1,0,0,136,0,5,0,202,0,0,0,158,1,0,0,156,1,0,0,157,1,0,0,
|
||||
62,0,3,0,126,1,0,0,158,1,0,0,249,0,2,0,154,1,0,0,248,0,2,0,
|
||||
154,1,0,0,61,0,4,0,202,0,0,0,160,1,0,0,126,1,0,0,65,0,5,0,
|
||||
8,0,0,0,161,1,0,0,48,0,0,0,111,0,0,0,61,0,4,0,7,0,0,0,
|
||||
162,1,0,0,161,1,0,0,79,0,8,0,202,0,0,0,163,1,0,0,162,1,0,0,
|
||||
162,1,0,0,0,0,0,0,1,0,0,0,2,0,0,0,148,0,5,0,6,0,0,0,
|
||||
164,1,0,0,160,1,0,0,163,1,0,0,12,0,7,0,6,0,0,0,165,1,0,0,
|
||||
1,0,0,0,40,0,0,0,215,0,0,0,164,1,0,0,62,0,3,0,159,1,0,0,
|
||||
165,1,0,0,65,0,5,0,8,0,0,0,166,1,0,0,48,0,0,0,108,0,0,0,
|
||||
61,0,4,0,7,0,0,0,167,1,0,0,166,1,0,0,79,0,8,0,202,0,0,0,
|
||||
168,1,0,0,167,1,0,0,167,1,0,0,0,0,0,0,1,0,0,0,2,0,0,0,
|
||||
65,0,5,0,8,0,0,0,169,1,0,0,48,0,0,0,91,0,0,0,61,0,4,0,
|
||||
7,0,0,0,170,1,0,0,169,1,0,0,79,0,8,0,202,0,0,0,171,1,0,0,
|
||||
170,1,0,0,170,1,0,0,0,0,0,0,1,0,0,0,2,0,0,0,65,0,5,0,
|
||||
8,0,0,0,172,1,0,0,48,0,0,0,114,0,0,0,61,0,4,0,7,0,0,0,
|
||||
173,1,0,0,172,1,0,0,79,0,8,0,202,0,0,0,174,1,0,0,173,1,0,0,
|
||||
173,1,0,0,0,0,0,0,1,0,0,0,2,0,0,0,133,0,5,0,202,0,0,0,
|
||||
175,1,0,0,171,1,0,0,174,1,0,0,129,0,5,0,202,0,0,0,176,1,0,0,
|
||||
168,1,0,0,175,1,0,0,61,0,4,0,7,0,0,0,177,1,0,0,88,1,0,0,
|
||||
79,0,8,0,202,0,0,0,178,1,0,0,177,1,0,0,177,1,0,0,0,0,0,0,
|
||||
1,0,0,0,2,0,0,0,65,0,5,0,8,0,0,0,179,1,0,0,48,0,0,0,
|
||||
117,0,0,0,61,0,4,0,7,0,0,0,180,1,0,0,179,1,0,0,79,0,8,0,
|
||||
202,0,0,0,181,1,0,0,180,1,0,0,180,1,0,0,0,0,0,0,1,0,0,0,
|
||||
2,0,0,0,133,0,5,0,202,0,0,0,182,1,0,0,178,1,0,0,181,1,0,0,
|
||||
61,0,4,0,6,0,0,0,183,1,0,0,159,1,0,0,142,0,5,0,202,0,0,0,
|
||||
184,1,0,0,182,1,0,0,183,1,0,0,129,0,5,0,202,0,0,0,185,1,0,0,
|
||||
176,1,0,0,184,1,0,0,80,0,6,0,202,0,0,0,186,1,0,0,215,0,0,0,
|
||||
215,0,0,0,215,0,0,0,80,0,6,0,202,0,0,0,187,1,0,0,80,1,0,0,
|
||||
80,1,0,0,80,1,0,0,12,0,8,0,202,0,0,0,188,1,0,0,1,0,0,0,
|
||||
43,0,0,0,185,1,0,0,186,1,0,0,187,1,0,0,65,0,5,0,19,0,0,0,
|
||||
189,1,0,0,88,1,0,0,18,0,0,0,81,0,5,0,6,0,0,0,190,1,0,0,
|
||||
188,1,0,0,0,0,0,0,62,0,3,0,189,1,0,0,190,1,0,0,65,0,5,0,
|
||||
19,0,0,0,191,1,0,0,88,1,0,0,24,0,0,0,81,0,5,0,6,0,0,0,
|
||||
192,1,0,0,188,1,0,0,1,0,0,0,62,0,3,0,191,1,0,0,192,1,0,0,
|
||||
65,0,5,0,19,0,0,0,193,1,0,0,88,1,0,0,30,0,0,0,81,0,5,0,
|
||||
6,0,0,0,194,1,0,0,188,1,0,0,2,0,0,0,62,0,3,0,193,1,0,0,
|
||||
194,1,0,0,249,0,2,0,125,1,0,0,248,0,2,0,125,1,0,0,65,0,6,0,
|
||||
19,0,0,0,195,1,0,0,48,0,0,0,57,0,0,0,30,0,0,0,61,0,4,0,
|
||||
6,0,0,0,196,1,0,0,195,1,0,0,186,0,5,0,62,0,0,0,197,1,0,0,
|
||||
196,1,0,0,210,0,0,0,247,0,3,0,199,1,0,0,0,0,0,0,250,0,4,0,
|
||||
197,1,0,0,198,1,0,0,199,1,0,0,248,0,2,0,198,1,0,0,65,0,5,0,
|
||||
19,0,0,0,200,1,0,0,86,1,0,0,36,0,0,0,61,0,4,0,6,0,0,0,
|
||||
201,1,0,0,200,1,0,0,186,0,5,0,62,0,0,0,202,1,0,0,201,1,0,0,
|
||||
215,0,0,0,249,0,2,0,199,1,0,0,248,0,2,0,199,1,0,0,245,0,7,0,
|
||||
62,0,0,0,203,1,0,0,197,1,0,0,125,1,0,0,202,1,0,0,198,1,0,0,
|
||||
247,0,3,0,205,1,0,0,0,0,0,0,250,0,4,0,203,1,0,0,204,1,0,0,
|
||||
205,1,0,0,248,0,2,0,204,1,0,0,65,0,6,0,19,0,0,0,207,1,0,0,
|
||||
48,0,0,0,57,0,0,0,30,0,0,0,61,0,4,0,6,0,0,0,208,1,0,0,
|
||||
207,1,0,0,186,0,5,0,62,0,0,0,209,1,0,0,208,1,0,0,61,0,0,0,
|
||||
247,0,3,0,212,1,0,0,0,0,0,0,250,0,4,0,209,1,0,0,211,1,0,0,
|
||||
222,1,0,0,248,0,2,0,211,1,0,0,65,0,5,0,19,0,0,0,213,1,0,0,
|
||||
86,1,0,0,36,0,0,0,61,0,4,0,6,0,0,0,214,1,0,0,213,1,0,0,
|
||||
65,0,6,0,19,0,0,0,215,1,0,0,48,0,0,0,123,0,0,0,18,0,0,0,
|
||||
61,0,4,0,6,0,0,0,216,1,0,0,215,1,0,0,133,0,5,0,6,0,0,0,
|
||||
217,1,0,0,214,1,0,0,216,1,0,0,12,0,8,0,6,0,0,0,219,1,0,0,
|
||||
1,0,0,0,43,0,0,0,217,1,0,0,215,0,0,0,218,1,0,0,127,0,4,0,
|
||||
6,0,0,0,220,1,0,0,219,1,0,0,12,0,6,0,6,0,0,0,221,1,0,0,
|
||||
1,0,0,0,27,0,0,0,220,1,0,0,62,0,3,0,210,1,0,0,221,1,0,0,
|
||||
249,0,2,0,212,1,0,0,248,0,2,0,222,1,0,0,65,0,6,0,19,0,0,0,
|
||||
223,1,0,0,48,0,0,0,123,0,0,0,30,0,0,0,61,0,4,0,6,0,0,0,
|
||||
224,1,0,0,223,1,0,0,65,0,5,0,19,0,0,0,225,1,0,0,86,1,0,0,
|
||||
36,0,0,0,61,0,4,0,6,0,0,0,226,1,0,0,225,1,0,0,131,0,5,0,
|
||||
6,0,0,0,227,1,0,0,224,1,0,0,226,1,0,0,65,0,6,0,19,0,0,0,
|
||||
228,1,0,0,48,0,0,0,123,0,0,0,30,0,0,0,61,0,4,0,6,0,0,0,
|
||||
229,1,0,0,228,1,0,0,65,0,6,0,19,0,0,0,230,1,0,0,48,0,0,0,
|
||||
123,0,0,0,24,0,0,0,61,0,4,0,6,0,0,0,231,1,0,0,230,1,0,0,
|
||||
131,0,5,0,6,0,0,0,232,1,0,0,229,1,0,0,231,1,0,0,136,0,5,0,
|
||||
6,0,0,0,233,1,0,0,227,1,0,0,232,1,0,0,12,0,8,0,6,0,0,0,
|
||||
234,1,0,0,1,0,0,0,43,0,0,0,233,1,0,0,215,0,0,0,80,1,0,0,
|
||||
62,0,3,0,210,1,0,0,234,1,0,0,249,0,2,0,212,1,0,0,248,0,2,0,
|
||||
212,1,0,0,61,0,4,0,6,0,0,0,235,1,0,0,210,1,0,0,62,0,3,0,
|
||||
206,1,0,0,235,1,0,0,65,0,5,0,8,0,0,0,236,1,0,0,48,0,0,0,
|
||||
120,0,0,0,61,0,4,0,7,0,0,0,237,1,0,0,236,1,0,0,79,0,8,0,
|
||||
202,0,0,0,238,1,0,0,237,1,0,0,237,1,0,0,0,0,0,0,1,0,0,0,
|
||||
2,0,0,0,61,0,4,0,7,0,0,0,239,1,0,0,88,1,0,0,79,0,8,0,
|
||||
202,0,0,0,240,1,0,0,239,1,0,0,239,1,0,0,0,0,0,0,1,0,0,0,
|
||||
2,0,0,0,61,0,4,0,6,0,0,0,241,1,0,0,206,1,0,0,80,0,6,0,
|
||||
202,0,0,0,242,1,0,0,241,1,0,0,241,1,0,0,241,1,0,0,12,0,8,0,
|
||||
202,0,0,0,243,1,0,0,1,0,0,0,46,0,0,0,238,1,0,0,240,1,0,0,
|
||||
242,1,0,0,65,0,5,0,19,0,0,0,244,1,0,0,88,1,0,0,18,0,0,0,
|
||||
81,0,5,0,6,0,0,0,245,1,0,0,243,1,0,0,0,0,0,0,62,0,3,0,
|
||||
244,1,0,0,245,1,0,0,65,0,5,0,19,0,0,0,246,1,0,0,88,1,0,0,
|
||||
24,0,0,0,81,0,5,0,6,0,0,0,247,1,0,0,243,1,0,0,1,0,0,0,
|
||||
62,0,3,0,246,1,0,0,247,1,0,0,65,0,5,0,19,0,0,0,248,1,0,0,
|
||||
88,1,0,0,30,0,0,0,81,0,5,0,6,0,0,0,249,1,0,0,243,1,0,0,
|
||||
2,0,0,0,62,0,3,0,248,1,0,0,249,1,0,0,249,0,2,0,205,1,0,0,
|
||||
248,0,2,0,205,1,0,0,65,0,6,0,19,0,0,0,250,1,0,0,48,0,0,0,
|
||||
57,0,0,0,36,0,0,0,61,0,4,0,6,0,0,0,251,1,0,0,250,1,0,0,
|
||||
186,0,5,0,62,0,0,0,252,1,0,0,251,1,0,0,210,0,0,0,247,0,3,0,
|
||||
254,1,0,0,0,0,0,0,250,0,4,0,252,1,0,0,253,1,0,0,254,1,0,0,
|
||||
248,0,2,0,253,1,0,0,65,0,5,0,19,0,0,0,255,1,0,0,86,1,0,0,
|
||||
30,0,0,0,62,0,3,0,255,1,0,0,215,0,0,0,249,0,2,0,254,1,0,0,
|
||||
248,0,2,0,254,1,0,0,249,0,2,0,95,1,0,0,248,0,2,0,95,1,0,0,
|
||||
61,0,4,0,7,0,0,0,4,2,0,0,86,1,0,0,65,0,5,0,5,2,0,0,
|
||||
6,2,0,0,3,2,0,0,56,0,0,0,62,0,3,0,6,2,0,0,4,2,0,0,
|
||||
61,0,4,0,7,0,0,0,8,2,0,0,88,1,0,0,62,0,3,0,7,2,0,0,
|
||||
8,2,0,0,61,0,4,0,9,2,0,0,14,2,0,0,13,2,0,0,62,0,3,0,
|
||||
11,2,0,0,14,2,0,0,253,0,1,0,56,0,1,0,54,0,5,0,7,0,0,0,
|
||||
15,0,0,0,0,0,0,0,9,0,0,0,55,0,3,0,8,0,0,0,10,0,0,0,
|
||||
55,0,3,0,8,0,0,0,11,0,0,0,55,0,3,0,8,0,0,0,12,0,0,0,
|
||||
55,0,3,0,8,0,0,0,13,0,0,0,55,0,3,0,8,0,0,0,14,0,0,0,
|
||||
248,0,2,0,16,0,0,0,65,0,5,0,19,0,0,0,20,0,0,0,10,0,0,0,
|
||||
18,0,0,0,61,0,4,0,6,0,0,0,21,0,0,0,20,0,0,0,61,0,4,0,
|
||||
7,0,0,0,22,0,0,0,11,0,0,0,142,0,5,0,7,0,0,0,23,0,0,0,
|
||||
22,0,0,0,21,0,0,0,65,0,5,0,19,0,0,0,25,0,0,0,10,0,0,0,
|
||||
24,0,0,0,61,0,4,0,6,0,0,0,26,0,0,0,25,0,0,0,61,0,4,0,
|
||||
7,0,0,0,27,0,0,0,12,0,0,0,142,0,5,0,7,0,0,0,28,0,0,0,
|
||||
27,0,0,0,26,0,0,0,129,0,5,0,7,0,0,0,29,0,0,0,23,0,0,0,
|
||||
28,0,0,0,65,0,5,0,19,0,0,0,31,0,0,0,10,0,0,0,30,0,0,0,
|
||||
61,0,4,0,6,0,0,0,32,0,0,0,31,0,0,0,61,0,4,0,7,0,0,0,
|
||||
33,0,0,0,13,0,0,0,142,0,5,0,7,0,0,0,34,0,0,0,33,0,0,0,
|
||||
32,0,0,0,129,0,5,0,7,0,0,0,35,0,0,0,29,0,0,0,34,0,0,0,
|
||||
65,0,5,0,19,0,0,0,37,0,0,0,10,0,0,0,36,0,0,0,61,0,4,0,
|
||||
6,0,0,0,38,0,0,0,37,0,0,0,61,0,4,0,7,0,0,0,39,0,0,0,
|
||||
14,0,0,0,142,0,5,0,7,0,0,0,40,0,0,0,39,0,0,0,38,0,0,0,
|
||||
129,0,5,0,7,0,0,0,41,0,0,0,35,0,0,0,40,0,0,0,254,0,2,0,
|
||||
41,0,0,0,56,0,1,0,
|
||||
};
|
||||
alignas(4) inline constexpr unsigned char scene_frag_spv[] = {
|
||||
3,2,35,7,0,0,1,0,11,0,13,0,62,0,0,0,0,0,0,0,17,0,2,0,
|
||||
1,0,0,0,11,0,6,0,1,0,0,0,71,76,83,76,46,115,116,100,46,52,53,48,
|
||||
0,0,0,0,14,0,3,0,0,0,0,0,1,0,0,0,15,0,8,0,4,0,0,0,
|
||||
4,0,0,0,109,97,105,110,0,0,0,0,17,0,0,0,21,0,0,0,60,0,0,0,
|
||||
16,0,3,0,4,0,0,0,7,0,0,0,3,0,3,0,2,0,0,0,194,1,0,0,
|
||||
4,0,10,0,71,76,95,71,79,79,71,76,69,95,99,112,112,95,115,116,121,108,101,95,
|
||||
108,105,110,101,95,100,105,114,101,99,116,105,118,101,0,0,4,0,8,0,71,76,95,71,
|
||||
79,79,71,76,69,95,105,110,99,108,117,100,101,95,100,105,114,101,99,116,105,118,101,0,
|
||||
5,0,4,0,4,0,0,0,109,97,105,110,0,0,0,0,5,0,3,0,9,0,0,0,
|
||||
99,0,0,0,5,0,4,0,13,0,0,0,105,109,97,103,101,0,0,0,5,0,3,0,
|
||||
17,0,0,0,118,117,118,0,5,0,4,0,21,0,0,0,118,99,111,108,111,114,0,0,
|
||||
5,0,5,0,25,0,0,0,77,97,116,101,114,105,97,108,0,0,0,0,6,0,5,0,
|
||||
25,0,0,0,0,0,0,0,112,97,114,97,109,115,0,0,5,0,3,0,27,0,0,0,
|
||||
0,0,0,0,5,0,4,0,60,0,0,0,114,101,115,117,108,116,0,0,71,0,4,0,
|
||||
13,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,13,0,0,0,34,0,0,0,
|
||||
2,0,0,0,71,0,4,0,17,0,0,0,30,0,0,0,1,0,0,0,71,0,4,0,
|
||||
21,0,0,0,30,0,0,0,0,0,0,0,71,0,3,0,25,0,0,0,2,0,0,0,
|
||||
72,0,5,0,25,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,71,0,4,0,
|
||||
27,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,27,0,0,0,34,0,0,0,
|
||||
3,0,0,0,71,0,4,0,60,0,0,0,30,0,0,0,0,0,0,0,19,0,2,0,
|
||||
2,0,0,0,33,0,3,0,3,0,0,0,2,0,0,0,22,0,3,0,6,0,0,0,
|
||||
32,0,0,0,23,0,4,0,7,0,0,0,6,0,0,0,4,0,0,0,32,0,4,0,
|
||||
8,0,0,0,7,0,0,0,7,0,0,0,25,0,9,0,10,0,0,0,6,0,0,0,
|
||||
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,
|
||||
27,0,3,0,11,0,0,0,10,0,0,0,32,0,4,0,12,0,0,0,0,0,0,0,
|
||||
11,0,0,0,59,0,4,0,12,0,0,0,13,0,0,0,0,0,0,0,23,0,4,0,
|
||||
15,0,0,0,6,0,0,0,2,0,0,0,32,0,4,0,16,0,0,0,1,0,0,0,
|
||||
15,0,0,0,59,0,4,0,16,0,0,0,17,0,0,0,1,0,0,0,32,0,4,0,
|
||||
20,0,0,0,1,0,0,0,7,0,0,0,59,0,4,0,20,0,0,0,21,0,0,0,
|
||||
1,0,0,0,20,0,2,0,24,0,0,0,30,0,3,0,25,0,0,0,7,0,0,0,
|
||||
32,0,4,0,26,0,0,0,2,0,0,0,25,0,0,0,59,0,4,0,26,0,0,0,
|
||||
27,0,0,0,2,0,0,0,21,0,4,0,28,0,0,0,32,0,0,0,1,0,0,0,
|
||||
43,0,4,0,28,0,0,0,29,0,0,0,0,0,0,0,21,0,4,0,30,0,0,0,
|
||||
32,0,0,0,0,0,0,0,43,0,4,0,30,0,0,0,31,0,0,0,0,0,0,0,
|
||||
32,0,4,0,32,0,0,0,2,0,0,0,6,0,0,0,43,0,4,0,6,0,0,0,
|
||||
35,0,0,0,0,0,0,0,43,0,4,0,30,0,0,0,39,0,0,0,3,0,0,0,
|
||||
32,0,4,0,40,0,0,0,7,0,0,0,6,0,0,0,43,0,4,0,30,0,0,0,
|
||||
50,0,0,0,1,0,0,0,43,0,4,0,6,0,0,0,53,0,0,0,0,0,0,63,
|
||||
43,0,4,0,6,0,0,0,57,0,0,0,0,0,128,63,32,0,4,0,59,0,0,0,
|
||||
3,0,0,0,7,0,0,0,59,0,4,0,59,0,0,0,60,0,0,0,3,0,0,0,
|
||||
54,0,5,0,2,0,0,0,4,0,0,0,0,0,0,0,3,0,0,0,248,0,2,0,
|
||||
5,0,0,0,59,0,4,0,8,0,0,0,9,0,0,0,7,0,0,0,61,0,4,0,
|
||||
11,0,0,0,14,0,0,0,13,0,0,0,61,0,4,0,15,0,0,0,18,0,0,0,
|
||||
17,0,0,0,87,0,5,0,7,0,0,0,19,0,0,0,14,0,0,0,18,0,0,0,
|
||||
61,0,4,0,7,0,0,0,22,0,0,0,21,0,0,0,133,0,5,0,7,0,0,0,
|
||||
23,0,0,0,19,0,0,0,22,0,0,0,62,0,3,0,9,0,0,0,23,0,0,0,
|
||||
65,0,6,0,32,0,0,0,33,0,0,0,27,0,0,0,29,0,0,0,31,0,0,0,
|
||||
61,0,4,0,6,0,0,0,34,0,0,0,33,0,0,0,190,0,5,0,24,0,0,0,
|
||||
36,0,0,0,34,0,0,0,35,0,0,0,247,0,3,0,38,0,0,0,0,0,0,0,
|
||||
250,0,4,0,36,0,0,0,37,0,0,0,38,0,0,0,248,0,2,0,37,0,0,0,
|
||||
65,0,5,0,40,0,0,0,41,0,0,0,9,0,0,0,39,0,0,0,61,0,4,0,
|
||||
6,0,0,0,42,0,0,0,41,0,0,0,65,0,6,0,32,0,0,0,43,0,0,0,
|
||||
27,0,0,0,29,0,0,0,31,0,0,0,61,0,4,0,6,0,0,0,44,0,0,0,
|
||||
43,0,0,0,188,0,5,0,24,0,0,0,45,0,0,0,42,0,0,0,44,0,0,0,
|
||||
249,0,2,0,38,0,0,0,248,0,2,0,38,0,0,0,245,0,7,0,24,0,0,0,
|
||||
46,0,0,0,36,0,0,0,5,0,0,0,45,0,0,0,37,0,0,0,247,0,3,0,
|
||||
48,0,0,0,0,0,0,0,250,0,4,0,46,0,0,0,47,0,0,0,48,0,0,0,
|
||||
248,0,2,0,47,0,0,0,252,0,1,0,248,0,2,0,48,0,0,0,65,0,6,0,
|
||||
32,0,0,0,51,0,0,0,27,0,0,0,29,0,0,0,50,0,0,0,61,0,4,0,
|
||||
6,0,0,0,52,0,0,0,51,0,0,0,186,0,5,0,24,0,0,0,54,0,0,0,
|
||||
52,0,0,0,53,0,0,0,247,0,3,0,56,0,0,0,0,0,0,0,250,0,4,0,
|
||||
54,0,0,0,55,0,0,0,56,0,0,0,248,0,2,0,55,0,0,0,65,0,5,0,
|
||||
40,0,0,0,58,0,0,0,9,0,0,0,39,0,0,0,62,0,3,0,58,0,0,0,
|
||||
57,0,0,0,249,0,2,0,56,0,0,0,248,0,2,0,56,0,0,0,61,0,4,0,
|
||||
7,0,0,0,61,0,0,0,9,0,0,0,62,0,3,0,60,0,0,0,61,0,0,0,
|
||||
253,0,1,0,56,0,1,0,
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
#version 450
|
||||
layout(set=2,binding=0) uniform sampler2D image;
|
||||
layout(set=3,binding=0) uniform Material { vec4 params; };
|
||||
layout(location=0) in vec4 vcolor;
|
||||
layout(location=1) in vec2 vuv;
|
||||
layout(location=0) out vec4 result;
|
||||
void main(){ vec4 c=texture(image,vuv)*vcolor; if(params.x>=0.0 && c.a<=params.x) discard; if(params.y>0.5) c.a=1.0; result=c; }
|
||||
@@ -0,0 +1,50 @@
|
||||
#version 450
|
||||
layout(location=0) in vec4 position;
|
||||
layout(location=1) in vec4 color;
|
||||
layout(location=2) in vec2 uv;
|
||||
layout(location=3) in vec4 normal;
|
||||
layout(location=4) in uvec4 bones;
|
||||
layout(location=5) in vec4 weights;
|
||||
struct Transform {
|
||||
vec4 world[4]; vec4 mvp[4];
|
||||
vec4 diffuse; vec4 ambient; vec4 emissive;
|
||||
vec4 lightDirection; vec4 lightAmbient; vec4 lightDiffuse;
|
||||
vec4 fogColor; vec4 fogParams; vec4 modes; vec4 skin;
|
||||
};
|
||||
layout(set=1,binding=0,std140) uniform Header { Transform header; };
|
||||
layout(set=1,binding=1,std140) uniform Palette { vec4 palette[512]; };
|
||||
layout(set=0,binding=0,std140) readonly buffer Instances { Transform instances[]; };
|
||||
layout(location=0) out vec4 vcolor;
|
||||
layout(location=1) out vec2 vuv;
|
||||
vec4 transformRows(vec4 p, vec4 a,vec4 b,vec4 c,vec4 d){return p.x*a+p.y*b+p.z*c+p.w*d;}
|
||||
void main(){
|
||||
Transform t=header.modes.x>1.5 ? instances[gl_InstanceIndex] : header;
|
||||
vec4 p=position; vec3 n=normal.xyz;
|
||||
if(t.skin.x>0.5){
|
||||
vec4 skinned=vec4(0); vec3 sn=vec3(0); float total=0;
|
||||
for(int i=0;i<4;++i) if(weights[i]>0 && bones[i]<uint(t.skin.x)) {
|
||||
uint b=bones[i]*4; float w=weights[i];
|
||||
skinned+=transformRows(p,palette[b],palette[b+1],palette[b+2],palette[b+3])*w;
|
||||
sn+=transformRows(vec4(n,0),palette[b],palette[b+1],palette[b+2],palette[b+3]).xyz*w;
|
||||
total+=w;
|
||||
}
|
||||
if(total>0.0001){p=vec4(skinned.xyz,1);n=sn;}
|
||||
}
|
||||
vec4 clip=p; vec4 c=color;
|
||||
if(t.modes.x>0.5){
|
||||
clip=transformRows(p,t.mvp[0],t.mvp[1],t.mvp[2],t.mvp[3]);
|
||||
c*=t.diffuse;
|
||||
if(t.modes.y>0.5 && normal.w>0.5){
|
||||
vec3 wn=transformRows(vec4(n,0),t.world[0],t.world[1],t.world[2],t.world[3]).xyz;
|
||||
float len=length(wn);if(len>0.00001)wn/=len;
|
||||
float ndotl=max(0,dot(wn,t.lightDirection.xyz));
|
||||
c.rgb=clamp(t.emissive.rgb+t.ambient.rgb*t.lightAmbient.rgb+c.rgb*t.lightDiffuse.rgb*ndotl,0,1);
|
||||
}
|
||||
if(t.modes.z>0.5 && clip.w>0){
|
||||
float f=t.modes.z>1.5 ? exp(-clamp(clip.w*t.fogParams.x,0,10)) : clamp((t.fogParams.z-clip.w)/(t.fogParams.z-t.fogParams.y),0,1);
|
||||
c.rgb=mix(t.fogColor.rgb,c.rgb,f);
|
||||
}
|
||||
if(t.modes.w>0.5)clip.z=0;
|
||||
}
|
||||
gl_Position=clip;vcolor=c;vuv=uv;
|
||||
}
|
||||
@@ -120,9 +120,13 @@ public:
|
||||
if(!s_resourceRoot.empty()) {
|
||||
auto relative=candidates;
|
||||
candidates.clear();
|
||||
for(const auto& candidate:relative) {
|
||||
std::vector<std::filesystem::path> roots{s_resourceRoot};
|
||||
if (s_resourceRoot.filename() == "root") roots.push_back(s_resourceRoot.parent_path());
|
||||
if (s_resourceRoot.filename() == "python-root") roots.push_back(s_resourceRoot.parent_path().parent_path());
|
||||
for (const auto& root : roots) for (const auto& candidate : relative) {
|
||||
std::filesystem::path rel(candidate);
|
||||
if(!rel.is_absolute()&&candidate.find(':')==std::string::npos) candidates.push_back((s_resourceRoot/rel).string());
|
||||
if (!rel.is_absolute() && candidate.find(':') == std::string::npos)
|
||||
candidates.push_back((root / rel).string());
|
||||
}
|
||||
candidates.insert(candidates.end(),relative.begin(),relative.end());
|
||||
}
|
||||
|
||||
@@ -136,11 +136,11 @@ std::string SoundManager::ResolveAudioPath(const std::string& filename) const {
|
||||
"sound/" + clean,
|
||||
"bgm/" + clean,
|
||||
"BGM/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Sound/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/BGM/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/ETC/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/Sound/sound/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/TEST/1. Client DEV/pack_maker/BGM/bgm/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/1. Client DEV/pack_maker/Sound/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/1. Client DEV/pack_maker/BGM/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/1. Client DEV/pack_maker/ETC/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/1. Client DEV/pack_maker/Sound/sound/" + clean,
|
||||
"/Users/shen/Work/Code/Metin2/AVA2/1. Client DEV/pack_maker/BGM/bgm/" + clean,
|
||||
"build/dev/" + clean
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
#include "Font.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#ifdef AVA2_HAS_FREETYPE
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#endif
|
||||
|
||||
namespace UI {
|
||||
namespace {
|
||||
std::vector<unsigned> Codepoints(const std::string& text) {
|
||||
std::vector<unsigned> out;
|
||||
for (size_t i = 0; i < text.size();) {
|
||||
unsigned c = static_cast<unsigned char>(text[i++]);
|
||||
int n = c >= 0xf0 && c <= 0xf4 ? 3 : c >= 0xe0 && c < 0xf0 ? 2 : c >= 0xc2 && c < 0xe0 ? 1 : 0;
|
||||
unsigned value = n ? c & ((1u << (6 - n)) - 1) : c;
|
||||
size_t end = i;
|
||||
for (int j = 0; j < n && end < text.size() && (static_cast<unsigned char>(text[end]) & 0xc0) == 0x80; ++j)
|
||||
value = (value << 6) | (static_cast<unsigned char>(text[end++]) & 0x3f);
|
||||
if (end - i == static_cast<size_t>(n)) { i = end; c = value; }
|
||||
// Some legacy labels include a trailing NUL; SDL's debug font hid it.
|
||||
if (c >= 32 && c != 127) out.push_back(c);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
#ifdef AVA2_HAS_FREETYPE
|
||||
struct Glyph {
|
||||
int width = 0, height = 0, left = 0, top = 0;
|
||||
float advance = 0;
|
||||
std::vector<Uint8> alpha;
|
||||
};
|
||||
struct FontCache {
|
||||
FT_Library library = nullptr;
|
||||
FT_Face face = nullptr;
|
||||
std::map<std::pair<int, unsigned>, Glyph> glyphs;
|
||||
FontCache() {
|
||||
if (FT_Init_FreeType(&library)) return;
|
||||
// User-supplied / packaged fonts take precedence over platform fonts.
|
||||
std::vector<std::string> paths;
|
||||
if (const char* path = std::getenv("AVA2_UI_FONT")) paths.emplace_back(path);
|
||||
paths.insert(paths.end(), {"fonts/Arial.ttf", "fonts/DejaVuSans.ttf",
|
||||
"/System/Library/Fonts/Supplemental/Arial.ttf", "C:/Windows/Fonts/arial.ttf",
|
||||
"/system/fonts/Roboto-Regular.ttf", "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"});
|
||||
for (const auto& path : paths)
|
||||
if (!FT_New_Face(library, path.c_str(), 0, &face)) break;
|
||||
}
|
||||
~FontCache() { if (face) FT_Done_Face(face); if (library) FT_Done_FreeType(library); }
|
||||
const Glyph& Get(int size, unsigned code) {
|
||||
auto key = std::make_pair(size, code);
|
||||
auto it = glyphs.find(key);
|
||||
if (it != glyphs.end()) return it->second;
|
||||
Glyph g;
|
||||
// Rasterize at 2x; SDL downsamples to logical size and keeps Retina text sharp.
|
||||
FT_Set_Pixel_Sizes(face, 0, size * 2);
|
||||
if (!FT_Load_Char(face, code, FT_LOAD_RENDER)) {
|
||||
const auto& b = face->glyph->bitmap;
|
||||
g.width = b.width; g.height = b.rows;
|
||||
g.left = face->glyph->bitmap_left; g.top = face->glyph->bitmap_top;
|
||||
g.advance = face->glyph->advance.x / 128.0f;
|
||||
g.alpha.resize(g.width * g.height);
|
||||
for (int y = 0; y < g.height; ++y)
|
||||
std::copy_n(b.buffer + y * b.pitch, g.width, g.alpha.data() + y * g.width);
|
||||
}
|
||||
return glyphs.emplace(key, std::move(g)).first->second;
|
||||
}
|
||||
};
|
||||
FontCache& Cache() { static FontCache cache; return cache; }
|
||||
|
||||
// Cache white text masks, then tint at draw time. Destroying a texture after every
|
||||
// label forces SDL to flush its pending GPU batch, including the entire 3D scene.
|
||||
struct TextTexture {
|
||||
SDL_Texture* texture = nullptr;
|
||||
int width = 0, height = 0;
|
||||
size_t bytes = 0;
|
||||
std::list<std::string>::iterator recent;
|
||||
};
|
||||
struct TextTextures {
|
||||
std::unordered_map<std::string, TextTexture> entries;
|
||||
std::list<std::string> recent;
|
||||
size_t bytes = 0;
|
||||
};
|
||||
constexpr const char* TEXT_CACHE_PROPERTY = "ava2.font.textures";
|
||||
TextTextures& TextureCache(SDL_Renderer* renderer) {
|
||||
auto props = SDL_GetRendererProperties(renderer);
|
||||
auto* cache = static_cast<TextTextures*>(SDL_GetPointerProperty(props, TEXT_CACHE_PROPERTY, nullptr));
|
||||
if (!cache) {
|
||||
cache = new TextTextures;
|
||||
// SDL owns renderer textures and destroys them with the renderer. This
|
||||
// callback only releases metadata, so renderer teardown cannot double-free.
|
||||
SDL_SetPointerPropertyWithCleanup(props, TEXT_CACHE_PROPERTY, cache,
|
||||
[](void*, void* value) { delete static_cast<TextTextures*>(value); }, nullptr);
|
||||
}
|
||||
return *cache;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int TextFontSize(const std::string& name) {
|
||||
const auto colon = name.find(':');
|
||||
const int size = colon == std::string::npos ? 12 : std::atoi(name.c_str() + colon + 1);
|
||||
return std::clamp(size, 8, 48);
|
||||
}
|
||||
|
||||
float MeasureText(const std::string& text, int size) {
|
||||
float width = 0;
|
||||
for (unsigned code : Codepoints(text)) {
|
||||
#ifdef AVA2_HAS_FREETYPE
|
||||
if (Cache().face) { width += Cache().Get(size, code).advance; continue; }
|
||||
#endif
|
||||
width += size * 0.5f;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
void DrawText(SDL_Renderer* renderer, const std::string& text, int size, float x, float y, Uint32 color) {
|
||||
if (!renderer || text.empty()) return;
|
||||
#ifdef AVA2_HAS_FREETYPE
|
||||
if (Cache().face) {
|
||||
auto& cache = TextureCache(renderer);
|
||||
const std::string key = std::to_string(size) + ":" + text;
|
||||
auto found = cache.entries.find(key);
|
||||
if (found != cache.entries.end()) {
|
||||
cache.recent.splice(cache.recent.begin(), cache.recent, found->second.recent);
|
||||
auto& item = found->second;
|
||||
SDL_SetTextureColorMod(item.texture, (color >> 16) & 255, (color >> 8) & 255, color & 255);
|
||||
SDL_SetTextureAlphaMod(item.texture, color >> 24);
|
||||
SDL_FRect dest{x, y, item.width / 2.0f, item.height / 2.0f};
|
||||
SDL_RenderTexture(renderer, item.texture, nullptr, &dest);
|
||||
return;
|
||||
}
|
||||
const int width = std::max(1, int(std::ceil(MeasureText(text, size) * 2)) + size * 2);
|
||||
const int height = size * 3;
|
||||
SDL_Surface* surface = SDL_CreateSurface(width, height, SDL_PIXELFORMAT_ARGB8888);
|
||||
if (!surface) return;
|
||||
SDL_FillSurfaceRect(surface, nullptr, 0);
|
||||
float pen = 0;
|
||||
for (unsigned code : Codepoints(text)) {
|
||||
const auto& glyph = Cache().Get(size, code);
|
||||
const int gx = int(std::round(pen * 2)) + glyph.left;
|
||||
const int gy = size * 2 - glyph.top;
|
||||
for (int row = 0; row < glyph.height; ++row) {
|
||||
const int sy = gy + row;
|
||||
if (sy < 0 || sy >= height) continue;
|
||||
auto* pixels = reinterpret_cast<Uint32*>(static_cast<Uint8*>(surface->pixels) + sy * surface->pitch);
|
||||
for (int col = 0; col < glyph.width; ++col) {
|
||||
const int sx = gx + col;
|
||||
if (sx < 0 || sx >= width) continue;
|
||||
const unsigned alpha = glyph.alpha[row * glyph.width + col];
|
||||
if (alpha) pixels[sx] = (std::max(alpha, pixels[sx] >> 24) << 24) | 0xffffff;
|
||||
}
|
||||
}
|
||||
pen += glyph.advance;
|
||||
}
|
||||
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
SDL_DestroySurface(surface);
|
||||
if (texture) {
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_LINEAR);
|
||||
const size_t bytes = size_t(width) * height * 4;
|
||||
while (!cache.entries.empty() && (cache.entries.size() >= 512 || cache.bytes + bytes > 16 * 1024 * 1024)) {
|
||||
auto old = cache.entries.find(cache.recent.back());
|
||||
cache.bytes -= old->second.bytes;
|
||||
SDL_DestroyTexture(old->second.texture);
|
||||
cache.entries.erase(old);
|
||||
cache.recent.pop_back();
|
||||
}
|
||||
cache.recent.push_front(key);
|
||||
cache.entries.emplace(key, TextTexture{texture, width, height, bytes, cache.recent.begin()});
|
||||
cache.bytes += bytes;
|
||||
SDL_SetTextureColorMod(texture, (color >> 16) & 255, (color >> 8) & 255, color & 255);
|
||||
SDL_SetTextureAlphaMod(texture, color >> 24);
|
||||
SDL_FRect dest{x, y, width / 2.0f, height / 2.0f};
|
||||
SDL_RenderTexture(renderer, texture, nullptr, &dest);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// Keep fallback glyph advances consistent with MeasureText on SDKs without FreeType.
|
||||
float sx = 1, sy = 1;
|
||||
SDL_GetRenderScale(renderer, &sx, &sy);
|
||||
const float scale = size / 16.0f;
|
||||
SDL_SetRenderScale(renderer, sx * scale, sy * scale);
|
||||
SDL_SetRenderDrawColor(renderer, (color >> 16) & 255, (color >> 8) & 255, color & 255, color >> 24);
|
||||
SDL_RenderDebugText(renderer, x / scale, y / scale, text.c_str());
|
||||
SDL_SetRenderScale(renderer, sx, sy);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
#include <string>
|
||||
|
||||
namespace UI {
|
||||
// Shared measurement and rendering metrics in logical pixels (independent of Retina scale).
|
||||
int TextFontSize(const std::string& name);
|
||||
float MeasureText(const std::string& text, int size);
|
||||
void DrawText(SDL_Renderer* renderer, const std::string& text, int size,
|
||||
float x, float y, Uint32 color);
|
||||
}
|
||||
+153
-31
@@ -337,10 +337,24 @@ namespace UI
|
||||
|
||||
CWindow * CWindow::PickWindow(long x, long y)
|
||||
{
|
||||
if (!IsShow()) return nullptr;
|
||||
|
||||
for (auto it = m_pChildList.rbegin(); it != m_pChildList.rend(); ++it)
|
||||
{
|
||||
CWindow * pWin = (*it)->PickWindow(x, y);
|
||||
if (pWin) return pWin;
|
||||
CWindow * pWin = *it;
|
||||
if (pWin->IsShow())
|
||||
{
|
||||
if (!pWin->IsFlag(CWindow::FLAG_IGNORE_SIZE))
|
||||
{
|
||||
if (!pWin->IsIn(x, y)) {
|
||||
if (0L <= pWin->GetWidth()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
CWindow * pResult = pWin->PickWindow(x, y);
|
||||
if (pResult) return pResult;
|
||||
}
|
||||
}
|
||||
if (IsFlag(FLAG_NOT_PICK)) return nullptr;
|
||||
if (IsIn(x, y)) return this;
|
||||
@@ -406,9 +420,38 @@ namespace UI
|
||||
if (m_poHandler) PyCallClassMemberFunc(m_poHandler, "OnMoveWindow", Py_BuildValue("(ii)", x, y));
|
||||
}
|
||||
|
||||
BOOL CWindow::RunIMETabEvent() { return OnIMETabEvent(); }
|
||||
BOOL CWindow::RunIMEReturnEvent() { return OnIMEReturnEvent(); }
|
||||
BOOL CWindow::RunIMEKeyDownEvent(int ikey) { return OnIMEKeyDownEvent(ikey); }
|
||||
BOOL CWindow::RunIMETabEvent()
|
||||
{
|
||||
if (!IsRendering()) return FALSE;
|
||||
if (OnIMETabEvent()) return TRUE;
|
||||
for (auto itor = m_pChildList.rbegin(); itor != m_pChildList.rend(); ++itor)
|
||||
{
|
||||
if ((*itor)->RunIMETabEvent()) return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::RunIMEReturnEvent()
|
||||
{
|
||||
if (!IsRendering()) return FALSE;
|
||||
if (OnIMEReturnEvent()) return TRUE;
|
||||
for (auto itor = m_pChildList.rbegin(); itor != m_pChildList.rend(); ++itor)
|
||||
{
|
||||
if ((*itor)->RunIMEReturnEvent()) return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::RunIMEKeyDownEvent(int ikey)
|
||||
{
|
||||
if (!IsRendering()) return FALSE;
|
||||
if (OnIMEKeyDownEvent(ikey)) return TRUE;
|
||||
for (auto itor = m_pChildList.rbegin(); itor != m_pChildList.rend(); ++itor)
|
||||
{
|
||||
if ((*itor)->RunIMEKeyDownEvent(ikey)) return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
CWindow * CWindow::RunKeyDownEvent(int ikey)
|
||||
{
|
||||
@@ -431,17 +474,99 @@ namespace UI
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::RunPressEscapeKeyEvent() { return OnPressEscapeKey(); }
|
||||
BOOL CWindow::RunPressExitKeyEvent() { return OnPressExitKey(); }
|
||||
BOOL CWindow::RunPressEscapeKeyEvent()
|
||||
{
|
||||
for (auto itor = m_pChildList.rbegin(); itor != m_pChildList.rend(); ++itor)
|
||||
{
|
||||
CWindow * pWindow = *itor;
|
||||
if (pWindow->IsShow() && pWindow->RunPressEscapeKeyEvent())
|
||||
return TRUE;
|
||||
}
|
||||
return OnPressEscapeKey();
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMETabEvent() { return FALSE; }
|
||||
BOOL CWindow::OnIMEReturnEvent() { return FALSE; }
|
||||
BOOL CWindow::OnIMEKeyDownEvent(int ikey) { return FALSE; }
|
||||
BOOL CWindow::OnIMEChangeCodePage() { return FALSE; }
|
||||
BOOL CWindow::OnIMEOpenCandidateListEvent() { return FALSE; }
|
||||
BOOL CWindow::OnIMECloseCandidateListEvent() { return FALSE; }
|
||||
BOOL CWindow::OnIMEOpenReadingWndEvent() { return FALSE; }
|
||||
BOOL CWindow::OnIMECloseReadingWndEvent() { return FALSE; }
|
||||
BOOL CWindow::RunPressExitKeyEvent()
|
||||
{
|
||||
for (auto itor = m_pChildList.rbegin(); itor != m_pChildList.rend(); ++itor)
|
||||
{
|
||||
CWindow * pWindow = *itor;
|
||||
if (pWindow->IsShow() && pWindow->RunPressExitKeyEvent())
|
||||
return TRUE;
|
||||
}
|
||||
return OnPressExitKey();
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMETabEvent()
|
||||
{
|
||||
if (!m_poHandler) return FALSE;
|
||||
long lValue = 0;
|
||||
if (PyCallClassMemberFunc(m_poHandler, "OnIMETab", BuildEmptyTuple(), &lValue))
|
||||
if (0 != lValue) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMEReturnEvent()
|
||||
{
|
||||
if (!m_poHandler) return FALSE;
|
||||
long lValue = 0;
|
||||
if (PyCallClassMemberFunc(m_poHandler, "OnIMEReturn", BuildEmptyTuple(), &lValue))
|
||||
if (0 != lValue) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMEKeyDownEvent(int ikey)
|
||||
{
|
||||
if (!m_poHandler) return FALSE;
|
||||
long lValue = 0;
|
||||
if (PyCallClassMemberFunc(m_poHandler, "OnIMEKeyDown", Py_BuildValue("(i)", ikey), &lValue))
|
||||
if (0 != lValue) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMEChangeCodePage()
|
||||
{
|
||||
if (!m_poHandler) return FALSE;
|
||||
long lValue = 0;
|
||||
if (PyCallClassMemberFunc(m_poHandler, "OnIMEChangeCodePage", BuildEmptyTuple(), &lValue))
|
||||
if (0 != lValue) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMEOpenCandidateListEvent()
|
||||
{
|
||||
if (!m_poHandler) return FALSE;
|
||||
long lValue = 0;
|
||||
if (PyCallClassMemberFunc(m_poHandler, "OnIMEOpenCandidateList", BuildEmptyTuple(), &lValue))
|
||||
if (0 != lValue) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMECloseCandidateListEvent()
|
||||
{
|
||||
if (!m_poHandler) return FALSE;
|
||||
long lValue = 0;
|
||||
if (PyCallClassMemberFunc(m_poHandler, "OnIMECloseCandidateList", BuildEmptyTuple(), &lValue))
|
||||
if (0 != lValue) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMEOpenReadingWndEvent()
|
||||
{
|
||||
if (!m_poHandler) return FALSE;
|
||||
long lValue = 0;
|
||||
if (PyCallClassMemberFunc(m_poHandler, "OnIMEOpenReadingWnd", BuildEmptyTuple(), &lValue))
|
||||
if (0 != lValue) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::OnIMECloseReadingWndEvent()
|
||||
{
|
||||
if (!m_poHandler) return FALSE;
|
||||
long lValue = 0;
|
||||
if (PyCallClassMemberFunc(m_poHandler, "OnIMECloseReadingWnd", BuildEmptyTuple(), &lValue))
|
||||
if (0 != lValue) return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CWindow::OnMouseLeftButtonDown()
|
||||
{
|
||||
@@ -664,9 +789,10 @@ namespace UI
|
||||
if (displayText.empty() && !m_showCursor)
|
||||
return;
|
||||
|
||||
const float charWidth = 8.0f;
|
||||
const float charHeight = 8.0f;
|
||||
float textWidth = static_cast<float>(displayText.length()) * charWidth;
|
||||
const int fontSize = TextFontSize(m_font);
|
||||
const float charWidth = MeasureText("*", fontSize);
|
||||
const float charHeight = float(fontSize);
|
||||
float textWidth = MeasureText(displayText, fontSize);
|
||||
float textHeight = charHeight;
|
||||
|
||||
float startX = m_v2Position.x;
|
||||
@@ -709,29 +835,25 @@ namespace UI
|
||||
}
|
||||
|
||||
uint8_t a = (m_color >> 24) & 0xff;
|
||||
uint8_t r = (m_color >> 16) & 0xff;
|
||||
uint8_t g = (m_color >> 8) & 0xff;
|
||||
uint8_t b = m_color & 0xff;
|
||||
if (a == 0 && m_color != 0) a = 255;
|
||||
if (a == 0) return;
|
||||
|
||||
if (m_outline && !displayText.empty())
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, a);
|
||||
SDL_RenderDebugText(renderer, startX - 1.0f, startY, displayText.c_str());
|
||||
SDL_RenderDebugText(renderer, startX + 1.0f, startY, displayText.c_str());
|
||||
SDL_RenderDebugText(renderer, startX, startY - 1.0f, displayText.c_str());
|
||||
SDL_RenderDebugText(renderer, startX, startY + 1.0f, displayText.c_str());
|
||||
const DWORD outline = (m_outlineColor & 0xffffff) | (DWORD(a) << 24);
|
||||
DrawText(renderer, displayText, fontSize, startX - 1, startY, outline);
|
||||
DrawText(renderer, displayText, fontSize, startX + 1, startY, outline);
|
||||
DrawText(renderer, displayText, fontSize, startX, startY - 1, outline);
|
||||
DrawText(renderer, displayText, fontSize, startX, startY + 1, outline);
|
||||
}
|
||||
|
||||
if (!displayText.empty())
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
SDL_RenderDebugText(renderer, startX, startY, displayText.c_str());
|
||||
DrawText(renderer, displayText, fontSize, startX, startY, m_color);
|
||||
}
|
||||
|
||||
if (m_showCursor)
|
||||
{
|
||||
float cursorX = startX + static_cast<float>(displayText.length()) * charWidth;
|
||||
float cursorX = startX + textWidth;
|
||||
SDL_SetRenderDrawColor(renderer, 240, 240, 240, 255);
|
||||
SDL_FRect cursorRect{ cursorX + 1.0f, startY, 2.0f, charHeight + 2.0f };
|
||||
SDL_RenderFillRect(renderer, &cursorRect);
|
||||
@@ -1559,7 +1681,7 @@ namespace UI
|
||||
{
|
||||
if (!m_bEnable) return FALSE;
|
||||
m_isPressed = FALSE;
|
||||
SetUp();
|
||||
Up();
|
||||
if (m_poHandler) PyCallClassMemberFunc(m_poHandler, "CallEvent", BuildEmptyTuple());
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "src/eter_image/GrpExpandedImageInstance.h"
|
||||
#include "src/eter_image/GrpMarkInstance.h"
|
||||
#include "src/eter_resource/ResourceManager.h"
|
||||
#include "Font.h"
|
||||
|
||||
namespace UI
|
||||
{
|
||||
@@ -63,8 +64,9 @@ namespace UI
|
||||
void HideCursor() { m_showCursor = false; }
|
||||
int GetCursorPosition() const { return (int)m_text.length(); }
|
||||
void GetTextSize(int* w, int* h) {
|
||||
if (w) *w = (int)m_text.length() * 6;
|
||||
if (h) *h = 12;
|
||||
const int size = TextFontSize(m_font);
|
||||
if (w) *w = int(std::ceil(MeasureText(m_secret ? std::string(m_text.length(), '*') : m_text, size)));
|
||||
if (h) *h = size;
|
||||
}
|
||||
void SetOutLineColor(float r, float g, float b, float a) {
|
||||
auto c = [](float v) { return DWORD(std::clamp(v, 0.0f, 1.0f) * 255.0f + 0.5f); };
|
||||
@@ -72,8 +74,9 @@ namespace UI
|
||||
}
|
||||
int PixelPositionToCharacterPosition(int pixelPos) const {
|
||||
if (pixelPos <= 0) return 0;
|
||||
int charPos = pixelPos / 6;
|
||||
return std::min<int>(charPos, (int)m_text.length());
|
||||
for (size_t i = 0; i < m_text.size(); ++i)
|
||||
if (MeasureText(m_text.substr(0, i + 1), TextFontSize(m_font)) > pixelPos) return int(i);
|
||||
return int(m_text.size());
|
||||
}
|
||||
void SetPosition(float fx, float fy) { m_v2Position.x = fx; m_v2Position.y = fy; }
|
||||
D3DXVECTOR2 GetPosition() const { return m_v2Position; }
|
||||
|
||||
@@ -368,13 +368,17 @@ namespace UI
|
||||
void CWindowManager::RunMouseLeftButtonDown(long x, long y)
|
||||
{
|
||||
SetMousePosition(x, y);
|
||||
CWindow * pWin = GetPointWindow();
|
||||
CWindow * pWin = __PickWindow(m_lMouseX, m_lMouseY);
|
||||
|
||||
if (!pWin) pWin = GetPointWindow();
|
||||
if (!pWin) return;
|
||||
m_pPointWindow = pWin;
|
||||
|
||||
if (pWin->IsFlag(CWindow::FLAG_ATTACH)) pWin = pWin->GetRoot();
|
||||
if (!pWin->IsFlag(CWindow::FLAG_NOT_CAPTURE)) m_pLeftCaptureWindow = pWin;
|
||||
|
||||
m_lDragX = m_lMouseX - pWin->GetPositionX();
|
||||
m_lDragY = m_lMouseY - pWin->GetPositionY();
|
||||
m_lDragX = m_lMouseX - pWin->GetRect().left;
|
||||
m_lDragY = m_lMouseY - pWin->GetRect().top;
|
||||
pWin->OnMouseLeftButtonDown();
|
||||
}
|
||||
|
||||
@@ -383,15 +387,31 @@ namespace UI
|
||||
SetMousePosition(x, y);
|
||||
if (m_pLeftCaptureWindow)
|
||||
{
|
||||
m_pLeftCaptureWindow->OnMouseLeftButtonUp();
|
||||
if (m_pLeftCaptureWindow->OnMouseLeftButtonUp())
|
||||
{
|
||||
m_pLeftCaptureWindow = nullptr;
|
||||
return;
|
||||
}
|
||||
m_pLeftCaptureWindow = nullptr;
|
||||
}
|
||||
|
||||
CWindow * pWin = __PickWindow(m_lMouseX, m_lMouseY);
|
||||
printf("DEBUG RunMouseLeftButtonUp: pos=(%ld, %ld) m_lMouse=(%ld, %ld) picked=%s\n", x, y, m_lMouseX, m_lMouseY, pWin ? pWin->GetName() : "null");
|
||||
if (!pWin) pWin = GetPointWindow();
|
||||
if (pWin)
|
||||
{
|
||||
pWin->OnMouseLeftButtonUp();
|
||||
}
|
||||
|
||||
m_pLeftCaptureWindow = nullptr;
|
||||
}
|
||||
|
||||
void CWindowManager::RunMouseLeftButtonDoubleClick(long x, long y)
|
||||
{
|
||||
SetMousePosition(x, y);
|
||||
if (m_pPointWindow) m_pPointWindow->OnMouseLeftButtonDoubleClick();
|
||||
CWindow * pWin = __PickWindow(m_lMouseX, m_lMouseY);
|
||||
if (!pWin) pWin = GetPointWindow();
|
||||
if (pWin) pWin->OnMouseLeftButtonDoubleClick();
|
||||
}
|
||||
|
||||
void CWindowManager::RunMouseRightButtonDown(long x, long y)
|
||||
@@ -501,4 +521,118 @@ namespace UI
|
||||
{
|
||||
if (m_pRootWindow) m_pRootWindow->RunPressExitKeyEvent();
|
||||
}
|
||||
|
||||
void CWindowManager::RunIMEUpdate()
|
||||
{
|
||||
if (m_pLockWindow)
|
||||
{
|
||||
m_pLockWindow->OnIMEUpdate();
|
||||
return;
|
||||
}
|
||||
if (!m_pActiveWindow || !m_pActiveWindow->IsRendering())
|
||||
return;
|
||||
m_pActiveWindow->OnIMEUpdate();
|
||||
}
|
||||
|
||||
void CWindowManager::RunIMETabEvent()
|
||||
{
|
||||
if (m_pLockWindow)
|
||||
{
|
||||
m_pLockWindow->OnIMETabEvent();
|
||||
return;
|
||||
}
|
||||
if (m_pActiveWindow && m_pActiveWindow->IsRendering())
|
||||
{
|
||||
if (m_pActiveWindow->OnIMETabEvent())
|
||||
return;
|
||||
}
|
||||
if (m_pRootWindow && !m_pRootWindow->RunIMETabEvent())
|
||||
{
|
||||
if (!m_ActiveWindowList.empty())
|
||||
{
|
||||
CWindow * pWindow = *(m_ActiveWindowList.begin());
|
||||
ActivateWindow(pWindow);
|
||||
|
||||
CWindow * pParentWindow = pWindow;
|
||||
CWindow * pCurrentWindow = pWindow->GetParent();
|
||||
|
||||
for (DWORD i = 0; i < 20; ++i)
|
||||
{
|
||||
if (!pParentWindow) break;
|
||||
auto it = m_LayerWindowMap.find("GAME");
|
||||
if (it != m_LayerWindowMap.end() && pParentWindow == it->second)
|
||||
{
|
||||
SetTop(pCurrentWindow);
|
||||
break;
|
||||
}
|
||||
pCurrentWindow = pParentWindow;
|
||||
pParentWindow = pCurrentWindow->GetParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CWindowManager::RunIMEReturnEvent()
|
||||
{
|
||||
if (m_pLockWindow)
|
||||
{
|
||||
m_pLockWindow->OnIMEReturnEvent();
|
||||
return;
|
||||
}
|
||||
if (m_pActiveWindow && m_pActiveWindow->IsRendering())
|
||||
{
|
||||
if (m_pActiveWindow->OnIMEReturnEvent())
|
||||
return;
|
||||
}
|
||||
if (m_pRootWindow)
|
||||
m_pRootWindow->RunIMEReturnEvent();
|
||||
}
|
||||
|
||||
void CWindowManager::RunIMEKeyDown(int vkey)
|
||||
{
|
||||
if (m_pLockWindow)
|
||||
{
|
||||
m_pLockWindow->OnKeyDown(vkey);
|
||||
return;
|
||||
}
|
||||
if (m_pActiveWindow && m_pActiveWindow->IsRendering())
|
||||
{
|
||||
if (m_pActiveWindow->OnIMEKeyDownEvent(vkey))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void CWindowManager::RunChangeCodePage()
|
||||
{
|
||||
if (m_pActiveWindow && m_pActiveWindow->IsRendering())
|
||||
m_pActiveWindow->OnIMEChangeCodePage();
|
||||
}
|
||||
|
||||
void CWindowManager::RunOpenCandidate()
|
||||
{
|
||||
if (m_pLockWindow) { m_pLockWindow->OnIMEOpenCandidateListEvent(); return; }
|
||||
if (m_pActiveWindow && m_pActiveWindow->IsRendering())
|
||||
m_pActiveWindow->OnIMEOpenCandidateListEvent();
|
||||
}
|
||||
|
||||
void CWindowManager::RunCloseCandidate()
|
||||
{
|
||||
if (m_pLockWindow) { m_pLockWindow->OnIMECloseCandidateListEvent(); return; }
|
||||
if (m_pActiveWindow && m_pActiveWindow->IsRendering())
|
||||
m_pActiveWindow->OnIMECloseCandidateListEvent();
|
||||
}
|
||||
|
||||
void CWindowManager::RunOpenReading()
|
||||
{
|
||||
if (m_pLockWindow) { m_pLockWindow->OnIMEOpenReadingWndEvent(); return; }
|
||||
if (m_pActiveWindow && m_pActiveWindow->IsRendering())
|
||||
m_pActiveWindow->OnIMEOpenReadingWndEvent();
|
||||
}
|
||||
|
||||
void CWindowManager::RunCloseReading()
|
||||
{
|
||||
if (m_pLockWindow) { m_pLockWindow->OnIMECloseReadingWndEvent(); return; }
|
||||
if (m_pActiveWindow && m_pActiveWindow->IsRendering())
|
||||
m_pActiveWindow->OnIMECloseReadingWndEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,15 @@ namespace UI
|
||||
void RunKeyUp(int vkey);
|
||||
void RunPressEscapeKey();
|
||||
void RunPressExitKey();
|
||||
void RunIMEUpdate();
|
||||
void RunIMETabEvent();
|
||||
void RunIMEReturnEvent();
|
||||
void RunIMEKeyDown(int vkey);
|
||||
void RunChangeCodePage();
|
||||
void RunOpenCandidate();
|
||||
void RunCloseCandidate();
|
||||
void RunOpenReading();
|
||||
void RunCloseReading();
|
||||
|
||||
private:
|
||||
void SetMousePosition(long x, long y);
|
||||
|
||||
+10
-3
@@ -126,10 +126,17 @@ void LoginClient::pump() {
|
||||
if(on_game_ && session_->handshake_phase_entered() && !handshake_notified_) { handshake_notified_=true;if(!direct_enter_) notify(EventType::Handshake); }
|
||||
if(on_game_ && session_->game_login_sent() && !login_notified_) { login_notified_=true;if(!direct_enter_) notify(EventType::LoginStart); }
|
||||
if(session_->state()==LoginSession::State::Selecting && !selection_notified_) {
|
||||
selection_notified_=true;status_=Status::Selecting;notify(direct_enter_?EventType::DirectEnterReady:EventType::SelectReady);
|
||||
selection_notified_=true;status_=Status::Selecting;
|
||||
if(direct_enter_) {
|
||||
select(direct_enter_slot_);
|
||||
// Do not notify DirectEnterReady here before the server actually transitions to Loading!
|
||||
} else {
|
||||
notify(EventType::SelectReady);
|
||||
}
|
||||
}
|
||||
if(session_->state()==LoginSession::State::Loading && !loading_notified_) {
|
||||
loading_notified_=true;status_=Status::Loading;notify(EventType::Loading);return;
|
||||
loading_notified_=true;status_=Status::Loading;
|
||||
notify(EventType::Loading);return;
|
||||
}
|
||||
flush();if(status_==Status::Failed) return;
|
||||
}
|
||||
@@ -149,7 +156,7 @@ void LoginClient::direct_enter(std::uint8_t slot) {
|
||||
if(!character.address || !character.port || !inet_ntop(AF_INET,&address,host,sizeof(host)))
|
||||
throw std::invalid_argument("character server endpoint is missing");
|
||||
session_->reconnect_game();
|
||||
direct_enter_=true;handshake_notified_=false;login_notified_=selection_notified_=loading_notified_=false;
|
||||
direct_enter_=true;direct_enter_slot_=slot;handshake_notified_=false;login_notified_=selection_notified_=loading_notified_=false;
|
||||
deadline_=std::chrono::steady_clock::now()+std::chrono::seconds(15);
|
||||
start_endpoint({host,character.port});
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ private:
|
||||
std::shared_ptr<Resolution> resolution_;
|
||||
Endpoint game_;
|
||||
bool direct_enter_=false;
|
||||
std::uint8_t direct_enter_slot_=0;
|
||||
bool handshake_notified_=false;
|
||||
bool on_game_=false, login_notified_=false, selection_notified_=false, loading_notified_=false;
|
||||
std::uint64_t generation_=0;
|
||||
|
||||
+14
-5
@@ -24,11 +24,11 @@ void LoginSession::clear_password() { volatile char* p=password_.empty()?nullptr
|
||||
void LoginSession::fail(std::string reason) { failure_=std::move(reason); state_=State::Failed; clear_password(); output_.clear(); }
|
||||
void LoginSession::begin_game() {
|
||||
if(state_!=State::Authenticated) throw std::logic_error("game connection requires successful authentication");
|
||||
game_=true; handshake_phase_entered_=false; encrypted_=false; sequence_=0; raw_.clear(); plain_.clear(); output_.clear(); tx_=rx_=locale_key(); state_=State::Handshake;
|
||||
game_=true; server_clock_ready_=false; handshake_phase_entered_=false; encrypted_=false; sequence_=0; raw_.clear(); plain_.clear(); output_.clear(); tx_=rx_=locale_key(); state_=State::Handshake;
|
||||
}
|
||||
void LoginSession::reconnect_game() {
|
||||
if(state_!=State::Selecting) throw std::logic_error("DirectEnter requires a selected account session");
|
||||
handshake_phase_entered_=false;encrypted_=false; sequence_=0; raw_.clear(); plain_.clear(); output_.clear();
|
||||
server_clock_ready_=false;handshake_phase_entered_=false;encrypted_=false; sequence_=0; raw_.clear(); plain_.clear(); output_.clear();
|
||||
tx_=rx_=locale_key(); state_=State::Handshake;
|
||||
roster_received_=select_phase_received_=game_login_sent_=false;
|
||||
}
|
||||
@@ -52,7 +52,9 @@ void LoginSession::feed(std::span<const std::uint8_t> input) {
|
||||
}
|
||||
bool LoginSession::process_packet() {
|
||||
if(plain_.empty() || state_==State::Loading) return false;
|
||||
auto header=plain_[0]; std::size_t size=0;
|
||||
auto header=plain_[0];
|
||||
if(plain_.empty() || state_==State::Loading) return false;
|
||||
std::size_t size=0;
|
||||
switch(header) {
|
||||
case 0:size=1;break; case 253:size=2;break; case 255:size=13;break; case 44:size=1;break;
|
||||
case 254:size=7;break; // legacy UDP binding, not used by this TCP bootstrap
|
||||
@@ -64,7 +66,13 @@ bool LoginSession::process_packet() {
|
||||
break;
|
||||
case 150:size=6;break; case 7:size=10;break; case 90:size=2;break;
|
||||
case 32:size=444;break; // 5 * (70-byte player + 4-byte guild id + 13-byte guild name) + 9
|
||||
default:fail("unsupported login packet header "+std::to_string(header));return false;
|
||||
default:
|
||||
if(state_==State::Entering) {
|
||||
state_=State::Loading;
|
||||
return false;
|
||||
}
|
||||
fail("unsupported login packet header "+std::to_string(header));
|
||||
return false;
|
||||
}
|
||||
if(plain_.size()<size) return false;
|
||||
Bytes packet(plain_.begin(),plain_.begin()+size); plain_.erase(plain_.begin(),plain_.begin()+size);
|
||||
@@ -77,6 +85,7 @@ bool LoginSession::process_packet() {
|
||||
}
|
||||
if(header==255) {
|
||||
auto time=read32(packet,5),delta=read32(packet,9);
|
||||
server_clock_base_=time+delta;server_clock_received_=std::chrono::steady_clock::now();server_clock_ready_=true;
|
||||
Bytes reply{255};append32(reply,read32(packet,1));append32(reply,time+delta+delta);append32(reply,0);emit(std::move(reply),false);
|
||||
} else if(header==44) { emit({254},encrypted_); }
|
||||
else if(header==7) { fail(string_at(packet,1,9)); }
|
||||
@@ -93,7 +102,7 @@ bool LoginSession::process_packet() {
|
||||
Bytes login{109};text(login,account_,30);append32(login,login_key_);for(auto v:client_key_) append32(login,v);
|
||||
emit(std::move(login),true);tx_=client_key_;rx_=receive_key_;
|
||||
} else if(phase==3 && game_ && state_==State::LoggingIn) { select_phase_received_=true; if(roster_received_) state_=State::Selecting; }
|
||||
else if(phase==4 && game_ && state_==State::Entering) { state_=State::Loading; }
|
||||
else if((phase==4 || phase==5) && game_ && state_==State::Entering) { state_=State::Loading; }
|
||||
else { fail("unexpected login phase "+std::to_string(phase)); }
|
||||
} else if(header==150) {
|
||||
if(game_ || state_!=State::Authenticating) fail("authentication result in wrong state");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "legacy_cipher.h"
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
namespace ava2 {
|
||||
struct Character {
|
||||
@@ -35,6 +36,13 @@ public:
|
||||
const std::vector<Character>& characters() const { return characters_; }
|
||||
bool handshake_phase_entered() const { return handshake_phase_entered_; }
|
||||
bool game_login_sent() const { return game_login_sent_; }
|
||||
// Game bootstrap owns the first handshake before native Game-phase processing.
|
||||
bool server_milliseconds(std::uint32_t& value) const {
|
||||
if(!game_ || !server_clock_ready_) return false;
|
||||
value=server_clock_base_+std::uint32_t(std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now()-server_clock_received_).count());
|
||||
return true;
|
||||
}
|
||||
std::uint8_t empire() const { return empire_; }
|
||||
std::uint32_t login_key() const { return login_key_; }
|
||||
private:
|
||||
@@ -44,6 +52,9 @@ private:
|
||||
void clear_password();
|
||||
State state_=State::Handshake;
|
||||
bool handshake_phase_entered_=false;
|
||||
bool server_clock_ready_=false;
|
||||
std::uint32_t server_clock_base_=0;
|
||||
std::chrono::steady_clock::time_point server_clock_received_;
|
||||
bool game_=false, encrypted_=false, roster_received_=false, select_phase_received_=false, game_login_sent_=false;
|
||||
std::uint8_t empire_=0;
|
||||
std::string account_,password_,failure_;
|
||||
|
||||
+566
-115
File diff suppressed because it is too large
Load Diff
@@ -9,11 +9,37 @@
|
||||
// read as EFFECT_* offsets) are kept: RegisterEffect rejects them exactly like Windows does.
|
||||
// Emoticon chat strings are the original CP949 bytes.
|
||||
#include "player_settings.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "item_sound.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
|
||||
namespace ava2 {
|
||||
void RegisterPlayerSkills(uint8_t race, uint8_t group, uint8_t empire) {
|
||||
// AVA2 PythonPlayerSettingsModule.h::m_vecSkillIndex, not the 40250
|
||||
// defaults: slot 9 is the ninth skill, horse slots start at 10 and the
|
||||
// support list has AVA2's inspiration/charisma/auto-attack entries.
|
||||
const unsigned job = race < 8 ? race % 4 : 4;
|
||||
if (job < 4 && (group == 1 || group == 2)) {
|
||||
const int first = int(job) * 30 + (group == 2 ? 16 : 1);
|
||||
for (int slot = 1; slot <= 6; ++slot) SetPlayerSkill(slot, first + slot - 1);
|
||||
// Slots 7 and 8 are assigned by RecvSkillLevelNew (ward / boost).
|
||||
const int ninth[4][2] = {{176,176}, {177,178}, {179,180}, {181,182}};
|
||||
SetPlayerSkill(9, ninth[job][group - 1]);
|
||||
const int horse[] = {137,0,138,0,139,0};
|
||||
for (int i = 0; i < 6; ++i) SetPlayerSkill(10 + i, horse[i]);
|
||||
if (job == 1) SetPlayerSkill(16, 140);
|
||||
const int support[] = {0,0,121,134,133,129,130,131,123,124,122,132,246};
|
||||
for (int i = 0; i < 13; ++i) SetPlayerSkill(101 + i, support[i]);
|
||||
}
|
||||
if (empire >= 1 && empire <= 3) {
|
||||
int slot = 101;
|
||||
for (int language = 1; language <= 3; ++language)
|
||||
if (language != empire) SetPlayerSkill(slot++, 125 + language);
|
||||
}
|
||||
SetPlayerSkill(200, 151);
|
||||
for (int i = 0; i < 6; ++i) SetPlayerSkill(210 + i, 152 + i);
|
||||
}
|
||||
namespace {
|
||||
struct TCacheEffect { unsigned type; const char* bone; const char* file; bool cache; };
|
||||
struct TEmoticon { unsigned type; const char* bone; const char* file; const char* chat; };
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
namespace ava2 {
|
||||
// CPythonPlayerSettingsModule effect / emoticon / item-sound registration (AVA2 app.Create).
|
||||
void LoadPlayerSettings();
|
||||
void RegisterPlayerSkills(uint8_t race, uint8_t group, uint8_t empire);
|
||||
}
|
||||
|
||||
+80
-13
@@ -21,6 +21,9 @@
|
||||
#include "eter_ui/PythonWindowManager.h"
|
||||
#include "eter_effect/EffectManager.h"
|
||||
#include "eter_effect/FlyingManager.h"
|
||||
#include "eter_render/TextTailManager.h"
|
||||
#include "eter_render/Gr2ModelRenderer.h"
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <Python.h>
|
||||
@@ -32,6 +35,8 @@
|
||||
#include <thread>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <SDL3/SDL.h>
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include "eter_resource/ResourceManager.h"
|
||||
|
||||
namespace ava2 {
|
||||
@@ -43,12 +48,14 @@ ServerClock server_clock(local_milliseconds());
|
||||
// EterBase Timer.cpp gs_dwServerTime / gs_dwClientTime (ELTimer_*ServerMSec), separate from app.GetGlobalTime.
|
||||
std::uint32_t elt_server_time=0,elt_client_time=0;
|
||||
auto app_start=std::chrono::steady_clock::now();
|
||||
bool s_cameraSettingPending = false;
|
||||
float s_camera_distance = 1500.0f;
|
||||
float s_camera_pitch = 30.0f;
|
||||
float s_camera_rotation = 0.0f;
|
||||
float s_camera_height = 180.0f;
|
||||
float s_camera_max_distance = 2500.0f;
|
||||
int s_camera_speed = 100;
|
||||
int cameraRotateInput=0, cameraPitchInput=0, cameraZoomInput=0;
|
||||
float s_camera_rotate_speed = 1.0f;
|
||||
float s_camera_pitch_speed = 1.0f;
|
||||
float s_camera_zoom_speed = 0.05f;
|
||||
@@ -79,6 +86,26 @@ PyObject* app_get_global_timestamp(PyObject*, PyObject*) {
|
||||
return PyInt_FromLong(server_clock.timestamp(unix_seconds()));
|
||||
}
|
||||
|
||||
static float s_centerX = 0.0f, s_centerY = 0.0f, s_centerZ = 0.0f;
|
||||
static void SyncCameraToRenderer() {
|
||||
auto* renderer3d = TextTailManager::Instance().GetCurrentSceneRenderer();
|
||||
if (!renderer3d) return;
|
||||
constexpr float DEG_TO_RAD = 3.14159265358979323846f / 180.0f;
|
||||
float pitchRad = s_camera_pitch * DEG_TO_RAD;
|
||||
float rotRad = s_camera_rotation * DEG_TO_RAD;
|
||||
float horiz = s_camera_distance * std::cos(pitchRad);
|
||||
float vert = s_camera_distance * std::sin(pitchRad);
|
||||
float targetX = s_centerX;
|
||||
float targetY = s_centerY + s_camera_height;
|
||||
float targetZ = s_centerZ;
|
||||
float eyeX = targetX - horiz * std::sin(rotRad);
|
||||
float eyeY = targetY + vert;
|
||||
// Windows starts at (0, -distance, 0) and rotates about native Z.
|
||||
// Native Y maps to -engine Z; CCamera also uses a RH view matrix.
|
||||
float eyeZ = targetZ + horiz * std::cos(rotRad);
|
||||
renderer3d->SetCameraLookAtRH(eyeX, eyeY, eyeZ, targetX, targetY, targetZ, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
PyObject* app_set_camera(PyObject*, PyObject* args) {
|
||||
float Distance = 0.0f, Pitch = 0.0f, Rotation = 0.0f, DestinationHeight = 0.0f;
|
||||
if (!PyTuple_GetFloat(args, 0, &Distance) ||
|
||||
@@ -91,6 +118,8 @@ PyObject* app_set_camera(PyObject*, PyObject* args) {
|
||||
s_camera_pitch = Pitch;
|
||||
s_camera_rotation = Rotation;
|
||||
s_camera_height = DestinationHeight;
|
||||
s_cameraSettingPending = true;
|
||||
SyncCameraToRenderer();
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -110,7 +139,7 @@ PyObject* app_rotate_camera(PyObject*, PyObject* args) {
|
||||
int iDirection = 0;
|
||||
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
||||
return Py_BuildException();
|
||||
s_camera_rotation += s_camera_rotate_speed * static_cast<float>(iDirection);
|
||||
cameraRotateInput = iDirection;
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -118,7 +147,7 @@ PyObject* app_pitch_camera(PyObject*, PyObject* args) {
|
||||
int iDirection = 0;
|
||||
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
||||
return Py_BuildException();
|
||||
s_camera_pitch += s_camera_pitch_speed * static_cast<float>(iDirection);
|
||||
cameraPitchInput = iDirection;
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -126,9 +155,7 @@ PyObject* app_zoom_camera(PyObject*, PyObject* args) {
|
||||
int iDirection = 0;
|
||||
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
||||
return Py_BuildException();
|
||||
s_camera_distance *= (1.0f + s_camera_zoom_speed * static_cast<float>(iDirection));
|
||||
if (s_camera_distance > s_camera_max_distance) s_camera_distance = s_camera_max_distance;
|
||||
if (s_camera_distance < 100.0f) s_camera_distance = 100.0f;
|
||||
cameraZoomInput = iDirection;
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -136,7 +163,7 @@ PyObject* app_movie_rotate_camera(PyObject*, PyObject* args) {
|
||||
int iDirection = 0;
|
||||
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
||||
return Py_BuildException();
|
||||
s_camera_rotation += s_camera_rotate_speed * static_cast<float>(iDirection);
|
||||
cameraRotateInput = iDirection;
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -144,7 +171,7 @@ PyObject* app_movie_pitch_camera(PyObject*, PyObject* args) {
|
||||
int iDirection = 0;
|
||||
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
||||
return Py_BuildException();
|
||||
s_camera_pitch += s_camera_pitch_speed * static_cast<float>(iDirection);
|
||||
cameraPitchInput = iDirection;
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -228,6 +255,7 @@ PyObject* app_set_default_camera(PyObject*, PyObject*) {
|
||||
s_camera_pitch = 30.0f;
|
||||
s_camera_rotation = 0.0f;
|
||||
s_camera_height = 180.0f;
|
||||
s_cameraSettingPending = true;
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -288,6 +316,7 @@ PyObject* app_get_cursor_position(PyObject*, PyObject*) {
|
||||
return Py_BuildValue("ii", lx, ly);
|
||||
}
|
||||
|
||||
static float gameFrameDelta = 0.033f;
|
||||
PyObject* app_update_game(PyObject*, PyObject*) {
|
||||
long lx = 0, ly = 0;
|
||||
UI::CWindowManager::Instance().GetMousePosition(lx, ly);
|
||||
@@ -299,7 +328,7 @@ PyObject* app_update_game(PyObject*, PyObject*) {
|
||||
camZ = static_cast<float>(mainActor->m_lCurZ);
|
||||
}
|
||||
CPythonBackground::Instance().Update(camX, camY, camZ);
|
||||
float dt = 0.033f;
|
||||
float dt = gameFrameDelta;
|
||||
NetworkActorManager::Instance().Update(dt, CPythonBackground::Instance().GetTerrain());
|
||||
EffectManager::Instance().Update(dt);
|
||||
static float s_flyingTime = 0.0f;
|
||||
@@ -350,8 +379,20 @@ PyObject* app_create(PyObject*, PyObject* args) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
PyObject* app_loop(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* app_exit(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* app_abort(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* app_exit(PyObject*, PyObject*) {
|
||||
PythonNetworkStream::Instance().RequestQuit();
|
||||
SDL_Event ev{};
|
||||
ev.type = SDL_EVENT_QUIT;
|
||||
SDL_PushEvent(&ev);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
PyObject* app_abort(PyObject*, PyObject*) {
|
||||
PythonNetworkStream::Instance().RequestQuit();
|
||||
SDL_Event ev{};
|
||||
ev.type = SDL_EVENT_QUIT;
|
||||
SDL_PushEvent(&ev);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
PyObject* app_is_pressed(PyObject*, PyObject* args) { return PyInt_FromLong(0); }
|
||||
|
||||
PyObject* app_get_locale_service_name(PyObject*, PyObject*) {
|
||||
@@ -441,13 +482,16 @@ PyObject* app_set_guild_mark_path(PyObject*, PyObject* args) {
|
||||
|
||||
} // namespace
|
||||
|
||||
void GetCameraInput(int& rotate,int& pitch,int& zoom) { rotate=cameraRotateInput; pitch=cameraPitchInput; zoom=cameraZoomInput; }
|
||||
void StopCameraInput() { cameraRotateInput=cameraPitchInput=cameraZoomInput=0; }
|
||||
void SetGameFrameDelta(float dt) { gameFrameDelta = std::clamp(dt, 0.001f, 0.25f); }
|
||||
std::int32_t GetServerTimeStamp() { return server_clock.timestamp(unix_seconds()); }
|
||||
void SetServerTime(std::int32_t time) { server_clock.set(time,local_milliseconds(),unix_seconds()); }
|
||||
std::uint32_t GetLocalMSec() { return local_milliseconds(); }
|
||||
std::int32_t GetApplicationSeconds() { return static_cast<std::int32_t>(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now()-app_start).count()); }
|
||||
void SetServerMSec(std::uint32_t time) { if(time==0) return;elt_server_time=time;elt_client_time=local_milliseconds(); ELTimer_SetServerMSec(time); }
|
||||
std::uint32_t GetServerMSec() { return local_milliseconds()-elt_client_time+elt_server_time; }
|
||||
void ResetPythonAppState() { elt_server_time=elt_client_time=0;ELTimer_Init();server_clock=ServerClock(local_milliseconds());app_start=std::chrono::steady_clock::now();s_test_server_flag=false;twoHandedAttackSpeedDecrease=0; }
|
||||
void ResetPythonAppState() { s_cameraSettingPending=false; elt_server_time=elt_client_time=0;ELTimer_Init();server_clock=ServerClock(local_milliseconds());app_start=std::chrono::steady_clock::now();s_test_server_flag=false;twoHandedAttackSpeedDecrease=0; }
|
||||
std::uint8_t GetEnterGameLanguage() {
|
||||
const char* locales[]={"ymir","en","de","tr","pt","es","fr","ro","pl","it","cz","hu"};
|
||||
for(std::uint8_t i=1;i<12;++i) if(s_locale_name==locales[i]) return i;
|
||||
@@ -468,7 +512,6 @@ static float s_minFog = 0.0f;
|
||||
static bool s_frameSkip = false;
|
||||
static int s_fps = 60;
|
||||
static int s_globalCenterX = 0, s_globalCenterY = 0;
|
||||
static float s_centerX = 0.0f, s_centerY = 0.0f, s_centerZ = 0.0f;
|
||||
static int s_cursorNum = 0;
|
||||
static bool s_cursorVisible = true;
|
||||
static bool s_softwareCursor = false;
|
||||
@@ -627,7 +670,8 @@ static PyObject* app_set_global_center_position(PyObject*, PyObject* args) {
|
||||
static PyObject* app_set_center_position(PyObject*, PyObject* args) {
|
||||
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||
if (!PyTuple_GetFloat(args, 0, &x) || !PyTuple_GetFloat(args, 1, &y) || !PyTuple_GetFloat(args, 2, &z)) return Py_BuildException();
|
||||
s_centerX = x; s_centerY = y; s_centerZ = z;
|
||||
s_centerX = x; s_centerY = z; s_centerZ = -y;
|
||||
SyncCameraToRenderer();
|
||||
return Py_BuildNone();
|
||||
}
|
||||
static PyObject* app_run_python_file(PyObject*, PyObject* args) {
|
||||
@@ -973,6 +1017,11 @@ void initapp() {
|
||||
{nullptr, nullptr, 0, nullptr}
|
||||
};
|
||||
auto* module = Py_InitModule("app", methods);
|
||||
#ifdef __ANDROID__
|
||||
PyModule_AddIntConstant(module, "ENABLE_MOBILE_HUD", 1);
|
||||
#else
|
||||
PyModule_AddIntConstant(module, "ENABLE_MOBILE_HUD", 0);
|
||||
#endif
|
||||
register_app_constants(module);
|
||||
|
||||
#ifdef ENABLE_MANAGER_BANK_SYSTEM
|
||||
@@ -1032,6 +1081,15 @@ void initapp() {
|
||||
PyModule_AddIntConstant(module, "DIK_LEFT", 0xCB);
|
||||
PyModule_AddIntConstant(module, "DIK_RIGHT", 0xCD);
|
||||
|
||||
// Virtual Keys
|
||||
PyModule_AddIntConstant(module, "VK_LEFT", 0x25);
|
||||
PyModule_AddIntConstant(module, "VK_UP", 0x26);
|
||||
PyModule_AddIntConstant(module, "VK_RIGHT", 0x27);
|
||||
PyModule_AddIntConstant(module, "VK_DOWN", 0x28);
|
||||
PyModule_AddIntConstant(module, "VK_HOME", 0x24);
|
||||
PyModule_AddIntConstant(module, "VK_END", 0x23);
|
||||
PyModule_AddIntConstant(module, "VK_DELETE", 0x2E);
|
||||
|
||||
PyModule_AddIntConstant(module, "INFO_ITEM", 0);
|
||||
PyModule_AddIntConstant(module, "INFO_ACTOR", 1);
|
||||
PyModule_AddIntConstant(module, "INFO_EFFECT", 2);
|
||||
@@ -1110,6 +1168,15 @@ bool LoadLocaleData(const std::string& localePath) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ConsumeCameraSetting(float& distance,float& pitch,float& yaw,float& height) {
|
||||
if (!s_cameraSettingPending) return false;
|
||||
s_cameraSettingPending=false;
|
||||
distance=s_camera_distance;pitch=s_camera_pitch;yaw=s_camera_rotation;height=s_camera_height;
|
||||
return true;
|
||||
}
|
||||
void UpdateCameraFromHost(float distance,float pitch,float yaw,float height) {
|
||||
s_camera_distance=distance;s_camera_pitch=pitch;s_camera_rotation=yaw;s_camera_height=height;
|
||||
}
|
||||
float GetCameraZoomSpeed() { return s_camera_zoom_speed; }
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
@@ -19,4 +19,9 @@ unsigned GetDefaultCodePage();
|
||||
// ::LoadLocaleData (AVA2 UserInterface/PythonApplication.cpp), backing app.LoadLocaleData.
|
||||
bool LoadLocaleData(const std::string& localePath);
|
||||
float GetCameraZoomSpeed();
|
||||
void SetGameFrameDelta(float dt);
|
||||
void GetCameraInput(int& rotate,int& pitch,int& zoom);
|
||||
void StopCameraInput();
|
||||
bool ConsumeCameraSetting(float& distance,float& pitch,float& yaw,float& height);
|
||||
void UpdateCameraFromHost(float distance,float pitch,float yaw,float height);
|
||||
}
|
||||
|
||||
+138
-25
@@ -206,12 +206,22 @@ bool CPythonBackground::LoadMap(const std::string& mapName, float x, float y, fl
|
||||
(void)z;
|
||||
Create();
|
||||
|
||||
std::vector<std::string> base_candidates = {
|
||||
"map/" + mapName,
|
||||
mapName,
|
||||
"Maps/" + mapName,
|
||||
"build/dev/test-rundir/map/" + mapName
|
||||
};
|
||||
if (m_mapObjects) m_mapObjects->ClearObjects();
|
||||
if (m_forest) m_forest->Clear();
|
||||
m_water = std::make_unique<WaterManager>();
|
||||
|
||||
for (const auto& property : CResourceManager::GetCandidatePaths("property")) {
|
||||
if (!std::filesystem::is_directory(property)) continue;
|
||||
if (m_mapObjects && m_mapObjects->GetPropertyCount() == 0)
|
||||
m_mapObjects->ScanPropertyDirectory(property);
|
||||
if (m_forest && m_forest->GetMainTreeCount() == 0)
|
||||
m_forest->ScanPropertyDirectory(property);
|
||||
}
|
||||
std::vector<std::string> base_candidates;
|
||||
for (const auto& path : {"map/" + mapName, mapName, "maps/" + mapName}) {
|
||||
auto candidates = CResourceManager::GetCandidatePaths(path);
|
||||
base_candidates.insert(base_candidates.end(), candidates.begin(), candidates.end());
|
||||
}
|
||||
|
||||
std::string found_base = "";
|
||||
for (const auto& base : base_candidates) {
|
||||
@@ -251,6 +261,23 @@ bool CPythonBackground::LoadMap(const std::string& mapName, float x, float y, fl
|
||||
m_outdoorMap.baseX = static_cast<uint32_t>(std::atol(base->second[0].c_str()));
|
||||
m_outdoorMap.baseY = static_cast<uint32_t>(std::atol(base->second[1].c_str()));
|
||||
}
|
||||
auto env_it = tokens.find("environment");
|
||||
if (env_it != tokens.end() && !env_it->second.empty()) {
|
||||
std::string env_name = env_it->second[0];
|
||||
RegisterEnvironmentData(0, env_name.c_str());
|
||||
SetEnvironmentData(0);
|
||||
}
|
||||
auto tex_it = tokens.find("textureset");
|
||||
if (tex_it != tokens.end() && !tex_it->second.empty()) {
|
||||
std::string tex_path = tex_it->second[0];
|
||||
std::replace(tex_path.begin(), tex_path.end(), '\\', '/');
|
||||
for (const auto& candidate : CResourceManager::GetCandidatePaths(CResourceManager::NormalizePath(tex_path.c_str()))) {
|
||||
if (std::filesystem::is_regular_file(candidate)) {
|
||||
m_terrain->LoadTextureSet(candidate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int bx = static_cast<int>(std::floor(x / 25600.0f));
|
||||
@@ -264,6 +291,9 @@ bool CPythonBackground::LoadMap(const std::string& mapName, float x, float y, fl
|
||||
std::string height_path = block_dir + "/height.raw";
|
||||
if (std::filesystem::exists(height_path)) {
|
||||
ok = m_terrain->LoadRaw(height_path);
|
||||
// height.raw includes a one-sample border around each 25600-unit block.
|
||||
m_terrain->SetWorldOrigin(bx * 25600.0f - m_terrain->GetCellScale(),
|
||||
by * 25600.0f - m_terrain->GetCellScale());
|
||||
}
|
||||
std::string tile_path = block_dir + "/tile.raw";
|
||||
if (std::filesystem::exists(tile_path)) {
|
||||
@@ -273,6 +303,16 @@ bool CPythonBackground::LoadMap(const std::string& mapName, float x, float y, fl
|
||||
if (std::filesystem::exists(attr_path)) {
|
||||
m_terrain->LoadAttr(attr_path);
|
||||
}
|
||||
std::string areadata_path = block_dir + "/areadata.txt";
|
||||
if (std::filesystem::exists(areadata_path) && m_mapObjects) {
|
||||
m_mapObjects->LoadAreaData(areadata_path, 1.0f, m_forest.get(), true);
|
||||
}
|
||||
std::string water_path = block_dir + "/water.wtr";
|
||||
if (std::filesystem::exists(water_path) && m_water) {
|
||||
m_water->LoadWater(water_path, m_terrain ? m_terrain->GetCellScale() : 200.0f, 0.5f, 200.0f,
|
||||
m_terrain ? m_terrain->GetWorldMinX() : -2560.0f,
|
||||
m_terrain ? m_terrain->GetWorldMinZ() : -2560.0f);
|
||||
}
|
||||
} else {
|
||||
// Fallback: look for 000000 or any block in the directory
|
||||
for (const auto& entry : std::filesystem::directory_iterator(found_base)) {
|
||||
@@ -284,15 +324,27 @@ bool CPythonBackground::LoadMap(const std::string& mapName, float x, float y, fl
|
||||
if (std::filesystem::exists(tpath)) m_terrain->LoadTileRaw(tpath);
|
||||
std::string apath = entry.path().string() + "/attr.atr";
|
||||
if (std::filesystem::exists(apath)) m_terrain->LoadAttr(apath);
|
||||
std::string adpath = entry.path().string() + "/areadata.txt";
|
||||
if (std::filesystem::exists(adpath) && m_mapObjects) {
|
||||
m_mapObjects->LoadAreaData(adpath, 1.0f, m_forest.get(), true);
|
||||
}
|
||||
std::string wpath = entry.path().string() + "/water.wtr";
|
||||
if (std::filesystem::exists(wpath) && m_water) {
|
||||
m_water->LoadWater(wpath, m_terrain ? m_terrain->GetCellScale() : 200.0f, 0.5f, 200.0f,
|
||||
m_terrain ? m_terrain->GetWorldMinX() : -2560.0f,
|
||||
m_terrain ? m_terrain->GetWorldMinZ() : -2560.0f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string textureset_path = "textureset/metin2_map1.txt";
|
||||
if (std::filesystem::exists(textureset_path)) {
|
||||
m_terrain->LoadTextureSet(textureset_path);
|
||||
if (m_terrain && m_terrain->GetTextureSet().empty()) {
|
||||
std::string textureset_path = "textureset/metin2_map1.txt";
|
||||
if (std::filesystem::exists(textureset_path)) {
|
||||
m_terrain->LoadTextureSet(textureset_path);
|
||||
}
|
||||
}
|
||||
|
||||
m_strMapName = mapName;
|
||||
@@ -444,16 +496,34 @@ void CPythonBackground::ClearGuildArea() {
|
||||
|
||||
bool CPythonBackground::RegisterEnvironmentData(int iIndex, const char* pszEnvironmentFileName) {
|
||||
if (!pszEnvironmentFileName) return false;
|
||||
std::string fname = pszEnvironmentFileName;
|
||||
std::replace(fname.begin(), fname.end(), '\\', '/');
|
||||
|
||||
std::string lower_fname = fname;
|
||||
std::transform(lower_fname.begin(), lower_fname.end(), lower_fname.begin(), ::tolower);
|
||||
|
||||
std::vector<std::string> candidates = {
|
||||
fname,
|
||||
"ymir work/environment/" + fname,
|
||||
"environment/" + fname,
|
||||
lower_fname,
|
||||
"ymir work/environment/" + lower_fname,
|
||||
"environment/" + lower_fname,
|
||||
"build/dev/ymir work/environment/" + lower_fname
|
||||
};
|
||||
|
||||
EnvironmentData env;
|
||||
if (env.LoadFromFile(pszEnvironmentFileName)) {
|
||||
m_mapEnvironmentData[iIndex] = env;
|
||||
return true;
|
||||
}
|
||||
std::string text;
|
||||
try { text = ReadPackedText(pszEnvironmentFileName); } catch (...) {}
|
||||
if (!text.empty() && env.LoadFromString(text)) {
|
||||
m_mapEnvironmentData[iIndex] = env;
|
||||
return true;
|
||||
for (const auto& path : candidates) {
|
||||
if (std::filesystem::exists(path) && env.LoadFromFile(path)) {
|
||||
m_mapEnvironmentData[iIndex] = env;
|
||||
return true;
|
||||
}
|
||||
std::string text;
|
||||
try { text = ReadPackedText(path); } catch (...) {}
|
||||
if (!text.empty() && env.LoadFromString(text)) {
|
||||
m_mapEnvironmentData[iIndex] = env;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -462,6 +532,9 @@ bool CPythonBackground::SetEnvironmentData(int iIndex) {
|
||||
auto it = m_mapEnvironmentData.find(iIndex);
|
||||
if (it != m_mapEnvironmentData.end()) {
|
||||
m_pCurrentEnvironment = &it->second;
|
||||
if (m_skybox) {
|
||||
m_skybox->SetEnvironment(it->second);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -518,6 +591,12 @@ void CPythonBackground::DeleteSpecialEffect(uint32_t dwID) {
|
||||
|
||||
void CPythonBackground::Update(float fCameraX, float fCameraY, float fCameraZ) {
|
||||
(void)fCameraX; (void)fCameraY; (void)fCameraZ;
|
||||
if (m_skybox) {
|
||||
m_skybox->Update(0.033f);
|
||||
}
|
||||
if (m_forest) {
|
||||
m_forest->UpdateSystem(0.033f);
|
||||
}
|
||||
}
|
||||
|
||||
void CPythonBackground::Render() {
|
||||
@@ -556,6 +635,11 @@ void CPythonBackground::RenderSnow() {
|
||||
void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float* projMatrix, const float* camPos, std::vector<Render3DDraw>& outDraws) {
|
||||
if (!IsMapReady()) return;
|
||||
|
||||
if (m_bVisiblePart[PART_SKY] && m_skybox && viewMatrix && projMatrix && camPos) {
|
||||
auto sdraws = m_skybox->BuildDrawCommands(viewMatrix, projMatrix, camPos[0], camPos[1], camPos[2]);
|
||||
for (auto& sd : sdraws) outDraws.push_back(std::move(sd));
|
||||
}
|
||||
|
||||
if (m_bVisiblePart[PART_TERRAIN] && m_terrain) {
|
||||
std::vector<Render3DDraw> tdraws;
|
||||
if (viewMatrix && projMatrix) {
|
||||
@@ -570,26 +654,55 @@ void CPythonBackground::BuildDrawCommands(const float* viewMatrix, const float*
|
||||
td.light_direction[0] = m_pCurrentEnvironment->dir_light.direction[0];
|
||||
td.light_direction[1] = m_pCurrentEnvironment->dir_light.direction[1];
|
||||
td.light_direction[2] = m_pCurrentEnvironment->dir_light.direction[2];
|
||||
td.light_ambient[0] = m_pCurrentEnvironment->dir_light.bg_ambient[0];
|
||||
td.light_ambient[1] = m_pCurrentEnvironment->dir_light.bg_ambient[1];
|
||||
td.light_ambient[2] = m_pCurrentEnvironment->dir_light.bg_ambient[2];
|
||||
td.light_ambient[0] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[0]);
|
||||
td.light_ambient[1] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[1]);
|
||||
td.light_ambient[2] = std::max(0.38f, m_pCurrentEnvironment->dir_light.bg_ambient[2]);
|
||||
}
|
||||
outDraws.push_back(std::move(td));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bVisiblePart[PART_WATER] && m_water && m_water->HasWater()) {
|
||||
outDraws.push_back(m_water->BuildDrawCommand(0.0f));
|
||||
auto wd = m_water->BuildDrawCommand(0.0f);
|
||||
if (m_pCurrentEnvironment) {
|
||||
wd.light_direction[0] = m_pCurrentEnvironment->dir_light.direction[0];
|
||||
wd.light_direction[1] = m_pCurrentEnvironment->dir_light.direction[1];
|
||||
wd.light_direction[2] = m_pCurrentEnvironment->dir_light.direction[2];
|
||||
wd.light_ambient[0] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[0]);
|
||||
wd.light_ambient[1] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[1]);
|
||||
wd.light_ambient[2] = std::max(0.38f, m_pCurrentEnvironment->dir_light.bg_ambient[2]);
|
||||
}
|
||||
outDraws.push_back(std::move(wd));
|
||||
}
|
||||
|
||||
if (m_bVisiblePart[PART_OBJECT] && m_mapObjects) {
|
||||
auto bdraws = m_mapObjects->BuildDrawCommands();
|
||||
for (auto& bd : bdraws) outDraws.push_back(std::move(bd));
|
||||
auto bdraws = m_mapObjects->BuildDrawCommands(viewMatrix, projMatrix);
|
||||
for (auto& bd : bdraws) {
|
||||
if (m_pCurrentEnvironment) {
|
||||
bd.light_direction[0] = m_pCurrentEnvironment->dir_light.direction[0];
|
||||
bd.light_direction[1] = m_pCurrentEnvironment->dir_light.direction[1];
|
||||
bd.light_direction[2] = m_pCurrentEnvironment->dir_light.direction[2];
|
||||
bd.light_ambient[0] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[0]);
|
||||
bd.light_ambient[1] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[1]);
|
||||
bd.light_ambient[2] = std::max(0.38f, m_pCurrentEnvironment->dir_light.bg_ambient[2]);
|
||||
}
|
||||
outDraws.push_back(std::move(bd));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bVisiblePart[PART_TREE] && m_forest && viewMatrix && projMatrix && camPos) {
|
||||
auto fdraws = m_forest->BuildDrawCommands(viewMatrix, projMatrix, camPos[0], camPos[1], camPos[2], GetFarClip());
|
||||
for (auto& fd : fdraws) outDraws.push_back(std::move(fd));
|
||||
for (auto& fd : fdraws) {
|
||||
if (m_pCurrentEnvironment) {
|
||||
fd.light_direction[0] = m_pCurrentEnvironment->dir_light.direction[0];
|
||||
fd.light_direction[1] = m_pCurrentEnvironment->dir_light.direction[1];
|
||||
fd.light_direction[2] = m_pCurrentEnvironment->dir_light.direction[2];
|
||||
fd.light_ambient[0] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[0]);
|
||||
fd.light_ambient[1] = std::max(0.35f, m_pCurrentEnvironment->dir_light.bg_ambient[1]);
|
||||
fd.light_ambient[2] = std::max(0.38f, m_pCurrentEnvironment->dir_light.bg_ambient[2]);
|
||||
}
|
||||
outDraws.push_back(std::move(fd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+74
-9
@@ -9,10 +9,12 @@
|
||||
#include <Python.h>
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_net/PythonNetworkStream.h"
|
||||
#include "eter_render/RaceData.h"
|
||||
#include "eter_render/TextTailManager.h"
|
||||
#include "eter_render/Gr2ModelRenderer.h"
|
||||
#include "eter_render/TerrainHeightmap.h"
|
||||
#include "eter_image/GrpDevice.h"
|
||||
#include "shared/common/PythonUtils.h"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
@@ -36,7 +38,7 @@ SNetworkActorData* GetInstancePtr(int vid) { return Mgr().GetActorData(uint32_t(
|
||||
// CInstanceBase::NEW_GetPixelPosition: the port's actor stores (x, height, y).
|
||||
void GetPixelPosition(const SNetworkActorData& inst, float* x, float* y, float* z) {
|
||||
if (inst.m_pActorInstance) {
|
||||
*x = inst.m_pActorInstance->GetX(); *y = inst.m_pActorInstance->GetZ(); *z = inst.m_pActorInstance->GetY();
|
||||
*x = inst.m_pActorInstance->GetX(); *y = inst.m_pActorInstance->GetZ() * (inst.m_isScriptInstance ? -1.0f : 1.0f); *z = inst.m_pActorInstance->GetY();
|
||||
} else {
|
||||
*x = float(inst.m_lCurX); *y = float(inst.m_lCurY); *z = float(inst.m_lCurZ);
|
||||
}
|
||||
@@ -46,8 +48,11 @@ void SetPixelPosition(SNetworkActorData& inst, float x, float y, float z) {
|
||||
inst.m_lCurX = inst.m_lDstX = int32_t(x);
|
||||
inst.m_lCurY = inst.m_lDstY = int32_t(y);
|
||||
inst.m_lCurZ = int32_t(z);
|
||||
if (inst.m_pActorInstance) inst.m_pActorInstance->SetPosition(x, z, y);
|
||||
TextTailManager::Instance().SetCharacterPosition(inst.m_dwVID, x, z, y);
|
||||
// In Windows Metin2: v3PosCur.x = +x, v3PosCur.y = -y, v3PosCur.z = +z.
|
||||
// In our Y-up coordinate system: X is right, Y is up, Z is depth/forward.
|
||||
const float engineZ=inst.m_isScriptInstance ? -y : y;
|
||||
if (inst.m_pActorInstance) inst.m_pActorInstance->SetPosition(x, z, engineZ);
|
||||
TextTailManager::Instance().SetCharacterPosition(inst.m_dwVID, x, z, engineZ);
|
||||
}
|
||||
// CInstanceBase::__GetBackgroundHeight (0 without a map).
|
||||
float GetBackgroundHeight(float x, float y) {
|
||||
@@ -70,6 +75,7 @@ void CreateInstance(SNetworkActorData& createData) {
|
||||
return;
|
||||
}
|
||||
createData.m_lCurZ = int32_t(GetBackgroundHeight(float(createData.m_lCurX), float(createData.m_lCurY)));
|
||||
createData.m_isScriptInstance = true;
|
||||
Mgr().AppendActor(createData);
|
||||
}
|
||||
|
||||
@@ -434,6 +440,8 @@ PyObject* chrRaceToSex(PyObject*, PyObject* poArgs) {
|
||||
|
||||
PyObject* chrDestroy(PyObject*, PyObject*) {
|
||||
Mgr().Destroy();
|
||||
// Destroying the phase's character instances must not discard the server's identity.
|
||||
Mgr().SetMainActorVID(PythonNetworkStream::Instance().GetMainActorVID());
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -446,14 +454,69 @@ PyObject* chrUpdate(PyObject*, PyObject*) {
|
||||
const float dt = s_hasLast ? std::chrono::duration<float>(now - s_last).count() : 0.0f;
|
||||
s_last = now;
|
||||
s_hasLast = true;
|
||||
Mgr().Update(dt, GetActiveBackgroundTerrain());
|
||||
// Intro instances keep the explicit height set by introselect / introcreate,
|
||||
// even when a previously visited game map remains loaded.
|
||||
Mgr().Update(dt, PythonNetworkStream::Instance().IsGamePhase() ? GetActiveBackgroundTerrain() : nullptr);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
// Deform / Render / RenderCollision: the port deforms in ActorInstance::Update and draws the actor
|
||||
// list through GetAllActiveChrDraws (main loop), so the script calls have nothing left to do.
|
||||
PyObject* chrDeform(PyObject*, PyObject*) { return Py_BuildNone(); }
|
||||
PyObject* chrRender(PyObject*, PyObject*) { return Py_BuildNone(); }
|
||||
PyObject* chrDeform(PyObject*, PyObject*) {
|
||||
// BuildDrawCommands skins the current pose during Render. Windows Deform
|
||||
// does not tick movement or animations a second time after chr.Update.
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
PyObject* chrRender(PyObject*, PyObject*) {
|
||||
Gr2SceneRenderer* sceneRenderer = TextTailManager::Instance().GetCurrentSceneRenderer();
|
||||
SDL_Renderer* renderer = CGraphicDevice::Instance().GetRenderer();
|
||||
if (!renderer) renderer = TextTailManager::Instance().GetCurrentRenderer();
|
||||
if (sceneRenderer && renderer) {
|
||||
auto draws = GetAllActiveChrDraws();
|
||||
if (!draws.empty()) {
|
||||
for (auto& d : draws) {
|
||||
d.material_ambient[0] = 0.85f;
|
||||
d.material_ambient[1] = 0.85f;
|
||||
d.material_ambient[2] = 0.85f;
|
||||
d.light_ambient[0] = std::max(0.55f, d.light_ambient[0]);
|
||||
d.light_ambient[1] = std::max(0.55f, d.light_ambient[1]);
|
||||
d.light_ambient[2] = std::max(0.58f, d.light_ambient[2]);
|
||||
d.material_emissive[0] = std::max(0.05f, d.material_emissive[0]);
|
||||
d.material_emissive[1] = std::max(0.05f, d.material_emissive[1]);
|
||||
d.material_emissive[2] = std::max(0.05f, d.material_emissive[2]);
|
||||
}
|
||||
|
||||
int sw = sceneRenderer->GetLogicalWidth();
|
||||
int sh = sceneRenderer->GetLogicalHeight();
|
||||
if (sw <= 0) sw = 1024;
|
||||
if (sh <= 0) sh = 768;
|
||||
|
||||
static std::unique_ptr<SDL_Surface, decltype(&SDL_DestroySurface)> s_chrSurface(nullptr, SDL_DestroySurface);
|
||||
static std::unique_ptr<SDL_Texture, decltype(&SDL_DestroyTexture)> s_chrTexture(nullptr, SDL_DestroyTexture);
|
||||
static int s_chrW = 0, s_chrH = 0;
|
||||
|
||||
if (!s_chrSurface || s_chrW != sw || s_chrH != sh) {
|
||||
s_chrW = sw;
|
||||
s_chrH = sh;
|
||||
s_chrSurface.reset(SDL_CreateSurface(s_chrW, s_chrH, SDL_PIXELFORMAT_ARGB8888));
|
||||
s_chrTexture.reset(SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, s_chrW, s_chrH));
|
||||
if (s_chrTexture) {
|
||||
SDL_SetTextureBlendMode(s_chrTexture.get(), SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureScaleMode(s_chrTexture.get(), SDL_SCALEMODE_LINEAR);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_chrSurface && s_chrTexture) {
|
||||
SDL_FillSurfaceRect(s_chrSurface.get(), nullptr, 0x00000000);
|
||||
sceneRenderer->Clear(0, 1.0f);
|
||||
sceneRenderer->RenderScene(s_chrSurface.get(), draws);
|
||||
SDL_UpdateTexture(s_chrTexture.get(), nullptr, s_chrSurface->pixels, s_chrSurface->pitch);
|
||||
SDL_FRect dst = { 0.0f, 0.0f, static_cast<float>(sw), static_cast<float>(sh) };
|
||||
SDL_RenderTexture(renderer, s_chrTexture.get(), nullptr, &dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Py_BuildNone();
|
||||
}
|
||||
PyObject* chrRenderCollision(PyObject*, PyObject*) { return Py_BuildNone(); }
|
||||
|
||||
PyObject* chrCreateInstance(PyObject*, PyObject* poArgs) {
|
||||
@@ -480,7 +543,8 @@ PyObject* chrCreateInstance(PyObject*, PyObject* poArgs) {
|
||||
|
||||
CreateInstance(kCreateData);
|
||||
} else {
|
||||
Mgr().RegisterInstance(uint32_t(iVirtualID));
|
||||
if (auto instance = Mgr().RegisterInstance(uint32_t(iVirtualID)))
|
||||
instance->m_isScriptInstance = true;
|
||||
}
|
||||
return Py_BuildNone();
|
||||
}
|
||||
@@ -827,6 +891,7 @@ PyObject* chrSetRotation(PyObject*, PyObject* poArgs) {
|
||||
if (!PyTuple_GetFloat(poArgs, 0, &fRotation)) return Py_BuildException();
|
||||
SNetworkActorData* pCharacterInstance = GetSelectedInstancePtr();
|
||||
if (!pCharacterInstance) return Py_BuildNone();
|
||||
// Windows chr.SetRotation adds 180 degrees at the scripting boundary.
|
||||
SetRotation(*pCharacterInstance, std::fmod(fRotation + 180.0f, 360.0f));
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,15 @@ static int s_quickPage=0;
|
||||
static PyObject* s_playerGameWindow=nullptr;
|
||||
static PyObject* player_SetGameWindow(PyObject*,PyObject* args) {
|
||||
PyObject* window;if(!PyArg_ParseTuple(args,"O",&window)) return nullptr;
|
||||
if(window==Py_None) window=nullptr;Py_XINCREF(window);auto* old=s_playerGameWindow;s_playerGameWindow=window;Py_XDECREF(old);Py_RETURN_NONE;
|
||||
if(window==Py_None || (PyInt_Check(window) && PyInt_AsLong(window)==0)) window=nullptr;
|
||||
if(window==s_playerGameWindow) Py_RETURN_NONE;
|
||||
Py_XINCREF(window);
|
||||
auto* old=s_playerGameWindow; s_playerGameWindow=nullptr;
|
||||
// The previous GameWindow destructor calls SetGameWindow(0). Dispose it
|
||||
// before assigning its successor so it cannot clear the new callback owner.
|
||||
Py_XDECREF(old);
|
||||
s_playerGameWindow=window;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static bool player_window_call(const char* name, PyObject* args = nullptr) {
|
||||
if (!s_playerGameWindow) {
|
||||
@@ -153,7 +161,7 @@ static PyObject* player_AffectIndexToSkillIndex(PyObject*,PyObject* args) {
|
||||
static PyObject* player_GetSkillSlotIndex(PyObject*,PyObject* args) {
|
||||
int index;if(!PyArg_ParseTuple(args,"i",&index)) return nullptr;
|
||||
auto it=s_skillSlots.find(index);
|
||||
if(it==s_skillSlots.end()) {PyErr_SetString(PyExc_RuntimeError,"unknown skill index");return nullptr;}
|
||||
if(it==s_skillSlots.end()) return Py_BuildException();
|
||||
return PyInt_FromLong(it->second);
|
||||
}
|
||||
template<bool Next> static PyObject* player_GetSkillPower(PyObject*,PyObject* args) {
|
||||
@@ -227,14 +235,14 @@ static PyObject* player_SetStatus(PyObject*, PyObject* args) {
|
||||
long long value = 0;
|
||||
if (PyArg_ParseTuple(args, "iL", &type, &value)) {
|
||||
if(uint32_t(type)<255) {
|
||||
s_playerPoints[type] = value;
|
||||
SetPlayerStatusPoint(type, value);
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
long lVal = 0;
|
||||
if (PyArg_ParseTuple(args, "il", &type, &lVal)) {
|
||||
if(uint32_t(type)<255) {
|
||||
s_playerPoints[type] = lVal;
|
||||
SetPlayerStatusPoint(type, lVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -963,6 +971,15 @@ void UseGuildSkill(int skillSlot) {
|
||||
}
|
||||
|
||||
static bool s_isAtkKey = false;
|
||||
static std::array<bool, 256> s_movementKeys{};
|
||||
bool GetPlayerMovementYaw(float cameraYaw, float& movementYaw) {
|
||||
const int x = int(s_movementKeys[32] || s_movementKeys[205]) - int(s_movementKeys[30] || s_movementKeys[203]);
|
||||
const int z = int(s_movementKeys[31] || s_movementKeys[208]) - int(s_movementKeys[17] || s_movementKeys[200]);
|
||||
if (!x && !z) return false;
|
||||
movementYaw = std::atan2(float(x), float(z)) * 180.0f / 3.14159265f - cameraYaw;
|
||||
movementYaw = std::fmod(movementYaw + 720.0f, 360.0f);
|
||||
return true;
|
||||
}
|
||||
static float s_fCmrRotSpd = 0.0f;
|
||||
static uint32_t s_inGuildAreaID = 0xffffffff;
|
||||
|
||||
@@ -1177,16 +1194,33 @@ void SetMainCharacterPosition(float x, float y, float z) {
|
||||
s_mainActorPos.z = z;
|
||||
}
|
||||
|
||||
void GetMainCharacterPosition(float& x, float& y, float& z) {
|
||||
x = s_mainActorPos.x;
|
||||
y = s_mainActorPos.y;
|
||||
z = s_mainActorPos.z;
|
||||
}
|
||||
|
||||
const std::string& GetMainCharacterName() { return s_playerName; }
|
||||
|
||||
void SetMainCharacterName(const std::string& name) {
|
||||
s_playerName = name;
|
||||
}
|
||||
|
||||
static void UpdateBattleStatus();
|
||||
long long GetPlayerStatusPoint(int type) {if(uint32_t(type)>=255)return 0;auto it=s_playerPoints.find(type);return it==s_playerPoints.end()?0:it->second;}
|
||||
void SetPlayerStatusPoint(int type, long long value) {
|
||||
if(uint32_t(type)>=255)return;
|
||||
s_playerPoints[type] = value;
|
||||
// CPythonPlayer::SetStatus: derived combat points are client-calculated,
|
||||
// both on the initial points packet and subsequent stat changes.
|
||||
switch (type) {
|
||||
case 1: case 12: case 14: case 15: // level, ST, DX, IQ
|
||||
case 18: case 29: case 30: // evade, min/max attack
|
||||
case 200: case 201: case 204: // min/max weapon, hit rate
|
||||
case 205: case 207: case 208: case 209: case 210:
|
||||
UpdateBattleStatus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerItemSlot GetPlayerItem(int slot) {
|
||||
@@ -1261,10 +1295,13 @@ bool GetPartyMemberState(uint32_t pid,uint8_t* state) {
|
||||
bool PartyMemberPIDToVID(uint32_t pid,uint32_t* vid) {
|
||||
auto* member=find_party_member(pid);if(!member) return false;*vid=member->vid;return true;
|
||||
}
|
||||
static bool party_member_vid_to_pid(uint32_t vid,uint32_t* pid) {
|
||||
bool PartyMemberVIDToPID(uint32_t vid,uint32_t* pid) {
|
||||
for(const auto& [memberPid,member]:s_partyMembers) if(member.vid==vid) {*pid=memberPid;return true;}
|
||||
return false;
|
||||
}
|
||||
static inline bool party_member_vid_to_pid(uint32_t vid,uint32_t* pid) {
|
||||
return PartyMemberVIDToPID(vid, pid);
|
||||
}
|
||||
// CPythonBackground::m_strMapName: only Warp() sets it (LoadMap does not), Destroy() clears it.
|
||||
static std::string s_warpMapName;
|
||||
bool IsPartyMemberByVID(uint32_t vid) { uint32_t pid;return party_member_vid_to_pid(vid,&pid); }
|
||||
@@ -1630,6 +1667,7 @@ bool HasEnoughArrow() {
|
||||
}
|
||||
|
||||
void ResetPlayerState() {
|
||||
CancelPlayerMovement();
|
||||
s_coolTimeEnabled=true;
|
||||
s_playerName.clear();s_mainActorPos={};s_playerPoints.clear();s_playerSkills.clear();s_skillSlots.clear();
|
||||
s_quickPage=0;s_playTime=0;s_playerQuickSlots.fill({});s_playerItems.fill({});s_windowItems.clear();
|
||||
@@ -1787,6 +1825,13 @@ struct SDropItemEntry {
|
||||
};
|
||||
static std::unordered_map<uint32_t, std::vector<SDropItemEntry>> s_chestDropInfoMap;
|
||||
|
||||
void ClearChestDropInfo(uint32_t chestVnum) {
|
||||
s_chestDropInfoMap.erase(chestVnum);
|
||||
}
|
||||
void AddChestDropItem(uint32_t chestVnum, uint32_t itemVnum, uint32_t count) {
|
||||
s_chestDropInfoMap[chestVnum].push_back({itemVnum, int(count)});
|
||||
}
|
||||
|
||||
static PyObject* item_CreateItem(PyObject*, PyObject* poArgs) {
|
||||
int iVirtualID = 0, iVirtualNumber = 0;
|
||||
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||
@@ -2465,6 +2510,9 @@ static std::map<int, AutoPotionInfo> s_autoPotionInfo;
|
||||
static std::map<int, uint32_t> s_emotionIcons;
|
||||
static int s_mouseFunc[8] = {0};
|
||||
static int s_mouseState[8] = {0};
|
||||
bool IsPlayerMouseMoving() { return s_mouseState[0] == 1 && (s_mouseFunc[0] == 0 || s_mouseFunc[0] == 1); }
|
||||
bool IsPlayerCameraDragging() { return s_mouseState[1] == 1 && s_mouseFunc[1] == 2; }
|
||||
void CancelPlayerMovement() { s_movementKeys.fill(false); std::fill(std::begin(s_mouseState),std::end(s_mouseState),0); }
|
||||
static int s_mouseMiddleButtonState = 0;
|
||||
static bool s_playerVisible = true;
|
||||
static bool s_levelLimit = false;
|
||||
@@ -2543,6 +2591,7 @@ static PyObject* player_ComboAttack(PyObject*, PyObject*) {
|
||||
}
|
||||
|
||||
static PyObject* player_EndKeyWalkingImmediately(PyObject*, PyObject*) {
|
||||
s_movementKeys.fill(false);
|
||||
NEW_CancelFishing();
|
||||
return Py_BuildNone();
|
||||
}
|
||||
@@ -3037,6 +3086,9 @@ static PyObject* player_MoveItem(PyObject*, PyObject* args) {
|
||||
static PyObject* player_OpenCharacterMenu(PyObject*, PyObject* args) {
|
||||
int vid = 0;
|
||||
if (!PyTuple_GetInteger(args, 0, &vid)) return Py_BuildException();
|
||||
if (auto* actor = NetworkActorManager::Instance().GetActorData(uint32_t(vid))) {
|
||||
player_window_call("SetPCTargetBoard", Py_BuildValue("(is)", vid, actor->m_stName.c_str()));
|
||||
}
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -3236,6 +3288,7 @@ static PyObject* player_SetSingleDIKKeyState(PyObject*, PyObject* args) {
|
||||
return Py_BuildException();
|
||||
if (NEW_CancelFishing())
|
||||
return Py_BuildNone();
|
||||
if (dik >= 0 && dik < int(s_movementKeys.size())) s_movementKeys[dik] = pressed != 0;
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -3510,7 +3563,7 @@ void initPlayer() {
|
||||
};
|
||||
NetworkActorManager::SetPartyMemberQuery(IsPartyMemberByVID);
|
||||
NetworkActorManager::SetNPCWearQuery([](uint32_t race, uint8_t wearIndex) {
|
||||
return NonPlayerData::Instance().getNPCWear(int(race), wearIndex, s_warpMapName);
|
||||
return NonPlayerData::Instance().getNPCWear(int(race), wearIndex, CPythonBackground::Instance().GetWarpMapName());
|
||||
});
|
||||
NetworkActorManager::SetItemScaleQuery([](uint32_t vnum, uint32_t pos, float scale[3], float position[3]) {
|
||||
ItemScaleInfo info;
|
||||
|
||||
@@ -42,7 +42,10 @@ void UpdatePartyMemberInfo(uint32_t pid,uint8_t state,uint8_t hp);
|
||||
void UpdatePartyMemberAffect(uint32_t pid,uint8_t slot,int16_t affect);
|
||||
bool GetPartyMemberState(uint32_t pid,uint8_t* state);
|
||||
bool PartyMemberPIDToVID(uint32_t pid,uint32_t* vid);
|
||||
bool PartyMemberVIDToPID(uint32_t vid,uint32_t* pid);
|
||||
bool IsPartyMemberByVID(uint32_t vid);
|
||||
void ClearChestDropInfo(uint32_t chestVnum);
|
||||
void AddChestDropItem(uint32_t chestVnum, uint32_t itemVnum, uint32_t count);
|
||||
void RememberChallengeInstance(uint32_t vid);
|
||||
void RememberRevengeInstance(uint32_t vid);
|
||||
void RememberCantFightInstance(uint32_t vid);
|
||||
@@ -77,10 +80,15 @@ std::string GetWeaponModelPathByVnum(uint32_t vnum);
|
||||
std::vector<Render3DDraw> GetAllActiveChrDraws();
|
||||
|
||||
void SetMainCharacterPosition(float x, float y, float z);
|
||||
void GetMainCharacterPosition(float& x, float& y, float& z);
|
||||
const std::string& GetMainCharacterName();
|
||||
void SetMainCharacterName(const std::string& name);
|
||||
long long GetPlayerStatusPoint(int type);
|
||||
void SetPlayerStatusPoint(int type, long long value);
|
||||
bool GetPlayerMovementYaw(float cameraYaw, float& movementYaw);
|
||||
bool IsPlayerMouseMoving();
|
||||
bool IsPlayerCameraDragging();
|
||||
void CancelPlayerMovement();
|
||||
void SetWeaponPower(uint32_t dwMinPower, uint32_t dwMaxPower, uint32_t dwMinMagicPower, uint32_t dwMaxMagicPower, uint32_t dwAddPower);
|
||||
void UpdateEquippedWeaponPower();
|
||||
bool HasEnoughArrow();
|
||||
|
||||
+28
-3
@@ -4,6 +4,9 @@
|
||||
#include "eter_image/GrpExpandedImageInstance.h"
|
||||
#include "eter_resource/ResourceManager.h"
|
||||
#include "eter_ui/PythonWindow.h"
|
||||
#include "eter_ui/PythonWindowManager.h"
|
||||
#include "eter_render/TextTailManager.h"
|
||||
#include "eter_render/Gr2ModelRenderer.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <Python.h>
|
||||
#include <string>
|
||||
@@ -383,8 +386,11 @@ static PyObject* grpSetEyeCamera(PyObject*, PyObject* poArgs) {
|
||||
|
||||
static PyObject* grpSetPerspective(PyObject*, PyObject* poArgs) {
|
||||
float fov = 0, aspect = 0, zNear = 0, zFar = 0;
|
||||
if (!PyTuple_GetFloat(poArgs, 0, &fov) || !PyTuple_GetFloat(poArgs, 1, &aspect) || !PyTuple_GetFloat(poArgs, 2, &zNear) || !PyTuple_GetFloat(poArgs, 3, &zFar))
|
||||
if (!PyTuple_GetFloat(poArgs, 0, &fov) || !PyTuple_GetFloat(poArgs, 1, &aspect) ||
|
||||
!PyTuple_GetFloat(poArgs, 2, &zNear) || !PyTuple_GetFloat(poArgs, 3, &zFar))
|
||||
return Py_BuildException();
|
||||
auto* renderer3d = TextTailManager::Instance().GetCurrentSceneRenderer();
|
||||
if (renderer3d) renderer3d->SetPerspective(fov, aspect, zNear, zFar);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -572,12 +578,31 @@ static PyObject* grpSetGameRenderState(PyObject*, PyObject*) { return Py_BuildNo
|
||||
|
||||
static PyObject* grpSetViewport(PyObject*, PyObject* poArgs) {
|
||||
float fx = 0, fy = 0, fWidth = 0, fHeight = 0;
|
||||
if (!PyTuple_GetFloat(poArgs, 0, &fx) || !PyTuple_GetFloat(poArgs, 1, &fy) || !PyTuple_GetFloat(poArgs, 2, &fWidth) || !PyTuple_GetFloat(poArgs, 3, &fHeight))
|
||||
if (!PyTuple_GetFloat(poArgs, 0, &fx) || !PyTuple_GetFloat(poArgs, 1, &fy) ||
|
||||
!PyTuple_GetFloat(poArgs, 2, &fWidth) || !PyTuple_GetFloat(poArgs, 3, &fHeight))
|
||||
return Py_BuildException();
|
||||
long sw = UI::CWindowManager::Instance().GetScreenWidth();
|
||||
long sh = UI::CWindowManager::Instance().GetScreenHeight();
|
||||
if (sw <= 0) sw = 1024;
|
||||
if (sh <= 0) sh = 768;
|
||||
int vx = static_cast<int>(fx * sw);
|
||||
int vy = static_cast<int>(fy * sh);
|
||||
int vw = static_cast<int>(fWidth * sw);
|
||||
int vh = static_cast<int>(fHeight * sh);
|
||||
auto* renderer3d = TextTailManager::Instance().GetCurrentSceneRenderer();
|
||||
if (renderer3d) renderer3d->SetViewport(vx, vy, vw, vh);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
static PyObject* grpRestoreViewport(PyObject*, PyObject*) { return Py_BuildNone(); }
|
||||
static PyObject* grpRestoreViewport(PyObject*, PyObject*) {
|
||||
long sw = UI::CWindowManager::Instance().GetScreenWidth();
|
||||
long sh = UI::CWindowManager::Instance().GetScreenHeight();
|
||||
if (sw <= 0) sw = 1024;
|
||||
if (sh <= 0) sh = 768;
|
||||
auto* renderer3d = TextTailManager::Instance().GetCurrentSceneRenderer();
|
||||
if (renderer3d) renderer3d->SetViewport(0, 0, static_cast<int>(sw), static_cast<int>(sh));
|
||||
return Py_BuildNone();
|
||||
}
|
||||
static PyObject* grpSetOmniLight(PyObject*, PyObject*) { return Py_BuildNone(); }
|
||||
|
||||
static PyObject* grpGetCameraPosition(PyObject*, PyObject*) {
|
||||
|
||||
+132
-11
@@ -1,6 +1,9 @@
|
||||
#include "python_ime.h"
|
||||
#include <Python.h>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include "eter_ui/PythonWindowManager.h"
|
||||
|
||||
namespace ava2 {
|
||||
namespace {
|
||||
@@ -11,11 +14,32 @@ int s_user_max = 64;
|
||||
int s_cursor_pos = 0;
|
||||
int s_input_mode = 0;
|
||||
bool s_paste_enabled = true;
|
||||
bool s_capture_input = false;
|
||||
bool s_ime_enabled = false;
|
||||
|
||||
PyObject* ime_enable(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* ime_disable(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* ime_enable_capture_input(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* ime_disable_capture_input(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
void TriggerIMEUpdate() {
|
||||
UI::CWindowManager::Instance().RunIMEUpdate();
|
||||
}
|
||||
|
||||
PyObject* ime_enable(PyObject*, PyObject*) {
|
||||
s_ime_enabled = true;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_disable(PyObject*, PyObject*) {
|
||||
s_ime_enabled = false;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_enable_capture_input(PyObject*, PyObject*) {
|
||||
s_capture_input = true;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_disable_capture_input(PyObject*, PyObject*) {
|
||||
s_capture_input = false;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_set_max(PyObject*, PyObject* args) {
|
||||
if (!PyArg_ParseTuple(args, "i", &s_max)) return nullptr;
|
||||
@@ -63,8 +87,15 @@ PyObject* ime_get_reading_error(PyObject*, PyObject*) {
|
||||
return PyInt_FromLong(0);
|
||||
}
|
||||
|
||||
PyObject* ime_enable_ime(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* ime_disable_ime(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* ime_enable_ime(PyObject*, PyObject*) {
|
||||
s_ime_enabled = true;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_disable_ime(PyObject*, PyObject*) {
|
||||
s_ime_enabled = false;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_get_input_mode(PyObject*, PyObject*) {
|
||||
return PyInt_FromLong(s_input_mode);
|
||||
@@ -75,8 +106,16 @@ PyObject* ime_set_input_mode(PyObject*, PyObject* args) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_set_number_mode(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* ime_set_string_mode(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* ime_set_number_mode(PyObject*, PyObject*) {
|
||||
s_input_mode = 1;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_set_string_mode(PyObject*, PyObject*) {
|
||||
s_input_mode = 0;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_add_except_key(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
PyObject* ime_clear_except_key(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
||||
|
||||
@@ -102,12 +141,16 @@ PyObject* ime_move_end(PyObject*, PyObject*) {
|
||||
|
||||
PyObject* ime_set_cursor_position(PyObject*, PyObject* args) {
|
||||
if (!PyArg_ParseTuple(args, "i", &s_cursor_pos)) return nullptr;
|
||||
if (s_cursor_pos < 0 || s_cursor_pos > static_cast<int>(s_text.length())) {
|
||||
s_cursor_pos = static_cast<int>(s_text.length());
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject* ime_delete(PyObject*, PyObject*) {
|
||||
if (s_cursor_pos < static_cast<int>(s_text.length())) {
|
||||
s_text.erase(s_cursor_pos, 1);
|
||||
TriggerIMEUpdate();
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@@ -115,9 +158,19 @@ PyObject* ime_delete(PyObject*, PyObject*) {
|
||||
PyObject* ime_paste_string(PyObject*, PyObject* args) {
|
||||
const char* str = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "s", &str)) return nullptr;
|
||||
if (str) {
|
||||
s_text.insert(s_cursor_pos, str);
|
||||
s_cursor_pos += static_cast<int>(strlen(str));
|
||||
if (str && s_paste_enabled) {
|
||||
int limit = std::min(s_max, s_user_max);
|
||||
if (limit <= 0) limit = 64;
|
||||
std::string insert_str = str;
|
||||
int remaining = limit - static_cast<int>(s_text.length());
|
||||
if (remaining > 0) {
|
||||
if (static_cast<int>(insert_str.length()) > remaining) {
|
||||
insert_str = insert_str.substr(0, remaining);
|
||||
}
|
||||
s_text.insert(s_cursor_pos, insert_str);
|
||||
s_cursor_pos += static_cast<int>(insert_str.length());
|
||||
TriggerIMEUpdate();
|
||||
}
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@@ -126,6 +179,7 @@ PyObject* ime_paste_backspace(PyObject*, PyObject*) {
|
||||
if (s_cursor_pos > 0 && !s_text.empty()) {
|
||||
s_text.erase(s_cursor_pos - 1, 1);
|
||||
--s_cursor_pos;
|
||||
TriggerIMEUpdate();
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@@ -142,6 +196,73 @@ PyObject* ime_enable_paste(PyObject*, PyObject* args) {
|
||||
|
||||
} // namespace
|
||||
|
||||
void IME_OnChar(char c) {
|
||||
if (!s_capture_input) return;
|
||||
int limit = std::min(s_max, s_user_max);
|
||||
if (limit <= 0) limit = 64;
|
||||
if (static_cast<int>(s_text.length()) >= limit) return;
|
||||
if (s_input_mode == 1) { // number mode
|
||||
if (c < '0' || c > '9') return;
|
||||
}
|
||||
if (s_cursor_pos > static_cast<int>(s_text.length())) s_cursor_pos = static_cast<int>(s_text.length());
|
||||
s_text.insert(s_cursor_pos, 1, c);
|
||||
++s_cursor_pos;
|
||||
TriggerIMEUpdate();
|
||||
}
|
||||
|
||||
void IME_InsertText(const char* text) {
|
||||
if (!text || !s_capture_input) return;
|
||||
int limit = std::min(s_max, s_user_max);
|
||||
if (limit <= 0) limit = 64;
|
||||
while (*text) {
|
||||
if (static_cast<int>(s_text.length()) >= limit) break;
|
||||
char c = *text++;
|
||||
if (s_input_mode == 1 && (c < '0' || c > '9')) continue;
|
||||
if (s_cursor_pos > static_cast<int>(s_text.length())) s_cursor_pos = static_cast<int>(s_text.length());
|
||||
s_text.insert(s_cursor_pos, 1, c);
|
||||
++s_cursor_pos;
|
||||
}
|
||||
TriggerIMEUpdate();
|
||||
}
|
||||
|
||||
void IME_OnBackspace() {
|
||||
if (!s_capture_input) return;
|
||||
if (s_cursor_pos > 0 && !s_text.empty()) {
|
||||
if (s_cursor_pos > static_cast<int>(s_text.length())) s_cursor_pos = static_cast<int>(s_text.length());
|
||||
s_text.erase(s_cursor_pos - 1, 1);
|
||||
--s_cursor_pos;
|
||||
TriggerIMEUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void IME_OnDelete() {
|
||||
if (!s_capture_input) return;
|
||||
if (s_cursor_pos < static_cast<int>(s_text.length())) {
|
||||
s_text.erase(s_cursor_pos, 1);
|
||||
TriggerIMEUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void IME_MoveLeft() {
|
||||
if (s_cursor_pos > 0) --s_cursor_pos;
|
||||
}
|
||||
|
||||
void IME_MoveRight() {
|
||||
if (s_cursor_pos < static_cast<int>(s_text.length())) ++s_cursor_pos;
|
||||
}
|
||||
|
||||
void IME_MoveHome() {
|
||||
s_cursor_pos = 0;
|
||||
}
|
||||
|
||||
void IME_MoveEnd() {
|
||||
s_cursor_pos = static_cast<int>(s_text.length());
|
||||
}
|
||||
|
||||
bool IME_IsCaptureInput() {
|
||||
return s_capture_input;
|
||||
}
|
||||
|
||||
void initime() {
|
||||
static PyMethodDef methods[] = {
|
||||
{"Enable", ime_enable, METH_VARARGS, nullptr},
|
||||
|
||||
@@ -4,4 +4,14 @@ namespace ava2 {
|
||||
|
||||
void initime();
|
||||
|
||||
void IME_OnChar(char c);
|
||||
void IME_InsertText(const char* text);
|
||||
void IME_OnBackspace();
|
||||
void IME_OnDelete();
|
||||
void IME_MoveLeft();
|
||||
void IME_MoveRight();
|
||||
void IME_MoveHome();
|
||||
void IME_MoveEnd();
|
||||
bool IME_IsCaptureInput();
|
||||
|
||||
} // namespace ava2
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "guild_state.h"
|
||||
#include "eter_net/NetworkActorManager.h"
|
||||
#include "eter_resource/ResourceManager.h"
|
||||
#include "eter_image/GrpDevice.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include "eter_image/GrpImage.h"
|
||||
#include "shared/common/PythonUtils.h"
|
||||
#include <algorithm>
|
||||
@@ -305,6 +307,53 @@ void CPythonMiniMap::Render(float fScreenX, float fScreenY)
|
||||
__SetPosition();
|
||||
}
|
||||
|
||||
// Draw the native terrain minimap tiles under the existing player/NPC marks.
|
||||
auto* device = CGraphicDevice::InstancePtr();
|
||||
if (auto* renderer = device ? device->GetRenderer() : nullptr) {
|
||||
const auto* map = GetOutdoorMap();
|
||||
const int width = int(m_fWidth), height = int(m_fHeight);
|
||||
if (width > 0 && height > 0) {
|
||||
if (!m_terrainTexture || width != m_terrainWidth || height != m_terrainHeight) {
|
||||
SDL_DestroyTexture(m_terrainTexture);
|
||||
m_terrainTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||
m_terrainWidth = width; m_terrainHeight = height;
|
||||
if (m_terrainTexture) SDL_SetTextureBlendMode(m_terrainTexture, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
std::vector<uint8_t> pixels(size_t(width) * height * 4);
|
||||
std::map<std::pair<int, int>, CGraphicImage*> tiles;
|
||||
const float units = CELLSCALE / m_fScale;
|
||||
for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) {
|
||||
const float dx = x + 0.5f - width * 0.5f, dy = y + 0.5f - height * 0.5f;
|
||||
if (dx * dx + dy * dy > m_fMiniMapRadius * m_fMiniMapRadius) continue;
|
||||
const float wx = m_fCenterX + dx * units, wy = m_fCenterY + dy * units;
|
||||
const int bx = int(std::floor(wx / TERRAIN_SIZE)), by = int(std::floor(wy / TERRAIN_SIZE));
|
||||
if (bx < 0 || by < 0 || bx >= map->terrainCountX || by >= map->terrainCountY) continue;
|
||||
const auto key = std::make_pair(bx, by);
|
||||
if (!tiles.count(key)) {
|
||||
char block[32]; snprintf(block, sizeof(block), "/%03d%03d/minimap.dds", bx, by);
|
||||
auto* image = LoadImagePointer((map->name + block).c_str());
|
||||
if (!image) image = LoadImagePointer(("map/" + map->name + block).c_str());
|
||||
tiles[key] = image;
|
||||
}
|
||||
auto* image = tiles[key];
|
||||
if (!image || image->IsEmpty()) continue;
|
||||
const auto& texture = image->GetTextureReference();
|
||||
const int tx = std::clamp(int((wx - bx * TERRAIN_SIZE) / TERRAIN_SIZE * texture.GetWidth()), 0, texture.GetWidth() - 1);
|
||||
const int ty = std::clamp(int((wy - by * TERRAIN_SIZE) / TERRAIN_SIZE * texture.GetHeight()), 0, texture.GetHeight() - 1);
|
||||
const size_t source = (size_t(ty) * texture.GetWidth() + tx) * 4, target = (size_t(y) * width + x) * 4;
|
||||
const auto& rgba = texture.GetPixels();
|
||||
if (source + 3 < rgba.size()) {
|
||||
std::copy_n(rgba.data() + source, 3, pixels.data() + target);
|
||||
pixels[target + 3] = 255;
|
||||
}
|
||||
}
|
||||
if (m_terrainTexture) {
|
||||
SDL_UpdateTexture(m_terrainTexture, nullptr, pixels.data(), width * 4);
|
||||
SDL_FRect destination{fScreenX, fScreenY, float(width), float(height)};
|
||||
SDL_RenderTexture(renderer, m_terrainTexture, nullptr, &destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& rPosition : m_OtherPCPositionVector)
|
||||
{
|
||||
m_WhiteMark.SetPosition(rPosition.m_fX, rPosition.m_fY);
|
||||
@@ -1030,6 +1079,9 @@ void CPythonMiniMap::__Initialize()
|
||||
|
||||
void CPythonMiniMap::Destroy()
|
||||
{
|
||||
SDL_DestroyTexture(m_terrainTexture);
|
||||
m_terrainTexture = nullptr;
|
||||
m_terrainWidth = m_terrainHeight = 0;
|
||||
ClearAllSignalPoint();
|
||||
m_poHandler = 0;
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// Provenance: AVA2 UserInterface/PythonMiniMap.{h,cpp} and PythonMiniMapModule.cpp, compiled with the
|
||||
// Locale_inc.h set ENABLE_MINIMAP_WHITEMARK_NEW, NAMECOLOR_BOSS_CLIENT, ENABLE_STONEMINIMAP,
|
||||
// ENABLE_OFFLINESHOP_SYSTEM and ENABLE_GRAPHIC_ON_OFF; WJ_COMBAT_ZONE is off.
|
||||
// The D3D minimap texture/vertex pipeline (Create's buffers, Render, RenderAtlas) is not ported: the
|
||||
// state, mark lists, picking and atlas bookkeeping are, so GetInfo/GetAtlasInfo answer like Windows.
|
||||
// Native minimap terrain tiles are sampled through SDL; mark lists, picking and atlas
|
||||
// bookkeeping preserve the Windows behavior. The D3D atlas vertex pipeline is not ported.
|
||||
#include <Python.h>
|
||||
#include "eter_image/GrpImageInstance.h"
|
||||
#include <cstdint>
|
||||
@@ -262,6 +262,8 @@ protected:
|
||||
|
||||
PyObject* m_poHandler;
|
||||
uint32_t (*m_now)() = nullptr;
|
||||
SDL_Texture* m_terrainTexture = nullptr;
|
||||
int m_terrainWidth = 0, m_terrainHeight = 0;
|
||||
};
|
||||
|
||||
void initMiniMap();
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <cstdio>
|
||||
#include "Poly.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "player_settings.h"
|
||||
#include "eter_ui/PythonWindow.h"
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
#include "skill_description.h"
|
||||
@@ -611,6 +613,20 @@ static PyObject* texttail_register_item(PyObject*, PyObject* args) {
|
||||
}
|
||||
|
||||
void initTextTail() {
|
||||
// Use the same FreeType font path as UI text, preserving the Retina render
|
||||
// scale. SDL_RenderDebugText's fixed bitmap font is only a host fallback.
|
||||
TextTailManager::Instance().SetTextPainter(
|
||||
[](float x,float y,const std::string& value,uint32_t color,float scale,bool outline) {
|
||||
UI::CGraphicTextInstance text;
|
||||
text.SetFontName(("Tahoma:" + std::to_string(int(12 * scale))).c_str());
|
||||
text.SetValue(value.c_str()); text.SetFontColor(color);
|
||||
text.SetPosition(x,y); text.SetOutline(outline); text.Render();
|
||||
},
|
||||
[](const std::string& value,float scale) {
|
||||
UI::CGraphicTextInstance text;
|
||||
text.SetFontName(("Tahoma:" + std::to_string(int(12 * scale))).c_str());
|
||||
text.SetValue(value.c_str()); int width=0; text.GetTextSize(&width,nullptr); return float(width);
|
||||
});
|
||||
static PyMethodDef methods[] = {
|
||||
{"Clear", texttail_clear, METH_VARARGS, nullptr},
|
||||
{"UpdateAllTextTail", texttail_update_all, METH_VARARGS, nullptr},
|
||||
@@ -1469,6 +1485,7 @@ static PyObject* playerLoad_RegisterSkill(PyObject*, PyObject* args) {
|
||||
uint8_t bRaceIndex = 0, bSkillGroupIndex = 0, bEmpireIndex = 0;
|
||||
if (!PyTuple_GetByte(args, 0, &bRaceIndex) || !PyTuple_GetByte(args, 1, &bSkillGroupIndex) || !PyTuple_GetByte(args, 2, &bEmpireIndex))
|
||||
return Py_BuildException();
|
||||
RegisterPlayerSkills(bRaceIndex, bSkillGroupIndex, bEmpireIndex);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
|
||||
+37
-5
@@ -1,4 +1,5 @@
|
||||
#include "python_net.h"
|
||||
#include "python_app.h"
|
||||
#include "guild_state.h"
|
||||
#include "python_gameplay_modules.h"
|
||||
#include "login_client.h"
|
||||
@@ -45,7 +46,18 @@ void callback(PyObject* target,const char* name,const char* text=nullptr) {
|
||||
|
||||
PyObject* set_handler(PyObject*,PyObject* args) { PyObject* value;if(!PyArg_ParseTuple(args,"O",&value)) return nullptr;replace(handler,value);PythonNetworkStream::Instance().SetHandler(value);Py_RETURN_NONE; }
|
||||
PyObject* set_account_handler(PyObject*,PyObject* args) { PyObject* value;if(!PyArg_ParseTuple(args,"O",&value)) return nullptr;replace(account_handler,value);Py_RETURN_NONE; }
|
||||
PyObject* set_phase(PyObject*,PyObject* args) { int phase;PyObject* value;if(!PyArg_ParseTuple(args,"iO",&phase,&value)) return nullptr;if(phase<0 || phase>=7) { PyErr_SetString(PyExc_ValueError,"invalid phase window");return nullptr; }replace(phases[phase],value);PythonNetworkStream::Instance().SetPhaseWindow(phase, value);Py_RETURN_NONE; }
|
||||
PyObject* set_phase(PyObject*,PyObject* args) { int phase;PyObject* value;if(!PyArg_ParseTuple(args,"iO",&phase,&value)) return nullptr;if(phase<0 || phase>=7) { PyErr_SetString(PyExc_ValueError,"invalid phase window");return nullptr; }// Release both native owners before installing a successor: old LoadingWindow
|
||||
// __del__ calls SetPhaseWindow(LOAD, 0), which otherwise unregisters the new one.
|
||||
if(value==Py_None || (value && PyInt_Check(value) && PyInt_AsLong(value)==0)) value=nullptr;
|
||||
if(phases[phase]==value) Py_RETURN_NONE;
|
||||
Py_XINCREF(value);
|
||||
auto* previous=phases[phase]; phases[phase]=nullptr;
|
||||
PythonNetworkStream::Instance().SetPhaseWindow(phase,nullptr);
|
||||
Py_XDECREF(previous);
|
||||
replace(phases[phase],value);
|
||||
PythonNetworkStream::Instance().SetPhaseWindow(phase,value);
|
||||
Py_XDECREF(value);
|
||||
Py_RETURN_NONE; }
|
||||
PyObject* clear_phase(PyObject*,PyObject* args) { int phase;PyObject* value;if(!PyArg_ParseTuple(args,"iO",&phase,&value)) return nullptr;if(phase<0 || phase>=7) { PyErr_SetString(PyExc_ValueError,"invalid phase window");return nullptr; }if(phases[phase]==value) { replace(phases[phase],nullptr);PythonNetworkStream::Instance().ClearPhaseWindow(phase, value); }Py_RETURN_NONE; }
|
||||
PyObject* set_login(PyObject*,PyObject* args) { const char* id;const char* pass;if(!PyArg_ParseTuple(args,"ss",&id,&pass)) return nullptr;account=id;password=pass;Py_RETURN_NONE; }
|
||||
PyObject* connect(PyObject*,PyObject* args) {
|
||||
@@ -62,6 +74,10 @@ PyObject* select(PyObject*,PyObject* args) {
|
||||
if(!PyArg_ParseTuple(args,"i",&slot)) return nullptr;
|
||||
if(slot<0 || slot>=5) { PyErr_SetString(PyExc_ValueError,"invalid character slot");return nullptr; }
|
||||
if(has_mock_characters) Py_RETURN_NONE;
|
||||
if(client.is_direct_enter()) {
|
||||
// DirectEnter already executed the character selection on the map core
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
try { client.select(slot);Py_RETURN_NONE; }
|
||||
catch(const std::exception& e) { PyErr_SetString(PyExc_ValueError,e.what());return nullptr; }
|
||||
}
|
||||
@@ -180,9 +196,9 @@ PyObject* netSendMessengerRemovePacket(PyObject*, PyObject* poArgs) {
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
// IAbstractPlayer::PartyMemberVIDToPID. The port does not track party members yet
|
||||
// (player.IsPartyMember is still a placeholder), so the lookup fails like an empty party.
|
||||
bool party_member_vid_to_pid(uint32_t, uint32_t*) { return false; }
|
||||
static inline bool party_member_vid_to_pid(uint32_t vid, uint32_t* pid) {
|
||||
return PartyMemberVIDToPID(vid, pid);
|
||||
}
|
||||
|
||||
PyObject* netSendPartyInvitePacket(PyObject*, PyObject* poArgs) {
|
||||
int vid;
|
||||
@@ -896,14 +912,17 @@ static PyObject* net_SetUDPRecvBufferSize(PyObject*, PyObject* poArgs) {
|
||||
}
|
||||
|
||||
static PyObject* net_LogOutGame(PyObject*, PyObject*) {
|
||||
PythonNetworkStream::Instance().SendChatPacket("/logout");
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
static PyObject* net_ExitGame(PyObject*, PyObject*) {
|
||||
PythonNetworkStream::Instance().SendChatPacket("/phase_select");
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
static PyObject* net_ExitApplication(PyObject*, PyObject*) {
|
||||
PythonNetworkStream::Instance().SendChatPacket("/quit");
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -1022,10 +1041,12 @@ static PyObject* net_SendAddOfflineShopItem(PyObject*, PyObject* poArgs) {
|
||||
!PyTuple_GetLongLong(poArgs, 2, &iPrice) ||
|
||||
!PyTuple_GetInteger(poArgs, 3, &bWindowType))
|
||||
return Py_BuildException();
|
||||
PythonNetworkStream::Instance().SendAddOfflineShopItem(TItemPos{uint8_t(bWindowType), uint16_t(bDisplayPos)}, uint8_t(bPos), iPrice);
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
static PyObject* net_SendTakeOfflineMoney(PyObject*, PyObject*) {
|
||||
PythonNetworkStream::Instance().SendTakeOfflineMoney();
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -1033,14 +1054,17 @@ static PyObject* net_SendOfflineShopChangeTitle(PyObject*, PyObject* poArgs) {
|
||||
char* title = nullptr;
|
||||
if (!PyTuple_GetString(poArgs, 0, &title))
|
||||
return Py_BuildException();
|
||||
PythonNetworkStream::Instance().SendOfflineShopChangeTitle(title ? title : "");
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
static PyObject* net_SendOfflineShopCheck(PyObject*, PyObject*) {
|
||||
PythonNetworkStream::Instance().SendOfflineShopCheck();
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
static PyObject* net_SendOfflineShopButton(PyObject*, PyObject*) {
|
||||
PythonNetworkStream::Instance().SendOfflineShopButton();
|
||||
return Py_BuildNone();
|
||||
}
|
||||
|
||||
@@ -1368,6 +1392,14 @@ void set_mock_empire(std::uint8_t empire) {
|
||||
|
||||
void pump_python_net() {
|
||||
client.pump();
|
||||
static uint64_t bootstrapClockGeneration=0;
|
||||
uint32_t serverMS=0;
|
||||
if(client.status()==LoginClient::Status::Loading && client.generation()!=bootstrapClockGeneration &&
|
||||
client.session() && client.session()->server_milliseconds(serverMS)) {
|
||||
SetServerMSec(serverMS);
|
||||
bootstrapClockGeneration=client.generation();
|
||||
SDL_Log("Game clock synchronized from login handshake: %u",serverMS);
|
||||
}
|
||||
auto events = client.take_events();
|
||||
for(const auto& event : events) {
|
||||
if(event.generation != client.generation()) continue;
|
||||
@@ -1380,7 +1412,7 @@ void pump_python_net() {
|
||||
} else if(event.type == LoginClient::EventType::DirectEnterReady) callback(handler, "SetLoadingPhase");
|
||||
else if(event.type == LoginClient::EventType::Loading) {
|
||||
PythonNetworkStream::Instance().SetPhase(PHASE_LOADING);
|
||||
if(!client.is_direct_enter()) callback(handler,"SetLoadingPhase");
|
||||
callback(handler,"SetLoadingPhase");
|
||||
}
|
||||
else {
|
||||
auto* target = account_handler ? account_handler : phases[1];
|
||||
|
||||
+55
-15
@@ -4,6 +4,7 @@
|
||||
#include "src/eter_image/GrpExpandedImageInstance.h"
|
||||
#include "src/eter_image/GrpMarkInstance.h"
|
||||
#include "python_runtime.h"
|
||||
#include "python_minimap.h"
|
||||
#include "quest_state.h"
|
||||
#include "guild_state.h"
|
||||
#include "battlepass_state.h"
|
||||
@@ -39,22 +40,31 @@ std::filesystem::path resolve(const char* name) {
|
||||
std::filesystem::path rel(normalized);
|
||||
if(rel.is_absolute()) throw std::invalid_argument("pack path must be relative");
|
||||
for(const auto& part:rel) if(part=="..") throw std::invalid_argument("pack traversal rejected");
|
||||
auto current=pack_root;
|
||||
for(const auto& part:rel) {
|
||||
if(part=="." || part.empty()) continue;
|
||||
auto wanted=part.string();std::transform(wanted.begin(),wanted.end(),wanted.begin(),[](unsigned char c){return std::tolower(c);});
|
||||
bool found=false; std::filesystem::path match;
|
||||
if(!std::filesystem::is_directory(current)) throw std::runtime_error("pack path not found");
|
||||
for(const auto& entry:std::filesystem::directory_iterator(current)) {
|
||||
auto candidate=entry.path().filename().string();std::transform(candidate.begin(),candidate.end(),candidate.begin(),[](unsigned char c){return std::tolower(c);});
|
||||
if(candidate==wanted) { if(found) throw std::runtime_error("ambiguous case-insensitive pack path");match=entry.path();found=true; }
|
||||
std::vector<std::filesystem::path> mounts{pack_root};
|
||||
// The bundle keeps scripts in root/ and the other virtual packs beside it.
|
||||
if (pack_root.filename()=="root" && std::filesystem::is_regular_file(pack_root.parent_path()/"asset_manifest.json"))
|
||||
mounts.push_back(pack_root.parent_path());
|
||||
for (const auto& mount:mounts) {
|
||||
auto current=mount;
|
||||
bool missing=false;
|
||||
for(const auto& part:rel) {
|
||||
if(part=="." || part.empty()) continue;
|
||||
if(!std::filesystem::is_directory(current)) {missing=true;break;}
|
||||
auto wanted=part.string();std::transform(wanted.begin(),wanted.end(),wanted.begin(),[](unsigned char c){return std::tolower(c);});
|
||||
bool found=false;std::filesystem::path match;
|
||||
for(const auto& entry:std::filesystem::directory_iterator(current)) {
|
||||
auto candidate=entry.path().filename().string();std::transform(candidate.begin(),candidate.end(),candidate.begin(),[](unsigned char c){return std::tolower(c);});
|
||||
if(candidate==wanted) {if(found) throw std::runtime_error("ambiguous case-insensitive pack path");match=entry.path();found=true;}
|
||||
}
|
||||
if(!found) {missing=true;break;}
|
||||
current=match;
|
||||
}
|
||||
if(!found) throw std::runtime_error("pack path not found");
|
||||
current=match;
|
||||
if(missing) continue;
|
||||
auto canonical=std::filesystem::canonical(current);auto relative=canonical.lexically_relative(mount);
|
||||
if(relative.empty() || *relative.begin()=="..") throw std::runtime_error("pack path escapes mount");
|
||||
return canonical;
|
||||
}
|
||||
auto canonical=std::filesystem::canonical(current);auto relative=canonical.lexically_relative(pack_root);
|
||||
if(relative.empty() || *relative.begin()=="..") throw std::runtime_error("pack path escapes mount");
|
||||
return canonical;
|
||||
throw std::runtime_error("pack path not found");
|
||||
}
|
||||
PyObject* pack_exist(PyObject*,PyObject* args) {
|
||||
const char* name=nullptr;if(!PyArg_ParseTuple(args,"s",&name)) return nullptr;
|
||||
@@ -247,12 +257,14 @@ sys.meta_path.insert(0, _AVA2PackImporter())
|
||||
// The event sets hold weak references to Python objects.
|
||||
CPythonEventManager::Instance().Destroy();CPythonChat::Instance().Destroy();CPythonSystem::Instance().Clear();
|
||||
CPythonEventManager::Instance().SetInterfaceWindow(nullptr);
|
||||
clear_compiled_code();
|
||||
Py_Finalize();
|
||||
if (m_windowManager)
|
||||
{
|
||||
m_windowManager->Destroy();
|
||||
m_windowManager.reset();
|
||||
}
|
||||
CPythonMiniMap::Instance().Destroy();
|
||||
CGraphicExpandedImageInstance::DestroySystem();
|
||||
CGraphicImageInstance::DestroySystem();
|
||||
CGraphicMarkInstance::DestroySystem();
|
||||
@@ -278,12 +290,14 @@ PythonRuntime::~PythonRuntime() {
|
||||
// The event sets hold weak references to Python objects.
|
||||
CPythonEventManager::Instance().Destroy();CPythonChat::Instance().Destroy();CPythonSystem::Instance().Clear();
|
||||
CPythonEventManager::Instance().SetInterfaceWindow(nullptr);
|
||||
clear_compiled_code();
|
||||
Py_Finalize();
|
||||
if (m_windowManager)
|
||||
{
|
||||
m_windowManager->Destroy();
|
||||
m_windowManager.reset();
|
||||
}
|
||||
CPythonMiniMap::Instance().Destroy();
|
||||
CGraphicExpandedImageInstance::DestroySystem();
|
||||
CGraphicImageInstance::DestroySystem();
|
||||
CGraphicMarkInstance::DestroySystem();
|
||||
@@ -294,7 +308,33 @@ PythonRuntime::~PythonRuntime() {
|
||||
}
|
||||
pack_root.clear();
|
||||
}
|
||||
void PythonRuntime::execute(const std::string& code) { if(PyRun_SimpleString(code.c_str())!=0) throw std::runtime_error("embedded Python execution failed (see traceback)"); }
|
||||
void PythonRuntime::clear_compiled_code() {
|
||||
for(auto& entry:m_compiledCode)Py_DECREF(entry.object);
|
||||
m_compiledCode.clear();m_compiledBytes=0;
|
||||
}
|
||||
void PythonRuntime::execute(const std::string& source) {
|
||||
PyObject* code=nullptr;
|
||||
for(auto it=m_compiledCode.begin();it!=m_compiledCode.end();++it) {
|
||||
if(it->source!=source)continue;
|
||||
code=it->object;Py_INCREF(code);m_compiledCode.splice(m_compiledCode.begin(),m_compiledCode,it);break;
|
||||
}
|
||||
if(!code) {
|
||||
code=Py_CompileString(source.c_str(),"<string>",Py_file_input);++m_compileCount;
|
||||
if(!code){PyErr_Print();throw std::runtime_error("embedded Python execution failed (see traceback)");}
|
||||
if(source.size()<=16u*1024u) {
|
||||
Py_INCREF(code);m_compiledCode.push_front({source,code});m_compiledBytes+=source.size();
|
||||
while(m_compiledCode.size()>64 || m_compiledBytes>128u*1024u) {
|
||||
auto& entry=m_compiledCode.back();m_compiledBytes-=entry.source.size();Py_DECREF(entry.object);m_compiledCode.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
auto* module=PyImport_AddModule("__main__");
|
||||
auto* globals=module ? PyModule_GetDict(module) : nullptr;
|
||||
auto* result=globals ? PyEval_EvalCode(reinterpret_cast<PyCodeObject*>(code),globals,globals) : nullptr;
|
||||
Py_DECREF(code);
|
||||
if(!result){PyErr_Print();throw std::runtime_error("embedded Python execution failed (see traceback)");}
|
||||
Py_DECREF(result);
|
||||
}
|
||||
}
|
||||
|
||||
namespace ava2 {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
struct _object;
|
||||
namespace UI { class CWindowManager; }
|
||||
class CResourceManager;
|
||||
|
||||
@@ -13,6 +15,10 @@ struct LoginViewSnapshot {
|
||||
std::string phase,message;int selected=-1;std::vector<Slot> slots;
|
||||
};
|
||||
class PythonRuntime {
|
||||
struct CompiledCode {std::string source; _object* object;};
|
||||
std::list<CompiledCode> m_compiledCode;
|
||||
size_t m_compiledBytes=0, m_compileCount=0;
|
||||
void clear_compiled_code();
|
||||
std::unique_ptr<CResourceManager> m_resourceManager;
|
||||
std::unique_ptr<UI::CWindowManager> m_windowManager;
|
||||
public:
|
||||
@@ -21,6 +27,9 @@ public:
|
||||
PythonRuntime(const PythonRuntime&)=delete;
|
||||
PythonRuntime& operator=(const PythonRuntime&)=delete;
|
||||
void execute(const std::string& code);
|
||||
size_t compiled_code_count() const { return m_compiledCode.size(); }
|
||||
size_t compiled_code_bytes() const { return m_compiledBytes; }
|
||||
size_t compilation_count() const { return m_compileCount; }
|
||||
void load_login_view(const std::filesystem::path& file);
|
||||
void connect_view(const std::string& game_host,int game_port,const std::string& auth_host,int auth_port,const std::string& account,const std::string& password);
|
||||
void view_action(const char* method,int value=-1);
|
||||
|
||||
@@ -347,6 +347,7 @@ void CPythonSystem::SetDefaultConfig()
|
||||
m_Config.bDecompressDDS = 0;
|
||||
m_Config.bSoftwareTiling = 0;
|
||||
m_Config.iShadowLevel = 3;
|
||||
m_Config.bShowShadow = true;
|
||||
m_Config.bViewChat = true;
|
||||
m_Config.bAlwaysShowName = DEFAULT_VALUE_ALWAYS_SHOW_NAME;
|
||||
m_Config.bShowDamage = true;
|
||||
|
||||
Reference in New Issue
Block a user