Coder Social home page Coder Social logo

templeblock / sx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from septag/sx

0.0 1.0 0.0 1.05 MB

Portable base library for C programmers, tailored for performance and simplicity.

License: BSD 2-Clause "Simplified" License

CMake 1.40% Assembly 35.58% C 52.28% C++ 10.02% Objective-C 0.71%

sx's Introduction

SX: Portable base library for C/C++ programs (WIP)

@septag

SX is merely a collection of sources and 3rdparty libraries. It is written in C and can be compiled using C++ compiler like MSVC. Designed for simplicity and performance, It is tailored more towards system and game programmers.
Inspired by the works of Sean Barret, Branimir Karadric, Andre Weissflog, Mathias Gustavsson, r-lyeh, ocornut, I decided to make my own C base library for future projects. I also used and borrowed many of their code inside SX.

This library currently contains:

  • allocator.h: basic memory allocation functions and default heap/leak_check allocators. Allocators are used anywhere in the code that needs memory allocation/deallocation. There is no direct memory allocations like malloc inside any function.
  • app.h: sokol_app implementation and wrapper
  • array.h: stretchy_buffer implementation
  • atomic.h: Set of portable atomic types and functions like CAS/Exchange/Incr/...
  • cmdline.h: getopt command line parser wrapper
  • fiber.h: low-level portable assembly fiber implementation taken from my other de-boostified project deboost.context
  • jobs.h: Fiber based task scheduler. Proof of concept for Christian Gyrling 2015 GDC Talk
    • Very fast assembly fibers
    • Wait on job dependencies without task chains or context switches
    • Fixed thread pool
    • Job execution priority support
  • gfx.h: sokol_gfx implementation and wrapper
  • handlepool.h: Handle pool
  • hash.h: Some nice hash functions and a fast fibonacci multiplicative hash-table
  • ini.h: ini.h implementation for sx
  • io.h: Input/output to memory/file IO
  • lin-alloc.h: Generic linear allocator
  • platform.h: Platform detection macros, taken from bx
  • pool.h: Fixed size pool allocator
  • rng.h: PCG random number generator
  • stack-alloc.h: Generic linear stack based allocator
  • string.h: Useful C-style string functions
  • threads.h: Portable threading primitives (Thread, Tls, Mutex, Semaphore, Signal, SpScQueue)
  • timer.h: Portable high-res timer, wrapper for sokol_time
  • virtual-alloc.h: Portable virtual memory allocator and functions
  • math.h:
    • Vector/Matrix math, many of the them taken from bx
    • Easing functions
  • os.h: Common portable OS related routines
  • bheap.h: Binary heap implementation

Build

CMake options

These are general options for cmake, where you can trim or customize the build:

  • SX_BUILD_TESTS (Default=1): Set SX_BUILD_TESTS=0 to skip building test applications
  • SX_NO_GFX (Default=0): By default SX includes and implements sokol_gfx, set SX_NO_GFX=1 to ignore sokol_gfx in the build
  • SX_NO_APP (Default=0): By default SX includes and implements sokol_app, set SX_NO_APP=1 to ignore sokol_app in the build

Windows

On windows, MSVC's support for C99/C11 standard is basically broken and non-usable, the code is compatible with C++ compilers, so in MSVC it uses CPP compiler instead of C:

cd build
cmake .. -G "Visual Studio 14 2015 Win64"

It is possible to build it with MSVC + clang_c2 toolset which in that case you have to add the -T v140_clang_c2 switch to cmake command (vs2015)

Linux

Dependencies

  • glew (libglew-dev): If you are planning to use graphics (OpenGL) module, else use SX_NO_GFX flag in cmake options

Emscripten

It can be built on emscripten (using the Emscripten.cmake toolchain) with some limitations:

  • threads.h: support is not yet implemented, blocking primitives like signals and semaphores doesn't seem to work on this platform. Support maybe added in future.
  • fibers.h: Emscripten doesn't seem to support boost's assembly fibers which I'm currently using, however it is possible to implement async functions using emscripten API, which I'll try to implement in the future.
  • virtual-alloc.h: Virtual memory allocation functions does not seem to be working, it works like normal malloc, where reserving just pre-allocates all required memory
Copyright 2018 Sepehr Taghdisian. All rights reserved.

https://github.com/septag/sx

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.

   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

sx's People

Contributors

septag avatar

Watchers

 avatar

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.