Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohkdesgds committed Sep 9, 2024
0 parents commit b7bfe1b
Show file tree
Hide file tree
Showing 5 changed files with 727 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build test
# Based on Allegro's pipeline

#on: [push, pull_request]

jobs:
windows_test:
name: Windows (MSYS2) tests
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 1
- uses: msys2/setup-msys2@main
- name: Setup
shell: msys2 {0}
run: |
pacman --noconfirm -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake make mingw-w64-x86_64-physfs mingw-w64-x86_64-freetype mingw-w64-x86_64-libvorbis mingw-w64-x86_64-flac mingw-w64-x86_64-dumb mingw-w64-x86_64-libtheora mingw-w64-x86_64-libjpeg-turbo mingw-w64-x86_64-opusfile mingw-w64-x86_64-enet mingw-w64-x86_64-libwebp
mkdir build
- name: Configure
shell: msys2 {0}
run: |
cd build
cmake .. -G"MSYS Makefiles"
- name: Build
shell: msys2 {0}
run: |
cd build
make -j4
- name: Save build folder as artifact
uses: actions/upload-artifact@main
with:
name: build_folder_windows
path: ${{ runner.workspace }}/build
ubuntu_test:
name: Ubuntu tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 1
- name: Setup
run: |
sudo apt-get update
sudo apt-get install -y xvfb libvorbis-dev libtheora-dev libwebp-dev libphysfs-dev libopusfile-dev libdumb1-dev libflac-dev libpulse-dev libgtk-3-dev pandoc libcurl4-nss-dev libenet-dev pulseaudio libasound2-dev libopenal-dev libgl1-mesa-dev libglu-dev;
mkdir build
cd build
- name: Configure
run: |
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWANT_SHADERS_GL=on -DWANT_CURL_EXAMPLE=on
- name: Build
run: |
cd build
make -j4
- name: Save build folder as artifact
uses: actions/upload-artifact@main
with:
name: build_folder_ubuntu
path: ${{ runner.workspace }}/build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vs/
out/
36 changes: 36 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.5)
project (AllegroProject)
include(FetchContent)

FetchContent_Declare(
allegro5
GIT_REPOSITORY https://github.com/liballeg/allegro5.git
GIT_TAG 5.2.9.1
)
FetchContent_GetProperties(allegro5)
if(NOT allegro5_POPULATED)
FetchContent_Populate(allegro5)
if (MSVC)
set(SHARED ON)
else()
set(SHARED OFF)
endif()
set(WANT_TESTS OFF)
set(WANT_EXAMPLES OFF)
set(WANT_DEMO OFF)
add_subdirectory(${allegro5_SOURCE_DIR} ${allegro5_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

add_executable(al_example src/main.c)
target_include_directories(al_example PUBLIC ${allegro5_SOURCE_DIR}/include)
target_include_directories(al_example PUBLIC ${allegro5_BINARY_DIR}/include)
target_link_libraries(al_example LINK_PUBLIC allegro allegro_main allegro_font allegro_primitives)

# These include files are typically copied into the correct places via allegro's install
# target, but we do it manually.
file(COPY ${allegro5_SOURCE_DIR}/addons/font/allegro5/allegro_font.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5
)
file(COPY ${allegro5_SOURCE_DIR}/addons/primitives/allegro5/allegro_primitives.h
DESTINATION ${allegro5_SOURCE_DIR}/include/allegro5
)
129 changes: 129 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>

#ifdef ALLEGRO_ANDROID
#include "allegro5/allegro_android.h"
#endif

void init_platform_specific(void);
void abort_example(char const *format, ...);
void open_log(void);
void open_log_monospace(void);
void close_log(bool wait_for_user);
void log_printf(char const *format, ...);

void init_platform_specific(void)
{
#ifdef ALLEGRO_ANDROID
al_install_touch_input();
al_android_set_apk_file_interface();
#endif
}

#ifdef ALLEGRO_POPUP_EXAMPLES

#include "allegro5/allegro_native_dialog.h"

ALLEGRO_TEXTLOG *textlog = NULL;

void abort_example(char const *format, ...)
{
char str[1024];
va_list args;
ALLEGRO_DISPLAY *display;

va_start(args, format);
vsnprintf(str, sizeof str, format, args);
va_end(args);

if (al_init_native_dialog_addon()) {
display = al_is_system_installed() ? al_get_current_display() : NULL;
al_show_native_message_box(display, "Error", "Cannot run example", str, NULL, 0);
}
else {
fprintf(stderr, "%s", str);
}
exit(1);
}

void open_log(void)
{
if (al_init_native_dialog_addon()) {
textlog = al_open_native_text_log("Log", 0);
}
}

void open_log_monospace(void)
{
if (al_init_native_dialog_addon()) {
textlog = al_open_native_text_log("Log", ALLEGRO_TEXTLOG_MONOSPACE);
}
}

void close_log(bool wait_for_user)
{
if (textlog && wait_for_user) {
ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
al_register_event_source(queue, al_get_native_text_log_event_source(
textlog));
al_wait_for_event(queue, NULL);
al_destroy_event_queue(queue);
}

al_close_native_text_log(textlog);
textlog = NULL;
}

void log_printf(char const *format, ...)
{
char str[1024];
va_list args;
va_start(args, format);
vsnprintf(str, sizeof str, format, args);
va_end(args);
al_append_native_text_log(textlog, "%s", str);
}

#else

void abort_example(char const *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
exit(1);
}

void open_log(void)
{
}

void open_log_monospace(void)
{
}

void close_log(bool wait_for_user)
{
(void)wait_for_user;
}

void log_printf(char const *format, ...)
{
va_list args;
va_start(args, format);
#ifdef ALLEGRO_ANDROID
char x[1024];
vsnprintf(x, sizeof x, format, args);
ALLEGRO_TRACE_CHANNEL_LEVEL("log", 1)("%s", x);
#else
vprintf(format, args);
#endif
va_end(args);
}

#endif

/* vim: set sts=3 sw=3 et: */
Loading

0 comments on commit b7bfe1b

Please sign in to comment.