Compare commits
No commits in common. "8f68ae45ceeaf95c9341612c3d05f99627f7cd96" and "ba97c7c57443bdd053e5bb7420563175b73f9892" have entirely different histories.
8f68ae45ce
...
ba97c7c574
20 changed files with 54 additions and 181 deletions
Binary file not shown.
Before Width: | Height: | Size: 413 B |
|
@ -3,10 +3,10 @@
|
|||
// I/O
|
||||
|
||||
out vec4 fColor;
|
||||
uniform vec4 aColor;
|
||||
uniform vec3 aColor;
|
||||
|
||||
// Main
|
||||
|
||||
void main() {
|
||||
fColor = aColor;
|
||||
fColor = vec4(aColor, 1.0);
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
#include "panic.h"
|
||||
#include <memory>
|
||||
|
||||
Service::Service(const InstanceType* type) : Instance(type) {}
|
||||
Service::Service(const InstanceType* type) : Instance(type){}
|
||||
|
||||
// Fail if parented to non-datamodel, otherwise lock parent
|
||||
void Service::OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#include "hint.h"
|
||||
|
||||
Hint::Hint(): Message(&TYPE) {}
|
||||
Hint::~Hint() = default;
|
|
@ -1,18 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include "objects/message.h"
|
||||
#include <memory>
|
||||
|
||||
// Dims the player's screen and displays some centered text
|
||||
class DEF_INST_(explorer_icon="message") Hint : public Message {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
public:
|
||||
Hint();
|
||||
~Hint();
|
||||
|
||||
static inline std::shared_ptr<Hint> New() { return std::make_shared<Hint>(); };
|
||||
static inline std::shared_ptr<Instance> Create() { return std::make_shared<Hint>(); };
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
#include "message.h"
|
||||
|
||||
Message::Message(const InstanceType* type) : Instance(type) {}
|
||||
Message::Message(): Instance(&TYPE) {}
|
||||
Message::~Message() = default;
|
|
@ -1,21 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include <memory>
|
||||
|
||||
// Dims the player's screen and displays some centered text
|
||||
class DEF_INST_(explorer_icon="message") Message : public Instance {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
protected:
|
||||
Message(const InstanceType* type);
|
||||
public:
|
||||
Message();
|
||||
~Message();
|
||||
|
||||
DEF_PROP std::string text;
|
||||
|
||||
static inline std::shared_ptr<Message> New() { return std::make_shared<Message>(); };
|
||||
static inline std::shared_ptr<Instance> Create() { return std::make_shared<Message>(); };
|
||||
};
|
|
@ -1,11 +1,9 @@
|
|||
#include "meta.h"
|
||||
#include "objects/folder.h"
|
||||
#include "objects/hint.h"
|
||||
#include "objects/joint/jointinstance.h"
|
||||
#include "objects/joint/rotate.h"
|
||||
#include "objects/joint/rotatev.h"
|
||||
#include "objects/joint/weld.h"
|
||||
#include "objects/message.h"
|
||||
#include "objects/service/jointsservice.h"
|
||||
#include "objects/model.h"
|
||||
#include "objects/part.h"
|
||||
|
@ -29,8 +27,6 @@ std::map<std::string, const InstanceType*> INSTANCE_MAP = {
|
|||
{ "JointInstance", &JointInstance::TYPE },
|
||||
{ "Script", &Script::TYPE },
|
||||
{ "Model", &Model::TYPE },
|
||||
{ "Message", &Message::TYPE },
|
||||
{ "Hint", &Hint::TYPE },
|
||||
// { "Folder", &Folder::TYPE },
|
||||
|
||||
// Services
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "script.h"
|
||||
#include "common.h"
|
||||
#include "datatypes/variant.h"
|
||||
#include "lauxlib.h"
|
||||
#include "logger.h"
|
||||
#include "objects/base/instance.h"
|
||||
|
@ -32,6 +31,23 @@ void Script::Run() {
|
|||
this->thread = lua_newthread(L);
|
||||
lua_State* Lt = thread;
|
||||
|
||||
lua_pushthread(Lt); // Push thread for later*
|
||||
|
||||
// Initialize script globals
|
||||
scriptContext->NewEnvironment(Lt); // Pushes envtable, metatable
|
||||
|
||||
// Set script in metatable source
|
||||
InstanceRef(shared_from_this()).PushLuaValue(Lt);
|
||||
lua_setfield(Lt, -2, "source");
|
||||
|
||||
lua_pop(Lt, 1); // Pop metatable
|
||||
|
||||
InstanceRef(shared_from_this()).PushLuaValue(Lt);
|
||||
lua_setfield(Lt, -2, "script");
|
||||
|
||||
lua_setfenv(Lt, -2); // *Set env of current thread
|
||||
lua_pop(Lt, 1); // Pop thread
|
||||
|
||||
// Push wrapper as thread function
|
||||
lua_getfield(Lt, LUA_REGISTRYINDEX, "LuaPCallWrapper");
|
||||
|
||||
|
@ -45,21 +61,6 @@ void Script::Run() {
|
|||
return;
|
||||
}
|
||||
|
||||
// Initialize script globals
|
||||
scriptContext->NewEnvironment(Lt); // Pushes envtable, metatable
|
||||
|
||||
// Set script in metatable source
|
||||
InstanceRef(shared_from_this()).PushLuaValue(Lt);
|
||||
lua_setfield(Lt, -2, "source");
|
||||
|
||||
lua_pop(Lt, 1); // Pop metatable
|
||||
|
||||
// Set script in environment
|
||||
InstanceRef(shared_from_this()).PushLuaValue(Lt);
|
||||
lua_setfield(Lt, -2, "script");
|
||||
|
||||
lua_setfenv(Lt, -2); // Set env of loaded function
|
||||
|
||||
// Push our error handler and then generate the wrapped function
|
||||
lua_pushcfunction(Lt, script_errhandler);
|
||||
lua_call(Lt, 2, 1);
|
||||
|
@ -75,34 +76,6 @@ void Script::Stop() {
|
|||
// TODO:
|
||||
}
|
||||
|
||||
static std::shared_ptr<Script> getfsource(lua_State* L, lua_Debug* dbg) {
|
||||
int top = lua_gettop(L);
|
||||
|
||||
lua_getinfo(L, "f", dbg);
|
||||
lua_getfenv(L, -1); // Get fenv of stack pos
|
||||
if (lua_isnil(L, -1)) { // No env could be found
|
||||
lua_settop(L, top);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Get source from metatable
|
||||
lua_getmetatable(L, -1);
|
||||
lua_getfield(L, -1, "source");
|
||||
|
||||
auto result = InstanceRef::FromLuaValue(L, -1);
|
||||
if (!result) {
|
||||
lua_settop(L, top);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
lua_settop(L, top);
|
||||
|
||||
std::shared_ptr<Instance> ref = result.expect().get<InstanceRef>();
|
||||
if (!ref->IsA<Script>()) return nullptr;
|
||||
|
||||
return ref->CastTo<Script>().expect();
|
||||
}
|
||||
|
||||
int script_errhandler(lua_State* L) {
|
||||
std::string errorMessage = lua_tostring(L, -1);
|
||||
Logger::error(errorMessage);
|
||||
|
@ -119,10 +92,7 @@ int script_errhandler(lua_State* L) {
|
|||
if (strcmp(dbg.what, "C") == 0 || strcmp(dbg.source, "=PCALL_WRAPPER") == 0)
|
||||
continue;
|
||||
|
||||
// Find script source
|
||||
std::shared_ptr<Script> source = getfsource(L, &dbg);
|
||||
|
||||
Logger::scriptLogf("'%s', Line %d", Logger::LogLevel::TRACE, {source, dbg.currentline}, dbg.source, dbg.currentline);
|
||||
Logger::scriptLogf("'%s', Line %d", Logger::LogLevel::TRACE, {}, dbg.source, dbg.currentline);
|
||||
}
|
||||
|
||||
Logger::trace("Stack end");
|
||||
|
|
|
@ -11,8 +11,6 @@ extern Texture* debugFontTexture;
|
|||
extern Shader* debugFontShader;
|
||||
extern Shader* identityShader;
|
||||
|
||||
void drawRect(int x, int y, int width, int height, glm::vec4 color);
|
||||
|
||||
void drawChar(char c, int x, int y, float scale=1.f) {
|
||||
debugFontShader->use();
|
||||
debugFontTexture->activate(1);
|
||||
|
@ -43,6 +41,22 @@ void drawString(std::string str, int x, int y, float scale=1.f) {
|
|||
}
|
||||
}
|
||||
|
||||
void drawRect(int x, int y, int w, int h, glm::vec4 color) {
|
||||
identityShader->use();
|
||||
identityShader->set("aColor", color);
|
||||
|
||||
float x0 = 2*float(x)/viewportWidth-1, y0 = 2*float(y)/viewportHeight-1, x1 = 2*float(x + w)/viewportWidth-1, y1 = 2*float(y + h)/viewportHeight-1;
|
||||
float tmp;
|
||||
tmp = -y0, y0 = -y1, y1 = tmp;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(x0, y0, 0);
|
||||
glVertex3f(x1, y0, 0);
|
||||
glVertex3f(x1, y1, 0);
|
||||
glVertex3f(x0, y1, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static tu_time_t lastTime;
|
||||
extern tu_time_t renderTime;
|
||||
extern tu_time_t physTime;
|
||||
|
|
|
@ -63,8 +63,7 @@ std::shared_ptr<Font> loadFont(std::string fontName) {
|
|||
|
||||
std::shared_ptr<Font> font = std::make_shared<Font>();
|
||||
|
||||
FT_Set_Pixel_Sizes(face, 0, 16);
|
||||
font->height = face->size->metrics.y_ppem;
|
||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
||||
|
||||
// Load each glyph
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
@ -132,7 +131,7 @@ void drawText(std::shared_ptr<Font> font, std::string text, float x, float y, fl
|
|||
Character ch = font->characters[c];
|
||||
|
||||
float xpos = x + ch.bearing.x * scale;
|
||||
float ypos = viewportHeight - y - font->height - (ch.size.y - ch.bearing.y) * scale;
|
||||
float ypos = y - (ch.size.y - ch.bearing.y) * scale;
|
||||
|
||||
float w = ch.size.x * scale;
|
||||
float h = ch.size.y * scale;
|
||||
|
@ -160,17 +159,4 @@ void drawText(std::shared_ptr<Font> font, std::string text, float x, float y, fl
|
|||
x += (ch.advance >> 6) * scale; // bitshift by 6 to get value in pixels (2^6 = 64)
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
float calcTextWidth(std::shared_ptr<Font> font, std::string text, float scale) {
|
||||
float x = 0;
|
||||
// iterate through all characters
|
||||
for (size_t i = 0; i < text.size(); i++) {
|
||||
unsigned char c = text[i];
|
||||
Character ch = font->characters[c];
|
||||
|
||||
x += (ch.advance >> 6) * scale;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
|
@ -14,12 +14,10 @@ struct Character {
|
|||
};
|
||||
|
||||
struct Font {
|
||||
unsigned int height;
|
||||
Character characters[128];
|
||||
};
|
||||
|
||||
void fontInit();
|
||||
void fontFinish();
|
||||
std::shared_ptr<Font> loadFont(std::string fontName);
|
||||
void drawText(std::shared_ptr<Font> font, std::string text, float x, float y, float scale=1.f, glm::vec3 color = glm::vec3(1,1,1));
|
||||
float calcTextWidth(std::shared_ptr<Font> font, std::string text, float scale = 1.f);
|
||||
void drawText(std::shared_ptr<Font> font, std::string text, float x, float y, float scale=1.f, glm::vec3 color = glm::vec3(1,1,1));
|
|
@ -20,8 +20,6 @@
|
|||
#include "datatypes/vector.h"
|
||||
#include "handles.h"
|
||||
#include "math_helper.h"
|
||||
#include "objects/hint.h"
|
||||
#include "objects/message.h"
|
||||
#include "objects/service/selection.h"
|
||||
#include "partassembly.h"
|
||||
#include "rendering/font.h"
|
||||
|
@ -64,8 +62,7 @@ bool wireframeRendering = false;
|
|||
int viewportWidth, viewportHeight;
|
||||
|
||||
void renderDebugInfo();
|
||||
void drawRect(int x, int y, int width, int height, glm::vec4 color);
|
||||
inline void drawRect(int x, int y, int width, int height, glm::vec3 color) { return drawRect(x, y, width, height, glm::vec4(color, 1)); };
|
||||
void drawRect(int x, int y, int width, int height, glm::vec3 color);
|
||||
|
||||
void renderInit(int width, int height) {
|
||||
viewportWidth = width, viewportHeight = height;
|
||||
|
@ -652,33 +649,6 @@ void addDebugRenderCFrame(CFrame frame, Color3 color) {
|
|||
DEBUG_CFRAMES.push_back(std::make_pair(frame, color));
|
||||
}
|
||||
|
||||
void renderMessages() {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
// glEnable(GL_BLEND);
|
||||
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
for (auto it = gWorkspace()->GetDescendantsStart(); it != gWorkspace()->GetDescendantsEnd(); it++) {
|
||||
if (!it->IsA<Message>()) continue;
|
||||
std::shared_ptr<Message> message = it->CastTo<Message>().expect();
|
||||
|
||||
float textWidth = calcTextWidth(sansSerif, message->text);
|
||||
|
||||
// Render hint
|
||||
if (message->GetClass() == &Hint::TYPE) {
|
||||
drawRect(0, 0, viewportWidth, 20, glm::vec4(0,0,0,1));
|
||||
drawText(sansSerif, message->text, (viewportWidth - textWidth) / 2, 0);
|
||||
} else {
|
||||
// Don't draw if text is empty
|
||||
if (message->text == "") continue;
|
||||
|
||||
drawRect(0, 0, viewportWidth, viewportHeight, glm::vec4(0.5));
|
||||
drawText(sansSerif, message->text, ((float)viewportWidth - textWidth) / 2, ((float)viewportHeight - sansSerif->height) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tu_time_t renderTime;
|
||||
void render() {
|
||||
tu_time_t startTime = tu_clock_micros();
|
||||
|
@ -698,14 +668,13 @@ void render() {
|
|||
renderWireframe();
|
||||
if (debugRendererEnabled)
|
||||
renderDebugInfo();
|
||||
renderMessages();
|
||||
// TODO: Make this a debug flag
|
||||
// renderAABB();
|
||||
|
||||
renderTime = tu_clock_micros() - startTime;
|
||||
}
|
||||
|
||||
void drawRect(int x, int y, int width, int height, glm::vec4 color) {
|
||||
void drawRect(int x, int y, int width, int height, glm::vec3 color) {
|
||||
// GL_CULL_FACE has to be disabled as we are flipping the order of the vertices here, besides we don't really care about it
|
||||
glDisable(GL_CULL_FACE);
|
||||
glm::mat4 model(1.0f); // Same applies to this VV
|
||||
|
|
|
@ -610,23 +610,19 @@ ScriptDocument* MainWindow::findScriptWindow(std::shared_ptr<Script> script) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void MainWindow::openScriptDocument(std::shared_ptr<Script> script, int line) {
|
||||
void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
||||
// Document already exists, don't open it
|
||||
ScriptDocument* doc = findScriptWindow(script);
|
||||
if (doc != nullptr) {
|
||||
ui->mdiArea->setActiveSubWindow(doc);
|
||||
doc->setFocus();
|
||||
if (line > -1) doc->moveCursor(line);
|
||||
return;
|
||||
}
|
||||
|
||||
doc = new ScriptDocument(script);
|
||||
doc->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
if (line > -1) doc->moveCursor(line);
|
||||
ui->mdiArea->addSubWindow(doc);
|
||||
ui->mdiArea->setActiveSubWindow(doc);
|
||||
doc->showMaximized();
|
||||
doc->setFocus();
|
||||
}
|
||||
|
||||
void MainWindow::closeScriptDocument(std::shared_ptr<Script> script) {
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
GridSnappingMode snappingMode;
|
||||
bool editSoundEffects = true;
|
||||
|
||||
void openScriptDocument(std::shared_ptr<Script>, int line = -1);
|
||||
void openScriptDocument(std::shared_ptr<Script>);
|
||||
void closeScriptDocument(std::shared_ptr<Script>);
|
||||
|
||||
void openFile(std::string path);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Openblocks Editor</string>
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "outputtextview.h"
|
||||
#include "logger.h"
|
||||
#include "mainwindow.h"
|
||||
#include "objects/script.h"
|
||||
#include "panes/outputtextview.h"
|
||||
#include <QEvent>
|
||||
#include <QTextEdit>
|
||||
|
@ -59,7 +60,7 @@ void OutputTextView::handleLog(Logger::LogLevel logLevel, std::string message, L
|
|||
stackTraceScripts[id] = source.script;
|
||||
|
||||
format.setAnchor(true);
|
||||
format.setAnchorHref(QString::number(id) + ":" + QString::number(source.line));
|
||||
format.setAnchorHref(QString::number(id));
|
||||
}
|
||||
|
||||
cursor.insertText(message.c_str(), format);
|
||||
|
@ -71,13 +72,11 @@ void OutputTextView::mousePressEvent(QMouseEvent *e) {
|
|||
QString anchor = anchorAt(e->pos());
|
||||
if (anchor == "" || e->modifiers() & Qt::AltModifier) return QTextEdit::mousePressEvent(e);
|
||||
|
||||
int idx = anchor.indexOf(":");
|
||||
int id = anchor.mid(0, idx).toInt(), line = anchor.mid(idx+1).toInt();
|
||||
auto script = stackTraceScripts[id];
|
||||
auto script = stackTraceScripts[anchor.toInt()];
|
||||
if (script.expired()) return QTextEdit::mousePressEvent(e);
|
||||
|
||||
MainWindow* mainWnd = dynamic_cast<MainWindow*>(window());
|
||||
mainWnd->openScriptDocument(script.lock(), line);
|
||||
mainWnd->openScriptDocument(script.lock());
|
||||
}
|
||||
|
||||
void OutputTextView::mouseReleaseEvent(QMouseEvent *e) {
|
||||
|
|
|
@ -32,6 +32,11 @@ void CommandEdit::executeCommand() {
|
|||
int top = lua_gettop(L);
|
||||
lua_State* Lt = lua_newthread(L);
|
||||
|
||||
lua_pushthread(Lt); // Push thread
|
||||
getOrCreateEnvironment(Lt);
|
||||
lua_setfenv(Lt, -2); // Set env of current thread
|
||||
lua_pop(Lt, 1); // Pop thread
|
||||
|
||||
// Push wrapper as thread function
|
||||
lua_getfield(Lt, LUA_REGISTRYINDEX, "LuaPCallWrapper");
|
||||
|
||||
|
@ -45,14 +50,10 @@ void CommandEdit::executeCommand() {
|
|||
return;
|
||||
}
|
||||
|
||||
getOrCreateEnvironment(Lt);
|
||||
lua_setfenv(Lt, -2); // Set env of loaded function
|
||||
|
||||
// Push our error handler and then generate the wrapped function
|
||||
lua_pushcfunction(Lt, script_errhandler);
|
||||
lua_call(Lt, 2, 1);
|
||||
|
||||
|
||||
// Resume the thread
|
||||
lua_resume(Lt, 0);
|
||||
|
||||
|
|
|
@ -179,13 +179,6 @@ ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
|
|||
ScriptDocument::~ScriptDocument() {
|
||||
}
|
||||
|
||||
void ScriptDocument::moveCursor(int line) {
|
||||
if (line == -1) return;
|
||||
|
||||
int lineLength = scintilla->lineLength(line-1);
|
||||
scintilla->setCursorPosition(line-1, lineLength-1);
|
||||
}
|
||||
|
||||
QsciAPIs* makeApis(QsciLexer* lexer) {
|
||||
QsciAPIs* apis = new QsciAPIs(lexer);
|
||||
|
||||
|
|
|
@ -17,5 +17,4 @@ public:
|
|||
~ScriptDocument() override;
|
||||
|
||||
inline std::shared_ptr<Script> getScript() { return script; }
|
||||
void moveCursor(int line);
|
||||
};
|
Loading…
Add table
Reference in a new issue