Giter VIP home page Giter VIP logo

rizz's Introduction

Build Status

Rizz

@septag

Rizz (ریز) is a tiny, multi-platform, and minimal game/app development framework, Written in C language. Inspired by The Machinery and sokol libs. It's currently a work in progress, features and improvements will be added constantly to different platforms.

preview sample model is the courtesy of Ferre Poorkazem

Design and Basic usage

For more detailed information about design principles, architecture and basic usage of the framework, please read the document rizz Architecture and Basic usage, which is also available in docs/guide

Note

This is not a game engine, it's a relatively low-level framework for programmers to build their own engine/renderer/physics on top of it. The core of rizz does not and will not implement any rendering techniques/physics or impose any specific entity system to the user. It just provides the basic building blocks for game developers. Other features will be implemented as plugins.

Features

Core

  • Portable C code: C11 (gcc/clang), C99 (msvc) compatible code, designed with data-oriented mindset.
  • Plugin system: Engine has a small core. Many functionalities are implemented through plugins.
  • Minimal Dependencies: No external/large dependencies. Only a handful of small dependencies included in the source.
  • Hot-reloading of C/C++ code: Plugins/Game code are all hot-reloadable with some restrictions and rules.
  • Fiber based job system: Simple to use fiber-based job system.
  • Reflection: Provides simple reflection system for structs, enums and functions along with built-in JSON serialization/deserialization.
  • Async Asset Manager: Flexible reference counting asset manager. New asset types can be added by third-party code to the manager.
  • Hot-reloading of assets and shaders: All in-game resources and shaders can be hot-reloaded.
  • Virtual file system: Async read/write. Directories or archives can be mounted as virtual directories.
  • Support for coroutines: Coroutines can be suspended for N frames or N milliseconds.
  • Custom crash handling: Custom callbacks for crashes. Along with Crash.dmp file creation (windows only)

Graphics

  • Multiple graphics API support: Metal (iOS, MacOS). OpenGL-ES 2/3 (Android). Direct3D11 (Windows), OpenGL 3.3 (Linux)
  • Portable shaders: Write shaders once in GLSL, toolset will automatically translate the shader to other APIs.
  • Multi-threaded GPU command-buffer: Draw commands can be submitted by multiple threads with staged API.
  • Compute shader support (Experimental): Experimental compute-shader support, currently only under Direct3D, more backends will be added.

Plugins

Many of the engine features are implemented in the plugins, visit each link to read their README:

  • imgui: Dear-imgui plugin with some utility API
  • 2dtools: 2D rendering tools: sprite, sprite animation, font drawing with TTF support
  • sound: Simple sound system. Audio mixer and 2d-sounds.
  • input: Input system with gamepad and touch support
  • 3dtools: 3D rendering tools: support for GLTF 3d models, basic debug primitive creation and drawing
  • astar: A-star path-finding implementation plugin
  • collision: 2.5D/Isometric Collision detection plugin
  • utility: misc utility functionality. Currently, spline and noise generator
  • basisut: basis_universal texture format support (asset type name: "texture_basisu")

Debugging and Profiling

  • Remote Profiler: Integrated Remotery for remote debugger/command console and log viewer.
  • Graphics API introspection: Debug application level graphic calls and objects.
  • Memory Debugger: Debug and monitor memory allocations for all subsystems.

Supported platforms

  • Windows
  • Linux
  • MacOS
  • Android
  • RaspberryPI
  • iOS

Build

rizz is designed to run on all major mobile (iOS, android), PC (Windows, Linux, MacOS) and web (WebASM) platforms. But as the engine is in it's early age, the current platforms are built and tested:

  • Windows: Tested on Windows10 with visual studio 14 2015 update 3 (Win64).
  • Linux: Tested on ubuntu 16 with clang (6.0.0) and gcc (7.3.0). Package requirements:
    • libx11-dev
    • libxrandr-dev
    • libxi-dev
    • libasound2-dev (if you are planning to build sound plugin)
    • libglew-dev
  • MacOS: Tested on MacOS High Sierra - AppleClang 9.1.0
  • Android: For android, there is a python script android.py which takes care of preparing android project structure, building the code and packaging the final APK. please read the begining of android.py.
  • RaspberryPI: Tested on RPi1 ModelB Ubuntu-jessie (gcc Raspbian 4.9.2). Package requirements:
    • libasound2-dev (if you are planning to build sound plugin)
  • iOS: For iOS, there is a python script ios.py which takes care of initializing iOS project

