From 88eafd051aff416d8b9c7c84b8782f73f62ecbe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Neun=C3=BCller?= Date: Fri, 26 Jul 2013 11:20:46 +0200 Subject: [PATCH] Make Mainloop and EventDispatcher Component-independent. This is now possible with new-style events. --- src/luaexport/EventDispatcherMeta.cpp | 41 +++++++++------------------ src/luaexport/MainloopMeta.cpp | 26 ++++++++--------- src/svc/EventDispatcher.hpp | 6 +--- src/svc/Mainloop.cpp | 12 +++----- src/svc/Mainloop.hpp | 8 +----- 5 files changed, 32 insertions(+), 61 deletions(-) diff --git a/src/luaexport/EventDispatcherMeta.cpp b/src/luaexport/EventDispatcherMeta.cpp index fb8a5e8..ff253bd 100644 --- a/src/luaexport/EventDispatcherMeta.cpp +++ b/src/luaexport/EventDispatcherMeta.cpp @@ -4,47 +4,34 @@ #include "svc/EventDispatcher.hpp" -#include "compsys/BasicMetaComponent.hpp" #include "LuaEventHelpers.hpp" #include "SfBaseTypes.hpp" static char const libname[] = "EventDispatcher"; #include "ExportThis.hpp" - -JD_BASIC_EVT_COMPONENT_IMPL(EventDispatcher) - -JD_EVENT_TABLE_BEGIN(EventDispatcher) -#define E0(n) JD_EVENT_ENTRY0(n, void) -#define E1(n) JD_EVENT_ENTRY(n, void, _1) - E0(closed) - E1(resized) - E0(lostFocus) - E0(gainedFocus) - E1(textEntered) - - E1(keyPressed) - E1(keyReleased) - - E1(mouseWheelMoved) - E1(mouseButtonPressed) - E1(mouseButtonReleased) - E1(mouseMoved) - E0(mouseEntered) - E0(mouseLeft) -#undef E0 -#undef E1 -JD_EVENT_TABLE_END - static void init(LuaVm& vm) { vm.initLib("ComponentSystem"); LHMODULE [ # define LHCURCLASS EventDispatcher - class_(BOOST_STRINGIZE(LHCURCLASS)) + LHCLASS .LHPROPG(isWindowFocused) .LHMEMFN(isKeyPressed) .LHMEMFN(isMouseButtonPressed) .LHMEMFN(mousePosition) + .JD_EVENT(closed, Closed) + .JD_EVENT(resized, Resized) + .JD_EVENT(lostFocus, LostFocus) + .JD_EVENT(gainedFocus, GainedFocus) + .JD_EVENT(textEntered, TextEntered) + .JD_EVENT(keyPressed, KeyPressed) + .JD_EVENT(keyReleased, KeyReleased) + .JD_EVENT(mouseWheelMoved, MouseWheelMoved) + .JD_EVENT(mouseButtonPressed, MouseButtonPressed) + .JD_EVENT(mouseButtonReleased, MouseButtonReleased) + .JD_EVENT(mouseMoved, MouseMoved) + .JD_EVENT(mouseEntered, MouseEntered) + .JD_EVENT(mouseLeft, MouseLeft) ]; } diff --git a/src/luaexport/MainloopMeta.cpp b/src/luaexport/MainloopMeta.cpp index 8023452..0423416 100644 --- a/src/luaexport/MainloopMeta.cpp +++ b/src/luaexport/MainloopMeta.cpp @@ -2,26 +2,13 @@ // This file is subject to the terms of the BSD 2-Clause License. // See LICENSE.txt or http://opensource.org/licenses/BSD-2-Clause -#define MAINLOOP_KEEP_CALLBACKS #include "svc/Mainloop.hpp" -#include "compsys/BasicMetaComponent.hpp" #include "LuaEventHelpers.hpp" static char const libname[] = "Mainloop"; #include "ExportThis.hpp" - -JD_BASIC_EVT_COMPONENT_IMPL(Mainloop) - -JD_EVENT_TABLE_BEGIN(Mainloop) -#define ENTRY(n) JD_EVENT_ENTRY0(n, void) - CALLBACKS(ENTRY) -#undef ENTRY - JD_EVENT_ENTRY(quitting, void, _1) - JD_EVENT_ENTRY(quitRequested, void, _1) -JD_EVENT_TABLE_END - static void quit0(Mainloop& ml) { ml.quit(); // use default value for exitcode @@ -32,8 +19,19 @@ static void init(LuaVm& vm) vm.initLib("ComponentSystem"); LHMODULE [ # define LHCURCLASS Mainloop - class_(BOOST_STRINGIZE(LHCURCLASS)) + LHCLASS .LHMEMFN(quit) .def("quit", &quit0) + .JD_EVENT(started, Started) + .JD_EVENT(preFrame, PreFrame) + .JD_EVENT(processInput, ProcessInput) + .JD_EVENT(update, Update) + .JD_EVENT(interact, Interact) + .JD_EVENT(preDraw, PreDraw) + .JD_EVENT(draw, Draw) + .JD_EVENT(postDraw, PostDraw) + .JD_EVENT(postFrame, PostFrame) + .JD_EVENT(quitting, Quitting) + .JD_EVENT(quitRequested, QuitRequested) ]; } diff --git a/src/svc/EventDispatcher.hpp b/src/svc/EventDispatcher.hpp index cb92208..4319784 100644 --- a/src/svc/EventDispatcher.hpp +++ b/src/svc/EventDispatcher.hpp @@ -5,17 +5,13 @@ #ifndef EVENT_DISPATCHER_HPP_INCLUDED #define EVENT_DISPATCHER_HPP_INCLUDED EVENT_DISPATCHER_HPP_INCLUDED -#include "compsys/Component.hpp" - #include #include namespace sf { class Window; } -class EventDispatcher: public Component { - JD_COMPONENT - +class EventDispatcher { // Raw SSIG_DEFINE_MEMBERSIGNAL(sfEvent, void(sf::Event const&)) diff --git a/src/svc/Mainloop.cpp b/src/svc/Mainloop.cpp index 3127e95..2112921 100644 --- a/src/svc/Mainloop.cpp +++ b/src/svc/Mainloop.cpp @@ -2,6 +2,7 @@ // This file is subject to the terms of the BSD 2-Clause License. // See LICENSE.txt or http://opensource.org/licenses/BSD-2-Clause +#define MAINLOOP_KEEP_CALLBACKS #include "Mainloop.hpp" Mainloop::Mainloop(): @@ -14,14 +15,9 @@ int Mainloop::exec() { m_sig_started(); while (!m_exitRequested) { - m_sig_preFrame(); - m_sig_processInput(); - m_sig_update(); - m_sig_interact(); - m_sig_preDraw(); - m_sig_draw(); - m_sig_postDraw(); - m_sig_postFrame(); +#define EMIT(s) m_sig_##s(); + CALLBACKS(EMIT) +#undef EMIT } m_sig_quitting(m_exitcode); return m_exitcode; diff --git a/src/svc/Mainloop.hpp b/src/svc/Mainloop.hpp index b92c29b..7bf45e6 100644 --- a/src/svc/Mainloop.hpp +++ b/src/svc/Mainloop.hpp @@ -5,10 +5,6 @@ #ifndef MAINLOOP_HPP_INCLUDED #define MAINLOOP_HPP_INCLUDED MAINLOOP_HPP_INCLUDED -namespace sf { class RenderWindow; } - -#include "compsys/Component.hpp" - #include #include @@ -16,9 +12,7 @@ namespace sf { class RenderWindow; } class MetaComponent; -class Mainloop: public Component { - JD_COMPONENT - +class Mainloop { #define CALLBACKS(m) \ m(started) \ m(preFrame) \