Giter Site home page Giter Site logo

gamekyuubi / game-of-life-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gifnksm/game-of-life-rs

0.0 1.0 0.0 1.8 MB

Conway's Game of Life implementations for Native/Emscripten

License: Apache License 2.0

Makefile 5.99% Shell 3.49% Rust 90.52%

game-of-life-rs's Introduction

Conway's Game of Life implementation for Native/Web

This game runs on both the web and native!

Try in your browser

How to Build for Native

  1. Install SDL2
  • Arch Linux:

    sudo pacman -S sdl2
    
  • macOS (Homebrew):

    brew install sdl2
    
  • Windows (MSYS2):

    pacman -S mingw-w64-SDL2
    
  1. Build and Run

    git clone https://github.com/gifnksm/game-of-life-rs.git
    cd game-of-life-rs.git
    
    export LIBRARY_PATH=<path_to_sdl2> # optional
    cargo run --release
    

How to Build for the Web

You should read the following post before start building: https://users.rust-lang.org/t/compiling-to-the-web-with-rust-and-emscripten/7627

  1. Install Emscripten SDK

    curl -O https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz
    tar -xzf emsdk-portable.tar.gz
    source emsdk_portable/emsdk_env.sh
    emsdk update
    emsdk install sdk-incoming-64bit
    emsdk activate sdk-incoming-64bit
    
  2. Install Rust Standard Library for asm.js

    rustup target add asmjs-unknown-emscripten --toolchain nightly
    
  3. Prepare Emscripten Caches

    # Set envvars for Emscripten toolchains
    source emsdk_portable/emsdk_env.sh
    
    echo "int main(void) { return 0; }" > empty.c
    emcc -s USE_SDL=2 empty.c     # for debug builds
    emcc -s USE_SDL=2 -O3 empty.c # for release builds
    

    Without this step, cargo build may fail.

    I think this is because cargo runs emcc in parallel. emcc does a lazy compile of dependencies (libc, gl, SDL2, ...) the first time you run it. If cargo runs emcc in parallel, each emcc process starts compiling dependencies and seems to write the build artifacts on the same path at the same time. This makes the build broken.

  4. Build and Launch Web Server

    git clone https://github.com/gifnksm/game-of-life-rs.git
    cd game-of-life-rs
    
    # asmjs target is available only for nightly so far.
    rustup toolchain add nightly
    rustup override set nightly
    
    # Set envvars for Emscripten toolchains
    source emsdk_portable/emsdk_env.sh
    
    # Build and serve
    make
    make serve
    
  5. Access to the Following URL

    http://localhost:8080/
    

game-of-life-rs's People

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.