Compare commits
3
Commits
71f393bbd1
...
7236edf747
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7236edf747 | ||
|
|
bfd42bd776 | ||
|
|
6282199179 |
+24
-1
@@ -1069,7 +1069,7 @@ item:
|
||||
(`CGrannyLODController::UpdateLODLevel` + `CGrannyModelInstance::Update`):
|
||||
only models with a `_lod_01.gr2` sibling, more than 500 units from the camera
|
||||
target, 30-120 FPS by camera distance over 5000 (25000 for models of 500+
|
||||
units). The `_lod_` meshes are still not swapped in.
|
||||
units). The `_lod_` meshes are now swapped in too; see the follow-up below.
|
||||
|
||||
GPU skinning limit reviewed, not changed: 36 of 3755 skinned models in pc*,
|
||||
monster*, npc*, npc_mount and npc_pet exceed 128 bones (bosses, metin stones,
|
||||
@@ -1081,3 +1081,26 @@ Verified: Debug macOS/Metal build, 50/50 CTests (new regressions for
|
||||
`FlattenDraws`, scaled-scene compositing and LOD animation rate). Not verified:
|
||||
in-game frame-time capture and 3D screenshots (no server in this session), and
|
||||
any Vulkan/Android device run.
|
||||
|
||||
### 2026-10-12 FPS pass 2 follow-up: real-time clocks and LOD meshes
|
||||
|
||||
- Animation clocks follow real frame time: `main.cpp` sums the frame delta into
|
||||
a game clock (still fixed at 0.033 s per frame under `--frames`) for water,
|
||||
network actors, `FlyingManager` and weapon traces; the skybox,
|
||||
`effect.Update`/`fly.Update` (`app.GetGameFrameDelta`) and `CRenderTarget`
|
||||
previews (elapsed `SDL_GetTicksNS`, clamped to 0.25 s) use real deltas.
|
||||
The SpeedTree `UpdateSystem(0.033f)` wind clock is unchanged (SDK work pending).
|
||||
- Actor bodies swap to `_lod_01.._03` meshes (`CGrannyLODController`): queue
|
||||
`{lod_03, lod_02, lod_01, main}`, lazy loading, the original distance bands
|
||||
(including the BYTE wrap for a single LOD) and the building factor. Parts,
|
||||
`.msm` skins and the current motion follow the drawn instance.
|
||||
- 9 of 1739 shipped LODs drop an attaching bone (`lion2_lod_02/03` lose
|
||||
`saddle`; `shaman_miyeom_lod_*`, `mutant_1/2`, `gold_monkey` and
|
||||
`assassin_easter_day_2016` `_lod_01` lose `equip_*`). Such a level stays on
|
||||
PART_MAIN while that bone is in use, and bone queries fall back to PART_MAIN.
|
||||
- Not ported: weapon/item LOD models; helper attachments made outside the part
|
||||
slots are still dropped on rebind (as before).
|
||||
|
||||
Verified: Debug macOS/Metal build, 50/50 CTests (`render_3d` covers the LOD
|
||||
bands, the 30 FPS far pose rate on `_lod_03` and the `lion2` saddle fallback).
|
||||
Not verified: in-game or device visuals (no server in this session).
|
||||
|
||||
+9
-8
@@ -370,6 +370,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
bool running = true, requested = false, entered = false;
|
||||
int frames = 0, focus = 4;
|
||||
float game_clock = 0.0f; // seconds of game time (sum of dt); deterministic under --frames
|
||||
std::string local_error, last_phase;
|
||||
auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(60);
|
||||
|
||||
@@ -1686,6 +1687,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
prev_frame_time = cur_time;
|
||||
if (frame_limit > 0) dt = 0.033f;
|
||||
else dt = std::clamp(dt, 0.001f, 0.25f);
|
||||
game_clock += dt;
|
||||
|
||||
#ifdef AVA2_HAS_PYTHON
|
||||
if (python) {
|
||||
@@ -1819,7 +1821,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
ava2::SoundManager::Instance().SetPosition(player_actor.GetX(), player_actor.GetY(), player_actor.GetZ());
|
||||
ava2::SoundManager::Instance().Update(dt);
|
||||
ava2::EffectManager::Instance().Update(dt);
|
||||
ava2::FlyingManager::Instance().Update(dt, static_cast<float>(frames) / 60.0f);
|
||||
ava2::FlyingManager::Instance().Update(dt, game_clock);
|
||||
|
||||
// Drive PythonNetworkStream and NetworkActorManager
|
||||
ava2::PythonNetworkStream::Instance().ProcessRecvData();
|
||||
@@ -1854,7 +1856,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
if (player_actor.IsAttacking()) {
|
||||
float bx, by, bz;
|
||||
if (player_actor.GetBonePosition("equip_right_hand", bx, by, bz)) {
|
||||
player_weapon_trace.UpdateNewPosition(bx, by, bz, static_cast<float>(frames) / 60.0f);
|
||||
player_weapon_trace.UpdateNewPosition(bx, by, bz, game_clock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1972,7 +1974,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
const auto profileBuildStart = std::chrono::steady_clock::now();
|
||||
if (last_phase == "game") {
|
||||
// Update outdoor SkyBox, Clouds UV scrolling & dynamic environment
|
||||
outdoor_skybox.Update(0.033f);
|
||||
outdoor_skybox.Update(dt);
|
||||
outdoor_forest.UpdateSystem(0.033f);
|
||||
|
||||
// Atmospheric Environment Fog (modeled after 40250 CMapOutdoor & .msenv)
|
||||
@@ -2057,8 +2059,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
|
||||
// Add water surface (translucent, animated)
|
||||
if (outdoor_water.HasWater()) {
|
||||
float anim_time = static_cast<float>(frames) * 0.033f;
|
||||
auto water_draw = outdoor_water.BuildDrawCommand(anim_time);
|
||||
auto water_draw = outdoor_water.BuildDrawCommand(game_clock);
|
||||
draws.push_back(std::move(water_draw));
|
||||
}
|
||||
|
||||
@@ -2113,7 +2114,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
auto dog_draws = preview_data ? mob_dog.BuildDrawCommands() : std::vector<ava2::Render3DDraw>{};
|
||||
auto metin_draws = preview_data ? mob_metin.BuildDrawCommands() : std::vector<ava2::Render3DDraw>{};
|
||||
ava2::NetworkActorManager::Instance().UpdateLODLevel(eyeX, eyeY, eyeZ, player_world_x, player_world_z);
|
||||
auto net_draws = ava2::NetworkActorManager::Instance().BuildDrawCommands(static_cast<float>(frames) * 0.033f, renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix());
|
||||
auto net_draws = ava2::NetworkActorManager::Instance().BuildDrawCommands(game_clock, renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix());
|
||||
if (until_game && rendered_game_frames == 20) {
|
||||
for (const auto& entry : ava2::NetworkActorManager::Instance().GetActorDict()) {
|
||||
const auto& npc=entry.second;
|
||||
@@ -2161,9 +2162,9 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
|
||||
// Add Particle effects, projectiles, and weapon ribbon trails
|
||||
float camPos[3] = {eyeX, eyeY, eyeZ};
|
||||
ava2::EffectManager::Instance().BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), camPos, draws);
|
||||
ava2::FlyingManager::Instance().BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), static_cast<float>(frames) / 60.0f, draws);
|
||||
ava2::FlyingManager::Instance().BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), game_clock, draws);
|
||||
if (!player_weapon_trace.IsEmpty()) {
|
||||
player_weapon_trace.BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), static_cast<float>(frames) / 60.0f, draws);
|
||||
player_weapon_trace.BuildDrawCommands(renderer3d->GetViewMatrix(), renderer3d->GetProjMatrix(), game_clock, draws);
|
||||
}
|
||||
} else {
|
||||
renderer3d->SetFog(false);
|
||||
|
||||
@@ -52,32 +52,102 @@ void ActorInstance::SetMainModel(std::shared_ptr<Gr2ModelInstance> model, const
|
||||
auto it = m_motionPaths.find(m_currentMotion);
|
||||
if (it != m_motionPaths.end()) {
|
||||
std::string resolved = ResolvePath(it->second);
|
||||
if (m_model->LoadExternalAnimation(resolved))
|
||||
if (m_model->LoadExternalAnimation(resolved)) {
|
||||
m_motionFile = resolved;
|
||||
m_motionDuration = std::max(0.1f, m_model->GetAnimationDuration());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Re-attaches the part slots to PART_MAIN: hair deforms with the main skeleton, the others follow
|
||||
// their attaching bone; PART_SASH also takes the ENABLE_OBJ_SCALLING scale matrix.
|
||||
// their attaching bone; PART_SASH also takes the ENABLE_OBJ_SCALLING scale matrix. Parts follow the
|
||||
// current LOD instance (pSkelController->m_pCurrentModelInstance / AttachModelInstance).
|
||||
void ActorInstance::RebindParts() {
|
||||
if (!m_model) return;
|
||||
m_model->DetachAll();
|
||||
for (auto& lod : m_lodModels)
|
||||
if (lod.model) lod.model->DetachAll();
|
||||
Gr2ModelInstance* target = DrawModel();
|
||||
for (uint32_t part = 1; part < kPartCount; ++part) {
|
||||
const auto& slot = m_parts[part];
|
||||
if (!slot.model) continue;
|
||||
if (slot.bone.empty()) {
|
||||
m_model->AttachPart(slot.model);
|
||||
target->AttachPart(slot.model);
|
||||
continue;
|
||||
}
|
||||
m_model->AttachModel(slot.bone, slot.model);
|
||||
target->AttachModel(slot.bone, slot.model);
|
||||
if (part == RaceData::PART_SASH) {
|
||||
m_model->SetAttachmentAnimated(slot.bone, true);
|
||||
if (m_hasSashScale) m_model->SetAttachmentScale(slot.bone, m_sashScale[0], m_sashScale[1], m_sashScale[2]);
|
||||
target->SetAttachmentAnimated(slot.bone, true);
|
||||
if (m_hasSashScale) target->SetAttachmentScale(slot.bone, m_sashScale[0], m_sashScale[1], m_sashScale[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Gr2ModelInstance* ActorInstance::DrawModel() const {
|
||||
if (m_lodLevel < m_lodModels.size() && m_lodModels[m_lodLevel].model) return m_lodModels[m_lodLevel].model.get();
|
||||
return m_model.get();
|
||||
}
|
||||
|
||||
static bool HasBone(const Gr2ModelInstance& model, const std::string& name) {
|
||||
const auto& skeletons = model.GetInfo().skeletons;
|
||||
if (skeletons.empty()) return false;
|
||||
for (const auto& bone : skeletons[0].bones)
|
||||
if (bone.name == name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Some shipped LODs drop attaching bones (lion2_lod_02/03 lose "saddle", shaman_miyeom_lod_* lose
|
||||
// equip_left/right). Drawing those would detach the rider or a part, so such a level falls back to
|
||||
// PART_MAIN.
|
||||
bool ActorInstance::LodHasAttachBones(const Gr2ModelInstance& lod) const {
|
||||
for (uint32_t part = 1; part < kPartCount; ++part) {
|
||||
const auto& slot = m_parts[part];
|
||||
if (slot.model && !slot.bone.empty() && !HasBone(lod, slot.bone)) return false;
|
||||
}
|
||||
static const std::string kSaddle = "saddle";
|
||||
return !HasBone(*m_model, kSaddle) || HasBone(lod, kSaddle);
|
||||
}
|
||||
|
||||
// CGrannyLODController::SetLODLevel + SetCurrentModelInstance.
|
||||
void ActorInstance::SetLodLevel(uint32_t level) {
|
||||
level = std::min<uint32_t>(level, uint32_t(m_lodPaths.size()));
|
||||
if (level < m_lodPaths.size()) {
|
||||
if (m_lodModels.size() != m_lodPaths.size()) m_lodModels.resize(m_lodPaths.size());
|
||||
auto& lod = m_lodModels[level];
|
||||
if (!lod.model) {
|
||||
lod.model = LoadPartModel(m_lodPaths[level]);
|
||||
if (!lod.model) { // unreadable LOD: keep drawing the current instance
|
||||
m_lodPaths.resize(level);
|
||||
m_lodModels.resize(level);
|
||||
return;
|
||||
}
|
||||
for (const auto& skin : m_mainSkins) lod.model->SetSkin(skin.first, skin.second);
|
||||
}
|
||||
if (!LodHasAttachBones(*lod.model)) level = uint32_t(m_lodPaths.size());
|
||||
}
|
||||
if (level == m_lodLevel) return;
|
||||
m_lodLevel = level;
|
||||
RebindParts();
|
||||
SyncLodMotion();
|
||||
}
|
||||
|
||||
// CGrannyLODController::SetMotionPointer applies the motion to every LOD instance; only the drawn
|
||||
// one is kept in step here.
|
||||
void ActorInstance::SyncLodMotion() {
|
||||
if (m_lodLevel >= m_lodModels.size() || !m_lodModels[m_lodLevel].model) return;
|
||||
auto& lod = m_lodModels[m_lodLevel];
|
||||
bool loaded = false;
|
||||
if (lod.motionFile != m_motionFile && !m_motionFile.empty() && lod.model->LoadExternalAnimation(m_motionFile)) {
|
||||
lod.motionFile = m_motionFile;
|
||||
loaded = true;
|
||||
}
|
||||
if (loaded || lod.motionLoop != m_loopMotion) {
|
||||
lod.motionLoop = m_loopMotion;
|
||||
lod.model->SetAnimationLoop(m_loopMotion, m_loopMotion);
|
||||
}
|
||||
}
|
||||
|
||||
bool ActorInstance::SetRace(uint32_t race) {
|
||||
RaceData* raceData = RaceManager::Instance().GetRaceDataPointer(race);
|
||||
if (!raceData) {
|
||||
@@ -94,6 +164,8 @@ bool ActorInstance::SetRace(uint32_t race) {
|
||||
m_model.reset();
|
||||
m_modelPath.clear();
|
||||
m_shapeFile.clear();
|
||||
m_mainSkins.clear();
|
||||
ResetLodModel();
|
||||
|
||||
// SetMotionIndex(eRace): the race's GENERAL motion set (motlist.txt for NPC races, the
|
||||
// chrmgr.RegisterMotionData calls for races built from Python).
|
||||
@@ -127,17 +199,21 @@ void ActorInstance::SetShape(uint32_t shape, float specular) {
|
||||
const std::string& file = pkShape->model.empty() ? raceData->GetBaseModelFileName() : pkShape->model;
|
||||
// The _lod_01.._03 LOD things are not ported: LOD 0 always draws.
|
||||
auto model = LoadPartModel(file);
|
||||
m_mainSkins.clear();
|
||||
for (const auto& skin : pkShape->skins) m_mainSkins.emplace_back(skin.srcFileName, skin.dstFileName);
|
||||
if (model) {
|
||||
for (const auto& skin : pkShape->skins) model->SetSkin(skin.srcFileName, skin.dstFileName);
|
||||
for (const auto& skin : m_mainSkins) model->SetSkin(skin.first, skin.second);
|
||||
}
|
||||
m_shapeFile = file;
|
||||
SetMainModel(std::move(model), file);
|
||||
} else if (raceData->IsTree()) {
|
||||
// __CreateTree (SpeedTree actors) is not ported.
|
||||
m_mainSkins.clear();
|
||||
m_shapeFile.clear();
|
||||
SetMainModel(nullptr, std::string());
|
||||
} else {
|
||||
const std::string& file = raceData->GetBaseModelFileName();
|
||||
m_mainSkins.clear();
|
||||
m_shapeFile = file;
|
||||
SetMainModel(LoadPartModel(file), file);
|
||||
}
|
||||
@@ -211,11 +287,22 @@ void ActorInstance::ResetLodModel() {
|
||||
m_hasLodModel = false;
|
||||
m_lodAniFps = 120;
|
||||
m_poseTimeValid = false;
|
||||
m_lodPaths.clear();
|
||||
m_lodModels.clear();
|
||||
m_lodLevel = 0;
|
||||
if (!m_model) return;
|
||||
const size_t dot = m_modelPath.find_last_of('.');
|
||||
const bool hasExtension = dot != std::string::npos && m_modelPath.find_first_of("/\\", dot) == std::string::npos;
|
||||
std::error_code error;
|
||||
m_hasLodModel = std::filesystem::is_regular_file(ResolvePath((hasExtension ? m_modelPath.substr(0, dot) : m_modelPath) + "_lod_01.gr2"), error);
|
||||
const std::string stem = hasExtension ? m_modelPath.substr(0, dot) : m_modelPath;
|
||||
// _lod_01.._03 until the first missing file; push_front keeps the main model last.
|
||||
for (int index = 1; index <= 3; ++index) {
|
||||
const std::string lod = stem + "_lod_0" + std::to_string(index) + ".gr2";
|
||||
std::error_code error;
|
||||
if (!std::filesystem::is_regular_file(ResolvePath(lod), error)) break;
|
||||
m_lodPaths.insert(m_lodPaths.begin(), lod);
|
||||
}
|
||||
m_lodLevel = uint32_t(m_lodPaths.size());
|
||||
m_hasLodModel = !m_lodPaths.empty();
|
||||
// CGrannyLODController::AddModel: models of 500 units or more use the building LOD distance.
|
||||
float loX, loY, loZ, hiX, hiY, hiZ;
|
||||
m_lodDistance = 5000.0f; // LODDISTANCE_ACTOR
|
||||
@@ -233,6 +320,7 @@ bool ActorInstance::SetModel(const std::string& modelPath) {
|
||||
m_model = Gr2ModelInstance::Load(resolved);
|
||||
if (!m_model) return false;
|
||||
m_modelPath = modelPath;
|
||||
m_mainSkins.clear();
|
||||
ResetLodModel();
|
||||
return true;
|
||||
}
|
||||
@@ -297,10 +385,12 @@ bool ActorInstance::PlayMotion(MotionType type, bool loop) {
|
||||
if (!loaded) return false;
|
||||
|
||||
m_currentMotion = type;
|
||||
m_motionFile = resolved;
|
||||
m_animTime = 0.0f;
|
||||
m_motionDuration = std::max(0.1f, m_model->GetAnimationDuration());
|
||||
m_loopMotion = loop;
|
||||
m_model->SetAnimationLoop(loop, loop);
|
||||
SyncLodMotion();
|
||||
|
||||
if (type == MotionType::Attack || type == MotionType::ComboAttack1 ||
|
||||
type == MotionType::ComboAttack2 || type == MotionType::ComboAttack3 ||
|
||||
@@ -608,7 +698,7 @@ std::vector<Render3DDraw> ActorInstance::BuildDrawCommands(const float* worldOve
|
||||
if (!m_model) return {};
|
||||
float world[16];
|
||||
MakeTransformMatrix(m_yaw, m_posX, m_posY + m_modelYOffset * m_scale, m_posZ, m_scale, world);
|
||||
auto draws = m_model->BuildDrawCommands(PoseTime(), worldOverride ? worldOverride : world);
|
||||
auto draws = DrawModel()->BuildDrawCommands(PoseTime(), worldOverride ? worldOverride : world);
|
||||
|
||||
// Shining system (ENABLE_SHINING_SYSTEM): weapon aura / glow
|
||||
if (m_weaponShining > 0) {
|
||||
@@ -686,24 +776,36 @@ std::vector<Render3DDraw> ActorInstance::BuildDrawCommands(const float* worldOve
|
||||
void ActorInstance::UpdateLODLevel(float eyeX, float eyeY, float eyeZ, float targetX, float targetZ) {
|
||||
// CGrannyLODController::UpdateLODLevel; the distance from the camera target ignores height.
|
||||
m_lodAniFps = 120;
|
||||
const uint32_t count = GetLODCount();
|
||||
uint32_t level = count - 1; // m_que_pkModelInst.back(): the main model
|
||||
if (m_hasLodModel) {
|
||||
const float centerX = targetX - m_posX, centerZ = targetZ - m_posZ;
|
||||
if (std::sqrt(centerX * centerX + centerZ * centerZ) > 500.0f) { // LOD_APPLY_MIN
|
||||
const float dx = eyeX - m_posX, dy = eyeY - m_posY, dz = eyeZ - m_posZ;
|
||||
const float factor = std::clamp(m_lodDistance - std::sqrt(dx * dx + dy * dy + dz * dz), 0.0f, m_lodDistance);
|
||||
const float camera = std::sqrt(dx * dx + dy * dy + dz * dz);
|
||||
const float factor = std::clamp(m_lodDistance - camera, 0.0f, m_lodDistance);
|
||||
m_lodAniFps = static_cast<uint32_t>((120 - 30) * factor / m_lodDistance + 30) / 10 * 10; // ANIFPS_MAX/MIN
|
||||
uint8_t lodLevel = uint8_t(factor / (m_lodDistance / float(count)));
|
||||
if (m_lodDistance <= 5000.0f) {
|
||||
const uint32_t band = camera < 500.0f ? 0 : camera < 1500.0f ? 1 : camera < 2500.0f ? 2 : 3;
|
||||
// BYTE arithmetic as in the original: band == count wraps to 255, which SetLODLevel
|
||||
// clamps back to the main model (e.g. a single _lod_01 beyond 1500 units).
|
||||
lodLevel = uint8_t(count - std::min(band, count) - 1);
|
||||
}
|
||||
level = std::min<uint32_t>(count - 1, lodLevel);
|
||||
}
|
||||
}
|
||||
SetLodLevel(level);
|
||||
// CGrannyModelInstance::Update: hold the pose until the next ANIFPS_STEP frame. A restarted or
|
||||
// switched motion (time going back, new model) re-samples at once instead of mixing clips.
|
||||
const uint32_t frame = static_cast<uint32_t>(m_lodLocalTime * 120.0f);
|
||||
const uint32_t step = 120 / m_lodAniFps;
|
||||
if (m_poseTimeValid && m_poseModel == m_model.get() && m_animTime >= m_poseAnimTime
|
||||
if (m_poseTimeValid && m_poseModel == DrawModel() && m_animTime >= m_poseAnimTime
|
||||
&& frame > step && frame / step == m_oldUpdateFrame / step)
|
||||
return;
|
||||
m_oldUpdateFrame = frame;
|
||||
m_poseAnimTime = m_animTime;
|
||||
m_poseModel = m_model.get();
|
||||
m_poseModel = DrawModel();
|
||||
m_poseTimeValid = step > 1; // full rate: always draw the current time
|
||||
}
|
||||
|
||||
@@ -750,7 +852,9 @@ bool ActorInstance::HitTestScreen(float clickX, float clickY, const Gr2SceneRend
|
||||
bool ActorInstance::GetBoneWorldTransform(const std::string& boneName, float* outWorld16) const {
|
||||
if (!m_model || !outWorld16) return false;
|
||||
float localBone[16];
|
||||
if (!m_model->GetBoneWorldTransform(boneName, localBone, PoseTime())) {
|
||||
// A bone the LOD skeleton dropped is still read from PART_MAIN.
|
||||
if (!DrawModel()->GetBoneWorldTransform(boneName, localBone, PoseTime()) &&
|
||||
(DrawModel() == m_model.get() || !m_model->GetBoneWorldTransform(boneName, localBone, PoseTime()))) {
|
||||
return false;
|
||||
}
|
||||
// Bone poses are still Granny Z-up, just like the mesh vertices. Convert
|
||||
|
||||
@@ -214,6 +214,10 @@ public:
|
||||
// _lod_ models far from the camera sample their pose at a reduced animation FPS (Y-up world).
|
||||
void UpdateLODLevel(float eyeX, float eyeY, float eyeZ, float targetX, float targetZ);
|
||||
uint32_t GetLODAniFPS() const { return m_lodAniFps; }
|
||||
// Index into the CGrannyLODController queue {_lod_N .. _lod_01, main}; the last entry is the main model.
|
||||
uint32_t GetLODLevel() const { return m_lodLevel; }
|
||||
uint32_t GetLODCount() const { return uint32_t(m_lodPaths.size()) + 1; }
|
||||
Gr2ModelInstance* GetDrawModel() { return DrawModel(); }
|
||||
|
||||
Gr2ModelInstance* GetModel() { return m_model.get(); }
|
||||
const std::string& GetModelPath() const { return m_modelPath; }
|
||||
@@ -223,6 +227,10 @@ private:
|
||||
std::shared_ptr<Gr2ModelInstance> LoadPartModel(const std::string& path) const;
|
||||
void SetMainModel(std::shared_ptr<Gr2ModelInstance> model, const std::string& path);
|
||||
void ResetLodModel();
|
||||
Gr2ModelInstance* DrawModel() const;
|
||||
void SetLodLevel(uint32_t level);
|
||||
bool LodHasAttachBones(const Gr2ModelInstance& lod) const;
|
||||
void SyncLodMotion();
|
||||
void AttachWeaponPart(uint32_t part, const SPartItem& item);
|
||||
void RebindParts();
|
||||
|
||||
@@ -246,8 +254,18 @@ private:
|
||||
mutable const Gr2ModelInstance* m_boundsModel = nullptr;
|
||||
mutable float m_boundsRadius = 500.f;
|
||||
std::string m_modelPath;
|
||||
// LOD animation rate (CGrannyLODController); the meshes of _lod_01.._03 are still not ported.
|
||||
// CGrannyLODController: _lod_01.._03 instances (queue order, coarsest first), animation rate.
|
||||
float PoseTime() const { return m_poseTimeValid ? m_poseAnimTime : m_animTime; }
|
||||
struct SLodModel {
|
||||
std::shared_ptr<Gr2ModelInstance> model;
|
||||
std::string motionFile; // external animation currently loaded on this instance
|
||||
bool motionLoop = true;
|
||||
};
|
||||
std::vector<std::string> m_lodPaths; // queue order: _lod_N first
|
||||
std::vector<SLodModel> m_lodModels; // loaded on first use, same order as m_lodPaths
|
||||
uint32_t m_lodLevel = 0; // == m_lodPaths.size(): main model
|
||||
std::vector<std::pair<std::string, std::string>> m_mainSkins; // shape skins, applied to every LOD
|
||||
std::string m_motionFile; // resolved animation on m_model
|
||||
bool m_hasLodModel = false;
|
||||
float m_lodDistance = 5000.0f; // LODDISTANCE_ACTOR, LODDISTANCE_BUILDING for size >= 500
|
||||
float m_lodLocalTime = 0.0f;
|
||||
|
||||
@@ -265,7 +265,11 @@ void CRenderTarget::Render(SDL_Renderer* renderer, const SDL_FRect& destRect) {
|
||||
EnsureTextures(renderer);
|
||||
if (!m_surface || !m_texture) return;
|
||||
|
||||
Update(1.0f / 60.0f);
|
||||
// Real elapsed time between renders, so preview animation/rotation speed is frame-rate independent.
|
||||
const uint64_t now = SDL_GetTicksNS();
|
||||
const float dt = m_lastUpdateNs ? std::clamp(float(now - m_lastUpdateNs) * 1e-9f, 0.0f, 0.25f) : 1.0f / 60.0f;
|
||||
m_lastUpdateNs = now;
|
||||
Update(dt);
|
||||
|
||||
// If background exists, render background first directly to UI
|
||||
if (m_background) {
|
||||
|
||||
@@ -70,6 +70,7 @@ private:
|
||||
uint32_t m_acceVnum = 0;
|
||||
|
||||
float m_rotation = 0.0f;
|
||||
uint64_t m_lastUpdateNs = 0;
|
||||
float m_scale = 1.0f;
|
||||
float m_zoom = 1.0f;
|
||||
float m_pitch = 12.0f;
|
||||
|
||||
@@ -485,6 +485,7 @@ PyObject* app_set_guild_mark_path(PyObject*, PyObject* args) {
|
||||
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); }
|
||||
float GetGameFrameDelta() { return gameFrameDelta; }
|
||||
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(); }
|
||||
|
||||
@@ -20,6 +20,7 @@ unsigned GetDefaultCodePage();
|
||||
bool LoadLocaleData(const std::string& localePath);
|
||||
float GetCameraZoomSpeed();
|
||||
void SetGameFrameDelta(float dt);
|
||||
float GetGameFrameDelta();
|
||||
void GetCameraInput(int& rotate,int& pitch,int& zoom);
|
||||
void StopCameraInput();
|
||||
bool ConsumeCameraSetting(float& distance,float& pitch,float& yaw,float& height);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "python_background.h"
|
||||
#include "python_app.h"
|
||||
#include "python_minimap.h"
|
||||
#include "python_runtime.h"
|
||||
#include "python_system.h"
|
||||
@@ -596,7 +597,7 @@ void CPythonBackground::Update(float fCenterX, float fCenterY, float fCenterZ) {
|
||||
m_mapObjects->SetLoadingCenter(fCenterX, fCenterZ, std::max(5000.0f, CPythonSystem::Instance().GetObjectDistance()));
|
||||
}
|
||||
if (m_skybox) {
|
||||
m_skybox->Update(0.033f);
|
||||
m_skybox->Update(GetGameFrameDelta());
|
||||
}
|
||||
if (m_forest) {
|
||||
m_forest->UpdateSystem(0.033f);
|
||||
|
||||
@@ -750,7 +750,7 @@ static PyObject* effect_RegisterIndexedFlyData(PyObject*, PyObject* args) {
|
||||
}
|
||||
|
||||
static PyObject* effect_Update(PyObject*, PyObject*) {
|
||||
ava2::EffectManager::Instance().Update(1.0f / 60.0f);
|
||||
ava2::EffectManager::Instance().Update(ava2::GetGameFrameDelta());
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
@@ -795,7 +795,9 @@ void initeffect() {
|
||||
}
|
||||
|
||||
static PyObject* fly_Update(PyObject*, PyObject*) {
|
||||
ava2::FlyingManager::Instance().Update(1.0f / 60.0f, 0.0f);
|
||||
static float flyingTime = 0.0f;
|
||||
flyingTime += ava2::GetGameFrameDelta();
|
||||
ava2::FlyingManager::Instance().Update(ava2::GetGameFrameDelta(), flyingTime);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
@@ -829,31 +829,54 @@ int main(int argc, char** argv) {
|
||||
assert(!actor.IsVisible(cullCamera.GetViewMatrix(),cullCamera.GetProjMatrix()));
|
||||
assert(actor.GetModel()->GetImpl()->GetPoseEvaluationCount()==poseBeforeCull);
|
||||
|
||||
// CGrannyLODController: warrior_assasin1 has _lod_ models, so far from the camera it animates at
|
||||
// ANIFPS_MIN (pose re-sampled every 4/120 s) and near the camera target at full rate.
|
||||
// CGrannyLODController: warrior_assasin1 has _lod_01.._03, queued {lod_03, lod_02, lod_01, main}.
|
||||
// Far from the camera it draws the coarsest LOD at ANIFPS_MIN (pose re-sampled every 4/120 s);
|
||||
// near the camera target it draws the main model at full rate.
|
||||
actor.SetPosition(0,0,0);
|
||||
assert(actor.GetLODCount()==4);
|
||||
actor.UpdateLODLevel(0,200,-300,0,0);
|
||||
assert(actor.GetLODAniFPS()==120);
|
||||
assert(actor.GetLODAniFPS()==120 && actor.GetLODLevel()==3 && actor.GetDrawModel()==actor.GetModel());
|
||||
actor.UpdateLODLevel(0,200,-1000,2000,0);
|
||||
assert(actor.GetLODLevel()==2 && actor.GetDrawModel()->GetFilePath().find("_lod_01.gr2")!=std::string::npos);
|
||||
actor.UpdateLODLevel(0,200,-2000,2000,0);
|
||||
assert(actor.GetLODLevel()==1 && actor.GetDrawModel()->GetFilePath().find("_lod_02.gr2")!=std::string::npos);
|
||||
actor.UpdateLODLevel(0,200,-4900,2000,0);
|
||||
assert(actor.GetLODAniFPS()==30);
|
||||
assert(actor.GetLODAniFPS()==30 && actor.GetLODLevel()==0);
|
||||
assert(actor.GetDrawModel()->GetFilePath().find("_lod_03.gr2")!=std::string::npos);
|
||||
assert(!actor.BuildDrawCommands().empty());
|
||||
float lodBone[16];
|
||||
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
|
||||
const auto poseBeforeLod=actor.GetModel()->GetImpl()->GetPoseEvaluationCount();
|
||||
const auto poseBeforeLod=actor.GetDrawModel()->GetImpl()->GetPoseEvaluationCount();
|
||||
for(int frame=0;frame<24;++frame){
|
||||
actor.Update(1.0f/60.0f,&terrain);
|
||||
actor.UpdateLODLevel(0,200,-4900,2000,0);
|
||||
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
|
||||
}
|
||||
const auto farEvaluations=actor.GetModel()->GetImpl()->GetPoseEvaluationCount()-poseBeforeLod;
|
||||
const auto farEvaluations=actor.GetDrawModel()->GetImpl()->GetPoseEvaluationCount()-poseBeforeLod;
|
||||
assert(farEvaluations>=10 && farEvaluations<=14 && "30 FPS animation over 0.4 s");
|
||||
actor.UpdateLODLevel(0,200,-300,0,0);
|
||||
assert(actor.GetDrawModel()==actor.GetModel());
|
||||
const auto poseNear=actor.GetModel()->GetImpl()->GetPoseEvaluationCount();
|
||||
for(int frame=0;frame<24;++frame){
|
||||
actor.Update(1.0f/60.0f,&terrain);
|
||||
actor.UpdateLODLevel(0,200,-300,0,0);
|
||||
assert(actor.GetBoneWorldTransform("Bip01 Spine",lodBone));
|
||||
}
|
||||
assert(actor.GetModel()->GetImpl()->GetPoseEvaluationCount()-poseBeforeLod-farEvaluations==24);
|
||||
assert(actor.GetModel()->GetImpl()->GetPoseEvaluationCount()-poseNear==24);
|
||||
assert(actor.IsVisible(nullptr,nullptr));
|
||||
|
||||
// lion2_lod_02/03 dropped the "saddle" bone the rider attaches to: those levels stay on PART_MAIN.
|
||||
{
|
||||
ava2::ActorInstance mount;
|
||||
assert(mount.SetModel("ymir work/npc/lion_2/lion2.gr2") && mount.GetLODCount()==4);
|
||||
mount.UpdateLODLevel(0,200,-1000,2000,0);
|
||||
assert(mount.GetLODLevel()==2 && mount.GetDrawModel()!=mount.GetModel());
|
||||
mount.UpdateLODLevel(0,200,-4900,2000,0);
|
||||
assert(mount.GetLODLevel()==3 && mount.GetDrawModel()==mount.GetModel());
|
||||
float saddle[16];
|
||||
assert(mount.GetBoneWorldTransform("saddle",saddle));
|
||||
}
|
||||
|
||||
// Test movement driving
|
||||
actor.SetPosition(0.0f, 0.0f, 0.0f);
|
||||
actor.MoveInDirection(90.0f, 0.2f, &terrain); // Move East
|
||||
|
||||
Reference in New Issue
Block a user