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

Fix CI and Windows build #42

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,44 @@ name: CI
on: [push, pull_request]

jobs:
build-linux-gcc:
runs-on: ubuntu-18.04
build-linux:
runs-on: ubuntu-latest
strategy:
matrix:
compiler: [gcc, clang]
penger: ["", "PENGER=1"]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install -qq libsdl2-dev
- name: build sowon
run: |
make
make ${{ matrix.penger }}
env:
CC: gcc
build-linux-clang:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install -qq libsdl2-dev
- name: build sowon
run: |
make
env:
CC: clang
CC: ${{ matrix.compiler }}
build-macos:
runs-on: macOS-latest
strategy:
matrix:
penger: ["", "PENGER=1"]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: install dependencies
run: brew install sdl2 pkg-config
- name: build sowon
run: |
make
make ${{ matrix.penger }}
env:
CC: clang
build-windows-msvc:
runs-on: windows-2019
runs-on: windows-latest
strategy:
matrix:
penger: ["", "PENGER"]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
# this runs vcvarsall for us, so we get the MSVC toolchain in PATH.
- uses: seanmiddleditch/gha-setup-vsdevenv@master
- name: download sdl2
Expand All @@ -53,19 +50,22 @@ jobs:
- name: build sowon
shell: cmd
run: |
./build_msvc.bat
# TODO: FreeBSD build is broken
# build-freebsd:
# runs-on: macos-latest
# name: FreeBSD LLVM Clang build
# steps:
# - uses: actions/checkout@v2
# - name: Build on FreeBSD
# id: build
# uses: vmactions/[email protected]
# with:
# usesh: true
# prepare: pkg install -y sdl2 pkgconf
# run: |
# freebsd-version
# make
build_msvc.bat ${{ matrix.penger }}

build-freebsd:
runs-on: ubuntu-latest
name: FreeBSD LLVM Clang build
strategy:
matrix:
penger: ["", "PENGER=1"]
steps:
- uses: actions/checkout@v4
- name: Build on FreeBSD
id: build
uses: vmactions/freebsd-vm@v1
with:
usesh: true
prepare: pkg install -y sdl2 pkgconf
run: |
freebsd-version
make ${{ matrix.penger }}
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
COMMON_CFLAGS= -Wall -Wextra -std=c99 -pedantic
CFLAGS+= `pkg-config --cflags sdl2` $(COMMON_CFLAGS)
CFLAGS+= `pkg-config --cflags sdl2` $(if $(PENGER),-DPENGER) $(COMMON_CFLAGS)
COMMON_LIBS= -lm
LIBS= `pkg-config --libs sdl2` $(COMMON_LIBS)
PREFIX?= /usr/local
Expand All @@ -8,7 +8,7 @@ INSTALL?= install
.PHONY: all
all: Makefile sowon man

sowon: main.c digits.h penger_walk_sheet.h
sowon: main.c digits.h $(if $(PENGER),penger_walk_sheet.h)
$(CC) $(CFLAGS) -o sowon main.c $(LIBS)

digits.h: png2c digits.png
Expand Down
9 changes: 7 additions & 2 deletions build_msvc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ rem launch this from msvc-enabled console
set CXXFLAGS=/std:c++17 /O2 /FC /W4 /WX /nologo
set INCLUDES=/I SDL2\include
set LIBS=SDL2\lib\x64\SDL2.lib SDL2\lib\x64\SDL2main.lib Shell32.lib

if "%1"=="PENGER" (
set CXXFLAGS=%CXXFLAGS% /DPENGER
)
cl.exe %CXXFLAGS% /Fepng2c png2c.c /link Shell32.lib -SUBSYSTEM:console
png2c.exe digits.png > digits.h
png2c.exe digits.png digits > digits.h
if "%1"=="PENGER" (
png2c.exe penger_walk_sheet.png penger > penger_walk_sheet.h
)
cl.exe %CXXFLAGS% %INCLUDES% /Fesowon main.c /link %LIBS% -SUBSYSTEM:windows
10 changes: 7 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <string.h>
#include <time.h>

#ifdef _WIN32
#include <SDL.h>
#else
#include <SDL2/SDL.h>
#endif

#include "./digits.h"

Expand Down Expand Up @@ -118,7 +122,7 @@ void render_penger_at(SDL_Renderer *renderer, SDL_Texture *penger, float time, i

int step = (int)(time*sps)%(60*sps); //step index [0,60*sps-1]

float progress = step/(60.0*sps); // [0,1]
float progress = step/(60.0f*sps); // [0,1]

int frame_index = step%2;

Expand All @@ -134,8 +138,8 @@ void render_penger_at(SDL_Renderer *renderer, SDL_Texture *penger, float time, i
};

SDL_Rect dst_rect = {
floorf((float)penger_walk_width * progress - penger_drawn_width),
window_height - (penger_height / PENGER_SCALE),
(int) (penger_walk_width * progress - penger_drawn_width),
(int) (window_height - (penger_height / PENGER_SCALE)),
(int) (penger_width / 2) / PENGER_SCALE,
(int) penger_height / PENGER_SCALE
};
Expand Down