All Projects → screepers → cppreeps

screepers / cppreeps

Licence: MIT license
WASM C++ Screeps API and utilities pack (beta, proof-of-concepts)

Programming Languages

C++
36643 projects - #6 most used programming language
javascript
184084 projects - #8 most used programming language
shell
77523 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to cppreeps

TypeScriptXX
🧷 Stay safe! Type-safe scripting for C++ using TypeScriptToLua and CMake with auto-generated declarations.
Stars: ✭ 33 (-13.16%)
Mutual labels:  emscripten, embind
emscripten-webxr
WebXR library for use with Emscripten.
Stars: ✭ 21 (-44.74%)
Mutual labels:  emscripten
Screeps-Typescript-Declarations
The repository for *Screeps's* TypeScript type definitions.
Stars: ✭ 69 (+81.58%)
Mutual labels:  screeps
screeps-grafana
Pretty graphs for screeps
Stars: ✭ 61 (+60.53%)
Mutual labels:  screeps
AECforWebAssembly
A port of ArithmeticExpressionCompiler from x86 to WebAssembly, so that the programs written in the language can run in a browser. The compiler has been rewritten from JavaScript into C++.
Stars: ✭ 15 (-60.53%)
Mutual labels:  emscripten
screeps-game-api
Typed bindings to the Screeps in-game API for WASM Rust AIs
Stars: ✭ 99 (+160.53%)
Mutual labels:  screeps
creep-tasks
Screeps plugin for a flexible method of controlling creep actions
Stars: ✭ 45 (+18.42%)
Mutual labels:  screeps
jstodef
Library for sending messages from JavaScript to Defold (Lua)
Stars: ✭ 21 (-44.74%)
Mutual labels:  emscripten
imgui
Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.
Stars: ✭ 348 (+815.79%)
Mutual labels:  emscripten
rust to js
An example of Rust code that compiles to javascript.
Stars: ✭ 26 (-31.58%)
Mutual labels:  emscripten
dcraw.js
Generated JavaScript executable code from dcraw.c
Stars: ✭ 14 (-63.16%)
Mutual labels:  emscripten
noita-tools
A collection of tools for Nolla's Noita that help get insight into seeds and find ones with special constraints.
Stars: ✭ 22 (-42.11%)
Mutual labels:  emscripten
python-wasm
Build scripts and configuration for building CPython for Emscripten
Stars: ✭ 606 (+1494.74%)
Mutual labels:  emscripten
creeptalk
Giving Creeps Social Skills Since 2016
Stars: ✭ 14 (-63.16%)
Mutual labels:  screeps
ffmpeg-h264-dec
H.264 decoder extracted from FFmpeg.
Stars: ✭ 81 (+113.16%)
Mutual labels:  emscripten
gba.ninja
A port of visualboyadvance-m to JavaScript and a custom frontend
Stars: ✭ 69 (+81.58%)
Mutual labels:  emscripten
datachannel-wasm
C++ WebRTC Data Channels and WebSockets for WebAssembly in browsers
Stars: ✭ 77 (+102.63%)
Mutual labels:  emscripten
web-ifc
Reading and writing IFC files with Javascript, at native speeds.
Stars: ✭ 229 (+502.63%)
Mutual labels:  emscripten
webDOOM
Classic DOOM recompiled with WebAssembly
Stars: ✭ 61 (+60.53%)
Mutual labels:  emscripten
rotation master
Provide conversion between the major representations of 3D rotation and visualize the orientation of a rigid body
Stars: ✭ 157 (+313.16%)
Mutual labels:  emscripten

CPPREEPS

Example of C++ API, bindings and utilities for Screeps game. Native C++ source code can be compiled to WebAssembly (WASM) format using Emscripten compiler.

WebAssembly (or wasm) is a low-level bytecode format for in-browser client-side scripting, evolved from JavaScript. Its initial aim is to support compilation from C and C++, though other source languages such as Rust are also supported... WIKI

Emscripten is an Open Source LLVM to JavaScript compiler. Using Emscripten you can: compile C and C++ code into JavaScript, compile any other code that can be translated into LLVM bitcode into JavaScript, compile the C/C++ runtimes of other languages into JavaScript, and then run code in those other languages in an indirect way (this has been done for Python and Lua)!.. DOCS

