librarization clean up

This commit is contained in:
Sebastian Krzyszkowiak 2016-07-03 00:43:32 +02:00
parent a8475eb99b
commit b8008d2872
19 changed files with 67 additions and 113 deletions

View file

@ -6,5 +6,4 @@ include("cmake/include.cmake")
include("cmake/SetPaths.cmake")
add_subdirectory(src)
add_subdirectory(data)

View file

@ -1,25 +1,16 @@
Become Derpy Hooves and fight with muffinzombies in this free software game in order to rescue Ponyville ponies so they can defeat Discord once again!
# libsuperderpy
A game engine for games written in C and Allegro 5.
Equestria is again under Discord's attack! Now he's using an army of muffinzombies to bring back chaos and lack of harmony into ponies world. But he didn't think about some mare who knows everything about muffins...
Used by such games as:
- Super Derpy: Muffin Attack
- Cadence Throw: Throwing Wives is Magic
- Radio Edit
- Controls Control
- Tickle Monster vs. Suits
- Mediator
- Back to the Browser Wars
*Super Derpy: Muffin Attack* is written in C and requires Allegro 5.0.6. Works on Windows, GNU/Linux and Mac OS X.
WIP: The engine is being separated from its games and modularized right now. Stay tuned for documentation and examples soon!
The game uses CMake as build system, so its building process is pretty typical.
Compilation:
mkdir build; cd build
cmake ..
make
Running (from top directory):
build/superderpy
Installation (as root):
make install
For packaging information, read lib/README.txt
Written by Sebastian Krzyszkowiak <dos@dosowisko.net>
--
by dos - Sebastian Krzyszkowiak

View file

@ -1,25 +1,25 @@
add_definitions(-D_XOPEN_SOURCE=600)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c11")
if(APPLE)
if(CMAKE_INSTALL_PREFIX MATCHES "/usr/local")
set(CMAKE_INSTALL_PREFIX "/Applications")
set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
endif(CMAKE_INSTALL_PREFIX MATCHES "/usr/local")
if(CMAKE_INSTALL_PREFIX MATCHES "/usr/local")
set(CMAKE_INSTALL_PREFIX "/Applications")
set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
endif(CMAKE_INSTALL_PREFIX MATCHES "/usr/local")
endif(APPLE)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/libsuperderpy/cmake ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/libsuperderpy/cmake ${PROJECT_SOURCE_DIR}/cmake)
include_directories(".")
include_directories("." "libsuperderpy/src")
if(MINGW)
# Guess MINGDIR from the value of CMAKE_C_COMPILER if it's not set.
if("$ENV{MINGDIR}" STREQUAL "")
string(REGEX REPLACE "/bin/[^/]*$" "" MINGDIR "${CMAKE_C_COMPILER}")
message(STATUS "Guessed MinGW directory: ${MINGDIR}")
string(REGEX REPLACE "/bin/[^/]*$" "" MINGDIR "${CMAKE_C_COMPILER}")
message(STATUS "Guessed MinGW directory: ${MINGDIR}")
else("$ENV{MINGDIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{MINGDIR}" MINGDIR)
message(STATUS "Using MINGDIR: ${MINGDIR}")
file(TO_CMAKE_PATH "$ENV{MINGDIR}" MINGDIR)
message(STATUS "Using MINGDIR: ${MINGDIR}")
endif("$ENV{MINGDIR}" STREQUAL "")
# Search in MINGDIR for headers and libraries.
@ -29,26 +29,24 @@ if(MINGW)
endif(MINGW)
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib/${LIBSUPERDERPY_GAMENAME}:\$ORIGIN/gamestates:\$ORIGIN:\$ORIGIN/../lib:\$ORIGIN/lib:\$ORIGIN/bin")
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib/${LIBSUPERDERPY_GAMENAME}:\$ORIGIN/gamestates:\$ORIGIN:\$ORIGIN/../lib:\$ORIGIN/lib:\$ORIGIN/bin")
MACRO(GAMESTATE name)
MACRO(register_gamestate name)
add_library("libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" SHARED "${name}.c")
add_library("libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" SHARED "${name}.c")
SET_TARGET_PROPERTIES("libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" PROPERTIES PREFIX "")
set_target_properties("libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" PROPERTIES PREFIX "")
target_link_libraries("libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" ${ALLEGRO5_LIBRARIES} ${ALLEGRO5_FONT_LIBRARIES} ${ALLEGRO5_TTF_LIBRARIES} ${ALLEGRO5_PRIMITIVES_LIBRARIES} ${ALLEGRO5_AUDIO_LIBRARIES} ${ALLEGRO5_ACODEC_LIBRARIES} ${ALLEGRO5_IMAGE_LIBRARIES} ${ALLEGRO5_COLOR_LIBRARIES} m libsuperderpy)
target_link_libraries("libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" ${ALLEGRO5_LIBRARIES} ${ALLEGRO5_FONT_LIBRARIES} ${ALLEGRO5_TTF_LIBRARIES} ${ALLEGRO5_PRIMITIVES_LIBRARIES} ${ALLEGRO5_AUDIO_LIBRARIES} ${ALLEGRO5_ACODEC_LIBRARIES} ${ALLEGRO5_IMAGE_LIBRARIES} ${ALLEGRO5_COLOR_LIBRARIES} m libsuperderpy)
install(TARGETS "libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" DESTINATION ${LIB_INSTALL_DIR})
#add_custom_command(TARGET "libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}.so" $<TARGET_FILE_DIR:${LIBSUPERDERPY_GAMENAME}>)
install(TARGETS "libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" DESTINATION ${LIB_INSTALL_DIR})
ENDMACRO()
MACRO(libsuperderpy_copy EXECUTABLE)
add_custom_command(TARGET "${EXECUTABLE}" PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "../libsuperderpy/src/libsuperderpy.so" $<TARGET_FILE_DIR:${EXECUTABLE}>)
add_custom_command(TARGET "${EXECUTABLE}" PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "../libsuperderpy/src/libsuperderpy.so" $<TARGET_FILE_DIR:${EXECUTABLE}>)
ENDMACRO()

