Merge branch 'libnethack2' into NetHack-3.7
This commit is contained in:
1127
sys/lib/libnethackmain.c
Normal file
1127
sys/lib/libnethackmain.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,11 @@ The main module returns a setup function: `startNethack(uiCallback, moduleOption
|
||||
* `moduleOptions` - An optional [emscripten Module object](https://emscripten.org/docs/api_reference/module.html) for configuring the WASM that will be run.
|
||||
* `Module.arguments` - Of note is the [arguments property](https://emscripten.org/docs/api_reference/module.html#Module.arguments) which gets passed to NetHack as its [command line parameters](https://nethackwiki.com/wiki/Options).
|
||||
|
||||
There are a number of auxilary functions and variables that may help with building your applications. All of these are under `globalThis.nethackOptions`. Use `console.log(globalThis.nethackOptions)` for a full list of options. Some worth mentioning are:
|
||||
* `globalThis.nethackOptions.helpers` - Helper functions that are useful for NetHack windowing ports
|
||||
* `globalThis.nethackOptions.mapglyphHelper` - Converts an integer glyph into a character to be displayed. Useful if you are using ASCII characters for representing NetHack (as opposed to tiles). Interface is `mapglyphHelper(glyph, x, y, mgflags)` and will typically be called as part of the `shim_print_glyph` function.
|
||||
* `globalThis.nethackOptions.constants` - A Object full of constants that are `#define`'d in NetHack's C code. Useful for translating to / from numbers in the APIs and return values.
|
||||
|
||||
## Example
|
||||
``` js
|
||||
let nethackStart = require("nethack");
|
||||
|
||||
5
sys/lib/npm-package/package-lock.json
generated
Normal file
5
sys/lib/npm-package/package-lock.json
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "@neth4ck/neth4ck",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@neth4ck/neth4ck",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "The original NetHack rogue-like game built as a WebAssembly module",
|
||||
"main": "src/nethackShim.js",
|
||||
"scripts": {
|
||||
@@ -13,7 +13,12 @@
|
||||
"nethack",
|
||||
"rogue",
|
||||
"rogue-like",
|
||||
"game"
|
||||
"roguelike",
|
||||
"dungeon",
|
||||
"dungeons",
|
||||
"game",
|
||||
"rpg",
|
||||
"dnd"
|
||||
],
|
||||
"author": "Adam Powers <apowers@ato.ms>",
|
||||
"license": "SEE LICENSE IN LICENSE.md"
|
||||
|
||||
55
sys/lib/npm-package/test/test.js
Normal file
55
sys/lib/npm-package/test/test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
let nethackStart = require("../src/nethackShim.js");
|
||||
Error.stackTraceLimit = 20;
|
||||
|
||||
// debugging to make sure the JavaScript event loop isn't blocked
|
||||
// const {performance} = require("perf_hooks");
|
||||
// let currentTime = 0;
|
||||
// let lastTime = 0;
|
||||
// setInterval(() => {
|
||||
// lastTime = currentTime;
|
||||
// currentTime = performance.now();
|
||||
// console.log("Time since last JavaScript loop:", currentTime-lastTime);
|
||||
// }, 10);
|
||||
|
||||
let Module = {};
|
||||
let winCount = 0;
|
||||
|
||||
/* global globalThis */
|
||||
nethackStart(async function (name, ... args) {
|
||||
switch(name) {
|
||||
case "shim_init_nhwindows":
|
||||
console.log("globalThis.nethackGlobal", globalThis.nethackGlobal);
|
||||
break;
|
||||
case "shim_create_nhwindow":
|
||||
winCount++;
|
||||
console.log("creating window", args, "returning", winCount);
|
||||
return winCount;
|
||||
case "shim_print_glyph":
|
||||
var x = args[1];
|
||||
var y = args[2];
|
||||
var glyph = args[3];
|
||||
|
||||
var ret = globalThis.nethackGlobal.helpers.mapglyphHelper(glyph, x, y, 0);
|
||||
console.log(`GLYPH (${x},${y}): ${String.fromCharCode(ret.ch)}`);
|
||||
return;
|
||||
// case "shim_update_inventory":
|
||||
// globalThis.nethackGlobal.helpers.displayInventory();
|
||||
// return;
|
||||
case "shim_select_menu":
|
||||
return await selectMenu(...args);
|
||||
case "shim_yn_function":
|
||||
case "shim_message_menu":
|
||||
return 121; // 'y'
|
||||
case "shim_nhgetch":
|
||||
case "shim_nh_poskey":
|
||||
return 0;
|
||||
default:
|
||||
console.log(`called doGraphics: ${name} [${args}]`);
|
||||
return 0;
|
||||
}
|
||||
}, Module);
|
||||
|
||||
async function selectMenu(window, how, selected) {
|
||||
Module.setValue(selected, 0, "*");
|
||||
return -1;
|
||||
}
|
||||
@@ -146,5 +146,6 @@ PANICTRACE_LIBC=0
|
||||
# option settings via NETHACKOPTIONS in their environment or via
|
||||
# ~/.nethackrc run-time configuration file.
|
||||
#OPTIONS=!autopickup,fruit:tomato,symset:DECgraphics
|
||||
OPTIONS=perm_invent
|
||||
|
||||
#eof
|
||||
|
||||
@@ -161,7 +161,7 @@ $(TARGETPFX)recover.exe : $(TARGETPFX)recover.o
|
||||
$(TARGET_LINK) $(TARGET_LFLAGS) $(TARGETPFX)recover.o -o $@
|
||||
endif # CROSS_SHARED
|
||||
#
|
||||
ifdef BUILD_LUA
|
||||
ifdef BUILD_TARGET_LUA
|
||||
# Lua lib
|
||||
$(LUACROSSLIB): $(LUALIBOBJS)
|
||||
if [ -f $@ ]; then rm $@; fi;
|
||||
@@ -206,7 +206,7 @@ $(TARGETPFX)lundump.o : $(LUATOP)/src/lundump.c
|
||||
$(TARGETPFX)lutf8lib.o : $(LUATOP)/src/lutf8lib.c
|
||||
$(TARGETPFX)lvm.o : $(LUATOP)/src/lvm.c
|
||||
$(TARGETPFX)lzio.o : $(LUATOP)/src/lzio.c
|
||||
endif # BUILD_LUA
|
||||
endif # BUILD_TARGET_LUA
|
||||
|
||||
ifdef BUILD_PDCURSES
|
||||
ifdef WANT_WIN_CURSES
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#
|
||||
|
||||
ifdef CROSS_TO_MSDOS
|
||||
BUILD_LUA=1
|
||||
BUILD_TARGET_LUA=1
|
||||
BUILD_PDCURSES=1
|
||||
CROSS_SHARED=1
|
||||
override TARGET = msdos
|
||||
@@ -15,7 +15,7 @@ override TARGET_LIBS=
|
||||
endif
|
||||
|
||||
ifdef CROSS_TO_AMIGA
|
||||
BUILD_LUA=1
|
||||
BUILD_TARGET_LUA=1
|
||||
BUILD_PDCURSES=1
|
||||
CROSS_SHARED=1
|
||||
override TARGET = amiga
|
||||
@@ -25,14 +25,14 @@ override TARGET_LIBS=
|
||||
endif
|
||||
|
||||
ifdef CROSS_TO_WASM
|
||||
BUILD_LUA=1
|
||||
BUILD_TARGET_LUA=1
|
||||
override TARGET = wasm
|
||||
override TARGETDIR=../targets/$(TARGET)
|
||||
override TARGETPFX = $(TARGETDIR)/
|
||||
override TARGET_LIBS=
|
||||
endif
|
||||
|
||||
ifdef BUILD_LUA
|
||||
ifdef BUILD_TARGET_LUA
|
||||
#===============-=================================================
|
||||
# LUA library
|
||||
# Source from http://www.lua.org/ftp/lua-5.4.0.tar.gz
|
||||
@@ -65,7 +65,7 @@ BUILDMORE += $(LUACROSSLIB)
|
||||
override TARGET_LIBS += $(LUACROSSLIB) -lm
|
||||
else
|
||||
LUAINCL=
|
||||
endif # BUILD_LUA
|
||||
endif # BUILD_TARGET_LUA
|
||||
|
||||
ifdef BUILD_PDCURSES
|
||||
#===============-=================================================
|
||||
@@ -333,11 +333,11 @@ override TARGET_CFLAGS = $(EMCC_CFLAGS) -c \
|
||||
override TARGET_CXXFLAGS = $(TARGET_CFLAGS)
|
||||
override TARGET_LINK = $(TARGET_CC)
|
||||
override TARGET_LFLAGS= $(EMCC_LFLAGS)
|
||||
override SYSSRC = ../sys/unix/unixmain.c \
|
||||
override SYSSRC = ../sys/lib/libnethackmain.c \
|
||||
../sys/share/ioctl.c ../sys/share/unixtty.c \
|
||||
../sys/unix/unixunix.c ../sys/unix/unixres.c \
|
||||
../win/shim/winshim.c
|
||||
override SYSOBJ= $(TARGETPFX)unixmain.o \
|
||||
override SYSOBJ= $(TARGETPFX)libnethackmain.o \
|
||||
$(TARGETPFX)ioctl.o $(TARGETPFX)unixtty.o \
|
||||
$(TARGETPFX)unixunix.o $(TARGETPFX)unixres.o \
|
||||
$(TARGETPFX)winshim.o
|
||||
@@ -354,6 +354,9 @@ CLEANMORE += rm -f -r $(TARGETDIR)
|
||||
# Rule for file in sys/unix
|
||||
$(TARGETPFX)%.o : ../sys/unix/%.c
|
||||
$(TARGET_CC) $(TARGET_CFLAGS) -c -o$@ $<
|
||||
# Rule for file in sys/lib
|
||||
$(TARGETPFX)%.o : ../sys/lib/%.c
|
||||
$(TARGET_CC) $(TARGET_CFLAGS) -c -o$@ $<
|
||||
# Rule for files in win/shim
|
||||
$(TARGETPFX)%.o : ../win/shim/%.c
|
||||
$(TARGET_CC) $(TARGET_CFLAGS) -c -o$@ $<
|
||||
@@ -377,11 +380,11 @@ $(TARGETPFX)%.o : ../util/%.c
|
||||
$(TARGET_CC) $(TARGET_CFLAGS) -o$@ $<
|
||||
endif # CROSS_SHARED
|
||||
|
||||
ifdef BUILD_LUA
|
||||
ifdef BUILD_TARGET_LUA
|
||||
# Rule for LUA files
|
||||
$(TARGETPFX)%.o : $(LUATOP)/src/%.c
|
||||
$(TARGET_CC) $(TARGET_CFLAGS) $(LUA_FLAGS) -o$@ $<
|
||||
endif # BUILD_LUA
|
||||
endif # BUILD_TARGET_LUA
|
||||
#
|
||||
# End of cross-compiling -PRE section
|
||||
#===============-=================================================
|
||||
|
||||
@@ -166,10 +166,15 @@ VARDATND += $(sort $(VARDATND0))
|
||||
|
||||
ifdef WANT_LIBNH
|
||||
CFLAGS += -DSHIM_GRAPHICS -DNOTTYGRAPHICS -DNOSHELL -DLIBNH
|
||||
WINOBJ = winshim.o
|
||||
LIBNHSYSSRC = ../sys/lib/libnethackmain.c \
|
||||
../sys/share/ioctl.c ../sys/share/unixtty.c \
|
||||
../sys/unix/unixunix.c ../sys/unix/unixres.c \
|
||||
../win/shim/winshim.c
|
||||
LIBNHSYSOBJ= libnethackmain.o ioctl.o unixtty.o unixunix.o \
|
||||
unixres.o winshim.o
|
||||
MOREALL += ( cd src ; $(MAKE) pregame ; $(MAKE) libnethack.a )
|
||||
libnethack.a: $(HOBJ) $(SYSOBJ) $(WINOBJ) ../lib/lua/liblua.a
|
||||
$(AR) rcs $@ $(HOBJ) $(WINOBJ) ../lib/lua/liblua.a
|
||||
libnethack.a: $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a
|
||||
$(AR) rcs $@ $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a
|
||||
@echo "$@ built."
|
||||
winshim.o : ../win/shim/winshim.c $(HACK_H)
|
||||
$(CC) $(CFLAGS) -c -o$@ $<
|
||||
|
||||
@@ -173,10 +173,15 @@ VARDATND += $(sort $(VARDATND0))
|
||||
|
||||
ifdef WANT_LIBNH
|
||||
CFLAGS += -DSHIM_GRAPHICS -DNOTTYGRAPHICS -DNOSHELL -DLIBNH
|
||||
WINOBJ = winshim.o
|
||||
LIBNHSYSSRC = ../sys/lib/libnethackmain.c \
|
||||
../sys/share/ioctl.c ../sys/share/unixtty.c \
|
||||
../sys/unix/unixunix.c ../sys/unix/unixres.c \
|
||||
../win/shim/winshim.c
|
||||
LIBNHSYSOBJ= libnethackmain.o ioctl.o unixtty.o unixunix.o \
|
||||
unixres.o winshim.o
|
||||
MOREALL += ( cd src ; $(MAKE) pregame ; $(MAKE) libnethack.a )
|
||||
libnethack.a: $(HOBJ) $(SYSOBJ) $(WINOBJ) ../lib/lua/liblua.a
|
||||
$(AR) rcs $@ $(HOBJ) $(WINOBJ) ../lib/lua/liblua.a
|
||||
libnethack.a: $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a
|
||||
$(AR) rcs $@ $(HOBJ) $(LIBNHSYSOBJ) ../lib/lua/liblua.a
|
||||
@echo "$@ built."
|
||||
winshim.o : ../win/shim/winshim.c $(HACK_H)
|
||||
$(CC) $(CFLAGS) -c -o$@ $<
|
||||
|
||||
Reference in New Issue
Block a user