Commit b25a522a authored by Florian Oetke's avatar Florian Oetke

Merge branch 'develop' of...

Merge branch 'develop' of gitlab.fsi.hochschule-trier.de:GameDevWeek/sommersemester-2019/cpp/phaseshifter into develop
parents 72530708 593e9372
Pipeline #3301 passed with stage
in 2 minutes and 33 seconds
1.834376418:
2.275555557:
2.728344672:
3.215963720:
3.552653062:
3.900952382:
4.237641724:
4.597551021:
5.050340137:
5.503129253:
5.979138323:
6.431927439:
6.884716554:
7.349115647:
7.825124718:
8.277913833:
8.730702949:
9.171882087:
9.624671203:
10.077460318:
10.518639457:
10.959818595:
11.412607711:
11.853786849:
12.294965987:
12.747755103:
13.200544219:
13.630113380:
14.082902495:
14.524081634:
14.965260772:
15.418049888:
15.859229026:
16.358458051:
16.811247167:
17.264036282:
17.716825398:
18.204444445:
18.657233561:
19.110022677:
19.551201815:
20.003990931:
20.456780046:
20.897959185:
21.350748300:
21.791927439:
22.476916101:
22.929705216:
23.382494332:
23.742403629:
24.195192745:
24.647981860:
25.100770976:
25.588390024:
26.041179139:
26.493968255:
27.190566894:
27.643356010:
28.096145126:
28.583764173:
29.036553289:
29.489342405:
29.965351475:
30.418140591:
30.870929706:
31.346938776:
31.799727892:
32.252517008:
32.740136055:
33.192925171:
33.645714287:
34.098503402:
34.539682541:
34.992471656:
35.445260772:
35.967709752:
36.420498867:
36.873287983:
37.349297053:
37.802086169:
38.254875284:
38.730884355:
39.183673470:
39.648072563:
40.124081634:
40.576870749:
41.029659865:
41.482448981:
41.970068028:
42.422857144:
42.875646259:
43.351655330:
43.804444445:
44.257233561:
44.733242631:
45.186031747:
45.638820863:
46.126439910:
46.579229026:
47.032018142:
47.484807257:
47.925986396:
48.378775511:
48.831564627:
49.354013606:
49.806802722:
50.259591838:
50.735600908:
51.188390024:
51.641179139:
52.082358278:
52.535147393:
52.987936509:
53.440725625:
53.881904763:
54.334693879:
54.787482994:
55.228662132:
55.669841271:
56.122630386:
56.563809525:
57.004988663:
57.457777779:
57.898956917:
58.340136055:
58.781315194:
59.234104309:
59.663673470:
60.116462586:
60.557641724:
60.998820863:
61.440000001:
61.881179139:
62.333968255:
62.763537416:
63.216326532:
63.669115647:
64.098684808:
64.551473924:
65.004263040:
65.445442178:
65.886621316:
66.339410432:
66.792199547:
67.361088436:
67.813877552:
68.266666668:
68.707845806:
69.160634922:
69.613424037:
70.124263040:
70.577052155:
71.029841271:
71.471020409:
71.923809525:
72.376598640:
72.817777779:
73.270566894:
73.723356010:
74.176145126:
74.733424037:
75.186213153:
75.639002269:
76.347210885:
76.800000001:
77.287619049:
77.740408164:
78.193197280:
78.645986396:
79.133605443:
79.586394559:
80.039183674:
80.515192745:
80.967981860:
81.420770976:
81.908390024:
82.361179139:
82.813968255:
83.289977325:
83.742766441:
84.195555557:
84.648344672:
85.356553289:
85.809342405:
86.285351475:
86.738140591:
87.190929706:
87.678548754:
88.131337869:
88.584126985:
89.036916101:
89.512925171:
89.965714287:
90.430113380:
90.906122450:
91.358911566:
91.811700681:
92.287709752:
92.740498867:
93.204897960:
93.669297053:
94.122086169:
94.574875284:
95.027664400:
95.735873017:
96.188662132:
96.676281180:
97.129070296:
97.581859411:
98.057868482:
98.510657597:
98.963446713:
99.416235829:
99.892244899:
100.345034015:
100.797823130:
101.285442178:
101.738231293:
102.191020409:
102.899229026:
103.352018142:
103.804807257:
104.280816328:
104.733605443:
105.186394559:
105.662403629:
106.115192745:
106.567981860:
107.043990931:
107.496780046:
107.949569162:
108.402358278:
108.843537416:
109.284716554:
109.737505670:
110.271564627:
110.724353742:
111.177142858:
111.618321996:
112.071111112:
112.523900228:
113.046349207:
113.499138323:
113.951927439:
114.427936509:
114.880725625:
115.333514740:
115.786303856:
116.273922903:
116.726712019:
117.179501135:
117.655510205:
118.108299321:
118.561088436:
119.002267575:
119.455056690:
119.907845806:
120.430294786:
120.883083901:
121.335873017:
121.788662132:
122.229841271:
122.682630386:
123.135419502:
123.657868482:
124.110657597:
124.563446713:
125.051065761:
125.503854876:
125.945034015:
126.386213153:
126.839002269:
127.291791384:
127.744580500:
128.185759638:
128.638548754:
129.091337869:
129.532517008:
129.985306123:
130.438095239:
131.041814060:
131.494603176:
131.947392291:
132.388571430:
132.841360545:
133.294149661:
133.723718822:
134.176507937:
134.629297053:
135.082086169:
135.523265307:
135.976054423:
136.428843538:
136.858412699:
137.311201815:
137.763990931:
138.193560092:
138.646349207:
139.099138323:
139.551927439:
139.993106577:
140.445895693:
140.898684808:
141.339863947:
141.792653062:
142.245442178:
142.686621316:
143.127800454:
143.580589570:
144.033378686:
144.474557824:
144.927346940:
145.380136055:
145.809705216:
146.262494332:
146.715283448:
147.156462586:
147.609251702:
148.062040817:
148.514829933:
148.956009071:
149.408798187:
149.849977325:
150.291156464:
150.743945579:
151.196734695:
151.637913833:
152.090702949:
152.543492064:
152.996281180:
153.646439910:
154.099229026:
154.586848074:
155.039637189:
155.492426305:
155.945215420:
156.386394559:
156.827573697:
157.280362813:
157.721541951:
158.174331067:
158.627120182:
159.068299321:
159.521088436:
159.973877552:
160.426666668:
161.030385489:
161.483174604:
162.377142858:
162.818321996:
163.271111112:
163.712290250:
164.165079366:
164.617868482:
165.337687076:
165.790476191:
166.243265307:
166.719274377:
167.160453516:
167.613242631:
168.100861679:
168.553650795:
169.006439910:
169.482448981:
169.935238096:
......@@ -8,8 +8,6 @@
namespace phase_shifter::gameplay {
namespace {
constexpr auto beat_time = 1.f;
auto smootherstep(float edge0, float edge1, float x)
{
x = std::clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
......@@ -17,23 +15,40 @@ namespace phase_shifter::gameplay {
}
} // namespace
Beat_system::Beat_system(mirrage::util::Message_bus& bus) : _bus(bus) {}
Beat_system::Beat_system(mirrage::util::Message_bus& bus, mirrage::asset::Asset_manager& assets)
: _bus(bus), _assets(assets)
{
auto input = _assets.open(mirrage::asset::AID("beat:pulse")).get_or_throw();
std::string line;
int i = 0;
while(std::getline(input, line)) {
_time_stamps.push_back(static_cast<float>(atof(line.substr(1, line.length() - 4).c_str())));
i++;
}
_state.avg_beat_time = static_cast<float>(_time_stamps[_time_stamps.size() - 1]) / _time_stamps.size();
}
void Beat_system::update(mirrage::util::Time dt)
{
_acc += dt.value();
auto beat = _acc >= beat_time;
int size = static_cast<int>(_time_stamps.size());
auto beat = _beat_index + 1 < size && _acc >= _time_stamps[_beat_index + 1];
if(beat) {
_state.beats_left--;
_beat_index++;
LOG(plog::debug) << "beat";
_acc = 0;
if(_state.beats_left == 0) {
if(_beat_index + 1 >= size) {
_bus.send<Lose_msg>();
}
}
_state = {beat, _acc, beat_time - _acc, beat_time, _state.beats_left};
_state = {beat,
_beat_index >= 0 ? _acc - _time_stamps[_beat_index] : _acc,
_beat_index + 1 < size ? _time_stamps[_beat_index + 1] - _acc : 999,
_state.avg_beat_time,
size - 1 - _beat_index
};
}
auto Beat_system::graphic_time_scale() const -> float
......@@ -61,4 +76,12 @@ namespace phase_shifter::gameplay {
}
}
const std::vector<float>& Beat_system::time_stamps() const {
return _time_stamps;
}
int Beat_system::beat_index() const {
return _beat_index;
}
} // namespace phase_shifter::gameplay
......@@ -2,6 +2,8 @@
#include <mirrage/utils/messagebus.hpp>
#include <mirrage/utils/units.hpp>
#include <vector>
#include <mirrage/asset/asset_manager.hpp>
namespace phase_shifter::gameplay {
......@@ -17,7 +19,7 @@ namespace phase_shifter::gameplay {
// TODO: replace placeholder logic with actual beat detection
class Beat_system {
public:
Beat_system(mirrage::util::Message_bus&);
Beat_system(mirrage::util::Message_bus&, mirrage::asset::Asset_manager&);
void update(mirrage::util::Time);
......@@ -27,10 +29,16 @@ namespace phase_shifter::gameplay {
auto graphic_time_scale() const -> float;
const std::vector<float>& time_stamps() const ;
int beat_index() const;
private:
mirrage::util::Message_bus& _bus;
mirrage::asset::Asset_manager& _assets;
Beat_state _state;
float _acc = 0.f;
std::vector<float> _time_stamps;
int _beat_index = -1;
};
} // namespace phase_shifter::gameplay
......@@ -32,7 +32,7 @@ namespace phase_shifter {
, _audio()
, _renderer(engine.renderer_factory().create_renderer(_entities, engine.render_pass_mask()))
, _model_loading(std::make_unique<renderer::Loading_system>(_entities, engine.assets()))
, _beat_system(std::make_unique<gameplay::Beat_system>(engine.bus()))
, _beat_system(std::make_unique<gameplay::Beat_system>(engine.bus(), engine.assets()))
, _level_system(std::make_unique<level::Level_system>(_entities, engine.assets()))
, _movement_system(std::make_unique<gameplay::Movement_system>(
engine.bus(), _entities, *_beat_system, *_level_system))
......
......@@ -14,9 +14,10 @@ namespace phase_shifter::ui {
namespace {
constexpr auto hud_height = 100;
constexpr auto bar_height = 90;
constexpr auto beat_bar_height = 80;
constexpr auto bar_height = 80;
constexpr auto beat_bar_height = 79;
constexpr auto bar_speed = 100;
constexpr auto beat_bar_length = 300.0f;
} // namespace
Hud_system::Hud_system(mirrage::gui::Gui& gui,
......@@ -27,9 +28,8 @@ namespace phase_shifter::ui {
//_circle_texture = _gui.load_texture("tex:circle"_aid);
}
void Hud_system::update(mirrage::util::Time dt)
{
_offset = _beat_system.beat_state().time_to_beat * bar_speed;
void Hud_system::update(mirrage::util::Time dt) {
_passed += dt.value();
}
void Hud_system::draw()
......@@ -63,20 +63,27 @@ namespace phase_shifter::ui {
ImGui::PushStyleColor(ImGuiCol_Border, "#00000000"_imcolor.Value); // Hide Border
ImVec2 cursor = ImGui::GetCursorScreenPos();
cursor.y += hud_height / 2.f - 10;
auto beat_state = _beat_system.beat_state();
auto line_offset = bar_speed * beat_state.avg_beat_time;
auto beats = std::clamp(beat_state.beats_left, 0, 5);
auto beat_state = _beat_system.beat_state();
auto beats = _beat_system.time_stamps();
auto beat_index = _beat_system.beat_index() + 1;
//auto line_offset = bar_speed * beat_state.avg_beat_time;
//auto beats = std::clamp(beat_state.beats_left, 0, 5);
ImGui::BeginChild("Line", {viewport.z, bar_height}, true);
ImDrawList* drawList = ImGui::GetWindowDrawList();
for(int i = 0; i < beats; i++) {
auto x_offset = _offset + i * line_offset;
auto height = beat_bar_height * (1.f - glm::smoothstep(0.f, beats * line_offset, x_offset));
while (beat_index < static_cast<int>(beats.size())) {
auto x_offset = (beats[beat_index] - _passed) * bar_speed;
auto height = beat_bar_height * (1.f - glm::smoothstep(0.f, beat_bar_length, x_offset));
ImVec2 p(cursor.x + viewport.z / 2 - x_offset, cursor.y - height / 2.f);
drawList->AddLine(p, {p.x, p.y + height}, 0xFFFFFFFF, 1);
p.x = cursor.x + viewport.z / 2 + x_offset;
drawList->AddLine(p, {p.x, p.y + height}, 0xFFFFFFFF, 1);
if(x_offset > beat_bar_length + 50) {
break;
}
beat_index++;
}
ImVec2 middle(cursor.x + viewport.z / 2, cursor.y - bar_height / 2.f);
......
......@@ -24,7 +24,7 @@ namespace phase_shifter::ui {
private:
mirrage::gui::Gui& _gui;
mirrage::ecs::Entity_manager& _ecs;
float _offset = 0;
float _passed = 0;
const phase_shifter::gameplay::Beat_system& _beat_system;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment