buildat/games/test/test2/test2.cpp

74 lines
1.4 KiB
C++
Raw Normal View History

2014-09-17 02:18:03 +03:00
#include "interface/module.h"
#include "interface/server.h"
#include "interface/event.h"
#include "test1/api.h"
#include "core/log.h"
2014-09-17 02:18:03 +03:00
using interface::Event;
namespace test2 {
struct Module: public interface::Module
{
interface::Server *m_server;
Event::Type m_EventType_core_start;
Module(interface::Server *server):
2014-09-17 23:00:31 +03:00
interface::Module("test2"),
2014-09-17 02:18:03 +03:00
m_server(server),
2014-09-17 16:43:05 +03:00
m_EventType_core_start(Event::t("core:start"))
2014-09-17 02:18:03 +03:00
{
log_v(MODULE, "test2 construct");
2014-09-17 02:18:03 +03:00
}
~Module()
{
log_v(MODULE, "test2 destruct");
}
2014-09-17 14:53:06 +03:00
void init()
{
log_v(MODULE, "test2 init");
2014-09-17 14:53:06 +03:00
m_server->sub_event(this, m_EventType_core_start);
}
2014-09-17 18:52:59 +03:00
void event(const Event::Type &type, const Event::Private *p)
2014-09-17 02:18:03 +03:00
{
2014-09-17 18:52:59 +03:00
if(type == m_EventType_core_start){
2014-09-17 16:43:05 +03:00
on_start();
2014-09-17 02:18:03 +03:00
}
}
2014-09-17 16:43:05 +03:00
void on_start()
2014-09-17 02:18:03 +03:00
{
log_i(MODULE, "test2 start(): Calling test1");
2014-10-17 13:49:55 +03:00
{ // Raw
2014-09-17 20:15:46 +03:00
Event::Type type = Event::t("test1:thing");
Event event(type, up_<Event::Private>(new test1::Thing("Nakki")));
m_server->emit_event(std::move(event));
}
2014-10-17 13:49:55 +03:00
{ // Simplified raw
2014-09-17 20:15:46 +03:00
Event event("test1:thing", new test1::Thing("Kebab"));
m_server->emit_event(std::move(event));
}
2014-10-17 13:49:55 +03:00
{ // Even simpler
2014-09-17 20:15:46 +03:00
m_server->emit_event("test1:thing", new test1::Thing("Pitsa"));
}
2014-10-17 13:49:55 +03:00
{ // Inline wrapper
2014-09-17 20:15:46 +03:00
test1::do_thing(m_server, "Rulla");
}
2014-09-17 02:18:03 +03:00
}
};
extern "C" {
BUILDAT_EXPORT void* createModule_test2(interface::Server *server){
2014-09-17 02:18:03 +03:00
return (void*)(new Module(server));
}
}
}
2014-09-24 14:53:57 +03:00
// vim: set noet ts=4 sw=4: