Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions bytecode/bytecode_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "compat/variant_decoder_compat.h"
#include "compat/variant_writer_compat.h"
#include "utility/common.h"
#include "utility/gdre_config.h"
#include "utility/gdre_settings.h"
#include "utility/godotver.h"

Expand Down Expand Up @@ -623,24 +624,6 @@
Error err = get_script_state(p_buffer, s);
ERR_FAIL_COND_V(err != OK, err);

int tab_size = 4;

if (s.columns.size() > 0) {
Vector<int> diffs;
int prev_column = 1;
for (auto &[key, value] : s.columns) {
int curr_column = value;
if (curr_column > prev_column) {
diffs.push_back(curr_column - prev_column);
}
prev_column = curr_column;
}
tab_size = gdre::get_most_popular_value(diffs);
if (tab_size <= 1) {
tab_size = 4;
}
}

Ref<GDScriptTokenizerCompat> tokenizer = GDScriptTokenizerCompat::create_buffer_tokenizer(this, p_buffer);
if (tokenizer.is_null()) {
return ERR_INVALID_DATA;
Expand All @@ -655,7 +638,8 @@
current = tokenizer->scan();
}

bool use_spaces = false;
bool use_spaces = (IndentType)GDREConfig::get_singleton()->get_setting("Script/Indent/type", 0) == INDENT_TYPE_SPACES;
int tab_size = GDREConfig::get_singleton()->get_setting("Script/Indent/size", 4).operator int();
bool first_line = true;
int version = s.bytecode_version;
int bytecode_version = get_bytecode_version();
Expand Down Expand Up @@ -684,11 +668,11 @@
auto handle_newline = [&](int i, GlobalToken curr_token) {
auto curr_line = tokens[i].end_line;
write_current_line(indent);
if (curr_line <= prev_line) {

Check warning on line 671 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / Windows Template Release

'<=': signed/unsigned mismatch

Check warning on line 671 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / Windows Editor

'<=': signed/unsigned mismatch
curr_line = prev_line + 1; // force new line
}
bool was_escaped = false;

Check warning on line 674 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / 🍎 macOS Template Release

variable 'was_escaped' set but not used

Check warning on line 674 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / 🍎 macOS Template Release

variable 'was_escaped' set but not used

Check warning on line 674 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / 🍎 macOS Editor

variable 'was_escaped' set but not used

Check warning on line 674 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android Template Release

variable 'was_escaped' set but not used

Check warning on line 674 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android Template Release

variable 'was_escaped' set but not used
while (curr_line > prev_line) {

Check warning on line 675 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / Windows Template Release

'>': signed/unsigned mismatch

Check warning on line 675 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / Windows Editor

'>': signed/unsigned mismatch
if (curr_token != G_TK_NEWLINE && bytecode_version < GDSCRIPT_2_0_VERSION) {
script_text += "\\"; // line continuation
was_escaped = true;
Expand All @@ -708,7 +692,7 @@

auto check_new_line = [&](int i) {
auto ln = tokens[i].start_line;
if (ln > prev_line && ln != 0) {

Check warning on line 695 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / Windows Template Release

'>': signed/unsigned mismatch

Check warning on line 695 in bytecode/bytecode_base.cpp

View workflow job for this annotation

GitHub Actions / Windows Editor

'>': signed/unsigned mismatch
return true;
}
ln = tokens[i].end_line;
Expand Down
6 changes: 6 additions & 0 deletions bytecode/bytecode_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ class GDScriptDecomp : public RefCounted {
TOKEN_LINE_MASK = (1 << TOKEN_LINE_BITS) - 1,
};

enum IndentType {
INDENT_TYPE_TABS,
INDENT_TYPE_SPACES,
INDENT_TYPE_MAX,
};

// bytecode_version, ids, constants, tokens, lines, columns
struct ScriptState {
int bytecode_version = -1;
Expand Down
103 changes: 77 additions & 26 deletions compat/fake_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
/**************************************************************************/

#include "fake_mesh.h"

#include "core/math/convex_hull.h"
#include "core/object/class_db.h"
#include "core/templates/pair.h"
#include "scene/resources/3d/importer_mesh.h"
#include "scene/resources/surface_tool.h"
#include "servers/rendering/rendering_server.h"

#ifndef PHYSICS_3D_DISABLED
#include "scene/resources/3d/concave_polygon_shape_3d.h"
Expand Down Expand Up @@ -196,27 +195,28 @@ void _fix_array_compatibility(const Vector<uint8_t> &p_src, uint64_t p_old_forma
if ((p_old_format & OLD_ARRAY_COMPRESS_NORMAL) && (p_old_format & OLD_ARRAY_FORMAT_TANGENT) && (p_old_format & OLD_ARRAY_COMPRESS_TANGENT)) {
for (uint32_t i = 0; i < p_elements; i++) {
const int8_t *src = (const int8_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset];
int16_t *dst = (int16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_NORMAL]];
uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_NORMAL]];

dst[0] = (int16_t)CLAMP(src[0] / 127.0f * 32767, -32768, 32767);
dst[1] = (int16_t)CLAMP(src[1] / 127.0f * 32767, -32768, 32767);
// 4.x requires biasing the octahedron components to a 0.0 <-> 1.0 range, whereas in 3.x they were stored in the -1.0 <-> 1.0 range
dst[0] = (uint16_t)CLAMP((src[0] / 127.0f * .5f + .5f) * 65535, 0, 65535);
dst[1] = (uint16_t)CLAMP((src[1] / 127.0f * .5f + .5f) * 65535, 0, 65535);
}
src_offset += sizeof(int8_t) * 2;
} else {
for (uint32_t i = 0; i < p_elements; i++) {
const int16_t *src = (const int16_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset];
int16_t *dst = (int16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_NORMAL]];
uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_NORMAL]];

dst[0] = src[0];
dst[1] = src[1];
dst[0] = (uint16_t)CLAMP((src[0] / 32767.0f * .5f + .5f) * 65535, 0, 65535);
dst[1] = (uint16_t)CLAMP((src[1] / 32767.0f * .5f + .5f) * 65535, 0, 65535);
}
src_offset += sizeof(int16_t) * 2;
}
} else { // No Octahedral compression
if (p_old_format & OLD_ARRAY_COMPRESS_NORMAL) {
for (uint32_t i = 0; i < p_elements; i++) {
const int8_t *src = (const int8_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset];
const Vector3 original_normal(src[0], src[1], src[2]);
const Vector3 original_normal(src[0] / 127.0f, src[1] / 127.0f, src[2] / 127.0f);
Vector2 res = original_normal.octahedron_encode();

uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_NORMAL]];
Expand Down Expand Up @@ -264,10 +264,10 @@ void _fix_array_compatibility(const Vector<uint8_t> &p_src, uint64_t p_old_forma
if (p_old_format & OLD_ARRAY_COMPRESS_TANGENT) {
for (uint32_t i = 0; i < p_elements; i++) {
const int8_t *src = (const int8_t *)&src_vertex_ptr[i * src_vertex_stride + src_offset];
const Vector3 original_tangent(src[0], src[1], src[2]);
Vector2 res = original_tangent.octahedron_tangent_encode(src[3]);
const Vector3 original_tangent(src[0] / 127.0f, src[1] / 127.0f, src[2] / 127.0f);
Vector2 res = original_tangent.octahedron_tangent_encode(src[3] / 127.0f);

uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_NORMAL]];
uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_TANGENT]];
dst[0] = (uint16_t)CLAMP(res.x * 65535, 0, 65535);
dst[1] = (uint16_t)CLAMP(res.y * 65535, 0, 65535);
if (dst[0] == 0 && dst[1] == 65535) {
Expand All @@ -283,7 +283,7 @@ void _fix_array_compatibility(const Vector<uint8_t> &p_src, uint64_t p_old_forma
const Vector3 original_tangent(src[0], src[1], src[2]);
Vector2 res = original_tangent.octahedron_tangent_encode(src[3]);

uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_NORMAL]];
uint16_t *dst = (uint16_t *)&dst_vertex_ptr[i * dst_normal_tangent_stride + dst_offsets[Mesh::ARRAY_TANGENT]];
dst[0] = (uint16_t)CLAMP(res.x * 65535, 0, 65535);
dst[1] = (uint16_t)CLAMP(res.y * 65535, 0, 65535);
if (dst[0] == 0 && dst[1] == 65535) {
Expand Down Expand Up @@ -520,7 +520,7 @@ bool FakeMesh::_set(const StringName &p_name, const Variant &p_value) {
new_format |= ARRAY_FORMAT_INDEX;
}
if (old_format & OLD_ARRAY_FLAG_USE_2D_VERTICES) {
new_format |= OLD_ARRAY_FLAG_USE_2D_VERTICES;
new_format |= ARRAY_FLAG_USE_2D_VERTICES;
}

Vector<uint8_t> vertex_array;
Expand Down Expand Up @@ -1458,17 +1458,7 @@ void FakeMesh::set_shadow_mesh(const Ref<Resource> &p_mesh) {
ERR_FAIL_COND_MSG(p_mesh == this, "Cannot set a mesh as its own shadow mesh.");
Ref<MissingResource> mr = p_mesh;
if (mr.is_valid()) {
Ref<MissingResource> m_res = mr;
if (ResourceCompatConverter::is_external_resource(mr)) {
Error err;
m_res = ResourceCompatLoader::fake_load(mr->get_path(), "", &err);
ERR_FAIL_COND_MSG(err != OK || !m_res.is_valid(), "Failed to load material: " + mr->get_path());
}
Ref<FakeMesh> fake_mesh;
fake_mesh.instantiate();
fake_mesh->load_type = load_type;

shadow_mesh = ResourceCompatConverter::set_real_from_missing_resource(m_res, fake_mesh, load_type);
shadow_mesh = create_from_missing_resource(mr, load_type);
} else {
shadow_mesh = p_mesh;
}
Expand All @@ -1483,6 +1473,67 @@ Ref<Resource> FakeMesh::get_shadow_mesh() const {
return shadow_mesh;
}

Ref<ArrayMesh> FakeMesh::mesh_to_array_mesh(const Ref<Mesh> &p_mesh) {
if (p_mesh.is_null()) {
return Ref<ArrayMesh>();
}
Ref<ArrayMesh> ret_mesh = p_mesh;
if (ret_mesh.is_valid()) {
return ret_mesh;
}
Ref<ImporterMesh> importer_mesh = ImporterMesh::from_mesh(p_mesh);

Ref<FakeMesh> fake_mesh = p_mesh;
if (fake_mesh.is_valid()) {
// Convert blend shape mode and names if any.
if (fake_mesh->get_blend_shape_count() > 0) {
importer_mesh->set_blend_shape_mode(fake_mesh->get_blend_shape_mode());
}
for (int32_t surface_i = 0; surface_i < p_mesh->get_surface_count(); surface_i++) {
String surface_name = fake_mesh->surface_get_name(surface_i);
if (!surface_name.is_empty()) {
importer_mesh->set_surface_name(surface_i, surface_name);
}
}
}
ret_mesh = importer_mesh->get_mesh();

// Merge metadata.
ret_mesh->merge_meta_from(*p_mesh);
ret_mesh->set_name(p_mesh->get_name());
ret_mesh->set_local_to_scene(p_mesh->is_local_to_scene());
ret_mesh->set_scene_unique_id(p_mesh->get_scene_unique_id());
ret_mesh->set_path_cache(p_mesh->get_path());

return ret_mesh;
}

Ref<FakeMesh> FakeMesh::load_from_array_mesh(const String &p_path) {
Error err;
Ref<MissingResource> mr = ResourceCompatLoader::fake_load(p_path, "", &err);
return create_from_missing_resource(mr, ResourceCompatLoader::get_default_load_type());
}

Ref<FakeMesh> FakeMesh::create_from_missing_resource(const Ref<MissingResource> &p_mr, ResourceInfo::LoadType p_load_type) {
ERR_FAIL_COND_V_MSG(!p_mr.is_valid(), Ref<FakeMesh>(), "Missing resource is not valid");
ERR_FAIL_COND_V_MSG(p_mr->get_original_class() != "ArrayMesh", Ref<FakeMesh>(), "Missing resource is not an array mesh");
Ref<FakeMesh> mesh;
mesh.instantiate();
mesh->load_type = p_load_type;
// Not using ResourceCompatConverter::set_real_from_missing_resource because we have to convert any embedded ArrayMeshes to FakeMeshes
List<PropertyInfo> property_info;
p_mr->get_property_list(&property_info);
for (auto &property : property_info) {
if (property.usage & PROPERTY_USAGE_STORAGE) {
mesh->set(property.name, p_mr->get(property.name));
}
}
mesh->set_path_cache(p_mr->get_path());
mesh->set_local_to_scene(p_mr->is_local_to_scene());
mesh->set_scene_unique_id(p_mr->get_scene_unique_id());
return mesh;
}

void FakeMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &FakeMesh::add_blend_shape);
ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &FakeMesh::get_blend_shape_count);
Expand Down
8 changes: 5 additions & 3 deletions compat/fake_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@