CMake options

  • BUNDLE (default=0, android/ios=1):

    • BUNDLE=0 indicates that rizz is built as an executable host which runs the game by rizz --run game.dll (on linux it's rizz --run ./game.so). Recommended for development, where you need reduced binary sizes and live-reloading of game code and plugins.
    • BUNDLE=1 Builds rizz as static library. To link and bundle rizz and other plugins with a single stand-alone executable, so there will be only one executable and bundles rizz and all the plugins you specify. to build the bundle properly, you should set these cmake arguments on configure:
      • BUNDLE_TARGET: target name of the executable you are trying to build (first example: -DBUNDLE_TARGET=01-hello)
      • BUNDLE_TARGET_NAME: if the cmake target and the actual name of your application differs, use argument to address that. (first example: -DBUNDLE_TARGET_NAME=hello)
      • BUNDLE_PLUGINS: list the plugins that is required by your application, separated by semicolon. (first example: -DBUNDLE_PLUGINS=imgui)
  • ENABLE_HOT_LOADING (default=1, android/ios=0) Enables hot reloading of assets and monitoring the assets directories. Doesn't work on mobile OSes.

  • ENABLE_PROFILER (default=0/debug, default=1/release)

  • BUILD_EXAMPLES (default=1, android/ios=0) Build example projects in /examples directory.

  • MSVC_STATIC_RUNTIME (default=0): MSVC specific. Compiles the RELEASE config with '/MT' flag instead of '/MD'

  • MSVC_MULTITHREADED_COMPILE (default=1): MSVC specific. Turns on multi-threaded compilation (turns it off with Ninja)

  • CLANG_ENABLE_PROFILER (default=0): Clang specific. Turns on -ftime-trace flag. Only supported in clang-9 and higher

Examples

Examples Basic examples are included with this repo, in examples directory:

examples-overview

Space invaders clone - link to github project

space-invaders

Changes

v0.5

WIP

v0.4

  • BREAKING: json parser, replace sjson with cj5
  • BREAKING: renamed sprite plugin to 2dtools
  • BREAKING: external macro APIS (rizz_log_xxxx) are now same as internal ones (api variable is defined in header)
  • BREAKING: Reflection now has contexts in it's API
  • NEW: imgui log window
  • NEW: true-type font (fontstash) support through 'rizz_api_font' API
  • NEW: basis texture support
  • NEW: astar path-finding plugin, thanks to @aminv
  • NEW: Hybrid collision detection plugin
  • NEW: "json" asset type (see rizz/json.h)
  • NEW: utility plugin (spline, noise, more stuff will be added), thanks to @aminv
  • Updated remotery
  • ImGui to 1.79-docking branch
  • sx io API and backend to native instead of std.fopen
  • Async vfs API tget individual files
  • IFF load/save API in sx/io.h
  • shader_get/texture_get and other asset getters to all asset types
  • Lots of math lib improvements and refactors
  • tmp_alloc overhaul
  • fixes in dds-ktx parser
  • MSVC compiler C11 support
  • Better C-API compatbility with C++, and some simple wrappers for C++ (array, hash-table, math operators, ..)
  • Reflection system improvements, two new serialize/deserialize functions for writing custom serialization
  • Reflection system built-in JSON serialization
  • New ImGui theme (Thanks to @aminv)

Open-Source libraries used

Primarily developed for rizz

  • sx: Portable base library
  • glslcc: GLSL cross-compiler (external binary tool)
  • dds-ktx: Single header KTX/DDS reader
  • cj5: Very minimal single header JSON5 parser in C99, derived from jsmn
  • atlasc: Command-line tool that builds atlas texture from a bunch of input images. (External binary tool)
  • dmon: Single header C99 portable library for monitoring directory changes.
  • stackwalkerc: Windows single header stack walker.

3rdparties

  • sokol: minimal cross-platform standalone C headers
  • cr: Simple C Hot Reload Header-only Library
  • cimgui: C-API for imgui (used in imgui plugin)
  • imgui: Dear ImGui: Bloat-free Immediate Mode Graphical User interface for C++ with minimal dependencies (used in imgui plugin)
  • Remotery: Single C file, Realtime CPU/GPU Profiler with Remote Web Viewer
  • lz4: Extremely Fast Compression algorithm
  • http: Basic HTTP protocol implementation over sockets
  • stb: stb single-file public domain libraries for C/C++
  • sort: Sorting routine implementations in "template" C
  • ImGuizmo: 3D gizmo for imgui (used in imgui plugin)
  • gainput: Input library for games (used in input plugin)
  • basis_universal: Basis Universal GPU Texture Codec
  • fontstash: Light-weight online font texture atlas builder (used in 2dtools plugin)
  • cgltf: Single-file glTF 2.0 loader and writer written in C99 (used in 3dtools plugin)
  • cute_headers: Randy Gaul's header libs (cute_c2.h used in collision plugin)
Copyright 2021 Sepehr Taghdisian. All rights reserved.

https://github.com/septag/rizz

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.

rizz's People

Contributors

amin67v avatar anthonyhan avatar charles-l avatar kochol avatar septag avatar timgates42 avatar zacharycarter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rizz's Issues

lt comparison should be gt

if (arg_len > (int)sizeof(item.value) - 1) {

I believe the check here is backwards - it is currently checking if the length of the argument passed to the option is greater than the size of value array of the union (8 bytes). If it is, it currently copies 8 bytes from the argument into the buffer. I believe it should really allocate in this case - unless I'm misunderstanding the intent of this section of code.

compute shader

Hi, I really love the way of rizz and its provided functionalities, like gfx, jobs, reflection, etc.
however, the compute shader seems not supported yet?

is it possible to support the compute shader so that it would be much convenient to do some advanced rendering tests.

so brilliant!

MinGW support

Thanks for the project, I'm currently building it with MSVC, but it would be great if you can add support for MinGW. In general, the building process runs fine excepting several errors like:

Rizz\src\sx\src\threads.c:493:45: error: operand of ?: changes signedness from 'int' to 'unsigned int' due to unsignedness of other operand [-Werror=sign-compare]
     DWORD _msecs = (msecs < 0) ? INFINITE : msecs;
                                             ^~~~~
Rizz\src\sx\src\threads.c: In function 'sx_signal_wait':
Rizz\src\sx\src\threads.c:539:45: error: operand of ?: changes signedness from 'int' to 'unsigned int' due to unsignedness of other operand [-Werror=sign-compare]
     DWORD _msecs = (msecs < 0) ? INFINITE : msecs;
                                             ^~~~~
Rizz\src\sx\src\threads.c: In function 'sx_thread_setname':
Rizz\src\sx\src\threads.c:631:5: error: '__try' undeclared (first use in this function)
     __try {
     ^~~~~
Rizz\src\sx\src\threads.c:631:5: note: each undeclared identifier is reported only once for each function it appears in
Rizz\src\sx\src\threads.c:631:10: error: expected ';' before '{' token
     __try {
          ^~
          ;
cc1.exe: all warnings being treated as errors
make[2]: *** [src\sx\CMakeFiles\sx.dir\build.make:91: src/sx/CMakeFiles/sx.dir/src/threads.c.obj] Error 1
make[1]: *** [CMakeFiles\Makefile2:596: src/sx/CMakeFiles/sx.dir/all] Error 2
make: *** [Makefile:83: all] Error 2

Hot reloading of shader doesn't seem to work on macOS

I've tried to recompile a shader on macOS while rizz is running a game plugin, and this causes an assert to fail in dmon.h. Here are the steps to reproduce

  1. Clone repo
  2. Build using Cmake
  3. Run ./rizz --run lib08-draw3d.dylib from the bin directory
  4. Change the assignment statement in the fragment shader draw3d.frag for frag_color to something like - frag_color = vec4(1.0, 0.0, 0.0, 1.0);
  5. Re-compile the sgs file using the following command - ./tools/darwin/glslcc --vert=examples/08-draw3d/draw3d.vert --frag=examples/08-draw3d/draw3d.frag --lang=msl --reflect --sgs --output=examples/assets/shader s/msl/draw3d.sgs

This will cause the following assertion to fail -

Assertion failed: (strstr(abs_filepath, watch->rootdir) == abs_filepath), function dmon__fsevent_callback, file /Users/zacharycarter/dev/rizz/include/dmon/dmon.h, line 1347.

Errors with running examples on a fresh clone/build

DrawSprite
seems like there are some problems with loading the resources:

$ ./rizz --run ./lib03-drawsprite.so 
version: 0.4-17-gf9b8182
(init) vfs
(init) temp memory: 8x5120 kb
(init) jobs: threads=7, max_fibers=64, stack_size=1024kb
(init) asset system: hot-loading=1
(init) profiler (cpu): port=17815
(init) graphics: OpenGL 3.3
(init) coroutines: max_fibers=64, stack_size=2048kb
(init) http client
vfs: mounted '/cache' on '/d/code/game/rizz/rizz/bin/.cache'
(init) plugin: imgui (libimgui.so) - dear-imgui plugin - v1.77.0
(init) plugin: 2dtools (lib2dtools.so) - 2dtools plugin - v1.0.0
vfs: mounted '/assets' on '/d/code/game/rizz/rizz/examples/assets'
(init) plugin: drawsprite (lib03-drawsprite.so) -  - v0.0.0
ERROR: sg_image_desc.width must be > 0
ERROR: sg_image_desc.height must be > 0
ERROR: ^^^^  VALIDATION FAILED, TERMINATING ^^^^
rizz: /d/code/game/rizz/rizz/src/rizz/../../3rdparty/sokol/sokol_gfx.h:12819: _sg_validate_end: Assertion `0' failed.

NBody
Seems like is not built by default ?

Draw3d

$ ./rizz --run ./lib08-draw3d.so 
version: 0.4-17-gf9b8182
(init) vfs
(init) temp memory: 8x5120 kb
(init) jobs: threads=7, max_fibers=64, stack_size=1024kb
(init) asset system: hot-loading=1
(init) profiler (cpu): port=17815
(init) graphics: OpenGL 3.3
(init) coroutines: max_fibers=64, stack_size=2048kb
(init) http client
vfs: mounted '/cache' on '/d/code/game/rizz/rizz/bin/.cache'
(init) plugin: imgui (libimgui.so) - dear-imgui plugin - v1.77.0
ERROR: error: vertex shader output `f_color' specifies flat interpolation qualifier, but fragment shader input specifies no interpolation qualifier

ERROR: sg_pipeline_desc.shader missing or invalid
ERROR: ^^^^  VALIDATION FAILED, TERMINATING ^^^^
rizz: /d/code/game/rizz/rizz/src/rizz/../../3rdparty/sokol/sokol_gfx.h:12819: _sg_validate_end: Assertion `0' failed.
ERROR: plugin init failed: ./lib3dtools.so
ERROR: initializing plugins failed

Btw, I couldn't see the imgui windows in any of the examples (unlike the screenshots)

Leaks in dmon.h on macOS

When the project is built in debug mode, upon closing the application, the following debug logs are printed:

DEBUG: LEAKED: dmon.h@1182: dmon__cf_malloc: 90  at 0x00007fdd5323eff0
DEBUG: LEAKED: dmon.h@1182: dmon__cf_malloc: 40  at 0x00007fdd5323e3b0
DEBUG: LEAKED: dmon.h@1182: dmon__cf_malloc: 456  at 0x00007fdd5323eda0
DEBUG: LEAKED: dmon.h@1182: dmon__cf_malloc: 85  at 0x00007fdd5322ecb0
DEBUG: LEAKED: dmon.h@1182: dmon__cf_malloc: 40  at 0x00007fdd5322ec00
DEBUG: LEAKED: dmon.h@1182: dmon__cf_malloc: 456  at 0x00007fdd5322e9b0

Fixed with PR #12

rizz__vfs_release lead to crash when conf->job_num_threads is 16

static int rizz__core_thread_func(void* user1, void* user2)
{
typedef int (thread_fn)(void user_data);
thread_fn func = (thread_fn)user2;
sx_assert(func);

int r = func(user1);

// find the any existing thread temp allocator and destroy it
uint32_t tid = sx_thread_tid();
sx_mutex_lock(g_core.tmp_allocs_mtx) {
    for (int i = 0, c = sx_array_count(g_core.tmp_allocs); i < c; i++) {
        if (g_core.tmp_allocs[i]->tid == tid) {
            rizz__release_tmp_alloc_tls(g_core.tmp_allocs[i]);
            sx_swap(g_core.tmp_allocs[i], g_core.tmp_allocs[c-1], rizz__tmp_alloc_tls*);
            sx_array_pop_last(g_core.tmp_allocs);
            break;
        }
    }
}

return r;

}

"if (g_core.tmp_allocs[i]->tid == tid)", this line will crash.

Discord Channel?

What about create a discord channel to development discussions?

WebAssembly and usability

Thank you for this great framework. I have two questions:

  • If you want to try to compile rizz to webassembly/asm.js, do you see problems arising from that? like will co-routines, the virtual file system, and the async loading work?
  • Is the 2dtools usable, or it has major missing features?

Thanks

No imgui menu on Linux

I cannot seem to get the IMGUI to show up in the examples - although the rendering seems to mostly work here.

I've tested it both on Intel and AMD gpu hardware with mesa-21.0.3.

can i use cpp file

Hello,

when I rename hello.c to hello.cpp, the following line:

g_stage = the_gfx->stage_register("main", (rizz_gfx_stage){ .id = 0 });

with the following errors:

error C2059: syntax error: '.'
error C2059: syntax error: ')'

as I need to include <string>, otherwise, if I do not rename c to cpp, std will not be compiled!

thanks

Example 08-draw3d locks up during startup

Running the 08-draw3d example on Windows with VS2019 results in an unresponsive white screen. It appears that the asset system tries to start a job to read and load the a 3d asset, but it gets stuck in a spin waiting for a lock to be released.

rizz.exe!sx_anderson_lock_enter(sx_anderson_lock_t * lock) Line 793
	at C:\Work\rizz\src\sx\src\threads.c(793)
rizz.exe!sx_job_dispatch(sx_job_context * ctx, int count, void(*)(int, int, int, void *) callback, void * user, sx_job_priority priority, unsigned int tags) Line 320
	at C:\Work\rizz\src\sx\src\jobs.c(320)
rizz.exe!rizz__job_dispatch(int count, void(*)(int, int, int, void *) callback, void * user, sx_job_priority priority, unsigned int tags) Line 1757
	at C:\Work\rizz\src\rizz\core.c(1757)
rizz.exe!rizz__asset_on_read(const char * path, sx_mem_block * mem, void * user) Line 328
	at C:\Work\rizz\src\rizz\asset.c(328)
rizz.exe!rizz__vfs_async_update() Line 397
	at C:\Work\rizz\src\rizz\vfs.c(397)
rizz.exe!rizz__core_frame() Line 1582
	at C:\Work\rizz\src\rizz\core.c(1582)
rizz.exe!rizz__app_frame() Line 476
	at C:\Work\rizz\src\rizz\app.c(476)
rizz.exe!_sapp_call_frame() Line 1146
	at C:\Work\rizz\3rdparty\sokol\sokol_app.h(1146)
rizz.exe!_sapp_frame() Line 1266
	at C:\Work\rizz\3rdparty\sokol\sokol_app.h(1266)
rizz.exe!_sapp_run(const sapp_desc * desc) Line 5007
	at C:\Work\rizz\3rdparty\sokol\sokol_app.h(5007)
rizz.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 5086
	at C:\Work\rizz\3rdparty\sokol\sokol_app.h(5086)

If you modify the k_models array in draw3d.c to only contain 1 asset, then the main thread is unblocked, but the asset still doesn't load since the thread trying to load the asset is also stuck in a spin.

Commenting out the spin completely to ignore the lock makes everything work and load correctly, but ofc that's bad and not a real workaround.

System Info:

  • Windows 10 Pro
  • Version 10.0.19042 Build 19042
  • Visual Studio 2019 16.11.3
  • Platform toolset v142

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.