Skip to content

Commit

Permalink
Make Mainloop and EventDispatcher Component-independent.
Browse files Browse the repository at this point in the history
This is now possible with new-style events.
  • Loading branch information
Oberon00 committed Jul 26, 2013
1 parent 6f9c7a8 commit 88eafd0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 61 deletions.
41 changes: 14 additions & 27 deletions src/luaexport/EventDispatcherMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<LHCURCLASS, Component>(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)
];
}
26 changes: 12 additions & 14 deletions src/luaexport/MainloopMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,8 +19,19 @@ static void init(LuaVm& vm)
vm.initLib("ComponentSystem");
LHMODULE [
# define LHCURCLASS Mainloop
class_<LHCURCLASS, Component>(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)
];
}
6 changes: 1 addition & 5 deletions src/svc/EventDispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
#ifndef EVENT_DISPATCHER_HPP_INCLUDED
#define EVENT_DISPATCHER_HPP_INCLUDED EVENT_DISPATCHER_HPP_INCLUDED

#include "compsys/Component.hpp"

#include <SFML/Window/Event.hpp>
#include <ssig.hpp>


namespace sf { class Window; }

class EventDispatcher: public Component {
JD_COMPONENT

class EventDispatcher {
// Raw
SSIG_DEFINE_MEMBERSIGNAL(sfEvent, void(sf::Event const&))

Expand Down
12 changes: 4 additions & 8 deletions src/svc/Mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions src/svc/Mainloop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
#ifndef MAINLOOP_HPP_INCLUDED
#define MAINLOOP_HPP_INCLUDED MAINLOOP_HPP_INCLUDED

namespace sf { class RenderWindow; }

#include "compsys/Component.hpp"

#include <ssig.hpp>

#include <cstdlib>


class MetaComponent;

class Mainloop: public Component {
JD_COMPONENT

class Mainloop {
#define CALLBACKS(m) \
m(started) \
m(preFrame) \
Expand Down

0 comments on commit 88eafd0

Please sign in to comment.