Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Restructured plugin interface

  • Loading branch information...
commit 8cce8cd8c08d96cce8d3ce455bf6c2ae77c84716 1 parent ac6a123
@andrewfenn andrewfenn authored
View
68 src/blocks/basic.cpp
@@ -0,0 +1,68 @@
+/*
+ Copyright (c) 2010, The Mineserver Project
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the The Mineserver Project nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "basic.h"
+
+void BlockBasic::setData(User* user, int x, int y, int z, int meta)
+{
+ this->user = user;
+ this->x = x;
+ this->y = y;
+ this->z = z;
+ this->meta = meta;
+}
+
+void BlockBasic::onStartedDigging()
+{
+ printf("works\n");
+}
+
+void BlockBasic::onDigging()
+{
+
+}
+
+void BlockBasic::onStoppedDigging()
+{
+
+}
+
+void BlockBasic::onBreak()
+{
+
+}
+
+void BlockBasic::onNeighbourBreak(int x, int y, int z, int type, int meta)
+{
+
+}
+
+void BlockBasic::onPlace()
+{
+
+}
+
View
52 src/blocks/basic.h
@@ -0,0 +1,52 @@
+/*
+ Copyright (c) 2010, The Mineserver Project
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the The Mineserver Project nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <stdio.h>
+
+class User;
+
+class BlockBasic
+{
+private:
+ User* user;
+ int x;
+ int y;
+ int z;
+ int meta;
+
+public:
+ void setData(User* user, int x, int y, int z, int meta);
+ void onStartedDigging();
+ void onDigging();
+ void onStoppedDigging();
+ void onBreak();
+ void onNeighbourBreak(int x, int y, int z, int type, int meta);
+ void onPlace();
+};
+
View
27 src/delegate/delegate.hpp
@@ -0,0 +1,27 @@
+/*
+ (c) Sergey Ryazanov (http://home.onego.ru/~ryazanov)
+
+ Fast delegate compatible with C++ Standard.
+*/
+#ifndef SRUTIL_DELEGATE_INCLUDED
+#define SRUTIL_DELEGATE_INCLUDED
+
+namespace srutil
+{
+#ifdef SRUTIL_DELEGATE_PREFERRED_SYNTAX
+ template <typename TSignature> class delegate;
+ template <typename TSignature> class delegate_invoker;
+#endif
+}
+
+#ifdef _MSC_VER
+#define SRUTIL_DELEGATE_CALLTYPE __fastcall
+#else
+#define SRUTIL_DELEGATE_CALLTYPE
+#endif
+
+#include "detail/delegate_list.hpp"
+
+#undef SRUTIL_DELEGATE_CALLTYPE
+
+#endif//SRUTIL_DELEGATE_INCLUDED
View
189 src/delegate/detail/delegate_list.hpp
@@ -0,0 +1,189 @@
+// Automaticly generaged by C:\Work\Projects\Delegates\include\srutil\delegate\detail\make_delegates.pl
+
+// 0 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 0
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS
+#define SRUTIL_DELEGATE_PARAMS
+#define SRUTIL_DELEGATE_ARGS
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#define SRUTIL_DELEGATE_INVOKER_DATA
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 1 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 1
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1
+#define SRUTIL_DELEGATE_PARAMS A1 a1
+#define SRUTIL_DELEGATE_ARGS a1
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 2 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 2
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2
+#define SRUTIL_DELEGATE_ARGS a1,a2
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 3 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 3
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2, typename A3
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2, A3
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2, A3 a3
+#define SRUTIL_DELEGATE_ARGS a1,a2,a3
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2),a3(a3)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;A3 a3;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 4 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 4
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2, typename A3, typename A4
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2, A3, A4
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2, A3 a3, A4 a4
+#define SRUTIL_DELEGATE_ARGS a1,a2,a3,a4
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2),a3(a3),a4(a4)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;A3 a3;A4 a4;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 5 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 5
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2, typename A3, typename A4, typename A5
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2, A3, A4, A5
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2, A3 a3, A4 a4, A5 a5
+#define SRUTIL_DELEGATE_ARGS a1,a2,a3,a4,a5
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2),a3(a3),a4(a4),a5(a5)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;A3 a3;A4 a4;A5 a5;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 6 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 6
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2, typename A3, typename A4, typename A5, typename A6
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2, A3, A4, A5, A6
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6
+#define SRUTIL_DELEGATE_ARGS a1,a2,a3,a4,a5,a6
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2),a3(a3),a4(a4),a5(a5),a6(a6)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;A3 a3;A4 a4;A5 a5;A6 a6;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 7 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 7
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2, A3, A4, A5, A6, A7
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7
+#define SRUTIL_DELEGATE_ARGS a1,a2,a3,a4,a5,a6,a7
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2),a3(a3),a4(a4),a5(a5),a6(a6),a7(a7)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;A3 a3;A4 a4;A5 a5;A6 a6;A7 a7;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 8 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 8
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2, A3, A4, A5, A6, A7, A8
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8
+#define SRUTIL_DELEGATE_ARGS a1,a2,a3,a4,a5,a6,a7,a8
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2),a3(a3),a4(a4),a5(a5),a6(a6),a7(a7),a8(a8)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;A3 a3;A4 a4;A5 a5;A6 a6;A7 a7;A8 a8;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 9 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 9
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2, A3, A4, A5, A6, A7, A8, A9
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9
+#define SRUTIL_DELEGATE_ARGS a1,a2,a3,a4,a5,a6,a7,a8,a9
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2),a3(a3),a4(a4),a5(a5),a6(a6),a7(a7),a8(a8),a9(a9)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;A3 a3;A4 a4;A5 a5;A6 a6;A7 a7;A8 a8;A9 a9;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
+// 10 params
+#define SRUTIL_DELEGATE_PARAM_COUNT 10
+#define SRUTIL_DELEGATE_TEMPLATE_PARAMS typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10
+#define SRUTIL_DELEGATE_TEMPLATE_ARGS A1, A2, A3, A4, A5, A6, A7, A8, A9, A10
+#define SRUTIL_DELEGATE_PARAMS A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10
+#define SRUTIL_DELEGATE_ARGS a1,a2,a3,a4,a5,a6,a7,a8,a9,a10
+#define SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST a1(a1),a2(a2),a3(a3),a4(a4),a5(a5),a6(a6),a7(a7),a8(a8),a9(a9),a10(a10)
+#define SRUTIL_DELEGATE_INVOKER_DATA A1 a1;A2 a2;A3 a3;A4 a4;A5 a5;A6 a6;A7 a7;A8 a8;A9 a9;A10 a10;
+#include "delegate_template.hpp"
+#undef SRUTIL_DELEGATE_PARAM_COUNT
+#undef SRUTIL_DELEGATE_TEMPLATE_PARAMS
+#undef SRUTIL_DELEGATE_TEMPLATE_ARGS
+#undef SRUTIL_DELEGATE_PARAMS
+#undef SRUTIL_DELEGATE_ARGS
+#undef SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+#undef SRUTIL_DELEGATE_INVOKER_DATA
+
View
149 src/delegate/detail/delegate_template.hpp
@@ -0,0 +1,149 @@
+/*
+ (c) Sergey Ryazanov (http://home.onego.ru/~ryazanov)
+
+ Template file. May be included many times with different predefined macros.
+*/
+#if SRUTIL_DELEGATE_PARAM_COUNT > 0
+#define SRUTIL_DELEGATE_SEPARATOR ,
+#else
+#define SRUTIL_DELEGATE_SEPARATOR
+#endif
+
+// see BOOST_JOIN for explanation
+#define SRUTIL_DELEGATE_JOIN_MACRO( X, Y) SRUTIL_DELEGATE_DO_JOIN( X, Y )
+#define SRUTIL_DELEGATE_DO_JOIN( X, Y ) SRUTIL_DELEGATE_DO_JOIN2(X,Y)
+#define SRUTIL_DELEGATE_DO_JOIN2( X, Y ) X##Y
+
+namespace srutil
+{
+#ifdef SRUTIL_DELEGATE_PREFERRED_SYNTAX
+#define SRUTIL_DELEGATE_CLASS_NAME delegate
+#define SRUTIL_DELEGATE_INVOKER_CLASS_NAME delegate_invoker
+#else
+#define SRUTIL_DELEGATE_CLASS_NAME SRUTIL_DELEGATE_JOIN_MACRO(delegate,SRUTIL_DELEGATE_PARAM_COUNT)
+#define SRUTIL_DELEGATE_INVOKER_CLASS_NAME SRUTIL_DELEGATE_JOIN_MACRO(delegate_invoker,SRUTIL_DELEGATE_PARAM_COUNT)
+ template <typename R SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_TEMPLATE_PARAMS>
+ class SRUTIL_DELEGATE_INVOKER_CLASS_NAME;
+#endif
+
+ template <typename R SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_TEMPLATE_PARAMS>
+#ifdef SRUTIL_DELEGATE_PREFERRED_SYNTAX
+ class SRUTIL_DELEGATE_CLASS_NAME<R (SRUTIL_DELEGATE_TEMPLATE_ARGS)>
+#else
+ class SRUTIL_DELEGATE_CLASS_NAME
+#endif
+ {
+ public:
+ typedef R return_type;
+#ifdef SRUTIL_DELEGATE_PREFERRED_SYNTAX
+ typedef return_type (SRUTIL_DELEGATE_CALLTYPE *signature_type)(SRUTIL_DELEGATE_TEMPLATE_ARGS);
+ typedef SRUTIL_DELEGATE_INVOKER_CLASS_NAME<signature_type> invoker_type;
+#else
+ typedef SRUTIL_DELEGATE_INVOKER_CLASS_NAME<R SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_TEMPLATE_ARGS> invoker_type;
+#endif
+
+ SRUTIL_DELEGATE_CLASS_NAME()
+ : object_ptr(0)
+ , stub_ptr(0)
+ {}
+
+ template <return_type (*TMethod)(SRUTIL_DELEGATE_TEMPLATE_ARGS)>
+ static SRUTIL_DELEGATE_CLASS_NAME from_function()
+ {
+ return from_stub(0, &function_stub<TMethod>);
+ }
+
+ template <class T, return_type (T::*TMethod)(SRUTIL_DELEGATE_TEMPLATE_ARGS)>
+ static SRUTIL_DELEGATE_CLASS_NAME from_method(T* object_ptr)
+ {
+ return from_stub(object_ptr, &method_stub<T, TMethod>);
+ }
+
+ template <class T, return_type (T::*TMethod)(SRUTIL_DELEGATE_TEMPLATE_ARGS) const>
+ static SRUTIL_DELEGATE_CLASS_NAME from_const_method(T const* object_ptr)
+ {
+ return from_stub(const_cast<T*>(object_ptr), &const_method_stub<T, TMethod>);
+ }
+
+ return_type operator()(SRUTIL_DELEGATE_PARAMS) const
+ {
+ return (*stub_ptr)(object_ptr SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_ARGS);
+ }
+
+ operator bool () const
+ {
+ return stub_ptr != 0;
+ }
+
+ bool operator!() const
+ {
+ return !(operator bool());
+ }
+
+ private:
+
+ typedef return_type (SRUTIL_DELEGATE_CALLTYPE *stub_type)(void* object_ptr SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_PARAMS);
+
+ void* object_ptr;
+ stub_type stub_ptr;
+
+ static SRUTIL_DELEGATE_CLASS_NAME from_stub(void* object_ptr, stub_type stub_ptr)
+ {
+ SRUTIL_DELEGATE_CLASS_NAME d;
+ d.object_ptr = object_ptr;
+ d.stub_ptr = stub_ptr;
+ return d;
+ }
+
+ template <return_type (*TMethod)(SRUTIL_DELEGATE_TEMPLATE_ARGS)>
+ static return_type SRUTIL_DELEGATE_CALLTYPE function_stub(void* SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_PARAMS)
+ {
+ return (TMethod)(SRUTIL_DELEGATE_ARGS);
+ }
+
+ template <class T, return_type (T::*TMethod)(SRUTIL_DELEGATE_TEMPLATE_ARGS)>
+ static return_type SRUTIL_DELEGATE_CALLTYPE method_stub(void* object_ptr SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_PARAMS)
+ {
+ T* p = static_cast<T*>(object_ptr);
+ return (p->*TMethod)(SRUTIL_DELEGATE_ARGS);
+ }
+
+ template <class T, return_type (T::*TMethod)(SRUTIL_DELEGATE_TEMPLATE_ARGS) const>
+ static return_type SRUTIL_DELEGATE_CALLTYPE const_method_stub(void* object_ptr SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_PARAMS)
+ {
+ T const* p = static_cast<T*>(object_ptr);
+ return (p->*TMethod)(SRUTIL_DELEGATE_ARGS);
+ }
+ };
+
+ template <typename R SRUTIL_DELEGATE_SEPARATOR SRUTIL_DELEGATE_TEMPLATE_PARAMS>
+#ifdef SRUTIL_DELEGATE_PREFERRED_SYNTAX
+ class SRUTIL_DELEGATE_INVOKER_CLASS_NAME<R (SRUTIL_DELEGATE_TEMPLATE_ARGS)>
+#else
+ class SRUTIL_DELEGATE_INVOKER_CLASS_NAME
+#endif
+ {
+ SRUTIL_DELEGATE_INVOKER_DATA
+
+ public:
+ SRUTIL_DELEGATE_INVOKER_CLASS_NAME(SRUTIL_DELEGATE_PARAMS)
+#if SRUTIL_DELEGATE_PARAM_COUNT > 0
+ :
+#endif
+ SRUTIL_DELEGATE_INVOKER_INITIALIZATION_LIST
+ {
+ }
+
+ template <class TDelegate>
+ R operator()(TDelegate d) const
+ {
+ return d(SRUTIL_DELEGATE_ARGS);
+ }
+ };
+}
+
+#undef SRUTIL_DELEGATE_CLASS_NAME
+#undef SRUTIL_DELEGATE_SEPARATOR
+#undef SRUTIL_DELEGATE_JOIN_MACRO
+#undef SRUTIL_DELEGATE_DO_JOIN
+#undef SRUTIL_DELEGATE_DO_JOIN2
View
34 src/plugin.cpp
@@ -26,6 +26,7 @@
*/
#include "plugin.h"
+#include "blocks/basic.h"
Plugin &Plugin::get()
{
@@ -35,29 +36,24 @@ Plugin &Plugin::get()
void Plugin::initPlugin()
{
- // populate all block behaviour with default functions
- this->setBlockBehaviour(BLOCK_STONE, newDelegate(BlockBasic));
- this->setBlockBehaviour(BLOCK_GRASS, newDelegate(BlockBasic));
- this->setBlockBehaviour(BLOCK_DIRT, newDelegate(BlockBasic));
- this->setBlockBehaviour(BLOCK_COBBLESTONE, newDelegate(BlockBasic));
+ // Set default behaviours
+ this->setBlockObj(BLOCK_STONE, new BlockBasic);
}
-bool Plugin::setBlockBehaviour(int type, std::string func, void* delegate)
+void Plugin::setBlockObj(int type, void* obj)
{
- if (!blocks.has(type))
- {
- Delegates block;
- blocks.insert(block);
- }
-
- Delegates block = blocks.at(type);
- block.insert(std::pair<std::string,void*>(func, delegate));
- blocks.insert(block);
- return false;
+ Object* call = new Object(&obj);
+
+ // remove old obj
+ if (this->blocks.at(type))
+ delete &this->blocks.at(type);
+
+ this->blocks[type] = call;
}
-bool Plugin::setBlockBehaviour(int type, void* delegate)
+Object* Plugin::getBlockObj(int type)
{
- this->setBlockBehaviour(type, "onStartedDigging", delegate->onStartedDigging());
- return false;
+ if (!this->blocks.at(type))
+ return this->blocks.at(type);
+ return 0;
}
View
40 src/plugin.h
@@ -29,17 +29,49 @@
#include <string>
#include <vector>
+#include <map>
-typedef std::vector<std::string, void*> Delegates;
-typedef std::vector<int, Delegates> BlockDelegates;
+#include "constants.h"
+#include "delegate/delegate.hpp"
+
+#ifdef SRUTIL_DELEGATE_PREFERRED_SYNTAX
+typedef srutil::delegate<void (int, int)> Delegate;
+#else
+typedef srutil::delegate2<void, int, int> Delegate;
+#endif
+
+class Object
+{
+public:
+ Object(void* obj)
+ {
+ this->obj = obj;
+// callbacks.insert(std::pair<std::string, Delegate>("onStartedDigging", Delegate::from_function<&obj->onStartedDigging>());
+ }
+
+ ~Object()
+ {
+ if (this->obj) {
+ delete &this->obj;
+ }
+ }
+private:
+ void* obj;
+/* typedef std::map<std::string, Delegate> Callbacks;
+ Callbacks callbacks;*/
+};
class Plugin
{
private:
- BlockDelegates blocks;
+ Plugin()
+ {
+ }
+ std::vector<Object*> blocks;
public:
- Plugin();
void initPlugin();
+ void setBlockObj(int type, void* obj);
+ Object* getBlockObj(int type);
static Plugin &get();
};
Please sign in to comment.
Something went wrong with that request. Please try again.