# HG changeset patch # User terom # Date 1225754661 0 # Node ID faa4e777cc6eabd9517483549f63f96cca6dce35 # Parent 617813994ab1ce47ed39febc77a7fb49f4854efc fiddle with cmake, fix some compile errors diff -r 617813994ab1 -r faa4e777cc6e cmake/Modules/FindClanLib.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/Modules/FindClanLib.cmake Mon Nov 03 23:24:21 2008 +0000 @@ -0,0 +1,48 @@ +# - Try to find ClanLib +# Example usage: find_package(ClanLib 0.8 REQUIRED COMPONENTS Core App Display GL Sound) +# +# Once done, this will define +# +# ClanLib_FOUND - system has ClanLib (all the components requested) +# ClanLib_INCLUDE_DIRS - the ClanLib include directories +# ClanLib_LIBRARIES - link these to use ClanLib +# +# See documentation on how to write CMake scripts at +# http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries + +include(LibFindMacros) + +if (ClanLib_FIND_VERSION_MAJOR AND ClanLib_FIND_VERSION_MINOR) + set(ClanLib_VERSION "${ClanLib_FIND_VERSION_MAJOR}.${ClanLib_FIND_VERSION_MINOR}") +else (ClanLib_FIND_VERSION_MAJOR AND ClanLib_FIND_VERSION_MINOR) + set(ClanLib_VERSION "0.8") +endif (ClanLib_FIND_VERSION_MAJOR AND ClanLib_FIND_VERSION_MINOR) + +libfind_pkg_check_modules(ClanLib_PKGCONF clanCore-${ClanLib_VERSION}) + +find_path(ClanLib_INCLUDE_DIR + NAMES ClanLib/core.h + PATHS ${ClanLib_PKGCONF_INCLUDE_DIRS} + PATH_SUFFIXES ClanLib-${ClanLib_VERSION} +) + +# Extract the actual version number +if (ClanLib_INCLUDE_DIR) + file(READ "${ClanLib_INCLUDE_DIR}/ClanLib/core.h" _ClanLib_CORE_H_CONTENTS) + set(_ClanLib_VERSION_REGEX ".*#define CL_VERSION_STRING \"([^\n]*)\".*") + if ("${_ClanLib_CORE_H_CONTENTS}" MATCHES "${_ClanLib_VERSION_REGEX}") + string(REGEX REPLACE "${_ClanLib_VERSION_REGEX}" "\\1" ClanLib_VERSION "${_ClanLib_CORE_H_CONTENTS}") + endif ("${_ClanLib_CORE_H_CONTENTS}" MATCHES "${_ClanLib_VERSION_REGEX}") +endif (ClanLib_INCLUDE_DIR) + +foreach(COMPONENT ${ClanLib_FIND_COMPONENTS}) + find_library(ClanLib_${COMPONENT}_LIBRARY + NAMES clan${COMPONENT} + PATHS ${ClanLib_PKGCONF_LIBRARY_DIRS} + ) + set(ClanLib_PROCESS_LIBS ${ClanLib_PROCESS_LIBS} ClanLib_${COMPONENT}_LIBRARY) +endforeach(COMPONENT) + +set(ClanLib_PROCESS_INCLUDES ClanLib_INCLUDE_DIR) +libfind_process(ClanLib) + diff -r 617813994ab1 -r faa4e777cc6e cmake/Modules/LibFindMacros.cmake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmake/Modules/LibFindMacros.cmake Mon Nov 03 23:24:21 2008 +0000 @@ -0,0 +1,77 @@ +# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments +# used for the current package. For this to work, the first parameter must be the +# prefix of the current package, then the prefix of the new package etc, which are +# passed to find_package. +macro (libfind_package PREFIX) + set (LIBFIND_PACKAGE_ARGS ${ARGN}) + if (${PREFIX}_FIND_QUIETLY) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) + endif (${PREFIX}_FIND_QUIETLY) + if (${PREFIX}_FIND_REQUIRED) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) + endif (${PREFIX}_FIND_REQUIRED) + find_package(${LIBFIND_PACKAGE_ARGS}) +endmacro (libfind_package) + +# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6) +# where they added pkg_check_modules. Consequently I need to support both in my scripts +# to avoid those deprecated warnings. Here's a helper that does just that. +# Works identically to pkg_check_modules, except that no checks are needed prior to use. +macro (libfind_pkg_check_modules PREFIX PKGNAME) + if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + include(UsePkgConfig) + pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) + else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(${PREFIX} ${PKGNAME}) + endif (PKG_CONFIG_FOUND) + endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) +endmacro (libfind_pkg_check_modules) + +# Do the final processing once the paths have been detected. +# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain +# all the variables, each of which contain one include directory. +# Ditto for ${PREFIX}_PROCESS_LIBS and library files. +# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. +# Also handles errors in case library detection was required, etc. +macro (libfind_process PREFIX) + # Skip processing if already processed during this run + if (NOT ${PREFIX}_FOUND) + # Start with the assumption that the library was found + set (${PREFIX}_FOUND TRUE) + + # Process all includes and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_INCLUDES}) + if (${i}) + set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Process all libraries and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_LIBS}) + if (${i}) + set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Print message and/or exit on fatal error + if (${PREFIX}_FOUND) + if (NOT ${PREFIX}_FIND_QUIETLY) + message (STATUS "Found ${PREFIX}") + endif (NOT ${PREFIX}_FIND_QUIETLY) + else (${PREFIX}_FOUND) + if (${PREFIX}_FIND_REQUIRED) + foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) + message("${i}=${${i}}") + endforeach (i) + message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") + endif (${PREFIX}_FIND_REQUIRED) + endif (${PREFIX}_FOUND) + endif (NOT ${PREFIX}_FOUND) +endmacro (libfind_process) + diff -r 617813994ab1 -r faa4e777cc6e src/CMakeLists.txt --- a/src/CMakeLists.txt Mon Nov 03 22:59:50 2008 +0000 +++ b/src/CMakeLists.txt Mon Nov 03 23:24:21 2008 +0000 @@ -27,3 +27,6 @@ target_link_libraries("${PROJECT_SHORT_NAME}" ${LIBS}) install(TARGETS "${PROJECT_SHORT_NAME}" DESTINATION bin) +# prototype +add_subdirectory(proto2) + diff -r 617813994ab1 -r faa4e777cc6e src/proto2/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/proto2/CMakeLists.txt Mon Nov 03 23:24:21 2008 +0000 @@ -0,0 +1,29 @@ +FILE(GLOB SOURCE_FILES "*.cc") +FILE(GLOB HEADER_FILES "*.hh") + +set(SOURCES ${SOURCE_FILES} ${HEADER_FILES}) + +# Set default compile flags for GCC +if(CMAKE_COMPILER_IS_GNUCXX) + message(STATUS "GCC detected, enabling pedantic mode and warnings") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98 -pedantic -Wall -Wextra") +endif(CMAKE_COMPILER_IS_GNUCXX) + +# Generate config.h +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY) +include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +# Libraries + +# ClanLib 0.8 +find_package(ClanLib 0.8 REQUIRED COMPONENTS Core App Network) +include_directories(${ClanLib_INCLUDE_DIRS}) +set(LIBS ${LIBS} ${ClanLib_LIBRARIES}) + +# Assumes the project generates only one executable. If you need more, you'll need to alter +# the script and replace ${PROJECT_SHORT_NAME} by executable name. +add_executable("${PROJECT_SHORT_NAME}/proto2" ${SOURCES}) +target_link_libraries("${PROJECT_SHORT_NAME}/proto2" ${LIBS}) +install(TARGETS "${PROJECT_SHORT_NAME}/proto2" DESTINATION bin) + + diff -r 617813994ab1 -r faa4e777cc6e src/proto2/Dimension.hh --- a/src/proto2/Dimension.hh Mon Nov 03 22:59:50 2008 +0000 +++ b/src/proto2/Dimension.hh Mon Nov 03 23:24:21 2008 +0000 @@ -1,6 +1,7 @@ #ifndef DIMENSION_HH #define DIMENSION_HH + class Dimension { public: uint32_t width; @@ -9,6 +10,14 @@ Dimension (uint32_t width, uint32_t height) : width(width), height(height) { } }; +class PositionDelta { + public: + uint32_t dx; + uint32_t dy; + + PositionDelta (uint32_t dx, uint32_t dy) : dx(dx), dy(dy) { } +}; + class Coordinate { public: uint32_t x; @@ -19,6 +28,8 @@ Coordinate &operator+= (const PositionDelta &d) { this->x += d.dx; this->y += d.dy; + + return *this; } uint32_t scaledX() { @@ -32,12 +43,4 @@ } }; -class PositionDelta { - public: - uint32_t dx; - uint32_t dy; - - PositionDelta (uint32_t dx, uint32_t dy) : dx(dx), dy(dy) { } -}; - #endif diff -r 617813994ab1 -r faa4e777cc6e src/proto2/GameState.hh --- a/src/proto2/GameState.hh Mon Nov 03 22:59:50 2008 +0000 +++ b/src/proto2/GameState.hh Mon Nov 03 23:24:21 2008 +0000 @@ -5,31 +5,21 @@ #include -class GameState { - public: - Dimension map_dimensions; - std::list player_list; - - LocalPlayer &getLocalPlayer (void) { - // XXX: jotain - } -}; - enum PlayerType { - PLAYER_LOCAL = 0x01; - PLAYER_REMOTE = 0x02; + PLAYER_LOCAL = 0x01, + PLAYER_REMOTE = 0x02 }; class Player { - private: + protected: Coordinate position; public: - Player(Coordinate c) : position(c) {} + Player(Coordinate c) : position(c), dimensions(10, 10) {} PlayerType type; - Dimensions dimensions; + Dimension dimensions; Coordinate getPosition (void) const { return this->position; @@ -47,9 +37,20 @@ class RemotePlayer : public Player { public: - void updatePosition (Position p) { + void updatePosition (Coordinate p) { this->position = p; } -} +}; + +class GameState { + public: + Dimension map_dimensions; + std::list player_list; + + LocalPlayer &getLocalPlayer (void) { + // XXX: jotain + } +}; + #endif diff -r 617813994ab1 -r faa4e777cc6e src/proto2/NetworkServer.cc --- a/src/proto2/NetworkServer.cc Mon Nov 03 22:59:50 2008 +0000 +++ b/src/proto2/NetworkServer.cc Mon Nov 03 23:24:21 2008 +0000 @@ -2,7 +2,7 @@ #include -NetworkServer::NetworkServer (GameState &state, const CL_IPAddress &listen_ip) : NetworkBase(), state(state) { +NetworkServer::NetworkServer (GameState *state, const CL_IPAddress &listen_ip) : NetworkBase(), state(state) { socket.bind(listen_ip); socket.listen(NETWORK_SERVER_BACKLOG); diff -r 617813994ab1 -r faa4e777cc6e src/proto2/NetworkServer.hh --- a/src/proto2/NetworkServer.hh Mon Nov 03 22:59:50 2008 +0000 +++ b/src/proto2/NetworkServer.hh Mon Nov 03 23:24:21 2008 +0000 @@ -1,10 +1,18 @@ #ifndef NETWORKSERVER_HH #define NETWORKSERVER_HH +#include "Network.hh" +#include "GameState.hh" + #include +#include +#include #define NETWORK_SERVER_BACKLOG 8 +// forward-declare +class NetworkServerClient; + class NetworkServer : public NetworkBase { private: GameState *state; @@ -13,7 +21,7 @@ CL_EventListener listener; - CL_Slot slot_on_accept; + CL_Slot slot_on_recv; NetworkServer (GameState *state, const CL_IPAddress &listen_ip); @@ -23,7 +31,7 @@ void run (void); private: - void _onAccept (void); + void _onRecv (void); }; class NetworkServerClient { diff -r 617813994ab1 -r faa4e777cc6e src/proto2/config.h.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/proto2/config.h.in Mon Nov 03 23:24:21 2008 +0000 @@ -0,0 +1,13 @@ +#ifndef @PROJECT_SHORT_NAME@_CONFIG_H +#define @PROJECT_SHORT_NAME@_CONFIG_H + +/* Note: CMake autogenerates build/src/config.h from src/config.h.in */ +/* #include "config.h" to use the generated file */ + +#define PROJECT_DATA_DIR "@PROJECT_DATA_DIR@" +#define PROJECT_SHORT_NAME "@PROJECT_SHORT_NAME@" +#define PROJECT_LONG_NAME "@PROJECT_LONG_NAME@" +#define PROJECT_VERSION "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@" + +#endif +