librarify!

This commit is contained in:
Sebastian Krzyszkowiak 2016-07-02 23:23:08 +02:00
parent 0a6b70f72e
commit a8475eb99b
26 changed files with 166 additions and 2201 deletions

View file

@ -2,42 +2,9 @@ cmake_minimum_required(VERSION 2.8)
project(libsuperderpy C)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -std=c11")
if(APPLE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fnested-functions")
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}/cmake)
include("cmake/include.cmake")
include("cmake/SetPaths.cmake")
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}")
else("$ENV{MINGDIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{MINGDIR}" MINGDIR)
message(STATUS "Using MINGDIR: ${MINGDIR}")
endif("$ENV{MINGDIR}" STREQUAL "")
# Search in MINGDIR for headers and libraries.
set(CMAKE_PREFIX_PATH "${MINGDIR}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mwindows")
endif(MINGW)
add_subdirectory(src)
add_subdirectory(data)
add_subdirectory(lib)
# uninstall target
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
INCLUDE(InstallRequiredSystemLibraries)

1860
ChangeLog

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
# Project related configuration options
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Super Derpy: Muffin Attack"
PROJECT_NAME = "libsuperderpy"
PROJECT_NUMBER =
PROJECT_BRIEF =
PROJECT_LOGO =

1
bin/.gitignore vendored
View file

@ -1 +0,0 @@
*

View file

