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

#include "audio/audio_asset.hpp"
#include "game_engine.hpp"
Florian Oetke's avatar
Florian Oetke committed
5
#include "gameplay/beat_system.hpp"
6
#include "gameplay/camera_system.hpp"
7
#include "gameplay/combat_system.hpp"
Florian Oetke's avatar
Florian Oetke committed
8
#include "gameplay/dash_system.hpp"
9
#include "gameplay/enemy_system.hpp"
Florian Oetke's avatar
Florian Oetke committed
10
#include "gameplay/killable_comp.hpp"
11
#include "gameplay/movement_system.hpp"
12
#include "helper/attachment_system.hpp"
Florian Oetke's avatar
Florian Oetke committed
13
#include "input/input_system.hpp"
Georg Schäfer's avatar
Georg Schäfer committed
14
#include "level/level_system.hpp"
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#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)
	  , _audio()
	  , _renderer(engine.renderer_factory().create_renderer(_entities, engine.render_pass_mask()))
	  , _model_loading(std::make_unique<renderer::Loading_system>(_entities, engine.assets()))
Kevin Balz's avatar
Kevin Balz committed
35
	  , _beat_system(std::make_unique<gameplay::Beat_system>(engine.bus(), engine.assets()))
Florian Oetke's avatar
Florian Oetke committed
36
37
38
	  , _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
39
	  , _input_system(std::make_unique<input::Input_system>(engine.bus(), _entities))
40
	  , _combat_system(std::make_unique<gameplay::Combat_system>(engine.bus(), _entities, *_beat_system))
41
	  , _attachment_system(std::make_unique<helper::Attachment_system>(_entities))
42
	  , _hud_system(std::make_unique<ui::Hud_system>(engine.gui(), _entities, *_beat_system))
43
	  , _camera_system(std::make_unique<gameplay::Camera_system>(_entities))
44
	  , _enemy_system(std::make_unique<gameplay::Enemy_system>(_entities))
Kevin Balz's avatar
Dash    
Kevin Balz committed
45
	  , _dash_system(std::make_unique<gameplay::Dash_system>(_entities))
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
	{
		_entities.register_component_type<ecs::components::Transform_comp>();

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

		eam::settings setting{{16, true, false, false}, 2, 48000, 1024};
		_audio.set_sink<eam::sdl_sink>(setting);
		_audio.set_master_volume(35);
		/*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();
			}
		});

88
		_level_system->load("dummy");
89
90
91
92
93
94
95
96
97
98
99
100
	}

	Meta_system::~Meta_system()
	{
		_renderer->device().wait_idle();
		_entities.clear();
	}

	void Meta_system::update(mirrage::util::Time dt)
	{
		_entities.process_queued_actions();

Florian Oetke's avatar
Florian Oetke committed
101
		_beat_system->update(dt);
Florian Oetke's avatar
Florian Oetke committed
102
		_input_system->update(dt);
Georg Schäfer's avatar
Georg Schäfer committed
103
		_level_system->update(dt);
Kevin Balz's avatar
Dash    
Kevin Balz committed
104
		_dash_system->update(dt);
Florian Oetke's avatar
Florian Oetke committed
105
		_movement_system->update(dt);
106
		_combat_system->update(dt);
107
		_camera_system->update(dt);
108
		_enemy_system->update(dt);
Florian Oetke's avatar
Florian Oetke committed
109

110
111
112
113
114
		_attachment_system->update(dt);

		_hud_system->update(dt);

		_model_loading->update(dt);
Florian Oetke's avatar
Florian Oetke committed
115
		_renderer->update(dt * _beat_system->graphic_time_scale());
116
117
118
119
120
121
122
123
	}
	void Meta_system::draw()
	{
		_hud_system->draw();
		_renderer->draw();
	}


Florian Oetke's avatar
Florian Oetke committed
124
125
	void Meta_system::pause() { _input_system->disable(); }
	void Meta_system::resume() { _input_system->enable(); }
126
127
128
129

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

} // namespace phase_shifter