WASM modules (.wasm files) can be relatively easily loaded within .js code. After that, native C++ functions can be called from JS, example:

const wasm_loader = require("wasm_loader");
const module = wasm_loader("js_filename", "wasm_filename");
/* * * * */
let result = module.native_function(arg1, arg2);
let some_sinus = module.sin(9001);
let packed_mem = module.lzw_encode(RawMemory.get());
let path = module.find_path(creep1, creep2);

Getting started (under construction)

  1. Download and install emsdk (Emscripten SDK, compiler toolchain): guide.

    NOTE: the simplest way to get started with WASM is to use portable emsdk package: it easy to install and work with, just follow installation guide very carefully.

    This step briefly (Linux/iOS syntax):

    $ #Download emsdk-portable.tar.gz && Unpack archive
    $ ./emsdk update
    $ ./emsdk install latest
    $ ./emsdk activate latest
  2. Prepare building environment:

    • Linux/iOS: $ source ./emsdk_env.sh

    • Windows: > emsdk_env.bat

    • OR by configuring own building system (see official example).

      NOTE: configuring own building system (cmake + make etc.) is the most painful way to get started with Emscripten, so we really need help here to complete this guide =)

  3. Build project using em++ to WASM module (pair of .wasm and .js files):

    • Linux/iOS: $ ./create.sh (see script file example)
    • Windows: > create.bat (see script file example)
    • OR using your own building system (make etc.)
  4. Push generated files from /dist folder to Screeps/PTR (using grunt, gulp, or whatever), see Screeps docs: 1, 2.

    NOTE: WASM is an experimental feature, and for now it only available on PTR.

    NOTE: for now binary GUI uploading isn't implemented yet.

See src/loop.cpp, src/main.js for WASM usage examples.

Current repo can be cloned by: git clone --recursive git://***.git

Submodules updating can be performed by: git submodule update --init --recursive


Utility pack:

LZW-based codec (submodule) Build Status

Header-only library lib/lzw/lzw.hpp contains implementation of original LZW compression/decompression algorithms. It's a submodule, see my source repo for details.

Header file include/lzw.hpp contains wrapper around lzw_codec<ASCII_128_common, UTF16_pack> codec functions and EMSCRIPTEN_BINDINGS(lzw){...} block exporting them to WASM module making them easy to use. Their native signatures:

std::wstring lzw_encode(std::wstring in);
std::wstring lzw_decode(std::wstring in);

...and example of JS usage (see sources for other examples):

const src = "Ololo, some string!";
const enc = mod.lzw_encode(src);
const dec = mod.lzw_decode(enc);
// assert(src == dec);

Native performance test (1 KIB string):

LZW encode = 94 us/KIB, decode = 94 us/KIB
ZIP ratio = 0.0527344 (enc/src) str="AAAAAAAAAAAAAAAA..."
LZW encode = 117 us/KIB, decode = 20 us/KIB
ZIP ratio = 0.538086 (enc/src) str="{"key1":42, "key2":"val1"..." (~JSON)
LZW encode = 151 us/KIB, decode = 16 us/KIB
ZIP ratio = 1.25977 (enc/src) str="v21ny6E5624VjTk8..." (random)

JS performance tests, lzw_xxcode(RawMemory.get()), ~600 KIB:

LZW encode = 167.497 CPU, 244.144 CPU/MIB
           => ratio = 0.229, len = 597102
LZW decode = 185.010 CPU, 1413.525 CPU/MIB

In-game usage result:

Memory view:

1.1 KB
src :   {\"stats\":{\"profiler.findInRange\":0.06027972683740784,..."

0.3 KB
enc :  **࢛ກҔຣ࢓ݡ䂠๣ᢏൃᒌ๣㑎෤⒄෢Ѳ෣ᒇᄃ㡐ء塐݁呕ځ呒ۡ䁘݁䣌ځじѡ䂃...

Thanks @ags131, @primus, @tedivm for their examples and experience =)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].