Skip to content

Commit

Permalink
Break off more of Optimiser to ProcessedSong
Browse files Browse the repository at this point in the history
  • Loading branch information
GenericMadScientist committed Apr 25, 2020
1 parent c144c59 commit 4ba2c11
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 237 deletions.
76 changes: 38 additions & 38 deletions include/optimiser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,6 @@
#include "sp.hpp"
#include "time.hpp"

class ProcessedSong {
private:
// The order of these members is important. We must have m_converter before
// m_points.
TimeConverter m_converter;
PointSet m_points;
SpData m_sp_data;
int m_total_solo_boost;

public:
ProcessedSong(const NoteTrack& track, int resolution,
const SyncTrack& sync_track, double early_whammy,
double squeeze);

// Return the minimum and maximum amount of SP can be acquired between two
// points. Does not include SP from the point act_start. first_point is
// given for the purposes of counting SP grantings notes, e.g. if start is
// after the middle of first_point's timing window.
[[nodiscard]] SpBar total_available_sp(Beat start, PointPtr first_point,
PointPtr act_start) const;

[[nodiscard]] const TimeConverter& converter() const { return m_converter; }
[[nodiscard]] const PointSet& points() const { return m_points; }
[[nodiscard]] const SpData& sp_data() const { return m_sp_data; }
[[nodiscard]] int total_solo_boost() const { return m_total_solo_boost; }
};

struct ActivationCandidate {
PointPtr act_start;
PointPtr act_end;
Expand All @@ -68,12 +41,12 @@ struct Activation {
PointPtr act_end;
};

// Part of the return value of Optimiser::is_candidate_valid. Says if an
// Part of the return value of ProcessedSong::is_candidate_valid. Says if an
// activation is valid, and if not whether the problem is too little or too much
// Star Power.
enum class ActValidity { success, insufficient_sp, surplus_sp };

// Return value of Optimiser::is_candidate_valid, providing information on
// Return value of ProcessedSong::is_candidate_valid, providing information on
// whether an activation is valid, and if so the earliest position it can end.
struct ActResult {
Position ending_position;
Expand All @@ -88,6 +61,42 @@ struct Path {
// Represents a song processed for Star Power optimisation. The constructor
// should only fail due to OOM; invariants on the song are supposed to be
// upheld by the constructors of the arguments.
class ProcessedSong {
private:
// The order of these members is important. We must have m_converter before
// m_points.
TimeConverter m_converter;
PointSet m_points;
SpData m_sp_data;
int m_total_solo_boost;

public:
ProcessedSong(const NoteTrack& track, int resolution,
const SyncTrack& sync_track, double early_whammy,
double squeeze);

// Return the minimum and maximum amount of SP can be acquired between two
// points. Does not include SP from the point act_start. first_point is
// given for the purposes of counting SP grantings notes, e.g. if start is
// after the middle of first_point's timing window.
[[nodiscard]] SpBar total_available_sp(Beat start, PointPtr first_point,
PointPtr act_start) const;
// Returns an ActResult which says if an activation is valid, and if so the
// earliest position it can end.
[[nodiscard]] ActResult
is_candidate_valid(const ActivationCandidate& activation) const;
// Return the summary of a path.
[[nodiscard]] std::string path_summary(const Path& path) const;

[[nodiscard]] const PointSet& points() const { return m_points; }
[[nodiscard]] const SpData& sp_data() const { return m_sp_data; }
};

// The class that stores extra information needed on top of a ProcessedSong for
// the purposes of optimisation, and finds the optimal path. The song passed to
// Optimiser's constructor must outlive Optimiser; the class is done this way so
// that other code can make use of the PointIters that are returned by Optimiser
// without needing access to Optimiser itself.
class Optimiser {
private:
// The Cache is used to store paths starting from a certain point onwards,
Expand Down Expand Up @@ -119,9 +128,6 @@ class Optimiser {
const ProcessedSong* m_song;
std::vector<PointPtr> m_next_candidate_points;

static constexpr double MEASURES_PER_BAR = 8.0;
static constexpr double MINIMUM_SP_AMOUNT = 0.5;

[[nodiscard]] PointPtr next_candidate_point(PointPtr point) const;
[[nodiscard]] CacheKey advance_cache_key(CacheKey key) const;
[[nodiscard]] PointPtr act_end_lower_bound(PointPtr point, Measure pos,
Expand All @@ -136,14 +142,8 @@ class Optimiser {

public:
explicit Optimiser(const ProcessedSong* song);
// Returns an ActResult which says if an activation is valid, and if so the
// earliest position it can end.
[[nodiscard]] ActResult
is_candidate_valid(const ActivationCandidate& activation) const;
// Return the optimal Star Power path.
[[nodiscard]] Path optimal_path() const;
// Return the summary of a path.
[[nodiscard]] std::string path_summary(const Path& path) const;
};

#endif
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char** argv)
auto end = act.act_end->position.beat.value();
instructions.blue_ranges.emplace_back(start, end);
}
std::cout << optimiser.path_summary(path) << std::endl;
std::cout << processed_track.path_summary(path) << std::endl;
}
const auto image = create_path_image(instructions);
image.save(settings.image_path.c_str());
Expand Down
Loading

0 comments on commit 4ba2c11

Please sign in to comment.