#pragma once
#include "core/io/resource.h"
#include "core/math/face3.h"
#include "core/math/triangle_mesh.h"
#include "scene/resources/material.h"
#include "servers/rendering/rendering_server.h"

#include "utility/resource_info.h"

Expand All @@ -45,6 +42,8 @@ class ConvexPolygonShape3D;
class Shape3D;
#endif // PHYSICS_3D_DISABLED
class MeshConvexDecompositionSettings;
class ImporterMesh;
class MissingResource;

#include "scene/resources/mesh.h"

Expand Down Expand Up @@ -155,6 +154,9 @@ class FakeMesh : public Mesh {

void set_shadow_mesh(const Ref<Resource> &p_mesh);
Ref<Resource> get_shadow_mesh() const;
static Ref<ArrayMesh> mesh_to_array_mesh(const Ref<Mesh> &p_mesh);
static Ref<FakeMesh> create_from_missing_resource(const Ref<MissingResource> &p_mr, ResourceInfo::LoadType p_load_type);
static Ref<FakeMesh> load_from_array_mesh(const String &p_path);

FakeMesh();

Expand Down
10 changes: 3 additions & 7 deletions compat/resource_loader_compat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,23 +830,19 @@ Ref<Resource> ResourceCompatConverter::set_real_from_missing_resource(Ref<Missin
mr->get_property_list(&property_info);
for (auto &property : property_info) {
bool is_storage = property.usage & PROPERTY_USAGE_STORAGE;
// if (property.usage & PROPERTY_USAGE_STORAGE) {
if (property.name == "resource_path") {
res->set_path_cache(mr->get(property.name));
} else if (is_storage) {
if (is_storage) {
Ref<MissingResource> m_res = mr->get(property.name);
const String &set_prop = prop_map.has(property.name) ? prop_map[property.name] : property.name;
if (m_res.is_valid()) {
res->set(set_prop, get_real_from_missing_resource(m_res, load_type));
} else {
res->set(set_prop, mr->get(property.name));
}
} else {
// WARN_PRINT("Property " + property.name + " is not storage");
}
// }
}
res->set_path_cache(mr->get_path());
res->set_local_to_scene(mr->is_local_to_scene());
res->set_scene_unique_id(mr->get_scene_unique_id());
return res;
}

Expand Down
Loading
Loading