{"id":13418990,"url":"https://github.com/emilk/emilib","last_synced_at":"2025-04-09T12:09:44.655Z","repository":{"id":40990878,"uuid":"52147478","full_name":"emilk/emilib","owner":"emilk","description":"Loose collection of misc C++ libs","archived":false,"fork":false,"pushed_at":"2022-01-09T06:25:04.000Z","size":1238,"stargazers_count":351,"open_issues_count":1,"forks_count":18,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-02T11:04:32.071Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emilk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-20T10:09:05.000Z","updated_at":"2025-03-05T16:40:33.000Z","dependencies_parsed_at":"2022-08-10T01:29:25.966Z","dependency_job_id":null,"html_url":"https://github.com/emilk/emilib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emilk%2Femilib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emilk%2Femilib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emilk%2Femilib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emilk%2Femilib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emilk","download_url":"https://codeload.github.com/emilk/emilib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036067,"owners_count":21037092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:09.824Z","updated_at":"2025-04-09T12:09:44.636Z","avatar_url":"https://github.com/emilk.png","language":"C++","readme":"# emilib\nThis is a loose collection of C++14 libraries I tend to reuse between different (mostly game-related) projects.\n\nThey are meant mostly for me (Emil Ernerfeldt), but if you find them useful, have at it.\n\nTheir only dependencies are either system dependencies (pthread etc) and [Loguru](https://github.com/emilk/loguru). gl_lib also depends on OpenGL and GLEW. The libraries does not depend on each other (with an exception for ShaderMngr).\n\nThey all work on OSX and iOS and probably Linux. Some may work elsewhere.\n\n\n# License\nThis software is in the public domain. Where that dedication is not\nrecognized, you are granted a perpetual, irrevocable license to copy\nand modify this file as you see fit.\n\n\n# Documentation\nDocumentation can be found at [https://emilk.github.io/emilib/html/index.html](https://emilk.github.io/emilib/html/index.html).\n\n\n# Usage\nMost libraries in emilib are stand-alone, so you can, for instance, use the coroutine library without having to compile anything but that.\n\nSome are header-only, but most come with a `.cpp` file too.\n\nTo 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.:\n\n\t#include \u003cemilib/coroutine.hpp\u003e\n\t#include \u003cemilib/coroutine.cpp\u003e // Do this only in one of your .cpp files\n\nYou 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.\n\nYou 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:\n\n\t#define LOGURU_IMPLEMENTATION\n\t#include \u003cloguru.hpp\u003e\n\nMake sure you compile with -std=c++11 -lpthread -ldl\n\n#### Documentation\nThis file (README.md) contains an overview of each library. Read the header for each library to learn more.\n\n#### Examples\nThere is a very limited set of examples in the `examples/` folder.\n\n#### Tests\nThere is a very limited set of tests in the `tests/` folder.\n\n\n# Stand-alone libraries\n\n#### algorithm.hpp\nUseful extensions to STL\n\n#### coroutine.hpp/.cpp\nThis is a \"fake coroutine\" class which implements a cooperative thread and methods for passing execution between the outer and inner thread.\n\nThis 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.\n\n#### dir_watcher.hpp/.cpp\nThis 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.\n\nPOSIX systems only.\n\n#### dual.hpp\nLibrary for [dual numbers](https://en.wikipedia.org/wiki/Dual_number). Can be used for numerical stable differentiation. Works inside of Eigen.\n\n#### filesystem.hpp/.cpp\nContains functions for easily reading/writing files, getting file size and modified time, listing all files in a directory, etc.\n\nIt also contains functions for working with file paths.\n\n#### hash_cache.hpp\nHashCache wraps a value and memoizes the hash of that value. Can speed up hash sets and maps by a lot.\n\n#### hash_map.hpp / hash_set.hpp\nCache-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:\n\n* Much better performance\n* Key/values may move when rehashing\n\n#### irange.hpp\nSimple integer range, allowing you to replace `for (size_t i = 0; i \u003c limit; ++i)` with `for (auto i : irange(limit))`.\nIt also provides a `Range` class which represent an integer range in a half-closed interval [begin, end) as well as the following functions:\n\n``` C++\n\tfor (const auto ix : irange(end))                        { CHECK_F(0     \u003c= ix \u0026\u0026 ix \u003c end);           }\n\tfor (const auto ix : irange(begin, end))                 { CHECK_F(begin \u003c= ix \u0026\u0026 ix \u003c end);           }\n\tfor (const auto ix : indices(some_vector))               { CHECK_F(0 \u003c= ix \u0026\u0026 ix \u003c some_vector.size(); }\n\tfor (const char ch : emilib::cstr_range(\"hello world!\")) { ...                                         }\n\tfor (auto\u0026 value : it_range(begin, end))                 { std::cout \u003c\u003c value;                         }\n```\n\n#### list_map.hpp / list_set.hpp\nSimple O(N) map/set with small overhead and great performance for small N.\n\n#### magica_voxel.hpp/.cpp\nLoader for [MagicaVoxel](https://voxel.codeplex.com/) models.\n\n#### marching_squares.hpp/.cpp\nShort, simple marching squares implementation.\n\n#### mem_map.hpp/.cpp\nSimple wrapper around memory mapping with RAII.\n\n#### movement_tracker.hpp/.cpp\nTrack movement of some data, e.g. to estimate velocity from recent movement.\nFor 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.\n\n#### profiler.hpp/.cpp profiler_gui.hpp/cpp\nFast opt-in profiling using easy to use macros.\nNice flamegraph UI which you can explore.\n\n#### read_write_mutex.hpp\nFast mutex for multiple-readers, single-writer scenarios written in pure C++11.\n\n#### scope_exit.hpp\nAdds the macro `SCOPE_EXIT` for running some code at the end of the scope (or when a function returns, etc). Example:\n\n``` C++\nvoid foo()\n{\n    File* file = fopen(...);\n    SCOPE_EXIT{ fclose(file); };\n    if (bar) { return; }\n    if (baz) { exit(); }\n    might_throw_an_exception(file);\n}\n```\n\n#### string_interning.hpp/.cpp\nStupid simple thread-safe string interning.\n\n#### strprintf.hpp/.cpp\nMinimalistic 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.\n\n#### tga.hpp/.cpp\nDump a tga image to disk.\n\n#### thread_pool.hpp/.cpp\nA simple thread pool.\n\n#### timer.hpp/.cpp\nMonotonic wall time chronometer.\n\n#### tuple_util.hpp\nAdds `for_each_tuple` for iterating over a `std::tuple` and also overloads `std::hash` for `std::tuple`.\n\n#### utf8.hpp/.cpp\nReally basic utf8 operations.\n\n#### wav.hpp/.cpp\nParse WAVE (.wav) sound files.\n\n#### word_wrap.hpp/.cpp\nWrap lines of text to fit within a given width.\n\n\n# iOS / OSX specific libraries:\n\n#### music.hpp/.mm\nStream mp3 music on OSX and iOS.\n\n#### os.hpp/.mm\nDevice information like screen size and orientation.\n\n#### pvr.hpp/.mm\nLoading of compressed .pvr textures. Depends on gl_lib.\n\n#### text_paint.hpp/.mm\nPretty 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.\n\nIt draws the text to memory, so it is up to you to display it (e.g. upload it to a texture).\n\n\n# Libraries with third-party dependencies\n\n#### al_lib\nCode for loading, playing and positioning sounds using OpenAL.\n\nDepends on OpenAL and other parts of emilib.\n\nInclude `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.\n\n#### gl_lib\nCode for doing simple things in OpenGL and/or OpenGL ES (GLES). It has classes and methods for dealing with:\n\n* 2D Textures\n* Vertex and fragment shaders\n\t* You can use the same shader code for GLES and non-GLES targets\n* Vertex buffers (VBO/VAO)\n* Viewports\n* Off-screen buffers (FBO)\n\nDepends on OpenGL and GLEW.\n\nInclude `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).\n\n#### gl_lib_sdl.hpp/.cpp\nHelper functions for creating an SDL2 OpenGL window.\n\n#### imgui_gl_lib.hpp/.cpp\nProvides bindings between my `gl_lib` and the wonderful [Dear ImGui](https://github.com/ocornut/imgui) GUI library. Can be used alone or together with `emilib/imgui_sdl.hpp/.cpp`.\n\n#### imgui_gl_lib_tools.hpp/.cpp\nSome additional helpers for painting OpenGL stuff with `gl_lib` inside of [Dear ImGui](https://github.com/ocornut/imgui).\n\n#### imgui_helpers.hpp/.cpp\nHelpers for working with the wonderful [Dear ImGui](https://github.com/ocornut/imgui) GUI library.\n\n#### imgui_sdl.hpp/.cpp\nBindings between [SDL2](https://www.libsdl.org/) and the wonderful [Dear ImGui](https://github.com/ocornut/imgui) GUI library. Can be used alone or together with `emilib/imgui_gl_lib.hpp/.cpp`.\n\n#### sdl_input.hpp/.cpp\nsdl_input wraps the input events from [SDL2](https://www.libsdl.org/) with an easy-to-use interface that is unified for desktop and mobile.\n\n#### shader_mngr.hpp/.cpp\nThis is NOT a stand-alone library, but depends on other parts of emilib as well as loguru and configuru.\nShaderMngr's job is to encapsulate loading, memoization and reloading of shader files.\nIn particular, ShaderMngr can detect changes in .shader files and automatically reload (hot-reloading) them.\n\n#### texture_mngr.hpp/.cpp\nThis is NOT a stand-alone library, but depends on other parts of emilib as well as loguru.\nTextureMngr's job is to encapsulate loading, memoization and reloading of texture files.\nIn particular, TextureMngr can detect changes in image files and automatically reload (hot-reloading) them.\n\n\n# Libraries not part of emilib, but incldued for convenicence:\n\n#### configuru.hpp\nThis is not part of emilib, but a copy of https://github.com/emilk/configuru here only for convenience.\n\n#### loguru.hpp\nThis 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.\n","funding_links":[],"categories":["TODO scan for Android support in followings","Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femilk%2Femilib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femilk%2Femilib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femilk%2Femilib/lists"}