emilib
|
This is a loose collection of C++14 libraries I tend to reuse between different (mostly game-related) projects.
They are meant mostly for me (Emil Ernerfeldt), but if you find them useful, have at it.
Their only dependencies are either system dependencies (pthread etc) and Loguru. gl_lib also depends on OpenGL and GLEW. The libraries does not depend on each other (with an exception for ShaderMngr).
They all work on OSX and iOS and probably Linux. Some may work elsewhere.
This software is in the public domain. Where that dedication is not recognized, you are granted a perpetual, irrevocable license to copy and modify this file as you see fit.
Documentation can be found at https://emilk.github.io/emilib/html/index.html.
Most libraries in emilib are stand-alone, so you can, for instance, use the coroutine library without having to compile anything but that.
Some are header-only, but most come with a .cpp
file too.
To use a single library, just #include
the header, and if there is a .cpp
(or .mm
in case of iOS/OSX) either compile and link that, or just include that too, e.g.:
#include <emilib/coroutine.hpp> #include <emilib/coroutine.cpp> // Do this only in one of your .cpp files
You can also make use of unity_build.cpp
to compile all of emilib all at once. To use the iOS/OSX specific libraries, use unity_build.mm
instead.
You also need to compile Loguru. Luckily, loguru.hpp
is included in this repo, and to compile it you just need to add the following to one of your .cpp files:
#define LOGURU_IMPLEMENTATION #include <loguru.hpp>
Make sure you compile with -std=c++11 -lpthread -ldl
This file (README.md) contains an overview of each library. Read the header for each library to learn more.
There is a very limited set of examples in the examples/
folder.
There is a very limited set of tests in the tests/
folder.
This is a "fake coroutine" class which implements a cooperative thread and methods for passing execution between the outer and inner thread.
This is really nice for handling things that you would normally use a state machine for. Perfect for games where you might want to have a scripted event, a dialogue or something else running in its own thread, but not at the same time as the main game logic thread.
This library allows you to watch for changes in a directory, e.g. new files, deleted files or changes in existing files. This is great for doing automatic hot-reloading of things like textures, shaders, etc.
POSIX systems only.
Library for dual numbers. Can be used for numerical stable differentiation. Works inside of Eigen.
Contains functions for easily reading/writing files, getting file size and modified time, listing all files in a directory, etc.
It also contains functions for working with file paths.
HashCache wraps a value and memoizes the hash of that value. Can speed up hash sets and maps by a lot.
Cache-friendly hash map/set with open addressing, linear probing and power-of-two capacity. Acts mostly like std::unordered_map/std::unordered_set
except for:
Simple integer range, allowing you to replace for (size_t i = 0; i < limit; ++i)
with for (auto i : irange(limit))
. It also provides a Range
class which represent an integer range in a half-closed interval [begin, end) as well as the following functions:
Simple O(N) map/set with small overhead and great performance for small N.
Loader for MagicaVoxel models.
Short, simple marching squares implementation.
Simple wrapper around memory mapping with RAII.
Track movement of some data, e.g. to estimate velocity from recent movement. For instance, you can use this to track a finger flicking something on a touch-screen to calculate the final velocity when the finger is released.
Fast mutex for multiple-readers, single-writer scenarios written in pure C++11.
Adds the macro SCOPE_EXIT
for running some code at the end of the scope (or when a function returns, etc). Example:
Stupid simple thread-safe string interning.
Minimalistic string formating library. Provides two functions: strprintf
and vstrprintf
that act like printf
and vprintf
respectively, but return the formated text as a std::string
instead of printing it.
Dump a tga image to disk.
A simple thread pool.
Monotonic wall time chronometer.
Adds for_each_tuple
for iterating over a std::tuple
and also overloads std::hash
for std::tuple
.
Really basic utf8 operations.
Parse WAVE (.wav) sound files.
Wrap lines of text to fit within a given width.
Stream mp3 music on OSX and iOS.
Device information like screen size and orientation.
Loading of compressed .pvr textures. Depends on gl_lib.
Pretty multi-line Unicode text rendering for OSX and iOS. It lets you select font, size, alignment, wrapping size and allows you to colorize and italicize sub-ranges of the text.
It draws the text to memory, so it is up to you to display it (e.g. upload it to a texture).
Code for loading, playing and positioning sounds using OpenAL.
Depends on OpenAL and other parts of emilib.
Include al_lib.hpp
and link with al_lib.cpp
. You can also make use of al_lib_fwd.hpp
to bring in forward declarations for most things in al_lib.
Code for doing simple things in OpenGL and/or OpenGL ES (GLES). It has classes and methods for dealing with:
Depends on OpenGL and GLEW.
Include gl_lib.hpp
and link with gl_lib.cpp
. You can also make use of gl_lib_fwd.hpp
to bring in forward declarations for most things in gl_lib. To do OpenGL calls you can include gl_lib_opengl.hpp
(which just includes the correct OpenGL and/or glew headers for you system).
Helper functions for creating an SDL2 OpenGL window.
Provides bindings between my gl_lib
and the wonderful Dear Imgui GUI library. Can be used alone or together with emilib/imgui_sdl.hpp/.cpp
.
Helpers for working with the wonderful Dear Imgui GUI library.
Bindings between SDL2 and the wonderful Dear Imgui GUI library. Can be used alone or together with emilib/imgui_gl_lib.hpp/.cpp
..
This is NOT a stand-alone library, but depends on other parts of emilib as well as loguru and configuru. ShaderMngr's job is to encapsulate loading, memoization and reloading of shader files. In particular, ShaderMngr can detect changes in .shader files and automatically reload (hot-reloading) them.
This is NOT a stand-alone library, but depends on other parts of emilib as well as loguru. TextureMngr's job is to encapsulate loading, memoization and reloading of texture files. In particular, TextureMngr can detect changes in image files and automatically reload (hot-reloading) them.
This is not part of emilib, but a copy of https://github.com/emilk/configuru here only for convenience.
This is not part of emilib, but a copy of https://github.com/emilk/loguru here for convenience, and as a dependency for most other libraries.