-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_data.hpp
145 lines (108 loc) · 3.79 KB
/
level_data.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef LEVEL_DATA_HPP_INCLUDED
#define LEVEL_DATA_HPP_INCLUDED
#include <optional>
#include <string>
#include <map>
#include <dcpu16-sim/base_sim.hpp>
#include <dcpu16-ide/base_ide.hpp>
#include <dcpu16-sim/base_hardware.hpp>
#include <dcpu16-sim/all_hardware.hpp>
#include <deque>
#include "world_state.hpp"
#include "constant_time_exec.hpp"
#include "level_stats.hpp"
#include <atomic>
struct level_over_state
{
level_stats::info best_stats;
level_stats::info current_stats;
};
struct level_data
{
int cpus = 1;
std::string name;
std::string description;
std::string short_description;
std::string section;
std::optional<std::string> io_program;
std::optional<std::string> dynamic_validation_program;
std::vector<std::string> hardware_names;
std::vector<int> input_channels;
std::vector<int> output_channels;
bool unspecified_output_is_write = false;
bool unspecified_output_is_read = false;
bool is_input_channel(int c) const;
bool is_output_channel(int c) const;
};
struct level_runtime_parameters
{
void build_from(const level_data& data);
std::map<int, std::vector<uint16_t>> channel_to_input;
std::map<int, std::vector<uint16_t>> channel_to_output;
std::map<int, std::map<int, std::vector<int>>> output_to_input_start;
std::optional<std::shared_ptr<dcpu::sim::CPU>> io_cpu;
std::optional<std::shared_ptr<dcpu::sim::CPU>> dynamic_validation_cpu;
std::vector<dcpu::sim::hardware*> hardware;
//world_state real_world_state;
private:
void generate_io(std::span<dcpu::sim::hardware*> hw, const level_data& data);
};
struct assembler_state
{
bool has_error = false;
};
struct level_runtime_data
{
void build_from(const level_runtime_parameters& params);
world_state real_world_state;
std::map<int, std::deque<uint16_t>> input_queue;
std::optional<level_stats::info> current_run_stats;
std::optional<std::shared_ptr<dcpu::sim::CPU>> dynamic_validation_cpu;
std::vector<dcpu::sim::hardware*> hardware;
dcpu::sim::fabric fab;
constant_time_exec exec;
std::map<int, std::vector<uint16_t>> found_output;
};
struct runtime_errors
{
std::vector<int> error_locs;
std::vector<int> error_channels;
};
struct level_instance
{
level_data data;
level_runtime_parameters constructed_data;
level_runtime_data runtime_data;
assembler_state ass_state;
runtime_errors execution_state;
bool displayed_level_over = false;
bool successful_validation = false;
void update_assembly_errors(dcpu::ide::project_instance<dcpu::ide::editor>& instance);
};
struct all_level_data
{
std::vector<level_data> all_levels;
void load(const std::string& folder = "./levels");
level_instance make_instance(const level_data& data);
//void display_level_select();
};
struct level_manager
{
std::atomic_bool finished{false};
all_level_data levels;
std::optional<level_data> selected_level;
std::optional<level_instance> current_level;
bool should_return_to_main_menu = false;
void load(const std::string& folder = "./levels");
void save_current(dcpu::ide::project_instance<dcpu::ide::editor>& instance);
void back_to_main_menu();
void display_level_select(dcpu::ide::project_instance<dcpu::ide::editor>& instance);
void reset_level(dcpu::ide::project_instance<dcpu::ide::editor>& instance);
//void start_level(const std::string& level);
//void setup_validation(dcpu::ide::project_instance& instance);
void step_validation(dcpu::ide::project_instance<dcpu::ide::editor>& instance);
private:
void switch_to_level(dcpu::ide::project_instance<dcpu::ide::editor>& instance, const level_data& data);
void start_level(dcpu::ide::project_instance<dcpu::ide::editor>& instance, const level_data& data);
};
#endif // LEVEL_DATA_HPP_INCLUDED