Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak authored Oct 28, 2023
0 parents commit 0de65a4
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 0 deletions.
166 changes: 166 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Build Github Action, to run a test build on all targets
# (Linux, Blit, MacOS, Visual Studio) when the project is checked in.
#
# Thanks in large part to the phenomenal examples of DaftFreak.

name: Build

on:
push:
branches:
- '**' # only run on branches
pull_request:
release:
types: [published]

env:
BUILD_TYPE: Release
EM_VERSION: 2.0.18 # Emscripten version
EM_CACHE_FOLDER: 'emsdk-cache' # Cache for Emscripten libs

jobs:

build:

name: ${{matrix.name}}
strategy:
matrix:
include:
- os: ubuntu-20.04
name: Linux
release-suffix: LIN64
cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE/32blit-sdk
apt-packages: libsdl2-dev libsdl2-image-dev libsdl2-net-dev python3-setuptools

- os: ubuntu-20.04
name: STM32
release-suffix: STM32
cmake-args: -DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/32blit-sdk/32blit.toolchain
apt-packages: gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib python3-setuptools

- os: ubuntu-20.04
name: Emscripten
release-suffix: WEB
cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE/32blit-sdk
cmake-prefix: emcmake
apt-packages: python3-setuptools

- os: macos-latest
name: macOS
release-suffix: MACOS
cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE/32blit-sdk
brew-packages: sdl2 sdl2_image sdl2_net

- os: windows-latest
name: Visual Studio
release-suffix: WIN64
cmake-args: -D32BLIT_DIR=$GITHUB_WORKSPACE/32blit-sdk

runs-on: ${{matrix.os}}

env:
RELEASE_FILE: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.release-suffix}}

steps:
# Check out the main repo
- name: Checkout
uses: actions/checkout@v3
with:
path: main

# Check out the 32Blit API we build against
- name: Checkout 32Blit API
uses: actions/checkout@v3
with:
repository: 32blit/32blit-sdk
path: 32blit-sdk

# Linux dependencies
- name: Install Linux deps
if: runner.os == 'Linux'
run: |
sudo apt update && sudo apt install ${{matrix.apt-packages}}
pip3 install 32blit
# MacOS dependencies
- name: Install macOS deps
if: runner.os == 'macOS'
run: |
brew install ${{matrix.brew-packages}}
python3 -m pip install 32blit
# Windows dependencies
- name: Install Windows deps
if: runner.os == 'Windows'
shell: bash
run: |
python -m pip install 32blit
# Emscripten SDK setup
- name: Setup Emscripten cache
if: matrix.name == 'Emscripten'
id: cache-system-libraries
uses: actions/cache@v3
with:
path: ${{env.EM_CACHE_FOLDER}}
key: ${{env.EM_VERSION}}-${{runner.os}}

- name: Setup Emscripten
if: matrix.name == 'Emscripten'
uses: mymindstorm/setup-emsdk@v12
with:
version: ${{env.EM_VERSION}}
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}

- name: Pre-build Emscripten ports
if: matrix.name == 'Emscripten'
run: embuilder.py build sdl2 sdl2-image-jpg sdl2-net

# Set up the cmake build environment
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/main/build

# Ask cmake to build the makefiles
- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/main/build
run: ${{matrix.cmake-prefix}} cmake $GITHUB_WORKSPACE/main -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCPACK_PACKAGE_FILE_NAME=${{env.RELEASE_FILE}} ${{matrix.cmake-args}}

# And then run the build itself
- name: Build
working-directory: ${{runner.workspace}}/main/build
shell: bash
run: |
cmake --build . --config $BUILD_TYPE -j 2
# When it's a release, generate tar/zip files of the build
- name: Package Release
if: github.event_name == 'release' && matrix.release-suffix != ''
shell: bash
working-directory: ${{runner.workspace}}/main/build
run: |
cmake --build . --config $BUILD_TYPE --target package
# Push the tar file to the release
- name: Upload tar
if: github.event_name == 'release' && matrix.release-suffix != ''
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
asset_path: ${{runner.workspace}}/main/build/${{env.RELEASE_FILE}}.tar.gz
upload_url: ${{github.event.release.upload_url}}
asset_name: ${{env.RELEASE_FILE}}.tar.gz
asset_content_type: application/octet-stream

