Name: screeps-regenerator
Owner: screepers
Description: Use generators in Screeps
Created: 2017-02-15 06:51:09.0
Updated: 2018-02-04 12:35:36.0
Pushed: 2017-07-16 00:57:02.0
Homepage: null
Size: 3503
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This package implements a babel transformation that allows you to use
generators/yield
in the game screeps to emulate
synchronous, multithreaded programming.
This project is based on regenerator, by Facebook.
Generators can be serialized and deserialized from plan JSON objects, which allows their running state to be stored in Memory. Note that an advanced heap serializer is needed for anything more than trivial examples, because JSON does not allow circular references.
Here is a working example using nothing more than this package:
ire('screeps-regenerator-runtime/runtime');
tion* main() {
t counter = 0;
ile (true) {
console.log("Code has been running for", counter, "ticks");
yield null;
counter += 1;
rts.loop = function () {
r thread;
(Memory.thread) {
try {
thread = regeneratorRuntime.deserializeGenerator(Memory.thread);
} finally {
delete Memory.thread;
}
else {
thread = main();
t result = thread.next();
(!result.done) {
Memory.thread = regeneratorRuntime.serializeGenerator(thread);
From NPM:
install --save-dev screeps-regenerator-preset screeps-regenerator-runtime
From GitHub:
ath/to/node_modules
clone git://github.com/facebook/regenerator.git
creeps-regenerator
install .
test
You have several options for using this module.
Via .babelrc (Recommended)
resets": ["screeps-regenerator-preset"]
Via CLI:
l --preset screeps-regenerator-prefix script.js
Via Node API:
ire("babel-core").transform("code", {
esets: ["screeps-regenerator-preset"]
The easiest way to get involved is to try out some scripts yourself and submit feature requests for what you'd like to be able to do. If you're feeling especially brave, you are more than welcome to dive into the runtime code and add new features yourself.