View file

@ -1,6 +0,0 @@
SET(DATADIR "${SHARE_INSTALL_PREFIX}/${LIBSUPERDERPY_GAMENAME}/data")
if(APPLE)
SET(DATADIR "${BIN_INSTALL_DIR}/${LIBSUPERDERPY_GAMENAME_PRETTY}.app/Contents/Resources/data") #OMG NASTY
endif(APPLE)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -3,19 +3,13 @@ SET(SRC_LIST
config.c
timeline.c
gamestate.c
main.c
)
SET(EXECUTABLE_SRC_LIST
main.c
libsuperderpy.c
)
add_definitions(-DLIBSUPERDERPY_GAMENAME_PRETTY="${LIBSUPERDERPY_GAMENAME_PRETTY}")
add_definitions(-DLIBSUPERDERPY_GAMENAME="${LIBSUPERDERPY_GAMENAME}")
add_definitions(-DLIBSUPERDERPY_INITIAL_GAMESTATE="${LIBSUPERDERPY_INITIAL_GAMESTATE}")
add_definitions(-D_XOPEN_SOURCE=600)
find_package(Allegro5 REQUIRED)
find_package(Allegro5Font REQUIRED)
find_package(Allegro5TTF REQUIRED)
@ -28,26 +22,13 @@ if(APPLE)
find_package(Allegro5Main)
endif(APPLE)
if(MINGW)
# resource compilation for MinGW
add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/icon.o COMMAND ${CMAKE_RC_COMPILER} -I${CMAKE_SOURCE_DIR} -i${CMAKE_SOURCE_DIR}/data/icons/icon.rc -o ${CMAKE_CURRENT_BINARY_DIR}/icon.o )
set(EXECUTABLE_SRC_LIST ${EXECUTABLE_SRC_LIST} ${CMAKE_CURRENT_BINARY_DIR}/icon.o)
set(LINK_FLAGS -Wl,-subsystem,windows)
endif(MINGW)
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib/${LIBSUPERDERPY_GAMENAME}:\$ORIGIN/gamestates:\$ORIGIN:\$ORIGIN/../lib:\$ORIGIN/lib:\$ORIGIN/bin")
add_library("libsuperderpy" SHARED ${SRC_LIST})
#add_executable(${EXECUTABLE} WIN32 MACOSX_BUNDLE ${EXECUTABLE_SRC_LIST})
SET_TARGET_PROPERTIES("libsuperderpy" PROPERTIES PREFIX "")
include_directories(${ALLEGRO5_INCLUDE_DIR} ${ALLEGRO5_FONT_INCLUDE_DIR} ${ALLEGRO5_TTF_INCLUDE_DIR} ${ALLEGRO5_PRIMITIVES_INCLUDE_DIR} ${ALLEGRO5_AUDIO_INCLUDE_DIR} ${ALLEGRO5_ACODEC_INCLUDE_DIR} ${ALLEGRO5_IMAGE_INCLUDE_DIR})
#target_link_libraries(${EXECUTABLE} ${ALLEGRO5_LIBRARIES} ${ALLEGRO5_FONT_LIBRARIES} ${ALLEGRO5_TTF_LIBRARIES} ${ALLEGRO5_PRIMITIVES_LIBRARIES} ${ALLEGRO5_AUDIO_LIBRARIES} ${ALLEGRO5_ACODEC_LIBRARIES} ${ALLEGRO5_IMAGE_LIBRARIES} ${ALLEGRO5_MAIN_LIBRARIES} m dl libsuperderpy-${LIBSUPERDERPY_GAMENAME})
target_link_libraries("libsuperderpy" ${ALLEGRO5_LIBRARIES} ${ALLEGRO5_FONT_LIBRARIES} ${ALLEGRO5_TTF_LIBRARIES} ${ALLEGRO5_PRIMITIVES_LIBRARIES} ${ALLEGRO5_AUDIO_LIBRARIES} ${ALLEGRO5_ACODEC_LIBRARIES} ${ALLEGRO5_IMAGE_LIBRARIES} ${ALLEGRO5_MAIN_LIBRARIES} m dl)
#install(TARGETS ${EXECUTABLE} DESTINATION ${BIN_INSTALL_DIR})
install(TARGETS "libsuperderpy" DESTINATION ${LIB_INSTALL_DIR})