@ -7,7 +7,7 @@
FIND_PATH(ALLEGRO5_INCLUDE_DIR allegro5/allegro.h)
SET(ALLEGRO5_NAMES ${ALLEGRO5_NAMES} allegro allegro_static liballegro liballegro_static)
SET(ALLEGRO5_NAMES ${ALLEGRO5_NAMES} allegro allegro_static liballegro liballegro_static Allegro-5.2)
FIND_LIBRARY(ALLEGRO5_LIBRARY NAMES ${ALLEGRO5_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set ALLEGRO5_FOUND to TRUE if

View file

@ -7,7 +7,7 @@
FIND_PATH(ALLEGRO5_ACODEC_INCLUDE_DIR allegro5/allegro_acodec.h)
SET(ALLEGRO5_ACODEC_NAMES ${ALLEGRO5_ACODEC_NAMES} allegro_acodec allegro_acodec_static liballegro_acodec liballegro_acodec_static)
SET(ALLEGRO5_ACODEC_NAMES ${ALLEGRO5_ACODEC_NAMES} allegro_acodec allegro_acodec_static liballegro_acodec liballegro_acodec_static AllegroAcodec-5.2)
FIND_LIBRARY(ALLEGRO5_ACODEC_LIBRARY NAMES ${ALLEGRO5_ACODEC_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set ALLEGRO5_ACODEC_FOUND to TRUE if

View file

@ -7,7 +7,7 @@
FIND_PATH(ALLEGRO5_AUDIO_INCLUDE_DIR allegro5/allegro_audio.h)
SET(ALLEGRO5_AUDIO_NAMES ${ALLEGRO5_AUDIO_NAMES} allegro_audio allegro_audio_static liballegro_audio liballegro_audio_static)
SET(ALLEGRO5_AUDIO_NAMES ${ALLEGRO5_AUDIO_NAMES} allegro_audio allegro_audio_static liballegro_audio liballegro_audio_static AllegroAudio-5.2)
FIND_LIBRARY(ALLEGRO5_AUDIO_LIBRARY NAMES ${ALLEGRO5_AUDIO_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set ALLEGRO5_AUDIO_FOUND to TRUE if

View file

@ -7,7 +7,7 @@
FIND_PATH(ALLEGRO5_COLOR_INCLUDE_DIR allegro5/allegro_color.h)
SET(ALLEGRO5_COLOR_NAMES ${ALLEGRO5_COLOR_NAMES} allegro_color allegro_color_static liballegro_color liballegro_color_static)
SET(ALLEGRO5_COLOR_NAMES ${ALLEGRO5_COLOR_NAMES} allegro_color allegro_color_static liballegro_color liballegro_color_static AllegroColor-5.2)
FIND_LIBRARY(ALLEGRO5_COLOR_LIBRARY NAMES ${ALLEGRO5_COLOR_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set ALLEGRO5_COLOR_FOUND to TRUE if

View file

@ -7,7 +7,7 @@
FIND_PATH(ALLEGRO5_FONT_INCLUDE_DIR allegro5/allegro_font.h)
SET(ALLEGRO5_FONT_NAMES ${ALLEGRO5_FONT_NAMES} allegro_font allegro_font_static liballegro_font liballegro_font_static)
SET(ALLEGRO5_FONT_NAMES ${ALLEGRO5_FONT_NAMES} allegro_font allegro_font_static liballegro_font liballegro_font_static AllegroFont-5.2)
FIND_LIBRARY(ALLEGRO5_FONT_LIBRARY NAMES ${ALLEGRO5_FONT_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set ALLEGRO5_FONT_FOUND to TRUE if

View file

@ -7,7 +7,7 @@
FIND_PATH(ALLEGRO5_IMAGE_INCLUDE_DIR allegro5/allegro_image.h)
SET(ALLEGRO5_IMAGE_NAMES ${ALLEGRO5_IMAGE_NAMES} allegro_image allegro_image_static liballegro_image liballegro_image_static)
SET(ALLEGRO5_IMAGE_NAMES ${ALLEGRO5_IMAGE_NAMES} allegro_image allegro_image_static liballegro_image liballegro_image_static AllegroImage-5.2)
FIND_LIBRARY(ALLEGRO5_IMAGE_LIBRARY NAMES ${ALLEGRO5_IMAGE_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set ALLEGRO5_IMAGE_FOUND to TRUE if

View file

@ -7,7 +7,7 @@
FIND_PATH(ALLEGRO5_PRIMITIVES_INCLUDE_DIR allegro5/allegro_primitives.h)
SET(ALLEGRO5_PRIMITIVES_NAMES ${ALLEGRO5_PRIMITIVES_NAMES} allegro_primitives allegro_primitives_static liballegro_primitives liballegro_primitives_static)
SET(ALLEGRO5_PRIMITIVES_NAMES ${ALLEGRO5_PRIMITIVES_NAMES} allegro_primitives allegro_primitives_static liballegro_primitives liballegro_primitives_static AllegroPrimitives-5.2)
FIND_LIBRARY(ALLEGRO5_PRIMITIVES_LIBRARY NAMES ${ALLEGRO5_PRIMITIVES_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set ALLEGRO5_PRIMITIVES_FOUND to TRUE if

View file

@ -7,7 +7,7 @@
FIND_PATH(ALLEGRO5_TTF_INCLUDE_DIR allegro5/allegro_ttf.h)
SET(ALLEGRO5_TTF_NAMES ${ALLEGRO5_TTF_NAMES} allegro_ttf allegro_ttf_static liballegro_ttf liballegro_ttf_static)
SET(ALLEGRO5_TTF_NAMES ${ALLEGRO5_TTF_NAMES} allegro_ttf allegro_ttf_static liballegro_ttf liballegro_ttf_static AllegroTTF-5.2)
FIND_LIBRARY(ALLEGRO5_TTF_LIBRARY NAMES ${ALLEGRO5_TTF_NAMES} )
# handle the QUIETLY and REQUIRED arguments and set ALLEGRO5_TTF_FOUND to TRUE if

55
cmake/include.cmake Normal file
View file

@ -0,0 +1,55 @@
add_definitions(-D_XOPEN_SOURCE=600)
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")
endif(APPLE)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/libsuperderpy/cmake ${PROJECT_SOURCE_DIR}/cmake)
include_directories(".")
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}")
else("$ENV{MINGDIR}" STREQUAL "")
file(TO_CMAKE_PATH "$ENV{MINGDIR}" MINGDIR)
message(STATUS "Using MINGDIR: ${MINGDIR}")
endif("$ENV{MINGDIR}" STREQUAL "")
# Search in MINGDIR for headers and libraries.
set(CMAKE_PREFIX_PATH "${MINGDIR}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mwindows")
endif(MINGW)
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib/${LIBSUPERDERPY_GAMENAME}:\$ORIGIN/gamestates:\$ORIGIN:\$ORIGIN/../lib:\$ORIGIN/lib:\$ORIGIN/bin")
MACRO(GAMESTATE name)
add_library("libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" SHARED "${name}.c")
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)
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}>)
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}>)
ENDMACRO()
include(InstallRequiredSystemLibraries)

View file

@ -1,16 +0,0 @@
IF(${PACKAGE_BUILD})
IF(WIN32)
FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/win32/*.dll")
INSTALL(FILES ${files} DESTINATION ${BIN_INSTALL_DIR})
ENDIF(WIN32)
IF(UNIX)
FILE(GLOB files "${CMAKE_SOURCE_DIR}/lib/linux-x86/*.so*")
INSTALL(FILES ${files} DESTINATION ${LIB_INSTALL_DIR}/superderpy)
ENDIF(UNIX)
ENDIF(${PACKAGE_BUILD})
# TODO: handle libraries in Mac OS X version if needed
# TODO: handle other architectures

View file

@ -1,56 +0,0 @@
This directory is used for distributing library binaries together with
Super Derpy packages.
It's optional - Super Derpy will build correctly without any file placed there,
but they're important when trying to create redistributable packages supposed
to run on systems without Allegro installed.
To include those files in Super Derpy build, run cmake with -DPACKAGE_BUILD=1
-------------------------------------------------------------------------------
When building for Windows, place all run-time DLLs in "win32" directory.
This is the list of DLLs included with official release:
* allegro-5.1.dll
* allegro_audio-5.1.dll
* allegro_image-5.1.dll
* allegro_ttf-5.1.dll
* allegro_acodec-5.1.dll
* allegro_font-5.1.dll
* allegro_primitives-5.1.dll
* libgcc_s_dw2-1.dll
* libstdc++-6.dll
* freetype6.dll
* libogg-0.dll
* zlib1.dll
As there's no standard way of installing packages in Windows, including those
files may be a good idea even when building just for yourself, unless you
made all those libraries registered in your system.
-------------------------------------------------------------------------------
When building for GNU/Linux, place all shared libraries in "linux-x86"
directory.
This is the list of shared libraries included with official release:
* liballegro.so.5.1
* liballegro_acodec.so.5.1
* liballegro_audio.so.5.1
* liballegro_font.so.5.1
* liballegro_image.so.5.1
* liballegro_primitives.so.5.1
* liballegro_ttf.so.5.1
Please note that while Windows version contains also DLLs with dependences from
Allegro, on GNU/Linux there's no need to provide them, as FreeType, libogg or
zlib are commonly available in distribition repositiories. Allegro 5 is not,
that's why it's included here until proper packages make it into the most
common distributions.
If you're on GNU/Linux, and you're not packaging but only building for
yourself, there's no need to place any files here.
Remember to adjust install prefix when packaging.
-------------------------------------------------------------------------------
TODO: Support Mac OS X (if it's needed at all) and other architectures
than x86.

View file

@ -1 +0,0 @@
*.so*

View file

@ -1 +0,0 @@
*.dll

View file

@ -1,18 +1,21 @@
SET(SRC_LIST
utils.c
config.c
timeline.c
gamestate.c
)
utils.c
config.c
timeline.c
gamestate.c
main.c
)
SET(EXECUTABLE_SRC_LIST
main.c
)
main.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)
@ -22,36 +25,29 @@ find_package(Allegro5ACodec REQUIRED)
find_package(Allegro5Image REQUIRED)
find_package(Allegro5Color REQUIRED)
if(APPLE)
find_package(Allegro5Main)
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)
# 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")
set(EXECUTABLE ${LIBSUPERDERPY_GAMENAME})
add_library("libsuperderpy-${LIBSUPERDERPY_GAMENAME}" SHARED ${SRC_LIST})
add_executable(${EXECUTABLE} WIN32 MACOSX_BUNDLE ${EXECUTABLE_SRC_LIST})
add_library("libsuperderpy" SHARED ${SRC_LIST})
#add_executable(${EXECUTABLE} WIN32 MACOSX_BUNDLE ${EXECUTABLE_SRC_LIST})
SET_TARGET_PROPERTIES("libsuperderpy-${LIBSUPERDERPY_GAMENAME}" PROPERTIES PREFIX "")
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(${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-${LIBSUPERDERPY_GAMENAME}" ${ALLEGRO5_LIBRARIES} ${ALLEGRO5_FONT_LIBRARIES} ${ALLEGRO5_TTF_LIBRARIES} ${ALLEGRO5_PRIMITIVES_LIBRARIES} ${ALLEGRO5_AUDIO_LIBRARIES} ${ALLEGRO5_ACODEC_LIBRARIES} ${ALLEGRO5_IMAGE_LIBRARIES} ${ALLEGRO5_MAIN_LIBRARIES} m)
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)
if(ALLEGRO5_MAIN_FOUND)
target_link_libraries(${EXECUTABLE} ${ALLEGRO5_MAIN_LIBRARIES})
endif(ALLEGRO5_MAIN_FOUND)
add_subdirectory(gamestates)
install(TARGETS ${EXECUTABLE} DESTINATION ${BIN_INSTALL_DIR})
install(TARGETS "libsuperderpy-${LIBSUPERDERPY_GAMENAME}" DESTINATION ${LIB_INSTALL_DIR})
#install(TARGETS ${EXECUTABLE} DESTINATION ${BIN_INSTALL_DIR})
install(TARGETS "libsuperderpy" DESTINATION ${LIB_INSTALL_DIR})

View file

@ -1,15 +0,0 @@
MACRO(GAMESTATE name)
add_library("libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" SHARED "${name}.c")
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-${LIBSUPERDERPY_GAMENAME})
install(TARGETS "libsuperderpy-${LIBSUPERDERPY_GAMENAME}-${name}" DESTINATION ${LIB_INSTALL_DIR})
ENDMACRO()
#GAMESTATE("dosowisko")
GAMESTATE("loading")

View file

@ -1,54 +0,0 @@
/*! \file loading.c
* \brief Loading screen.
*/
/*
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <allegro5/allegro_primitives.h>
#include "../utils.h"
#include "loading.h"
void Progress(struct Game *game, struct LoadingResources *data, float p) {
al_set_target_bitmap(al_get_backbuffer(game->display));
al_draw_bitmap(data->loading_bitmap,0,0,0);
al_draw_filled_rectangle(0, game->viewport.height/2 - 1, p*game->viewport.width, game->viewport.height/2 + 1, al_map_rgba(128,128,128,128));
}
void Draw(struct Game *game, struct LoadingResources *data, float p) {
al_draw_bitmap(data->loading_bitmap,0,0,0);
Progress(game, data, p);
}
void* Load(struct Game *game) {
struct LoadingResources *data = malloc(sizeof(struct LoadingResources));
al_clear_to_color(al_map_rgb(0,0,0));
data->loading_bitmap = al_create_bitmap(game->viewport.width, game->viewport.height);
al_set_target_bitmap(data->loading_bitmap);
al_clear_to_color(al_map_rgb(0,0,0));
al_draw_filled_rectangle(0, game->viewport.height/2 - 1, game->viewport.width, game->viewport.height/2 + 1, al_map_rgba(32,32,32,32));
al_set_target_bitmap(al_get_backbuffer(game->display));
return data;
}
void Start(struct Game *game, struct LoadingResources *data) {}
void Stop(struct Game *game, struct LoadingResources *data) {}
void Unload(struct Game *game, struct LoadingResources *data) {
al_destroy_bitmap(data->loading_bitmap);
free(data);
}

View file

@ -1,29 +0,0 @@
/*! \file loading.h
* \brief Loading screen headers.
*/
/*
* Copyright (c) Sebastian Krzyszkowiak <dos@dosowisko.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
/*! \brief Resources used by Loading state. */
struct LoadingResources {
ALLEGRO_BITMAP *loading_bitmap; /*!< Rendered loading bitmap. */
};

View file

@ -31,10 +31,16 @@
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_ttf.h>
#ifdef ALLEGRO_MACOSX
#include <mach-o/dyld.h>
#include <sys/param.h>
#endif
#include "utils.h"
#include "config.h"
#include "main.h"
extern int main(int, char**);
void DrawGamestates(struct Game *game) {
al_set_target_backbuffer(game->display);
al_clear_to_color(al_map_rgb(0,0,0));
@ -95,7 +101,7 @@ void derp(int sig) {
}
// TODO: let's break it up and move the binary out of libsuperderpy!
int main(int argc, char **argv){
int libsuperderpy(int argc, char **argv){
signal(SIGSEGV, derp);
srand(time(NULL));
@ -103,6 +109,16 @@ int main(int argc, char **argv){
al_set_org_name("dosowisko.net");
al_set_app_name(LIBSUPERDERPY_GAMENAME);
#ifdef ALLEGRO_MACOSX
char exe_path[MAXPATHLEN];
char link_path[MAXPATHLEN];
uint32_t size = sizeof(exe_path);
_NSGetExecutablePath(exe_path, &size);
realpath(exe_path, link_path);
chdir(link_path);
#endif
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
@ -119,7 +135,7 @@ int main(int argc, char **argv){
game._priv.font_bsod = NULL;
game._priv.console = NULL;
game.config.fullscreen = atoi(GetConfigOptionDefault(&game, "SuperDerpy", "fullscreen", "0"));
game.config.fullscreen = atoi(GetConfigOptionDefault(&game, "SuperDerpy", "fullscreen", "1"));
game.config.music = atoi(GetConfigOptionDefault(&game, "SuperDerpy", "music", "10"));
game.config.voice = atoi(GetConfigOptionDefault(&game, "SuperDerpy", "voice", "10"));
game.config.fx = atoi(GetConfigOptionDefault(&game, "SuperDerpy", "fx", "10"));
@ -132,7 +148,7 @@ int main(int argc, char **argv){
if(!al_init_image_addon()) {
fprintf(stderr, "failed to initialize image addon!\n");
/*al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!",
NULL, ALLEGRO_MESSAGEBOX_ERROR);*/
NULL, ALLEGRO_MESSAGEBOX_ERROR);*/
return -1;
}
@ -156,11 +172,11 @@ int main(int argc, char **argv){
return -1;
}
if(!al_install_mouse()) {
fprintf(stderr, "failed to initialize the mouse!\n");
return -1;
}
if(!al_install_mouse()) {
fprintf(stderr, "failed to initialize the mouse!\n");
return -1;
}
al_init_font_addon();
if(!al_init_ttf_addon()){
@ -186,13 +202,13 @@ int main(int argc, char **argv){
PrintConsole(&game, "Viewport %dx%d", game.viewport.width, game.viewport.height);
ALLEGRO_BITMAP *icon = al_load_bitmap(GetDataFilePath(&game, "icons/" LIBSUPERDERPY_GAMENAME ".png"));
ALLEGRO_BITMAP *icon = al_load_bitmap(GetDataFilePath(&game, "icons/" LIBSUPERDERPY_GAMENAME ".png"));
al_set_window_title(game.display, LIBSUPERDERPY_GAMENAME_PRETTY);
al_set_display_icon(game.display, icon);
al_destroy_bitmap(icon);
if (game.config.fullscreen) al_hide_mouse_cursor(game.display);
al_inhibit_screensaver(true);
if (game.config.fullscreen) al_hide_mouse_cursor(game.display);
al_inhibit_screensaver(true);
al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR);
@ -219,8 +235,8 @@ int main(int argc, char **argv){
al_set_mixer_gain(game.audio.voice, game.config.voice/10.0);
al_register_event_source(game._priv.event_queue, al_get_display_event_source(game.display));
al_register_event_source(game._priv.event_queue, al_get_mouse_event_source());
al_register_event_source(game._priv.event_queue, al_get_keyboard_event_source());
al_register_event_source(game._priv.event_queue, al_get_mouse_event_source());
al_register_event_source(game._priv.event_queue, al_get_keyboard_event_source());
game._priv.showconsole = game.config.debug;
@ -240,7 +256,7 @@ int main(int argc, char **argv){
game.shuttingdown = false;
game.restart = false;
char* gamestate = strdup(LIBSUPERDERPY_INITIAL_GAMESTATE); // FIXME: don't hardcore gamestate
char* gamestate = strdup(LIBSUPERDERPY_INITIAL_GAMESTATE); // FIXME: don't hardcore gamestate
int c;
while ((c = getopt (argc, argv, "l:s:")) != -1)
@ -257,19 +273,19 @@ int main(int argc, char **argv){
}
LoadGamestate(&game, gamestate);
game._priv.gamestates->showLoading = false; // we have only one gamestate right now
StartGamestate(&game, gamestate);
game._priv.gamestates->showLoading = false; // we have only one gamestate right now
StartGamestate(&game, gamestate);
free(gamestate);
char libname[1024] = {};
snprintf(libname, 1024, "libsuperderpy-%s-loading" LIBRARY_EXTENSION, LIBSUPERDERPY_GAMENAME);
snprintf(libname, 1024, "libsuperderpy-%s-loading" LIBRARY_EXTENSION, LIBSUPERDERPY_GAMENAME);
void *handle = dlopen(libname, RTLD_NOW);
if (!handle) {
FatalError(&game, true, "Error while initializing loading screen %s", dlerror());
exit(1);
} else {
#define GS_LOADINGERROR FatalError(&game, true, "Error on resolving loading symbol: %s", dlerror()); exit(1);
#define GS_LOADINGERROR FatalError(&game, true, "Error on resolving loading symbol: %s", dlerror()); exit(1);
if (!(game._priv.loading.Draw = dlsym(handle, "Draw"))) { GS_LOADINGERROR; }
if (!(game._priv.loading.Load = dlsym(handle, "Load"))) { GS_LOADINGERROR; }
@ -324,7 +340,7 @@ int main(int argc, char **argv){
al_stop_timer(game._priv.timer);
// TODO: take proper game name
char libname[1024];
snprintf(libname, 1024, "libsuperderpy-%s-%s" LIBRARY_EXTENSION, LIBSUPERDERPY_GAMENAME, tmp->name);
snprintf(libname, 1024, "libsuperderpy-%s-%s" LIBRARY_EXTENSION, LIBSUPERDERPY_GAMENAME, tmp->name);
tmp->handle = dlopen(libname,RTLD_NOW);
if (!tmp->handle) {
//PrintConsole(&game, "Error while loading gamestate \"%s\": %s", tmp->name, dlerror());
@ -371,7 +387,7 @@ int main(int argc, char **argv){
// initially draw loading screen with empty bar
DrawGamestates(&game);
if (tmp->showLoading) {
(*game._priv.loading.Draw)(&game, game._priv.loading.data, loaded/(float)toLoad);
(*game._priv.loading.Draw)(&game, game._priv.loading.data, loaded/(float)toLoad);
}
DrawConsole(&game);
if (al_get_time() - t >= 1/60.0) {
@ -468,9 +484,9 @@ int main(int argc, char **argv){
al_save_bitmap(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), al_get_backbuffer(game.display));
PrintConsole(&game, "Screenshot stored in %s", al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP));
al_destroy_path(path);
} else {
EventGamestates(&game, &ev);
}
} else {
EventGamestates(&game, &ev);
}
}
}
game.shuttingdown = true;

View file

@ -38,19 +38,19 @@ struct Game {
ALLEGRO_TRANSFORM projection;
struct {
int width; /*!< Actual available width of viewport. */
int height; /*!< Actual available height of viewport. */
int width; /*!< Actual available width of viewport. */
int height; /*!< Actual available height of viewport. */
} viewport;
struct {
int fx; /*!< Effects volume. */
int music; /*!< Music volume. */
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. */
int fx; /*!< Effects volume. */
int music; /*!< Music volume. */
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;
struct {
@ -95,25 +95,8 @@ struct Game {
bool shuttingdown; /*!< If true then shut down of the game is pending. */
bool restart; /*!< If true then restart of the game is pending. */
struct {
struct {
ALLEGRO_SAMPLE *bg, *fg, *drums;
} sample;
struct {
ALLEGRO_SAMPLE_INSTANCE *bg, *fg, *drums;
} instance;
} muzyczka;
struct {
int score;
int lives;
float modificator;
struct Character *heart;
char* next;
int strike;
bool pause;
} mediator;
};
int libsuperderpy(int argc, char **argv);
#endif

View file

@ -154,18 +154,18 @@ void TM_Propagate(struct Timeline* timeline, enum TM_ActionState action) {
}
void TM_Draw(struct Timeline* timeline) {
TM_Propagate(timeline, TM_ACTIONSTATE_DRAW);
TM_Propagate(timeline, TM_ACTIONSTATE_DRAW);
}
void TM_Pause(struct Timeline* timeline) {
PrintConsole(timeline->game, "Timeline Manager[%s]: Pause.", timeline->name);
PauseTimers(timeline, true);
TM_Propagate(timeline, TM_ACTIONSTATE_PAUSE);
TM_Propagate(timeline, TM_ACTIONSTATE_PAUSE);
}
void TM_Resume(struct Timeline* timeline) {
PrintConsole(timeline->game, "Timeline Manager[%s]: Resume.", timeline->name);
TM_Propagate(timeline, TM_ACTIONSTATE_RESUME);
TM_Propagate(timeline, TM_ACTIONSTATE_RESUME);
PauseTimers(timeline, false);
}

View file

@ -64,7 +64,7 @@ void Console_Load(struct Game *game) {
game->_priv.console = NULL;
game->_priv.font_console = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"),al_get_display_height(game->display)*0.025,0 );
if (al_get_display_height(game->display)*0.025 >= 16) {
game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/PerfectDOSVGA437.ttf"),16 * ((al_get_display_height(game->display) > 1080) ? 2 : 1) ,0 );
game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/PerfectDOSVGA437.ttf"),16 * ((al_get_display_height(game->display) > 1080) ? 2 : 1) ,0 );
} else {
game->_priv.font_bsod = al_load_ttf_font(GetDataFilePath(game, "fonts/DejaVuSansMono.ttf"), al_get_display_height(game->display)*0.025,0 );
}
@ -116,19 +116,19 @@ void SetupViewport(struct Game *game) {
void DrawVerticalGradientRect(float x, float y, float w, float h, ALLEGRO_COLOR top, ALLEGRO_COLOR bottom) {
ALLEGRO_VERTEX v[] = {
{.x = x, .y = y, .z = 0, .color = top},
{.x = x + w, .y = y, .z = 0, .color = top},
{.x = x, .y = y + h, .z = 0, .color = bottom},
{.x = x + w, .y = y + h, .z = 0, .color = bottom}};
{.x = x, .y = y, .z = 0, .color = top},
{.x = x + w, .y = y, .z = 0, .color = top},
{.x = x, .y = y + h, .z = 0, .color = bottom},
{.x = x + w, .y = y + h, .z = 0, .color = bottom}};
al_draw_prim(v, NULL, NULL, 0, 4, ALLEGRO_PRIM_TRIANGLE_STRIP);
}
void DrawHorizontalGradientRect(float x, float y, float w, float h, ALLEGRO_COLOR left, ALLEGRO_COLOR right) {
ALLEGRO_VERTEX v[] = {
{.x = x, .y = y, .z = 0, .color = left},
{.x = x + w, .y = y, .z = 0, .color = right},
{.x = x, .y = y + h, .z = 0, .color = left},
{.x = x + w, .y = y + h, .z = 0, .color = right}};
{.x = x, .y = y, .z = 0, .color = left},
{.x = x + w, .y = y, .z = 0, .color = right},
{.x = x, .y = y + h, .z = 0, .color = left},
{.x = x + w, .y = y + h, .z = 0, .color = right}};
al_draw_prim(v, NULL, NULL, 0, 4, ALLEGRO_PRIM_TRIANGLE_STRIP);
}
@ -140,9 +140,9 @@ void DrawTextWithShadow(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float
/* linear filtering code written by SiegeLord */
ALLEGRO_COLOR interpolate(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac) {
return al_map_rgba_f(c1.r + frac * (c2.r - c1.r),
c1.g + frac * (c2.g - c1.g),
c1.b + frac * (c2.b - c1.b),
c1.a + frac * (c2.a - c1.a));
c1.g + frac * (c2.g - c1.g),
c1.b + frac * (c2.b - c1.b),
c1.a + frac * (c2.a - c1.a));
}
/*! \brief Scales bitmap using software linear filtering method to current target. */
@ -239,7 +239,7 @@ void FatalError(struct Game *game, bool fatal, char* format, ...) {
al_set_target_backbuffer(game->display);
al_clear_to_color(al_map_rgb(0,0,170));
char *header = LIBSUPERDERPY_GAMENAME_PRETTY;
char *header = LIBSUPERDERPY_GAMENAME_PRETTY;
al_draw_filled_rectangle(al_get_display_width(game->display)/2 - al_get_text_width(game->_priv.font_bsod, header)/2 - 4, (int)(al_get_display_height(game->display) * 0.32), 4 + al_get_display_width(game->display)/2 + al_get_text_width(game->_priv.font_bsod, header)/2, (int)(al_get_display_height(game->display) * 0.32) + al_get_font_line_height(game->_priv.font_bsod), al_map_rgb(170,170,170));
@ -321,14 +321,14 @@ char* GetDataFilePath(struct Game *game, char* filename) {
}
{
char origfn[255] = "libsuperderpy/data/";
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);
@ -514,14 +514,14 @@ void AnimateCharacter(struct Game *game, struct Character *character, float spee
character->pos_tmp = 0;
character->pos++;
}
if (character->pos>=character->spritesheet->cols*character->spritesheet->rows-character->spritesheet->blanks) {
character->pos=0;
if (character->spritesheet->kill) {
if (character->pos>=character->spritesheet->cols*character->spritesheet->rows-character->spritesheet->blanks) {
character->pos=0;
if (character->spritesheet->kill) {
character->dead = true;
} else if (character->successor) {
SelectSpritesheet(game, character, character->successor);
SelectSpritesheet(game, character, character->successor);
}
}
}
}
}
@ -541,7 +541,7 @@ void SetCharacterPosition(struct Game *game, struct Character *character, int x,
void DrawCharacter(struct Game *game, struct Character *character, ALLEGRO_COLOR tint, int flags) {
if (character->dead) return;
int spritesheetX = al_get_bitmap_width(character->bitmap)*(character->pos%character->spritesheet->cols);
int spritesheetY = al_get_bitmap_height(character->bitmap)*(character->pos/character->spritesheet->cols);
al_draw_tinted_scaled_rotated_bitmap_region(character->spritesheet->bitmap, spritesheetX, spritesheetY, al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap), tint, al_get_bitmap_width(character->bitmap)/2, al_get_bitmap_height(character->bitmap)/2, character->x + al_get_bitmap_width(character->bitmap)/2, character->y + al_get_bitmap_height(character->bitmap)/2, 1, 1, character->angle, flags);
int spritesheetX = al_get_bitmap_width(character->bitmap)*(character->pos%character->spritesheet->cols);
int spritesheetY = al_get_bitmap_height(character->bitmap)*(character->pos/character->spritesheet->cols);
al_draw_tinted_scaled_rotated_bitmap_region(character->spritesheet->bitmap, spritesheetX, spritesheetY, al_get_bitmap_width(character->bitmap), al_get_bitmap_height(character->bitmap), tint, al_get_bitmap_width(character->bitmap)/2, al_get_bitmap_height(character->bitmap)/2, character->x + al_get_bitmap_width(character->bitmap)/2, character->y + al_get_bitmap_height(character->bitmap)/2, 1, 1, character->angle, flags);
}

View file

@ -24,26 +24,12 @@
#ifdef ALLEGRO_WINDOWS
#define LIBRARY_EXTENSION ".dll"
#elseif ALLEGRO_MACOSX
#define LIBRARY_EXTENTION ".dylib"
#else
#define LIBRARY_EXTENSION ".so"
#endif
// hacks for "pixelness"
#define al_draw_bitmap(a,b,c,d) al_draw_bitmap(a,(int)(b), (int)(c), d)
#define al_draw_scaled_bitmap(a,b,c,d,e,f,g,h,i,j) al_draw_scaled_bitmap(a,b,c,d,e,(int)(f), (int)(g), (int)(h), (int)(i), j)
//#define al_draw_tinted_scaled_bitmap(a,tint,b,c,d,e,f,g,h,i,j) al_draw_tinted_scaled_bitmap(a,tint,(int)(b),(int)(c),(int)(d),(int)(e),(int)(f), (int)(g), (int)(h), (int)(i), j)
#define al_draw_rotated_bitmap(a,b,c,d,e,f,g) al_draw_rotated_bitmap(a,(int)(b),(int)(c),(int)(d),(int)(e), f, g)
#define al_draw_bitmap_region(a, b, c, d, e, f, g, h) al_draw_bitmap_region(a,(int)(b),(int)(c),(int)(d),(int)(e),(int)(f), (int)(g), h)
#define al_draw_tinted_bitmap_region(a, tint, b, c, d, e, f, g, h) al_draw_tinted_bitmap_region(a,tint,(int)(b),(int)(c),(int)(d),(int)(e),(int)(f), (int)(g), h)
#define al_draw_tinted_rotated_bitmap(a,tint,b,c,d,e,f,g) al_draw_tinted_rotated_bitmap(a,tint,(int)(b),(int)(c),(int)(d),(int)(e), f, g)
//#define al_draw_filled_rectangle
//#define al_draw_prim()
#define al_load_ttf_font(a,b,c) al_load_ttf_font(a, (int)(b / 8)*8 == 0 ? 8 : (int)(b / 8)*8, c)
#define al_draw_text(a,b,c,d,e,f) al_draw_text(a, b, (int)(c), (int)(d), e, f)
char* strdup(const char *str);
void SetupViewport(struct Game *game);
void Console_Unload(struct Game *game);
void DrawConsole(struct Game *game);
@ -129,8 +115,3 @@ 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);
// FIXME: game specific
bool GetAbstractIsItBonusLevelTimeNowFactoryProvider(struct Game *game);
void AdvanceLevel(struct Game *game, bool won);
void ShowLevelStatistics(struct Game *game);