Skip to content

Commit

Permalink
Add options to set size and select which frames to draw
Browse files Browse the repository at this point in the history
  • Loading branch information
mls-m5 committed Nov 4, 2023
1 parent 2d642cf commit 9510e0d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/codeplayback/codeplayback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ int main(int argc, char *argv[]) {
for (auto &edit : edits) {
std::cout << currentEdit << "/" << count << std::endl;
++currentEdit;

if (currentEdit < settings.startFrameNumber ||
currentEdit > settings.stopFrameNumber) {
continue;
}

drawBufferEdit(edit);
if (!isRunning) {
break;
Expand Down
8 changes: 5 additions & 3 deletions src/codeplayback/edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct FrameNumLineDescription {
BlockEnd,
};

#if 0
bool tryPrefix(const std::string fullLine) {
auto line = fullLine;
std::string beginStr = std::string{};
Expand Down Expand Up @@ -101,6 +102,7 @@ struct FrameNumLineDescription {
this->line = line;
return true;
}
#endif

/// For formating sake i sometimes comment out some of the versions
/// so that you could run clang-format on the file without it being messed
Expand Down Expand Up @@ -204,9 +206,9 @@ struct FrameNumLineDescription {
}

FrameNumLineDescription(const std::string &fullLine) {
if (tryPrefix(fullLine)) {
return;
}
// if (tryPrefix(fullLine)) {
// return;
// }

tryComments(fullLine);
}
Expand Down
30 changes: 30 additions & 0 deletions src/codeplayback/playbacksettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

constexpr auto helpStr = R"_(
Expand All @@ -12,6 +14,11 @@ code_playback scriptfile.txt [options]
flags:
--help print this text
--profiling enable profiling
--start start frame number
--stop stop frame number
--size set font size
--width character width
--height character height
)_";

struct CodePlaybackSettings {
Expand All @@ -21,6 +28,9 @@ struct CodePlaybackSettings {
int fontSize = 30;
bool shouldEnableProfiling = false;

int startFrameNumber = 0;
int stopFrameNumber = std::numeric_limits<int>::max();

CodePlaybackSettings(int argc, char **argv) {
auto args = std::vector<std::string>{argv + 1, argv + argc};

Expand All @@ -35,7 +45,27 @@ struct CodePlaybackSettings {
std::cout << "profiling enabled..." << std::endl;
shouldEnableProfiling = true;
}
else if (arg == "--start") {
startFrameNumber = std::stoi(args.at(++i));
}
else if (arg == "--stop") {
stopFrameNumber = std::stoi(args.at(++i));
}
else if (arg == "--size" || arg == "-s") {
fontSize = std::stoi(args.at(++i));
}
else if (arg == "--width" || arg == "-w") {
viewportWidth = std::stoi(args.at(++i));
}
else if (arg == "--height" || arg == "-h") {
viewportHeight = std::stoi(args.at(++i));
}
else {
if (arg.starts_with('-')) {
std::cerr << helpStr << "\n";
std::cerr << "unknown argument " << arg << "\n";
std::exit(1);
}
scriptFile = arg;
}
}
Expand Down

0 comments on commit 9510e0d

Please sign in to comment.