Skip to content

Commit

Permalink
cleanup build issues; update code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ppiecuch committed Nov 21, 2023
1 parent 561dcf3 commit 61ae0a8
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 51 deletions.
10 changes: 7 additions & 3 deletions modules/gdextensions/common/gd_plotter_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const Color GuiColor_PlotHistogramHovered = Color(1.00, 0.60, 0.00, 1.00);
const int GuiStyle_FramePadding = 2;
const int GuiStyle_ItemInnerSpacing = 2;

static _ALWAYS_INLINE_ Vector2 LERP(const Vector2 &a, const Vector2 &b, real_t t) { return Vector2(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t); }
static _ALWAYS_INLINE_ Vector2 LERP(const Vector2 &a, const Vector2 &b, const Vector2 &t) { return Vector2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); }
static _ALWAYS_INLINE_ real_t SATURATE(real_t f) { return (f < 0 ? 0 : (f > 1 ? 1 : f)); }

Expand All @@ -72,7 +71,6 @@ static void PlotFlame(CanvasItem *canvas, Ref<Font> &text_font, const String &la

const Rect2 frame_bb = Rect2(frame_rect.position, frame_rect.size - Size2(0, label_size.y)); // label on the bottom
const Rect2 inner_bb(frame_bb.shrink(GuiStyle_FramePadding));
const Rect2 total_bb = frame_rect;

// determine scale from values if not specified
if (scale_min == FLT_MAX || scale_max == FLT_MAX) {
Expand Down Expand Up @@ -179,7 +177,6 @@ static void PlotGraph(CanvasItem *canvas, Ref<Font> &text_font, PlotType plot_ty

const Rect2 frame_bb = Rect2(frame_rect.position, frame_rect.size - Size2(0, label_size.y)); // label on the bottom
const Rect2 inner_bb(frame_bb.shrink(GuiStyle_FramePadding));
const Rect2 total_bb = frame_rect;

// Determine scale from values if not specified
if (scale_min == FLT_MAX || scale_max == FLT_MAX) {
Expand Down Expand Up @@ -309,3 +306,10 @@ void PlotHistogram(CanvasItem *canvas, Ref<Font> &text_font, const String &label
void PlotHistogram(CanvasItem *canvas, Ref<Font> &text_font, const String &label, ValuesGetter values_getter, void *data, int values_count, int values_offset, const String &overlay_text, real_t scale_min, real_t scale_max, const Rect2 &frame_rect) {
PlotGraph(canvas, text_font, PlotType_Histogram, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, frame_rect);
}

void PlotFlame(CanvasItem *canvas, Ref<Font> &text_font, const String &label, const real_t *values, int values_count, int values_offset, const String &overlay_text, real_t scale_min, real_t scale_max, const Rect2 &frame_rect, int stride) {
}

void PlotFlame(CanvasItem *canvas, Ref<Font> &text_font, const String &label, SeriesGetter values_getter, void *data, int values_count, int values_offset, const char *overlay_text, real_t scale_min, real_t scale_max, const Rect2 &frame_rect) {
PlotFlame(canvas, text_font, label, values_getter, data, values_count, values_offset, overlay_text, scale_min, scale_max, frame_rect, nullptr);
}
27 changes: 9 additions & 18 deletions modules/gdextensions/submodules/core/line_builder_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,18 @@

#include "line_builder_2d.h"

#include "common/gd_core.h"

// Needed so we can bind functions
VARIANT_ENUM_CAST(Line2D::LineJointMode)
VARIANT_ENUM_CAST(Line2D::LineCapMode)
VARIANT_ENUM_CAST(Line2D::LineTextureMode)

#define CopyArray(fr, to) \
{ \
to.resize(fr.size()); \
for (int i = 0; i < fr.size(); ++i) \
to.set(i, fr[i]); \
}

void LineBuilder2D::set_points(const PoolVector2Array &p_points) {
lb.points.clear();
CopyArray(p_points, lb.points);
lb.points = p_points;
}
PoolVector2Array LineBuilder2D::get_points() const {
PoolVector2Array ret;
CopyArray(lb.points, ret);
return ret;
return lb.points;
}
void LineBuilder2D::set_default_color(const Color &p_default_color) {
lb.default_color = p_default_color;
Expand Down Expand Up @@ -126,22 +118,22 @@ Ref<Curve> LineBuilder2D::get_curve() const {

PoolIntArray LineBuilder2D::get_indices() const {
PoolIntArray ret;
CopyArray(lb.indices, ret);
copyarray(lb.indices, ret);
return ret;
}
PoolVector2Array LineBuilder2D::get_vertices() const {
PoolVector2Array ret;
CopyArray(lb.vertices, ret);
copyarray(lb.vertices, ret);
return ret;
}
PoolColorArray LineBuilder2D::get_colors() const {
PoolColorArray ret;
CopyArray(lb.colors, ret);
copyarray(lb.colors, ret);
return ret;
}
PoolVector2Array LineBuilder2D::get_uvs() const {
PoolVector2Array ret;
CopyArray(lb.uvs, ret);
copyarray(lb.uvs, ret);
return ret;
}

Expand All @@ -152,7 +144,7 @@ LineBuilder2D::LineBuilder2D() {
lb.width = 10;
lb.default_color = Color(0.4, 0.5, 1);
lb.texture_mode = Line2D::LINE_TEXTURE_TILE;
lb.sharp_limit = 2.f;
lb.sharp_limit = 2;
lb.round_precision = 8;
}

Expand Down Expand Up @@ -204,5 +196,4 @@ void LineBuilder2D::_bind_methods() {
ClassDB::bind_method("get_indices", &LineBuilder2D::get_indices);

ClassDB::bind_method("build", &LineBuilder2D::build);
ClassDB::bind_method("clear_output", &LineBuilder2D::clear_output);
}
6 changes: 2 additions & 4 deletions modules/gdextensions/submodules/core/line_builder_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
class LineBuilder2D : public Reference {
GDCLASS(LineBuilder2D, Reference);

LineBuilder lb;

protected:
static void _bind_methods();

Expand Down Expand Up @@ -76,12 +78,8 @@ class LineBuilder2D : public Reference {
PoolVector2Array get_uvs() const;

void build() { lb.build(); }
void clear_output() { lb.clear_output(); }

LineBuilder2D();

private:
LineBuilder lb;
};

#endif // LINEBUILDER2D_H
38 changes: 28 additions & 10 deletions modules/gdextensions/submodules/debugdraw/debugdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool DebugDraw::init() {
void DebugDraw::circle(const Vector2 &position, real_t radius, const Color &color, real_t duration) {
if (ready || init()) {
auto *vs = VS::get_singleton();
Drawing d = { vs->canvas_item_create(), duration };
const Drawing d = { vs->canvas_item_create(), duration };
vs->canvas_item_set_parent(d.canvas_item, canvas);
vs->canvas_item_add_circle(d.canvas_item, _viewport_xform(position), radius, color);
drawings.push_back(d);
Expand All @@ -71,7 +71,7 @@ void DebugDraw::circle(const Vector2 &position, real_t radius, const Color &colo
void DebugDraw::line(const Vector2 &a, const Vector2 &b, const Color &color, real_t width, real_t duration) {
if (ready || init()) {
auto *vs = VS::get_singleton();
Drawing d = { vs->canvas_item_create(), duration };
const Drawing d = { vs->canvas_item_create(), duration };
vs->canvas_item_set_parent(d.canvas_item, canvas);
vs->canvas_item_add_line(d.canvas_item, _viewport_xform(a), _viewport_xform(b), color, width);
drawings.push_back(d);
Expand All @@ -86,7 +86,7 @@ void DebugDraw::rect(const Rect2 &rect, const Color &color, real_t width, real_t
Vector2 br = _viewport_xform(rect.position + rect.size);

auto *vs = VS::get_singleton();
Drawing d = { vs->canvas_item_create(), duration };
const Drawing d = { vs->canvas_item_create(), duration };
vs->canvas_item_set_parent(d.canvas_item, canvas);
vs->canvas_item_add_line(d.canvas_item, tl, tr, color, width);
vs->canvas_item_add_line(d.canvas_item, tr, br, color, width);
Expand All @@ -99,7 +99,7 @@ void DebugDraw::rect(const Rect2 &rect, const Color &color, real_t width, real_t
void DebugDraw::area(const Rect2 &rect, const Color &color, real_t duration) {
if (ready || init()) {
auto *vs = VS::get_singleton();
Drawing d = { vs->canvas_item_create(), duration };
const Drawing d = { vs->canvas_item_create(), duration };
vs->canvas_item_set_parent(d.canvas_item, canvas);
vs->canvas_item_add_rect(d.canvas_item, _viewport_xform(rect), color);
drawings.push_back(d);
Expand All @@ -109,7 +109,7 @@ void DebugDraw::area(const Rect2 &rect, const Color &color, real_t duration) {
void DebugDraw::print(const String &text, const Color &color, real_t duration) {
if (ready || init()) {
auto *vs = VS::get_singleton();
Drawing d = { vs->canvas_item_create(), duration };
const Drawing d = { vs->canvas_item_create(), duration };
vs->canvas_item_set_parent(d.canvas_item, canvas);
default_font->draw(d.canvas_item, Vector2(1, 1), text, color.inverted());
default_font->draw(d.canvas_item, Vector2(), text, color);
Expand All @@ -119,6 +119,23 @@ void DebugDraw::print(const String &text, const Color &color, real_t duration) {
}
}

void DebugDraw::print_canvas(Node *parent, const String &text, const Point2 &pos, const Color &color, real_t duration) {
if (ready || init()) {
if (const Node2D *node = cast_to<Node2D>(parent)) {
auto *vs = VS::get_singleton();
const Drawing d = { vs->canvas_item_create(), duration };
vs->canvas_item_set_parent(d.canvas_item, node->get_canvas());
default_font->draw(d.canvas_item, Vector2(1, 1), text, color.inverted());
default_font->draw(d.canvas_item, Vector2(), text, color);
const Vector2 unscale = Vector2::ONE / node->get_scale();
vs->canvas_item_set_transform(d.canvas_item, Transform2D(0, unscale, pos));
prints.push_back(d);
} else {
WARN_PRINT("Parent is not Node2D");
}
}
}

void DebugDraw::clear() {
auto *vs = VS::get_singleton();

Expand Down Expand Up @@ -211,11 +228,12 @@ DebugDraw *DebugDraw::get_singleton() {
}

void DebugDraw::_bind_methods() {
ClassDB::bind_method(D_METHOD("circle", "position", "radius", "color", "duration"), &DebugDraw::circle, DEFVAL(0));
ClassDB::bind_method(D_METHOD("line", "a", "b", "color", "width", "duration"), &DebugDraw::line, DEFVAL(1.f), DEFVAL(0));
ClassDB::bind_method(D_METHOD("rect", "rect", "color", "width", "duration"), &DebugDraw::rect, DEFVAL(1.f), DEFVAL(0));
ClassDB::bind_method(D_METHOD("area", "rect", "color", "duration"), &DebugDraw::area, DEFVAL(0));
ClassDB::bind_method(D_METHOD("print", "text", "color", "duration"), &DebugDraw::print, DEFVAL(0));
ClassDB::bind_method(D_METHOD("circle", "position", "radius", "color", "duration"), &DebugDraw::circle, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(0));
ClassDB::bind_method(D_METHOD("line", "a", "b", "color", "width", "duration"), &DebugDraw::line, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(1), DEFVAL(0));
ClassDB::bind_method(D_METHOD("rect", "rect", "color", "width", "duration"), &DebugDraw::rect, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(1), DEFVAL(0));
ClassDB::bind_method(D_METHOD("area", "rect", "color", "duration"), &DebugDraw::area, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(0));
ClassDB::bind_method(D_METHOD("print", "text", "color", "duration"), &DebugDraw::print, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(0));
ClassDB::bind_method(D_METHOD("print_canvas", "canvas", "pos", "text", "color", "duration"), &DebugDraw::print_canvas, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(0));

ClassDB::bind_method(D_METHOD("clear"), &DebugDraw::clear);

Expand Down
20 changes: 11 additions & 9 deletions modules/gdextensions/submodules/debugdraw/debugdraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "core/list.h"
#include "core/object.h"
#include "scene/2d/node_2d.h"
#include "scene/resources/font.h"

class DebugDraw : public Object {
Expand All @@ -50,7 +51,7 @@ class DebugDraw : public Object {

static DebugDraw *singleton;

/// Current drawings
// Current drawings
struct Drawing {
RID canvas_item;
real_t time_left;
Expand All @@ -60,20 +61,21 @@ class DebugDraw : public Object {
Ref<Font> default_font;
RID canvas;

/// State
// State
bool init();
bool ready;

public:
/// Singleton
// Singleton
static DebugDraw *get_singleton();

/// Methods
void circle(const Vector2 &position, real_t radius, const Color &color, real_t duration = 0);
void line(const Vector2 &a, const Vector2 &b, const Color &color, real_t width = 1, real_t duration = 0);
void rect(const Rect2 &rect, const Color &color, real_t width = 1, real_t duration = 0);
void area(const Rect2 &rect, const Color &color, real_t duration = 0);
void print(const String &text, const Color &color, real_t duration = 0);
// Methods
void circle(const Vector2 &position, real_t radius, const Color &color = Color(1, 1, 1, 1), real_t duration = 0);
void line(const Vector2 &a, const Vector2 &b, const Color &color = Color(1, 1, 1, 1), real_t width = 1, real_t duration = 0);
void rect(const Rect2 &rect, const Color &color = Color(1, 1, 1, 1), real_t width = 1, real_t duration = 0);
void area(const Rect2 &rect, const Color &color = Color(1, 1, 1, 1), real_t duration = 0);
void print(const String &text, const Color &color = Color(1, 1, 1, 1), real_t duration = 0);
void print_canvas(Node *parent, const String &text, const Point2 &pos = Point2(), const Color &color = Color(1, 1, 1, 1), real_t duration = 0);

void clear();

Expand Down
9 changes: 7 additions & 2 deletions modules/gdextensions/submodules/scenemerge/merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,10 @@ Node *MeshMergeMaterialRepack::_output(MergeState &state, int p_count) {
}

#ifdef TOOLS_ENABLED
void SceneMergePlugin::_on_merge(Variant p_null) {
merge();
}

void SceneMergePlugin::merge() {
file_export_lib_merge->set_pressed(false);
List<String> extensions;
Expand Down Expand Up @@ -1115,13 +1119,14 @@ void SceneMergePlugin::_dialog_action(String p_file) {
EditorFileSystem::get_singleton()->scan_changes();
}
void SceneMergePlugin::_bind_methods() {
ClassDB::bind_method("_dialog_action", &SceneMergePlugin::_dialog_action);
ClassDB::bind_method(D_METHOD("_dialog_action"), &SceneMergePlugin::_dialog_action);
ClassDB::bind_method(D_METHOD("_on_merge"), &SceneMergePlugin::_on_merge, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("merge"), &SceneMergePlugin::merge);
}

void SceneMergePlugin::_notification(int notification) {
if (notification == NOTIFICATION_ENTER_TREE) {
editor->add_tool_menu_item("Merge Scene", this, "merge");
editor->add_tool_menu_item("Merge Scene", this, "_on_merge");
} else if (notification == NOTIFICATION_EXIT_TREE) {
editor->remove_tool_menu_item("Merge Scene");
}
Expand Down
1 change: 1 addition & 0 deletions modules/gdextensions/submodules/scenemerge/merge.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class SceneMergePlugin : public EditorPlugin {
Ref<SceneMerge> scene_optimize;

void _dialog_action(String p_file);
void _on_merge(Variant p_null);
void merge();

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ static std::string unquote(const char *begin, const char *end) {
return std::string(begin, end - begin);
}

static bool read_etc_file(const char *filename,
const std::string &id_key, const std::string &version_key, const std::string &pretty_name_key,
std::string &id_val, std::string &version_val, std::string &pretty_name_val) {
static bool read_etc_file(const char *filename, const std::string &id_key, const std::string &version_key, const std::string &pretty_name_key, std::string &id_val, std::string &version_val, std::string &pretty_name_val) {
std::string line;
std::ifstream stream("/etc/os-release");
if (!stream) {
Expand All @@ -58,7 +56,7 @@ static bool read_etc_file(const char *filename,

// _____________________________________________________________________________________________________________________

static bool readOsRelease(QUnixOSVersion &v) {
static bool readOsRelease(UnixOSVersionInfo &v) {
static const std::string ID = "ID=";
static const std::string VERSIONID = "VERSION_ID=";
static const std::string PRETTYNAME = "PRETTY_NAME=";
Expand All @@ -67,7 +65,7 @@ static bool readOsRelease(QUnixOSVersion &v) {
// The file /etc/os-release takes precedence over /usr/lib/os-release.
// Applications should check for the former, and exclusively use its data
// if it exists, and only fall back to /usr/lib/os-release if it is missing.
return read_etc_file(v, "/etc/os-release", id, versionId, prettyName) || readEtcFile(v, "/usr/lib/os-release", id, versionId, prettyName);
return read_etc_file(v, "/etc/os-release", id, versionId, prettyName) || read_etc_file(v, "/usr/lib/os-release", id, versionId, prettyName);
}

static std::string get_full_name() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include "abstracted_pipeline.h"

#include "igneous_pipeline.h"
#include "sedimentary_pipeline.h"
#include "metamorphic_pipeline.h"

#include "core/error_macros.h"
#include "common/gd_core.h"

Expand Down

0 comments on commit 61ae0a8

Please sign in to comment.