Git Product home page Git Product logo

apg's Introduction

APG

A simple framework for writing primarily 2D games using Modern C++ (C++14), OpenGL, SDL2 and Tiled maps.

The design is heavily inspired by LibGDX.

What's Included

  • COMING SOON: emscripten support (WASM)
  • An easy entry-point with clearly defined functions to implement to make your own cross platform game.
  • A SpriteBatch class similar to the one in LibGDX which aims to minimise draw calls for 2D sprites.
  • An SDL2 input manager for the keyboard supporting "isPressed" and "isJustPressed" as required.
  • An SDL2_mixer audio manager for playing a channel of music and multiple channels of sound effects.
  • SDL2_net/Native Socket wrappers for networking including a modified version of ByteBufferCpp for handling data.
  • The ability to compile without SDL/GL at all, allowing you to use the rest of the library freely and reduce dependencies/library size if you don't need some components (ideal for, for example, servers which share some data structures with the client).
  • C++14 unique_ptr wrappers around common SDL2 structs (SDL_Surface, SDL_Window, etc) which let you stop having to worry about cleanup.

How To Use

Cloning

Most of APG's dependencies are vendored using git submodules, so just cloning the repository won't be enough to get all the code. You can do something like the following:

# Clone APG as usual, and cd into the directory
g submodule update --init --recursive  # this will fetch all the dependencies at the correct commit

Dependencies for Build

Generally, you'll need a C++ compiler, zlib, OpenGL and the SDL2 libraries (SDL2, SDL2_image, SDL2_mixer, SDL2_net, SDL2_ttf) installed and nothing else.

WASM

Install emscripten as shown in the Wiki.

Activate emscripten (source ./emsdk_env.sh) then run:

python $EMSCRIPTEN/embuilder.py build ALL

to build SDL2 and OpenGL.

Don't forget to use emcmake cmake .. instead of the regular cmake command.

macOS

You'll need Homebrew installed along with git (likely through the XCode command line tools).

brew install cmake sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf glew

Linux Deb-based (Debian, Ubuntu, etc.)

You should be able to install the dependencies you need through your package manager.

sudo apt install git cmake  # basic build dependencies; you'll also need a compiler (something like build-essential)
# Now install library dependencies which are not vendored
sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-net-dev libsdl2-ttf-dev libglew-dev zlib1g-dev

Windows

Coming soon!

Building

Clone the repository and navigate to the folder, then:

mkdir build && cd build
cmake ..
make -jN # where N is the number of cores you have

If you don't care about the tests you can use cmake -DEXCLUDE_TESTS=ON. By default, all tests are built as well as the libraries.

Usage Notes - Logging

The library depends on easylogging++ which is included by source. To use the library, you simply need to: #include "easylogging++.h" in your files. Important: In your file which contains your main function you must include the line INITIALIZE_EASYLOGGINGPP directly after you include the function.

It's also recommended that you use the function START_EASYLOGGINGPP(argc, argv); on your first line of your main function.

For more information on easylogging++, visit the GitHub repository.

apg's People

Contributors

sgtcodfish avatar

Watchers

 avatar  avatar  avatar

apg's Issues

Use CRTP for Game class

This will be a breaking API change (similar to the Tmxrenderer change) but will ensure that we don't pay a virtual-function price for every frame.

Create a thread-safe resource manager

Currently there are too many concepts of ownership, split across different classes and resources. This could be centralised, for the resources where that makes sense - texture IDs, sound resource IDs, etc.

Force SDL/GL/Logger init outside of SDLGame

Currently SDLGame handles the "magic" of initialising SDL (and the various SDL submodules), creating a window, creating a GL context and initialising the APG logger. This has two effects:

  • Nothing with APG can realistically be done before these things are initialised.
  • This forces a recursive "unique_ptr" bloat across the whole codebase, which makes initialisation much more complicated, adds overhead and exposes us to various nullptr bugs which wouldn't happen if the classes we were creating were just members.

By moving SDLGame's constructor logic out into a separate class which owns the SDL/GL context, we add an extra initialisation step before getting a working screen, but the gains outweigh the losses.

It might be possible to avoid a breaking API change by creating an entirely new game class, perhaps using CRTP... but it might be cleaner, given that APG is not widely used, to just break SDLGame.

Test Builds on Different Browsers / OSes

Both WASM builds and native builds

Windows

  • Native
  • Edge
  • Chrome
  • Firefox

MacOS

  • Native
  • Safari
  • Chrome
  • Firefox

Linux (Debian)

  • Native
  • Chromium
  • Firefox

Linux (Ubuntu)

  • Native
  • Chromium
  • Firefox

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.