From 7cf44b24623700a30d96a9ec683b6c54144b9bd7 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 19 Jan 2024 01:44:50 -0600 Subject: [PATCH] Added infinite and nan checks for positions. --- Adventures in Lestoria/Monster.cpp | 11 ++++++++++- Adventures in Lestoria/Monster.h | 1 + Adventures in Lestoria/Player.cpp | 11 ++++++++++- Adventures in Lestoria/Ranger.cpp | 2 +- Adventures in Lestoria/TODO.txt | 3 ++- Adventures in Lestoria/Version.h | 2 +- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index 33f4f9c1..444d61ca 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -61,7 +61,7 @@ safemap>STRATEGY_DAT std::mapMonsterData::imgs; Monster::Monster(vf2d pos,MonsterData data,bool upperLevel,bool bossMob): - pos(pos),hp(data.GetHealth()),size(data.GetSizeMult()),targetSize(data.GetSizeMult()),strategy(data.GetAIStrategy()),name(data.GetDisplayName()),upperLevel(upperLevel),isBoss(bossMob),facingDirection(DOWN){ + pos(pos),spawnPos(pos),hp(data.GetHealth()),size(data.GetSizeMult()),targetSize(data.GetSizeMult()),strategy(data.GetAIStrategy()),name(data.GetDisplayName()),upperLevel(upperLevel),isBoss(bossMob),facingDirection(DOWN){ bool firstAnimation=true; for(std::string&anim:data.GetAnimations()){ animation.AddState(anim,ANIMATION_DATA[anim]); @@ -376,6 +376,15 @@ void Monster::Moved(){ monsterWalkSoundTimer-=1.f; SoundEffect::PlaySFX(GetWalkSound(),GetPos()); } + + if(!std::isfinite(pos.x)){ + ERR(std::format("WARNING! Player X position is {}...Trying to recover. THIS SHOULD NOT BE HAPPENING!",pos.x)); + pos.x=spawnPos.x; + } + if(!std::isfinite(pos.y)){ + ERR(std::format("WARNING! Player Y position is {}...Trying to recover. THIS SHOULD NOT BE HAPPENING!",pos.y)); + pos.y=spawnPos.y; + } } std::string Monster::GetDeathAnimationName(){ return MONSTER_DATA[name].GetDeathAnimation(); diff --git a/Adventures in Lestoria/Monster.h b/Adventures in Lestoria/Monster.h index a13d0cdf..377b5fb1 100644 --- a/Adventures in Lestoria/Monster.h +++ b/Adventures in Lestoria/Monster.h @@ -189,6 +189,7 @@ private: float friction=400; vf2d target={0,0}; float targetAcquireTimer=0; + vf2d spawnPos; int hp; ItemAttributable stats; float size; diff --git a/Adventures in Lestoria/Player.cpp b/Adventures in Lestoria/Player.cpp index 9da6047c..e3113e10 100644 --- a/Adventures in Lestoria/Player.cpp +++ b/Adventures in Lestoria/Player.cpp @@ -619,7 +619,7 @@ void Player::Update(float fElapsedTime){ vf2d extendedLine=pointTowardsCursor.upoint(1.1f); float angleToCursor=atan2(extendedLine.y-GetPos().y,extendedLine.x-GetPos().x); attack_cooldown_timer=ARROW_ATTACK_COOLDOWN; - BULLET_LIST.push_back(std::make_unique(Arrow(GetPos(),extendedLine,vf2d{cos(angleToCursor)*"Ranger.Ability 1.ArrowSpd"_F,float(sin(angleToCursor)*"Ranger.Ability 1.ArrowSpd"_F-PI/8*"Ranger.Ability 1.ArrowSpd"_F)}+movementVelocity/2,12*"Ranger.Ability 1.ArrowRadius"_F/100,int(GetAttack()*"Ranger.Ability 1.DamageMult"_F),OnUpperLevel(),true))); + BULLET_LIST.push_back(std::make_unique(Arrow(GetPos(),extendedLine,vf2d{cos(angleToCursor)*"Ranger.Ability 1.ArrowSpd"_F,float(sin(angleToCursor)*"Ranger.Ability 1.ArrowSpd"_F-PI/8*"Ranger.Ability 1.ArrowSpd"_F)}+movementVelocity/1.5f,12*"Ranger.Ability 1.ArrowRadius"_F/100,int(GetAttack()*"Ranger.Ability 1.DamageMult"_F),OnUpperLevel(),true))); SetAnimationBasedOnTargetingDirection(angleToCursor); rapidFireTimer=RAPID_FIRE_SHOOT_DELAY; }else{ @@ -788,6 +788,15 @@ void Player::Moved(){ } } EnvironmentalAudio::UpdateEnvironmentalAudio(); + + if(!std::isfinite(pos.x)){ + ERR(std::format("WARNING! Player X position is {}...Trying to recover. THIS SHOULD NOT BE HAPPENING!",pos.x)); + ForceSetPos({float(game->GetCurrentMapData().playerSpawnLocation.x),pos.y}); + } + if(!std::isfinite(pos.y)){ + ERR(std::format("WARNING! Player Y position is {}...Trying to recover. THIS SHOULD NOT BE HAPPENING!",pos.y)); + ForceSetPos({pos.x,float(game->GetCurrentMapData().playerSpawnLocation.y)}); + } } void Player::Spin(float duration,float spinSpd){ diff --git a/Adventures in Lestoria/Ranger.cpp b/Adventures in Lestoria/Ranger.cpp index 4a4270af..d2f0c8a1 100644 --- a/Adventures in Lestoria/Ranger.cpp +++ b/Adventures in Lestoria/Ranger.cpp @@ -71,7 +71,7 @@ bool Ranger::AutoAttack(){ vf2d extendedLine=pointTowardsCursor.upoint(1.1f); float angleToCursor=atan2(extendedLine.y-GetPos().y,extendedLine.x-GetPos().x); attack_cooldown_timer=ARROW_ATTACK_COOLDOWN-GetAttackRecoveryRateReduction(); - BULLET_LIST.push_back(std::make_unique(Arrow(GetPos(),extendedLine,vf2d{cos(angleToCursor)*"Ranger.Auto Attack.ArrowSpd"_F,float(sin(angleToCursor)*"Ranger.Auto Attack.ArrowSpd"_F-PI/8*"Ranger.Auto Attack.ArrowSpd"_F)}+movementVelocity/2,"Ranger.Auto Attack.Radius"_F/100*12,int(GetAttack()*"Ranger.Auto Attack.DamageMult"_F),OnUpperLevel(),true))); + BULLET_LIST.push_back(std::make_unique(Arrow(GetPos(),extendedLine,vf2d{cos(angleToCursor)*"Ranger.Auto Attack.ArrowSpd"_F,float(sin(angleToCursor)*"Ranger.Auto Attack.ArrowSpd"_F-PI/8*"Ranger.Auto Attack.ArrowSpd"_F)}+movementVelocity/1.5f,"Ranger.Auto Attack.Radius"_F/100*12,int(GetAttack()*"Ranger.Auto Attack.DamageMult"_F),OnUpperLevel(),true))); SetState(State::SHOOT_ARROW); SetAnimationBasedOnTargetingDirection(angleToCursor); SoundEffect::PlaySFX("Ranger.Auto Attack.Sound"_S,SoundEffect::CENTERED); diff --git a/Adventures in Lestoria/TODO.txt b/Adventures in Lestoria/TODO.txt index cff81930..35ddc844 100644 --- a/Adventures in Lestoria/TODO.txt +++ b/Adventures in Lestoria/TODO.txt @@ -13,7 +13,6 @@ Settings Menu - Fix Stage Completed screen, item displays can hit the scrollbar. - Monster spawn list is not populated in Emscripten? -- Random pitch up down +/-10%. January 31st ============ @@ -32,6 +31,8 @@ Story proofreading/correcting/storyboarding - Lock up unimplemented classes. - Don't enable all stage plates normally. +ERR messages become just output messages in release build and won't crash the game. + - Hide mouse cursor during controller play. Reveal it again during mouse play. diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 72d37dd7..ac15afdb 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 6033 +#define VERSION_BUILD 6037 #define stringify(a) stringify_(a) #define stringify_(a) #a