Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake support #11

Open
wants to merge 13 commits into
base: allegro5
Choose a base branch
from
46 changes: 46 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(mayhem2)

set (CMAKE_CXX_STANDARD 11)

set(SOURCES
allegro_compatibility.cpp
mapping_joy.cpp
platform_data.cpp
utils.cpp
battle_sequence.cpp
mapping_key.cpp
player_info.cpp
vaisseau_data.cpp
collision.cpp
menuhandler.cpp
Mayhem2.cpp
player_input.cpp
vaisseau_gfx.cpp
command.cpp
#netgame.cpp
player_view.cpp
game_mgr.cpp
option.cpp
soundfx.cpp
intro_sequence.cpp
physics.cpp
ticktimer.cpp
xc.cpp
)

add_executable(mayhem2 ${SOURCES})

if (UNIX OR MSYS)
set(ALLEGRO_LIBS
allegro
allegro_primitives
allegro_audio
allegro_image
allegro_font
allegro_ttf
allegro_acodec)
target_link_libraries(mayhem2 ${ALLEGRO_LIBS})
endif()

file(COPY assets DESTINATION .)
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ CC = mingw32-gcc.exe
RES =
OBJ = allegro_compatibility.o battle_sequence.o collision.o command.o game_mgr.o intro_sequence.o player_input.o mapping_key.o mapping_joy.o menuhandler.o Mayhem2.o option.o physics.o platform_data.o player_info.o player_view.o soundfx.o ticktimer.o utils.o vaisseau_data.o vaisseau_gfx.o xc.o $(RES)
LINKOBJ = allegro_compatibility.o battle_sequence.o collision.o command.o game_mgr.o intro_sequence.o player_input.o mapping_key.o mapping_joy.o menuhandler.o Mayhem2.o option.o physics.o platform_data.o player_info.o player_view.o soundfx.o ticktimer.o utils.o vaisseau_data.o vaisseau_gfx.o xc.o $(RES)
LIBS = -L"C:\Users\mart\Documents\GitHub\mayhem-allegro5" -lallegro-5.2 -lallegro_audio-5.2 -lallegro_image-5.2 -lallegro_primitives-5.2 -lallegro_font-5.2 -lallegro_ttf-5.2 -lallegro_acodec-5.2 -mwindows
LIBS = -L"C:\Users\mart\Documents\GitHub\mayhem" -lallegro-5.2 -lallegro_audio-5.2 -lallegro_image-5.2 -lallegro_primitives-5.2 -lallegro_font-5.2 -lallegro_ttf-5.2 -lallegro_acodec-5.2 -mwindows
INCS =
BIN = "Mayhem2.exe"
CXXINCS= -I"C:\MinGW\include" -I"C:\Users\mart\Documents\GitHub\mayhem-allegro5" -O0 -g -Werror -Wno-write-strings -Wno-deprecated-declarations
CXXINCS= -I"C:\MinGW\include" -I"C:\Users\mart\Documents\GitHub\mayhem" -O0 -g -Werror -Wno-write-strings -Wno-deprecated-declarations
INCS= -O0 -g -Werror -Wno-write-strings -Wno-deprecated-declarations
CXXFLAGS = -std=c++11 $(CXXINCS)
CFLAGS = $(INCS)
Expand Down
Binary file modified Mayhem2.exe
Binary file not shown.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,52 @@ You maybe presented with message saying that the application was stopped from st

##Compile

