meta_system.cpp 5.52 KB
Newer Older
1
2
3
#include "meta_system.hpp"

#include "audio/audio_asset.hpp"
Florian Oetke's avatar
Florian Oetke committed
4
#include "audio/sound_manager.hpp"
5
#include "game_engine.hpp"
Florian Oetke's avatar
Florian Oetke committed
6
#include "gameplay/beat_system.hpp"
7
#include "gameplay/camera_system.hpp"
8
#include "gameplay/combat_system.hpp"
9
#include "gameplay/dash_system.hpp"
10
#include "gameplay/enemy_system.hpp"
11
#include "gameplay/killable_comp.hpp"
12
#include "gameplay/movement_system.hpp"
13
#include "gameplay/stationary_attack_system.hpp"
14
#include "helper/attachment_system.hpp"
Florian Oetke's avatar
Florian Oetke committed
15
#include "input/input_system.hpp"
Georg Schäfer's avatar
Georg Schäfer committed
16
#include "level/level_system.hpp"
17
#include "ui/effect_system.hpp"
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "ui/hud_system.hpp"

#include <context.hpp>
#include <mirrage/ecs/components/transform_comp.hpp>
#include <mirrage/renderer/deferred_renderer.hpp>
#include <mirrage/renderer/loading_system.hpp>
#include <settings.hpp>
#include <sinks/sdl_sink.hpp>
#include <sources/opus.hpp>


namespace phase_shifter {
	using namespace mirrage;
	using namespace mirrage::ecs::components;

	Meta_system::Meta_system(Game_engine& engine)
	  : _entities(engine.assets(), this)
	  , _renderer(engine.renderer_factory().create_renderer(_entities, engine.render_pass_mask()))
	  , _model_loading(std::make_unique<renderer::Loading_system>(_entities, engine.assets()))
37
	  , _sound_manager(std::make_unique<audio::Sound_manager>(engine.audio(), engine.bus(), engine.assets()))
Kevin Balz's avatar
Kevin Balz committed
38
	  , _beat_system(std::make_unique<gameplay::Beat_system>(engine.bus(), engine.assets()))
Florian Oetke's avatar
Florian Oetke committed
39
40
41
	  , _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))
Florian Oetke's avatar
Florian Oetke committed
42
	  , _input_system(std::make_unique<input::Input_system>(engine.bus(), _entities))
43
	  , _combat_system(std::make_unique<gameplay::Combat_system>(engine.bus(), _entities, *_beat_system))
44
	  , _attachment_system(std::make_unique<helper::Attachment_system>(_entities))
45
	  , _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities, *_beat_system))
46
	  , _camera_system(std::make_unique<gameplay::Camera_system>(_entities))
47
	  , _enemy_system(std::make_unique<gameplay::Enemy_system>(engine.bus(), _entities, *_beat_system))
48
	  , _dash_system(std::make_unique<gameplay::Dash_system>(engine.bus(), _entities))
49
50
	  , _stationary_attack_system(
	            std::make_unique<gameplay::Stationary_attack_system>(engine.bus(), _entities))
51
	  , _effect_system(std::make_unique<ui::Effect_system>(engine.bus(), _entities))
52
	{
Florian Oetke's avatar
Florian Oetke committed
53
54
		_sound_manager->load_effects_file("cfg:sound_effects"_aid);

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
		_entities.register_component_type<ecs::components::Transform_comp>();

		//auto s                     = _renderer->settings();
		//s.scene_luminance_override = 300.f;
		//_renderer->settings(s, false);

		/*auto bg_music =
		        engine.assets().load<std::shared_ptr<eam::opus>>("audio:bg_music_01"_aid).get_blocking();
		auto bg_context = _audio.generate_context(bg_music);
		bg_context.get_object()->set_loops(-1);
		bg_context.get_object()->set_volume(50);
		bg_context.play_fade(2);
*/
		_commands.add("reload | Reloads most assets", [&] { engine.assets().reload(); });

		_commands.add("ecs.emplace <blueprint> | Creates a new entity in front of the current camera",
		              [&](std::string blueprint) {
			              auto  pos  = glm::vec3(0, 0, 0);
			              float prio = -1.f;
			              for(auto&& [transform, cam] :
			                  _entities.list<Transform_comp, renderer::Camera_comp>()) {
				              if(cam.priority() > prio) {
					              prio = cam.priority();
					              pos  = transform.position + transform.direction() * 2.f;
				              }
			              }
			              _entities.entity_builder(blueprint).position(pos).create();
		              });

		_commands.add("mem.renderer | Prints memory usage of renderer", [&] {
			IF_LOG(plog::info)
			{
				auto msg = std::stringstream();
				_renderer->device().print_memory_usage(msg);
				LOG(plog::info) << "Renderer Memory usage: " << msg.str();
			}
		});
92
		_level_system->load("dummy");
Georg Schäfer's avatar
Georg Schäfer committed
93
94
95
96
97
98

		auto bg_music = engine.assets().load<std::shared_ptr<eam::opus>>("music:pulse"_aid).get_blocking();
		_music        = engine.audio().generate_context_ptr(bg_music);
		_music->get_object()->set_loops(-1);
		_music->get_object()->set_position(engine.audio_latency()
		                                   / _music->get_object()->get_length_in_sec());
99
100
101
102
	}

	Meta_system::~Meta_system()
	{
Georg Schäfer's avatar
Georg Schäfer committed
103
		_music->stop_fade(2.f);
104
105
106
107
108
109
		_renderer->device().wait_idle();
		_entities.clear();
	}

	void Meta_system::update(mirrage::util::Time dt)
	{
Georg Schäfer's avatar
Georg Schäfer committed
110
111
112
113
114
115
116
117
		if(_play_music) {
			_play_music = false;
			_music->play();
		} else if(_first_frame) {
			_play_music  = true;
			_first_frame = false;
		}

118
119
		_entities.process_queued_actions();

Florian Oetke's avatar
Florian Oetke committed
120
		_beat_system->update(dt);
Florian Oetke's avatar
Florian Oetke committed
121
		_input_system->update(dt);
Georg Schäfer's avatar
Georg Schäfer committed
122
		_level_system->update(dt);
Kevin Balz's avatar
Dash    
Kevin Balz committed
123
		_dash_system->update(dt);
Kevin Balz's avatar
Kevin Balz committed
124
		_stationary_attack_system->update(dt);
125
		_enemy_system->update(dt);
Florian Oetke's avatar
Florian Oetke committed
126
		_movement_system->update(dt);
127
		_combat_system->update(dt);
128
		_camera_system->update(dt);
Florian Oetke's avatar
Florian Oetke committed
129

130
131
		_attachment_system->update(dt);

132
		_effect_system->update(dt);
133
134
135
		_hud_system->update(dt);

		_model_loading->update(dt);
136
		_level_system->draw(*_renderer);
Florian Oetke's avatar
Florian Oetke committed
137
		_renderer->update(dt * _beat_system->graphic_time_scale());
Florian Oetke's avatar
Florian Oetke committed
138
		_sound_manager->update(dt);
139
140
141
142
143
144
145
146
	}
	void Meta_system::draw()
	{
		_hud_system->draw();
		_renderer->draw();
	}


Florian Oetke's avatar
Florian Oetke committed
147
148
149
150
151
152
153
154
155
156
	void Meta_system::pause()
	{
		_input_system->disable();
		_sound_manager->pause();
	}
	void Meta_system::resume()
	{
		_input_system->enable();
		_sound_manager->resume();
	}
157
158
159
160

	void Meta_system::shrink_to_fit() { _renderer->shrink_to_fit(); }

} // namespace phase_shifter