2023-10-19 19:42:33 -04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// DATAPACK
|
|
|
|
|
//
|
|
|
|
|
// Invocations contain a field 'datapack' which contains additional
|
|
|
|
|
// data for the invocation, packed up in a serialized format. Executing
|
|
|
|
|
// the invocation involves unpacking the datapack.
|
|
|
|
|
//
|
|
|
|
|
// The actual contents of the datapack depends on the type of invocation:
|
|
|
|
|
//
|
|
|
|
|
// KIND_INVALID:
|
|
|
|
|
//
|
|
|
|
|
// Nothing.
|
|
|
|
|
//
|
|
|
|
|
// KIND_PLAN:
|
|
|
|
|
//
|
|
|
|
|
// Name of a callback function, in plaintext.
|
|
|
|
|
//
|
|
|
|
|
// KIND_LUA:
|
|
|
|
|
//
|
|
|
|
|
// A block of lua source code, in plaintext.
|
|
|
|
|
//
|
|
|
|
|
// KIND_FLUSH_PRINTS:
|
|
|
|
|
//
|
|
|
|
|
// Line number in ascii.
|
|
|
|
|
//
|
|
|
|
|
// KIND_TICK:
|
|
|
|
|
//
|
|
|
|
|
// Nothing.
|
|
|
|
|
//
|
|
|
|
|
// KIND_LUA_SOURCE:
|
|
|
|
|
//
|
|
|
|
|
// Packaged lua sourcecode. See drvutil::package_lua_source.
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2021-07-19 15:32:34 -04:00
|
|
|
#ifndef INVOCATION_HPP
|
|
|
|
|
#define INVOCATION_HPP
|
|
|
|
|
|
2022-02-23 23:08:28 -05:00
|
|
|
#include "wrap-string.hpp"
|
|
|
|
|
#include "wrap-map.hpp"
|
|
|
|
|
#include "wrap-deque.hpp"
|
2021-07-19 15:32:34 -04:00
|
|
|
#include "streambuffer.hpp"
|
|
|
|
|
|
|
|
|
|
|
2023-10-23 20:57:47 -04:00
|
|
|
class Invocation : public eng::opnew {
|
2021-07-19 15:32:34 -04:00
|
|
|
public:
|
|
|
|
|
enum Kind {
|
|
|
|
|
KIND_INVALID,
|
2023-10-24 00:49:15 -04:00
|
|
|
KIND_CHOOSE,
|
|
|
|
|
KIND_PLAYER,
|
2021-10-15 14:47:12 -04:00
|
|
|
KIND_LUA,
|
2021-10-25 14:47:37 -04:00
|
|
|
KIND_FLUSH_PRINTS,
|
2021-11-26 15:45:36 -05:00
|
|
|
KIND_TICK,
|
2021-12-15 14:18:19 -05:00
|
|
|
KIND_LUA_SOURCE,
|
2021-07-19 15:32:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Kind kind_;
|
|
|
|
|
int64_t actor_;
|
|
|
|
|
int64_t place_;
|
2023-10-19 19:42:33 -04:00
|
|
|
eng::string datapack_;
|
2021-07-19 15:32:34 -04:00
|
|
|
public:
|
|
|
|
|
Invocation();
|
2023-10-19 19:42:33 -04:00
|
|
|
Invocation(Kind kind, int64_t actor, int64_t place, std::string_view datapack);
|
2021-11-16 12:20:11 -05:00
|
|
|
|
|
|
|
|
bool valid() const { return kind_ != KIND_INVALID; }
|
2021-07-19 15:32:34 -04:00
|
|
|
Kind kind() const { return kind_; }
|
|
|
|
|
int64_t actor() const { return actor_; }
|
|
|
|
|
int64_t place() const { return place_; }
|
2023-10-19 19:42:33 -04:00
|
|
|
const eng::string &datapack() const { return datapack_; }
|
2021-07-19 15:32:34 -04:00
|
|
|
|
|
|
|
|
void serialize(StreamBuffer *sb) const;
|
|
|
|
|
void deserialize(StreamBuffer *sb);
|
2021-11-11 16:23:11 -05:00
|
|
|
|
2023-04-10 16:00:47 -04:00
|
|
|
eng::string debug_string() const;
|
2021-07-19 15:32:34 -04:00
|
|
|
};
|
|
|
|
|
|
2023-10-23 20:57:47 -04:00
|
|
|
using UniqueInvocation = std::unique_ptr<Invocation>;
|
|
|
|
|
|
2022-02-24 02:17:41 -05:00
|
|
|
class InvocationQueue : public eng::deque<Invocation> {
|
2021-07-19 15:32:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // INVOCATION_HPP
|