Skip to content

Commit

Permalink
Make ssig an external library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oberon00 committed Jun 26, 2013
1 parent 1051a7a commit e97160a
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 393 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ The following libraries are needed:
<https://github.com/Oberon00/luabind>
- **[zlib][]** (tested with version 1.2.7).
- **[PhysFS][]** (tested with version 2.0.3).
- **[ssig][]**: My own library for signals (Boost.Signal is too slow).

The only compiler throughoutly tested is **[MSVC 11][]**, but once upon a time the
source code and `CMakeLists.txt` were adjusted to also work with g++ 4.7.2.
The build system used is **[CMake][]** in a recent 2.8.x version.

Especially on Windows, make sure to set any environment variables neccessary to
let CMake find the librarys are set correctly: `SFML_ROOT`, `BOOST_ROOT`,
`LUA_DIR`, `LUABIND_DIR`, `PHYSFSDIR`. zlib does not look at any environment
variables but only the `ZLIB_ROOT` CMake variable: See the second point in the
next section for how to set it.
`LUA_DIR`, `LUABIND_DIR`, `PHYSFSDIR`, `SSIG_DIR`. zlib does not look at any
environment variables but only the `ZLIB_ROOT` CMake variable: See the second
option in the [`Find*.cmake`](#setcmakevar) subsection for how to set it.

As an alternative to setting the variables you can also install the libraries
to the (CMake) standard locations or add the containing directories to
Expand All @@ -52,26 +53,30 @@ to the (CMake) standard locations or add the containing directories to
[Luabind]: http://www.rasterbar.com/products/luabind.html
[zlib]: http://www.zlib.net/
[PhysFS]: http://icculus.org/physfs/
[ssig]: https://github.com/Oberon00/ssig
[MSVC 11]: http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-windows-desktop#product-express-desktop
[CMake]: http://www.cmake.org/


### `Find*.cmake` ###
The `CMakeLists.txt` for jd call `find_package()` with some libraries where
the corresponding `Find*.cmake` is not built in, namely `Lua52`, `Luabind` and
`SFML`. The latter is included with SFML itself and the first two are both
contained in my Luabind fork, linked above. To make CMake find them you have
two options:
the corresponding `Find*.cmake` is not built in:

* `FindLua52.cmake` and `FindLuabind.cmake` are contained in my Luabind fork
linked above.
* `FindSFML.cmake` and `Findssig.cmake` are contained in their own libraries.

To make CMake find them you have two options:

- Copy the files to your CMake installation's module directory. This is the
directory where e.g. the `AddFileDependencies.cmake` module is located. It
usually lies in `<prefix>/share/cmake-2.8/Modules`, where `<prefix>` is the
installation directory on Windows (usually
`C:\Program Files (x86)\CMake 2.8`) and usually simply `/usr` on Linux.
- Specify the directories where the files are located as a semicolon `;`
separated list in the `CMAKE_MODULE_PATH` CMake cache variable: *Add entry*,
type string in the Windows GUI; or `-DCMAKE_MODULE_PATH=<path-list>` on the
command line.
- <a name=setcmakevar></a>Specify the directories where the files are located
as a semicolon `;` separated list in the `CMAKE_MODULE_PATH` CMake cache
variable: *Add entry*, type string in the Windows GUI;
or `-DCMAKE_MODULE_PATH=<path-list>` on the command line.


> Jade Engine -- Copyright (c) Christian Neumüller 2012--2013
Expand Down
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ source_group("Collisions" FILES ${COLLISION_SOURCES} ${COLLISION_HEADERS})

set(JD_HEADERS
encoding.hpp
ssig.hpp
ssig_template.hpp
MapInfo.hpp
exceptions.hpp
sfKeyCodes.hpp
Expand Down Expand Up @@ -212,6 +210,7 @@ find_package(PhysFS REQUIRED)
find_package(ZLIB REQUIRED)
find_package(Lua52 REQUIRED)
find_package(Luabind REQUIRED)
find_package(ssig REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
Expand All @@ -226,7 +225,8 @@ include_directories(
${LUABIND_INCLUDE_DIRS}
${PHYSFS_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
${Boost_INCLUDE_DIRS})
${Boost_INCLUDE_DIRS}
${SSIG_INCLUDE_DIRS})
add_executable(jd WIN32 ${JD_HEADERS} ${JD_SOURCES})
set_target_properties(jd PROPERTIES COMPILE_DEFINITIONS "${COMP_DEFS}")
target_link_libraries(jd
Expand Down
3 changes: 1 addition & 2 deletions src/comp/PositionComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

#include "compsys/Component.hpp"

#include "ssig.hpp"

#include <SFML/Graphics/Rect.hpp>
#include <ssig.hpp>


class Entity;
Expand Down
2 changes: 1 addition & 1 deletion src/comp/RectCollisionComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "compsys/Component.hpp"

#include "compsys/Entity.hpp"
#include "ssig.hpp"

#include <SFML/Graphics/Rect.hpp>
#include <ssig.hpp>

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions src/comp/TileCollisionComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

#include "compsys/Component.hpp"

#include "ssig.hpp"
#include "WeakRef.hpp"

#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector3.hpp>
#include <ssig.hpp>


class TileCollideableInfo;
Expand Down Expand Up @@ -49,7 +49,7 @@ class TileCollisionComponent: public Component {
void on_tilePositionChanged(
sf::Vector3<unsigned> oldPos, sf::Vector3<unsigned> newPos);

ScopedConnection<
ssig::ScopedConnection<
void(sf::Vector3<unsigned>, sf::Vector3<unsigned>)
> m_con_positionChanged;
WeakRef<TileCollideableInfo> m_tileinfo;
Expand Down
6 changes: 3 additions & 3 deletions src/comp/TilePositionComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include "compsys/Component.hpp"

#include "ssig.hpp"

#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector3.hpp>
#include <ssig.hpp>

#include <string>


Expand Down Expand Up @@ -38,7 +38,7 @@ class TilePositionComponent: public Component {
void on_positionChanged(
sf::FloatRect const& oldRect, sf::FloatRect const& newRect);

ScopedConnection<void(sf::FloatRect const&, sf::FloatRect const&)>
ssig::ScopedConnection<void(sf::FloatRect const&, sf::FloatRect const&)>
m_con_positionChanged;
Vector3u m_tilePosition;
jd::Tilemap const& m_tilemap;
Expand Down
15 changes: 8 additions & 7 deletions src/compsys/BasicMetaComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ class BasicMetaComponent: public MetaComponent {
};

#define JD_EVT_METACOMPONENT(c, bc) \
namespace { \
class c##Meta: public bc { \
public: \
virtual ConnectionBase* connectEvent(lua_State*, \
Component*, \
std::string const& name) const; \
}; \
namespace { \
class c##Meta: public bc { \
public: \
virtual ssig::ConnectionBase* connectEvent( \
lua_State*, \
Component*, \
std::string const& name) const; \
}; \
} // anonymous namespace


Expand Down
20 changes: 10 additions & 10 deletions src/compsys/MetaComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "Entity.hpp"
#include "Logfile.hpp"
#include "luaUtils.hpp"
#include "ssig.hpp"
#include "svc/ServiceLocator.hpp"
#include "svc/LuaVm.hpp"

Expand All @@ -18,6 +17,7 @@
#include <luabind/class_info.hpp>
#include <luabind/operator.hpp>
#include <luabind/raw_policy.hpp>
#include <ssig.hpp>

#include <unordered_map>

Expand Down Expand Up @@ -51,14 +51,14 @@ static std::ostream& operator<< (std::ostream& os, Component const& c)
return os << "jd.Component (" << c.metaComponent().name() << " @" << &c << ')';
}

static ConnectionBase* connectEvent(
static ssig::ConnectionBase* connectEvent(
lua_State* L,
Component& sender,
std::string const& eventname,
luabind::object const& receiver)
{
receiver.push(L);
ConnectionBase* result = sender.metaComponent().connectEvent(
ssig::ConnectionBase* result = sender.metaComponent().connectEvent(
L, &sender, eventname);
lua_pop(L, 1);
if (!result)
Expand Down Expand Up @@ -117,7 +117,7 @@ class wrap_Component: public Component, public luabind::wrap_base {
MetaComponent const* m_metaComponent;
};

class wrap_ConnectionBase: public ConnectionBase, public luabind::wrap_base {
class wrap_ConnectionBase: public ssig::ConnectionBase, public luabind::wrap_base {
public:
virtual void disconnect() { call<void>("disconnect"); }
virtual bool isConnected() const { return call<bool>("getIsConnected"); }
Expand Down Expand Up @@ -148,11 +148,11 @@ static void init(LuaVm& vm)
.LHISREFVALID2(Component),
def("registerComponent", &registerMetaComponent),
def("connect", &connectEvent, adopt(result)),
class_<ConnectionBase, wrap_ConnectionBase>("ConnectionBase")
class_<ssig::ConnectionBase, wrap_ConnectionBase>("ConnectionBase")
.def(constructor<>())
.def("disconnect", &ConnectionBase::disconnect)
.def("getIsConnected", &ConnectionBase::isConnected)
.property("isConnected", &ConnectionBase::isConnected)
.def("disconnect", &ssig::ConnectionBase::disconnect)
.def("getIsConnected", &ssig::ConnectionBase::isConnected)
.property("isConnected", &ssig::ConnectionBase::isConnected)
];

lua_getglobal(vm.L(), "jd");
Expand Down Expand Up @@ -204,12 +204,12 @@ void LuaMetaComponent::castDown(lua_State* L, Component* c) const
o.push(L);
}

ConnectionBase* LuaMetaComponent::connectEvent(Component* c, std::string const& name) const
ssig::ConnectionBase* LuaMetaComponent::connectEvent(Component* c, std::string const& name) const
{
using namespace luabind;
object receiver(from_stack(m_L, -1));
object callback = globals(m_L)[jd::moduleName]["callback_connectLuaEvent"];
if (type(callback) != LUA_TFUNCTION)
throw std::runtime_error("no callback for event connection defined (must be a plain function)");
return object_cast<ConnectionBase*>(callback(c, name, receiver)[adopt(result)]);
return object_cast<ssig::ConnectionBase*>(callback(c, name, receiver)[adopt(result)]);
}
6 changes: 3 additions & 3 deletions src/compsys/MetaComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


struct lua_State;
class ConnectionBase;
namespace ssig { class ConnectionBase; }
class Component;

class InvalidMetaComponentName: public std::runtime_error {
Expand All @@ -36,7 +36,7 @@ class InvalidMetaComponentName: public std::runtime_error {
}

// receiver is on top of stack; return value disconnects automatically on deletion
virtual ConnectionBase* connectEvent(lua_State*, Component*, std::string const& name) const
virtual ssig::ConnectionBase* connectEvent(lua_State*, Component*, std::string const& name) const
{
(void)name;
return nullptr;
Expand All @@ -58,7 +58,7 @@ class LuaMetaComponent: public MetaComponent {
virtual std::string const& name() const;

virtual void castDown(lua_State* L, Component* c) const override;
virtual ConnectionBase* connectEvent(Component* c, std::string const& name) const;
virtual ssig::ConnectionBase* connectEvent(Component* c, std::string const& name) const;

private:
lua_State* m_L;
Expand Down
19 changes: 10 additions & 9 deletions src/luaexport/LuaEventHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#define LUA_EVENT_HELPERS_HPP_INCLUDED LUA_EVENT_HELPERS_HPP_INCLUDED

#include "LuaFunction.hpp"
#include "ssig.hpp"

#include <boost/bind.hpp>
#include <ssig.hpp>


#define LUA_EVENT_HELPERS_MAX_ARGS SSIG_MAX_ARGS
Expand All @@ -26,22 +26,23 @@
else { }

#define JD_EVENT_TABLE_BEGIN(ct) \
ConnectionBase* ct##Meta::connectEvent( \
lua_State* L, \
Component* c, \
std::string const& name) const \
{ \
ct* cc = c->as<ct>(); \
ssig::ConnectionBase* ct##Meta::connectEvent( \
lua_State* L, \
Component* c, \
std::string const& name) const \
{ \
ct* cc = c->as<ct>(); \
luabind::object recv(luabind::from_stack(L, -1)); \
using boost::ref; using boost::cref;

#define JD_EVENT_TABLE_END return nullptr; }


template<typename Signature>
ScopedConnection<Signature>* makeConnection(Connection<Signature> const& con)
ssig::ScopedConnection<Signature>* makeConnection(
ssig::Connection<Signature> const& con)
{
return new ScopedConnection<Signature>(con);
return new ssig::ScopedConnection<Signature>(con);
}

#endif // include guard
2 changes: 1 addition & 1 deletion src/luaexport/TimerMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void init(LuaVm& vm)
.LHPROPG(frameDuration)
.property("factor", &LHCURCLASS::factor, &LHCURCLASS::setFactor)
.scope [
class_<LHCURCLASS::CallOrder, ConnectionBase>("CallOrder")
class_<LHCURCLASS::CallOrder, ssig::ConnectionBase>("CallOrder")
]

# undef LHCURCLASS
Expand Down
Loading

0 comments on commit e97160a

Please sign in to comment.