Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* BDSP Advance Clock
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <chrono>
#include "PokemonBDSP_AdvanceClock.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{


uint64_t AdvanceClock::advance_at(WallClock time) const{
double elapsed = std::chrono::duration_cast<std::chrono::duration<double>>(
time - anchor_time
).count();
double advances = elapsed / tick_seconds * (double)npcs;
double position = (double)anchor_advance + advances;
return position <= 0 ? 0 : (uint64_t)position;
}

WallClock AdvanceClock::time_of_advance(uint64_t advance) const{
if (npcs == 0){
return anchor_time;
}

int64_t ticks = (int64_t)(advance / npcs) - (int64_t)(anchor_advance / npcs);
return anchor_time + std::chrono::duration_cast<WallDuration>(
std::chrono::duration<double>((double)ticks * tick_seconds)
);
}

WallClock AdvanceClock::middle_of_advance(uint64_t advance) const{
return time_of_advance(advance) - std::chrono::duration_cast<WallDuration>(
std::chrono::duration<double>(tick_seconds / 2)
);
}


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* BDSP Advance Clock
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonBDSP_AdvanceClock_H
#define PokemonAutomation_PokemonBDSP_AdvanceClock_H

#include <stdint.h>
#include "Common/Cpp/Time.h"
#include "PokemonBDSP_BlinkModel.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{


struct AdvanceClock{
WallClock anchor_time{};
uint64_t anchor_advance = 0;
double tick_seconds = BDSP_NPC_TICK_SECONDS;
uint8_t npcs = 1;

uint64_t advance_at(WallClock time) const;


// the tick's leading edge, not necessarily safe to aim at
WallClock time_of_advance(uint64_t advance) const;

// half a tick earlier
WallClock middle_of_advance(uint64_t advance) const;
};


}
}
}
#endif
Loading
Loading