WASM Python integration milestone - game.py runs in browser

Major milestone for issue #158 (Emscripten/WebAssembly build target):
- Python 3.14 successfully initializes and runs in WASM
- mcrfpy module loads and works correctly
- Game scripts execute with full level generation
- Entities (boulders, rats, cyclops, spawn points) placed correctly

Key changes:
- CMakeLists.txt: Add 2MB stack, Emscripten link options, preload files
- platform.h: Add WASM-specific implementations for executable paths
- HeadlessTypes.h: Make Texture/Font/Sound stubs return success
- CommandLineParser.cpp: Guard filesystem operations for WASM
- McRFPy_API.cpp: Add WASM path configuration, debug output
- game.py: Make 'code' module import optional (not available in WASM)
- wasm_stdlib/: Add minimal Python stdlib for WASM (~4MB)

Build with: emmake make (from build-emscripten/)
Test with: node mcrogueface.js

Next steps:
- Integrate VRSFML for actual WebGL rendering
- Create HTML page to host WASM build
- Test in actual browsers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-01-31 05:15:11 -05:00
commit 8c3128e29c
222 changed files with 80639 additions and 25 deletions

View file

@ -493,8 +493,16 @@ class Texture {
public:
Texture() = default;
bool create(unsigned int width, unsigned int height) { size_ = Vector2u(width, height); return true; }
bool loadFromFile(const std::string& filename) { return false; }
bool loadFromMemory(const void* data, size_t size) { return false; }
// In headless mode, pretend texture loading succeeded with dummy dimensions
// This allows game scripts to run without actual graphics
bool loadFromFile(const std::string& filename) {
size_ = Vector2u(256, 256); // Default size for headless textures
return true;
}
bool loadFromMemory(const void* data, size_t size) {
size_ = Vector2u(256, 256);
return true;
}
Vector2u getSize() const { return size_; }
void setSmooth(bool smooth) {}
bool isSmooth() const { return false; }
@ -545,8 +553,9 @@ public:
};
Font() = default;
bool loadFromFile(const std::string& filename) { return false; }
bool loadFromMemory(const void* data, size_t sizeInBytes) { return false; }
// In headless mode, pretend font loading succeeded
bool loadFromFile(const std::string& filename) { return true; }
bool loadFromMemory(const void* data, size_t sizeInBytes) { return true; }
const Info& getInfo() const { static Info info; return info; }
};
@ -723,8 +732,9 @@ public:
class SoundBuffer {
public:
SoundBuffer() = default;
bool loadFromFile(const std::string& filename) { return false; }
bool loadFromMemory(const void* data, size_t sizeInBytes) { return false; }
// In headless mode, pretend sound loading succeeded
bool loadFromFile(const std::string& filename) { return true; }
bool loadFromMemory(const void* data, size_t sizeInBytes) { return true; }
Time getDuration() const { return Time(); }
};
@ -752,7 +762,8 @@ public:
enum Status { Stopped, Paused, Playing };
Music() = default;
bool openFromFile(const std::string& filename) { return false; }
// In headless mode, pretend music loading succeeded
bool openFromFile(const std::string& filename) { return true; }
void play() {}
void pause() {}