diff --git a/build/Spacepunk_Debug.exe b/build/Spacepunk_Debug.exe index 989e468..89a551e 100644 Binary files a/build/Spacepunk_Debug.exe and b/build/Spacepunk_Debug.exe differ diff --git a/build/Spacepunk_Hybrid.exe b/build/Spacepunk_Hybrid.exe index 2a182eb..08b0364 100644 Binary files a/build/Spacepunk_Hybrid.exe and b/build/Spacepunk_Hybrid.exe differ diff --git a/build/Spacepunk_Release.exe b/build/Spacepunk_Release.exe index f1a59af..35b4b2b 100644 Binary files a/build/Spacepunk_Release.exe and b/build/Spacepunk_Release.exe differ diff --git a/src/ArrayList.hpp b/src/ArrayList.hpp index 2e6fced..c728eac 100644 --- a/src/ArrayList.hpp +++ b/src/ArrayList.hpp @@ -3,9 +3,7 @@ #pragma once #include "Main.hpp" - -#include -#include +#include "sol.hpp" // templated ArrayList (similar to std::vector) // adding or removing elements can unsort the list. @@ -363,56 +361,43 @@ class ArrayList { // exposes this list type to a script // @param lua The script engine to expose to - // @param name The type name in lua - static void exposeToScript(lua_State* lua, const char* name) { - typedef T* (ArrayList::*ArrayFn)(); - ArrayFn getArray = static_cast(&ArrayList::getArray); - - typedef const T* (ArrayList::*ArrayConstFn)() const; - ArrayConstFn getArrayConst = static_cast(&ArrayList::getArray); - - typedef ArrayList& (ArrayList::*CopyFn)(const ArrayList&); - CopyFn copy = static_cast(&ArrayList::copy); - - typedef T& (ArrayList::*PeekFn)(); - PeekFn peek = static_cast(&ArrayList::peek); - - typedef const T& (ArrayList::*PeekConstFn)() const; - PeekConstFn peekConst = static_cast(&ArrayList::peek); - - typedef T& (ArrayList::*GetFn)(size_t); - GetFn get = static_cast(&ArrayList::get); - - typedef const T& (ArrayList::*GetConstFn)(size_t) const; - GetConstFn getConst = static_cast(&ArrayList::get); - - luabridge::getGlobalNamespace(lua) - .beginClass>(name) - .addConstructor() - .addFunction("getArray", getArray) - .addFunction("getArrayConst", getArrayConst) - .addFunction("getSize", &ArrayList::getSize) - .addFunction("getMaxSize", &ArrayList::getMaxSize) - .addFunction("empty", &ArrayList::empty) - .addFunction("alloc", &ArrayList::alloc) - .addFunction("resize", &ArrayList::resize) - .addFunction("clear", &ArrayList::clear) - .addFunction("copy", copy) - .addFunction("push", &ArrayList::push) - .addFunction("insert", &ArrayList::insert) - .addFunction("pop", &ArrayList::pop) - .addFunction("peek", peek) - .addFunction("peekConst", peekConst) - .addFunction("remove", &ArrayList::remove) - .addFunction("removeAndRearrange", &ArrayList::removeAndRearrange) - .addFunction("get", get) - .addFunction("getConst", getConst) - .endClass() - ; + // @param luaTypeName The type name in lua + static void exposeToScript(sol::state& lua, const char* luaTypeName) + { + //First identify the constructors. + sol::constructors()> constructors; + + //Then do the thing. + sol::usertype> usertype(constructors, + //"getArray", sol::resolve(&ArrayList::getArray), //This is not exposed because bad juju. GCC will kill you. (When passing in World* type, it hits strange errors for some reason...is it because it's an abstract base class?) + //"getArrayConst", sol::resolve(&ArrayList::getArray), + "getSize", &ArrayList::getSize, + "getMaxSize", &ArrayList::getMaxSize, + "empty", &ArrayList::empty, + "alloc", &ArrayList::alloc, + "resize", &ArrayList::resize, + "clear", &ArrayList::clear, + "copy", sol::resolve&(const ArrayList&)>(&ArrayList::copy), + "push", &ArrayList::push, + "insert", &ArrayList::insert, + "pop", &ArrayList::pop, + "peek", sol::resolve(&ArrayList::peek), + "peekConst", sol::resolve(&ArrayList::peek), + "remove", &ArrayList::remove, + "removeAndRearrange", &ArrayList::removeAndRearrange, + "get", sol::resolve(&ArrayList::get), + "getConst", sol::resolve(&ArrayList::get) + ); + + //Then do the thing. + //sol::usertype> usertype(constructors); + + //Finally register the thing. + lua.set_usertype(luaTypeName, usertype); } private: T* arr = nullptr; // array data size_t size = 0; // current array capacity size_t maxSize = 0; // maximum array capacity -}; \ No newline at end of file +}; diff --git a/src/BBox.cpp b/src/BBox.cpp index 48ec9e8..c0252b6 100644 --- a/src/BBox.cpp +++ b/src/BBox.cpp @@ -647,3 +647,33 @@ void BBox::serialize(FileInterface* file) { file->property("mass", mass); } } + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeBBox() { + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + sol::base_classes, sol::bases(), + "nearestCeiling", &BBox::nearestCeiling, + //"nearestFloor", &BBox::nearestFloor, + "distToCeiling", &BBox::distToCeiling, + "distToFloor", &BBox::distToFloor, + "getShape", &BBox::getShape, + "getMass", &BBox::getMass, + "isEnabled", &BBox::isEnabled, + "setEnabled", &BBox::setEnabled, + "setShape", &BBox::setShape, + "setMass", &BBox::setMass, + "findAllOverlappingEntities", &BBox::findAllOverlappingEntities + ); + + //Finally register the thing. + lua.set_usertype("BBox", usertype); + } + + LinkedList::exposeToScript(lua, "LinkedListBBoxPtr", "NodeBBoxPtr"); + ArrayList::exposeToScript(lua, "ArrayListBBoxPtr"); +} diff --git a/src/Button.hpp b/src/Button.hpp index 6bff8ba..c559c07 100644 --- a/src/Button.hpp +++ b/src/Button.hpp @@ -2,6 +2,8 @@ #pragma once +#include + #define GLM_FORCE_RADIANS #include @@ -58,7 +60,7 @@ class Button { const bool isHighlighted() const { return highlighted; } const bool isDisabled() const { return disabled; } const style_t getStyle() const { return style; } - Script::Args& getParams() { return params; } + const Script::Args& getParams() const { return params; } void setBorder(const int _border) { border = _border; } void setPos(const int x, const int y) { size.x = x; size.y = y; } @@ -73,23 +75,43 @@ class Button { void setStyle(const style_t _style) { style = _style; } void setPressed(const bool _pressed) { reallyPressed = _pressed; } + template + void addParam(T param) + { + if (nullptr == parent) + { + assert(0); + return; + } + + Script* scripter = parent->getScriptEngine(); + if (nullptr == scripter) + { + assert(0); + return; + } + + scripter->addParam(param, params); + } + private: - Frame* parent = nullptr; // parent frame - - String name; // internal button name - String text; // button text, if any - String icon; // icon, if any (supersedes text content) - String tooltip; // if empty, button has no tooltip; otherwise, it does - Script::Args params; // optional function parameters to use when the button function is called - int border = 3; // size of the button border in pixels - Rect size; // size and position of the button within its parent frame - bool pressed = false; // button pressed state - bool reallyPressed = false; // the "actual" button state, pre-mouse process - bool highlighted = true; // true if mouse is hovering over button; false otherwise - glm::vec4 color; // the button's color - glm::vec4 textColor; // text color - style_t style = STYLE_NORMAL; // button style - bool disabled=false; // if true, the button is invisible and unusable - Uint32 highlightTime = 0; // records the time since the button was highlighted - Image* iconImg = nullptr; // the icon image + Frame* parent = nullptr; // parent frame + + String name; // internal button name + String text; // button text, if any + String icon; // icon, if any (supersedes text content) + String tooltip; // if empty, button has no tooltip; otherwise, it does + //std::vector params; // optional function parameters to use when the button function is called. + Script::Args params; // optional function parameters to use when the button function is called. + int border = 3; // size of the button border in pixels + Rect size; // size and position of the button within its parent frame + bool pressed = false; // button pressed state + bool reallyPressed = false; // the "actual" button state, pre-mouse process + bool highlighted = true; // true if mouse is hovering over button; false otherwise + glm::vec4 color; // the button's color + glm::vec4 textColor; // text color + style_t style = STYLE_NORMAL; // button style + bool disabled=false; // if true, the button is invisible and unusable + Uint32 highlightTime = 0; // records the time since the button was highlighted + Image* iconImg = nullptr; // the icon image }; \ No newline at end of file diff --git a/src/Camera.cpp b/src/Camera.cpp index 82f9f5a..cca285d 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -303,4 +303,36 @@ void Camera::drawDebug() { void Camera::onFrameDrawn() { ++framesDrawn; -} \ No newline at end of file +} + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeCamera() { + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + sol::base_classes, sol::bases(), + "setupProjection", &Camera::setupProjection, + "worldPosToScreenPos", &Camera::worldPosToScreenPos, + "screenPosToWorldRay", &Camera::screenPosToWorldRay, + "getClipNear", &Camera::getClipNear, + "getClipFar", &Camera::getClipFar, + "getWin", &Camera::getWin, + "getFov", &Camera::getFov, + "isOrtho", &Camera::isOrtho, + "setClipNear", &Camera::setClipNear, + "setClipFar", &Camera::setClipFar, + "setWin", &Camera::setWin, + "setFov", &Camera::setFov, + "setOrtho", &Camera::setOrtho + ); + + //Finally register the thing. + lua.set_usertype("Camera", usertype); + } + + LinkedList::exposeToScript(lua, "LinkedListCameraPtr", "NodeCameraPtr"); + ArrayList::exposeToScript(lua, "ArrayListCameraPtr"); +} diff --git a/src/Character.cpp b/src/Character.cpp index 7d41066..988d440 100644 --- a/src/Character.cpp +++ b/src/Character.cpp @@ -113,4 +113,55 @@ void Character::serialize(FileInterface * file) { file->property("perception", perception); file->property("charisma", charisma); file->property("luck", luck); -} \ No newline at end of file +} + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeCharacter() { + { + auto characterType = lua.create_simple_usertype(sol::constructors(), + sol::base_classes, sol::bases() + ); + + //Bind all of the editor's member functions. + characterType.set("getHp", &Character::getHp); + characterType.set("getMp", &Character::getMp); + characterType.set("getSex", &Character::getSex); + characterType.set("getLevel", &Character::getLevel); + characterType.set("getXp", &Character::getXp); + characterType.set("getHunger", &Character::getHunger); + characterType.set("getNanoMatter", &Character::getNanoMatter); + characterType.set("getBioMatter", &Character::getBioMatter); + characterType.set("getNeuroThread", &Character::getNeuroThread); + characterType.set("getGold", &Character::getGold); + characterType.set("getStrength", &Character::getStrength); + characterType.set("getDexterity", &Character::getDexterity); + characterType.set("getIntelligence", &Character::getIntelligence); + characterType.set("getConstitution", &Character::getConstitution); + characterType.set("getPerception", &Character::getPerception); + characterType.set("getCharisma", &Character::getCharisma); + characterType.set("getLuck", &Character::getLuck); + characterType.set("setHp", &Character::setHp); + characterType.set("setMp", &Character::setMp); + characterType.set("setSex", &Character::setSex); + characterType.set("setLevel", &Character::setLevel); + characterType.set("setXp", &Character::setXp); + characterType.set("setHunger", &Character::setHunger); + characterType.set("setNanoMatter", &Character::setNanoMatter); + characterType.set("setBioMatter", &Character::setBioMatter); + characterType.set("setNeuroThread", &Character::setNeuroThread); + characterType.set("setGold", &Character::setGold); + characterType.set("setStrength", &Character::setStrength); + characterType.set("setDexterity", &Character::setDexterity); + characterType.set("setIntelligence", &Character::setIntelligence); + characterType.set("setConstitution", &Character::setConstitution); + characterType.set("setPerception", &Character::setPerception); + characterType.set("setCharisma", &Character::setCharisma); + characterType.set("setLuck", &Character::setLuck); + + //Finally register the thing. + lua.set_usertype("Character", characterType); + } + + LinkedList::exposeToScript(lua, "LinkedListCharacterPtr", "NodeCharacterPtr"); + ArrayList::exposeToScript(lua, "ArrayListCharacterPtr"); +} diff --git a/src/Client.cpp b/src/Client.cpp index 7ec3381..f18f031 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -30,7 +30,7 @@ Client::Client() { Client::~Client() { if( script ) { - script->dispatch("term"); + script->dispatchFunction("term"); delete script; } if( gui ) { @@ -67,7 +67,7 @@ void Client::init() { } script->load("scripts/client/main.lua"); - script->dispatch("init"); + script->dispatchFunction("init"); } void Client::handleNetMessages() { @@ -681,7 +681,7 @@ void Client::preProcess() { } if( framesToRun ) { renderer->clearBuffers(); - script->dispatch("preprocess"); + script->dispatchFunction("preprocess"); if( editor ) { editor->preProcess(); @@ -706,7 +706,7 @@ void Client::process() { Game::process(); for( Uint32 frame=0; framedispatch("process"); + script->dispatchFunction("process"); // drop down console if( consoleAllowed ) { @@ -877,7 +877,7 @@ void Client::postProcess() { renderer->swapWindow(); // run script - script->dispatch("postprocess"); + script->dispatchFunction("postprocess"); if( editor ) { editor->postProcess(); diff --git a/src/Component.cpp b/src/Component.cpp index c475c31..a893a82 100644 --- a/src/Component.cpp +++ b/src/Component.cpp @@ -799,7 +799,7 @@ void Component::serializeComponents(FileInterface* file) { } } -void Component::shootLaser(const glm::mat4& mat, WideVector& color, float size, float life) { +void Component::shootLaser(const glm::mat4& mat, const WideVector& color, float size, float life) { Vector start = Vector(mat[3].x, mat[3].z, -mat[3].y); //glm::mat4 endMat = glm::translate(mat, glm::vec3(-1024.f, 0.f, 0.f)); Vector end = start + (entity->getAng() + entity->getLookDir()).toVector() * 10000.f; @@ -813,4 +813,65 @@ void Component::shootLaser(const glm::mat4& mat, WideVector& color, float size, } } world->addLaser(start, end, color, size, life); -} \ No newline at end of file +} + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeComponent() { + { + auto componentType = lua.create_simple_usertype(sol::constructors()); + + //Bind all of the component's member functions. + componentType.set("getType", &Component::getType); + componentType.set("getParent", &Component::getParent); + componentType.set("isEditorOnly", &Component::isEditorOnly); + componentType.set("isUpdateNeeded", &Component::isUpdateNeeded); + componentType.set("getUID", &Component::getUID); + componentType.set("getName", &Component::getName); + componentType.set("getLocalPos", &Component::getLocalPos); + componentType.set("getLocalAng", &Component::getLocalAng); + componentType.set("getLocalScale", &Component::getLocalScale); + componentType.set("getGlobalPos", &Component::getGlobalPos); + componentType.set("getGlobalAng", &Component::getGlobalAng); + componentType.set("getGlobalScale", &Component::getGlobalScale); + componentType.set("setEditorOnly", &Component::setEditorOnly); + componentType.set("setName", &Component::setName); + componentType.set("setLocalPos", &Component::setLocalPos); + componentType.set("setLocalAng", &Component::setLocalAng); + componentType.set("setLocalScale", &Component::setLocalScale); + componentType.set("setLocalMat", &Component::setLocalMat); + componentType.set("update", &Component::update); + componentType.set("remove", &Component::remove); + componentType.set("checkCollision", &Component::checkCollision); + componentType.set("hasComponent", &Component::hasComponent); + componentType.set("removeComponentByName", &Component::removeComponentByName); + componentType.set("removeComponentByUID", &Component::removeComponentByUID); + componentType.set("addComponent", &Component::addComponent); + componentType.set("addBBox", &Component::addComponent); + componentType.set("addModel", &Component::addComponent); + componentType.set("addCamera", &Component::addComponent); + componentType.set("addLight", &Component::addComponent); + componentType.set("addSpeaker", &Component::addComponent); + componentType.set("addCharacter", &Component::addComponent); + componentType.set("findComponentByName", &Component::findComponentByName); + componentType.set("findBBoxByName", &Component::findComponentByName); + componentType.set("findModelByName", &Component::findComponentByName); + componentType.set("findLightByName", &Component::findComponentByName); + componentType.set("findCameraByName", &Component::findComponentByName); + componentType.set("findSpeakerByName", &Component::findComponentByName); + componentType.set("findCharacterByName", &Component::findComponentByName); + componentType.set("rotate", &Component::rotate); + componentType.set("translate", &Component::translate); + componentType.set("scale", &Component::scale); + componentType.set("revertRotation", &Component::revertRotation); + componentType.set("revertTranslation", &Component::revertTranslation); + componentType.set("revertScale", &Component::revertScale); + componentType.set("revertToIdentity", &Component::revertToIdentity); + componentType.set("shootLaser", &Component::shootLaser); + + //Finally register the thing. + lua.set_usertype("Component", componentType); + } + + LinkedList::exposeToScript(lua, "LinkedListComponentPtr", "NodeComponentPtr"); + ArrayList::exposeToScript(lua, "ArrayListComponentPtr"); +} diff --git a/src/Component.hpp b/src/Component.hpp index 4339752..ff70c0e 100644 --- a/src/Component.hpp +++ b/src/Component.hpp @@ -99,7 +99,7 @@ class Component { // @param color The laser's color // @param size The laser's size // @param life The laser's lifespan (in ticks, 60 ticks = 1 sec) - void shootLaser(const glm::mat4& mat, WideVector& color, float size, float life); + void shootLaser(const glm::mat4& mat, const WideVector& color, float size, float life); // find all components of a given type // @param type the type of component to search for diff --git a/src/Editor.cpp b/src/Editor.cpp index fc493e4..97fb32a 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -293,8 +293,8 @@ void Editor::buttonEntityAddComponent(unsigned int uid) { rect.x = border * 2 + (30 + border) * (c % 5); rect.w = 30; rect.y = border * 2 + (30 + border) * (c / 5); rect.h = 30; - button->getParams().addInt(uid); - button->getParams().addInt(c); + button->addParam(uid); + button->addParam(c); button->setTooltip(Component::typeStr[c]); button->setIcon(Component::typeIcon[c]); button->setSize(rect); @@ -1126,7 +1126,7 @@ void Editor::buttonMapSettings() { buttonRect.y = rect.h - 36 - (36 * (4 - rotate / 90)); buttonRect.h = 30; button->setSize(buttonRect); button->setName("buttonRotate"); - button->getParams().addInt(rotate); + button->addParam(rotate); StringBuf<16> text("Rotate %d*", rotate); button->setText(text.get()); @@ -2125,9 +2125,9 @@ void Editor::initGUI(const Rect& camRect) { field->setColor(glm::vec4(.2f,.2f,1.f,1.f)); break; } - //field->getParams().addInt(component->getUID()); - field->getParams().addInt(channel); - field->getParams().addInt(color); + // //field->addParam(component->getUID()); + // field->addParam(channel); //Why are script parameters being added for a field that exists in a frame without a Script engine? + // field->addParam(color); char f[16]; if( color==channel ) { @@ -2227,7 +2227,7 @@ void Editor::initGUI(const Rect& camRect) { if( def->exposedInEditor ) { Frame::entry_t* entry = frame->addEntry("spawn",true); entry->text = def->entity.getName(); - entry->params.addString(def->entity.getName()); + entry->addParam(def->entity.getName()); entry->color = glm::vec4(1.f); } } @@ -5520,7 +5520,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setSize(size); field->setEditable(true); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); field->setText(component->getName()); } @@ -5531,7 +5531,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& Button* button = properties.addButton("buttonExpand"); button->setIcon("images/gui/arrow_down.png"); button->setStyle(Button::STYLE_NORMAL); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); button->setBorder(2); Rect size; @@ -5547,7 +5547,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& Button* button = properties.addButton("buttonCollapse"); button->setIcon("images/gui/arrow_up.png"); button->setStyle(Button::STYLE_NORMAL); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); button->setBorder(2); Rect size; @@ -5606,8 +5606,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(0); - field->getParams().addInt(component->getUID()); + field->addParam(0); + field->addParam(component->getUID()); char x[16]; snprintf(x,16,"%.1f",component->getLocalPos().x); @@ -5646,8 +5646,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(1); - field->getParams().addInt(component->getUID()); + field->addParam(1); + field->addParam(component->getUID()); char y[16]; snprintf(y,16,"%.1f",component->getLocalPos().y); @@ -5687,8 +5687,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(2); - field->getParams().addInt(component->getUID()); + field->addParam(2); + field->addParam(component->getUID()); char z[16]; snprintf(z,16,"%.1f",component->getLocalPos().z); @@ -5741,8 +5741,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(0); - field->getParams().addInt(component->getUID()); + field->addParam(0); + field->addParam(component->getUID()); char roll[16]; snprintf(roll,16,"%.1f",component->getLocalAng().degreesRoll()); @@ -5781,8 +5781,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(1); - field->getParams().addInt(component->getUID()); + field->addParam(1); + field->addParam(component->getUID()); char pitch[16]; snprintf(pitch,16,"%.1f",component->getLocalAng().degreesPitch()); @@ -5822,8 +5822,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(2); - field->getParams().addInt(component->getUID()); + field->addParam(2); + field->addParam(component->getUID()); char yaw[16]; snprintf(yaw,16,"%.1f",component->getLocalAng().degreesYaw()); @@ -5876,8 +5876,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(0); - field->getParams().addInt(component->getUID()); + field->addParam(0); + field->addParam(component->getUID()); char x[16]; snprintf(x,16,"%.1f",component->getLocalScale().x); @@ -5916,8 +5916,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(1); - field->getParams().addInt(component->getUID()); + field->addParam(1); + field->addParam(component->getUID()); char y[16]; snprintf(y,16,"%.1f",component->getLocalScale().y); @@ -5957,8 +5957,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(2); - field->getParams().addInt(component->getUID()); + field->addParam(2); + field->addParam(component->getUID()); char z[16]; snprintf(z,16,"%.1f",component->getLocalScale().z); @@ -6006,8 +6006,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& for( Uint32 c = 0; c < BBox::shape_t::SHAPE_MAX; ++c ) { Frame::entry_t* entry = frame->addEntry("entry",true); entry->text = BBox::shapeStr[c]; - entry->params.addInt(component->getUID()); - entry->params.addString(BBox::shapeStr[c]); + entry->addParam(component->getUID()); + entry->addParam(BBox::shapeStr[c]); entry->color = glm::vec4(1.f); } } @@ -6021,7 +6021,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& button->setPressed( bbox->isEnabled() ); button->setTooltip("Toggles the BBox's collision on and off."); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); Rect size; size.x = x + border*2; size.w = 30; @@ -6071,7 +6071,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i,16,"%.2f",bbox->getMass()); @@ -6135,7 +6135,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setEditable(true); field->setText(model->getMesh()); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); } // material label @@ -6174,7 +6174,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setEditable(true); field->setText(model->getMaterial()); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); } // depth fail material label @@ -6213,7 +6213,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setEditable(true); field->setText(model->getDepthFailMat()); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); } // animation label @@ -6252,7 +6252,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setEditable(true); field->setText(model->getAnimation()); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); } // custom color flag @@ -6263,7 +6263,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& button->setStyle(Button::STYLE_CHECKBOX); button->setPressed( model->getShaderVars().customColorEnabled == GL_TRUE ); button->setTooltip("Enables custom color values for each color channel"); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); Rect size; size.x = border*2 + x; size.w = 30; @@ -6377,9 +6377,9 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setColor(glm::vec4(.2f,.2f,1.f,1.f)); break; } - field->getParams().addInt(component->getUID()); - field->getParams().addInt(channel); - field->getParams().addInt(color); + field->addParam(component->getUID()); + field->addParam(channel); + field->addParam(color); char f[16]; snprintf(f,16,"%.2f",(*vector)[color]); @@ -6443,7 +6443,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char r[16]; snprintf(r,16,"%.2f",light->getColor().x); @@ -6482,7 +6482,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char g[16]; snprintf(g,16,"%.2f",light->getColor().y); @@ -6522,7 +6522,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setTabDestFrame(dest.get()); field->setTabDestField("field"); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char b[16]; snprintf(b,16,"%.2f",light->getColor().z); @@ -6556,7 +6556,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i,16,"%.2f",light->getIntensity()); @@ -6605,7 +6605,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char r[16]; snprintf(r,16,"%.1f",light->getRadius()); @@ -6654,7 +6654,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char r[16]; snprintf(r,16,"%.1f",light->getArc()); @@ -6685,7 +6685,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& button->setPressed( light->isShadow() ); button->setTooltip("Toggles the light's shadow on and off."); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); Rect size; size.x = x + border*2; size.w = 30; @@ -6742,8 +6742,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& for( Uint32 c = 0; c < Light::shape_t::SHAPE_NUM; ++c ) { Frame::entry_t* entry = frame->addEntry("entry",true); entry->text = Light::shapeStr[c]; - entry->params.addInt(component->getUID()); - entry->params.addString(Light::shapeStr[c]); + entry->addParam(component->getUID()); + entry->addParam(Light::shapeStr[c]); entry->color = glm::vec4(1.f); } } @@ -6780,7 +6780,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char f[16]; snprintf(f,16,"%.1f",camera->getClipNear()); @@ -6829,7 +6829,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char f[16]; snprintf(f,16,"%.1f",camera->getClipFar()); @@ -6878,7 +6878,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i,16,"%d",camera->getWin().x); @@ -6927,7 +6927,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i,16,"%d",camera->getWin().y); @@ -6976,7 +6976,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i,16,"%d",camera->getWin().w); @@ -7025,7 +7025,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i,16,"%d",camera->getWin().h); @@ -7074,7 +7074,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f,1.f,1.f,1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i,16,"%d",camera->getFov()); @@ -7105,7 +7105,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& button->setPressed( camera->isOrtho() ); button->setTooltip("Causes the camera to use an orthographic projection"); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); Rect size; size.x = x + border*2; size.w = 30; @@ -7169,7 +7169,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setEditable(true); field->setText(speaker->getDefaultSound()); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); } // default range label @@ -7211,7 +7211,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& snprintf(data,16,"%.1f",speaker->getDefaultRange()); field->setText(data); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); } // default loop flag @@ -7223,7 +7223,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& button->setPressed( speaker->isDefaultLoop() ); button->setTooltip("Causes the speaker to loop the default sound effect"); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); Rect size; size.x = x + border*2; size.w = 30; @@ -7294,7 +7294,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getHp()); @@ -7343,7 +7343,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getMp()); @@ -7385,8 +7385,8 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& for( Uint32 c = 0; c < Character::sex_t::SEX_MAX; ++c ) { Frame::entry_t* entry = frame->addEntry("entry",true); entry->text = Character::sexStr[c]; - entry->params.addInt(component->getUID()); - entry->params.addString(Character::sexStr[c]); + entry->addParam(component->getUID()); + entry->addParam(Character::sexStr[c]); entry->color = glm::vec4(1.f); } @@ -7432,7 +7432,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getLevel()); @@ -7481,7 +7481,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getXp()); @@ -7530,7 +7530,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getHunger()); @@ -7594,7 +7594,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getNanoMatter()); @@ -7643,7 +7643,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getBioMatter()); @@ -7692,7 +7692,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getNeuroThread()); @@ -7741,7 +7741,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getGold()); @@ -7805,7 +7805,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getStrength()); @@ -7854,7 +7854,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getDexterity()); @@ -7903,7 +7903,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getIntelligence()); @@ -7952,7 +7952,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getConstitution()); @@ -8001,7 +8001,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getPerception()); @@ -8050,7 +8050,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getCharisma()); @@ -8099,7 +8099,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& field->setJustify(Field::RIGHT); field->setColor(glm::vec4(1.f, 1.f, 1.f, 1.f)); - field->getParams().addInt(component->getUID()); + field->addParam(component->getUID()); char i[16]; snprintf(i, 16, "%d", character->getLuck()); @@ -8138,7 +8138,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& Button* button = properties.addButton("buttonAdd"); button->setIcon("images/gui/add.png"); button->setStyle(Button::STYLE_NORMAL); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); button->setBorder(2); button->setTooltip("Add a sub-component."); @@ -8153,7 +8153,7 @@ void Editor::componentGUI(Frame& properties, Component* component, int& x, int& Button* button = properties.addButton("buttonDelete"); button->setIcon("images/gui/delete.png"); button->setStyle(Button::STYLE_NORMAL); - button->getParams().addInt(component->getUID()); + button->addParam(component->getUID()); button->setBorder(2); button->setTooltip("Delete this component."); @@ -8849,7 +8849,7 @@ void Editor::updateGUI(Frame& gui) { button->setStyle(Button::STYLE_CHECKBOX); button->setPressed( firstEntity->isFlag( static_cast( (int)floor(pow(2,c)) ) ) ); button->setTooltip(Entity::flagDesc[c]); - button->getParams().addInt(1<addParam(1< size; size.x = border*2; size.w = 30; @@ -8948,7 +8948,7 @@ void Editor::updateGUI(Frame& gui) { text.format("%s:%s", pair.a.get(), pair.b.get()); entry->text = text.get(); entry->color = glm::vec4(1.f); - entry->params.addString(text); + entry->addParam(text); } } @@ -8964,7 +8964,7 @@ void Editor::updateGUI(Frame& gui) { Button* button = properties->addButton("buttonAdd"); button->setIcon("images/gui/add.png"); button->setStyle(Button::STYLE_NORMAL); - button->getParams().addInt(0); + button->addParam(0); button->setBorder(2); button->setTooltip("Add a sub-component."); @@ -9437,4 +9437,114 @@ static int console_editor(int argc, const char** argv) { return 0; } +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeEditor(Editor& _editor) { + { + auto editorType = lua.create_simple_usertype(sol::constructors()); //Supposedly this method is faster at compile time? Or at the very least it uses less memory. At any rate, the other method exceeds the maximum default template instantiation depth for G++. + + //Bind all of the editor's member functions. + editorType.set("setEditingMode", &Editor::setEditingMode); + editorType.set("setEditingMode", &Editor::setEditingMode); + editorType.set("setCeilingMode", &Editor::setCeilingMode); + editorType.set("setHighlightedObj", &Editor::setHighlightedObj); + editorType.set("setWidgetMode", &Editor::setWidgetMode); + editorType.set("selectEntity", &Editor::selectEntity); + editorType.set("toggleSelectEntity", &Editor::toggleSelectEntity); + editorType.set("selectAllEntities", &Editor::selectAllEntities); + editorType.set("selectEntityForSpawn", &Editor::selectEntityForSpawn); + editorType.set("entitiesName", &Editor::entitiesName); + editorType.set("entitiesScript", &Editor::entitiesScript); + editorType.set("entitiesFlag", &Editor::entitiesFlag); + editorType.set("entitiesSave", &Editor::entitiesSave); + editorType.set("entityKeyValueEnter", &Editor::entityKeyValueEnter); + editorType.set("entityKeyValueRemove", &Editor::entityKeyValueRemove); + editorType.set("entityKeyValueSelect", &Editor::entityKeyValueSelect); + editorType.set("entityAddComponent", &Editor::entityAddComponent); + editorType.set("entityRemoveComponent", &Editor::entityRemoveComponent); + editorType.set("entityBBoxShape", &Editor::entityBBoxShape); + editorType.set("entityBBoxEnabled", &Editor::entityBBoxEnabled); + editorType.set("entityBBoxMass", &Editor::entityBBoxMass); + editorType.set("entityModelLoadMesh", &Editor::entityModelLoadMesh); + editorType.set("entityModelLoadMaterial", &Editor::entityModelLoadMaterial); + editorType.set("entityModelLoadDepthFailMat", &Editor::entityModelLoadDepthFailMat); + editorType.set("entityModelLoadAnimation", &Editor::entityModelLoadAnimation); + editorType.set("entityModelCustomColor", &Editor::entityModelCustomColor); + editorType.set("entityModelCustomColorChannel", &Editor::entityModelCustomColorChannel); + editorType.set("entityLightColorR", &Editor::entityLightColorR); + editorType.set("entityLightColorG", &Editor::entityLightColorG); + editorType.set("entityLightColorB", &Editor::entityLightColorB); + editorType.set("entityLightIntensity", &Editor::entityLightIntensity); + editorType.set("entityLightRadius", &Editor::entityLightRadius); + editorType.set("entityLightArc", &Editor::entityLightArc); + editorType.set("entityLightShadow", &Editor::entityLightShadow); + editorType.set("entityLightShape", &Editor::entityLightShape); + editorType.set("entityCameraClipNear", &Editor::entityCameraClipNear); + editorType.set("entityCameraClipFar", &Editor::entityCameraClipFar); + editorType.set("entityCameraWinX", &Editor::entityCameraWinX); + editorType.set("entityCameraWinY", &Editor::entityCameraWinY); + editorType.set("entityCameraWinW", &Editor::entityCameraWinW); + editorType.set("entityCameraWinH", &Editor::entityCameraWinH); + editorType.set("entityCameraFOV", &Editor::entityCameraFOV); + editorType.set("entityCameraOrtho", &Editor::entityCameraOrtho); + editorType.set("entitySpeakerDefaultSound", &Editor::entitySpeakerDefaultSound); + editorType.set("entitySpeakerDefaultRange", &Editor::entitySpeakerDefaultRange); + editorType.set("entitySpeakerDefaultLoop", &Editor::entitySpeakerDefaultLoop); + editorType.set("entityCharacterHp", &Editor::entityCharacterHp); + editorType.set("entityCharacterMp", &Editor::entityCharacterMp); + editorType.set("entityCharacterSex", &Editor::entityCharacterSex); + editorType.set("entityCharacterLevel", &Editor::entityCharacterLevel); + editorType.set("entityCharacterXp", &Editor::entityCharacterXp); + editorType.set("entityCharacterHunger", &Editor::entityCharacterHunger); + editorType.set("entityCharacterNanoMatter", &Editor::entityCharacterNanoMatter); + editorType.set("entityCharacterBioMatter", &Editor::entityCharacterBioMatter); + editorType.set("entityCharacterNeuroThread", &Editor::entityCharacterNeuroThread); + editorType.set("entityCharacterGold", &Editor::entityCharacterGold); + editorType.set("entityCharacterStrength", &Editor::entityCharacterStrength); + editorType.set("entityCharacterDexterity", &Editor::entityCharacterDexterity); + editorType.set("entityCharacterIntelligence", &Editor::entityCharacterIntelligence); + editorType.set("entityCharacterConstitution", &Editor::entityCharacterConstitution); + editorType.set("entityCharacterPerception", &Editor::entityCharacterPerception); + editorType.set("entityCharacterCharisma", &Editor::entityCharacterCharisma); + editorType.set("entityCharacterLuck", &Editor::entityCharacterLuck); + editorType.set("entityComponentExpand", &Editor::entityComponentExpand); + editorType.set("entityComponentCollapse", &Editor::entityComponentCollapse); + editorType.set("entityComponentName", &Editor::entityComponentName); + editorType.set("entityComponentTranslate", &Editor::entityComponentTranslate); + editorType.set("entityComponentRotate", &Editor::entityComponentRotate); + editorType.set("entityComponentScale", &Editor::entityComponentScale); + editorType.set("widgetTranslateX", &Editor::widgetTranslateX); + editorType.set("widgetTranslateY", &Editor::widgetTranslateY); + editorType.set("widgetTranslateZ", &Editor::widgetTranslateZ); + editorType.set("widgetRotateYaw", &Editor::widgetRotateYaw); + editorType.set("widgetRotatePitch", &Editor::widgetRotatePitch); + editorType.set("widgetRotateRoll", &Editor::widgetRotateRoll); + editorType.set("widgetScaleX", &Editor::widgetScaleX); + editorType.set("widgetScaleY", &Editor::widgetScaleY); + editorType.set("widgetScaleZ", &Editor::widgetScaleZ); + editorType.set("getEditingMode", &Editor::getEditingMode); + editorType.set("getHighlightedObj", &Editor::getHighlightedObj); + editorType.set("getWidgetMode", &Editor::getWidgetMode); + editorType.set("buttonEntityProperties", &Editor::buttonEntityProperties); + editorType.set("buttonEntityAddComponent", &Editor::buttonEntityAddComponent); + editorType.set("buttonNewConfirm", &Editor::buttonNewConfirm); + editorType.set("buttonNew", &Editor::buttonNew); + editorType.set("buttonSave", &Editor::buttonSave); + editorType.set("buttonLoad", &Editor::buttonLoad); + editorType.set("buttonEditorSettings", &Editor::buttonEditorSettings); + editorType.set("buttonEditorSettingsApply", &Editor::buttonEditorSettingsApply); + editorType.set("buttonMapSettings", &Editor::buttonMapSettings); + editorType.set("buttonMapSettingsApply", &Editor::buttonMapSettingsApply); + editorType.set("buttonHelp", &Editor::buttonHelp); + editorType.set("buttonWorldRotate", &Editor::buttonWorldRotate); + editorType.set("playSound", &Editor::playSound); + editorType.set("optimizeChunks", &Editor::optimizeChunks); + + //Finally register the thing. + lua.set_usertype("Editor", editorType); + } + + editor = &_editor; + lua["editor"] = editor; +} + static Ccmd ccmd_editor("editor","closes any running games and starts up the level editor",&console_editor); diff --git a/src/Engine.cpp b/src/Engine.cpp index e0692ec..19e7aaf 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -1487,4 +1487,61 @@ Engine::mod_t::mod_t(const char* _path): void Engine::mod_t::serialize(FileInterface* file) { file->property("name", name); file->property("author", author); -} \ No newline at end of file +} + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeEngine() { + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + "isInitialized", &Engine::isInitialized, + "isRunning", &Engine::isRunning, + "isPaused", &Engine::isPaused, + "isFullscreen", &Engine::isFullscreen, + "isRunningClient", &Engine::isRunningClient, + "isRunningServer", &Engine::isRunningServer, + "getGameTitle", &Engine::getGameTitle, + "getLocalClient", &Engine::getLocalClient, + "getLocalServer", &Engine::getLocalServer, + "getXres", &Engine::getXres, + "getYres", &Engine::getYres, + "getKeyStatus", &Engine::getKeyStatus, + "getMouseStatus", &Engine::getMouseStatus, + "getMouseX", &Engine::getMouseX, + "getMouseY", &Engine::getMouseY, + "getMouseMoveX", &Engine::getMouseMoveX, + "getMouseMoveY", &Engine::getMouseMoveY, + "getFPS", &Engine::getFPS, + "getTimeSync", &Engine::getTimeSync, + "getTicksPerSecond", &Engine::getTicksPerSecond, + "random", &Engine::random, + "playSound", &Engine::playSound, + "commandLine", &Engine::commandLine, + "shutdown", &Engine::shutdown, + "editorPlaytest", &Engine::editorPlaytest, + "smsg", &Engine::smsg, + "msg", &Engine::msg, + "triangleCoords", &Engine::triangleCoords, + "pointInTriangle", &Engine::pointInTriangle + ); + + //Finally register the thing. + lua.set_usertype("Engine", usertype); + } + + { + lua.new_usertype("matrix4x4"); + } + + if( engine ) { + lua["engine"] = engine; //MUST be a reference (or pointer). + } + + exposeString(); + + Rect::exposeToScript(lua, "RectSint32"); + Rect::exposeToScript(lua, "RectUint32"); +} diff --git a/src/Engine.hpp b/src/Engine.hpp index 5ae2b31..e00bb5e 100644 --- a/src/Engine.hpp +++ b/src/Engine.hpp @@ -222,7 +222,7 @@ class Engine { void smsg(const Uint32 msgType, const String& str); // logs a char string to the console - // @param msgType the type of message to send to the console + // @param msgType the type of message to send to the console, refer to Engine::msg_t enum for valid values // @param str a char string to print to the console void msg(const Uint32 msgType, const char* str); diff --git a/src/Entity.cpp b/src/Entity.cpp index abe763f..3cb5cd5 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -154,7 +154,7 @@ void Entity::addToEditorList() { Frame::entry_t* entry = levelList->addEntry("entity",true); entry->text = name.get(); - entry->params.addInt(uid); + entry->addParam(uid); if( selected ) { entry->color = glm::vec4(1.f,0.f,0.f,1.f); } else if( highlighted ) { @@ -205,7 +205,7 @@ void Entity::insertIntoWorld(World* _world) { path.format("scripts/server/entities/%s.lua", scriptStr.get()); } script->load(path.get()); - script->dispatch("init"); + script->dispatchFunction("init"); } } @@ -399,9 +399,9 @@ void Entity::process() { if( !ranScript ) { ranScript = true; script->load(path.get()); - script->dispatch("init"); + script->dispatchFunction("init"); } else { - script->dispatch("process"); + script->dispatchFunction("process"); processed = true; } } @@ -460,7 +460,7 @@ void Entity::process() { path.format("scripts/server/entities/%s.lua", scriptStr.get()); } - script->dispatch("postprocess"); + script->dispatchFunction("postprocess"); } } } @@ -782,11 +782,7 @@ bool Entity::interact(Entity& user, BBox& bbox) return false; } - Script::Args args; - args.addInt(user.getUID()); - args.addString(bbox.getName()); - - return (script->dispatch("interact", &args) == 0); + return script->dispatchFunction("interact", user, bbox); } void Entity::serialize(FileInterface * file) { @@ -1029,4 +1025,108 @@ void Entity::setScriptStr(const char* _scriptStr) { script = new Script(*this); } ranScript = false; -} \ No newline at end of file +} + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeEntity() { + { + auto entityType = lua.create_simple_usertype(sol::constructors()); + + //Bind all of the entity's member functions. + entityType.set("getName", &Entity::getName); + entityType.set("getUID", &Entity::getUID); + entityType.set("getTicks", &Entity::getTicks); + entityType.set("getPos", &Entity::getPos); + entityType.set("getVel", &Entity::getVel); + entityType.set("getAng", &Entity::getAng); + entityType.set("getRot", &Entity::getRot); + entityType.set("getScale", &Entity::getScale); + entityType.set("getScriptStr", &Entity::getScriptStr); + entityType.set("isToBeDeleted", &Entity::isToBeDeleted); + entityType.set("getFlags", &Entity::getFlags); + entityType.set("setKeyValue", &Entity::setKeyValue); + entityType.set("deleteKeyValue", &Entity::deleteKeyValue); + entityType.set("getKeyValueAsString", &Entity::getKeyValueAsString); + entityType.set("getKeyValueAsFloat", &Entity::getKeyValueAsFloat); + entityType.set("getKeyValueAsInt", &Entity::getKeyValueAsInt); + entityType.set("getKeyValue", &Entity::getKeyValue); + entityType.set("isFlag", &Entity::isFlag); + entityType.set("isFalling", &Entity::isFalling); + entityType.set("getLastUpdate", &Entity::getLastUpdate); + entityType.set("getDefName", &Entity::getDefName); + entityType.set("getSort", &Entity::getSort); + entityType.set("isSelected", &Entity::isSelected); + entityType.set("isHighlighted", &Entity::isHighlighted); + entityType.set("setName", &Entity::setName); + entityType.set("setFlags", &Entity::setFlags); + entityType.set("setFlag", &Entity::setFlag); + entityType.set("resetFlag", &Entity::resetFlag); + entityType.set("toggleFlag", &Entity::toggleFlag); + entityType.set("setPos", &Entity::setPos); + entityType.set("setVel", &Entity::setVel); + entityType.set("setAng", &Entity::setAng); + entityType.set("setRot", &Entity::setRot); + entityType.set("setScale", &Entity::setScale); + entityType.set("setScriptStr", &Entity::setScriptStr); + entityType.set("setSelected", &Entity::setSelected); + entityType.set("setHighlighted", &Entity::setHighlighted); + entityType.set("setFalling", &Entity::setFalling); + entityType.set("remove", &Entity::remove); + entityType.set("animate", &Entity::animate); + entityType.set("isNearCharacter", &Entity::isNearCharacter); + entityType.set("isCrouching", &Entity::isCrouching); + entityType.set("isMoving", &Entity::isMoving); + entityType.set("hasJumped", &Entity::hasJumped); + entityType.set("getLookDir", &Entity::getLookDir); + entityType.set("checkCollision", &Entity::checkCollision); + entityType.set("copy", &Entity::copy); + entityType.set("update", &Entity::update); + entityType.set("hasComponent", &Entity::hasComponent); + entityType.set("removeComponentByName", &Entity::removeComponentByName); + entityType.set("removeComponentByUID", &Entity::removeComponentByUID); + entityType.set("addComponent", &Entity::addComponent); + entityType.set("addBBox", &Entity::addComponent); + entityType.set("addModel", &Entity::addComponent); + entityType.set("addCamera", &Entity::addComponent); + entityType.set("addLight", &Entity::addComponent); + entityType.set("addSpeaker", &Entity::addComponent); + entityType.set("addCharacter", &Entity::addComponent); + entityType.set("findComponentByName", &Entity::findComponentByName); + entityType.set("findBBoxByName", &Entity::findComponentByName); + entityType.set("findModelByName", &Entity::findComponentByName); + entityType.set("findLightByName", &Entity::findComponentByName); + entityType.set("findCameraByName", &Entity::findComponentByName); + entityType.set("findSpeakerByName", &Entity::findComponentByName); + entityType.set("findCharacterByName", &Entity::findComponentByName); + entityType.set("lineTrace", &Entity::lineTrace); + entityType.set("findAPath", &Entity::findAPath); + entityType.set("findRandomPath", &Entity::findRandomPath); + entityType.set("pathFinished", &Entity::pathFinished); + entityType.set("hasPath", &Entity::hasPath); + entityType.set("getPathNodePosition", &Entity::getPathNodePosition); + entityType.set("getPathNodeDir", &Entity::getPathNodeDir); + entityType.set("getCurrentTileX", &Entity::getCurrentTileX); + entityType.set("getCurrentTileY", &Entity::getCurrentTileY); + entityType.set("getCurrentTileZ", &Entity::getCurrentTileZ); + entityType.set("isLocalPlayer", &Entity::isLocalPlayer); + + //Finally register the thing. + lua.set_usertype("Entity", entityType); + } + + // expose components + exposeComponent(); + exposeBBox(); + exposeModel(); + exposeLight(); + exposeCamera(); + exposeSpeaker(); + exposeCharacter(); + + if( entity ) { + lua["entity"] = entity; + } + + LinkedList::exposeToScript(lua, "LinkedListEntityPtr", "NodeEntityPtr"); + ArrayList::exposeToScript(lua, "ArrayListEntityPtr"); +} diff --git a/src/Field.hpp b/src/Field.hpp index 2e2b0e4..9b73f40 100644 --- a/src/Field.hpp +++ b/src/Field.hpp @@ -2,6 +2,8 @@ #pragma once +#include + #define GLM_FORCE_RADIANS #include @@ -70,7 +72,7 @@ class Field { const bool isNumbersOnly() const { return numbersOnly; } const char* getTabDestField() const { return tabDestField.get(); } const char* getTabDestFrame() const { return tabDestFrame.get(); } - Script::Args& getParams() { return params; } + const Script::Args& getParams() const { return params; } void setName(const char* _name) { name = _name; } void setText(const char* _text) { memset(text, '\0', textLen); strncpy(text,_text,textLen); } @@ -84,11 +86,30 @@ class Field { void setTabDestField(const char* _tabDest) { tabDestField = _tabDest; } void setTabDestFrame(const char* _tabDest) { tabDestFrame = _tabDest; } + template + void addParam(T param) + { + if (nullptr == parent) + { + assert(0); + return; + } + + Script* scripter = parent->getScriptEngine(); + if (nullptr == scripter) + { + assert(0); + return; + } + + scripter->addParam(param, params); + } + private: - Frame* parent = nullptr; // parent frame + Frame* parent = nullptr; // parent frame String name; - Script::Args params; + Script::Args params; // optional function parameters to use when the field function is called. char* text = nullptr; size_t textLen = 0; glm::vec4 color = glm::vec4(1.f,1.f,1.f,1.f); diff --git a/src/Frame.cpp b/src/Frame.cpp index 32fa444..11c7a54 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -404,8 +404,7 @@ Frame::result_t Frame::process(Rect _size, Rect _actualSize, bool usab if( !button.getName() || button.getName()[0] == '\0' ) { mainEngine->fmsg(Engine::MSG_WARN,"unnamed button clicked in '%s' gui",name.get()); } else if( script ) { - Script::Args args(button.getParams()); - script->dispatch(button.getName(), &args); + script->dispatchFunction(button.getName(), button.getParams()); } } } @@ -414,7 +413,7 @@ Frame::result_t Frame::process(Rect _size, Rect _actualSize, bool usab } if( script ) { - script->dispatch("process"); + script->dispatchFunction("process"); Sint32 omousex = mainEngine->getOldMouseX(); Sint32 omousey = mainEngine->getOldMouseY(); @@ -449,12 +448,10 @@ Frame::result_t Frame::process(Rect _size, Rect _actualSize, bool usab if( script ) { if( mainEngine->getKeyStatus(SDL_SCANCODE_LCTRL) || mainEngine->getKeyStatus(SDL_SCANCODE_RCTRL) ) { StringBuf<64> dispatch("%sCtrlClick", entry.name.get()); - Script::Args args(entry.params); - script->dispatch(dispatch.get(), &args); + script->dispatchFunction(dispatch.get(), entry.params); } else { StringBuf<64> dispatch("%sClick", entry.name.get()); - Script::Args args(entry.params); - script->dispatch(dispatch.get(), &args); + script->dispatchFunction(dispatch.get(), entry.params); } } } @@ -462,13 +459,11 @@ Frame::result_t Frame::process(Rect _size, Rect _actualSize, bool usab entry.pressed = false; if( script ) { StringBuf<64> dispatch("%sHighlighting", entry.name.get()); - Script::Args args(entry.params); - script->dispatch(dispatch.get(), &args); + script->dispatchFunction(dispatch.get(), entry.params); if( !entry.highlighted ) { entry.highlighted = true; StringBuf<64> dispatch("%sHighlight", entry.name.get()); - Script::Args args(entry.params); - script->dispatch(dispatch.get(), &args); + script->dispatchFunction(dispatch.get(), entry.params); } } } @@ -526,9 +521,7 @@ Frame::result_t Frame::process(Rect _size, Rect _actualSize, bool usab if( !field.getName() || field.getName()[0] == '\0' ) { mainEngine->fmsg(Engine::MSG_WARN,"unnamed field returned in '%s' gui",name.get()); } else if( script ) { - Script::Args args(field.getParams()); - args.addString(field.getText()); - script->dispatch(field.getName(), &args); + script->dispatchFunction(field.getName(), field.getParams(), field.getText()); } } } @@ -658,7 +651,7 @@ Frame::image_t* Frame::addImage( int x, int y, const glm::vec4& color, const cha } Frame::entry_t* Frame::addEntry( const char* name, bool resizeFrame ) { - entry_t* entry = new entry_t(); + entry_t* entry = new entry_t(*this); entry->name = name; entry->color = glm::vec4(1.f); entry->image = nullptr; diff --git a/src/Frame.hpp b/src/Frame.hpp index 9d0f099..84bcf70 100644 --- a/src/Frame.hpp +++ b/src/Frame.hpp @@ -37,6 +37,9 @@ class Frame { // frame list entry struct entry_t { + entry_t(Frame& parent) + : parent(parent) + { } ~entry_t(); StringBuf<32> name; @@ -48,8 +51,22 @@ class Frame { bool highlighted = false; Uint32 highlightTime = 0; bool suicide = false; + Frame& parent; std::shared_ptr listener; + + template + void addParam(T param) + { + Script* scripter = parent.getScriptEngine(); + if (nullptr == scripter) + { + assert(0); + return; + } + + scripter->addParam(param, params); + } }; // frame processing result structure @@ -187,6 +204,7 @@ class Frame { LinkedList& getFields() { return fields; } LinkedList& getButtons() { return buttons; } LinkedList& getEntries() { return list; } + Script* getScriptEngine() { return script; } const bool isDisabled() const { return disabled; } const bool isHollow() const { return hollow; } diff --git a/src/Light.cpp b/src/Light.cpp index 4220ec2..873cb32 100644 --- a/src/Light.cpp +++ b/src/Light.cpp @@ -169,4 +169,34 @@ void Light::createShadowMap() { void Light::deleteShadowMap() { shadowMap.term(); -} \ No newline at end of file +} + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeLight() { + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + sol::base_classes, sol::bases(), + "getColor", &Light::getColor, + "getIntensity", &Light::getIntensity, + "getRadius", &Light::getRadius, + "getArc", &Light::getArc, + "isShadow", &Light::isShadow, + "setColor", &Light::setColor, + "setIntensity", &Light::setIntensity, + "setRadius", &Light::setRadius, + "setShape", &Light::setShape, + "setArc", &Light::setArc, + "setShadow", &Light::setShadow + ); + + //Finally register the thing. + lua.set_usertype("Light", usertype); + } + + LinkedList::exposeToScript(lua, "LinkedListLightPtr", "NodeLightPtr"); + ArrayList::exposeToScript(lua, "ArrayListLightPtr"); +} diff --git a/src/LinkedList.hpp b/src/LinkedList.hpp index f921a96..e9b5f26 100644 --- a/src/LinkedList.hpp +++ b/src/LinkedList.hpp @@ -4,9 +4,7 @@ #include "Main.hpp" #include "Node.hpp" - -#include -#include +#include "Script.hpp" template class LinkedList { @@ -256,53 +254,38 @@ class LinkedList { // exposes this list type to a script // @param lua The script engine to expose to - // @param listName The type name for the list in lua - // @param nodeName The type name for the node in lua - static void exposeToScript(lua_State* lua, const char* listName, const char* nodeName) { - typedef Node* (LinkedList::*NodeFn)(); - NodeFn getFirst = static_cast(&LinkedList::getFirst); - NodeFn getLast = static_cast(&LinkedList::getLast); - - typedef const Node* (LinkedList::*NodeConstFn)() const; - NodeConstFn getFirstConst = static_cast(&LinkedList::getFirst); - NodeConstFn getLastConst = static_cast(&LinkedList::getLast); - - typedef Node* (LinkedList::*NodeIndexFn)(const size_t); - NodeIndexFn nodeForIndex = static_cast(&LinkedList::nodeForIndex); - - typedef const Node* (LinkedList::*NodeIndexConstFn)(const size_t) const; - NodeIndexConstFn nodeForIndexConst = static_cast(&LinkedList::nodeForIndex); - - typedef void (LinkedList::*NodeRemoveFn)(Node*); - NodeRemoveFn removeNode = static_cast(&LinkedList::removeNode); - - typedef void (LinkedList::*NodeRemoveIndexFn)(const size_t); - NodeRemoveIndexFn removeNodeIndex = static_cast(&LinkedList::removeNode); - - luabridge::getGlobalNamespace(lua) - .beginClass>(listName) - .addConstructor() - .addFunction("getFirst", getFirst) - .addFunction("getFirstConst", getFirstConst) - .addFunction("getLast", getLast) - .addFunction("getLastConst", getLastConst) - .addFunction("getSize", &LinkedList::getSize) - .addFunction("setFirst", &LinkedList::setFirst) - .addFunction("setLast", &LinkedList::setLast) - .addFunction("nodeForIndex", nodeForIndex) - .addFunction("nodeForIndexConst", nodeForIndexConst) - .addFunction("indexForNode", &LinkedList::indexForNode) - .addFunction("addNode", &LinkedList::addNode) - .addFunction("addNodeFirst", &LinkedList::addNodeFirst) - .addFunction("addNodeLast", &LinkedList::addNodeLast) - .addFunction("removeNode", removeNode) - .addFunction("removeNodeIndex", removeNodeIndex) - .addFunction("removeAll", &LinkedList::removeAll) - .addFunction("copy", &LinkedList::copy) - .endClass() - ; - - Node::exposeToScript(lua, nodeName); + // @param luaTypeName The type name for the list in lua + // @param nodeLuaTypeName The type name for the node in lua + static void exposeToScript(sol::state& lua, const char* luaTypeName, const char* nodeLuaTypeName) + { + //First identify the constructors. + sol::constructors()> constructors; + + //Then do the thing. + sol::usertype> usertype(constructors, + "getFirst", sol::resolve*()>(&LinkedList::getFirst), + "getFirstConst", sol::resolve*() const>(&LinkedList::getFirst), + "getLast", sol::resolve*()>(&LinkedList::getLast), + "getLastConst", sol::resolve*() const>(&LinkedList::getLast), + "getSize", &LinkedList::getSize, + "setFirst", &LinkedList::setFirst, + "setLast", &LinkedList::setLast, + "nodeForIndex", sol::resolve*(const size_t)>(&LinkedList::nodeForIndex), + "nodeForIndexConst", sol::resolve*(const size_t) const>(&LinkedList::nodeForIndex), + "indexForNode", &LinkedList::indexForNode, + "addNode", &LinkedList::addNode, + "addNodeFirst", &LinkedList::addNodeFirst, + "addNodeLast", &LinkedList::addNodeLast, + "removeNode", sol::resolve*)>(&LinkedList::removeNode), + "removeNodeIndex", sol::resolve(&LinkedList::removeNode), + "removeAll", &LinkedList::removeAll, + "copy", &LinkedList::copy + ); + + //Finally register the thing. + lua.set_usertype(luaTypeName, usertype); + + Node::exposeToScript(lua, nodeLuaTypeName); } private: diff --git a/src/Model.cpp b/src/Model.cpp index 63395a1..deaf77c 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -409,3 +409,81 @@ void Model::serialize(FileInterface * file) { file->property("genius", genius); } } + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeModel() { + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + sol::base_classes, sol::bases(), + "findBone", &Model::findBone, + "findAnimation", &Model::findAnimation, + "animate", &Model::animate, + "hasAnimations", &Model::hasAnimations, + "getMesh", &Model::getMesh, + "getMaterial", &Model::getMaterial, + "getDepthFailMat", &Model::getDepthFailMat, + "getAnimation", &Model::getAnimation, + "getShaderVars", &Model::getShaderVars, + "getAnimTicks", &Model::getAnimTicks, + "isAnimDone", &Model::isAnimDone, + "getAnimationSpeed", &Model::getAnimationSpeed, + "setMesh", &Model::setMesh, + "setMaterial", &Model::setMaterial, + "setDepthFailMat", &Model::setDepthFailMat, + "setAnimation", &Model::setAnimation, + "setShaderVars", &Model::setShaderVars, + "setAnimationSpeed", &Model::setAnimationSpeed, + "updateSkin", &Model::updateSkin, + "getCurrentAnimation", &Model::getCurrentAnimation, + "getPreviousAnimation", &Model::getPreviousAnimation + ); + + //Finally register the thing. + lua.set_usertype("Model", usertype); + } + + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + "getName", &AnimationState::getName, + "getTicks", &AnimationState::getTicks, + "getTicksRate", &AnimationState::getTicksRate, + "getBegin", &AnimationState::getBegin, + "getEnd", &AnimationState::getEnd, + "getLength", &AnimationState::getLength, + "getWeight", &AnimationState::getWeight, + "getWeightRate", &AnimationState::getWeightRate, + "isLoop", &AnimationState::isLoop, + "isFinished", &AnimationState::isFinished, + "setTicks", &AnimationState::setTicks, + "setTicksRate", &AnimationState::setTicksRate, + "setWeight", &AnimationState::setWeight, + "setWeightRate", &AnimationState::setWeightRate, + "setWeights", &AnimationState::setWeights, + "setWeightRates", &AnimationState::setWeightRates, + "clearWeights", &AnimationState::clearWeights + ); + + //Finally register the thing. + lua.set_usertype("AnimationState", usertype); + } + + lua.new_usertype("bone_t", + "valid", &Model::bone_t::valid, + "name", &Model::bone_t::name, + "mat", &Model::bone_t::mat, + "pos", &Model::bone_t::pos, + "ang", &Model::bone_t::ang, + "scale", &Model::bone_t::scale + ); + + LinkedList::exposeToScript(lua, "LinkedListModelPtr", "NodeModelPtr"); + ArrayList::exposeToScript(lua, "ArrayListModelPtr"); +} diff --git a/src/Node.hpp b/src/Node.hpp index 62c9bb1..2661960 100644 --- a/src/Node.hpp +++ b/src/Node.hpp @@ -3,9 +3,7 @@ #pragma once #include "Main.hpp" - -#include -#include +#include "Script.hpp" template class LinkedList; @@ -58,48 +56,34 @@ class Node { void setNext(Node* node) { next = node; } void setPrev(Node* node) { prev = node; } - void setData(T& _data) { data = _data; } + void setData(const T& _data) { data = _data; } // exposes this node type to a script // @param lua The script engine to expose to - // @param name The type name in lua - static void exposeToScript(lua_State* lua, const char* name) { - typedef Node* (Node::*NodeFn)(); - NodeFn getNext = static_cast(&Node::getNext); - NodeFn getPrev = static_cast(&Node::getPrev); - - typedef const Node* (Node::*NodeConstFn)() const; - NodeConstFn getNextConst = static_cast(&Node::getNext); - NodeConstFn getPrevConst = static_cast(&Node::getPrev); - - typedef LinkedList* (Node::*ListFn)(); - ListFn getList = static_cast(&Node::getList); - - typedef const LinkedList* (Node::*ListConstFn)() const; - ListConstFn getListConst = static_cast(&Node::getList); - - typedef T& (Node::*DataFn)(); - DataFn getData = static_cast(&Node::getData); - - typedef const T& (Node::*DataConstFn)() const; - DataConstFn getDataConst = static_cast(&Node::getData); - - luabridge::getGlobalNamespace(lua) - .beginClass>(name) - .addFunction("getNext", getNext) - .addFunction("getPrev", getPrev) - .addFunction("getList", getList) - .addFunction("getData", getData) - .addFunction("getNextConst", getNextConst) - .addFunction("getPrevConst", getPrevConst) - .addFunction("getListConst", getListConst) - .addFunction("getDataConst", getDataConst) - .addFunction("getSizeOfData", &Node::getSizeOfData) - .addFunction("setNext", &Node::setNext) - .addFunction("setPrev", &Node::setPrev) - .addFunction("setData", &Node::setData) - .endClass() - ; + // @param luaTypeName The type name in lua + static void exposeToScript(sol::state& lua, const char* luaTypeName) + { + //First identify the constructors. + sol::constructors(LinkedList&, Node*, const T&)> constructors; + + //Then do the thing. + sol::usertype> usertype(constructors, + "getNext", sol::resolve*()>(&Node::getNext), + "getPrev", sol::resolve*()>(&Node::getPrev), + "getList", sol::resolve*()>(&Node::getList), + "getData", sol::resolve(&Node::getData), + "getNextConst", sol::resolve*() const>(&Node::getNext), + "getPrevConst", sol::resolve*() const>(&Node::getPrev), + "getListConst", sol::resolve*() const>(&Node::getList), + "getDataConst", sol::resolve(&Node::getData), + "getSizeOfData", &Node::getSizeOfData, + "setNext", &Node::setNext, + "setPrev", &Node::setPrev, + "setData", &Node::setData + ); + + //Finally register the thing. + lua.set_usertype(luaTypeName, usertype); } private: diff --git a/src/Path.hpp b/src/Path.hpp index 3b9da4d..8698215 100644 --- a/src/Path.hpp +++ b/src/Path.hpp @@ -159,7 +159,7 @@ class PathFinder { ArrayList map; Uint32 mapWidth = 0; Uint32 mapHeight = 0; - void generateSimpleMap(); //TODO Make sure accessing this result is threadsafe...every thread should probably get a copy of the map on creation. + void generateSimpleMap(); //TODO: Make sure accessing this result is threadsafe...every thread should probably get a copy of the map on creation. }; // class pathTask diff --git a/src/Rect.hpp b/src/Rect.hpp index 8d4a24f..fbb217b 100644 --- a/src/Rect.hpp +++ b/src/Rect.hpp @@ -4,6 +4,7 @@ #pragma once #include "File.hpp" +#include "Script.hpp" template struct Rect { @@ -53,17 +54,22 @@ struct Rect { // exposes this rect type to a script // @param lua The script engine to expose to - // @param name The type name in lua - static void exposeToScript(lua_State* lua, const char* name) { - luabridge::getGlobalNamespace(lua) - .beginClass>(name) - .addConstructor() - .addData("x", &Rect::x, true) - .addData("y", &Rect::y, true) - .addData("w", &Rect::w, true) - .addData("h", &Rect::h, true) - .addFunction("containsPoint", &Rect::containsPoint) - .endClass() - ; + // @param luaTypeName The type name in lua + static void exposeToScript(sol::state& lua, const char* luaTypeName) + { + //First identify the constructors. + sol::constructors&)> constructors; + + //Then do the thing. + sol::usertype> usertype(constructors, + "x", &Rect::x, + "y", &Rect::y, + "w", &Rect::w, + "h", &Rect::h, + "containsPoint", &Rect::containsPoint + ); + + //Finally register the thing. + lua.set_usertype(luaTypeName, usertype); } }; \ No newline at end of file diff --git a/src/Script.cpp b/src/Script.cpp index f57c3fb..38c4500 100644 --- a/src/Script.cpp +++ b/src/Script.cpp @@ -1,8 +1,10 @@ // Script.cpp -#include -#include +//#include +//#include + #include +#include #include "Main.hpp" #include "Engine.hpp" @@ -10,7 +12,6 @@ #include "Server.hpp" #include "World.hpp" #include "Entity.hpp" -#include "Script.hpp" #include "Tile.hpp" #include "Chunk.hpp" #include "Frame.hpp" @@ -23,6 +24,14 @@ #include "Vector.hpp" #include "WideVector.hpp" +#include "Script.hpp" + +//Includes bindings for these modules. +#include "Node.hpp" +#include "LinkedList.hpp" +#include "ArrayList.hpp" +#include "Rect.hpp" + //Component headers #include "Component.hpp" #include "BBox.hpp" @@ -32,76 +41,39 @@ #include "Speaker.hpp" #include "Character.hpp" -int Script::load(const char* _filename) { - filename = mainEngine->buildPath(_filename); - - int result = luaL_dofile(lua, filename.get()); - if( result ) { - mainEngine->fmsg(Engine::MSG_ERROR,"failed to load script '%s':", filename.get()); - mainEngine->fmsg(Engine::MSG_ERROR," %s", lua_tostring(lua, -1)); - broken = true; - return 1; - } else { - broken = false; - return 0; - } -} - -int Script::dispatch(const char* function, Args* args) { - if (broken) { - return -1; - } - lua_getglobal(lua, function); - - size_t numArgs = 0; - if (args) - { - numArgs = args->getSize(); - args->push(lua); - } - - int status = lua_pcall(lua, (int)numArgs, 0, 0); - if (status) { - mainEngine->fmsg(Engine::MSG_ERROR,"script error in '%s' (dispatch '%s'):", filename.get(), function); - mainEngine->fmsg(Engine::MSG_ERROR," %s", lua_tostring(lua, -1)); - broken = true; - return -2; - } - - return 0; +Script::Script() +{ + lua.open_libraries(sol::lib::base, sol::lib::io, sol::lib::package, sol::lib::math); } -Script::Script(Client& _client) { +Script::Script(Client& _client) + : Script() +{ client = &_client; engine = mainEngine; - lua = luaL_newstate(); - luaL_openlibs(lua); - // expose functions exposeEngine(); exposeClient(); } -Script::Script(Server& _server) { +Script::Script(Server& _server) + : Script() +{ server = &_server; engine = mainEngine; - lua = luaL_newstate(); - luaL_openlibs(lua); - // expose functions exposeEngine(); exposeServer(); } -Script::Script(World& _world) { +Script::Script(World& _world) + : Script() +{ world = &_world; engine = mainEngine; - lua = luaL_newstate(); - luaL_openlibs(lua); - // expose functions exposeEngine(); exposeAngle(); @@ -109,13 +81,12 @@ Script::Script(World& _world) { exposeWorld(); } -Script::Script(Entity& _entity) { +Script::Script(Entity& _entity) + : Script() +{ entity = &_entity; engine = mainEngine; - lua = luaL_newstate(); - luaL_openlibs(lua); - // expose functions exposeEngine(); exposeAngle(); @@ -123,14 +94,13 @@ Script::Script(Entity& _entity) { exposeEntity(); } -Script::Script(Frame& _frame) { +Script::Script(Frame& _frame) + : Script() +{ frame = &_frame; engine = mainEngine; client = engine->getLocalClient(); - lua = luaL_newstate(); - luaL_openlibs(lua); - // expose functions exposeEngine(); exposeClient(); @@ -143,121 +113,124 @@ Script::Script(Frame& _frame) { } Script::~Script() { - if ( lua ) { - lua_close(lua); - lua = nullptr; - } } -void Script::exposeEngine() { - luabridge::getGlobalNamespace(lua) - .beginClass("Engine") - .addFunction("isInitialized", &Engine::isInitialized) - .addFunction("isRunning", &Engine::isRunning) - .addFunction("isPaused", &Engine::isPaused) - .addFunction("isFullscreen", &Engine::isFullscreen) - .addFunction("isRunningClient", &Engine::isRunningClient) - .addFunction("isRunningServer", &Engine::isRunningServer) - .addFunction("getGameTitle", &Engine::getGameTitle) - .addFunction("getLocalClient", &Engine::getLocalClient) - .addFunction("getLocalServer", &Engine::getLocalServer) - .addFunction("getXres", &Engine::getXres) - .addFunction("getYres", &Engine::getYres) - .addFunction("getKeyStatus", &Engine::getKeyStatus) - .addFunction("getMouseStatus", &Engine::getMouseStatus) - .addFunction("getMouseX", &Engine::getMouseX) - .addFunction("getMouseY", &Engine::getMouseY) - .addFunction("getMouseMoveX", &Engine::getMouseMoveX) - .addFunction("getMouseMoveY", &Engine::getMouseMoveY) - .addFunction("getFPS", &Engine::getFPS) - .addFunction("getTimeSync", &Engine::getTimeSync) - .addFunction("getTicksPerSecond", &Engine::getTicksPerSecond) - .addFunction("random", &Engine::random) - .addFunction("playSound", &Engine::playSound) - .addFunction("commandLine", &Engine::commandLine) - .addFunction("shutdown", &Engine::shutdown) - .addFunction("editorPlaytest", &Engine::editorPlaytest) - .addFunction("smsg", &Engine::smsg) - .addFunction("msg", &Engine::msg) - .addStaticFunction("triangleCoords", &Engine::triangleCoords) - .addStaticFunction("pointInTriangle", &Engine::pointInTriangle) - .endClass() - ; - - luabridge::getGlobalNamespace(lua) - .beginClass("matrix4x4") - .endClass() - ; - - if( engine ) { - luabridge::push(lua, engine); - lua_setglobal(lua, "engine"); - } +bool Script::load(const char* _filename) +{ + filename = mainEngine->buildPath(_filename); - exposeString(); + try + { + sol::protected_function_result script = lua.safe_script_file(filename.get()); + if (!script.valid()) + { + sol::error err = script; + mainEngine->fmsg(Engine::MSG_ERROR,"failed to load script '%s':", filename.get()); + mainEngine->fmsg(Engine::MSG_ERROR," %s", err.what()); + broken = true; + return false; + } + } + catch(const sol::error& e) + { + mainEngine->fmsg(Engine::MSG_ERROR,"failed to load script '%s':", filename.get()); + mainEngine->fmsg(Engine::MSG_ERROR," %s", e.what()); + broken = true; + return false; + } + // catch(const std::exception& e) + // { + // mainEngine->fmsg(Engine::MSG_ERROR,"failed to load script '%s':", filename.get()); + // mainEngine->fmsg(Engine::MSG_ERROR," %s", e.what()); + // broken = true; + // return false; + // return false; + // } + // catch(...) + // { + // mainEngine->fmsg(Engine::MSG_ERROR,"failed to load script '%s':", filename.get()); + // mainEngine->fmsg(Engine::MSG_ERROR," %s", e.what()); + // broken = true; + // return false; + // return false; + // } + + broken = false; + return true; +} - Rect::exposeToScript(lua, "RectSint32"); - Rect::exposeToScript(lua, "RectUint32"); +void Script::dispatchFunctionErrorMessage(const String& filename, const char* functionName, const sol::error& err) +{ + mainEngine->fmsg(Engine::MSG_ERROR, "script error in '%s' (dispatch '%s'):", filename.get(), functionName); + mainEngine->fmsg(Engine::MSG_ERROR," %s", err.what()); } + + void Script::exposeFrame() { - luabridge::getGlobalNamespace(lua) - .beginClass("Frame") - .addFunction("getBorder", &Frame::getBorder) - .addFunction("getSize", &Frame::getSize) - .addFunction("getActualSize", &Frame::getActualSize) - .addFunction("isHigh", &Frame::isHigh) - .addFunction("getFrames", &Frame::getFrames) - .addFunction("getButtons", &Frame::getButtons) - .addFunction("setBorder", &Frame::setBorder) - .addFunction("setSize", &Frame::setSize) - .addFunction("setActualSize", &Frame::setActualSize) - .addFunction("setHigh", &Frame::setHigh) - .addFunction("setColor", &Frame::setColor) - .addFunction("addFrame", &Frame::addFrame) - .addFunction("addButton", &Frame::addButton) - .addFunction("addField", &Frame::addField) - .addFunction("addImage", &Frame::addImage) - .addFunction("addEntry", &Frame::addEntry) - .addFunction("clear", &Frame::clear) - .addFunction("removeSelf", &Frame::removeSelf) - .addFunction("remove", &Frame::remove) - .addFunction("removeEntry", &Frame::removeEntry) - .addFunction("findEntry", &Frame::findEntry) - .addFunction("findFrame", &Frame::findFrame) - .endClass() - ; + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + "getBorder", &Frame::getBorder, + "getSize", &Frame::getSize, + "getActualSize", &Frame::getActualSize, + "isHigh", &Frame::isHigh, + "getFrames", &Frame::getFrames, + "getButtons", &Frame::getButtons, + "setBorder", &Frame::setBorder, + "setSize", &Frame::setSize, + "setActualSize", &Frame::setActualSize, + "setHigh", &Frame::setHigh, + "setColor", &Frame::setColor, + "addFrame", &Frame::addFrame, + "addButton", &Frame::addButton, + "addField", &Frame::addField, + "addImage", &Frame::addImage, + "addEntry", &Frame::addEntry, + "clear", &Frame::clear, + "removeSelf", &Frame::removeSelf, + "remove", &Frame::remove, + "removeEntry", &Frame::removeEntry, + "findEntry", &Frame::findEntry, + "findFrame", &Frame::findFrame + ); + + //Finally register the thing. + lua.set_usertype("Frame", usertype); + } if( frame ) { - luabridge::push(lua, frame); - lua_setglobal(lua, "frame"); + lua["frame"] = frame; } } void Script::exposeString() { - typedef size_t (String::*FindFn)(const char*, size_t) const; - FindFn find = static_cast(&String::find); - - typedef size_t (String::*FindCharFn)(const char, size_t) const; - FindCharFn findChar = static_cast(&String::find); - - luabridge::getGlobalNamespace(lua) - .beginClass("String") - .addConstructor() - .addFunction("get", &String::get) - .addFunction("getSize", &String::getSize) - .addFunction("alloc", &String::alloc) - .addFunction("empty", &String::empty) - .addFunction("length", &String::length) - .addFunction("assign", &String::assign) - .addFunction("append", &String::append) - .addFunction("substr", &String::substr) - .addFunction("find", find) - .addFunction("findChar", findChar) - .addFunction("toInt", &String::toInt) - .addFunction("toFloat", &String::toFloat) - .endClass() - ; + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + "get", &String::get, + "getSize", &String::getSize, + "alloc", &String::alloc, + "empty", &String::empty, + "length", &String::length, + "assign", &String::assign, + "append", &String::append, + "substr", &String::substr, + "find", sol::resolve(&String::find), + "findChar", sol::resolve(&String::find), + "toInt", &String::toInt, + "toFloat", &String::toFloat + ); + + //Finally register the thing. + lua.set_usertype("String", usertype); + } LinkedList::exposeToScript(lua, "LinkedListString", "NodeString"); LinkedList::exposeToScript(lua, "LinkedListStringPtr", "NodeStringPtr"); @@ -266,22 +239,28 @@ void Script::exposeString() { } void Script::exposeAngle() { - luabridge::getGlobalNamespace(lua) - .beginClass("Angle") - .addConstructor() - .addData("yaw", &Angle::yaw, true) - .addData("pitch", &Angle::pitch, true) - .addData("roll", &Angle::roll, true) - .addFunction("radiansYaw", &Angle::radiansYaw) - .addFunction("radiansPitch", &Angle::radiansPitch) - .addFunction("radiansRoll", &Angle::radiansRoll) - .addFunction("degreesYaw", &Angle::degreesYaw) - .addFunction("degreesPitch", &Angle::degreesPitch) - .addFunction("degreesRoll", &Angle::degreesRoll) - .addFunction("wrapAngles", &Angle::wrapAngles) - .addFunction("toVector", &Angle::toVector) - .endClass() - ; + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + "yaw", &Angle::yaw, + "pitch", &Angle::pitch, + "roll", &Angle::roll, + "radiansYaw", &Angle::radiansYaw, + "radiansPitch", &Angle::radiansPitch, + "radiansRoll", &Angle::radiansRoll, + "degreesYaw", &Angle::degreesYaw, + "degreesPitch", &Angle::degreesPitch, + "degreesRoll", &Angle::degreesRoll, + "wrapAngles", &Angle::wrapAngles, + "toVector", &Angle::toVector + ); + + //Finally register the thing. + lua.set_usertype("Angle", usertype); + } LinkedList::exposeToScript(lua, "LinkedListAngle", "NodeAngle"); LinkedList::exposeToScript(lua, "LinkedListAnglePtr", "NodeAnglePtr"); @@ -290,50 +269,63 @@ void Script::exposeAngle() { } void Script::exposeVector() { - luabridge::getGlobalNamespace(lua) - .beginClass("Vector") - .addConstructor() - .addData("x", &Vector::x, true) - .addData("y", &Vector::y, true) - .addData("z", &Vector::z, true) - .addData("r", &Vector::x, true) - .addData("g", &Vector::y, true) - .addData("b", &Vector::z, true) - .addFunction("hasVolume", &Vector::hasVolume) - .addFunction("dot", &Vector::dot) - .addFunction("cross", &Vector::cross) - .addFunction("length", &Vector::length) - .addFunction("lengthSquared", &Vector::lengthSquared) - .addFunction("normal", &Vector::normal) - .addFunction("normalize", &Vector::normalize) - .endClass() - ; + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + "x", &Vector::x, + "y", &Vector::y, + "z", &Vector::z, + "r", &Vector::x, + "g", &Vector::y, + "b", &Vector::z, + "hasVolume", &Vector::hasVolume, + "dot", &Vector::dot, + "cross", &Vector::cross, + "length", &Vector::length, + "lengthSquared", &Vector::lengthSquared, + "normal", &Vector::normal, + "normalize", &Vector::normalize + ); + + //Finally register the thing. + lua.set_usertype("Vector", usertype); + } LinkedList::exposeToScript(lua, "LinkedListVector", "NodeVector"); LinkedList::exposeToScript(lua, "LinkedListVectorPtr", "NodeVectorPtr"); ArrayList::exposeToScript(lua, "ArrayListVector"); ArrayList::exposeToScript(lua, "ArrayListVectorPtr"); - luabridge::getGlobalNamespace(lua) - .beginClass("WideVector") - .addConstructor() - .addData("x", &WideVector::x, true) - .addData("y", &WideVector::y, true) - .addData("z", &WideVector::z, true) - .addData("w", &WideVector::w, true) - .addData("r", &WideVector::x, true) - .addData("g", &WideVector::y, true) - .addData("b", &WideVector::z, true) - .addData("a", &WideVector::w, true) - .addFunction("hasVolume", &WideVector::hasVolume) - .addFunction("dot", &WideVector::dot) - .addFunction("cross", &WideVector::cross) - .addFunction("length", &WideVector::length) - .addFunction("lengthSquared", &WideVector::lengthSquared) - .addFunction("normal", &WideVector::normal) - .addFunction("normalize", &WideVector::normalize) - .endClass() - ; + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + sol::base_classes, sol::bases(), + "x", &WideVector::x, + "y", &WideVector::y, + "z", &WideVector::z, + "w", &WideVector::w, + "r", &WideVector::x, + "g", &WideVector::y, + "b", &WideVector::z, + "a", &WideVector::w, + "hasVolume", &WideVector::hasVolume, + "dot", &WideVector::dot, + "cross", &WideVector::cross, + "length", &WideVector::length, + "lengthSquared", &WideVector::lengthSquared, + "normal", &WideVector::normal, + "normalize", &WideVector::normalize + ); + + //Finally register the thing. + lua.set_usertype("WideVector", usertype); + } LinkedList::exposeToScript(lua, "LinkedListWideVector", "NodeWideVector"); LinkedList::exposeToScript(lua, "LinkedListWideVectorPtr", "NodeWideVectorPtr"); @@ -342,529 +334,88 @@ void Script::exposeVector() { } void Script::exposeGame() { - luabridge::getGlobalNamespace(lua) - .beginClass("Game") - .addFunction("getWorld", &Game::getWorld) - .addFunction("worldForName", &Game::worldForName) - .addFunction("loadWorld", &Game::loadWorld) - .addFunction("closeAllWorlds", &Game::closeAllWorlds) - .endClass() - ; + lua.new_usertype("Game", + "getWorld", &Game::getWorld, + "worldForName", &Game::worldForName, + "loadWorld", &Game::loadWorld, + "closeAllWorlds", &Game::closeAllWorlds + ); } void Script::exposeClient() { exposeGame(); - - luabridge::getGlobalNamespace(lua) - .deriveClass("Client") - .addFunction("isConsoleAllowed", &Client::isConsoleAllowed) - .addFunction("isConsoleActive", &Client::isConsoleActive) - .addFunction("isEditorActive", &Client::isEditorActive) - .addFunction("getGUI", &Client::getGUI) - .addFunction("startEditor", &Client::startEditor) - .endClass() - ; + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + sol::base_classes, sol::bases(), + "isConsoleAllowed", &Client::isConsoleAllowed, + "isConsoleActive", &Client::isConsoleActive, + "isEditorActive", &Client::isEditorActive, + "getGUI", &Client::getGUI, + "startEditor", &Client::startEditor + ); + + //Finally register the thing. + lua.set_usertype("Client", usertype); + } if( client ) { - luabridge::push(lua, client); - lua_setglobal(lua, "client"); + lua["client"] = client; } } -void Script::exposeEditor(Editor& _editor) { - luabridge::getGlobalNamespace(lua) - .beginClass("Editor") - .addFunction("setEditingMode", &Editor::setEditingMode) - .addFunction("setCeilingMode", &Editor::setCeilingMode) - .addFunction("setHighlightedObj", &Editor::setHighlightedObj) - .addFunction("setWidgetMode", &Editor::setWidgetMode) - .addFunction("selectEntity", &Editor::selectEntity) - .addFunction("toggleSelectEntity", &Editor::toggleSelectEntity) - .addFunction("selectAllEntities", &Editor::selectAllEntities) - .addFunction("selectEntityForSpawn", &Editor::selectEntityForSpawn) - .addFunction("entitiesName", &Editor::entitiesName) - .addFunction("entitiesScript", &Editor::entitiesScript) - .addFunction("entitiesFlag", &Editor::entitiesFlag) - .addFunction("entitiesSave", &Editor::entitiesSave) - .addFunction("entityKeyValueEnter", &Editor::entityKeyValueEnter) - .addFunction("entityKeyValueRemove", &Editor::entityKeyValueRemove) - .addFunction("entityKeyValueSelect", &Editor::entityKeyValueSelect) - .addFunction("entityAddComponent", &Editor::entityAddComponent) - .addFunction("entityRemoveComponent", &Editor::entityRemoveComponent) - .addFunction("entityBBoxShape", &Editor::entityBBoxShape) - .addFunction("entityBBoxEnabled", &Editor::entityBBoxEnabled) - .addFunction("entityBBoxMass", &Editor::entityBBoxMass) - .addFunction("entityModelLoadMesh", &Editor::entityModelLoadMesh) - .addFunction("entityModelLoadMaterial", &Editor::entityModelLoadMaterial) - .addFunction("entityModelLoadDepthFailMat", &Editor::entityModelLoadDepthFailMat) - .addFunction("entityModelLoadAnimation", &Editor::entityModelLoadAnimation) - .addFunction("entityModelCustomColor", &Editor::entityModelCustomColor) - .addFunction("entityModelCustomColorChannel", &Editor::entityModelCustomColorChannel) - .addFunction("entityLightColorR", &Editor::entityLightColorR) - .addFunction("entityLightColorG", &Editor::entityLightColorG) - .addFunction("entityLightColorB", &Editor::entityLightColorB) - .addFunction("entityLightIntensity", &Editor::entityLightIntensity) - .addFunction("entityLightRadius", &Editor::entityLightRadius) - .addFunction("entityLightArc", &Editor::entityLightArc) - .addFunction("entityLightShadow", &Editor::entityLightShadow) - .addFunction("entityLightShape", &Editor::entityLightShape) - .addFunction("entityCameraClipNear", &Editor::entityCameraClipNear) - .addFunction("entityCameraClipFar", &Editor::entityCameraClipFar) - .addFunction("entityCameraWinX", &Editor::entityCameraWinX) - .addFunction("entityCameraWinY", &Editor::entityCameraWinY) - .addFunction("entityCameraWinW", &Editor::entityCameraWinW) - .addFunction("entityCameraWinH", &Editor::entityCameraWinH) - .addFunction("entityCameraFOV", &Editor::entityCameraFOV) - .addFunction("entityCameraOrtho", &Editor::entityCameraOrtho) - .addFunction("entitySpeakerDefaultSound", &Editor::entitySpeakerDefaultSound) - .addFunction("entitySpeakerDefaultRange", &Editor::entitySpeakerDefaultRange) - .addFunction("entitySpeakerDefaultLoop", &Editor::entitySpeakerDefaultLoop) - .addFunction("entityCharacterHp", &Editor::entityCharacterHp) - .addFunction("entityCharacterMp", &Editor::entityCharacterMp) - .addFunction("entityCharacterSex", &Editor::entityCharacterSex) - .addFunction("entityCharacterLevel", &Editor::entityCharacterLevel) - .addFunction("entityCharacterXp", &Editor::entityCharacterXp) - .addFunction("entityCharacterHunger", &Editor::entityCharacterHunger) - .addFunction("entityCharacterNanoMatter", &Editor::entityCharacterNanoMatter) - .addFunction("entityCharacterBioMatter", &Editor::entityCharacterBioMatter) - .addFunction("entityCharacterNeuroThread", &Editor::entityCharacterNeuroThread) - .addFunction("entityCharacterGold", &Editor::entityCharacterGold) - .addFunction("entityCharacterStrength", &Editor::entityCharacterStrength) - .addFunction("entityCharacterDexterity", &Editor::entityCharacterDexterity) - .addFunction("entityCharacterIntelligence", &Editor::entityCharacterIntelligence) - .addFunction("entityCharacterConstitution", &Editor::entityCharacterConstitution) - .addFunction("entityCharacterPerception", &Editor::entityCharacterPerception) - .addFunction("entityCharacterCharisma", &Editor::entityCharacterCharisma) - .addFunction("entityCharacterLuck", &Editor::entityCharacterLuck) - .addFunction("entityComponentExpand", &Editor::entityComponentExpand) - .addFunction("entityComponentCollapse", &Editor::entityComponentCollapse) - .addFunction("entityComponentName", &Editor::entityComponentName) - .addFunction("entityComponentTranslate", &Editor::entityComponentTranslate) - .addFunction("entityComponentRotate", &Editor::entityComponentRotate) - .addFunction("entityComponentScale", &Editor::entityComponentScale) - .addFunction("widgetTranslateX", &Editor::widgetTranslateX) - .addFunction("widgetTranslateY", &Editor::widgetTranslateY) - .addFunction("widgetTranslateZ", &Editor::widgetTranslateZ) - .addFunction("widgetRotateYaw", &Editor::widgetRotateYaw) - .addFunction("widgetRotatePitch", &Editor::widgetRotatePitch) - .addFunction("widgetRotateRoll", &Editor::widgetRotateRoll) - .addFunction("widgetScaleX", &Editor::widgetScaleX) - .addFunction("widgetScaleY", &Editor::widgetScaleY) - .addFunction("widgetScaleZ", &Editor::widgetScaleZ) - .addFunction("getEditingMode", &Editor::getEditingMode) - .addFunction("getHighlightedObj", &Editor::getHighlightedObj) - .addFunction("getWidgetMode", &Editor::getWidgetMode) - .addFunction("buttonEntityProperties", &Editor::buttonEntityProperties) - .addFunction("buttonEntityAddComponent", &Editor::buttonEntityAddComponent) - .addFunction("buttonNewConfirm", &Editor::buttonNewConfirm) - .addFunction("buttonNew", &Editor::buttonNew) - .addFunction("buttonSave", &Editor::buttonSave) - .addFunction("buttonLoad", &Editor::buttonLoad) - .addFunction("buttonEditorSettings", &Editor::buttonEditorSettings) - .addFunction("buttonEditorSettingsApply", &Editor::buttonEditorSettingsApply) - .addFunction("buttonMapSettings", &Editor::buttonMapSettings) - .addFunction("buttonMapSettingsApply", &Editor::buttonMapSettingsApply) - .addFunction("buttonHelp", &Editor::buttonHelp) - .addFunction("buttonWorldRotate", &Editor::buttonWorldRotate) - .addFunction("playSound", &Editor::playSound) - .addFunction("optimizeChunks", &Editor::optimizeChunks) - .endClass() - ; - - editor = &_editor; - luabridge::push(lua, editor); - lua_setglobal(lua, "editor"); -} - void Script::exposeServer() { exposeGame(); - luabridge::getGlobalNamespace(lua) - .deriveClass("Server") - .endClass() - ; + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + sol::base_classes, sol::bases() + ); + + //Finally register the thing. + lua.set_usertype("Server", usertype); + } if( server ) { - luabridge::push(lua, server); - lua_setglobal(lua, "server"); + lua["server"] = server; } } void Script::exposeWorld() { - luabridge::getGlobalNamespace(lua) - .beginClass("World") - .addFunction("getTicks", &World::getTicks) - .addFunction("getFilename", &World::getFilename) - .addFunction("getNameStr", &World::getNameStr) - .addFunction("isClientObj", &World::isClientObj) - .addFunction("isServerObj", &World::isServerObj) - .addFunction("isShowTools", &World::isShowTools) - .addFunction("uidToEntity", &World::uidToEntity) - .addFunction("lineTrace", &World::lineTrace) - .addFunction("lineTraceList", &World::lineTraceList) - .addFunction("lineTraceNoEntities", &World::lineTraceNoEntities) - .addFunction("saveFile", &World::saveFile) - .addFunction("setShowTools", &World::setShowTools) - .addFunction("selectEntity", &World::selectEntity) - .addFunction("selectEntities", &World::selectEntities) - .addFunction("deselectGeometry", &World::deselectGeometry) - .endClass() - ; + lua.new_usertype("World", + "getTicks", &World::getTicks, + "getFilename", &World::getFilename, + "getNameStr", &World::getNameStr, + "isClientObj", &World::isClientObj, + "isServerObj", &World::isServerObj, + "isShowTools", &World::isShowTools, + "uidToEntity", &World::uidToEntity, + "lineTrace", &World::lineTrace, + "lineTraceList", &World::lineTraceList, + "lineTraceNoEntities", &World::lineTraceNoEntities, + "saveFile", &World::saveFile, + "setShowTools", &World::setShowTools, + "selectEntity", &World::selectEntity, + "selectEntities", &World::selectEntities, + "deselectGeometry", &World::deselectGeometry + ); if( world ) { - luabridge::push(lua, world); - lua_setglobal(lua, "world"); + lua["world"] = world; } LinkedList::exposeToScript(lua, "LinkedListWorldPtr", "NodeWorldPtr"); - ArrayList::exposeToScript(lua, "ArrayListWorldPtr"); -} - -void Script::exposeEntity() { - luabridge::getGlobalNamespace(lua) - .beginClass("Entity") - .addFunction("getName", &Entity::getName) - .addFunction("getUID", &Entity::getUID) - .addFunction("getTicks", &Entity::getTicks) - .addFunction("getPos", &Entity::getPos) - .addFunction("getVel", &Entity::getVel) - .addFunction("getAng", &Entity::getAng) - .addFunction("getRot", &Entity::getRot) - .addFunction("getScale", &Entity::getScale) - .addFunction("getScriptStr", &Entity::getScriptStr) - .addFunction("isToBeDeleted", &Entity::isToBeDeleted) - .addFunction("getFlags", &Entity::getFlags) - .addFunction("setKeyValue", &Entity::setKeyValue) - .addFunction("deleteKeyValue", &Entity::deleteKeyValue) - .addFunction("getKeyValueAsString", &Entity::getKeyValueAsString) - .addFunction("getKeyValueAsFloat", &Entity::getKeyValueAsFloat) - .addFunction("getKeyValueAsInt", &Entity::getKeyValueAsInt) - .addFunction("getKeyValue", &Entity::getKeyValue) - .addFunction("isFlag", &Entity::isFlag) - .addFunction("isFalling", &Entity::isFalling) - .addFunction("getLastUpdate", &Entity::getLastUpdate) - .addFunction("getDefName", &Entity::getDefName) - .addFunction("getSort", &Entity::getSort) - .addFunction("isSelected", &Entity::isSelected) - .addFunction("isHighlighted", &Entity::isHighlighted) - .addFunction("setName", &Entity::setName) - .addFunction("setFlags", &Entity::setFlags) - .addFunction("setFlag", &Entity::setFlag) - .addFunction("resetFlag", &Entity::resetFlag) - .addFunction("toggleFlag", &Entity::toggleFlag) - .addFunction("setPos", &Entity::setPos) - .addFunction("setVel", &Entity::setVel) - .addFunction("setAng", &Entity::setAng) - .addFunction("setRot", &Entity::setRot) - .addFunction("setScale", &Entity::setScale) - .addFunction("setScriptStr", &Entity::setScriptStr) - .addFunction("setSelected", &Entity::setSelected) - .addFunction("setHighlighted", &Entity::setHighlighted) - .addFunction("setFalling", &Entity::setFalling) - .addFunction("remove", &Entity::remove) - .addFunction("animate", &Entity::animate) - .addFunction("isNearCharacter", &Entity::isNearCharacter) - .addFunction("isCrouching", &Entity::isCrouching) - .addFunction("isMoving", &Entity::isMoving) - .addFunction("hasJumped", &Entity::hasJumped) - .addFunction("getLookDir", &Entity::getLookDir) - .addFunction("checkCollision", &Entity::checkCollision) - .addFunction("copy", &Entity::copy) - .addFunction("update", &Entity::update) - .addFunction("hasComponent", &Entity::hasComponent) - .addFunction("removeComponentByName", &Entity::removeComponentByName) - .addFunction("removeComponentByUID", &Entity::removeComponentByUID) - .addFunction("addComponent", &Entity::addComponent) - .addFunction("addBBox", &Entity::addComponent) - .addFunction("addModel", &Entity::addComponent) - .addFunction("addCamera", &Entity::addComponent) - .addFunction("addLight", &Entity::addComponent) - .addFunction("addSpeaker", &Entity::addComponent) - .addFunction("addCharacter", &Entity::addComponent) - .addFunction("findComponentByName", &Entity::findComponentByName) - .addFunction("findBBoxByName", &Entity::findComponentByName) - .addFunction("findModelByName", &Entity::findComponentByName) - .addFunction("findLightByName", &Entity::findComponentByName) - .addFunction("findCameraByName", &Entity::findComponentByName) - .addFunction("findSpeakerByName", &Entity::findComponentByName) - .addFunction("findCharacterByName", &Entity::findComponentByName) - .addFunction("lineTrace", &Entity::lineTrace) - .addFunction("findAPath", &Entity::findAPath) - .addFunction("findRandomPath", &Entity::findRandomPath) - .addFunction("pathFinished", &Entity::pathFinished) - .addFunction("hasPath", &Entity::hasPath) - .addFunction("getPathNodePosition", &Entity::getPathNodePosition) - .addFunction("getPathNodeDir", &Entity::getPathNodeDir) - .addFunction("getCurrentTileX", &Entity::getCurrentTileX) - .addFunction("getCurrentTileY", &Entity::getCurrentTileY) - .addFunction("getCurrentTileZ", &Entity::getCurrentTileZ) - .addFunction("isLocalPlayer", &Entity::isLocalPlayer) - .endClass() - ; - - // expose components - exposeComponent(); - exposeBBox(); - exposeModel(); - exposeLight(); - exposeCamera(); - exposeSpeaker(); - exposeCharacter(); - - if( entity ) { - luabridge::push(lua, entity); - lua_setglobal(lua, "entity"); - } - - LinkedList::exposeToScript(lua, "LinkedListEntityPtr", "NodeEntityPtr"); - ArrayList::exposeToScript(lua, "ArrayListEntityPtr"); -} - -void Script::exposeComponent() { - luabridge::getGlobalNamespace(lua) - .beginClass("Component") - .addFunction("getType", &Component::getType) - .addFunction("getParent", &Component::getParent) - .addFunction("isEditorOnly", &Component::isEditorOnly) - .addFunction("isUpdateNeeded", &Component::isUpdateNeeded) - .addFunction("getUID", &Component::getUID) - .addFunction("getName", &Component::getName) - .addFunction("getLocalPos", &Component::getLocalPos) - .addFunction("getLocalAng", &Component::getLocalAng) - .addFunction("getLocalScale", &Component::getLocalScale) - .addFunction("getGlobalPos", &Component::getGlobalPos) - .addFunction("getGlobalAng", &Component::getGlobalAng) - .addFunction("getGlobalScale", &Component::getGlobalScale) - .addFunction("setEditorOnly", &Component::setEditorOnly) - .addFunction("setName", &Component::setName) - .addFunction("setLocalPos", &Component::setLocalPos) - .addFunction("setLocalAng", &Component::setLocalAng) - .addFunction("setLocalScale", &Component::setLocalScale) - .addFunction("setLocalMat", &Component::setLocalMat) - .addFunction("update", &Component::update) - .addFunction("remove", &Component::remove) - .addFunction("checkCollision", &Component::checkCollision) - .addFunction("hasComponent", &Component::hasComponent) - .addFunction("removeComponentByName", &Component::removeComponentByName) - .addFunction("removeComponentByUID", &Component::removeComponentByUID) - .addFunction("addComponent", &Component::addComponent) - .addFunction("addBBox", &Component::addComponent) - .addFunction("addModel", &Component::addComponent) - .addFunction("addCamera", &Component::addComponent) - .addFunction("addLight", &Component::addComponent) - .addFunction("addSpeaker", &Component::addComponent) - .addFunction("addCharacter", &Component::addComponent) - .addFunction("findComponentByName", &Component::findComponentByName) - .addFunction("findBBoxByName", &Component::findComponentByName) - .addFunction("findModelByName", &Component::findComponentByName) - .addFunction("findLightByName", &Component::findComponentByName) - .addFunction("findCameraByName", &Component::findComponentByName) - .addFunction("findSpeakerByName", &Component::findComponentByName) - .addFunction("findCharacterByName", &Component::findComponentByName) - .addFunction("rotate", &Component::rotate) - .addFunction("translate", &Component::translate) - .addFunction("scale", &Component::scale) - .addFunction("revertRotation", &Component::revertRotation) - .addFunction("revertTranslation", &Component::revertTranslation) - .addFunction("revertScale", &Component::revertScale) - .addFunction("revertToIdentity", &Component::revertToIdentity) - .addFunction("shootLaser", &Component::shootLaser) - .endClass() - ; - - LinkedList::exposeToScript(lua, "LinkedListComponentPtr", "NodeComponentPtr"); - ArrayList::exposeToScript(lua, "ArrayListComponentPtr"); -} - -void Script::exposeBBox() { - luabridge::getGlobalNamespace(lua) - .deriveClass("BBox") - .addFunction("nearestCeiling", &BBox::nearestCeiling) - .addFunction("nearestFloor", &BBox::nearestFloor) - .addFunction("distToCeiling", &BBox::distToCeiling) - .addFunction("distToFloor", &BBox::distToFloor) - .addFunction("getShape", &BBox::getShape) - .addFunction("getMass", &BBox::getMass) - .addFunction("isEnabled", &BBox::isEnabled) - .addFunction("setEnabled", &BBox::setEnabled) - .addFunction("setShape", &BBox::setShape) - .addFunction("setMass", &BBox::setMass) - .addFunction("findAllOverlappingEntities", &BBox::findAllOverlappingEntities) - .endClass() - ; - - LinkedList::exposeToScript(lua, "LinkedListBBoxPtr", "NodeBBoxPtr"); - ArrayList::exposeToScript(lua, "ArrayListBBoxPtr"); -} - -void Script::exposeModel() { - luabridge::getGlobalNamespace(lua) - .deriveClass("Model") - .addFunction("findBone", &Model::findBone) - .addFunction("findAnimation", &Model::findAnimation) - .addFunction("animate", &Model::animate) - .addFunction("hasAnimations", &Model::hasAnimations) - .addFunction("getMesh", &Model::getMesh) - .addFunction("getMaterial", &Model::getMaterial) - .addFunction("getDepthFailMat", &Model::getDepthFailMat) - .addFunction("getAnimation", &Model::getAnimation) - .addFunction("getShaderVars", &Model::getShaderVars) - .addFunction("getAnimTicks", &Model::getAnimTicks) - .addFunction("isAnimDone", &Model::isAnimDone) - .addFunction("getAnimationSpeed", &Model::getAnimationSpeed) - .addFunction("setMesh", &Model::setMesh) - .addFunction("setMaterial", &Model::setMaterial) - .addFunction("setDepthFailMat", &Model::setDepthFailMat) - .addFunction("setAnimation", &Model::setAnimation) - .addFunction("setShaderVars", &Model::setShaderVars) - .addFunction("setAnimationSpeed", &Model::setAnimationSpeed) - .addFunction("updateSkin", &Model::updateSkin) - .addFunction("getCurrentAnimation", &Model::getCurrentAnimation) - .addFunction("getPreviousAnimation", &Model::getPreviousAnimation) - .endClass() - ; - - luabridge::getGlobalNamespace(lua) - .beginClass("AnimationState") - .addFunction("getName", &AnimationState::getName) - .addFunction("getTicks", &AnimationState::getTicks) - .addFunction("getTicksRate", &AnimationState::getTicksRate) - .addFunction("getBegin", &AnimationState::getBegin) - .addFunction("getEnd", &AnimationState::getEnd) - .addFunction("getLength", &AnimationState::getLength) - .addFunction("getWeight", &AnimationState::getWeight) - .addFunction("getWeightRate", &AnimationState::getWeightRate) - .addFunction("isLoop", &AnimationState::isLoop) - .addFunction("isFinished", &AnimationState::isFinished) - .addFunction("setTicks", &AnimationState::setTicks) - .addFunction("setTicksRate", &AnimationState::setTicksRate) - .addFunction("setWeight", &AnimationState::setWeight) - .addFunction("setWeightRate", &AnimationState::setWeightRate) - .addFunction("setWeights", &AnimationState::setWeights) - .addFunction("setWeightRates", &AnimationState::setWeightRates) - .addFunction("clearWeights", &AnimationState::clearWeights) - .endClass() - ; - - luabridge::getGlobalNamespace(lua) - .beginClass("bone_t") - .addData("valid", &Model::bone_t::valid, true) - .addData("name", &Model::bone_t::name, true) - .addData("mat", &Model::bone_t::mat, true) - .addData("pos", &Model::bone_t::pos, true) - .addData("ang", &Model::bone_t::ang, true) - .addData("scale", &Model::bone_t::scale, true) - .endClass() - ; - - LinkedList::exposeToScript(lua, "LinkedListModelPtr", "NodeModelPtr"); - ArrayList::exposeToScript(lua, "ArrayListModelPtr"); -} - -void Script::exposeLight() { - luabridge::getGlobalNamespace(lua) - .deriveClass("Light") - .addFunction("getColor", &Light::getColor) - .addFunction("getIntensity", &Light::getIntensity) - .addFunction("getRadius", &Light::getRadius) - .addFunction("getArc", &Light::getArc) - .addFunction("isShadow", &Light::isShadow) - .addFunction("setColor", &Light::setColor) - .addFunction("setIntensity", &Light::setIntensity) - .addFunction("setRadius", &Light::setRadius) - .addFunction("setShape", &Light::setShape) - .addFunction("setArc", &Light::setArc) - .addFunction("setShadow", &Light::setShadow) - .endClass() - ; - - LinkedList::exposeToScript(lua, "LinkedListLightPtr", "NodeLightPtr"); - ArrayList::exposeToScript(lua, "ArrayListLightPtr"); -} - -void Script::exposeCamera() { - luabridge::getGlobalNamespace(lua) - .deriveClass("Camera") - .addFunction("setupProjection", &Camera::setupProjection) - .addFunction("worldPosToScreenPos", &Camera::worldPosToScreenPos) - .addFunction("screenPosToWorldRay", &Camera::screenPosToWorldRay) - .addFunction("getClipNear", &Camera::getClipNear) - .addFunction("getClipFar", &Camera::getClipFar) - .addFunction("getWin", &Camera::getWin) - .addFunction("getFov", &Camera::getFov) - .addFunction("isOrtho", &Camera::isOrtho) - .addFunction("setClipNear", &Camera::setClipNear) - .addFunction("setClipFar", &Camera::setClipFar) - .addFunction("setWin", &Camera::setWin) - .addFunction("setFov", &Camera::setFov) - .addFunction("setOrtho", &Camera::setOrtho) - .endClass() - ; - - LinkedList::exposeToScript(lua, "LinkedListCameraPtr", "NodeCameraPtr"); - ArrayList::exposeToScript(lua, "ArrayListCameraPtr"); -} - -void Script::exposeSpeaker() { - luabridge::getGlobalNamespace(lua) - .deriveClass("Speaker") - .addFunction("playSound", &Speaker::playSound) - .addFunction("stopSound", &Speaker::stopSound) - .addFunction("stopAllSounds", &Speaker::stopAllSounds) - .addFunction("getDefaultSound", &Speaker::getDefaultSound) - .addFunction("getDefaultRange", &Speaker::getDefaultRange) - .addFunction("isDefaultLoop", &Speaker::isDefaultLoop) - .endClass() - ; - - LinkedList::exposeToScript(lua, "LinkedListSpeakerPtr", "NodeSpeakerPtr"); - ArrayList::exposeToScript(lua, "ArrayListSpeakerPtr"); -} - -void Script::exposeCharacter() { - luabridge::getGlobalNamespace(lua) - .deriveClass("Character") - .addFunction("getHp", &Character::getHp) - .addFunction("getMp", &Character::getMp) - .addFunction("getSex", &Character::getSex) - .addFunction("getLevel", &Character::getLevel) - .addFunction("getXp", &Character::getXp) - .addFunction("getHunger", &Character::getHunger) - .addFunction("getNanoMatter", &Character::getNanoMatter) - .addFunction("getBioMatter", &Character::getBioMatter) - .addFunction("getNeuroThread", &Character::getNeuroThread) - .addFunction("getGold", &Character::getGold) - .addFunction("getStrength", &Character::getStrength) - .addFunction("getDexterity", &Character::getDexterity) - .addFunction("getIntelligence", &Character::getIntelligence) - .addFunction("getConstitution", &Character::getConstitution) - .addFunction("getPerception", &Character::getPerception) - .addFunction("getCharisma", &Character::getCharisma) - .addFunction("getLuck", &Character::getLuck) - .addFunction("setHp", &Character::setHp) - .addFunction("setMp", &Character::setMp) - .addFunction("setSex", &Character::setSex) - .addFunction("setLevel", &Character::setLevel) - .addFunction("setXp", &Character::setXp) - .addFunction("setHunger", &Character::setHunger) - .addFunction("setNanoMatter", &Character::setNanoMatter) - .addFunction("setBioMatter", &Character::setBioMatter) - .addFunction("setNeuroThread", &Character::setNeuroThread) - .addFunction("setGold", &Character::setGold) - .addFunction("setStrength", &Character::setStrength) - .addFunction("setDexterity", &Character::setDexterity) - .addFunction("setIntelligence", &Character::setIntelligence) - .addFunction("setConstitution", &Character::setConstitution) - .addFunction("setPerception", &Character::setPerception) - .addFunction("setCharisma", &Character::setCharisma) - .addFunction("setLuck", &Character::setLuck) - .endClass() - ; - - LinkedList::exposeToScript(lua, "LinkedListCharacterPtr", "NodeCharacterPtr"); - ArrayList::exposeToScript(lua, "ArrayListCharacterPtr"); + ArrayList::exposeToScript(lua, "ArrayListWorldPtr"); //TODO: For a quick test, NOW try exposing that getArray() method that was erroring (since the World class is now bound). } void Script::exposeEmitter() { - // todo + // todo } + diff --git a/src/Script.hpp b/src/Script.hpp index 888a033..2098d8d 100644 --- a/src/Script.hpp +++ b/src/Script.hpp @@ -2,7 +2,8 @@ #pragma once -class Engine; +#include + class Client; class Server; class World; @@ -11,209 +12,128 @@ class Light; class Frame; class Editor; +//#include "Engine.hpp" #include "String.hpp" -#include +#include "sol.hpp" -class Script { +class Script +{ public: - Script(Client& _client); - Script(Server& _server); - Script(World& _world); - Script(Entity& _entity); - Script(Frame& _frame); + Script(Client& client); + Script(Server& server); + Script(World& world); + Script(Entity& entity); + Script(Frame& frame); ~Script(); - // script variable types - enum var_t { - TYPE_BOOLEAN, - TYPE_INTEGER, - TYPE_FLOAT, - TYPE_STRING, - TYPE_POINTER, - TYPE_NIL, - TYPE_MAX + //NOTE: Every Script::Args is inextricably tied to its respective Script engine instance! You shall never reuse a Script::Args with another Script engine instance. + struct Args + { + std::vector params; }; - // script function parameter - struct param_t { - param_t() {} - virtual ~param_t() {} + // load and evaluate the given script + // @param filename filename of the script to run + // @return 0 on success, nonzero on failure + bool load(const char* filename); - virtual var_t getType() = 0; - virtual void push(lua_State* lua) = 0; - virtual param_t* copy() = 0; - }; + static void dispatchFunctionErrorMessage(const String& filename, const char* functionName, const sol::error& err); - // boolean parameter - struct param_bool_t : param_t { - param_bool_t() {} - param_bool_t(const bool _value) : value(_value) {} - virtual ~param_bool_t() {} - virtual var_t getType() override { return TYPE_BOOLEAN; } - virtual void push(lua_State* lua) override { - lua_pushboolean(lua, value ? 1 : 0); + template + bool dispatchFunction(const char* functionName, Args&&...args) + { + if (broken) + { + return false; } - virtual param_t* copy() override { - return new param_bool_t(value); - } - bool value = false; - }; - // integer parameter - struct param_int_t : param_t { - param_int_t() {} - param_int_t(const int _value) : value(_value) {} - virtual ~param_int_t() {} - virtual var_t getType() override { return TYPE_INTEGER; } - virtual void push(lua_State* lua) override { - lua_pushinteger(lua, static_cast(value)); - } - virtual param_t* copy() override { - return new param_int_t(value); - } - int value = 0; - }; + sol::protected_function myFunc = lua[functionName]; - // float parameter - struct param_float_t : param_t { - param_float_t() {} - param_float_t(const float _value) : value(_value) {} - virtual ~param_float_t() {} - virtual var_t getType() override { return TYPE_FLOAT; } - virtual void push(lua_State* lua) override { - lua_pushnumber(lua, static_cast(value)); - } - virtual param_t* copy() override { - return new param_float_t(value); + sol::protected_function_result result; + result = myFunc(args...); + if (!result.valid()) + { + sol::error err = result; + dispatchFunctionErrorMessage(filename, functionName, err); + broken = true; + return false; } - float value = 0.f; - }; - // string parameter - struct param_string_t : param_t { - param_string_t() {} - param_string_t(const String& _value) : value(_value) {} - virtual ~param_string_t() {} - virtual var_t getType() override { return TYPE_STRING; } - virtual void push(lua_State* lua) override { - lua_pushlstring(lua, value.get(), value.getSize()); - } - virtual param_t* copy() override { - return new param_string_t(value); - } - String value; - }; + return true; + } - // pointer parameter - struct param_pointer_t : param_t { - param_pointer_t() {} - param_pointer_t(void* _value) : value(_value) {} - virtual ~param_pointer_t() {} - virtual var_t getType() override { return TYPE_POINTER; } - virtual void push(lua_State* lua) override { - lua_pushlightuserdata(lua, value); + bool dispatchFunction(const char* functionName, const Script::Args& params) + { + if (0 == params.params.size()) + { + return dispatchFunction(functionName); } - virtual param_t* copy() override { - return new param_pointer_t(value); - } - void* value = nullptr; - }; - // nil parameter - struct param_nil_t : param_t { - param_nil_t() {} - virtual ~param_nil_t() {} - virtual var_t getType() override { return TYPE_NIL; } - virtual void push(lua_State* lua) override { - lua_pushnil(lua); + if (broken) + { + return false; } - virtual param_t* copy() override { - return new param_nil_t(); - } - }; - // script function arguments - class Args { - public: - Args() {} - Args(const Args& src) { - for (size_t c = 0; c < src.list.getSize(); ++c) { - list.push(src.list[c]->copy()); - } - } - ~Args() { - while (list.getSize() > 0) { - delete list.pop(); - } - } + sol::protected_function myFunc = lua[functionName]; - // getters & setters - const ArrayList& getList() const { return list; } - const size_t getSize() const { return list.getSize(); } - - // push all args onto the lua stack - // @param lua the lua stack to push args into - void push(lua_State* lua) { - for (size_t c = 0; c < list.getSize(); ++c) { - param_t* param = list[c]; - param->push(lua); - } - while (list.getSize() > 0) { - delete list.pop(); - } - } - - // add a bool to the args list - // @param value the value to init with - void addBool(const bool value) { - list.push(new param_bool_t(value)); - } + sol::protected_function_result result; + result = myFunc(sol::as_args(params.params)); - // add an int to the args list - // @param value the value to init with - void addInt(const int value) { - list.push(new param_int_t(value)); + if (!result.valid()) + { + sol::error err = result; + dispatchFunctionErrorMessage(filename, functionName, err); + broken = true; + return false; } - // add a float to the args list - // @param value the value to init with - void addFloat(const float value) { - list.push(new param_float_t(value)); - } + return true; + } - // add a string to the args list - // @param value the value to init with - void addString(const String& value) { - list.push(new param_string_t(value)); + template + bool dispatchFunction(const char* functionName, Script::Args& params, Args&&...args) + { + if (0 == params.params.size()) + { + return dispatchFunction(functionName, args...); } - // add a pointer to the args list - // @param value the value to init with - void addPointer(void* value) { - list.push(new param_pointer_t(value)); + if (broken) + { + return false; } - // add a nil to the args list - void addNil() { - list.push(new param_nil_t()); + sol::protected_function myFunc = lua[functionName]; + + sol::protected_function_result result; + result = myFunc(sol::as_args(params.params), args...); + + if (!result.valid()) + { + sol::error err = result; + dispatchFunctionErrorMessage(filename, functionName, err); + broken = true; + return false; } - private: - ArrayList list; - }; + return true; + } - // load and evaluate the given script - // @param filename filename of the script to run - // @return 0 on success, nonzero on failure - int load(const char* filename); + template + void addParam(T&& obj, Script::Args& params) + { + params.params.push_back(makeObject(obj)); + } - // evaluate a function. args are discarded after use - // @param function name of the function to execute - // @param args a list of args to pass to the function - // @return 0 on success, nonzero on failure - int dispatch(const char* function, Args* args = nullptr); + template + sol::object makeObject(T&& obj) + { + return sol::make_object(lua, obj); + } private: + sol::state lua; + // class pointers: // if these are set, this script engine reliably owns that object's functionality Engine* engine = nullptr; @@ -230,6 +150,9 @@ class Script { // if an error occurs, this flag will raise, then no more dispatches will work bool broken = false; + // common constructor that initializes all universal base data. + Script(); + // exposition functions void exposeEngine(); void exposeFrame(); @@ -251,5 +174,4 @@ class Script { void exposeEmitter(); void exposeEditor(Editor& _editor); - lua_State* lua = nullptr; }; diff --git a/src/Server.cpp b/src/Server.cpp index b1ba766..7a8f05e 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -24,7 +24,7 @@ Server::~Server() { // free script engine if( script ) { - script->dispatch("term"); + script->dispatchFunction("term"); delete script; } } @@ -34,7 +34,7 @@ void Server::init() { net->host(Net::defaultPort); script->load("scripts/server/main.lua"); - script->dispatch("init"); + script->dispatchFunction("init"); // start a playtest if( mainEngine->isPlayTest() ) { @@ -491,7 +491,7 @@ void Server::onDisconnect(Uint32 remoteID) { void Server::preProcess() { if( framesToRun ) { - script->dispatch("preprocess"); + script->dispatchFunction("preprocess"); } handleNetMessages(); @@ -503,7 +503,7 @@ void Server::process() { Game::process(); for( Uint32 frame=0; framedispatch("process"); + script->dispatchFunction("process"); } } @@ -511,7 +511,7 @@ void Server::postProcess() { Game::postProcess(); if( framesToRun ) { - script->dispatch("postprocess"); + script->dispatchFunction("postprocess"); // send entity updates to client if( net->isConnected() ) { diff --git a/src/Speaker.cpp b/src/Speaker.cpp index e14718a..b405883 100644 --- a/src/Speaker.cpp +++ b/src/Speaker.cpp @@ -263,4 +263,30 @@ void Speaker::serialize(FileInterface * file) { playSound(defaultSound,defaultLoop,defaultRange); } } -} \ No newline at end of file +} + +//These functions are not in the script.cpp file since they drastically increase compile time and memory usage due to heavy template usage. +void Script::exposeSpeaker() { + { + //First identify the constructors. + sol::constructors constructors; + + //Then do the thing. + sol::usertype usertype(constructors, + sol::base_classes, sol::bases(), + "playSound", &Speaker::playSound, + "stopSound", &Speaker::stopSound, + "stopAllSounds", &Speaker::stopAllSounds, + "getDefaultSound", &Speaker::getDefaultSound, + "getDefaultRange", &Speaker::getDefaultRange, + "isDefaultLoop", &Speaker::isDefaultLoop + ); + + //Finally register the thing. + lua.set_usertype("Speaker", usertype); + } + + LinkedList::exposeToScript(lua, "LinkedListSpeakerPtr", "NodeSpeakerPtr"); + ArrayList::exposeToScript(lua, "ArrayListSpeakerPtr"); +} + diff --git a/src/sol.hpp b/src/sol.hpp new file mode 100644 index 0000000..30cb4f4 --- /dev/null +++ b/src/sol.hpp @@ -0,0 +1,22180 @@ +// The MIT License (MIT) + +// Copyright (c) 2013-2018 Rapptz, ThePhD and contributors + +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +// This file was generated with a script. +// Generated 2018-11-28 08:50:22.534324 UTC +// This header was generated with sol v2.20.6 (revision 9b782ff) +// https://github.com/ThePhD/sol2 + +#ifndef SOL_SINGLE_INCLUDE_HPP +#define SOL_SINGLE_INCLUDE_HPP + +// beginning of sol.hpp + +#ifndef SOL_HPP +#define SOL_HPP + +#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) +#define SOL_INSIDE_UNREAL 1 +#endif // Unreal Engine 4 bullshit + +#if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL +#ifdef check +#define SOL_INSIDE_UNREAL_REMOVED_CHECK 1 +#undef check +#endif +#endif // Unreal Engine 4 Bullshit + +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#pragma GCC diagnostic ignored "-Wconversion" +#if __GNUC__ > 6 +#pragma GCC diagnostic ignored "-Wnoexcept-type" +#endif +#elif defined(__clang__) +#elif defined _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4324 ) // structure was padded due to alignment specifier +#pragma warning( disable : 4503 ) // decorated name horse shit +#pragma warning( disable : 4702 ) // unreachable code +#pragma warning( disable: 4127 ) // 'conditional expression is constant' yeah that's the point your old compilers don't have `if constexpr` you jerk +#pragma warning( disable: 4505 ) // some other nonsense warning +#endif // clang++ vs. g++ vs. VC++ + +// beginning of sol/forward.hpp + +// beginning of sol/feature_test.hpp + +#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) +#ifndef SOL_CXX17_FEATURES +#define SOL_CXX17_FEATURES 1 +#endif // C++17 features macro +#endif // C++17 features check + +#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES +#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201403L)))) +#ifndef SOL_NOEXCEPT_FUNCTION_TYPE +#define SOL_NOEXCEPT_FUNCTION_TYPE 1 +#endif // noexcept is part of a function's type +#endif // compiler-specific checks +#if defined(__clang__) && defined(__APPLE__) +#if defined(__has_include) +#if __has_include() +#define SOL_STD_VARIANT 1 +#endif // has include nonsense +#endif // __has_include +#else +#define SOL_STD_VARIANT 1 +#endif // Clang screws up variant +#endif // C++17 only + +// beginning of sol/config.hpp + +#ifdef _MSC_VER + #if defined(_DEBUG) && !defined(NDEBUG) + + #ifndef SOL_IN_DEBUG_DETECTED + #define SOL_IN_DEBUG_DETECTED 1 + #endif + + #endif // VC++ Debug macros + + #ifndef _CPPUNWIND + #ifndef SOL_NO_EXCEPTIONS + #define SOL_NO_EXCEPTIONS 1 + #endif + #endif // Automatic Exceptions + + #ifndef _CPPRTTI + #ifndef SOL_NO_RTTI + #define SOL_NO_RTTI 1 + #endif + #endif // Automatic RTTI +#elif defined(__GNUC__) || defined(__clang__) + + #if !defined(NDEBUG) && !defined(__OPTIMIZE__) + + #ifndef SOL_IN_DEBUG_DETECTED + #define SOL_IN_DEBUG_DETECTED 1 + #endif + + #endif // Not Debug && g++ optimizer flag + + #ifndef __EXCEPTIONS + #ifndef SOL_NO_EXCEPTIONS + #define SOL_NO_EXCEPTIONS 1 + #endif + #endif // No Exceptions + + #ifndef __GXX_RTTI + #ifndef SOL_NO_RTII + #define SOL_NO_RTTI 1 + #endif + #endif // No RTTI + +#endif // vc++ || clang++/g++ + +#if defined(SOL_CHECK_ARGUMENTS) && SOL_CHECK_ARGUMENTS + + // Checks low-level getter function + // (and thusly, affects nearly entire framework) + #if !defined(SOL_SAFE_GETTER) + #define SOL_SAFE_GETTER 1 + #endif + + // Checks access on usertype functions + // local my_obj = my_type.new() + // my_obj.my_member_function() + // -- bad syntax and crash + #if !defined(SOL_SAFE_USERTYPE) + #define SOL_SAFE_USERTYPE 1 + #endif + + // Checks sol::reference derived boundaries + // sol::function ref(L, 1); + // sol::userdata sref(L, 2); + #if !defined(SOL_SAFE_REFERENCES) + #define SOL_SAFE_REFERENCES 1 + #endif + + // Changes all typedefs of sol::function to point to the + // protected_function version, instead of unsafe_function + #if !defined(SOL_SAFE_FUNCTION) + #define SOL_SAFE_FUNCTION 1 + #endif + + // Checks function parameters and + // returns upon call into/from Lua + // local a = 1 + // local b = "woof" + // my_c_function(a, b) + #if !defined(SOL_SAFE_FUNCTION_CALLS) + #define SOL_SAFE_FUNCTION_CALLS 1 + #endif + + // Checks conversions + // int v = lua["bark"]; + // int v2 = my_sol_function(); + #if !defined(SOL_SAFE_PROXIES) + #define SOL_SAFE_PROXIES 1 + #endif + + // Check overflowing number conversions + // for things like 64 bit integers that don't fit in a typical lua_Number + // for Lua 5.1 and 5.2 + #if !defined(SOL_SAFE_NUMERICS) + #define SOL_SAFE_NUMERICS 1 + #endif + + // Turn off Number Precision Checks + // if this is defined, we do not do range + // checks on integers / unsigned integers that might + // be bigger than what Lua can represent + #if !defined(SOL_NO_CHECK_NUMBER_PRECISION) + // off by default + #define SOL_NO_CHECK_NUMBER_PRECISION 0 + #endif + +#endif // Turn on Safety for all if top-level macro is defined + +#if defined(SOL_IN_DEBUG_DETECTED) && SOL_IN_DEBUG_DETECTED + + #if !defined(SOL_SAFE_REFERENCES) + // Ensure that references are forcefully type-checked upon construction + #define SOL_SAFE_REFERENCES 1 + #endif + + // Safe usertypes checks for errors such as + // obj = my_type.new() + // obj.f() -- note the '.' instead of ':' + // usertypes should be safe no matter what + #if !defined(SOL_SAFE_USERTYPE) + #define SOL_SAFE_USERTYPE 1 + #endif + + #if !defined(SOL_SAFE_FUNCTION_CALLS) + // Function calls from Lua should be automatically safe in debug mode + #define SOL_SAFE_FUNCTION_CALLS 1 + #endif + + // Print any exceptions / errors that occur + // in debug mode to the default error stream / console + #if !defined(SOL_PRINT_ERRORS) + #define SOL_PRINT_ERRORS 1 + #endif + +#endif // DEBUG: Turn on all debug safety features for VC++ / g++ / clang++ and similar + +#if !defined(SOL_PRINT_ERRORS) +#define SOL_PRINT_ERRORS 0 +#endif + +#if !defined(SOL_DEFAULT_PASS_ON_ERROR) +#define SOL_DEFAULT_PASS_ON_ERROR 0 +#endif + +#if !defined(SOL_ENABLE_INTEROP) +#define SOL_ENABLE_INTEROP 0 +#endif + +#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) +#if !defined(SOL_NO_NIL) +#define SOL_NO_NIL 1 +#endif +#endif // avoiding nil defines / keywords + +#if defined(SOL_USE_BOOST) && SOL_USE_BOOST +#ifndef SOL_UNORDERED_MAP_COMPATIBLE_HASH +#define SOL_UNORDERED_MAP_COMPATIBLE_HASH 1 +#endif // SOL_UNORDERED_MAP_COMPATIBLE_HASH +#endif + +#ifndef SOL_STACK_STRING_OPTIMIZATION_SIZE +#define SOL_STACK_STRING_OPTIMIZATION_SIZE 1024 +#endif // Optimized conversion routines using a KB or so off the stack + +// end of sol/config.hpp + +// beginning of sol/config_setup.hpp + +// end of sol/config_setup.hpp + +// end of sol/feature_test.hpp + +namespace sol { + + template + class basic_reference; + using reference = basic_reference; + using main_reference = basic_reference; + class stack_reference; + + struct proxy_base_tag; + template + struct proxy_base; + template + struct proxy; + + template + class usertype; + template + class simple_usertype; + template + class basic_table_core; + template + using table_core = basic_table_core; + template + using main_table_core = basic_table_core; + template + using stack_table_core = basic_table_core; + template + using basic_table = basic_table_core; + typedef table_core table; + typedef table_core global_table; + typedef main_table_core main_table; + typedef main_table_core main_global_table; + typedef stack_table_core stack_table; + typedef stack_table_core stack_global_table; + template + struct basic_environment; + using environment = basic_environment; + using main_environment = basic_environment; + using stack_environment = basic_environment; + template + class basic_function; + template + class basic_protected_function; + using unsafe_function = basic_function; + using safe_function = basic_protected_function; + using main_unsafe_function = basic_function; + using main_safe_function = basic_protected_function; + using stack_unsafe_function = basic_function; + using stack_safe_function = basic_protected_function; + using stack_aligned_unsafe_function = basic_function; + using stack_aligned_safe_function = basic_protected_function; + using protected_function = safe_function; + using main_protected_function = main_safe_function; + using stack_protected_function = stack_safe_function; + using stack_aligned_protected_function = stack_aligned_safe_function; +#if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION + using function = protected_function; + using main_function = main_protected_function; + using stack_function = stack_protected_function; +#else + using function = unsafe_function; + using main_function = main_unsafe_function; + using stack_function = stack_unsafe_function; +#endif + using stack_aligned_function = stack_aligned_unsafe_function; + using stack_aligned_stack_handler_function = basic_protected_function; + + struct unsafe_function_result; + struct protected_function_result; + using safe_function_result = protected_function_result; +#if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION + using function_result = safe_function_result; +#else + using function_result = unsafe_function_result; +#endif + + template + class basic_object; + template + class basic_userdata; + template + class basic_lightuserdata; + template + class basic_coroutine; + template + class basic_thread; + + using object = basic_object; + using userdata = basic_userdata; + using lightuserdata = basic_lightuserdata; + using thread = basic_thread; + using coroutine = basic_coroutine; + using main_object = basic_object; + using main_userdata = basic_userdata; + using main_lightuserdata = basic_lightuserdata; + using main_coroutine = basic_coroutine; + using stack_object = basic_object; + using stack_userdata = basic_userdata; + using stack_lightuserdata = basic_lightuserdata; + using stack_thread = basic_thread; + using stack_coroutine = basic_coroutine; + + struct stack_proxy_base; + struct stack_proxy; + struct variadic_args; + struct variadic_results; + struct stack_count; + struct this_state; + struct this_main_state; + struct this_environment; + + template + struct as_table_t; + template + struct as_container_t; + template + struct nested; + template + struct light; + template + struct user; + template + struct as_args_t; + template + struct protect_t; + template + struct filter_wrapper; + + template + struct usertype_traits; + template + struct unique_usertype_traits; +} // namespace sol + +// end of sol/forward.hpp + +// beginning of sol/state.hpp + +// beginning of sol/state_view.hpp + +// beginning of sol/error.hpp + +#include +#include + +namespace sol { + namespace detail { + struct direct_error_tag {}; + const auto direct_error = direct_error_tag{}; + } // namespace detail + + class error : public std::runtime_error { + private: + // Because VC++ is upsetting, most of the time! + std::string w; + + public: + error(const std::string& str) + : error(detail::direct_error, "lua: error: " + str) { + } + error(std::string&& str) + : error(detail::direct_error, "lua: error: " + std::move(str)) { + } + error(detail::direct_error_tag, const std::string& str) + : std::runtime_error(""), w(str) { + } + error(detail::direct_error_tag, std::string&& str) + : std::runtime_error(""), w(std::move(str)) { + } + + error(const error& e) = default; + error(error&& e) = default; + error& operator=(const error& e) = default; + error& operator=(error&& e) = default; + + virtual const char* what() const noexcept override { + return w.c_str(); + } + }; + +} // namespace sol + +// end of sol/error.hpp + +// beginning of sol/table.hpp + +// beginning of sol/table_core.hpp + +// beginning of sol/proxy.hpp + +// beginning of sol/traits.hpp + +// beginning of sol/tuple.hpp + +#include +#include + +namespace sol { + namespace detail { + using swallow = std::initializer_list; + } // namespace detail + + template + struct types { + typedef std::make_index_sequence indices; + static constexpr std::size_t size() { + return sizeof...(Args); + } + }; + namespace meta { + namespace detail { + template + struct tuple_types_ { typedef types type; }; + + template + struct tuple_types_> { typedef types type; }; + } // namespace detail + + template + using unqualified = std::remove_cv>; + + template + using unqualified_t = typename unqualified::type; + + template + using tuple_types = typename detail::tuple_types_::type; + + template + struct pop_front_type; + + template + using pop_front_type_t = typename pop_front_type::type; + + template + struct pop_front_type> { + typedef void front_type; + typedef types type; + }; + + template + struct pop_front_type> { + typedef Arg front_type; + typedef types type; + }; + + template + using tuple_element = std::tuple_element>; + + template + using tuple_element_t = std::tuple_element_t>; + + template + using unqualified_tuple_element = unqualified>; + + template + using unqualified_tuple_element_t = unqualified_t>; + + } // namespace meta +} // namespace sol + +// end of sol/tuple.hpp + +// beginning of sol/bind_traits.hpp + +namespace sol { +namespace meta { + namespace meta_detail { + + template + struct check_deducible_signature { + struct nat {}; + template + static auto test(int) -> decltype(&G::operator(), void()); + template + static auto test(...) -> nat; + + using type = std::is_void(0))>; + }; + } // namespace meta_detail + + template + struct has_deducible_signature : meta_detail::check_deducible_signature::type {}; + + namespace meta_detail { + + template + struct void_tuple_element : meta::tuple_element {}; + + template + struct void_tuple_element> { typedef void type; }; + + template + using void_tuple_element_t = typename void_tuple_element::type; + + template + struct basic_traits { + private: + typedef std::conditional_t::value, int, T>& first_type; + + public: + static const bool is_noexcept = it_is_noexcept; + static const bool is_member_function = std::is_void::value; + static const bool has_c_var_arg = has_c_variadic; + static const std::size_t arity = sizeof...(Args); + static const std::size_t free_arity = sizeof...(Args) + static_cast(!std::is_void::value); + typedef types args_list; + typedef std::tuple args_tuple; + typedef T object_type; + typedef R return_type; + typedef tuple_types returns_list; + typedef R(function_type)(Args...); + typedef std::conditional_t::value, args_list, types> free_args_list; + typedef std::conditional_t::value, R(Args...), R(first_type, Args...)> free_function_type; + typedef std::conditional_t::value, R (*)(Args...), R (*)(first_type, Args...)> free_function_pointer_type; + typedef std::remove_pointer_t signature_type; + template + using arg_at = void_tuple_element_t; + }; + + template ::value> + struct fx_traits : basic_traits {}; + + // Free Functions + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args..., ...); + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args..., ...); + }; + + // Member Functions + /* C-Style Variadics */ + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...); + }; + + /* Const Volatile */ + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile; + }; + + /* Member Function Qualifiers */ + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) &; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) &; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) &&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) &&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const&&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const&&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile&&; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile&&; + }; + +#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args..., ...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (*function_pointer_type)(Args..., ...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) noexcept; + }; + + /* Const Volatile */ + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) & noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) & noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) && noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) && noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const&& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const&& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args...) const volatile&& noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R (T::*function_pointer_type)(Args..., ...) const volatile&& noexcept; + }; + +#endif // noexcept is part of a function's type + +#if defined(_MSC_VER) && defined(_M_IX86) + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args...); + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...); + }; + + /* Const Volatile */ + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile; + }; + + /* Member Function Qualifiers */ + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) &; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const&; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) &&; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const&&; + }; + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&&; + }; + +#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE + + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args...) noexcept; + }; + + /* __stdcall cannot be applied to functions with varargs*/ + /*template + struct fx_traits<__stdcall R(Args..., ...) noexcept, false> : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept; + }; + + template + struct fx_traits : basic_traits { + typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) noexcept; + };*/ + + /* Const Volatile */ + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) & noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) & noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const& noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const& noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile& noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile& noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) && noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) && noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const&& noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const&& noexcept; + };*/ + + template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&& noexcept; + }; + + /* __stdcall does not work with varargs */ + /*template + struct fx_traits : basic_traits { + typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile&& noexcept; + };*/ +#endif // noexcept is part of a function's type +#endif // __stdcall x86 VC++ bug + + template + struct fx_traits : fx_traits::function_type, false> {}; + + template ::value> + struct callable_traits : fx_traits> { + }; + + template + struct callable_traits { + typedef std::conditional_t::value, std::add_lvalue_reference_t, R> return_type; + typedef return_type Arg; + typedef T object_type; + using signature_type = R(T::*); + static const bool is_noexcept = false; + static const bool is_member_function = false; + static const std::size_t arity = 1; + static const std::size_t free_arity = 2; + typedef std::tuple args_tuple; + typedef types args_list; + typedef types free_args_list; + typedef meta::tuple_types returns_list; + typedef return_type(function_type)(T&, return_type); + typedef return_type(*function_pointer_type)(T&, Arg); + typedef return_type(*free_function_pointer_type)(T&, Arg); + template + using arg_at = void_tuple_element_t; + }; + + } // namespace meta_detail + + template + struct bind_traits : meta_detail::callable_traits {}; + + template + using function_args_t = typename bind_traits::args_list; + + template + using function_signature_t = typename bind_traits::signature_type; + + template + using function_return_t = typename bind_traits::return_type; +} +} // namespace sol::meta + +// end of sol/bind_traits.hpp + +// beginning of sol/string_view.hpp + +#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES +#include +#endif // C++17 features +#include +#if defined(SOL_USE_BOOST) && SOL_USE_BOOST +#include +#endif + +namespace sol { +#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES + template > + using basic_string_view = std::basic_string_view; + typedef std::string_view string_view; + typedef std::wstring_view wstring_view; + typedef std::u16string_view u16string_view; + typedef std::u32string_view u32string_view; + typedef std::hash string_view_hash; +#else + template > + struct basic_string_view { + std::size_t s; + const Char* p; + + basic_string_view(const std::string& r) + : basic_string_view(r.data(), r.size()) { + } + basic_string_view(const Char* ptr) + : basic_string_view(ptr, Traits::length(ptr)) { + } + basic_string_view(const Char* ptr, std::size_t sz) + : s(sz), p(ptr) { + } + + static int compare(const Char* lhs_p, std::size_t lhs_sz, const Char* rhs_p, std::size_t rhs_sz) { + int result = Traits::compare(lhs_p, rhs_p, lhs_sz < rhs_sz ? lhs_sz : rhs_sz); + if (result != 0) + return result; + if (lhs_sz < rhs_sz) + return -1; + if (lhs_sz > rhs_sz) + return 1; + return 0; + } + + const Char* begin() const { + return p; + } + + const Char* end() const { + return p + s; + } + + const Char* cbegin() const { + return p; + } + + const Char* cend() const { + return p + s; + } + + const Char* data() const { + return p; + } + + std::size_t size() const { + return s; + } + + std::size_t length() const { + return size(); + } + + operator std::basic_string() const { + return std::basic_string(data(), size()); + } + + bool operator==(const basic_string_view& r) const { + return compare(p, s, r.data(), r.size()) == 0; + } + + bool operator==(const Char* r) const { + return compare(r, Traits::length(r), p, s) == 0; + } + + bool operator==(const std::basic_string& r) const { + return compare(r.data(), r.size(), p, s) == 0; + } + + bool operator!=(const basic_string_view& r) const { + return !(*this == r); + } + + bool operator!=(const char* r) const { + return !(*this == r); + } + + bool operator!=(const std::basic_string& r) const { + return !(*this == r); + } + }; + + template > + struct basic_string_view_hash { + typedef basic_string_view argument_type; + typedef std::size_t result_type; + + template + result_type operator()(const std::basic_string& r) const { + return (*this)(argument_type(r.c_str(), r.size())); + } + + result_type operator()(const argument_type& r) const { +#if defined(SOL_USE_BOOST) && SOL_USE_BOOST + return boost::hash_range(r.begin(), r.end()); +#else + // Modified, from libstdc++ + // An implementation attempt at Fowler No Voll, 1a. + // Supposedly, used in MSVC, + // GCC (libstdc++) uses MurmurHash of some sort for 64-bit though...? + // But, well. Can't win them all, right? + // This should normally only apply when NOT using boost, + // so this should almost never be tapped into... + std::size_t hash = 0; + const unsigned char* cptr = reinterpret_cast(r.data()); + for (std::size_t sz = r.size(); sz != 0; --sz) { + hash ^= static_cast(*cptr++); + hash *= static_cast(1099511628211ULL); + } + return hash; +#endif + } + }; +} // namespace sol + +namespace std { + template + struct hash< ::sol::basic_string_view > : ::sol::basic_string_view_hash {}; +} // namespace std + +namespace sol { + using string_view = basic_string_view; + using wstring_view = basic_string_view; + using u16string_view = basic_string_view; + using u32string_view = basic_string_view; + using string_view_hash = std::hash; +#endif // C++17 Support +} // namespace sol + +// end of sol/string_view.hpp + +#include +#include +#include +#include +#include +#include + +namespace sol { + template + using index_value = std::integral_constant; + + namespace meta { + typedef std::array sfinae_yes_t; + typedef std::array sfinae_no_t; + + template + struct identity { typedef T type; }; + + template + using identity_t = typename identity::type; + + template + struct is_tuple : std::false_type {}; + + template + struct is_tuple> : std::true_type {}; + + template + struct is_builtin_type : std::integral_constant::value || std::is_pointer::value || std::is_array::value> {}; + + template + struct unwrapped { + typedef T type; + }; + + template + struct unwrapped> { + typedef T type; + }; + + template + using unwrapped_t = typename unwrapped::type; + + template + struct unwrap_unqualified : unwrapped> {}; + + template + using unwrap_unqualified_t = typename unwrap_unqualified::type; + + template + struct remove_member_pointer; + + template + struct remove_member_pointer { + typedef R type; + }; + + template + struct remove_member_pointer { + typedef R type; + }; + + template + using remove_member_pointer_t = remove_member_pointer; + + namespace meta_detail { + template class Templ> + struct is_specialization_of : std::false_type {}; + template class Templ> + struct is_specialization_of, Templ> : std::true_type {}; + } + + template class Templ> + using is_specialization_of = meta_detail::is_specialization_of, Templ>; + + template + struct all_same : std::true_type {}; + + template + struct all_same : std::integral_constant::value && all_same::value> {}; + + template + struct any_same : std::false_type {}; + + template + struct any_same : std::integral_constant::value || any_same::value> {}; + + template + using boolean = std::integral_constant; + + template + using invoke_t = typename T::type; + + template + using invoke_b = boolean; + + template + using neg = boolean; + + template + using condition = std::conditional_t; + + template + struct all : boolean {}; + + template + struct all : condition, boolean> {}; + + template + struct any : boolean {}; + + template + struct any : condition, any> {}; + + enum class enable_t { + _ + }; + + constexpr const auto enabler = enable_t::_; + + template + using disable_if_t = std::enable_if_t; + + template + using enable = std::enable_if_t::value, enable_t>; + + template + using disable = std::enable_if_t>::value, enable_t>; + + template + using enable_any = std::enable_if_t::value, enable_t>; + + template + using disable_any = std::enable_if_t>::value, enable_t>; + + template + struct find_in_pack_v : boolean {}; + + template + struct find_in_pack_v : any, find_in_pack_v> {}; + + namespace meta_detail { + template + struct index_in_pack : std::integral_constant {}; + + template + struct index_in_pack : std::conditional_t::value, std::integral_constant, index_in_pack> {}; + } // namespace meta_detail + + template + struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> {}; + + template + struct index_in : meta_detail::index_in_pack<0, T, List> {}; + + template + struct index_in> : meta_detail::index_in_pack<0, T, Args...> {}; + + template + struct at_in_pack {}; + + template + using at_in_pack_t = typename at_in_pack::type; + + template + struct at_in_pack : std::conditional> {}; + + template + struct at_in_pack<0, Arg, Args...> { typedef Arg type; }; + + namespace meta_detail { + template class Pred, typename... Ts> + struct count_for_pack : std::integral_constant {}; + template class Pred, typename T, typename... Ts> + struct count_for_pack : std::conditional_t < sizeof...(Ts) + == 0 + || Limit<2, + std::integral_constant(Limit != 0 && Pred::value)>, + count_for_pack(Pred::value), Pred, Ts...>> {}; + template class Pred, typename... Ts> + struct count_2_for_pack : std::integral_constant {}; + template class Pred, typename T, typename U, typename... Ts> + struct count_2_for_pack : std::conditional_t(Pred::value)>, + count_2_for_pack(Pred::value), Pred, Ts...>> {}; + } // namespace meta_detail + + template