载入中...
搜索中...
未找到
PixelWorldModule.cpp
浏览该文件的文档.
2
3#include <simplesquirrel/simplesquirrel.hpp>
4
5#include <algorithm>
6#include <cstdint>
7#include <functional>
8#include <string>
9
10namespace eve::pixelworld {
11
14
16
19
21
22void PixelWorldModule::expose(ssq::Table& table) {
23 auto module = table.addClass(name, PixelWorldModule::create, false);
24 expose(module);
25
26 auto world = table.addClass<PixelWorld>(
27 "PixelWorld", std::function<PixelWorld*()>([]() -> PixelWorld* { return nullptr; }), true);
28 world.addFunc("getMaterial", [](PixelWorld* self, int x, int y) { return self->getMaterial(x, y); });
29 world.addFunc("setMaterial", [](PixelWorld* self, int x, int y, const std::string& material) {
30 self->setMaterial(x, y, material);
31 });
32 world.addFunc("paintCircle", [](PixelWorld* self, int x, int y, int radius, const std::string& material) {
33 return int(self->paintCircle(x, y, radius, material));
34 });
35 world.addFunc("step", [](PixelWorld* self) {
36 return int(self->step().cellsMoved);
37 });
38 world.addFunc("clear", [](PixelWorld* self) { self->clear(); });
39 world.addFunc("getSeed", [](PixelWorld* self) { return std::int64_t(self->seed()); });
40 world.addFunc("getRevision", [](PixelWorld* self) { return std::int64_t(self->revision()); });
41 world.addFunc("getTick", [](PixelWorld* self) { return std::int64_t(self->tickValue()); });
42 world.addFunc("getLastEditSequence", [](PixelWorld* self) {
43 return std::int64_t(self->lastEditSequence());
44 });
45 world.addFunc("getChunkCount", [](PixelWorld* self) { return self->chunkCount(); });
46 world.addFunc("getActiveChunkCount", [](PixelWorld* self) { return self->activeChunkCount(); });
47 world.addFunc("getChangedChunkCountSince", [](PixelWorld* self, int revision) {
48 return int(self->snapshotChangedChunks(revision < 0 ? 0U : std::uint64_t(revision)).size());
49 });
50 world.addFunc("explode", [](PixelWorld* self, int x, int y, int radius, int strength, int heat) {
51 return int(self->explode(x, y, radius, strength,
52 std::int16_t(std::clamp(heat, -32768, 32767))).cellsRemoved);
53 });
54}
55
56void PixelWorldModule::expose(ssq::Class& cls) {
57 cls.addFunc("newWorld", [](PixelWorldModule* self, int seed) {
58 return self->newWorld(std::uint64_t(std::uint32_t(seed)));
59 });
60}
61
62} // namespace eve::pixelworld
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
HSQOBJECT cls
Definition ECS.cpp:21
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
World3D * world
std::uint64_t revision
float radius
std::uint32_t seed
Definition PointSet.cpp:807
Material * material
float size
Definition TreeMesh.cpp:156
Script-facing owner/factory for deterministic pixel material worlds.
PixelWorld * newWorld(std::uint64_t seed=1)
Create a caller-owned world using the supplied deterministic seed.
~PixelWorldModule() override
Pixel world module.
Sparse, chunked, deterministic 2D falling-material world.
Definition PixelWorld.h:224