• Stars
    star
    4,259
  • Rank 10,127 (Top 0.2 %)
  • Language
    C
  • Created over 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games

cute_headers

Various single-file cross-platform C/C++ headers implementing self-contained libraries.

library description latest version language(s)
cute_c2 2D collision detection routines on primitives, boolean results and/or manifold generation, shape cast/sweep test, raycasts 1.10 C/C++
cute_net Networking library for games requiring an optional reliability layer over UDP with a baked in security scheme 1.03 C/C++
cute_tiled Very efficient loader for Tiled maps exported to JSON format 1.07 C/C++
cute_aseprite Parses .ase/.aseprite files into a compact and convenient struct collection 1.02 C/C++
cute_sound Load/play/loop (with plugin)/pan WAV + OGG (stb_vorbis wrapper for OGG) in mono/stereo, high performance custom mixer, music + crossfade support 2.04 C/C++
cute_math Professional level 3D vector math via SSE intrinsics 1.02 C++
cute_png load/save PNG, texture atlas compiler, DEFLATE compliant decompressor 1.05 C/C++
cute_spritebatch Run-time 2d sprite batcher. Builds atlases on-the-fly in-memory. Useful to implement a sprite batcher for any purpose (like 2D games) for high-performance rendering, without the need to precompile texture atlases on-disk. 1.04 C/C++
cute_sync Collection of practical synchronization primitives, including read/write lock and threadpool/task system 1.01 C/C++

How to Use

Generally these headers do not have dependencies and are intended to be included directly into your source (check each header for specific documentation at the top of the file). Each header has a LIBNAME_IMPLEMENTATION symbol; add this to a single translation unit in your code and include the header right after in order to define library symbols. Just include the header as normal otherwise.

Examples and Tests

Some headers also have example code or demos. In this repo just look for the corresponding examples or tests folders. The example folders are particularly useful for figuring out how to use a particular header.

Contact

Here's a link to the discord chat for cute_headers. Feel free to pop in and ask questions, make suggestions, or have a discussion. If anyone has used cute_headers it would be great to hear your experience! https://discord.gg/2DFHRmX

Another easy way to get a hold of me is on twitter @randypgaul.

FAQ

  • What's the point of making a single file? Why is there implementation and static functions in the headers?

Including these headers is like including a normal header. However, to define the implementation each header looks something like this:

// Do this ONCE in a .c/.cpp file
#define LIBNAME_IMPLEMENTATION
#include "libname.h"

// Everywhere else, just include like a typical header
#include "libname.h"

This will turn the file into a header + c file combo, one time. The point of this is: A) handling the header or sending it to people is easy, no zip files or anything just copy and paste a single file; B) build scripts are a pain in the ass, and these single-file libs can be integrated into any project without modifying a single build script.

  • Doesn't writing all the code in a header ruin compile times?

The stigma that header implementations slow compile time come from inline'd code and template spam. In either case every single translation unit must churn through the header and place inline versions of functions, or for templates generate various type-specific functions. It gets worse once the linker kicks in and needs to coalesce translation units together, deleting duplicated symbols. Often linkers are single-threaded tasks and can really bottleneck build times.

A well constructed single-file header will not use any templates and make use of inline sparingly. Additionally well constructed single-file headers use a #define to place implementation (the function definitions and symbols) into a single translation unit. In this way a well crafted single-file header is pretty much the best thing a C compiler can come across, as far as build times go. Especially when the header can optionally #define out unneeded features.

  • Aren't these header only libraries just a new fad?

I personally don't really know if it's a fad or not, but these files aren't really just headers. They are headers with the .C file part (the implementation) attached to the end. It's two different files stuck together with the C preprocessor, but the implementation part never shows up unless the user does #define LIB_IMPLEMENTATION. This define step is the only integration step required to use these headers.

Unfortunately writing a good header library is pretty hard, so just any random header lib out there in the wild is probably not a good one. The STB and RJM are pretty good header libs, and are a good reference to get an idea at what a good header lib looks like. Mattias Gustavsson has my favorite collection of headers.

  • What is the license?

Each lib contains license info at the end of the file. There is a choice between public domain, and zlib.

  • I was looking for a header I've seen before, but it's missing. Where did it go?

Some of the unpopular or not so useful headers became deprecated, and live here now.

  • *Do you have any higher level libraries? These seem a bit too low-level.

The cute headers are indeed rather low-level. They solve specific problems. If you're looking for a higher level game creation framework I suggestion trying out Cute Framework, a 2D game creation framework built largely on-top of the various low-level cute headers seen here.

More Repositories

1

qu3e

Lightweight and Simple 3D Open Source Physics Engine in C++
C
923
star
2

cute_framework

The *cutest* framework out there for creating 2D games in C++!
C
535
star
3

ImpulseEngine

Simple, open source, 2D impulse based physics engine for educational use.
C++
323
star
4

AsciiEngine

Game engine written in C to create Ascii art games within the Windows console.
C
130
star
5

C-Hotloading

Example of MSVC makefile project for hotloading C with intellisense/debugger compatability
C++
106
star
6

player2d

Educational demo implementing a swept 2D character controller
C
89
star
7

kk_slides

Some "slides" about coroutines in C
C
34
star
8

tinycavestory

Little demo of platforming and sprite batching via tinyheaders and Cave Story art
C
32
star
9

cute_snake

Snake example game written with Cute Framework
C++
17
star
10

Serialization_C

Serialization and Reflection proof of concept in C
C
13
star
11

CF_Lua

C
10
star
12

cute_headers_deprecated

Collection of deprecated cute headers
C
10
star
13

block_man

Block Man - A silly game, the first game ever made with Cute Framework
C++
9
star
14

randygaul.github.io

Ruby
6
star
15

GAM_150_SampleEngine

C
5
star
16

game_math_101

Materials for the blog post: Game Math 101, Writing your Own Math in C++
C
5
star
17

d3d9-Render-to-Texture

Example of Rendering to Texture via D3D9
C++
5
star
18

cute_pong

Pongish written in C++ with Cute Framework
C++
5
star
19

cf_net_test

Messing around with and testing client/server networking from Cute Framework
C++
4
star
20

GAM150Slides

GAM 150 Lecture Slides by Randy Gaul
3
star
21

pook

C
3
star
22

MetaData_Part5_Serialization

C++
3
star
23

cute_jam_2018

C
2
star
24

oop

Example of oop vs non-oop C++
C++
2
star
25

MetaData_Part4_Variant

C++
1
star
26

SimpleLuaBind

C
1
star
27

cute_framework_project_template

Copy + pastable CMake project template for Cute Framework
CMake
1
star
28

Scripting

Simple proof of concept for a domain specific language in C
C
1
star