-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
326 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <cassert> | ||
#include <map> | ||
#include <ranges> | ||
#include <simulator/garbage.hpp> | ||
#include <simulator/tetrion.hpp> | ||
|
||
[[nodiscard]] tl::optional<ObpfTetrion&> determine_garbage_target( | ||
std::vector<ObpfTetrion*> const& tetrions, | ||
u8 const sender_tetrion_id, | ||
u64 const frame | ||
) { | ||
if (tetrions.size() < 2) { | ||
assert(tetrions.empty() or tetrions.front()->id() == sender_tetrion_id); | ||
return tl::nullopt; | ||
} | ||
|
||
auto alive_tetrions = std::map<u8, ObpfTetrion*>{}; | ||
for (auto const tetrion : tetrions) { | ||
if (tetrion->id() == sender_tetrion_id) { | ||
continue; | ||
} | ||
if (auto const game_over_since_frame = tetrion->game_over_since_frame(); | ||
game_over_since_frame.has_value() and frame >= game_over_since_frame.value()) { | ||
continue; | ||
} | ||
alive_tetrions[tetrion->id()] = tetrion; | ||
} | ||
if (alive_tetrions.empty()) { | ||
return tl::nullopt; | ||
} | ||
auto const find_iterator = std::ranges::find_if(alive_tetrions, [sender_tetrion_id](auto const& pair) { | ||
auto const id = pair.first; | ||
return id > sender_tetrion_id; | ||
}); | ||
if (find_iterator != alive_tetrions.end()) { | ||
return *(find_iterator->second); | ||
} | ||
assert(alive_tetrions.begin()->first != sender_tetrion_id); | ||
return *(alive_tetrions.begin()->second); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <lib2k/types.hpp> | ||
#include <tl/optional.hpp> | ||
#include <vector> | ||
|
||
struct GarbageSendEvent { | ||
u64 frame; | ||
u8 num_lines; | ||
|
||
explicit constexpr GarbageSendEvent(u64 const frame, u8 const num_lines) | ||
: frame{ frame }, num_lines{ num_lines } {} | ||
}; | ||
|
||
struct ObpfTetrion; | ||
|
||
[[nodiscard]] tl::optional<ObpfTetrion&> determine_garbage_target( | ||
std::vector<ObpfTetrion*> const& tetrions, | ||
u8 sender_tetrion_id, | ||
u64 frame | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.