-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing replay files. Introduce line marker graphics, homemade GO…
…AL sign
- Loading branch information
1 parent
9315866
commit 8fb7919
Showing
8 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,82 @@ | ||
#include "replay_helpers.hpp" | ||
#include <cstring> | ||
#include "recorder.hpp" | ||
|
||
u32 ReplayInputDataSource::trigger() const | ||
{ | ||
if (index >= data.size()) return 0; | ||
return data[index].trigger; | ||
} | ||
|
||
u32 ReplayInputDataSource::held() const | ||
{ | ||
if (index >= data.size()) return 0; | ||
return data[index].held; | ||
} | ||
|
||
void ReplayInputDataSource::update() | ||
{ | ||
if (index >= data.size()) return; | ||
frame++; | ||
if (frame - start > data[index].frames) | ||
{ | ||
start += data[index].frames; | ||
index++; | ||
} | ||
} | ||
|
||
bool load_replay(const std::string& filename, ReplayInfo& info) | ||
{ | ||
std::ifstream file(filename.c_str(), std::ios::binary); | ||
return load_replay(file, info); | ||
} | ||
|
||
bool load_replay(std::istream& file, ReplayInfo& info) | ||
{ | ||
char magic[4]; | ||
|
||
file.read(magic, 4); | ||
if (memcmp(magic, "BBB", 4) != 0) | ||
return false; | ||
|
||
char major = file.get(); | ||
char minor = file.get(); | ||
|
||
if (major != RECORDER_MAJOR_VERSION) | ||
return false; | ||
if (minor != RECORDER_MINOR_VERSION) | ||
return false; | ||
|
||
info.rows = file.get(); | ||
info.columns = file.get(); | ||
info.type = file.get(); | ||
info.difficulty = file.get(); | ||
info.level = file.get(); | ||
|
||
std::vector<Panel::Type> initial; | ||
unsigned int size = info.rows * info.columns; | ||
initial.reserve(size); | ||
for (unsigned int i = 0; i < size; i++) | ||
initial.push_back(static_cast<Panel::Type>(file.get())); | ||
|
||
file.read(reinterpret_cast<char*>(&size), sizeof(size)); | ||
std::vector<Panel::Type> next; | ||
next.reserve(size); | ||
for (unsigned int i = 0; i < size; i++) | ||
next.push_back(static_cast<Panel::Type>(file.get())); | ||
|
||
info.source.reset(new ReplayPanelSource(info.rows, info.columns, initial, next)); | ||
|
||
file.read(reinterpret_cast<char*>(&size), sizeof(size)); | ||
std::vector<ReplayInputItem> items; | ||
for (unsigned int i = 0; i < size; i++) | ||
{ | ||
ReplayInputItem move; | ||
file.read(reinterpret_cast<char*>(&move), sizeof(move)); | ||
items.emplace_back(move); | ||
} | ||
|
||
info.input.reset(new ReplayInputDataSource(items)); | ||
|
||
return true; | ||
} |
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,68 @@ | ||
#ifndef REPLAY_HELPERS_HPP | ||
#define REPLAY_HELPERS_HPP | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <memory> | ||
#include <vector> | ||
|
||
#include <util/input_data_source_interface.hpp> | ||
|
||
#include "panel_source.hpp" | ||
|
||
struct ReplayInputItem | ||
{ | ||
u32 trigger; | ||
u32 held; | ||
u32 frames; | ||
}; | ||
|
||
class ReplayPanelSource : public PanelSource | ||
{ | ||
public: | ||
ReplayPanelSource(int rows, int columns, const std::vector<Panel::Type>& start, const std::vector<Panel::Type> next_set) : | ||
PanelSource(rows, columns), initial(start), next(next_set), index(0) {} | ||
~ReplayPanelSource() {} | ||
std::vector<Panel::Type> board() override {return initial;} | ||
Panel::Type panel() override | ||
{ | ||
if (index >= next.size()) return Panel::EMPTY; | ||
return next[index++]; | ||
} | ||
private: | ||
std::vector<Panel::Type> initial; | ||
std::vector<Panel::Type> next; | ||
unsigned int index; | ||
}; | ||
|
||
class ReplayInputDataSource : public InputDataSourceInterface | ||
{ | ||
public: | ||
ReplayInputDataSource(const std::vector<ReplayInputItem>& items) : data(items), index(0) {} | ||
~ReplayInputDataSource() {} | ||
u32 trigger() const override; | ||
u32 held() const override; | ||
void update() override; | ||
private: | ||
std::vector<ReplayInputItem> data; | ||
unsigned int index; | ||
unsigned int start; | ||
unsigned int frame; | ||
|
||
}; | ||
|
||
struct ReplayInfo | ||
{ | ||
std::unique_ptr<ReplayPanelSource> source; | ||
std::unique_ptr<ReplayInputDataSource> input; | ||
char rows; | ||
char columns; | ||
char type; | ||
char difficulty; | ||
char level; | ||
}; | ||
|
||
bool load_replay(const std::string& filename, ReplayInfo& info); | ||
bool load_replay(std::istream& file, ReplayInfo& info); | ||
|
||
#endif |
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