# Push the zip file to the release
- name: Upload zip
if: github.event_name == 'release' && matrix.release-suffix != ''
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
asset_path: ${{runner.workspace}}/main/build/${{env.RELEASE_FILE}}.zip
upload_url: ${{github.event.release.upload_url}}
asset_name: ${{env.RELEASE_FILE}}.zip
asset_content_type: application/zip
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
build.*/
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Basic parameters; check that these match your project / environment
cmake_minimum_required(VERSION 3.9)

# Replace "game" with a name for your project (this is used the name of the output)
project(game)

# Add your sources here (adding headers is optional, but helps some CMake generators)
set(PROJECT_SOURCE game.cpp game.hpp)

# ... and any other files you want in the release here
set(PROJECT_DISTRIBS LICENSE README.md)

# Build configuration; approach this with caution!
if(MSVC)
add_compile_options("/W4" "/wd4244" "/wd4324" "/wd4458" "/wd4100")
else()
add_compile_options("-Wall" "-Wextra" "-Wdouble-promotion" "-Wno-unused-parameter")
endif()

find_package (32BLIT CONFIG REQUIRED PATHS ../32blit-sdk $ENV{PATH_32BLIT_SDK})

blit_executable (${PROJECT_NAME} ${PROJECT_SOURCE})
blit_assets_yaml (${PROJECT_NAME} assets.yml)
blit_metadata (${PROJECT_NAME} metadata.yml)
add_custom_target (flash DEPENDS ${PROJECT_NAME}.flash)

# setup release packages
install (FILES ${PROJECT_DISTRIBS} DESTINATION .)
set (CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set (CPACK_GENERATOR "ZIP" "TGZ")
include (CPack)
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 <insert your name>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 32Blit Boilerplate

![Build](https://github.com/32blit/32blit-boilerplate/workflows/Build/badge.svg)

This is a basic template for starting 32blit projects. It shows the basic
code layout and asset pipeline, hopefully giving folk a starting point for
any new projects.

It's based on the original `template` project from the
[32Blit SDK](https://github.com/32blit/32blit-sdk), with added asset
handling, and some tidying up to fit in with how I do things.

## Usage

[Use this template](https://github.com/32blit/32blit-boilerplate/generate) to
generate your own project.

* Edit the CMakeList.txt file to set the name of your project
* Edit the metadata.yml file to set the information for your project
* Edit the LICENSE file to set your name on the license
* Write lots of super cool code!

You should then be able to follow the usual build instructions.

For local builds this is:
```
mkdir build
cd build
cmake -D32BLIT_DIR=/path/to/32blit-sdk/ ..
```

Platform/Editor specific insctuctions [can be found in the main 32blit repo](https://github.com/32blit/32blit-sdk#you-will-need)
(For Visual Studio, you should follow the "Option 2" instructions, as the boilerplate does not contain a solution file)
8 changes: 8 additions & 0 deletions assets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# All these assets will be created in assets.cpp, which CMake will
# link automagically.
# References can be picked up by including assets.hpp

assets.cpp:
assets/no-image.png:
name: asset_no_image

Binary file added assets/no-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/no-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "game.hpp"

using namespace blit;

///////////////////////////////////////////////////////////////////////////
//
// init()
//
// setup your game here
//
void init() {
set_screen_mode(ScreenMode::hires);
}

///////////////////////////////////////////////////////////////////////////
//
// render(time)
//
// This function is called to perform rendering of the game. time is the
// amount if milliseconds elapsed since the start of your game
//
void render(uint32_t time) {

// clear the screen -- screen is a reference to the frame buffer and can be used to draw all things with the 32blit
screen.clear();

// draw some text at the top of the screen
screen.alpha = 255;
screen.mask = nullptr;
screen.pen = Pen(255, 255, 255);
screen.rectangle(Rect(0, 0, 320, 14));
screen.pen = Pen(0, 0, 0);
screen.text("Hello 32blit!", minimal_font, Point(5, 4));
}

///////////////////////////////////////////////////////////////////////////
//
// update(time)
//
// This is called to update your game state. time is the
// amount if milliseconds elapsed since the start of your game
//
void update(uint32_t time) {
}
1 change: 1 addition & 0 deletions game.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "32blit.hpp"
10 changes: 10 additions & 0 deletions metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: game title
description: game description
author: you
splash:
file: assets/no-image.png
icon:
file: assets/no-icon.png
version: v0.0.1
category: game # game, demo, utility, ...
url: https://github.com/32blit/32blit-boilerplate

0 comments on commit 0de65a4

Please sign in to comment.