Comments (3)
Turns out this repository needs to be updated for changes that have occurred in the emscripten tool chain over the years.
This diff got things working for me:
diff --git a/create.sh b/create.sh
index 04c5666..09bba04 100755
--- a/create.sh
+++ b/create.sh
@@ -4,11 +4,16 @@ mkdir -p dist
mkdir -p build
em++ \
- --std=c++11 \
+ --std=c++17 \
--bind \
-s WASM=1 \
-s MODULARIZE=1 \
-s ALLOW_MEMORY_GROWTH=1 \
+ -s WASM_ASYNC_COMPILATION=0 \
+ -s BINARYEN_ASYNC_COMPILATION=0 \
+ -s EXPORTED_FUNCTIONS='["_loop"]' \
+ -s "EXPORTED_RUNTIME_METHODS=['ccall']" \
+ -s ENVIRONMENT=shell \
-Iinclude -Ilib \
-O3 -Wall -pedantic \
src/loop.cpp \
diff --git a/include/cppreeps.hpp b/include/cppreeps.hpp
index e45af61..105e639 100644
--- a/include/cppreeps.hpp
+++ b/include/cppreeps.hpp
@@ -75,9 +75,6 @@ namespace screeps {
val Memory = get_global("Memory");
val RawMemory = get_global("RawMemory");
val PathFinder = get_global("PathFinder");
-
- tick_t() { std::printf(LOG_HEAD "TICK{%d} CONSTRUCTED\n", Game["time"].as<int>()); }
- ~tick_t() { std::printf(LOG_HEAD "TICK{%d} DESTROYED\n", Game["time"].as<int>()); }
};
static std::unique_ptr<tick_t> tick;
diff --git a/src/loop.cpp b/src/loop.cpp
index 6d38d51..2f48ae6 100644
--- a/src/loop.cpp
+++ b/src/loop.cpp
@@ -8,34 +8,17 @@
/// Exporting lzw_xxcode() to current module
#include <lzw.hpp>
+extern "C"
+{
void loop() {
using namespace utils;
using namespace screeps;
INIT();
- std::printf("Updated Game.time = %d\n",
- tick->Game["time"].as<int>());
+ std::printf("life\n");
- std::printf("RawMemory.length = %d\n",
- tick->RawMemory.call<val>("get")["length"].as<int>());
-
- std::printf("[OK, MOVE, RESOURCE_ENERGY] = [%d, %s, %s]\n",
- gCONST("OK").as<int>(),
- gCONST("MOVE").as<std::string>().c_str(),
- gCONST("RESOURCE_ENERGY").as<std::string>().c_str());
-
- EM_ASM({
- console.log("ASM: Game time = " + Game.time);
- console.log("ASM: Creeps num = " + _.size(Game.creeps));
- });
-
- auto creeps_map = js_object_to_map(tick->Game["creeps"]);
- for(auto const& kv : creeps_map) {
- auto const& name = kv.first;
- auto const& creep = kv.second;
- creep.call<int>("say", name);
- }
+}
}
EMSCRIPTEN_BINDINGS(loop) {
from cppreeps.
Something like:
diff --git a/src/main.js b/src/main.js
index 97fe88a..e7451df 100644
--- a/src/main.js
+++ b/src/main.js
@@ -5,6 +5,8 @@ const wasm_loader = require('wasm_loader')
/// Module by XXX.js and XXX.wasm files
const mod = wasm_loader('loop_mod', 'loop');
+global.Game = Game;
+global.Game = RawMemory;
global.byteLength = function(str) {
str = str + "";
let len = str.length;
is also necessary to get at the memory
from cppreeps.
Hi @TylerSeanRau!
Thank you for report and actualizing binding code, repo is pretty old indeed. Feel free to make a PR, guess it will be very helpful to have an updated and working code.
from cppreeps.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppreeps.