R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
input_script.hpp
Go to the documentation of this file.
1
3#pragma once
4#include <aegis2d/ecs/components.hpp>
5
6#include <chrono>
7#include <cstddef>
8#include <cstdint>
9#include <filesystem>
10#include <string>
11#include <string_view>
12#include <variant>
13#include <vector>
14
15namespace rtype {
16
18struct ScriptStep {
20 std::chrono::milliseconds duration{};
22 std::uint8_t held = 0;
23};
24
28 std::vector<ScriptStep> steps;
29};
30
43[[nodiscard]] std::variant<InputScript, std::string> parse_input_script(std::string_view text);
44
48[[nodiscard]] std::variant<InputScript, std::string>
49load_input_script(const std::filesystem::path& file);
50
53public:
55 using Clock = std::chrono::steady_clock;
56
59 explicit ScriptedInputs(InputScript script);
60
64 [[nodiscard]] aegis2d::ecs::PlayerInput update(Clock::time_point now);
65
68 [[nodiscard]] std::uint64_t picks() const noexcept;
69
70private:
71 InputScript script_;
72 std::size_t step_ = 0;
73 Clock::time_point until_{};
74 std::uint64_t picks_ = 0;
75};
76
77} // namespace rtype
Plays an input script from the first call to update(), looping at its end.
Definition input_script.hpp:52
std::uint64_t picks() const noexcept
Number of steps started.
ScriptedInputs(InputScript script)
Creates the player of a script.
std::chrono::steady_clock Clock
Clock of the steps.
Definition input_script.hpp:55
aegis2d::ecs::PlayerInput update(Clock::time_point now)
The input to hold now, by the time since the first call.
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
std::variant< InputScript, std::string > load_input_script(const std::filesystem::path &file)
Reads an input script from a file.
std::variant< InputScript, std::string > parse_input_script(std::string_view text)
Reads an input script.
A sequence of inputs, played in order, then again from the start.
Definition input_script.hpp:26
std::vector< ScriptStep > steps
The steps, at least one, each at least 1 ms long.
Definition input_script.hpp:28
One line of an input script: actions held for a time.
Definition input_script.hpp:18
std::chrono::milliseconds duration
How long the actions are held.
Definition input_script.hpp:20
std::uint8_t held
Held actions, one ecs::Action bit each.
Definition input_script.hpp:22