View file

@ -19,7 +19,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "main.h"
#ifndef LIBSUPERDERPY_CONFIG_H
#define LIBSUPERDERPY_CONFIG_H
#include "libsuperderpy.h"
/*! \brief Reads config from file into memory. */
void InitConfig(struct Game *game);
@ -31,3 +34,5 @@ const char* GetConfigOptionDefault(struct Game *game, char* section, char* name,
void SetConfigOption(struct Game *game, char* section, char* name, char* value);
/*! \brief Writes config from memory to file. */
void DeinitConfig(struct Game *game);
#endif

View file

@ -35,15 +35,12 @@ struct Gamestate* AddNewGamestate(struct Game *game) {
tmp = tmp->next;
}
tmp->name = NULL;
tmp->fade = false;
tmp->fade_counter = 0;
tmp->handle = NULL;
tmp->loaded = false;
tmp->paused = false;
tmp->started = false;
tmp->pending_load = false;
tmp->pending_start = false;
tmp->after = NULL;
tmp->next = NULL;
return tmp;
}
@ -70,8 +67,6 @@ void LoadGamestate(struct Game *game, const char* name) {
} else {
gs = AddNewGamestate(game);
gs->name = strdup(name);
gs->fade = true;
gs->fade_counter = 0;
gs->pending_load = true;
gs->showLoading = true;
}

View file