Mayhem2 is compiled with [mingw](http://www.mingw.org/), use mingw32-make to build, paths in the MakeFile may need to be changed.
### Windows using MSYS2

Download and install [MSYS2](http://www.msys2.github.io). Open MinGW 64-bit or MinGW 32-bit shell depending on your architechture.

Install dependencies:

For mingw64 using i686:
```
pacman -S git make mingw-w64-i686-allegro mingw-w64-i686-make mingw-w64-i686-cmake mingw-w64-i686-gcc mingw-w64-i686-openal mingw-w64-i686-dumb mingw-w64-i686-freetype mingw-w64-i686-libvorbis mingw-w64-i686-flac mingw-w64-i686-libjpeg
```

For mingw64 using x86_64:
```
pacman -S git make mingw-w64-x86_64-allegro mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc mingw-w64-x86_64-openal mingw-w64-x86_64-dumb mingw-w64-x86_64-freetype mingw-w64-x86_64-libvorbis mingw-w64-x86_64-flac mingw-w64-x86_64-libjpeg
```

Clone repository, compile and run:
```
git clone https://github.com/martinohanlon/mayhem.git
cd mayhem
mkdir build
cd build
cmake -G "MSYS Makefiles" ..
make
./mayhem2.exe
```

### Ubuntu

Install dependencies:

```
sudo apt-get install liballegro5-dev git cmake
```

Clone repository, compile and run:

```
git clone https://github.com/martinohanlon/mayhem.git
cd mayhem
mkdir build
cd build
cmake ..
make
./mayhem2
```

##Version history
* beta - compiles, runs, ongoing mods
Expand Down
34 changes: 12 additions & 22 deletions game_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#define CHECKFPS

#define SHOWDEBUG
//#define SHOWDEBUG

#define FULLSCREEN

Expand All @@ -26,11 +26,6 @@
#define GFXOPENARG ALLEGRO_WINDOWED
#endif

/* write to a double buffer before the screen
On x86 / windows a double buffer slow performance
On Raspberry Pi, no double buffer results in screen flicker*/
//#define DOUBLEBUFFER

// initialise static members
int GameManager::display_height;
int GameManager::display_width;
Expand Down Expand Up @@ -133,7 +128,7 @@ void GameManager::ChangeScreenRes(int width, int height) {
}

void GameManager::Shutdown() {
al_destroy_display(display);
al_destroy_display(GameManager::display);

for (int i = 0; i < MAX_NUM_CONTROLLERS; i++)
delete GameManager::joysticks[i];
Expand All @@ -146,15 +141,15 @@ double tick_fps = 0.0;
#ifdef CHECKFPS
void draw_fps(ALLEGRO_BITMAP *screen_buffer) {
double new_time = al_get_time();
char fps[100];
char info[100];
#ifdef SHOWDEBUG
sprintf(fps, "goal fps:%d, draw fps:%.1f, tick ms:%.1f, tick fps: %.1f, debug time %.1f",
sprintf(info, "goal fps:%d, draw fps:%.1f, tick ms:%.1f, tick fps: %.1f, debug time %.1f",
GameManager::FPS, 1.0 / (new_time - old_time), 1000.0 * tick_time,
tick_fps, 1000 * GameManager::debug_time);
#else
sprintf(fps, "fps:%.1f", 1.0 / (new_time - old_time));
sprintf(info, "fps:%.1f", tick_fps);
#endif
textout(screen_buffer, GameManager::font, fps, 105, 5,
textout(screen_buffer, GameManager::font, info, 105, 5,
al_map_rgb(200, 200, 200));
char reso[100];
sprintf(reso, "%ix%i", GameManager::display_width,
Expand Down Expand Up @@ -182,12 +177,8 @@ void GameManager::Run(GameSequence *aSeq) {
al_register_event_source(event_queue, xc_get_event_source());

ALLEGRO_BITMAP *screen_buffer;
#ifdef DOUBLEBUFFER
screen_buffer =
al_create_bitmap(GameManager::display_width, GameManager::display_height);
#else
screen_buffer = al_get_backbuffer(GameManager::display);
#endif

al_set_target_bitmap(screen_buffer);
al_clear_to_color(al_map_rgb(0, 0, 0));

Expand Down Expand Up @@ -253,6 +244,7 @@ void GameManager::Run(GameSequence *aSeq) {
tick_fps = 1.0 / (now - last_time);
last_time = now;
tick_time = al_get_time() - now;

}

// joy debug
Expand All @@ -263,11 +255,10 @@ void GameManager::Run(GameSequence *aSeq) {
*/

draw_fps(screen_buffer);
#ifdef DOUBLEBUFFER
al_set_target_bitmap(al_get_backbuffer(GameManager::display));
al_draw_bitmap(screen_buffer, 0, 0, 0);
#endif
al_flip_display();

if (do_tick) {
al_flip_display();
}

if (doexit) {
if (seq_next != nullptr && seq_next->ReturnScreen() != aSeq)
Expand All @@ -283,5 +274,4 @@ void GameManager::Run(GameSequence *aSeq) {
}

al_destroy_event_queue(event_queue);
al_destroy_bitmap(screen_buffer);
}
2 changes: 2 additions & 0 deletions intro_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ IntroSequence::IntroSequence(GameSequence *previous, float zoom,
IntroSequence::~IntroSequence() {
if (iLogo)
al_destroy_bitmap(iLogo);
if (iDoublebuffer)
al_destroy_bitmap(iDoublebuffer);
}

GameSequence *IntroSequence::doTick(ALLEGRO_BITMAP *screen_buffer,
Expand Down
4 changes: 2 additions & 2 deletions intro_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class IntroSequence : public GameSequence {
double iZoom;
double iZoomMax;
double iZoomSpeed;
ALLEGRO_BITMAP *iLogo;
ALLEGRO_BITMAP *iDoublebuffer;
ALLEGRO_BITMAP *iLogo = nullptr;
ALLEGRO_BITMAP *iDoublebuffer = nullptr;

int width;
int height;
Expand Down