working on refactoring

This commit is contained in:
Vladislav Khorev committed 2026-10-24 22:37:20 +06:00
1 parent 9b71ee447a
commit d5ef126264
12 files changed
+309 -219

No files matched your search

+67 -43
View File
@@ -56,6 +56,18 @@ namespace FRG
{
}
Location::~Location()
{
// The player is shared with the next location and outlives this one: drop
// everything in him that points into this location: its path planner, the HP
// callback Game wires with this location's pointer, and a pending walk-to callback.
if (player) {
player->setPathPlanner(nullptr);
player->state.onHpChanged = nullptr;
player->state.onArrivedCallback = nullptr;
}
}
// ---- Pointer-to-index helpers ----
InteractiveObject* Location::getTargetInteractiveObject()
@@ -101,53 +113,14 @@ namespace FRG
interactiveObjects = GameObjectLoader::loadAndCreateInteractiveObjects(params.interactiveObjectsJsonPath, renderer, CONST_ZIP_FILE);
SDL_PumpEvents();
//auto playerTexture = std::make_shared<Texture>(CreateTextureDataFromPng("resources/w/gg/IMG_20260413_182354_992.png", CONST_ZIP_FILE));
//auto playerTexture = renderer.textureManager.LoadFromPng("resources/w/gg/UniV_Grid_2K_Base_color.png", CONST_ZIP_FILE);
auto playerTexture = renderer.textureManager.LoadFromPng("resources/w/gg/UniV_Grid_2K_Base_color001.png", CONST_ZIP_FILE);
auto sparkTexture = renderer.textureManager.LoadFromPng("resources/w/spark.png", CONST_ZIP_FILE);
player = std::make_unique<Character>();
player->loadBinaryAnimation(AnimationState::STAND, "resources/w/gg/new2/gg_stand_idle001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::WALK, "resources/w/gg/new2/gg_walk001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::STAND_TO_ACTION, "resources/w/gg/new2/gg_stand_to_action001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK, "resources/w/gg/new2/gg_action_chop001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK_2, "resources/w/gg/new2/gg_action_stab001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_IDLE, "resources/w/gg/new2/gg_action_idle002_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_TO_STAND, "resources/w/gg/new2/gg_action_to_stand001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_TO_DEATH, "resources/w/gg/new2/gg_die001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::DEATH_IDLE, "resources/w/gg/new2/gg_die_idle001_small.anim", CONST_ZIP_FILE);
player->weaponTexture = renderer.textureManager.LoadFromPng("resources/w/gg/Props.png", CONST_ZIP_FILE);
player->weaponMesh.data = LoadModelFromBinFile("resources/w/gg/knife002.txt.bin", CONST_ZIP_FILE);
player->weaponMesh.data.Move(Vector3f(0, -0.3, 0));
player->weaponMesh.data.Scale(0.2f);
player->weaponMesh.RefreshVBO();
player->weaponAttachBoneName = "RightHand";
player->weaponInitialRotation = Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitZ()).toRotationMatrix();
player->weaponInitialPosition = Eigen::Vector3f(0, 0.09, 0.016);
player->setTexture(playerTexture);
player->state.walkSpeed = 3.0f;
player->state.rotationSpeed = 8.0f;
player->state.modelScale = 1.f;
player->state.modelCorrectionRotation = Eigen::Quaternionf(
Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY())
*
Eigen::AngleAxisf(-M_PI*0.5, Eigen::Vector3f::UnitX())
);
player->state.canAttack = true;
player->state.isPlayer = true;
player = params.player ? params.player : createPlayer(renderer, audioPlayer);
// A shared player arrives from another location; until setupNavigation() below
// gives him this location's planner, he must not plan with anything else.
player->setPathPlanner(nullptr);
player->state.position = params.playerPosition;
player->setTarget(params.playerPosition);
player->setupHitSparks(sparkTexture);
player->audioPlayer = audioPlayer;
logger() << "Load resurces step 9" << std::endl;
SDL_PumpEvents();
@@ -229,6 +202,57 @@ namespace FRG
}
std::shared_ptr<Character> Location::createPlayer(Renderer& renderer, AudioPlayerAsync* audioPlayer)
{
//auto playerTexture = std::make_shared<Texture>(CreateTextureDataFromPng("resources/w/gg/IMG_20260413_182354_992.png", CONST_ZIP_FILE));
//auto playerTexture = renderer.textureManager.LoadFromPng("resources/w/gg/UniV_Grid_2K_Base_color.png", CONST_ZIP_FILE);
auto playerTexture = renderer.textureManager.LoadFromPng("resources/w/gg/UniV_Grid_2K_Base_color001.png", CONST_ZIP_FILE);
auto sparkTexture = renderer.textureManager.LoadFromPng("resources/w/spark.png", CONST_ZIP_FILE);
auto player = std::make_shared<Character>();
player->loadBinaryAnimation(AnimationState::STAND, "resources/w/gg/new2/gg_stand_idle001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::WALK, "resources/w/gg/new2/gg_walk001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::STAND_TO_ACTION, "resources/w/gg/new2/gg_stand_to_action001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK, "resources/w/gg/new2/gg_action_chop001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_ATTACK_2, "resources/w/gg/new2/gg_action_stab001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_IDLE, "resources/w/gg/new2/gg_action_idle002_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_TO_STAND, "resources/w/gg/new2/gg_action_to_stand001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::ACTION_TO_DEATH, "resources/w/gg/new2/gg_die001_small.anim", CONST_ZIP_FILE);
player->loadBinaryAnimation(AnimationState::DEATH_IDLE, "resources/w/gg/new2/gg_die_idle001_small.anim", CONST_ZIP_FILE);
player->weaponTexture = renderer.textureManager.LoadFromPng("resources/w/gg/Props.png", CONST_ZIP_FILE);
player->weaponMesh.data = LoadModelFromBinFile("resources/w/gg/knife002.txt.bin", CONST_ZIP_FILE);
player->weaponMesh.data.Move(Vector3f(0, -0.3, 0));
player->weaponMesh.data.Scale(0.2f);
player->weaponMesh.RefreshVBO();
player->weaponAttachBoneName = "RightHand";
player->weaponInitialRotation = Eigen::AngleAxisf(-M_PI * 0.5, Eigen::Vector3f::UnitZ()).toRotationMatrix();
player->weaponInitialPosition = Eigen::Vector3f(0, 0.09, 0.016);
player->setTexture(playerTexture);
player->state.walkSpeed = 3.0f;
player->state.rotationSpeed = 8.0f;
player->state.modelScale = 1.f;
player->state.modelCorrectionRotation = Eigen::Quaternionf(
Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitY())
*
Eigen::AngleAxisf(-M_PI*0.5, Eigen::Vector3f::UnitX())
);
player->state.canAttack = true;
player->state.isPlayer = true;
player->setupHitSparks(sparkTexture);
player->audioPlayer = audioPlayer;
return player;
}
void Location::loadTeleportZones(const std::string& jsonPath, const char* zipFile)
{
if (jsonPath.empty()) return;