Removed the old menu system (/menu and /choose) entirely
This commit is contained in:
@@ -222,7 +222,6 @@ enum DrvAction {
|
||||
PLAY_NOTIFY_ACCEPT,
|
||||
PLAY_CALL_EVENT_UPDATE,
|
||||
PLAY_INVOKE_PLAYER,
|
||||
PLAY_INVOKE_CHOOSE,
|
||||
PLAY_INVOKE_LUA_SOURCE,
|
||||
PLAY_RELEASE,
|
||||
};
|
||||
@@ -237,7 +236,6 @@ inline static const char *action_string(DrvAction act) {
|
||||
case PLAY_NOTIFY_ACCEPT: return "PLAY_NOTIFY_ACCEPT";
|
||||
case PLAY_CALL_EVENT_UPDATE: return "PLAY_CALL_EVENT_UPDATE";
|
||||
case PLAY_INVOKE_PLAYER: return "PLAY_INVOKE_PLAYER";
|
||||
case PLAY_INVOKE_CHOOSE: return "PLAY_INVOKE_CHOOSE";
|
||||
case PLAY_INVOKE_LUA_SOURCE: return "PLAY_INVOKE_LUA_SOURCE";
|
||||
case PLAY_RELEASE: return "PLAY_RELEASE";
|
||||
default: return "unknown";
|
||||
@@ -490,11 +488,6 @@ void DrivenEngine::drv_invoke_engio(int64_t place, uint32_t datapklen, const cha
|
||||
queued_invocations_.emplace_back(inv);
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_invoke_choose(int64_t place, uint32_t datapklen, const char *datapk) {
|
||||
Invocation *inv = new Invocation(Invocation::KIND_CHOOSE, visible_actor_id_, place, std::string_view(datapk, datapklen));
|
||||
queued_invocations_.emplace_back(inv);
|
||||
}
|
||||
|
||||
void DrivenEngine::drv_invoke_lua_source(uint32_t srcpklen, const char *srcpk) {
|
||||
Invocation *inv = new Invocation(Invocation::KIND_LUA_SOURCE, visible_actor_id_, visible_actor_id_, std::string_view(srcpk, srcpklen));
|
||||
queued_invocations_.emplace_back(inv);
|
||||
@@ -851,32 +844,6 @@ void replay_invoke_engio(EngineWrapper *w) {
|
||||
////////////////////////
|
||||
|
||||
|
||||
void play_invoke_choose(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk) {
|
||||
assert(w->rlog == nullptr);
|
||||
if (w->wlog != nullptr) {
|
||||
w->wlog->write_cmd_hash(PLAY_INVOKE_CHOOSE, eng::memhash());
|
||||
w->wlog->write_int64(place);
|
||||
w->wlog->write_string(std::string_view(datapk, datapklen));
|
||||
w->wlog->flush();
|
||||
}
|
||||
|
||||
w->engine->drv_invoke_choose(place, datapklen, datapk);
|
||||
}
|
||||
|
||||
void replay_invoke_choose(EngineWrapper *w) {
|
||||
int64_t place = w->rlog->read_int64();
|
||||
std::string srcpack = w->rlog->read_string();
|
||||
if (!w->rlog->good()) {
|
||||
return reset_wrapper(w, "replay log corrupt in replay_invoke_choose");
|
||||
}
|
||||
|
||||
w->engine->drv_invoke_choose(place, srcpack.size(), srcpack.c_str());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////
|
||||
|
||||
|
||||
void play_invoke_lua_source(EngineWrapper *w, uint32_t srcpklen, const char *srcpk) {
|
||||
assert(w->rlog == nullptr);
|
||||
if (w->wlog != nullptr) {
|
||||
@@ -966,7 +933,6 @@ static void replaycore_step(EngineWrapper *w) {
|
||||
case PLAY_NOTIFY_ACCEPT: replay_notify_accept(w); return;
|
||||
case PLAY_CALL_EVENT_UPDATE: replay_invoke_event_update(w); return;
|
||||
case PLAY_INVOKE_PLAYER: replay_invoke_lua_source(w); return;
|
||||
case PLAY_INVOKE_CHOOSE: replay_invoke_lua_source(w); return;
|
||||
case PLAY_INVOKE_LUA_SOURCE: replay_invoke_lua_source(w); return;
|
||||
case PLAY_RELEASE: release(w); return;
|
||||
default: return reset_wrapper(w, "Replay log corrupt in command dispatcher");
|
||||
@@ -1029,7 +995,6 @@ static void init_engine_wrapper_helper(EngineWrapper *w) {
|
||||
w->play_notify_accept = play_notify_accept;
|
||||
w->play_invoke_event_update = play_invoke_event_update;
|
||||
w->play_invoke_engio = play_invoke_engio;
|
||||
w->play_invoke_choose = play_invoke_choose;
|
||||
w->play_invoke_lua_source = play_invoke_lua_source;
|
||||
|
||||
w->replay_initialize = replaycore_initialize;
|
||||
|
||||
@@ -294,7 +294,6 @@ public:
|
||||
uint32_t drv_notify_accept(uint32_t port);
|
||||
void drv_call_event_update(double clock);
|
||||
void drv_invoke_engio(int64_t place, uint32_t datapklen, const char *datapk);
|
||||
void drv_invoke_choose(int64_t place, uint32_t datapklen, const char *datapk);
|
||||
void drv_invoke_lua_source(uint32_t srcpklen, const char *srcpk);
|
||||
|
||||
private:
|
||||
|
||||
@@ -204,13 +204,6 @@ struct EngineWrapper {
|
||||
//
|
||||
void (*play_invoke_engio)(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk);
|
||||
|
||||
// Send an invoke/KIND_CHOOSE
|
||||
//
|
||||
// This is the main pathway for the graphics engine to choose a menu
|
||||
// item or click a user interface button.
|
||||
//
|
||||
void (*play_invoke_choose)(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk);
|
||||
|
||||
// Send an invoke/KIND_LUA_SOURCE
|
||||
//
|
||||
// This is used to update the lua source at runtime, without stopping
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
#include "wrap-string.hpp"
|
||||
#include "wrap-map.hpp"
|
||||
#include "wrap-vector.hpp"
|
||||
#include "util.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "luastack.hpp"
|
||||
|
||||
void Gui::store_global_pointer(lua_State *L, Gui *g) {
|
||||
lua_pushstring(L, "gui");
|
||||
lua_pushlightuserdata(L, g);
|
||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
Gui *Gui::fetch_global_pointer(lua_State *L) {
|
||||
lua_pushstring(L, "gui");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
Gui *result = (Gui *)lua_touserdata(L, -1);
|
||||
if (result == nullptr) {
|
||||
luaL_error(L, "Not currently building a GUI");
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Gui::menu_item(const eng::string &action, const eng::string &label) {
|
||||
GuiElt elt;
|
||||
elt.type_ = GuiElt::TYPE_MENU_ITEM;
|
||||
elt.action_ = action;
|
||||
elt.label_ = label;
|
||||
elts_.push_back(elt);
|
||||
}
|
||||
|
||||
bool Gui::has_action(std::string_view action) const {
|
||||
for (const GuiElt &elt : elts_) {
|
||||
if (elt.action_ == action) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
eng::string Gui::get_action(int64_t index) {
|
||||
if ((index < 0) || (index >= int64_t(elts_.size()))) {
|
||||
return "";
|
||||
}
|
||||
return elts_[index].action();
|
||||
}
|
||||
|
||||
eng::string Gui::menu_debug_string() const {
|
||||
eng::ostringstream oss;
|
||||
int index = 0;
|
||||
for (const GuiElt &elt : elts()) {
|
||||
oss << index << " " << elt.label() << std::endl;
|
||||
index += 1;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
LuaDefine(gui_menu_item, "action,label", "add a menu item to the current gui") {
|
||||
Gui *gui = Gui::fetch_global_pointer(L);
|
||||
LuaArg laction, llabel;
|
||||
LuaDefStack LS(L, laction, llabel);
|
||||
eng::string action = LS.ckstring(laction);
|
||||
eng::string label = LS.ckstring(llabel);
|
||||
if (!sv::has_prefix(action, "cb_")) {
|
||||
luaL_error(L, "menuitem callbacks must start with cb_");
|
||||
}
|
||||
gui->menu_item(action, label);
|
||||
return LS.result();
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
#ifndef GUI_HPP
|
||||
#define GUI_HPP
|
||||
|
||||
#include "wrap-string.hpp"
|
||||
#include "wrap-map.hpp"
|
||||
#include "wrap-vector.hpp"
|
||||
|
||||
#include "luastack.hpp"
|
||||
#include "streambuffer.hpp"
|
||||
|
||||
class GuiElt : public eng::nevernew {
|
||||
friend class Gui;
|
||||
public:
|
||||
enum Type {
|
||||
TYPE_MENU_ITEM,
|
||||
};
|
||||
private:
|
||||
Type type_;
|
||||
eng::string action_;
|
||||
eng::string label_;
|
||||
|
||||
GuiElt() {}
|
||||
public:
|
||||
~GuiElt() {}
|
||||
Type type() const { return type_; }
|
||||
const eng::string &action() const { return action_; }
|
||||
const eng::string &label() const { return label_; }
|
||||
};
|
||||
|
||||
class Gui : public eng::nevernew {
|
||||
public:
|
||||
using EltVec = eng::vector<GuiElt>;
|
||||
private:
|
||||
int64_t place_;
|
||||
EltVec elts_;
|
||||
public:
|
||||
Gui() { place_ = 0; }
|
||||
int64_t place() { return place_; }
|
||||
const EltVec &elts() const { return elts_; }
|
||||
void clear(int64_t p) { place_ = p; elts_.clear(); }
|
||||
bool has_action(std::string_view action) const;
|
||||
void menu_item(const eng::string &action, const eng::string &label);
|
||||
eng::string get_action(int64_t index);
|
||||
eng::string menu_debug_string() const;
|
||||
|
||||
// Put a pointer to a gui into the lua registry.
|
||||
//
|
||||
// All lua commands that manipulate the GUI implicitly
|
||||
// operate on this global gui pointer.
|
||||
//
|
||||
static void store_global_pointer(lua_State *L, Gui *g);
|
||||
static Gui *fetch_global_pointer(lua_State *L);
|
||||
};
|
||||
|
||||
|
||||
#endif // GUI_HPP
|
||||
|
||||
@@ -31,7 +31,6 @@ eng::string Invocation::debug_string() const {
|
||||
oss << "inv[";
|
||||
switch (kind_) {
|
||||
case KIND_INVALID: oss << "invalid"; break;
|
||||
case KIND_CHOOSE: oss << "choose"; break;
|
||||
case KIND_LUA: oss << "lua"; break;
|
||||
case KIND_FLUSH_PRINTS: oss << "flush_prints"; break;
|
||||
case KIND_TICK: oss << "tick"; break;
|
||||
|
||||
@@ -12,13 +12,6 @@
|
||||
//
|
||||
// Nothing.
|
||||
//
|
||||
// KIND_CHOOSE:
|
||||
//
|
||||
// Name of a callback function, in plaintext. The function name
|
||||
// is sanity checked. First, we ensure that it begins with the
|
||||
// prefix "cb_." Then we regenerate the gui, and verify that the
|
||||
// gui has the specified callback as an option.
|
||||
//
|
||||
// KIND_ENGIO:
|
||||
//
|
||||
// First, a function name is read from the datapack. The function
|
||||
@@ -57,7 +50,6 @@ class Invocation : public eng::opnew {
|
||||
public:
|
||||
enum Kind {
|
||||
KIND_INVALID,
|
||||
KIND_CHOOSE,
|
||||
KIND_ENGIO,
|
||||
KIND_LUA,
|
||||
KIND_FLUSH_PRINTS,
|
||||
|
||||
@@ -19,7 +19,6 @@ public:
|
||||
SharedChannel channel_;
|
||||
LuaConsole console_;
|
||||
PrintChanneler print_channeler_;
|
||||
Gui gui_;
|
||||
|
||||
public:
|
||||
void set_initial_state_connect(const eng::string &hostspec) {
|
||||
|
||||
@@ -30,7 +30,6 @@ public:
|
||||
HttpChannelMap http_client_channels_;
|
||||
HttpChannelVec http_server_channels_;
|
||||
int64_t admin_id_;
|
||||
Gui gui_;
|
||||
int next_diff_chan_;
|
||||
double next_tick_;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "world.hpp"
|
||||
#include "idalloc.hpp"
|
||||
#include "animqueue.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "traceback.hpp"
|
||||
#include "pprint.hpp"
|
||||
#include "util.hpp"
|
||||
@@ -48,9 +47,6 @@ World::World(WorldType wt) {
|
||||
// Put the world pointer into the lua registry.
|
||||
World::store_global_pointer(state(), this);
|
||||
|
||||
// Clear the global GUI pointer.
|
||||
Gui::store_global_pointer(state(), nullptr);
|
||||
|
||||
// Clear the lthread state.
|
||||
clear_lthread_state();
|
||||
|
||||
@@ -347,52 +343,6 @@ eng::string World::probe_lua(int64_t actor_id, std::string_view lua) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
|
||||
assert(stack_is_clear());
|
||||
gui->clear(place_id);
|
||||
lua_State *L = state();
|
||||
|
||||
LuaVar actor, place, ugui, func, tangibles, mt, index;
|
||||
LuaExtStack LS(L, actor, place, ugui, func, tangibles, mt, index);
|
||||
|
||||
// Get the actor and place.
|
||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
||||
LS.rawget(actor, tangibles, actor_id);
|
||||
LS.rawget(place, tangibles, place_id);
|
||||
if (!LS.istable(actor) || !LS.istable(place)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the interface closure.
|
||||
LS.getmetatable(mt, place);
|
||||
if (!LS.istable(mt)) {
|
||||
return;
|
||||
}
|
||||
LS.rawget(index, mt, "__index");
|
||||
if (!LS.istable(index)) {
|
||||
return;
|
||||
}
|
||||
LS.rawget(func, index, "interface");
|
||||
if (!LS.isfunction(func)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Call the interface function.
|
||||
lua_pushvalue(L, func.index());
|
||||
lua_pushvalue(L, actor.index());
|
||||
lua_pushvalue(L, place.index());
|
||||
Gui::store_global_pointer(L, gui);
|
||||
open_lthread_state(actor_id, place_id, 0, false, false);
|
||||
eng::string msg = traceback_pcall(L, 2, 0);
|
||||
close_lthread_state();
|
||||
Gui::store_global_pointer(L, nullptr);
|
||||
if (!msg.empty()) {
|
||||
gui->clear(0);
|
||||
util::dprint(msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// This is called from World::update_source, and also
|
||||
// from World::patch_source in the difference transmitter.
|
||||
//
|
||||
@@ -563,7 +513,6 @@ HttpServerResponse World::http_serve(const HttpParser &request) {
|
||||
int oldtop = lua_gettop(L);
|
||||
lua_pushvalue(L, func.index());
|
||||
lua_pushvalue(L, reqtab.index());
|
||||
Gui::store_global_pointer(L, nullptr);
|
||||
open_lthread_state(0, 0, 0, false, false);
|
||||
eng::string msg = traceback_pcall(L, 1, LUA_MULTRET);
|
||||
close_lthread_state();
|
||||
@@ -602,9 +551,6 @@ void World::run_unittests() {
|
||||
|
||||
void World::invoke(const Invocation &inv) {
|
||||
switch (inv.kind()) {
|
||||
case Invocation::KIND_CHOOSE:
|
||||
invoke_choose(inv.actor(), inv.place(), inv.datapack());
|
||||
break;
|
||||
case Invocation::KIND_ENGIO:
|
||||
invoke_engio(inv.actor(), inv.place(), inv.datapack());
|
||||
break;
|
||||
@@ -757,40 +703,6 @@ void World::invoke_lua(int64_t actor_id, int64_t place_id, std::string_view data
|
||||
assert(stack_is_clear());
|
||||
}
|
||||
|
||||
void World::invoke_choose(int64_t actor_id, int64_t place_id, std::string_view datapack) {
|
||||
assert(stack_is_clear());
|
||||
|
||||
// Validate that the action is legal.
|
||||
Gui validation_gui;
|
||||
update_gui(actor_id, place_id, &validation_gui);
|
||||
if (!validation_gui.has_action(datapack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the action starts with "cb_"
|
||||
if (!sv::has_prefix(datapack, "cb_")) {
|
||||
return;
|
||||
}
|
||||
{
|
||||
lua_State *L = state();
|
||||
LuaVar func, invdata;
|
||||
LuaExtStack LS(L, func, invdata);
|
||||
|
||||
|
||||
LS.set(func, datapack);
|
||||
|
||||
// We're planning to add the ability to pass data in as a table.
|
||||
// For now the table is always empty.
|
||||
LS.newtable(invdata);
|
||||
|
||||
// Spawn the thread and run it.
|
||||
int nargs = 1;
|
||||
lua_pushvalue(L, invdata.index());
|
||||
spawn(LS, actor_id, place_id, func, true, nargs, false);
|
||||
}
|
||||
run_scheduled_threads();
|
||||
assert(stack_is_clear());
|
||||
}
|
||||
|
||||
// Read a SimpleDynamic value from the streambuffer and push
|
||||
// it onto the lua stack.
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "sched.hpp"
|
||||
#include "http.hpp"
|
||||
#include "source.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "luasnap.hpp"
|
||||
|
||||
class World;
|
||||
@@ -245,10 +244,6 @@ public:
|
||||
//
|
||||
eng::string probe_lua(int64_t actor_id, std::string_view lua);
|
||||
|
||||
// Probe the 'interface' function of the specified sprite.
|
||||
//
|
||||
void update_gui(int64_t actor_id, int64_t place_id, Gui *gui);
|
||||
|
||||
// Invoke an Invocation object.
|
||||
//
|
||||
// This is the primary dispatcher for all operations that mutate a world model.
|
||||
@@ -395,10 +390,6 @@ private:
|
||||
//
|
||||
static void store_global_pointer(lua_State *L, World *w);
|
||||
|
||||
// Invoke choosing an item from a plan.
|
||||
//
|
||||
void invoke_choose(int64_t actor_id, int64_t place_id, std::string_view datapack);
|
||||
|
||||
// Invoke a player method, used by the graphics engine to control the player.
|
||||
//
|
||||
void invoke_engio(int64_t actor_id, int64_t place_id, std::string_view datapack);
|
||||
|
||||
Reference in New Issue
Block a user