chore: added warnings and dependencies. also fixed warnings

This commit is contained in:
maelstrom 2025-06-05 20:19:36 +02:00
parent 253c617d19
commit 2b650c0fed
29 changed files with 63 additions and 51 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
/bin/
/lib/
/build/
/build-rel
/autogen/build
# Qt

View file

@ -3,6 +3,12 @@ set(CMAKE_CXX_STANDARD 20)
project(openblocks VERSION 0.1.0)
set(OpenGL_GL_PREFERENCE "GLVND")
if (MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic -Wno-unused-parameter)
endif()
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" )
add_subdirectory(autogen)

View file

@ -10,8 +10,6 @@
using namespace data;
static std::string toStaticName(std::string orig) {
bool isSnakeCase = orig.find('_') == -1;
std::string newName = "";
int wordStart = 0;
for (char c : orig) {
@ -46,7 +44,6 @@ static void processConstructor(CXCursor cur, ClassAnalysis* state) {
auto result = parseAnnotationString(propertyDef.value());
std::string symbolName = x_clang_toString(clang_getCursorSpelling(cur));
CXType retType = clang_getCursorResultType(cur);
anly.name = result["name"];
anly.functionName = "__ctor";

View file

@ -118,14 +118,14 @@ static void writeLuaMethodImpls(std::ofstream& out, ClassAnalysis& state) {
// Check number of arguments
out << "n == " << std::to_string(methodImpl.parameters.size() + 1); // Account for first argument as 'this'
for (int i = 0; i < methodImpl.parameters.size(); i++) {
for (size_t i = 0; i < methodImpl.parameters.size(); i++) {
out << " && ";
writeLuaTestArgument(out, methodImpl.parameters[i].type, i, true);
}
out << ") {\n"; // End if condition, start if body
for (int i = 0; i < methodImpl.parameters.size(); i++) {
for (size_t i = 0; i < methodImpl.parameters.size(); i++) {
writeLuaGetArgument(out, methodImpl.parameters[i].type, i, true);
}
@ -138,7 +138,7 @@ static void writeLuaMethodImpls(std::ofstream& out, ClassAnalysis& state) {
// Call function
out << "this_->" << methodImpl.functionName << "(";
for (int i = 0; i < methodImpl.parameters.size(); i++) {
for (size_t i = 0; i < methodImpl.parameters.size(); i++) {
std::string varname = "arg" + std::to_string(i);
if (i != 0) out << ", ";
out << varname;
@ -183,7 +183,7 @@ static void writeLuaMethodImpls(std::ofstream& out, ClassAnalysis& state) {
// Check number of arguments
out << "n == " << std::to_string(methodImpl.parameters.size());
for (int i = 0; i < methodImpl.parameters.size(); i++) {
for (size_t i = 0; i < methodImpl.parameters.size(); i++) {
out << " && ";
writeLuaTestArgument(out, methodImpl.parameters[i].type, i, false);
}
@ -191,7 +191,7 @@ static void writeLuaMethodImpls(std::ofstream& out, ClassAnalysis& state) {
out << ") {\n"; // End if condition, start if body
// Get the arguments
for (int i = 0; i < methodImpl.parameters.size(); i++) {
for (size_t i = 0; i < methodImpl.parameters.size(); i++) {
writeLuaGetArgument(out, methodImpl.parameters[i].type, i, false);
}
@ -207,7 +207,7 @@ static void writeLuaMethodImpls(std::ofstream& out, ClassAnalysis& state) {
else
out << fqn << "::" << methodImpl.functionName << "(";
for (int i = 0; i < methodImpl.parameters.size(); i++) {
for (size_t i = 0; i < methodImpl.parameters.size(); i++) {
std::string varname = "arg" + std::to_string(i);
if (i != 0) out << ", ";
out << varname;

View file

@ -25,11 +25,11 @@ std::map<std::string, std::string> parseAnnotationString(std::string src) {
int stage = 0;
bool quoted = false;
int i = 0;
size_t i = 0;
for (; i < src.length(); i++) {
if (src[i] == ' ' && (stage != 2 || !quoted)) continue; // Ignore spaces if not in stage 2 and quoted
if (src[i] == ',' && stage == 0) continue; // Let empty commas slip by
if (stage < 2 && (src[i] >= 'a' && src[i] <= 'z' || src[i] >= 'A' && src[i] <= 'Z' || src[i] >= '0' && src[i] <= '9' || src[i] == '_')) {
if (stage < 2 && ((src[i] >= 'a' && src[i] <= 'z') || (src[i] >= 'A' && src[i] <= 'Z') || (src[i] >= '0' && src[i] <= '9') || src[i] == '_')) {
currentIdent += src[i];
stage = 1;
continue;
@ -63,7 +63,7 @@ std::map<std::string, std::string> parseAnnotationString(std::string src) {
currentValue += src[i];
continue;
}
fprintf(stderr, "Unexpected symbol: %c at index %d\n", src[i], i);
fprintf(stderr, "Unexpected symbol: %c at index %zu\n", src[i], i);
fprintf(stderr, "\t%s\n", src.c_str());
fprintf(stderr, "\t%s^\n", i > 0 ? std::string(i, '~').c_str() : "");
abort();

View file

@ -5,3 +5,4 @@ find_package(glfw3 REQUIRED)
add_executable(client "src/main.cpp")
target_link_libraries(client PRIVATE ${SDL2_LIBRARIES} openblocks glfw)
add_dependencies(client openblocks)

View file

@ -26,6 +26,7 @@ foreach (SRC ${AUTOGEN_SOURCES})
add_custom_command(
OUTPUT "${OUT_PATH}"
DEPENDS autogen
DEPENDS "${SRC_PATH}"
COMMAND "${CMAKE_BINARY_DIR}/autogen/autogen" "${CMAKE_CURRENT_SOURCE_DIR}/src" "${SRC_PATH}" "${OUT_PATH}"
)
@ -43,6 +44,7 @@ add_library(openblocks STATIC ${SOURCES})
set_target_properties(openblocks PROPERTIES OUTPUT_NAME "openblocks")
target_link_libraries(openblocks ${GLEW_LIBRARIES} ${LUAJIT_LIBRARIES} OpenGL::GL ReactPhysics3D::ReactPhysics3D pugixml::pugixml)
target_include_directories(openblocks PUBLIC "src" "../include" ${LUAJIT_INCLUDE_DIR})
add_dependencies(openblocks autogen_build autogen)
# Windows-specific dependencies
if(WIN32)

View file

@ -26,7 +26,7 @@ public:
DEF_DATA_CTOR CFrame(Vector3 , Vector3 lookAt, Vector3 up = Vector3(0, 1, 0));
CFrame(const reactphysics3d::Transform&);
CFrame(Vector3 position, glm::quat quat);
~CFrame();
virtual ~CFrame();
// Same as CFrame(position, position + toward), but makes sure that up and toward are not linearly dependant
static CFrame pointToward(Vector3 position, Vector3 toward);

View file

@ -15,7 +15,7 @@ class DEF_DATA Color3 {
public:
DEF_DATA_CTOR Color3(float r, float g, float b);
Color3(const glm::vec3&);
~Color3();
virtual ~Color3();
DEF_DATA_METHOD static Color3 FromHex(std::string hex);

View file

@ -4,7 +4,7 @@
#include "error/data.h"
#include <pugixml.hpp>
TypeMeta::TypeMeta(const Enum* enum_) : enum_(enum_), descriptor(&EnumItem::TYPE) {}
TypeMeta::TypeMeta(const Enum* enum_) : descriptor(&EnumItem::TYPE), enum_(enum_) {}
Enum::Enum(_EnumData* data) : data(data) {}

View file

@ -20,6 +20,7 @@ class DEF_DATA Enum {
_EnumData* data;
public:
Enum(_EnumData*);
virtual ~Enum() = default;
static const TypeDesc TYPE;
@ -41,6 +42,7 @@ class DEF_DATA EnumItem {
int value;
public:
EnumItem(_EnumData*, std::string, int);
virtual ~EnumItem() = default;
static const TypeDesc TYPE;

View file

@ -11,7 +11,7 @@
#include "objects/base/member.h"
#include <pugixml.hpp>
TypeMeta::TypeMeta(const InstanceType* instType) : instType(instType), descriptor(&InstanceRef::TYPE) {}
TypeMeta::TypeMeta(const InstanceType* instType) : descriptor(&InstanceRef::TYPE), instType(instType) {}
InstanceRef::InstanceRef() {};
InstanceRef::InstanceRef(std::weak_ptr<Instance> instance) : ref(instance) {};

View file

@ -11,7 +11,7 @@ class InstanceRef {
public:
InstanceRef();
InstanceRef(std::weak_ptr<Instance>);
~InstanceRef();
virtual ~InstanceRef();
static const TypeDesc TYPE;

View file

@ -36,6 +36,7 @@ LuaSignalConnection::~LuaSignalConnection() {
luaL_unref(state, LUA_REGISTRYINDEX, thread);
}
#if 0
static void stackdump(lua_State* L) {
printf("%d\n", lua_gettop(L));
fflush(stdout);
@ -52,6 +53,7 @@ static void stackdump(lua_State* L) {
printf("\n\n");
fflush(stdout);
}
#endif
void LuaSignalConnection::Call(std::vector<Variant> args) {
lua_State* thread = lua_newthread(state);
@ -227,7 +229,10 @@ SignalRef::~SignalRef() = default;
const TypeDesc SignalRef::TYPE = {
.name = "Signal",
.serialize = nullptr,
.deserialize = nullptr,
.toString = toVariantFunction(&SignalRef::ToString),
.fromString = nullptr,
.pushLuaValue = toVariantFunction(&SignalRef::PushLuaValue),
.fromLuaValue = &SignalRef::FromLuaValue,
};
@ -348,7 +353,10 @@ SignalConnectionRef::~SignalConnectionRef() = default;
const TypeDesc SignalConnectionRef::TYPE = {
.name = "Signal",
.serialize = nullptr,
.deserialize = nullptr,
.toString = toVariantFunction(&SignalConnectionRef::ToString),
.fromString = nullptr,
.pushLuaValue = toVariantFunction(&SignalConnectionRef::PushLuaValue),
.fromLuaValue = &SignalConnectionRef::FromLuaValue,
};

View file

@ -40,6 +40,7 @@ protected:
void Call(std::vector<Variant>) override;
public:
CSignalConnection(std::function<void(std::vector<Variant>)>, std::weak_ptr<Signal> parent);
virtual ~CSignalConnection() = default;
};
class LuaSignalConnection : public SignalConnection {
@ -53,7 +54,7 @@ public:
LuaSignalConnection(lua_State*, std::weak_ptr<Signal> parent);
LuaSignalConnection (const LuaSignalConnection&) = delete;
LuaSignalConnection& operator= (const LuaSignalConnection&) = delete;
~LuaSignalConnection();
virtual ~LuaSignalConnection();
};
// Holds a signal connection such that when the holder is deleted (either via its parent object being deleted, or being overwritten),
@ -110,7 +111,7 @@ class SignalRef {
public:
SignalRef(std::weak_ptr<Signal>);
~SignalRef();
virtual ~SignalRef();
static const TypeDesc TYPE;
@ -127,7 +128,7 @@ class SignalConnectionRef {
public:
SignalConnectionRef(std::weak_ptr<SignalConnection>);
~SignalConnectionRef();
virtual ~SignalConnectionRef();
static const TypeDesc TYPE;

View file

@ -99,7 +99,7 @@ result<Vector3, DataParseError> Vector3::FromString(std::string string) {
if (string.length() == 0) return DataParseError(string, "Vector3");
while (string[0] == ' ' && string.length() > 0) string.erase(0, 1);
size_t nextPos = string.find(",");
if (nextPos == -1) nextPos = string.length();
if (nextPos == std::string::npos) nextPos = string.length();
std::string term = string.substr(0, nextPos);
string.erase(0, nextPos+1);

View file

@ -17,7 +17,7 @@ public:
DEF_DATA_CTOR Vector3(float x, float y, float z);
Vector3(const glm::vec3&);
Vector3(const reactphysics3d::Vector3&);
~Vector3();
virtual ~Vector3();
DEF_DATA_PROP static Vector3 ZERO;
DEF_DATA_PROP static Vector3 ONE;

View file

@ -28,6 +28,7 @@ const InstanceType Instance::TYPE = {
.className = "Instance",
.constructor = NULL, // Instance is abstract and therefore not creatable
.explorerIcon = "instance",
.flags = 0
};
// Instance is abstract, so it should not implement GetClass directly
@ -211,7 +212,7 @@ result<Variant, MemberNotFound> Instance::InternalGetPropertyValue(std::string n
result<PropertyMeta, MemberNotFound> Instance::InternalGetPropertyMeta(std::string name) {
if (name == "Name") {
return PropertyMeta { &STRING_TYPE };
return PropertyMeta { &STRING_TYPE, 0 };
} else if (name == "Parent") {
return PropertyMeta { &InstanceRef::TYPE, PROP_NOSAVE };
} else if (name == "ClassName") {
@ -391,7 +392,7 @@ result<std::shared_ptr<Instance>, NoSuchInstance> Instance::Deserialize(pugi::xm
// DescendantsIterator
DescendantsIterator::DescendantsIterator(std::shared_ptr<Instance> current) : current(current), root(current == DUMMY_INSTANCE ? DUMMY_INSTANCE : current->GetParent()), siblingIndex { 0 } { }
DescendantsIterator::DescendantsIterator(std::shared_ptr<Instance> current) : root(current == DUMMY_INSTANCE ? DUMMY_INSTANCE : current->GetParent()), current(current), siblingIndex { 0 } { }
DescendantsIterator::self_type DescendantsIterator::operator++(int _) {
// If the current item is dummy, an error has occurred, this is not supposed to happen.
@ -416,7 +417,7 @@ DescendantsIterator::self_type DescendantsIterator::operator++(int _) {
}
// If we've hit the end of this item's children, move one up
while (current->GetParent() && current->GetParent().value()->GetChildren().size() <= (siblingIndex.back() + 1)) {
while (current->GetParent() && current->GetParent().value()->GetChildren().size() <= size_t(siblingIndex.back() + 1)) {
siblingIndex.pop_back();
current = current->GetParent().value();

View file

@ -149,7 +149,7 @@ public:
typedef int difference_type;
DescendantsIterator(std::shared_ptr<Instance> current);
inline self_type operator++() { self_type i = *this; ++*this; return i; }
inline self_type operator++() { (*this)++; return (*this); }
inline std::shared_ptr<Instance> operator*() { return current; }
inline std::shared_ptr<Instance> operator->() { return current; }
inline bool operator==(const self_type& rhs) { return current == rhs.current; }

View file

@ -94,7 +94,7 @@ void ScriptContext::PushThreadSleep(lua_State* thread, float delay) {
}
void ScriptContext::RunSleepingThreads() {
for (int i = 0; i < sleepingThreads.size();) {
for (size_t i = 0; i < sleepingThreads.size();) {
bool deleted = false;
SleepingThread sleep = sleepingThreads[i];

View file

@ -24,7 +24,7 @@ Workspace::~Workspace() {
PhysicsEventListener::PhysicsEventListener(Workspace* parent) : workspace(parent) {}
void PhysicsEventListener::onContact(const rp::CollisionCallback::CallbackData& data) {
for (int i = 0; i < data.getNbContactPairs(); i++) {
for (size_t i = 0; i < data.getNbContactPairs(); i++) {
auto pair = data.getContactPair(i);
auto type = pair.getEventType();
if (type == rp::CollisionCallback::ContactPair::EventType::ContactStay) continue;
@ -84,8 +84,6 @@ void Workspace::InitService() {
void Workspace::SyncPartPhysics(std::shared_ptr<Part> part) {
if (!physicsWorld) return;
glm::mat4 rotMat = glm::mat4(1.0f);
rp::Transform transform = part->cframe;
if (!part->rigidBody) {
part->rigidBody = physicsWorld->createRigidBody(transform);

View file

@ -4,11 +4,11 @@
template <typename T>
bool operator ==(std::optional<std::weak_ptr<T>> a, std::optional<std::weak_ptr<T>> b) {
return (!a.has_value() || a.value().expired()) && (!b.has_value() || b.value().expired())
|| (a.has_value() && !a.value().expired()) && (b.has_value() && !b.value().expired()) && a.value().lock() == b.value().lock();
return ((!a.has_value() || a.value().expired()) && (!b.has_value() || b.value().expired()))
|| ((a.has_value() && !a.value().expired()) && (b.has_value() && !b.value().expired()) && a.value().lock() == b.value().lock());
}
template <typename T>
bool operator ==(std::weak_ptr<T> a, std::weak_ptr<T> b) {
return a.expired() && b.expired() || (!a.expired() && !b.expired() && a.lock() == b.lock());
return (a.expired() && b.expired()) || (!a.expired() && !b.expired() && a.lock() == b.lock());
}

View file

@ -52,8 +52,6 @@ void renderInit(GLFWwindow* window, int width, int height) {
viewportWidth = width, viewportHeight = height;
glViewport(0, 0, width, height);
int argc = 1;
char* argv = const_cast<char*>("");
initMeshes();
glEnable(GL_DEPTH_TEST);
@ -240,7 +238,6 @@ void renderSurfaceExtras() {
glm::mat4 model = CFrame::pointToward(surfaceCenter, part->cframe.Rotation() * normalFromFace(face));
model = glm::scale(model, glm::vec3(0.4,0.4,0.4));
ghostShader->set("model", model);
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
CYLINDER_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, CYLINDER_MESH->vertexCount);

View file

@ -69,6 +69,7 @@ endif()
target_include_directories(editor PUBLIC "../core/src" "../include" ${QSCINTILLA_INCLUDE_DIR})
target_link_libraries(editor PRIVATE openblocks Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia ${QSCINTILLA_LIBRARY})
add_dependencies(editor openblocks)
# Qt6 does not include QOpenGLWidgets as part of Widgets base anymore, so
# we have to include it manually

View file

@ -421,7 +421,7 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
draggingObject = part;
if (evt->modifiers() & Qt::ControlModifier) {
std::vector<std::shared_ptr<Instance>> currentSelection = getSelection();
for (int i = 0; i < currentSelection.size(); i++) {
for (size_t i = 0; i < currentSelection.size(); i++) {
std::shared_ptr<Instance> inst = currentSelection[i];
if (inst == part) {
currentSelection.erase(currentSelection.begin() + i);

View file

@ -45,7 +45,7 @@ QModelIndex ExplorerModel::index(int row, int column, const QModelIndex &parent)
? static_cast<Instance*>(parent.internalPointer())
: rootItem.get();
if (parentItem->GetChildren().size() >= row && !(parentItem->GetChildren()[row]->GetClass()->flags & INSTANCE_HIDDEN))
if (parentItem->GetChildren().size() >= (size_t)row && !(parentItem->GetChildren()[row]->GetClass()->flags & INSTANCE_HIDDEN))
return createIndex(row, column, parentItem->GetChildren()[row].get());
return {};
}
@ -56,7 +56,7 @@ QModelIndex ExplorerModel::toIndex(std::shared_ptr<Instance> item) {
std::shared_ptr<Instance> parentItem = item->GetParent().value();
// Check above ensures this item is not root, so value() must be valid
for (int i = 0; i < parentItem->GetChildren().size(); i++)
for (size_t i = 0; i < parentItem->GetChildren().size(); i++)
if (parentItem->GetChildren()[i] == item)
return createIndex(i, 0, item.get());
return QModelIndex{};
@ -79,7 +79,7 @@ QModelIndex ExplorerModel::parent(const QModelIndex &index) const {
// Check above ensures this item is not root, so value() must be valid
std::shared_ptr<Instance> parentParent = parentItem->GetParent().value();
for (int i = 0; i < parentParent->GetChildren().size(); i++)
for (size_t i = 0; i < parentParent->GetChildren().size(); i++)
if (parentParent->GetChildren()[i] == parentItem)
return createIndex(i, 0, parentItem.get());
return QModelIndex{};
@ -156,7 +156,7 @@ bool ExplorerModel::moveRows(const QModelIndex &sourceParentIdx, int sourceRow,
Logger::infof("Moved %d from %s", count, sourceParent->name.c_str());
if ((sourceRow + count) >= sourceParent->GetChildren().size()) {
if (size_t(sourceRow + count) >= sourceParent->GetChildren().size()) {
Logger::fatalErrorf("Attempt to move rows %d-%d from %s (%s) while it only has %zu children.", sourceRow, sourceRow + count, sourceParent->name.c_str(), sourceParent->GetClass()->className.c_str(), sourceParent->GetChildren().size());
return false;
}
@ -169,7 +169,7 @@ bool ExplorerModel::moveRows(const QModelIndex &sourceParentIdx, int sourceRow,
}
bool ExplorerModel::removeRows(int row, int count, const QModelIndex& parentIdx) {
Instance* parent = parentIdx.isValid() ? static_cast<Instance*>(parentIdx.internalPointer()) : rootItem.get();
// Instance* parent = parentIdx.isValid() ? static_cast<Instance*>(parentIdx.internalPointer()) : rootItem.get();
for (int i = row; i < (row + count); i++) {
//parent->GetChildren()[i]->SetParent(nullptr);

View file

@ -33,7 +33,6 @@ ExplorerView::ExplorerView(QWidget* parent):
this->expand(model.ObjectToIndex(gWorkspace()));
connect(this, &QTreeView::customContextMenuRequested, this, [&](const QPoint& point) {
QModelIndex index = this->indexAt(point);
contextMenu.exec(this->viewport()->mapToGlobal(point));
});

View file

@ -25,14 +25,12 @@
class PropertiesItemDelegate : public QStyledItemDelegate {
PropertiesView* view;
public:
PropertiesItemDelegate(PropertiesView* parent) : view(parent), QStyledItemDelegate(parent) {}
PropertiesItemDelegate(PropertiesView* parent) : QStyledItemDelegate(parent), view(parent) {}
void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override {
// https://stackoverflow.com/a/76645757/16255372
// https://stackoverflow.com/a/70078448/16255372
int indent = dynamic_cast<PropertiesView*>(parent())->indentation();
QStyledItemDelegate::initStyleOption(option, index);
if (!index.parent().isValid()) {
@ -110,7 +108,7 @@ public:
EnumItem enumItem = currentValue.get<EnumItem>();
std::vector<EnumItem> siblingItems = meta.type.enum_->GetEnumItems();
for (int i = 0; i < siblingItems.size(); i++) {
for (size_t i = 0; i < siblingItems.size(); i++) {
comboBox->addItem(QString::fromStdString(siblingItems[i].Name()));
if (siblingItems[i].Value() == enumItem.Value())
comboBox->setCurrentIndex(i);
@ -184,7 +182,7 @@ public:
EnumItem enumItem = currentValue.get<EnumItem>();
std::vector<EnumItem> siblingItems = meta.type.enum_->GetEnumItems();
for (int i = 0; i < siblingItems.size(); i++) {
for (size_t i = 0; i < siblingItems.size(); i++) {
if (siblingItems[i].Value() == enumItem.Value())
comboBox->setCurrentIndex(i);
}

View file

@ -110,7 +110,7 @@ class ObLuaLexer : public QsciLexerLua {
};
ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
script(script), QMdiSubWindow(parent) {
QMdiSubWindow(parent), script(script) {
setWindowTitle(QString::fromStdString(script->name));