@ -18,8 +18,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef GAMESTATE_H
#define GAMESTATE_H
#ifndef LIBSUPERDERPY_GAMESTATE_H
#define LIBSUPERDERPY_GAMESTATE_H
#include "allegro5/allegro.h"
@ -32,9 +32,6 @@ struct Gamestate {
bool started, pending_start;
bool showLoading;
bool paused;
bool fade; // TODO: or maybe should it be in API?
unsigned char fade_counter;
char** after; // TODO: and this one too?
struct Gamestate* next;
void* data;
struct {

View file

@ -37,7 +37,7 @@
#endif
#include "utils.h"
#include "config.h"
#include "main.h"
#include "libsuperderpy.h"
extern int main(int, char**);

View file

@ -20,14 +20,17 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef MAIN_H
#define MAIN_H
#ifndef LIBSUPERDERPY_MAIN_H
#define LIBSUPERDERPY_MAIN_H
#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_font.h>
#include "gamestate.h"
#include "config.h"
#include "timeline.h"
#include "utils.h"
struct Gamestate;
@ -35,11 +38,11 @@ struct Gamestate;
struct Game {
ALLEGRO_DISPLAY *display; /*!< Main Allegro display. */
ALLEGRO_TRANSFORM projection;
ALLEGRO_TRANSFORM projection; /*!< Projection of the game canvas into the actual game window. */
struct {
int width; /*!< Actual available width of viewport. */
int height; /*!< Actual available height of viewport. */
int width; /*!< Actual available width of the drawing canvas. */
int height; /*!< Actual available height of the drawing canvas. */
} viewport;
struct {
@ -48,7 +51,6 @@ struct Game {
int voice; /*!< Voice volume. */
bool fullscreen; /*!< Fullscreen toggle. */
bool debug; /*!< Toggles debug mode. */
int fps; /*!< FPS limit */
int width; /*!< Width of window as being set in configuration. */
int height; /*!< Height of window as being set in configuration. */
} config;
@ -62,33 +64,30 @@ struct Game {
} audio; /*!< Audio resources. */
struct {
//struct Gamestate *gamestate; /*!< Current gamestate. */
struct Gamestate *gamestates; /*!< List of known gamestates. */
ALLEGRO_FONT *font; /*!< Main font used in game. */
ALLEGRO_FONT *font_console; /*!< Font used in game console. */
ALLEGRO_FONT *font_bsod; /*!< Font used in Blue Screens of Derp. */
ALLEGRO_BITMAP *console; /*!< Bitmap with game console. */
ALLEGRO_EVENT_QUEUE *event_queue; /*!< Main event queue. */
ALLEGRO_TIMER *timer; /*!< Main LPS timer. */
ALLEGRO_TIMER *timer; /*!< Main LPS (logic) timer. */
bool showconsole; /*!< If true, game console is rendered on screen. */
struct {
double old_time, fps;
int frames_done;
} fps_count;
} fps_count; /*!< Used for counting the effective FPS. */
ALLEGRO_CONFIG *config;
ALLEGRO_CONFIG *config; /*!< Configuration file interface. */
struct {
void (*Draw)(struct Game *game, void* data, float p);
void* (*Load)(struct Game *game);
void (*Start)(struct Game *game, void* data);
void (*Stop)(struct Game *game, void* data);
void (*Unload)(struct Game *game, void* data);
void* data;
} loading;
} loading; /*!< Interface for accessing loading screen functions. */
} _priv; /*!< Private resources. Do not use in gamestates! */
@ -97,6 +96,6 @@ struct Game {
};
int libsuperderpy(int argc, char **argv);
int libsuperderpy(int argc, char **argv); /*!< Engine's main loop. */
#endif

View file

@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TIMELINE_H
#define TIMELINE_H
#ifndef LIBSUPERDERPY_TIMELINE_H
#define LIBSUPERDERPY_TIMELINE_H
#include "main.h"
#include "libsuperderpy.h"
#define TM_WrapArg(type, result, val) type* result = malloc(sizeof(type)); *result = val;

View file

@ -36,6 +36,7 @@ char* strdup(const char *str) {
void DrawConsole(struct Game *game) {
if (game->_priv.showconsole) {
al_set_target_backbuffer(game->display);
ALLEGRO_TRANSFORM trans;
al_identity_transform(&trans);
int clipX, clipY, clipWidth, clipHeight;
@ -51,9 +52,9 @@ void DrawConsole(struct Game *game) {
}
char sfps[6] = { };
snprintf(sfps, 6, "%.0f", game->_priv.fps_count.fps);
al_use_transform(&game->projection);
DrawTextWithShadow(game->_priv.font_console, al_map_rgb(255,255,255), clipX + clipWidth, clipY, ALLEGRO_ALIGN_RIGHT, sfps);
DrawTextWithShadow(game->_priv.font, al_map_rgb(255,255,255), game->viewport.width*0.99, 0, ALLEGRO_ALIGN_RIGHT, sfps);
al_use_transform(&game->projection);
}
game->_priv.fps_count.frames_done++;
@ -69,14 +70,12 @@ void Console_Load(struct Game *game) {
game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"), al_get_display_height(game->display)*0.025,0 );
}
game->_priv.console = al_create_bitmap((al_get_display_width(game->display) / 320) * 320, al_get_font_line_height(game->_priv.font_console)*5);
game->_priv.font = al_load_ttf_font(GetDataFilePath(game, "fonts/MonkeyIsland.ttf"), 0 ,0 );
al_set_target_bitmap(game->_priv.console);
al_clear_to_color(al_map_rgba(0,0,0,80));
al_set_target_bitmap(al_get_backbuffer(game->display));
}
void Console_Unload(struct Game *game) {
al_destroy_font(game->_priv.font);
al_destroy_font(game->_priv.font_console);
al_destroy_bitmap(game->_priv.console);
}
@ -320,20 +319,10 @@ char* GetDataFilePath(struct Game *game, char* filename) {
}
}
{
char origfn[255] = "libsuperderpy/data/";
strcat(origfn, filename);
if (al_filename_exists(origfn)) {
return strdup(origfn);
}
}
TestPath(filename, "data/", &result);
TestPath(filename, "../share/" LIBSUPERDERPY_GAMENAME "/data/", &result);
TestPath(filename, "../data/", &result);
TestPath(filename, "libsuperderpy/data/", &result);
#ifdef ALLEGRO_MACOSX
TestPath(filename, "../Resources/data/", &result);
TestPath(filename, "../Resources/gamestates/", &result);

View file

@ -18,9 +18,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef LIBSUPERDERPY_UTILS_H
#define LIBSUPERDERPY_UTILS_H
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include "main.h"
#include "libsuperderpy.h"
#ifdef ALLEGRO_WINDOWS
#define LIBRARY_EXTENSION ".dll"
@ -115,3 +119,5 @@ void UnloadSpritesheets(struct Game *game, struct Character *character);
void AnimateCharacter(struct Game *game, struct Character *character, float speed_modifier);
void MoveCharacter(struct Game *game, struct Character *character, float x, float y, float angle);
void SetCharacterPosition(struct Game *game, struct Character *character, int x, int y, float angle);
#endif