Remove exit(1)s, fix main menu error handler.
parent
ca3f99fdc7
commit
e45baf8901
|
@ -296,9 +296,8 @@ set(ZEPHA_SRC
|
|||
game/inventory/InventoryRefs.cpp
|
||||
game/inventory/InventoryRefs.h
|
||||
game/inventory/InventoryList.cpp
|
||||
game/inventory/InventoryList.h
|
||||
lua/api/modules/time.h
|
||||
net/PacketView.cpp
|
||||
game/inventory/InventoryList.h
|
||||
net/PacketView.cpp
|
||||
net/PacketView.h
|
||||
lua/api/modules/create_structure.h
|
||||
util/Any.h
|
||||
|
@ -316,9 +315,9 @@ set(ZEPHA_SRC
|
|||
lua/register/CreateBlockModel.cpp
|
||||
lua/register/CreateBlockModel.h
|
||||
lua/customization/vec3.hpp
|
||||
lua/api/modules/Module.h
|
||||
lua/api/modules/SubgameModule.h
|
||||
lua/api/modules/Register.cpp
|
||||
lua/api/modules/Register.h
|
||||
def/Subgame.h lua/api/modules/Module.cpp lua/api/modules/Block.cpp lua/api/modules/Block.h lua/api/modules/Entity.cpp lua/api/modules/Entity.h)
|
||||
def/Subgame.h lua/api/modules/SubgameModule.cpp lua/api/modules/Block.cpp lua/api/modules/Block.h lua/api/modules/Entity.cpp lua/api/modules/Entity.h lua/api/modules/Time.cpp lua/api/modules/Time.h lua/api/modules/BaseModule.cpp lua/api/modules/BaseModule.h)
|
||||
|
||||
add_library (Zepha_Core ${ZEPHA_SRC})
|
|
@ -22,18 +22,11 @@ std::map<std::string, std::string> parseArgs(int argc, char* argv[]) {
|
|||
size_t equals = arg.find('=');
|
||||
std::string first = (equals == -1) ? arg : arg.substr(0, equals);
|
||||
|
||||
if (args.count(first)) {
|
||||
std::cout << Log::err << "Duplicate argument '" << first << "'" << Log::endl;
|
||||
exit(1);
|
||||
}
|
||||
if (args.count(first)) throw std::invalid_argument("Duplicate argument " + first + ".");
|
||||
|
||||
if (equals == -1) args.emplace(first, "");
|
||||
else {
|
||||
if (equals == arg.length() - 1) {
|
||||
std::cout << Log::err << "Empty argument '" << first << "'" << Log::endl;
|
||||
exit(1);
|
||||
}
|
||||
args.emplace(first, arg.substr(equals + 1, arg.length()));
|
||||
}
|
||||
else if (equals == arg.length() - 1) throw std::invalid_argument("Empty argument " + first + ".");
|
||||
else args.emplace(first, arg.substr(equals + 1, arg.length()));
|
||||
}
|
||||
|
||||
return args;
|
||||
|
|
|
@ -24,10 +24,7 @@ std::string Shader::readFile(const std::string& fileLocation) {
|
|||
std::string contents;
|
||||
std::ifstream fileStream(fileLocation, std::ios::in);
|
||||
|
||||
if (!fileStream.is_open()) {
|
||||
std::cout << Log::err << "Failed to open shader file '" << fileLocation << "'." << Log::endl;
|
||||
exit(1);
|
||||
}
|
||||
if (!fileStream.is_open()) throw std::runtime_error("Failed to open shader file " + fileLocation + ".");
|
||||
|
||||
std::string line;
|
||||
while (!fileStream.eof()) {
|
||||
|
@ -88,11 +85,7 @@ void Shader::setArr(int loc, unsigned int count, glm::mat4 &start) {
|
|||
|
||||
void Shader::compileShader(const std::string& vertexSource, const std::string& fragmentSource, const std::string& geoSource) {
|
||||
shaderID = glCreateProgram();
|
||||
|
||||
if (!shaderID) {
|
||||
std::cout << Log::err << "Error creating shader program." << Log::endl;
|
||||
exit(1);
|
||||
}
|
||||
if (!shaderID) throw std::runtime_error("Failed to create shader program.");
|
||||
|
||||
addShader(shaderID, vertexSource, GL_VERTEX_SHADER);
|
||||
addShader(shaderID, fragmentSource, GL_FRAGMENT_SHADER);
|
||||
|
@ -106,8 +99,7 @@ void Shader::compileShader(const std::string& vertexSource, const std::string& f
|
|||
|
||||
if (!result) {
|
||||
glGetProgramInfoLog(shaderID, sizeof(eLog), nullptr, eLog);
|
||||
std::cout << Log::err << "Error linking program.\n" << eLog << Log::endl;
|
||||
exit(1);
|
||||
throw std::runtime_error("Failed to link shader program. Error:\n" + std::string(eLog));
|
||||
}
|
||||
|
||||
glValidateProgram(shaderID);
|
||||
|
@ -115,8 +107,7 @@ void Shader::compileShader(const std::string& vertexSource, const std::string& f
|
|||
|
||||
if (!result) {
|
||||
glGetProgramInfoLog(shaderID, sizeof(eLog), nullptr, eLog);
|
||||
std::cout << Log::err << "Error validating program.\n" << eLog << Log::endl;
|
||||
exit(1);
|
||||
throw std::runtime_error("Failed to validate shader program. Error:\n" + std::string(eLog));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,12 +126,9 @@ void Shader::addShader(GLuint program, const std::string& shaderCode, GLenum sha
|
|||
glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
|
||||
|
||||
if (!result) {
|
||||
std::string shaderTypeName = (shaderType == GL_VERTEX_SHADER) ? "vertex" : (shaderType == GL_FRAGMENT_SHADER) ? "fragment" : "geometry";
|
||||
|
||||
glGetShaderInfoLog(shader, sizeof(eLog), nullptr, eLog);
|
||||
std::cout << Log::err << "Error compiling the " << shaderTypeName << " shader:\n" << eLog
|
||||
<< Log::endl << Log::err << shaderCode << std::endl;
|
||||
return;
|
||||
std::string shaderTypeName = (shaderType == GL_VERTEX_SHADER) ? "vertex" : (shaderType == GL_FRAGMENT_SHADER) ? "fragment" : "geometry";
|
||||
throw std::runtime_error("Failed to compile the " + shaderTypeName + " shader. Error:\n" + eLog);
|
||||
}
|
||||
|
||||
glAttachShader(program, shader);
|
||||
|
|
|
@ -71,6 +71,9 @@ void GuiText::setText(std::string text) {
|
|||
for (unsigned int i = 0; i < this->text.length() + 1; i++) {
|
||||
char c = this->text[i];
|
||||
|
||||
//TODO: Proper font handling.
|
||||
if (c == '\t') c = ' ';
|
||||
|
||||
if (c == '\n' || i == this->text.length()) {
|
||||
if (lineWidth > 0) {
|
||||
lineWidth += 2;
|
||||
|
@ -111,6 +114,10 @@ void GuiText::setText(std::string text) {
|
|||
|
||||
for (unsigned int i = 0; i < this->text.length() + 1; i++) {
|
||||
char c = this->text[i];
|
||||
|
||||
//TODO: Proper font handling.
|
||||
if (c == '\t') c = ' ';
|
||||
|
||||
unsigned int h = Font::charHeight;
|
||||
|
||||
if (c == '\n' || i == this->text.length()) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "../../hud/components/basic/GuiContainer.h"
|
||||
|
||||
// Modules
|
||||
#include "../../../lua/api/modules/Time.h"
|
||||
#include "../../../lua/api/menu/mSetGui.h"
|
||||
#include "../../../lua/api/menu/mStartGame.h"
|
||||
|
||||
|
@ -40,11 +41,16 @@ void MenuSandbox::loadApi() {
|
|||
lua["zepha"] = core;
|
||||
core["__builtin"] = lua.create_table();
|
||||
|
||||
|
||||
modules.emplace_back(std::make_unique<Api::Module::Time>(Api::State::CLIENT, lua, core));
|
||||
|
||||
ClientApi::gui_element(lua);
|
||||
|
||||
MenuApi::set_gui (builder, win, lua, core);
|
||||
MenuApi::start_game (state, core);
|
||||
|
||||
bindModules();
|
||||
|
||||
// Create sandboxed runfile()
|
||||
lua["dofile"] = lua["loadfile"] = sol::nil;
|
||||
lua.set_function("runfile", &MenuSandbox::runFileSandboxed, this);
|
||||
|
@ -68,6 +74,7 @@ void MenuSandbox::windowResized() {
|
|||
|
||||
void MenuSandbox::update(double delta) {
|
||||
builder.update();
|
||||
core["__builtin"]["update_delayed_functions"]();
|
||||
}
|
||||
|
||||
sol::protected_function_result MenuSandbox::runFileSandboxed(const std::string& file) {
|
||||
|
@ -174,22 +181,25 @@ sol::protected_function_result MenuSandbox::errorCallback(sol::protected_functio
|
|||
|
||||
try {
|
||||
std::string::size_type lineNumStart = errString.find(':');
|
||||
assert(lineNumStart != std::string::npos);
|
||||
if (lineNumStart == std::string::npos) throw std::out_of_range("Improperly formatted error. [0]");
|
||||
std::string::size_type lineNumEnd = errString.find(':', lineNumStart + 1);
|
||||
assert(lineNumEnd != std::string::npos);
|
||||
if (lineNumEnd == std::string::npos) throw std::out_of_range("Improperly formatted error. [1]");
|
||||
|
||||
std::string fileName = errString.substr(0, lineNumStart);
|
||||
int lineNum = std::stoi(errString.substr(lineNumStart + 1, lineNumEnd - lineNumStart - 1));
|
||||
|
||||
for (LuaModFile &f : mod.files) {
|
||||
if (f.path == fileName) {
|
||||
std::cout << std::endl << ErrorFormatter::formatError(fileName, lineNum, errString, f.file) << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
for (LuaModFile &f : mod.files)
|
||||
if (f.path == fileName)
|
||||
throw std::runtime_error(ErrorFormatter::formatError(fileName, lineNum, errString, f.file));
|
||||
|
||||
throw std::out_of_range("Error thrown outside of handled files. [2]");
|
||||
}
|
||||
catch (...) {
|
||||
std::cout << std::endl << Log::err << errString << Log::endl;
|
||||
catch (std::runtime_error e) {
|
||||
std::cout << Log::err << e.what() << std::endl;
|
||||
throw;
|
||||
}
|
||||
catch (std::out_of_range e) {
|
||||
std::cout << Log::err << "Failed to format error, " << e.what() << Log::endl;
|
||||
throw std::runtime_error(errString);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -36,17 +36,32 @@ void Player::update(Input &input, double delta, glm::vec2 mouseDelta) {
|
|||
gameGui.update(delta);
|
||||
handItemModel.setVisible(gameGui.isVisible());
|
||||
|
||||
moveAndLook(input, delta, mouseDelta);
|
||||
updatePhysics(input, delta, mouseDelta);
|
||||
|
||||
moveCollide(isOnGround() ? 0.6 : vel.y <= 0 ? 0.1 : 0);
|
||||
updateCamera();
|
||||
|
||||
findPointedThing(input);
|
||||
updateWireframe();
|
||||
|
||||
if (!gameGui.isInMenu()) interact(input, delta);
|
||||
}
|
||||
|
||||
void Player::moveAndLook(Input &input, double delta, glm::vec2 mouseDelta) {
|
||||
bool Player::getKey(Input& input, Player::PlayerControl control) {
|
||||
if (gameGui.isInMenu()) return false;
|
||||
return input.keyDown(
|
||||
control == PlayerControl::FORWARD ? GLFW_KEY_W :
|
||||
control == PlayerControl::BACKWARD ? GLFW_KEY_S :
|
||||
control == PlayerControl::LEFT ? GLFW_KEY_A :
|
||||
control == PlayerControl::RIGHT ? GLFW_KEY_D :
|
||||
control == PlayerControl::JUMP ? GLFW_KEY_SPACE :
|
||||
control == PlayerControl::MOD1 ? GLFW_KEY_LEFT_SHIFT :
|
||||
GLFW_KEY_LEFT_CONTROL);
|
||||
}
|
||||
|
||||
void Player::updatePhysics(Input &input, double delta, glm::vec2 mouseDelta) {
|
||||
//Position movement
|
||||
bool sprinting = input.keyDown(GLFW_KEY_LEFT_CONTROL);
|
||||
bool sprinting = getKey(input, PlayerControl::MOD2);
|
||||
|
||||
double moveSpeed = BASE_MOVE_SPEED * delta * (sprinting ? 1.6 : 1);
|
||||
float friction = 0.3f;
|
||||
|
@ -55,9 +70,7 @@ void Player::moveAndLook(Input &input, double delta, glm::vec2 mouseDelta) {
|
|||
moveSpeed *= 4;
|
||||
friction = 0.15f;
|
||||
}
|
||||
else {
|
||||
if (input.keyDown(GLFW_KEY_SPACE) && isOnGround()) vel.y = JUMP_VEL;
|
||||
}
|
||||
else if (getKey(input, PlayerControl::JUMP) && isOnGround()) vel.y = JUMP_VEL;
|
||||
|
||||
//Calculate movement vector from camera angle.
|
||||
auto& camera = renderer.camera;
|
||||
|
@ -66,14 +79,14 @@ void Player::moveAndLook(Input &input, double delta, glm::vec2 mouseDelta) {
|
|||
|
||||
glm::vec3 mod {0, 0, 0};
|
||||
|
||||
if (input.keyDown(GLFW_KEY_W)) mod += frontFlat;
|
||||
if (input.keyDown(GLFW_KEY_S)) mod -= frontFlat;
|
||||
if (input.keyDown(GLFW_KEY_D)) mod += rightFlat;
|
||||
if (input.keyDown(GLFW_KEY_A)) mod -= rightFlat;
|
||||
if (getKey(input, PlayerControl::FORWARD)) mod += frontFlat;
|
||||
if (getKey(input, PlayerControl::BACKWARD)) mod -= frontFlat;
|
||||
if (getKey(input, PlayerControl::RIGHT)) mod += rightFlat;
|
||||
if (getKey(input, PlayerControl::LEFT)) mod -= rightFlat;
|
||||
|
||||
if (flying) {
|
||||
if (input.keyDown(GLFW_KEY_SPACE)) mod.y += 1;
|
||||
if (input.keyDown(GLFW_KEY_LEFT_SHIFT)) mod.y -= 1;
|
||||
if (getKey(input, PlayerControl::JUMP)) mod.y += 1;
|
||||
if (getKey(input, PlayerControl::MOD1)) mod.y -= 1;
|
||||
}
|
||||
else {
|
||||
if (!isOnGround()) vel.y = std::fmax(vel.y - 0.0085, -3);
|
||||
|
@ -107,9 +120,6 @@ void Player::moveAndLook(Input &input, double delta, glm::vec2 mouseDelta) {
|
|||
while (yaw < 0.f) yaw += 360.f;
|
||||
|
||||
pitch = std::fmin(std::fmax(pitch, -90), 90);
|
||||
|
||||
moveCollide(isOnGround() ? 0.6 : vel.y <= 0 ? 0.1 : 0);
|
||||
updateCamera();
|
||||
}
|
||||
|
||||
void Player::updateCamera() {
|
||||
|
|
|
@ -20,6 +20,10 @@ enum class NetPlayerField;
|
|||
|
||||
class Player : Collidable, public Drawable {
|
||||
public:
|
||||
enum class PlayerControl {
|
||||
FORWARD, LEFT, BACKWARD, RIGHT,
|
||||
JUMP, MOD1, MOD2
|
||||
};
|
||||
static constexpr float MOUSE_SENSITIVITY = 0.1f;
|
||||
static constexpr float LOOK_DISTANCE = 6.5f;
|
||||
static constexpr float LOOK_PRECISION = 0.01f;
|
||||
|
@ -75,10 +79,14 @@ public:
|
|||
|
||||
unsigned int id = 0;
|
||||
private:
|
||||
void moveAndLook(Input &input, double delta, glm::vec2 mouseDelta);
|
||||
bool getKey(Input& input, PlayerControl control);
|
||||
|
||||
void updatePhysics(Input &input, double delta, glm::vec2 mouseDelta);
|
||||
void updateCamera();
|
||||
|
||||
void findPointedThing(Input &input);
|
||||
void updateWireframe();
|
||||
|
||||
void interact(Input& input, double delta);
|
||||
|
||||
void updateWieldAndHandItems();
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "../util/Log.h"
|
||||
|
||||
std::string ErrorFormatter::formatError(const std::string &fileName, int line, const std::string &stack, std::string file, bool ansiColors) {
|
||||
std::string ErrorFormatter::formatError(const std::string &fileName, int line, const std::string &stack, std::string file, bool ansiColors) noexcept {
|
||||
const std::string red = (ansiColors ? Log::red : "");
|
||||
const std::string unbl = (ansiColors ? Log::unbl : "");
|
||||
const std::string endl = (ansiColors ? Log::endl : "\n");
|
||||
|
|
|
@ -9,5 +9,5 @@
|
|||
class ErrorFormatter {
|
||||
public:
|
||||
static std::string formatError(const std::string& fileName, int line,
|
||||
const std::string& stack, std::string file, bool ansiColors = true);
|
||||
const std::string& stack, std::string file, bool ansiColors = true) noexcept;
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
//#define SOL_ALL_SAFETIES_ON 1
|
||||
#define SOL_ALL_SAFETIES_ON 1
|
||||
|
||||
#define SOL_SAFE_USERTYPE 1
|
||||
#define SOL_SAFE_FUNCTION 1
|
||||
#define SOL_SAFE_FUNCTION_CALLS 1
|
||||
//#define SOL_SAFE_USERTYPE 1
|
||||
//#define SOL_SAFE_FUNCTION 1
|
||||
//#define SOL_SAFE_FUNCTION_CALLS 1
|
||||
|
||||
#include <sol/sol.hpp>
|
||||
#include "customization/vec3.hpp"
|
|
@ -9,7 +9,7 @@
|
|||
#include <list>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "api/modules/Module.h"
|
||||
#include "api/modules/SubgameModule.h"
|
||||
|
||||
#include "Lua.h"
|
||||
|
||||
|
@ -29,6 +29,6 @@ public:
|
|||
sol::state lua;
|
||||
sol::table core;
|
||||
|
||||
std::vector<std::unique_ptr<Api::Module::Module>> modules;
|
||||
std::vector<std::unique_ptr<Api::Module::BaseModule>> modules;
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
//
|
||||
// Created by aurailus on 2020-07-26.
|
||||
//
|
||||
|
||||
#include "BaseModule.h"
|
||||
|
||||
Api::Module::BaseModule::BaseModule(Api::State state, sol::state& lua, sol::table& core) :
|
||||
state(state), lua(lua), core(core) {}
|
|
@ -1,31 +1,23 @@
|
|||
//
|
||||
// Created by aurailus on 2020-07-23.
|
||||
// Created by aurailus on 2020-07-26.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "sol/forward.hpp"
|
||||
|
||||
class World;
|
||||
class Subgame;
|
||||
|
||||
namespace Api {
|
||||
enum class State { CLIENT, SERVER };
|
||||
|
||||
namespace Module {
|
||||
class Module {
|
||||
class BaseModule {
|
||||
public:
|
||||
Module(State state, Subgame& game, World& world, sol::table& core);
|
||||
BaseModule(State state, sol::state& lua, sol::table& core);
|
||||
virtual void bind() = 0;
|
||||
|
||||
protected:
|
||||
State state;
|
||||
|
||||
World& world;
|
||||
Subgame& game;
|
||||
|
||||
sol::state& lua;
|
||||
sol::table& core;
|
||||
};
|
|
@ -6,12 +6,12 @@
|
|||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "Module.h"
|
||||
#include "SubgameModule.h"
|
||||
|
||||
namespace Api::Module {
|
||||
class Block : public Api::Module::Module {
|
||||
class Block : public Api::Module::SubgameModule {
|
||||
public:
|
||||
using Module::Module;
|
||||
using SubgameModule::SubgameModule;
|
||||
void bind() override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -21,7 +21,7 @@ void Api::Module::Entity::bind() {
|
|||
else core.set_function("remove_entity", Util::bind_this(this, &Entity::serverRemoveEntity));
|
||||
}
|
||||
|
||||
sol::object Api::Module::Entity::addEntity(glm::ivec3 pos, const std::string &identifier, sol::optional<sol::object> staticData) {
|
||||
sol::object Api::Module::Entity::addEntity(glm::vec3 pos, const std::string &identifier, sol::optional<sol::object> staticData) {
|
||||
if (core["registered_entities"][identifier] == sol::nil) throw std::runtime_error(identifier + " is not a valid entity identifier.");
|
||||
sol::table def = core["registered_entities"][identifier];
|
||||
|
||||
|
@ -41,8 +41,8 @@ sol::object Api::Module::Entity::addEntity(glm::ivec3 pos, const std::string &id
|
|||
// Server
|
||||
if (state == State::SERVER) {
|
||||
auto entity = std::make_unique<ServerEntity>(ind);
|
||||
auto ref = std::make_shared<ServerLuaEntity>(std::move(entity), ind++, static_cast<ServerSubgame&>(game));
|
||||
entity->setPos(pos);
|
||||
auto ref = std::make_shared<ServerLuaEntity>(std::move(entity), ind++, static_cast<ServerSubgame&>(game));
|
||||
|
||||
luaEntity["object"] = ref;
|
||||
ref->set_display_type(*displayType, *displayObject, displayTexture);
|
||||
|
|
|
@ -6,16 +6,16 @@
|
|||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "Module.h"
|
||||
#include "SubgameModule.h"
|
||||
|
||||
namespace Api::Module {
|
||||
class Entity : public Api::Module::Module {
|
||||
class Entity : public Api::Module::SubgameModule {
|
||||
public:
|
||||
using Module::Module;
|
||||
using SubgameModule::SubgameModule;
|
||||
void bind() override;
|
||||
|
||||
protected:
|
||||
sol::object addEntity(glm::ivec3 pos, const std::string& identifier, sol::optional<sol::object> staticData);
|
||||
sol::object addEntity(glm::vec3 pos, const std::string& identifier, sol::optional<sol::object> staticData);
|
||||
void clientRemoveEntity(sol::table entity);
|
||||
void serverRemoveEntity(sol::table entity);
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2020-07-24.
|
||||
//
|
||||
|
||||
#include "Module.h"
|
||||
|
||||
#include "../../../def/Subgame.h"
|
||||
#include "../../../lua/LuaParser.h"
|
||||
|
||||
Api::Module::Module::Module(State state, Subgame &game, World& world, sol::table &core) :
|
||||
state(state),
|
||||
world(world),
|
||||
game(game),
|
||||
core(core),
|
||||
lua(game.getParser().lua) {}
|
|
@ -4,12 +4,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Module.h"
|
||||
#include <string>
|
||||
|
||||
#include "SubgameModule.h"
|
||||
|
||||
namespace Api::Module {
|
||||
class Register : public Api::Module::Module {
|
||||
class Register : public Api::Module::SubgameModule {
|
||||
public:
|
||||
using Module::Module;
|
||||
using SubgameModule::SubgameModule;
|
||||
void bind() override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
//
|
||||
// Created by aurailus on 2020-07-24.
|
||||
//
|
||||
|
||||
#include "SubgameModule.h"
|
||||
|
||||
#include "../../../def/Subgame.h"
|
||||
#include "../../../lua/LuaParser.h"
|
||||
|
||||
Api::Module::SubgameModule::SubgameModule(State state, sol::table& core, Subgame& game, World& world) :
|
||||
BaseModule(state, game.getParser().lua, core), game(game), world(world) {}
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// Created by aurailus on 2020-07-23.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BaseModule.h"
|
||||
|
||||
class World;
|
||||
class Subgame;
|
||||
|
||||
namespace Api {
|
||||
namespace Module {
|
||||
class SubgameModule : public BaseModule {
|
||||
public:
|
||||
SubgameModule(State state, sol::table& core, Subgame& game, World& world);
|
||||
virtual void bind() = 0;
|
||||
|
||||
protected:
|
||||
State state;
|
||||
|
||||
World& world;
|
||||
Subgame& game;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// Created by aurailus on 2020-07-26.
|
||||
//
|
||||
|
||||
#include "Time.h"
|
||||
|
||||
#include "../../Lua.h"
|
||||
|
||||
void Api::Module::Time::bind() {
|
||||
auto time = lua.create_table();
|
||||
core["time"] = time;
|
||||
|
||||
time.set_function("ns", Util::bind_this(this, &Time::ns));
|
||||
time.set_function("ms", Util::bind_this(this, &Time::ms));
|
||||
time.set_function("s", Util::bind_this(this, &Time::s));
|
||||
}
|
||||
|
||||
float Api::Module::Time::ns() {
|
||||
return timer.elapsedNs();
|
||||
}
|
||||
|
||||
float Api::Module::Time::ms() {
|
||||
return timer.elapsedNs() / 1000000.f;
|
||||
}
|
||||
|
||||
float Api::Module::Time::s() {
|
||||
return timer.elapsedNs() / 1000000.f / 1000.f;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// Created by aurailus on 2020-07-26.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "SubgameModule.h"
|
||||
#include "../../../util/Timer.h"
|
||||
|
||||
namespace Api::Module {
|
||||
class Time : public Api::Module::BaseModule {
|
||||
public:
|
||||
using BaseModule::BaseModule;
|
||||
void bind() override;
|
||||
|
||||
protected:
|
||||
float ns();
|
||||
float ms();
|
||||
float s();
|
||||
|
||||
Timer timer {};
|
||||
};
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2020-03-04.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../../util/Timer.h"
|
||||
|
||||
namespace Api {
|
||||
static void time(sol::state& lua, sol::table& core) {
|
||||
core["time"] = lua.create_table();
|
||||
sol::table time = core["time"];
|
||||
|
||||
Timer t = Timer("timer");
|
||||
|
||||
time.set_function("ns", [=]() {
|
||||
return t.elapsedNs();
|
||||
});
|
||||
|
||||
time.set_function("ms", [=]() {
|
||||
return t.elapsedNs() / 1000000.f;
|
||||
});
|
||||
|
||||
time.set_function("s", [=]() {
|
||||
return t.elapsedNs() / 1000000.f / 1000.f;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -7,8 +7,8 @@
|
|||
#include "../ErrorFormatter.h"
|
||||
#include "../../game/ClientState.h"
|
||||
#include "../../game/graph/Renderer.h"
|
||||
#include "../register/RegisterBlocks.h"
|
||||
#include "../register/RegisterItems.h"
|
||||
#include "../register/RegisterBlocks.h"
|
||||
#include "../register/RegisterBiomes.h"
|
||||
#include "../register/RegisterKeybinds.h"
|
||||
|
||||
|
@ -21,11 +21,11 @@
|
|||
#include "../api/usertype/cAnimationManager.h"
|
||||
|
||||
// Modules
|
||||
#include "../api/modules/Time.h"
|
||||
#include "../api/modules/Block.h"
|
||||
#include "../api/modules/Entity.h"
|
||||
#include "../api/modules/Register.h"
|
||||
|
||||
#include "../api/modules/time.h"
|
||||
#include "../api/modules/create_structure.h"
|
||||
|
||||
// Functions
|
||||
|
@ -74,13 +74,13 @@ void LocalLuaParser::loadApi(LocalSubgame &defs, LocalWorld &world, Player& play
|
|||
core["player"] = LocalLuaPlayer(player);
|
||||
|
||||
// Modules
|
||||
modules.emplace_back(std::make_unique<Api::Module::Block>(Api::State::CLIENT, game, world, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Entity>(Api::State::CLIENT, game, world, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Register>(Api::State::CLIENT, game, world, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Time>(Api::State::CLIENT, lua, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Block>(Api::State::CLIENT, core, game, world));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Entity>(Api::State::CLIENT, core, game, world));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Register>(Api::State::CLIENT, core, game, world));
|
||||
|
||||
bindModules();
|
||||
|
||||
Api::time(lua, core);
|
||||
Api::create_structure (lua, core);
|
||||
|
||||
// Functions
|
||||
|
@ -133,8 +133,7 @@ sol::protected_function_result LocalLuaParser::errorCallback(sol::protected_func
|
|||
<< std::endl << std::endl << errString << Log::endl;
|
||||
}
|
||||
|
||||
exit(1);
|
||||
return errPfr;
|
||||
throw std::runtime_error("Exiting.");
|
||||
}
|
||||
|
||||
sol::protected_function_result LocalLuaParser::runFileSandboxed(const std::string& file) {
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
#include "../api/usertype/cItemStack.h"
|
||||
|
||||
// Modules
|
||||
#include "../api/modules/Time.h"
|
||||
#include "../api/modules/Block.h"
|
||||
#include "../api/modules/Entity.h"
|
||||
#include "../api/modules/Register.h"
|
||||
|
||||
#include "../api/modules/time.h"
|
||||
#include "../api/modules/create_structure.h"
|
||||
|
||||
// Functions
|
||||
|
@ -105,13 +105,13 @@ void ServerLuaParser::loadApi(ServerSubgame &defs, ServerWorld &world) {
|
|||
core["players"] = lua.create_table();
|
||||
|
||||
// Modules
|
||||
modules.emplace_back(std::make_unique<Api::Module::Block>(Api::State::SERVER, game, world, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Entity>(Api::State::SERVER, game, world, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Register>(Api::State::SERVER, game, world, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Time>(Api::State::CLIENT, lua, core));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Block>(Api::State::SERVER, core, game, world));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Entity>(Api::State::SERVER, core, game, world));
|
||||
modules.emplace_back(std::make_unique<Api::Module::Register>(Api::State::SERVER, core, game, world));
|
||||
|
||||
bindModules();
|
||||
|
||||
Api::time(lua, core);
|
||||
Api::create_structure (lua, core);
|
||||
|
||||
// Functions
|
||||
|
@ -164,8 +164,7 @@ sol::protected_function_result ServerLuaParser::errorCallback(sol::protected_fun
|
|||
<< std::endl << std::endl << errString << Log::endl;
|
||||
}
|
||||
|
||||
exit(1);
|
||||
return errPfr;
|
||||
throw std::runtime_error("Exiting.");
|
||||
}
|
||||
|
||||
sol::protected_function_result ServerLuaParser::runFileSandboxed(const std::string& file) {
|
||||
|
|
|
@ -6,13 +6,16 @@
|
|||
|
||||
enum class PacketChannel {
|
||||
UNDEFINED = -1,
|
||||
|
||||
AUTH,
|
||||
CONNECT,
|
||||
|
||||
SERVER,
|
||||
PLAYER,
|
||||
ENTITY,
|
||||
|
||||
WORLD,
|
||||
BLOCK,
|
||||
ENTITY,
|
||||
INTERACT,
|
||||
|
||||
INVENTORY
|
||||
};
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ void ClientNetworkInterpreter::update() {
|
|||
.append(player.getYaw())
|
||||
.data;
|
||||
|
||||
p.sendTo(connection.getPeer(), PacketChannel::PLAYER);
|
||||
p.sendTo(connection.getPeer(), PacketChannel::INTERACT);
|
||||
}
|
||||
|
||||
void ClientNetworkInterpreter::receivedPacket(std::unique_ptr<PacketView> p) {
|
||||
|
@ -130,12 +130,12 @@ void ClientNetworkInterpreter::receivedPacket(std::unique_ptr<PacketView> p) {
|
|||
|
||||
void ClientNetworkInterpreter::blockPlace(glm::ivec3 pos, unsigned int block) {
|
||||
Serializer().append(pos).append(block).packet(PacketType::BLOCK_SET)
|
||||
.sendTo(connection.getPeer(), PacketChannel::BLOCK);
|
||||
.sendTo(connection.getPeer(), PacketChannel::INTERACT);
|
||||
}
|
||||
|
||||
void ClientNetworkInterpreter::blockInteract(glm::ivec3 pos) {
|
||||
Serializer().append(pos).packet(PacketType::BLOCK_INTERACT)
|
||||
.sendTo(connection.getPeer(), PacketChannel::BLOCK);
|
||||
.sendTo(connection.getPeer(), PacketChannel::INTERACT);
|
||||
}
|
||||
|
||||
void ClientNetworkInterpreter::invWatch(const std::string& inv, const std::string& list) {
|
||||
|
|
|
@ -115,5 +115,5 @@ void ServerClient::setWieldIndex(unsigned short index, bool assert) {
|
|||
template <typename T>
|
||||
void ServerClient::assertField(NetPlayerField field, T data) {
|
||||
Serializer().append(static_cast<unsigned int>(field)).append<T>(data)
|
||||
.packet(PacketType::THIS_PLAYER_INFO).sendTo(peer, PacketChannel::PLAYER);
|
||||
.packet(PacketType::THIS_PLAYER_INFO).sendTo(peer, PacketChannel::INTERACT);
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ void ServerWorld::setBlock(glm::ivec3 pos, unsigned int block) {
|
|||
{mapBlock.x + mapBlockGenRange.x, mapBlock.y + mapBlockGenRange.y, mapBlock.z + mapBlockGenRange.x}};
|
||||
|
||||
if (isInBounds(Space::MapBlock::world::fromChunk(chunkPos), bounds))
|
||||
b.sendTo(client->peer, PacketChannel::BLOCK);
|
||||
b.sendTo(client->peer, PacketChannel::INTERACT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
class Timer {
|
||||
|
|
|
@ -156,9 +156,9 @@ void LocalDimension::serverEntityInfo(PacketView& p) {
|
|||
auto entity = std::make_shared<ServerLocalLuaEntity>(id, game, displayMode, displayArg1, displayArg2);
|
||||
entity->entity->setPos(position);
|
||||
entity->entity->setVisualOffset(visualOffset);
|
||||
entity->entity->interpRotateX(rotation.x);
|
||||
entity->entity->interpRotateY(rotation.y);
|
||||
entity->entity->interpRotateZ(rotation.z);
|
||||
entity->entity->setRotateX(rotation.x);
|
||||
entity->entity->setRotateY(rotation.y);
|
||||
entity->entity->setRotateZ(rotation.z);
|
||||
entity->entity->setScale(scale);
|
||||
serverEntities.push_back(entity);
|
||||
serverEntityRefs.emplace(id, --serverEntities.end());
|
||||
|
|
|
@ -13,4 +13,7 @@ zepha.register_block(":dirt", {
|
|||
},
|
||||
|
||||
yields = "zeus:default:dirt",
|
||||
|
||||
on_interact = function(pos) zepha.set_block(pos, "zeus:default:grass") end,
|
||||
on_interact_client = function(pos) zepha.set_block(pos, "zeus:default:grass") end
|
||||
})
|
Binary file not shown.
Before Width: | Height: | Size: 205 B After Width: | Height: | Size: 205 B |
Loading…
Reference in New Issue