fix entt update

This commit is contained in:
Green Sky 2020-12-12 18:21:45 +01:00
parent f62ed43209
commit 1d59003858
26 changed files with 91 additions and 50 deletions

View File

@ -11,6 +11,8 @@
using ::testing::Return;
using ::testing::_;
using namespace entt::literals;
class MockService : public MM::Services::Service {
public:
const char* name(void) override { return "MockService"; }

View File

@ -11,6 +11,8 @@
using ::testing::Return;
using ::testing::_;
using namespace entt::literals;
class MockUpdateStrategy : public MM::UpdateStrategies::UpdateStrategy {
public:
MOCK_METHOD(

View File

@ -94,9 +94,9 @@ public:
ComponentInfo& registerComponent(const ComponentInfo& component_info)
{
auto index = entt::type_hash<Component>::value();
auto [it, insert_result] = component_infos.insert_or_assign(index, component_info);
MM_IEEE_ASSERT(insert_result);
return std::get<ComponentInfo>(*it);
auto insert_info = component_infos.insert_or_assign(index, component_info);
MM_IEEE_ASSERT(insert_info.second);
return std::get<ComponentInfo>(*insert_info.first);
}
template <class Component>

View File

@ -65,44 +65,9 @@ bool ImGuiService::enable(Engine& engine) {
#endif
}
// TODO: register event handle
_event_handle = sdl_ss.addEventHandler([](const SDL_Event& e) {
if (!ImGui_ImplSDL2_ProcessEvent(&e)) {
return false; // if the event was not relevant to imgui anyway
}
auto& io = ImGui::GetIO();
// keyboard
if ((
e.type == SDL_KEYDOWN ||
e.type == SDL_KEYUP ||
e.type == SDL_TEXTEDITING ||
e.type == SDL_TEXTINPUT
)
&& io.WantCaptureKeyboard) {
return true;
}
// mouse
if ((
e.type == SDL_MOUSEMOTION ||
e.type == SDL_MOUSEBUTTONUP ||
e.type == SDL_MOUSEBUTTONDOWN ||
e.type == SDL_MOUSEWHEEL // ????
)
&& io.WantCaptureMouse) {
return true;
}
//// controller ???
//if ((
//e.type == SDL_CONTROLLERBUTTONUP ||
//e.type == SDL_CONTROLLERBUTTONDOWN
//)[>
//&& io.WantCaptureKeyboard*/) {
//return false;
//}
return false;
});
_event_handle = sdl_ss.addEventHandler(
[this](const SDL_Event& e) { return handle_sdl_event(e); }
);
return true;
}
@ -121,6 +86,7 @@ void ImGuiService::disable(Engine& engine) {
}
std::vector<UpdateStrategies::UpdateCreationInfo> ImGuiService::registerUpdates(void) {
using namespace entt::literals;
return {
{
"ImGuiService::new_frame"_hs,
@ -144,5 +110,43 @@ void ImGuiService::imgui_new_frame(Engine& engine) {
ImGui::NewFrame();
}
bool ImGuiService::handle_sdl_event(const SDL_Event& e) {
if (!ImGui_ImplSDL2_ProcessEvent(&e)) {
return false; // if the event was not relevant to imgui anyway
}
auto& io = ImGui::GetIO();
// keyboard
if ((
e.type == SDL_KEYDOWN ||
e.type == SDL_KEYUP ||
e.type == SDL_TEXTEDITING ||
e.type == SDL_TEXTINPUT
)
&& io.WantCaptureKeyboard) {
return true;
}
// mouse
if ((
e.type == SDL_MOUSEMOTION ||
e.type == SDL_MOUSEBUTTONUP ||
e.type == SDL_MOUSEBUTTONDOWN ||
e.type == SDL_MOUSEWHEEL // ????
)
&& io.WantCaptureMouse) {
return true;
}
//// controller ???
//if ((
//e.type == SDL_CONTROLLERBUTTONUP ||
//e.type == SDL_CONTROLLERBUTTONDOWN
//)[>
//&& io.WantCaptureKeyboard*/) {
//return false;
//}
return false;
}
} // namespace MM::Services

View File

@ -23,6 +23,8 @@ namespace MM::Services {
private:
void imgui_new_frame(Engine& engine);
bool handle_sdl_event(const SDL_Event& e);
};
} // namespace MM::Services

View File

@ -203,6 +203,7 @@ namespace MM::Services {
}
std::vector<UpdateStrategies::UpdateCreationInfo> ImGuiSceneToolsService::registerUpdates(void) {
using namespace entt::literals;
return {
{
"ImGuiSceneToolsService::render"_hs,

View File

@ -16,6 +16,8 @@
static char* argv0;
using namespace entt::literals;
TEST(imgui_scene_tools, it) {
MM::Engine engine;

View File

@ -27,6 +27,8 @@
const char* argv0;
using namespace entt::literals;
class ImGuiSpeechy : public MM::Services::Service {
private:
SoLoud::Speech speech;

View File

@ -22,6 +22,7 @@
static char* argv0;
using namespace entt::literals;
class TemplateUpdateMainService : public MM::Services::Service {
std::function<void(MM::Engine&)> _fn;

View File

@ -18,6 +18,8 @@
const char* argv0;
using namespace entt::literals;
TEST(imgui_widgets, basic) {
MM::Engine engine;

View File

@ -106,6 +106,7 @@ void InputService::disable(Engine& engine) {
}
std::vector<UpdateStrategies::UpdateCreationInfo> InputService::registerUpdates(void) {
using namespace entt::literals;
return {
{
"InputService::update"_hs,

View File

@ -47,6 +47,7 @@ class InputVisualizer : public MM::Services::Service {
}
std::vector<MM::UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override {
using namespace entt::literals;
return {
{
"InputVisualizer::render"_hs,

View File

@ -33,6 +33,8 @@
namespace MM::Services {
using namespace entt::literals;
OpenGLRenderer::OpenGLRenderer(void) {
MM::Logger::initSectionLogger("OpenGL");
MM::Logger::initSectionLogger("OpenGLRenderer");
@ -71,8 +73,8 @@ bool OpenGLRenderer::enable(Engine& engine) {
_sdl_event_handle = sdl_s.addEventHandler([this, &engine](const SDL_Event& e) -> bool {
if (e.type == SDL_WINDOWEVENT) {
if (e.window.event == SDL_WINDOWEVENT_RESIZED || e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
auto& sdl_s = engine.getService<MM::Services::SDLService>();
auto new_window_size = sdl_s.getWindowSize();
auto& sdl = engine.getService<MM::Services::SDLService>();
auto new_window_size = sdl.getWindowSize();
glViewport(0, 0, new_window_size.first, new_window_size.second);
// TODO: recreate fbos, dirvers seem to have problems otherwise
@ -111,7 +113,6 @@ bool OpenGLRenderer::enable(Engine& engine) {
}
{ // default texures
using namespace entt::literals;
auto& rm_t = MM::ResourceManager<MM::OpenGL::Texture>::ref();
if (!rm_t.contains("default"_hs)) {
if (!rm_t.load<MM::OpenGL::TextureLoaderConstBuffer>("default", default_png, default_png_len)) {

View File

@ -20,6 +20,8 @@
#include <physfs.h>
#include "res/textures.zip.h"
using namespace entt::literals;
const char* argv0;
TEST(batched_spritesheet_render_task, it) {

View File

@ -28,6 +28,8 @@
#include <random>
using namespace entt::literals;
const char* argv0;
TEST(blur_render_task, it) {

View File

@ -12,6 +12,8 @@
#include <imgui/imgui.h>
using namespace entt::literals;
TEST(imgui_render_task, demowindow) {
MM::Engine engine;

View File

@ -19,6 +19,8 @@
#include <random>
using namespace entt::literals;
const char* argv0;
TEST(simple_sprite_render_task, it) {

View File

@ -20,6 +20,8 @@
#include <physfs.h>
#include "res/textures.zip.h"
using namespace entt::literals;
TEST(simple_spritesheet_render_task, it) {
MM::Engine engine;

View File

@ -17,6 +17,8 @@
#include <mm/opengl/texture_loader.hpp>
using namespace entt::literals;
TEST(tilemap_render_task_test, it) {
MM::Engine engine;

View File

@ -4,6 +4,8 @@
#include <entt/resource/cache.hpp>
using namespace entt::literals; // :D
// disable, this just tests entt and not MM
#if 0
TEST(EngineResourceManagerTest, entt_cache) {

View File

@ -26,6 +26,7 @@ void ScreenDirector::disable(MM::Engine&) {
}
std::vector<UpdateStrategies::UpdateCreationInfo> ScreenDirector::registerUpdates(void) {
using namespace entt::literals;
return {
{
"ScreenDirector::update"_hs,

View File

@ -140,11 +140,11 @@ TEST(SceneDirectorSimple, online) {
auto& screen_1 = sd.screens["screen_1"];
screen_1.start_disable.push_back(engine.type<TestService2>());
screen_1.start_enable.push_back(engine.type<TestService1>());
screen_1.start_fn = [](MM::Engine& engine) {
screen_1.start_fn = [](MM::Engine& e) {
std::cout << "now in screen_1\n";
// and queue next screen immediately (for the purpose of this test)
engine.tryService<MM::Services::ScreenDirector>()->queueChangeScreenTo("screen_2");
e.tryService<MM::Services::ScreenDirector>()->queueChangeScreenTo("screen_2");
};
screen_1.end_fn = [](auto&) {
std::cout << "exiting screen_1\n";
@ -156,11 +156,11 @@ TEST(SceneDirectorSimple, online) {
auto& screen_2 = sd.screens["screen_2"];
screen_2.start_disable.push_back(engine.type<TestService1>());
screen_2.start_enable.push_back(engine.type<TestService2>());
screen_2.start_fn = [](MM::Engine& engine) {
screen_2.start_fn = [](MM::Engine& e) {
std::cout << "now in screen_2\n";
// and queue next screen immediately (for the purpose of this test)
engine.tryService<MM::Services::ScreenDirector>()->queueChangeScreenTo("screen_end");
e.tryService<MM::Services::ScreenDirector>()->queueChangeScreenTo("screen_end");
};
screen_2.end_fn = [](auto&) {
std::cout << "exiting screen_2\n";
@ -170,8 +170,8 @@ TEST(SceneDirectorSimple, online) {
// id end, quits the engine
{
auto& screen_end = sd.screens["screen_end"];
screen_end.start_fn = [](MM::Engine& engine) {
engine.stop();
screen_end.start_fn = [](MM::Engine& e) {
e.stop();
};
}

View File

@ -61,6 +61,7 @@ SDLService::~SDLService(void) {
}
std::vector<UpdateStrategies::UpdateCreationInfo> SDLService::registerUpdates(void) {
using namespace entt::literals;
return {
{
"SDLService::events"_hs,

View File

@ -29,6 +29,7 @@ void SimpleSceneService::disable(Engine&) {
}
std::vector<UpdateStrategies::UpdateCreationInfo> SimpleSceneService::registerUpdates(void) {
using namespace entt::literals;
return {
{
"SimpleSceneService::scene_tick"_hs,

View File

@ -58,6 +58,7 @@ void SimpleSDLRendererService::disable(Engine&) {
}
std::vector<UpdateStrategies::UpdateCreationInfo> SimpleSDLRendererService::registerUpdates(void) {
using namespace entt::literals;
return {
{
"SimpleSDLRendererService::render"_hs,

View File

@ -17,6 +17,8 @@
// inlining zip
#include "res/erik_gun_fx_1.zip.h"
using namespace entt::literals;
extern char* argv0;
TEST(soloud_fs_loader, basic) {