Skip to content

Commit 0e5ac1d

Browse files
AlryscTheMaverickProgrammerArthur Cosentino
authored
Net improvement cleanup (#249)
* time freeze attachment nodes were 1 frame off. added get_move_direction() and set_move_direction(). fixed 1 letter-off Personal menu area name. un-auto'd my code * no more pvp ghosts. fixed lava tile. entities cannot get Hit() directly when iframes * Prevent mods from unsafely manipulating data in other lua states * Handshake before reading packets in download scene * Fix possible crash from late type check * texturetypes.h -> resourcepaths.h. freeze status effect * Allow components to be made for more entity types * Add is_counterable for lua * status queue prioritized drag statuses before other deferred hitbox data. shaking fx is requeued if not in time freeze due to drag or applied earlier otherwise. * blind status added. tweaked airshoe rule in CanMoveTo(). Optional 'head' point in blind status used otherwise it is calculated from player height * black player shader bug fixed for now. Forced card preview size limit on chip art. Emotion window UI flicker speed adjusted. Fixed counters not appearing. Removed more auto's. * audio cache tries to clear now too. frame_time_t stopwatch replacement for swoosh::Timer which uses seconds. ESC key in battle must have app in focus to trigger. Tweaked some problems detecting and displaying combos and counter info text. * sending correct hand over network in pvp. Skipping input processing on updates that serve to refresh the screen. Frame time objects replace swoosh timers. * added player guide PDF to source project. Tweaked handling player input's in mob battle scene and network battle scene. * fixed true breaking code for freeze status. made sure extra damage was subtracted from the entity's health. updated sound font. * removed lingering code * Initial logging and changes, timeout 20 seconds instead of 5, plus other misc. Some of these need to be undone later. * More logging for inputs, fix for inputs not being processed correctly during time freeze. * Game now defines a Version, used in window title. Version sent in DownloadScene handshake, aborts if version mismatch detected. Remove net logging from InputManager. * Starting DownloadScene creates new log file in logs directory, Bump version number. * Claim that netplay battlescene is synced during start. This may help sync softlocks on scene start and shouldn't desync because inputs are not being sent yet. Bump version. * TimeFreezeBattleState now resets the currState in its OnEnd. Some extra logging. Version increase. * Update .gitignore * Fix decross desync on next turn start. More logging around states starting and ending. CustomBarProgress is now reset in CardSelectBattleState::onStart instead of the CombatBattleState. Version bump. The desync fixed was one where being decrossed during the turn and then not choosing a form on the following card select would cause the remote player to think you changed forms to the form at -1, which would animate and desync. SetCustomBarProgress call moved in order to prevent progress from resetting during transitions between combat and transformation state during combat, ,such as through decross. Transformation state should not be added as a subcombat state, so this makes more sense. * char to int to help ARM64 compile * Remove some extra logging, add newline at end of some files that were missing one * Remove excess logging * Remove Logger::StartNewLog and filesystem import --------- Co-authored-by: TheMaverickProgrammer <[email protected]> Co-authored-by: Arthur Cosentino <[email protected]>
1 parent 05fd24f commit 0e5ac1d

File tree

80 files changed

+1395
-803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1395
-803
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,4 @@ _deps
388388
/log.txt
389389

390390
# ini files
391-
*.ini
391+
*.ini

BattleNetwork/battlescene/States/bnBattleStartBattleState.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ void BattleStartBattleState::onStart(const BattleSceneState* _)
1919
GetScene().IncrementTurnCount();
2020

2121
// only reveal first player's UI widget to them
22-
auto ui = GetScene().GetLocalPlayer()->GetFirstComponent<PlayerSelectedCardsUI>();
22+
std::shared_ptr<Player> localPlayer = GetScene().GetLocalPlayer();
23+
std::shared_ptr<PlayerSelectedCardsUI> ui = localPlayer->GetFirstComponent<PlayerSelectedCardsUI>();
2324

2425
if (ui) {
2526
ui->Reveal();

BattleNetwork/battlescene/States/bnBattleTextIntroState.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ void BattleTextIntroState::onEnd(const BattleSceneState*)
4747

4848
void BattleTextIntroState::onUpdate(double elapsed)
4949
{
50-
timer.update(sf::seconds(static_cast<float>(elapsed)));
50+
timer.tick();
5151
}
5252

5353
void BattleTextIntroState::onDraw(sf::RenderTexture& surface)
5454
{
55-
frame_time_t start = from_milliseconds(timer.getElapsed().asMilliseconds());
55+
frame_time_t start = timer.elapsed();
5656

5757
if (start >= startupDelay) {
5858
double delta = (start - startupDelay).asSeconds().value;
@@ -67,5 +67,5 @@ void BattleTextIntroState::onDraw(sf::RenderTexture& surface)
6767
}
6868

6969
bool BattleTextIntroState::IsFinished() {
70-
return timer.getElapsed().asSeconds() >= (startupDelay + preBattleLength).asSeconds().value;
70+
return timer.elapsed() >= startupDelay + preBattleLength;
7171
}

BattleNetwork/battlescene/States/bnBattleTextIntroState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct BattleTextIntroState : public BattleSceneState {
1616
frame_time_t preBattleLength{ frames(60) };
1717
frame_time_t startupDelay{ frames(0) }; /*!< Animation delay*/
1818
Text battleStart; /*!< e.g. "Battle Start" graphic */
19-
swoosh::Timer timer; /*!< How long the start graphic should stay on screen */
19+
frame_time_stopwatch_t timer; /*!< How long the start graphic should stay on screen */
2020
sf::Vector2f battleStartPos; /*!< Position of battle pre/post graphic on screen */
2121
BattleTextIntroState();
2222
virtual ~BattleTextIntroState();

BattleNetwork/battlescene/States/bnCardSelectBattleState.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ std::shared_ptr<std::vector<Battle::Card>> CardSelectBattleState::GetCardPtrList
6363

6464
void CardSelectBattleState::onStart(const BattleSceneState*)
6565
{
66-
CardSelectionCust& cardCust = GetScene().GetCardSelectWidget();
66+
BattleSceneBase& scene = GetScene();
67+
CardSelectionCust& cardCust = scene.GetCardSelectWidget();
6768

6869
Audio().Play(AudioType::CUSTOM_SCREEN_OPEN);
6970

71+
// Reset bar and related flags
72+
scene.SetCustomBarProgress(0.0);
73+
7074
// Load the next cards
7175
cardCust.ResetState();
7276
cardCust.GetNextCards();
@@ -79,17 +83,19 @@ void CardSelectBattleState::onStart(const BattleSceneState*)
7983

8084
void CardSelectBattleState::onUpdate(double elapsed)
8185
{
86+
BattleSceneBase& scene = GetScene();
87+
Camera& camera = scene.GetCamera();
8288
CardSelectionCust& cardCust = GetScene().GetCardSelectWidget();
8389

8490
if (!cardCust.IsInView() && currState == state::slidein) {
8591
cardCust.Move(sf::Vector2f(MODAL_SLIDE_PX_PER_SEC * (float)elapsed, 0));
86-
GetScene().GetCamera().MoveCamera(sf::Vector2f(240.f, 134.f), sf::seconds(0.1f));
92+
camera.MoveCamera(sf::Vector2f(240.f, 134.f), sf::seconds(0.1f));
8793
return;
8894
}
8995

9096
if (!cardCust.IsOutOfView() && currState == state::slideout) {
9197
cardCust.Move(sf::Vector2f(-MODAL_SLIDE_PX_PER_SEC * (float)elapsed, 0));
92-
GetScene().GetCamera().MoveCamera(sf::Vector2f(240.f, 160.f), sf::seconds(0.1f));
98+
camera.MoveCamera(sf::Vector2f(240.f, 160.f), sf::seconds(0.1f));
9399
return;
94100
}
95101

@@ -189,18 +195,25 @@ void CardSelectBattleState::onUpdate(double elapsed)
189195
Audio().Play(AudioType::CHIP_CONFIRM, AudioPriority::high);
190196

191197
// If the list is untouched, we do not re-assign the cards
192-
bool hasNewHand = cardCust.HasNewHand();
198+
hasNewChips = cardCust.HasNewHand();
193199
std::vector<Battle::Card> newCards = cardCust.GetCards();
194200

195-
std::shared_ptr<Player> player = GetScene().GetLocalPlayer();
201+
std::shared_ptr<Player> player = scene.GetLocalPlayer();
196202
std::shared_ptr<PlayerSelectedCardsUI> ui = player->GetFirstComponent<PlayerSelectedCardsUI>();
197203

198-
if (ui && hasNewHand) {
199-
*cards = newCards;
200-
GetScene().FilterSupportCards(player, *cards);
201-
ui->LoadCards(*cards);
202-
ui->Hide();
203-
hasNewChips = true;
204+
if (ui) {
205+
if (hasNewChips) {
206+
*cards = newCards;
207+
// inform scene implementations of the new hand
208+
scene.OnSelectNewCards(player, *cards);
209+
scene.FilterSupportCards(player, *cards);
210+
ui->LoadCards(*cards);
211+
ui->Hide();
212+
}
213+
else {
214+
// Send off the remaining hands to any scene implementations that need it
215+
scene.OnSelectNewCards(player, ui->GetRemainingCards());
216+
}
204217
}
205218

206219
CheckFormChanges();
@@ -219,7 +232,7 @@ void CardSelectBattleState::onUpdate(double elapsed)
219232
Audio().Play(AudioType::CHIP_ERROR, AudioPriority::lowest);
220233
}
221234
}
222-
else if (Input().Has(InputEvents::pressed_cancel) || sf::Mouse::isButtonPressed(sf::Mouse::Button::Right)) {
235+
else if (Input().Has(InputEvents::pressed_cancel)) {
223236
cardCust.CursorCancel() ? Audio().Play(AudioType::CHIP_CANCEL, AudioPriority::highest) : 1;
224237
}
225238
else if (Input().Has(InputEvents::held_option)) {

BattleNetwork/battlescene/States/bnCardSelectBattleState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CardSelectBattleState final : public BattleSceneState {
2727
bool pvpMode{ false };
2828
bool hasNewChips{ false };
2929
bool formSelected{ false };
30-
bool firstTime{ true };
30+
bool firstTime{ true }; //!< Show opposing mob's names on the first round
3131
int currForm{ -1 };
3232
float streamVolume{ -1.f };
3333
Font font;

BattleNetwork/battlescene/States/bnCharacterTransformBattleState.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ void CharacterTransformBattleState::UpdateAnimation(double elapsed)
8585

8686
if (shineAnimations[count].GetAnimationString() != "SHINE") {
8787
shineAnimations[count] << "SHINE";
88-
8988
if (index == -1) {
9089
// If decross, turn white immediately
91-
shineAnimations[count] << Animator::On(1, [=] {
90+
shineAnimations[count] << Animator::On(1, [=] {
9291
player->SetShader(Shaders().GetShader(ShaderType::WHITE));
9392
}) << Animator::On(10, onTransform);
9493
}
@@ -105,8 +104,9 @@ void CharacterTransformBattleState::UpdateAnimation(double elapsed)
105104

106105
} // else, it is already "SHINE" so wait the animation out...
107106

108-
// update for draw call later
107+
// Update animation
109108
frameElapsed = elapsed;
109+
shineAnimations[count].Update(frameElapsed, shine);
110110

111111
count++;
112112
}
@@ -126,6 +126,7 @@ bool CharacterTransformBattleState::IsFinished() {
126126
}
127127

128128
void CharacterTransformBattleState::onStart(const BattleSceneState*) {
129+
Logger::Log(LogLevel::info, "CharacterTransformBattleState::onStart");
129130
if (skipBackdrop) {
130131
currState = state::animate;
131132
}
@@ -157,6 +158,7 @@ void CharacterTransformBattleState::onUpdate(double elapsed) {
157158

158159
void CharacterTransformBattleState::onEnd(const BattleSceneState*)
159160
{
161+
Logger::Log(LogLevel::info, "CharacterTransformBattleState::onEnd");
160162
for (auto&& anims : shineAnimations) {
161163
anims.SetAnimation(""); // ends the shine anim
162164
}
@@ -169,12 +171,10 @@ void CharacterTransformBattleState::onDraw(sf::RenderTexture& surface)
169171
BattleSceneBase& scene = GetScene();
170172

171173
size_t count = 0;
174+
172175
for (std::shared_ptr<Player>& player : scene.GetAllPlayers()) {
173176
auto& [index, complete] = scene.GetPlayerFormData(player);
174177

175-
Animation& anim = shineAnimations[count];
176-
anim.Update(static_cast<float>(frameElapsed), shine);
177-
178178
if (index != -1 && !complete) {
179179
// re-use the shine graphic for all animating player-types
180180
const sf::Vector2f pos = player->getPosition();

BattleNetwork/battlescene/States/bnCharacterTransformBattleState.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class CharacterTransformBattleState final : public BattleSceneState {
2525
bool skipBackdrop{ false };
2626
sf::Sprite shine;
2727
std::vector<Animation> shineAnimations;
28-
2928
const bool FadeInBackdrop();
3029
const bool FadeOutBackdrop();
3130
void UpdateAnimation(double elapsed);

BattleNetwork/battlescene/States/bnCombatBattleState.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ void CombatBattleState::onStart(const BattleSceneState* last)
108108
scene.GetField()->ToggleTimeFreeze(false);
109109

110110
hasTimeFreeze = false;
111-
112-
// reset bar and related flags
113-
scene.SetCustomBarProgress(0);
114111
}
115112
}
116113

@@ -122,9 +119,6 @@ void CombatBattleState::onEnd(const BattleSceneState* next)
122119
// then reset our combat and custom progress values
123120
if (this->HandleNextRoundSetup(next)) {
124121
scene.StopBattleStepTimer();
125-
126-
// reset bar
127-
scene.SetCustomBarProgress(0);
128122
}
129123

130124
scene.HighlightTiles(false);
@@ -207,7 +201,7 @@ void CombatBattleState::OnCardActionUsed(std::shared_ptr<CardAction> action, uin
207201
// Only intercept this event if we are active
208202
if (scene.GetCurrentState() != this) return;
209203

210-
Logger::Logf(LogLevel::debug, "CombatBattleState::OnCardActionUsed() on frame #%i", scene.FrameNumber().count());
204+
Logger::Logf(LogLevel::debug, "CombatBattleState::OnCardActionUsed() on frame #%i, with gauge progress %f", scene.FrameNumber().count(), this->GetScene().GetCustomBarProgress());
211205
if (!IsMobCleared()) {
212206
hasTimeFreeze = action->GetMetaData().timeFreeze;
213207
}

BattleNetwork/battlescene/States/bnMobIntroBattleState.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,43 @@ MobIntroBattleState::MobIntroBattleState(Mob* mob):
1212

1313
void MobIntroBattleState::onUpdate(double elapsed)
1414
{
15-
if (!GetScene().IsSceneInFocus()) return;
15+
BattleSceneBase& scene = GetScene();
1616

17-
Field& field = *GetScene().GetField();
17+
if (!scene.IsSceneInFocus()) return;
18+
19+
Field& field = *scene.GetField();
1820

1921
if (mob->NextMobReady()) {
20-
auto data = mob->GetNextSpawn();
22+
std::unique_ptr<Mob::SpawnData> data = mob->GetNextSpawn();
2123

2224
Agent* cast = dynamic_cast<Agent*>(data->character.get());
2325

2426
// Some entities have AI and need targets
2527
// TODO: support multiple targets
2628
if (cast) {
27-
cast->SetTarget(GetScene().GetLocalPlayer());
29+
cast->SetTarget(scene.GetLocalPlayer());
2830
}
2931

3032
std::shared_ptr<Character>& enemy = data->character;
3133

3234
enemy->ToggleTimeFreeze(false);
3335

34-
Battle::Tile* destTile = GetScene().GetField()->GetAt(data->tileX, data->tileY);
36+
Battle::Tile* destTile = scene.GetField()->GetAt(data->tileX, data->tileY);
3537
enemy->SetTeam(destTile->GetTeam());
3638

37-
GetScene().GetField()->AddEntity(enemy, data->tileX, data->tileY);
39+
scene.GetField()->AddEntity(enemy, data->tileX, data->tileY);
3840

3941
if (destTile->GetTeam() == Team::red) {
4042
friendlies.push_back(enemy);
4143
}
4244

4345
// Listen for events
44-
GetScene().CounterHitListener::Subscribe(*enemy);
45-
GetScene().HitListener::Subscribe(*enemy);
46-
GetScene().SubscribeToCardActions(*enemy);
46+
scene.CounterHitListener::Subscribe(*enemy);
47+
scene.HitListener::Subscribe(*enemy);
48+
scene.SubscribeToCardActions(*enemy);
4749
}
4850

49-
GetScene().GetField()->Update((float)elapsed);
51+
scene.GetField()->Update((float)elapsed);
5052
}
5153

5254
void MobIntroBattleState::onEnd(const BattleSceneState*)

0 commit comments

Comments
 (0)