Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks

This commit is contained in:
Rémi Verschelde 2021-05-04 14:41:06 +02:00
parent 64a63e0861
commit b5e1e05ef2
No known key found for this signature in database
GPG key ID: C3336907360768E1
1439 changed files with 1 additions and 34187 deletions

View file

@ -76,7 +76,7 @@ IndentWidth: 4
# IndentWrappedFunctionNames: false
# JavaScriptQuotes: Leave
# JavaScriptWrapImports: true
# KeepEmptyLinesAtTheStartOfBlocks: true
KeepEmptyLinesAtTheStartOfBlocks: false
# MacroBlockBegin: ''
# MacroBlockEnd: ''
# MaxEmptyLinesToKeep: 1

View file

@ -42,7 +42,6 @@ public:
};
void Array::_ref(const Array &p_from) const {
ArrayPrivate *_fp = p_from._p;
ERR_FAIL_COND(!_fp); // should NOT happen.
@ -60,7 +59,6 @@ void Array::_ref(const Array &p_from) const {
}
void Array::_unref() const {
if (!_p)
return;
@ -71,69 +69,55 @@ void Array::_unref() const {
}
Variant &Array::operator[](int p_idx) {
return _p->array.write[p_idx];
}
const Variant &Array::operator[](int p_idx) const {
return _p->array[p_idx];
}
int Array::size() const {
return _p->array.size();
}
bool Array::empty() const {
return _p->array.empty();
}
void Array::clear() {
_p->array.clear();
}
bool Array::operator==(const Array &p_array) const {
return _p == p_array._p;
}
uint32_t Array::hash() const {
uint32_t h = hash_djb2_one_32(0);
for (int i = 0; i < _p->array.size(); i++) {
h = hash_djb2_one_32(_p->array[i].hash(), h);
}
return h;
}
void Array::operator=(const Array &p_array) {
_ref(p_array);
}
void Array::push_back(const Variant &p_value) {
_p->array.push_back(p_value);
}
void Array::append_array(const Array &p_array) {
_p->array.append_array(p_array._p->array);
}
Error Array::resize(int p_new_size) {
return _p->array.resize(p_new_size);
}
void Array::insert(int p_pos, const Variant &p_value) {
_p->array.insert(p_pos, p_value);
}
void Array::erase(const Variant &p_value) {
_p->array.erase(p_value);
}
@ -148,12 +132,10 @@ Variant Array::back() const {
}
int Array::find(const Variant &p_value, int p_from) const {
return _p->array.find(p_value, p_from);
}
int Array::rfind(const Variant &p_value, int p_from) const {
if (_p->array.size() == 0)
return -1;
@ -167,7 +149,6 @@ int Array::rfind(const Variant &p_value, int p_from) const {
}
for (int i = p_from; i >= 0; i--) {
if (_p->array[i] == p_value) {
return i;
}
@ -177,18 +158,15 @@ int Array::rfind(const Variant &p_value, int p_from) const {
}
int Array::find_last(const Variant &p_value) const {
return rfind(p_value);
}
int Array::count(const Variant &p_value) const {
if (_p->array.size() == 0)
return 0;
int amount = 0;
for (int i = 0; i < _p->array.size(); i++) {
if (_p->array[i] == p_value) {
amount++;
}
@ -202,22 +180,18 @@ bool Array::has(const Variant &p_value) const {
}
void Array::remove(int p_pos) {
_p->array.remove(p_pos);
}
void Array::set(int p_idx, const Variant &p_value) {
operator[](p_idx) = p_value;
}
const Variant &Array::get(int p_idx) const {
return operator[](p_idx);
}
Array Array::duplicate(bool p_deep) const {
Array new_arr;
int element_count = size();
new_arr.resize(element_count);
@ -229,7 +203,6 @@ Array Array::duplicate(bool p_deep) const {
}
int Array::_clamp_slice_index(int p_index) const {
int arr_size = size();
int fixed_index = CLAMP(p_index, -arr_size, arr_size - 1);
if (fixed_index < 0) {
@ -278,7 +251,6 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l
}
struct _ArrayVariantSort {
_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
bool valid = false;
Variant res;
@ -290,18 +262,15 @@ struct _ArrayVariantSort {
};
Array &Array::sort() {
_p->array.sort_custom<_ArrayVariantSort>();
return *this;
}
struct _ArrayVariantSortCustom {
Object *obj;
StringName func;
_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
const Variant *args[2] = { &p_l, &p_r };
Variant::CallError err;
bool res = obj->call(func, args, 2, err);
@ -311,7 +280,6 @@ struct _ArrayVariantSortCustom {
}
};
Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
ERR_FAIL_NULL_V(p_obj, *this);
SortArray<Variant, _ArrayVariantSortCustom, true> avs;
@ -322,7 +290,6 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
}
void Array::shuffle() {
const int n = _p->array.size();
if (n < 2)
return;
@ -337,7 +304,6 @@ void Array::shuffle() {
template <typename Less>
_FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value, bool p_before, const Less &p_less) {
int lo = 0;
int hi = p_array.size();
if (p_before) {
@ -363,12 +329,10 @@ _FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value
}
int Array::bsearch(const Variant &p_value, bool p_before) {
return bisect(_p->array, p_value, p_before, _ArrayVariantSort());
}
int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before) {
ERR_FAIL_NULL_V(p_obj, 0);
_ArrayVariantSortCustom less;
@ -379,18 +343,15 @@ int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringNam
}
Array &Array::invert() {
_p->array.invert();
return *this;
}
void Array::push_front(const Variant &p_value) {
_p->array.insert(0, p_value);
}
Variant Array::pop_back() {
if (!_p->array.empty()) {
int n = _p->array.size() - 1;
Variant ret = _p->array.get(n);
@ -401,7 +362,6 @@ Variant Array::pop_back() {
}
Variant Array::pop_front() {
if (!_p->array.empty()) {
Variant ret = _p->array.get(0);
_p->array.remove(0);
@ -411,7 +371,6 @@ Variant Array::pop_front() {
}
Variant Array::min() const {
Variant minval;
for (int i = 0; i < size(); i++) {
if (i == 0) {
@ -434,7 +393,6 @@ Variant Array::min() const {
}
Variant Array::max() const {
Variant maxval;
for (int i = 0; i < size(); i++) {
if (i == 0) {
@ -461,17 +419,14 @@ const void *Array::id() const {
}
Array::Array(const Array &p_from) {
_p = NULL;
_ref(p_from);
}
Array::Array() {
_p = memnew(ArrayPrivate);
_p->refcount.init();
}
Array::~Array() {
_unref();
}

View file

@ -39,7 +39,6 @@ class Object;
class StringName;
class Array {
mutable ArrayPrivate *_p;
void _ref(const Array &p_from) const;
void _unref() const;

File diff suppressed because it is too large Load diff

View file

@ -399,7 +399,6 @@ VARIANT_ENUM_CAST(_OS::ScreenOrientation);
VARIANT_ENUM_CAST(_OS::HandleType);
class _Geometry : public Object {
GDCLASS(_Geometry, Object);
static _Geometry *singleton;
@ -480,7 +479,6 @@ VARIANT_ENUM_CAST(_Geometry::PolyJoinType);
VARIANT_ENUM_CAST(_Geometry::PolyEndType);
class _File : public Reference {
GDCLASS(_File, Reference);
FileAccess *f;
bool eswap;
@ -583,7 +581,6 @@ VARIANT_ENUM_CAST(_File::ModeFlags);
VARIANT_ENUM_CAST(_File::CompressionMode);
class _Directory : public Reference {
GDCLASS(_Directory, Reference);
DirAccess *d;
@ -627,7 +624,6 @@ private:
};
class _Marshalls : public Object {
GDCLASS(_Marshalls, Object);
static _Marshalls *singleton;
@ -652,7 +648,6 @@ public:
};
class _Mutex : public Reference {
GDCLASS(_Mutex, Reference);
Mutex mutex;
@ -665,7 +660,6 @@ public:
};
class _Semaphore : public Reference {
GDCLASS(_Semaphore, Reference);
Semaphore semaphore;
@ -677,7 +671,6 @@ public:
};
class _Thread : public Reference {
GDCLASS(_Thread, Reference);
protected:
@ -711,7 +704,6 @@ public:
VARIANT_ENUM_CAST(_Thread::Priority);
class _ClassDB : public Object {
GDCLASS(_ClassDB, Object);
protected:

View file

@ -40,14 +40,12 @@
#ifdef DEBUG_METHODS_ENABLED
MethodDefinition D_METHOD(const char *p_name) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
return md;
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.push_back(StaticCString::create(p_arg1));
@ -55,7 +53,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) {
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(2);
@ -65,7 +62,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(3);
@ -76,7 +72,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(4);
@ -88,7 +83,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(5);
@ -101,7 +95,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(6);
@ -115,7 +108,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(7);
@ -130,7 +122,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(8);
@ -146,7 +137,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(9);
@ -163,7 +153,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(10);
@ -181,7 +170,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(11);
@ -200,7 +188,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(12);
@ -220,7 +207,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
}
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13) {
MethodDefinition md;
md.name = StaticCString::create(p_name);
md.args.resize(13);
@ -245,12 +231,10 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_
ClassDB::APIType ClassDB::current_api = API_CORE;
void ClassDB::set_current_api(APIType p_api) {
current_api = p_api;
}
ClassDB::APIType ClassDB::get_current_api() {
return current_api;
}
@ -259,7 +243,6 @@ HashMap<StringName, StringName> ClassDB::resource_base_extensions;
HashMap<StringName, StringName> ClassDB::compat_classes;
ClassDB::ClassInfo::ClassInfo() {
api = API_NONE;
creation_func = NULL;
inherits_ptr = NULL;
@ -271,11 +254,9 @@ ClassDB::ClassInfo::~ClassInfo() {
}
bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_inherits) {
StringName inherits = p_class;
while (inherits.operator String().length()) {
if (inherits == p_inherits)
return true;
inherits = _get_parent_class(inherits);
@ -285,20 +266,17 @@ bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_in
}
bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) {
OBJTYPE_RLOCK;
return _is_parent_class(p_class, p_inherits);
}
void ClassDB::get_class_list(List<StringName> *p_classes) {
OBJTYPE_RLOCK;
const StringName *k = NULL;
while ((k = classes.next(k))) {
p_classes->push_back(*k);
}
@ -306,33 +284,28 @@ void ClassDB::get_class_list(List<StringName> *p_classes) {
}
void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
OBJTYPE_RLOCK;
const StringName *k = NULL;
while ((k = classes.next(k))) {
if (*k != p_class && _is_parent_class(*k, p_class))
p_classes->push_back(*k);
}
}
void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
OBJTYPE_RLOCK;
const StringName *k = NULL;
while ((k = classes.next(k))) {
if (*k != p_class && _get_parent_class(*k) == p_class)
p_classes->push_back(*k);
}
}
StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@ -342,21 +315,18 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
}
StringName ClassDB::_get_parent_class(const StringName &p_class) {
ClassInfo *ti = classes.getptr(p_class);
ERR_FAIL_COND_V_MSG(!ti, StringName(), "Cannot get class '" + String(p_class) + "'.");
return ti->inherits;
}
StringName ClassDB::get_parent_class(const StringName &p_class) {
OBJTYPE_RLOCK;
return _get_parent_class(p_class);
}
ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@ -366,7 +336,6 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
}
uint64_t ClassDB::get_api_hash(APIType p_api) {
OBJTYPE_RLOCK;
#ifdef DEBUG_METHODS_ENABLED
@ -377,14 +346,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
const StringName *k = NULL;
while ((k = classes.next(k))) {
names.push_back(*k);
}
//must be alphabetically sorted for hash to compute
names.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
ClassInfo *t = classes.getptr(E->get());
ERR_FAIL_COND_V_MSG(!t, 0, "Cannot get class '" + String(E->get()) + "'.");
if (t->api != p_api || !t->exposed)
@ -399,7 +366,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
k = NULL;
while ((k = t->method_map.next(k))) {
String name = k->operator String();
ERR_CONTINUE(name.empty());
@ -413,7 +379,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
MethodBind *mb = t->method_map[F->get()];
hash = hash_djb2_one_64(mb->get_name().hash(), hash);
hash = hash_djb2_one_64(mb->get_argument_count(), hash);
@ -446,14 +411,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
k = NULL;
while ((k = t->constant_map.next(k))) {
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
hash = hash_djb2_one_64(F->get().hash(), hash);
hash = hash_djb2_one_64(t->constant_map[F->get()], hash);
}
@ -466,14 +429,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
k = NULL;
while ((k = t->signal_map.next(k))) {
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
MethodInfo &mi = t->signal_map[F->get()];
hash = hash_djb2_one_64(F->get().hash(), hash);
for (int i = 0; i < mi.arguments.size(); i++) {
@ -489,14 +450,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
k = NULL;
while ((k = t->property_setget.next(k))) {
snames.push_back(*k);
}
snames.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
PropertySetGet *psg = t->property_setget.getptr(F->get());
ERR_FAIL_COND_V(!psg, 0);
@ -508,7 +467,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
//property list
for (List<PropertyInfo>::Element *F = t->property_list.front(); F; F = F->next()) {
hash = hash_djb2_one_64(F->get().name.hash(), hash);
hash = hash_djb2_one_64(F->get().type, hash);
hash = hash_djb2_one_64(F->get().hint, hash);
@ -524,19 +482,16 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
}
bool ClassDB::class_exists(const StringName &p_class) {
OBJTYPE_RLOCK;
return classes.has(p_class);
}
void ClassDB::add_compatibility_class(const StringName &p_class, const StringName &p_fallback) {
OBJTYPE_WLOCK;
compat_classes[p_class] = p_fallback;
}
Object *ClassDB::instance(const StringName &p_class) {
ClassInfo *ti;
{
OBJTYPE_RLOCK;
@ -559,7 +514,6 @@ Object *ClassDB::instance(const StringName &p_class) {
return ti->creation_func();
}
bool ClassDB::can_instance(const StringName &p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@ -573,7 +527,6 @@ bool ClassDB::can_instance(const StringName &p_class) {
}
void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) {
OBJTYPE_WLOCK;
const StringName &name = p_class;
@ -587,7 +540,6 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit
ti.api = current_api;
if (ti.inherits) {
ERR_FAIL_COND(!classes.has(ti.inherits)); //it MUST be registered.
ti.inherits_ptr = &classes[ti.inherits];
@ -597,15 +549,12 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit
}
void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
if (type->disabled) {
if (p_no_inheritance)
break;
@ -616,12 +565,10 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
#ifdef DEBUG_METHODS_ENABLED
for (List<MethodInfo>::Element *E = type->virtual_methods.front(); E; E = E->next()) {
p_methods->push_back(E->get());
}
for (List<StringName>::Element *E = type->method_order.front(); E; E = E->next()) {
MethodBind *method = type->method_map.get(E->get());
MethodInfo minfo;
minfo.name = E->get();
@ -631,7 +578,6 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
continue;
for (int i = 0; i < method->get_argument_count(); i++) {
//Variant::Type t=method->get_argument_type(i);
minfo.arguments.push_back(method->get_argument_info(i));
@ -653,7 +599,6 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
const StringName *K = NULL;
while ((K = type->method_map.next(K))) {
MethodBind *m = type->method_map[*K];
MethodInfo mi;
mi.name = m->get_name();
@ -670,13 +615,11 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
}
MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
MethodBind **method = type->method_map.getptr(p_name);
if (method && *method)
return *method;
@ -686,7 +629,6 @@ MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
}
void ClassDB::bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant) {
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
@ -694,7 +636,6 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
ERR_FAIL_COND(!type);
if (type->constant_map.has(p_name)) {
ERR_FAIL();
}
@ -723,13 +664,11 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
}
void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
#ifdef DEBUG_METHODS_ENABLED
for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next())
p_constants->push_back(E->get());
@ -749,16 +688,13 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List<String>
}
int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
int *constant = type->constant_map.getptr(p_name);
if (constant) {
if (p_success)
*p_success = true;
return *constant;
@ -774,16 +710,13 @@ int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p
}
StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
const StringName *k = NULL;
while ((k = type->enum_map.next(k))) {
List<StringName> &constants_list = type->enum_map.get(*k);
const List<StringName>::Element *found = constants_list.find(p_name);
if (found)
@ -800,13 +733,11 @@ StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const S
}
void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
const StringName *k = NULL;
while ((k = type->enum_map.next(k))) {
p_enums->push_back(*k);
@ -820,13 +751,11 @@ void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums
}
void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
while (type) {
const List<StringName> *constants = type->enum_map.getptr(p_enum);
if (constants) {
@ -843,7 +772,6 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_
}
void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
@ -863,7 +791,6 @@ void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
}
void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, bool p_no_inheritance) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
@ -872,10 +799,8 @@ void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, b
ClassInfo *check = type;
while (check) {
const StringName *S = NULL;
while ((S = check->signal_map.next(S))) {
p_signals->push_back(check->signal_map[*S]);
}
@ -887,7 +812,6 @@ void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, b
}
bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
@ -901,7 +825,6 @@ bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
}
bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_signal) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
@ -919,7 +842,6 @@ bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_
}
void ClassDB::add_property_group(StringName p_class, const String &p_name, const String &p_prefix) {
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_COND(!type);
@ -928,7 +850,6 @@ void ClassDB::add_property_group(StringName p_class, const String &p_name, const
}
void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
lock.read_lock();
ClassInfo *type = classes.getptr(p_class);
lock.read_unlock();
@ -949,7 +870,6 @@ void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, cons
MethodBind *mb_get = NULL;
if (p_getter) {
mb_get = get_method(p_class, p_getter);
#ifdef DEBUG_METHODS_ENABLED
@ -994,15 +914,12 @@ void ClassDB::set_property_default_value(StringName p_class, const StringName &p
}
void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
OBJTYPE_RLOCK;
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
for (List<PropertyInfo>::Element *E = check->property_list.front(); E; E = E->next()) {
if (p_validator) {
PropertyInfo pi = E->get();
p_validator->_validate_property(pi);
@ -1025,7 +942,6 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
if (!psg->setter) {
if (r_valid)
*r_valid = false;
@ -1082,10 +998,8 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
r_value = p_object->call(psg->getter, arg, 1, ce);
} else {
Variant::CallError ce;
if (psg->_getptr) {
r_value = psg->_getptr->call(p_object, NULL, 0, ce);
} else {
r_value = p_object->call(psg->getter, NULL, 0, ce);
@ -1096,7 +1010,6 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
const int *c = check->constant_map.getptr(p_property);
if (c) {
r_value = *c;
return true;
}
@ -1108,13 +1021,11 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
}
int ClassDB::get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
if (r_is_valid)
*r_is_valid = true;
@ -1130,13 +1041,11 @@ int ClassDB::get_property_index(const StringName &p_class, const StringName &p_p
}
Variant::Type ClassDB::get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
if (r_is_valid)
*r_is_valid = true;
@ -1152,13 +1061,11 @@ Variant::Type ClassDB::get_property_type(const StringName &p_class, const String
}
StringName ClassDB::get_property_setter(StringName p_class, const StringName &p_property) {
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
return psg->setter;
}
@ -1169,13 +1076,11 @@ StringName ClassDB::get_property_setter(StringName p_class, const StringName &p_
}
StringName ClassDB::get_property_getter(StringName p_class, const StringName &p_property) {
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
return psg->getter;
}
@ -1186,7 +1091,6 @@ StringName ClassDB::get_property_getter(StringName p_class, const StringName &p_
}
bool ClassDB::has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance) {
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
@ -1202,7 +1106,6 @@ bool ClassDB::has_property(const StringName &p_class, const StringName &p_proper
}
void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_flags) {
OBJTYPE_WLOCK;
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
@ -1212,7 +1115,6 @@ void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_fl
}
bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) {
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
@ -1275,7 +1177,6 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c
defvals.resize(p_defcount);
for (int i = 0; i < p_defcount; i++) {
defvals.write[i] = *p_defs[p_defcount - i - 1];
}
@ -1299,7 +1200,6 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_
}
void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) {
ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'.");
#ifdef DEBUG_METHODS_ENABLED
@ -1307,7 +1207,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
for (List<MethodInfo>::Element *E = check->virtual_methods.front(); E; E = E->next()) {
p_methods->push_back(E->get());
}
@ -1321,7 +1220,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p
}
void ClassDB::set_class_enabled(StringName p_class, bool p_enable) {
OBJTYPE_WLOCK;
ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'.");
@ -1329,7 +1227,6 @@ void ClassDB::set_class_enabled(StringName p_class, bool p_enable) {
}
bool ClassDB::is_class_enabled(StringName p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@ -1344,7 +1241,6 @@ bool ClassDB::is_class_enabled(StringName p_class) {
}
bool ClassDB::is_class_exposed(StringName p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@ -1353,7 +1249,6 @@ bool ClassDB::is_class_exposed(StringName p_class) {
}
StringName ClassDB::get_category(const StringName &p_node) {
ERR_FAIL_COND_V(!classes.has(p_node), StringName());
#ifdef DEBUG_ENABLED
return classes[p_node].category;
@ -1363,7 +1258,6 @@ StringName ClassDB::get_category(const StringName &p_node) {
}
void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) {
if (resource_base_extensions.has(p_extension))
return;
@ -1371,17 +1265,14 @@ void ClassDB::add_resource_base_extension(const StringName &p_extension, const S
}
void ClassDB::get_resource_base_extensions(List<String> *p_extensions) {
const StringName *K = NULL;
while ((K = resource_base_extensions.next(K))) {
p_extensions->push_back(*K);
}
}
void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p_extensions) {
const StringName *K = NULL;
while ((K = resource_base_extensions.next(K))) {
@ -1395,9 +1286,7 @@ HashMap<StringName, HashMap<StringName, Variant>> ClassDB::default_values;
Set<StringName> ClassDB::default_values_cached;
Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid) {
if (!default_values_cached.has(p_class)) {
if (!default_values.has(p_class)) {
default_values[p_class] = HashMap<StringName, Variant>();
}
@ -1414,12 +1303,10 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con
}
if (c) {
List<PropertyInfo> plist;
c->get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
if (E->get().usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR)) {
if (!default_values[p_class].has(E->get().name)) {
Variant v = c->get(E->get().name);
default_values[p_class][E->get().name] = v;
@ -1455,24 +1342,20 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con
RWLock ClassDB::lock;
void ClassDB::cleanup_defaults() {
default_values.clear();
default_values_cached.clear();
}
void ClassDB::cleanup() {
//OBJTYPE_LOCK; hah not here
const StringName *k = NULL;
while ((k = classes.next(k))) {
ClassInfo &ti = classes[*k];
const StringName *m = NULL;
while ((m = ti.method_map.next(m))) {
memdelete(ti.method_map[*m]);
}
}

View file

@ -46,7 +46,6 @@
#ifdef DEBUG_METHODS_ENABLED
struct MethodDefinition {
StringName name;
Vector<StringName> args;
MethodDefinition() {}
@ -101,7 +100,6 @@ public:
public:
struct PropertySetGet {
int index;
StringName setter;
StringName getter;
@ -111,7 +109,6 @@ public:
};
struct ClassInfo {
APIType api;
ClassInfo *inherits_ptr;
void *class_ptr;
@ -170,13 +167,11 @@ public:
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
template <class T>
static void _add_class() {
_add_class2(T::get_class_static(), T::get_parent_class_static());
}
template <class T>
static void register_class() {
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
@ -189,7 +184,6 @@ public:
template <class T>
static void register_virtual_class() {
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
@ -201,13 +195,11 @@ public:
template <class T>
static Object *_create_ptr_func() {
return T::create();
}
template <class T>
static void register_custom_instance_class() {
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
@ -233,7 +225,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method) {
MethodBind *bind = create_method_bind(p_method);
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, NULL, 0); //use static function, much smaller binary usage
@ -241,7 +232,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[1] = { &p_def1 };
@ -250,7 +240,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[2] = { &p_def1, &p_def2 };
@ -259,7 +248,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[3] = { &p_def1, &p_def2, &p_def3 };
@ -268,7 +256,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[4] = { &p_def1, &p_def2, &p_def3, &p_def4 };
@ -277,7 +264,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[5] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5 };
@ -286,7 +272,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[6] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6 };
@ -295,7 +280,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[7] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7 };
@ -304,7 +288,6 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7, const Variant &p_def8) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[8] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8 };
@ -313,7 +296,6 @@ public:
template <class M>
static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
GLOBAL_LOCK_FUNCTION;
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);

View file

@ -36,7 +36,6 @@
#include "core/print_string.h"
uint32_t Color::to_argb32() const {
uint32_t c = (uint8_t)Math::round(a * 255);
c <<= 8;
c |= (uint8_t)Math::round(r * 255);
@ -49,7 +48,6 @@ uint32_t Color::to_argb32() const {
}
uint32_t Color::to_abgr32() const {
uint32_t c = (uint8_t)Math::round(a * 255);
c <<= 8;
c |= (uint8_t)Math::round(b * 255);
@ -62,7 +60,6 @@ uint32_t Color::to_abgr32() const {
}
uint32_t Color::to_rgba32() const {
uint32_t c = (uint8_t)Math::round(r * 255);
c <<= 8;
c |= (uint8_t)Math::round(g * 255);
@ -75,7 +72,6 @@ uint32_t Color::to_rgba32() const {
}
uint64_t Color::to_abgr64() const {
uint64_t c = (uint16_t)Math::round(a * 65535);
c <<= 16;
c |= (uint16_t)Math::round(b * 65535);
@ -88,7 +84,6 @@ uint64_t Color::to_abgr64() const {
}
uint64_t Color::to_argb64() const {
uint64_t c = (uint16_t)Math::round(a * 65535);
c <<= 16;
c |= (uint16_t)Math::round(r * 65535);
@ -101,7 +96,6 @@ uint64_t Color::to_argb64() const {
}
uint64_t Color::to_rgba64() const {
uint64_t c = (uint16_t)Math::round(r * 65535);
c <<= 16;
c |= (uint16_t)Math::round(g * 65535);
@ -114,7 +108,6 @@ uint64_t Color::to_rgba64() const {
}
float Color::get_h() const {
float min = MIN(r, g);
min = MIN(min, b);
float max = MAX(r, g);
@ -141,7 +134,6 @@ float Color::get_h() const {
}
float Color::get_s() const {
float min = MIN(r, g);
min = MIN(min, b);
float max = MAX(r, g);
@ -153,14 +145,12 @@ float Color::get_s() const {
}
float Color::get_v() const {
float max = MAX(r, g);
max = MAX(max, b);
return max;
}
void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
int i;
float f, p, q, t;
a = p_alpha;
@ -215,25 +205,21 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
}
bool Color::is_equal_approx(const Color &p_color) const {
return Math::is_equal_approx(r, p_color.r) && Math::is_equal_approx(g, p_color.g) && Math::is_equal_approx(b, p_color.b) && Math::is_equal_approx(a, p_color.a);
}
void Color::invert() {
r = 1.0 - r;
g = 1.0 - g;
b = 1.0 - b;
}
void Color::contrast() {
r = Math::fmod(r + 0.5, 1.0);
g = Math::fmod(g + 0.5, 1.0);
b = Math::fmod(b + 0.5, 1.0);
}
Color Color::hex(uint32_t p_hex) {
float a = (p_hex & 0xFF) / 255.0;
p_hex >>= 8;
float b = (p_hex & 0xFF) / 255.0;
@ -246,7 +232,6 @@ Color Color::hex(uint32_t p_hex) {
}
Color Color::hex64(uint64_t p_hex) {
float a = (p_hex & 0xFFFF) / 65535.0;
p_hex >>= 16;
float b = (p_hex & 0xFFFF) / 65535.0;
@ -259,7 +244,6 @@ Color Color::hex64(uint64_t p_hex) {
}
Color Color::from_rgbe9995(uint32_t p_rgbe) {
float r = p_rgbe & 0x1ff;
float g = (p_rgbe >> 9) & 0x1ff;
float b = (p_rgbe >> 18) & 0x1ff;
@ -274,11 +258,9 @@ Color Color::from_rgbe9995(uint32_t p_rgbe) {
}
static float _parse_col(const String &p_str, int p_ofs) {
int ig = 0;
for (int i = 0; i < 2; i++) {
int c = p_str[i + p_ofs];
int v = 0;
@ -304,21 +286,18 @@ static float _parse_col(const String &p_str, int p_ofs) {
}
Color Color::inverted() const {
Color c = *this;
c.invert();
return c;
}
Color Color::contrasted() const {
Color c = *this;
c.contrast();
return c;
}
Color Color::html(const String &p_color) {
String color = p_color;
if (color.length() == 0)
return Color();
@ -362,7 +341,6 @@ Color Color::html(const String &p_color) {
}
bool Color::html_is_valid(const String &p_color) {
String color = p_color;
if (color.length() == 0)
@ -423,13 +401,11 @@ Color Color::named(const String &p_name) {
}
String _to_hex(float p_val) {
int v = Math::round(p_val * 255);
v = CLAMP(v, 0, 255);
String ret;
for (int i = 0; i < 2; i++) {
CharType c[2] = { 0, 0 };
int lv = v & 0xF;
if (lv < 10)
@ -446,7 +422,6 @@ String _to_hex(float p_val) {
}
String Color::to_html(bool p_alpha) const {
String txt;
txt += _to_hex(r);
txt += _to_hex(g);
@ -464,18 +439,15 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
// FIXME: Remove once Godot 3.1 has been released
float Color::gray() const {
WARN_DEPRECATED_MSG("'Color.gray()' is deprecated and will be removed in a future version. Use 'Color.v' for a better grayscale approximation.");
return (r + g + b) / 3.0;
}
Color::operator String() const {
return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a);
}
Color Color::operator+(const Color &p_color) const {
return Color(
r + p_color.r,
g + p_color.g,
@ -484,7 +456,6 @@ Color Color::operator+(const Color &p_color) const {
}
void Color::operator+=(const Color &p_color) {
r = r + p_color.r;
g = g + p_color.g;
b = b + p_color.b;
@ -492,7 +463,6 @@ void Color::operator+=(const Color &p_color) {
}
Color Color::operator-(const Color &p_color) const {
return Color(
r - p_color.r,
g - p_color.g,
@ -501,7 +471,6 @@ Color Color::operator-(const Color &p_color) const {
}
void Color::operator-=(const Color &p_color) {
r = r - p_color.r;
g = g - p_color.g;
b = b - p_color.b;
@ -509,7 +478,6 @@ void Color::operator-=(const Color &p_color) {
}
Color Color::operator*(const Color &p_color) const {
return Color(
r * p_color.r,
g * p_color.g,
@ -518,7 +486,6 @@ Color Color::operator*(const Color &p_color) const {
}
Color Color::operator*(const real_t &rvalue) const {
return Color(
r * rvalue,
g * rvalue,
@ -527,7 +494,6 @@ Color Color::operator*(const real_t &rvalue) const {
}
void Color::operator*=(const Color &p_color) {
r = r * p_color.r;
g = g * p_color.g;
b = b * p_color.b;
@ -535,7 +501,6 @@ void Color::operator*=(const Color &p_color) {
}
void Color::operator*=(const real_t &rvalue) {
r = r * rvalue;
g = g * rvalue;
b = b * rvalue;
@ -543,7 +508,6 @@ void Color::operator*=(const real_t &rvalue) {
}
Color Color::operator/(const Color &p_color) const {
return Color(
r / p_color.r,
g / p_color.g,
@ -552,7 +516,6 @@ Color Color::operator/(const Color &p_color) const {
}
Color Color::operator/(const real_t &rvalue) const {
return Color(
r / rvalue,
g / rvalue,
@ -561,7 +524,6 @@ Color Color::operator/(const real_t &rvalue) const {
}
void Color::operator/=(const Color &p_color) {
r = r / p_color.r;
g = g / p_color.g;
b = b / p_color.b;
@ -569,7 +531,6 @@ void Color::operator/=(const Color &p_color) {
}
void Color::operator/=(const real_t &rvalue) {
if (rvalue == 0) {
r = 1.0;
g = 1.0;
@ -584,7 +545,6 @@ void Color::operator/=(const real_t &rvalue) {
};
Color Color::operator-() const {
return Color(
1.0 - r,
1.0 - g,

View file

@ -35,9 +35,7 @@
#include "core/ustring.h"
struct Color {
union {
struct {
float r;
float g;
@ -94,7 +92,6 @@ struct Color {
Color contrasted() const;
_FORCE_INLINE_ Color linear_interpolate(const Color &p_to, float p_weight) const {
Color res = *this;
res.r += (p_weight * (p_to.r - r));
@ -106,7 +103,6 @@ struct Color {
}
_FORCE_INLINE_ Color darkened(float p_amount) const {
Color res = *this;
res.r = res.r * (1.0f - p_amount);
res.g = res.g * (1.0f - p_amount);
@ -115,7 +111,6 @@ struct Color {
}
_FORCE_INLINE_ Color lightened(float p_amount) const {
Color res = *this;
res.r = res.r + (1.0f - res.r) * p_amount;
res.g = res.g + (1.0f - res.g) * p_amount;
@ -124,7 +119,6 @@ struct Color {
}
_FORCE_INLINE_ uint32_t to_rgbe9995() const {
const float pow2to9 = 512.0f;
const float B = 15.0f;
//const float Emax = 31.0f;
@ -158,7 +152,6 @@ struct Color {
}
_FORCE_INLINE_ Color blend(const Color &p_over) const {
Color res;
float sa = 1.0 - p_over.a;
res.a = a * sa + p_over.a;
@ -173,7 +166,6 @@ struct Color {
}
_FORCE_INLINE_ Color to_linear() const {
return Color(
r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
@ -181,7 +173,6 @@ struct Color {
a);
}
_FORCE_INLINE_ Color to_srgb() const {
return Color(
r < 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math::pow(r, 1.0f / 2.4f) - 0.055,
g < 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math::pow(g, 1.0f / 2.4f) - 0.055,
@ -222,7 +213,6 @@ struct Color {
};
bool Color::operator<(const Color &p_color) const {
if (r == p_color.r) {
if (g == p_color.g) {
if (b == p_color.b) {

View file

@ -34,30 +34,24 @@
#include "core/project_settings.h"
void CommandQueueMT::lock() {
mutex.lock();
}
void CommandQueueMT::unlock() {
mutex.unlock();
}
void CommandQueueMT::wait_for_flush() {
// wait one millisecond for a flush to happen
OS::get_singleton()->delay_usec(1000);
}
CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() {
int idx = -1;
while (true) {
lock();
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
if (!sync_sems[i].in_use) {
sync_sems[i].in_use = true;
idx = i;
@ -101,7 +95,6 @@ tryagain:
}
CommandQueueMT::CommandQueueMT(bool p_sync) {
read_ptr_and_epoch = 0;
write_ptr_and_epoch = 0;
dealloc_ptr = 0;
@ -112,7 +105,6 @@ CommandQueueMT::CommandQueueMT(bool p_sync) {
command_mem = (uint8_t *)memalloc(command_mem_size);
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
sync_sems[i].in_use = false;
}
if (p_sync) {
@ -123,7 +115,6 @@ CommandQueueMT::CommandQueueMT(bool p_sync) {
}
CommandQueueMT::~CommandQueueMT() {
if (sync)
memdelete(sync);
memfree(command_mem);

View file

@ -277,22 +277,18 @@
#define MAX_CMD_PARAMS 13
class CommandQueueMT {
struct SyncSemaphore {
Semaphore sem;
bool in_use;
};
struct CommandBase {
virtual void call() = 0;
virtual void post(){};
virtual ~CommandBase(){};
};
struct SyncCommand : public CommandBase {
SyncSemaphore *sync_sem;
virtual void post() {
@ -329,7 +325,6 @@ class CommandQueueMT {
template <class T>
T *allocate() {
// alloc size is size+T+safeguard
uint32_t alloc_size = ((sizeof(T) + 8 - 1) & ~(8 - 1)) + 8;
@ -342,7 +337,6 @@ class CommandQueueMT {
if (write_ptr < dealloc_ptr) {
// behind dealloc_ptr, check that there is room
if ((dealloc_ptr - write_ptr) <= alloc_size) {
// There is no more room, try to deallocate something
if (dealloc_one()) {
goto tryagain;
@ -395,12 +389,10 @@ class CommandQueueMT {
template <class T>
T *allocate_and_lock() {
lock();
T *ret;
while ((ret = allocate<T>()) == NULL) {
unlock();
// sleep a little until fetch happened and some room is made
wait_for_flush();
@ -482,7 +474,6 @@ public:
}
void flush_all() {
//ERR_FAIL_COND(sync);
lock();
while (flush_one(false))

View file

@ -37,7 +37,6 @@ extern "C" {
}
struct _PHashTranslationCmp {
int orig_len;
CharString compressed;
int offset;
@ -66,7 +65,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
int total_string_size = 0;
for (List<StringName>::Element *E = keys.front(); E; E = E->next()) {
//hash string
CharString cs = E->get().operator String().utf8();
uint32_t h = hash(0, cs.get_data());
@ -109,7 +107,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
int bucket_table_size = 0;
for (int i = 0; i < size; i++) {
const Vector<Pair<int, CharString>> &b = buckets[i];
Map<uint32_t, int> &t = table.write[i];
@ -120,10 +117,8 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
int item = 0;
while (item < b.size()) {
uint32_t slot = hash(d, b[item].second.get_data());
if (t.has(slot)) {
item = 0;
d++;
t.clear();
@ -152,7 +147,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
int collisions = 0;
for (int i = 0; i < size; i++) {
const Map<uint32_t, int> &t = table[i];
if (t.size() == 0) {
htw[i] = 0xFFFFFFFF; //nothing
@ -166,7 +160,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
btw[btindex++] = hfunc_table[i];
for (Map<uint32_t, int>::Element *E = t.front(); E; E = E->next()) {
btw[btindex++] = E->key();
btw[btindex++] = compressed[E->get()].offset;
btw[btindex++] = compressed[E->get()].compressed.size();
@ -188,7 +181,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
}
bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name.operator String();
if (name == "hash_table") {
hash_table = p_value;
@ -205,7 +197,6 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
}
bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name.operator String();
if (name == "hash_table")
r_ret = hash_table;
@ -220,7 +211,6 @@ bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
}
StringName PHashTranslation::get_message(const StringName &p_src_text) const {
int htsize = hash_table.size();
if (htsize == 0)
@ -249,9 +239,7 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
int idx = -1;
for (int i = 0; i < bucket.size; i++) {
if (bucket.elem[i].key == h) {
idx = i;
break;
}
@ -262,13 +250,11 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
}
if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) {
String rstr;
rstr.parse_utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size);
return rstr;
} else {
CharString uncomp;
uncomp.resize(bucket.elem[idx].uncomp_size + 1);
smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size);
@ -279,14 +265,12 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
}
void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::POOL_INT_ARRAY, "hash_table"));
p_list->push_back(PropertyInfo(Variant::POOL_INT_ARRAY, "bucket_table"));
p_list->push_back(PropertyInfo(Variant::POOL_BYTE_ARRAY, "strings"));
p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR));
}
void PHashTranslation::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate);
}

View file

@ -34,7 +34,6 @@
#include "core/translation.h"
class PHashTranslation : public Translation {
GDCLASS(PHashTranslation, Translation);
//this translation uses a sort of modified perfect hash algorithm
@ -48,12 +47,10 @@ class PHashTranslation : public Translation {
PoolVector<uint8_t> strings;
struct Bucket {
int size;
uint32_t func;
struct Elem {
uint32_t key;
uint32_t str_offset;
uint32_t comp_size;
@ -64,11 +61,9 @@ class PHashTranslation : public Translation {
};
_FORCE_INLINE_ uint32_t hash(uint32_t d, const char *p_str) const {
if (d == 0)
d = 0x1000193;
while (*p_str) {
d = (d * 0x1000193) ^ uint32_t(*p_str);
p_str++;
}

View file

@ -34,7 +34,6 @@
#include "core/string_name.h"
class CoreStringNames {
friend void register_core_types();
friend void unregister_core_types();

View file

@ -63,7 +63,6 @@ private:
// internal helpers
_FORCE_INLINE_ SafeNumeric<uint32_t> *_get_refcount() const {
if (!_ptr)
return NULL;
@ -71,7 +70,6 @@ private:
}
_FORCE_INLINE_ uint32_t *_get_size() const {
if (!_ptr)
return NULL;
@ -79,7 +77,6 @@ private:
}
_FORCE_INLINE_ T *_get_data() const {
if (!_ptr)
return NULL;
return reinterpret_cast<T *>(_ptr);
@ -139,21 +136,18 @@ public:
_FORCE_INLINE_ bool empty() const { return _ptr == 0; }
_FORCE_INLINE_ void set(int p_index, const T &p_elem) {
CRASH_BAD_INDEX(p_index, size());
_copy_on_write();
_get_data()[p_index] = p_elem;
}
_FORCE_INLINE_ T &get_m(int p_index) {
CRASH_BAD_INDEX(p_index, size());
_copy_on_write();
return _get_data()[p_index];
}
_FORCE_INLINE_ const T &get(int p_index) const {
CRASH_BAD_INDEX(p_index, size());
return _get_data()[p_index];
@ -162,12 +156,10 @@ public:
Error resize(int p_size);
_FORCE_INLINE_ void remove(int p_index) {
ERR_FAIL_INDEX(p_index, size());
T *p = ptrw();
int len = size();
for (int i = p_index; i < len - 1; i++) {
p[i] = p[i + 1];
};
@ -175,7 +167,6 @@ public:
};
Error insert(int p_pos, const T &p_val) {
ERR_FAIL_INDEX_V(p_pos, size() + 1, ERR_INVALID_PARAMETER);
resize(size() + 1);
for (int i = (size() - 1); i > p_pos; i--)
@ -194,7 +185,6 @@ public:
template <class T>
void CowData<T>::_unref(void *p_data) {
if (!p_data)
return;
@ -220,7 +210,6 @@ void CowData<T>::_unref(void *p_data) {
template <class T>
uint32_t CowData<T>::_copy_on_write() {
if (!_ptr)
return 0;
@ -258,7 +247,6 @@ uint32_t CowData<T>::_copy_on_write() {
template <class T>
Error CowData<T>::resize(int p_size) {
ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER);
int current_size = size();
@ -281,7 +269,6 @@ Error CowData<T>::resize(int p_size) {
ERR_FAIL_COND_V(!_get_alloc_size_checked(p_size, &alloc_size), ERR_OUT_OF_MEMORY);
if (p_size > current_size) {
if (alloc_size != current_alloc_size) {
if (current_size == 0) {
// alloc from scratch
@ -314,7 +301,6 @@ Error CowData<T>::resize(int p_size) {
*_get_size() = p_size;
} else if (p_size < current_size) {
if (!__has_trivial_destructor(T)) {
// deinitialize no longer needed elements
for (uint32_t i = p_size; i < *_get_size(); i++) {
@ -362,7 +348,6 @@ void CowData<T>::_ref(const CowData *p_from) {
template <class T>
void CowData<T>::_ref(const CowData &p_from) {
if (_ptr == p_from._ptr)
return; // self assign, do nothing.
@ -379,13 +364,11 @@ void CowData<T>::_ref(const CowData &p_from) {
template <class T>
CowData<T>::CowData() {
_ptr = NULL;
}
template <class T>
CowData<T>::~CowData() {
_unref(_ptr);
}

View file

@ -74,7 +74,6 @@ Crypto *Crypto::create() {
}
void Crypto::load_default_certificates(String p_path) {
if (_load_default_certificates)
_load_default_certificates(p_path);
}
@ -95,7 +94,6 @@ Crypto::Crypto() {
/// Resource loader/saver
RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error) {
String el = p_path.get_extension().to_lower();
if (el == "crt") {
X509Certificate *cert = X509Certificate::create();
@ -117,19 +115,16 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi
}
void ResourceFormatLoaderCrypto::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("crt");
p_extensions->push_back("key");
p_extensions->push_back("pub");
}
bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const {
return p_type == "X509Certificate" || p_type == "CryptoKey";
}
String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "crt")
return "X509Certificate";
@ -139,7 +134,6 @@ String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const
}
Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Error err;
Ref<X509Certificate> cert = p_resource;
Ref<CryptoKey> key = p_resource;
@ -156,7 +150,6 @@ Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resourc
}
void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
const X509Certificate *cert = Object::cast_to<X509Certificate>(*p_resource);
const CryptoKey *key = Object::cast_to<CryptoKey>(*p_resource);
if (cert) {
@ -170,6 +163,5 @@ void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource,
}
}
bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const {
return Object::cast_to<X509Certificate>(*p_resource) || Object::cast_to<CryptoKey>(*p_resource);
}

View file

@ -34,10 +34,8 @@
#include "core/reference.h"
class CryptoCore {
public:
class MD5Context {
private:
void *ctx; // To include, or not to include...
@ -51,7 +49,6 @@ public:
};
class SHA1Context {
private:
void *ctx; // To include, or not to include...
@ -65,7 +62,6 @@ public:
};
class SHA256Context {
private:
void *ctx; // To include, or not to include...
@ -79,7 +75,6 @@ public:
};
class AESContext {
private:
void *ctx; // To include, or not to include...

View file

@ -104,7 +104,6 @@ void HashingContext::_create_ctx(HashType p_type) {
}
void HashingContext::_delete_ctx() {
switch (type) {
case HASH_MD5:
memdelete((CryptoCore::MD5Context *)ctx);

View file

@ -35,13 +35,11 @@
#include "core/variant.h"
struct DictionaryPrivate {
SafeRefCount refcount;
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> variant_map;
};
void Dictionary::get_key_list(List<Variant> *p_keys) const {
if (_p->variant_map.empty())
return;
@ -51,7 +49,6 @@ void Dictionary::get_key_list(List<Variant> *p_keys) const {
}
Variant Dictionary::get_key_at_index(int p_index) const {
int index = 0;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
if (index == p_index) {
@ -64,7 +61,6 @@ Variant Dictionary::get_key_at_index(int p_index) const {
}
Variant Dictionary::get_value_at_index(int p_index) const {
int index = 0;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
if (index == p_index) {
@ -77,16 +73,13 @@ Variant Dictionary::get_value_at_index(int p_index) const {
}
Variant &Dictionary::operator[](const Variant &p_key) {
return _p->variant_map[p_key];
}
const Variant &Dictionary::operator[](const Variant &p_key) const {
return _p->variant_map[p_key];
}
const Variant *Dictionary::getptr(const Variant &p_key) const {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key);
if (!E)
@ -95,7 +88,6 @@ const Variant *Dictionary::getptr(const Variant &p_key) const {
}
Variant *Dictionary::getptr(const Variant &p_key) {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(p_key);
if (!E)
@ -104,7 +96,6 @@ Variant *Dictionary::getptr(const Variant &p_key) {
}
Variant Dictionary::get_valid(const Variant &p_key) const {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key);
if (!E)
@ -122,16 +113,13 @@ Variant Dictionary::get(const Variant &p_key, const Variant &p_default) const {
}
int Dictionary::size() const {
return _p->variant_map.size();
}
bool Dictionary::empty() const {
return !_p->variant_map.size();
}
bool Dictionary::has(const Variant &p_key) const {
return _p->variant_map.has(p_key);
}
@ -145,22 +133,18 @@ bool Dictionary::has_all(const Array &p_keys) const {
}
bool Dictionary::erase(const Variant &p_key) {
return _p->variant_map.erase(p_key);
}
bool Dictionary::operator==(const Dictionary &p_dictionary) const {
return _p == p_dictionary._p;
}
bool Dictionary::operator!=(const Dictionary &p_dictionary) const {
return _p != p_dictionary._p;
}
void Dictionary::_ref(const Dictionary &p_from) const {
//make a copy first (thread safe)
if (!p_from._p->refcount.ref())
return; // couldn't copy
@ -176,12 +160,10 @@ void Dictionary::_ref(const Dictionary &p_from) const {
}
void Dictionary::clear() {
_p->variant_map.clear();
}
void Dictionary::_unref() const {
ERR_FAIL_COND(!_p);
if (_p->refcount.unref()) {
memdelete(_p);
@ -189,7 +171,6 @@ void Dictionary::_unref() const {
_p = NULL;
}
uint32_t Dictionary::hash() const {
uint32_t h = hash_djb2_one_32(Variant::DICTIONARY);
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
@ -201,7 +182,6 @@ uint32_t Dictionary::hash() const {
}
Array Dictionary::keys() const {
Array varr;
if (_p->variant_map.empty())
return varr;
@ -218,7 +198,6 @@ Array Dictionary::keys() const {
}
Array Dictionary::values() const {
Array varr;
if (_p->variant_map.empty())
return varr;
@ -235,7 +214,6 @@ Array Dictionary::values() const {
}
const Variant *Dictionary::next(const Variant *p_key) const {
if (p_key == NULL) {
// caller wants to get the first element
if (_p->variant_map.front())
@ -250,7 +228,6 @@ const Variant *Dictionary::next(const Variant *p_key) const {
}
Dictionary Dictionary::duplicate(bool p_deep) const {
Dictionary n;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
@ -261,7 +238,6 @@ Dictionary Dictionary::duplicate(bool p_deep) const {
}
void Dictionary::operator=(const Dictionary &p_dictionary) {
_ref(p_dictionary);
}
@ -275,11 +251,9 @@ Dictionary::Dictionary(const Dictionary &p_from) {
}
Dictionary::Dictionary() {
_p = memnew(DictionaryPrivate);
_p->refcount.init();
}
Dictionary::~Dictionary() {
_unref();
}

View file

@ -40,7 +40,6 @@ class Variant;
struct DictionaryPrivate;
class Dictionary {
mutable DictionaryPrivate *_p;
void _ref(const Dictionary &p_from) const;

View file

@ -37,12 +37,10 @@
#include "core/version_hash.gen.h"
void Engine::set_iterations_per_second(int p_ips) {
ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0.");
ips = p_ips;
}
int Engine::get_iterations_per_second() const {
return ips;
}
@ -65,32 +63,26 @@ int Engine::get_target_fps() const {
}
uint64_t Engine::get_frames_drawn() {
return frames_drawn;
}
void Engine::set_frame_delay(uint32_t p_msec) {
_frame_delay = p_msec;
}
uint32_t Engine::get_frame_delay() const {
return _frame_delay;
}
void Engine::set_time_scale(float p_scale) {
_time_scale = p_scale;
}
float Engine::get_time_scale() const {
return _time_scale;
}
Dictionary Engine::get_version_info() const {
Dictionary dict;
dict["major"] = VERSION_MAJOR;
dict["minor"] = VERSION_MINOR;
@ -187,25 +179,21 @@ String Engine::get_license_text() const {
}
void Engine::add_singleton(const Singleton &p_singleton) {
singletons.push_back(p_singleton);
singleton_ptrs[p_singleton.name] = p_singleton.ptr;
}
Object *Engine::get_singleton_object(const String &p_name) const {
const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
ERR_FAIL_COND_V_MSG(!E, NULL, "Failed to retrieve non-existent singleton '" + p_name + "'.");
return E->get();
};
bool Engine::has_singleton(const String &p_name) const {
return singleton_ptrs.has(p_name);
};
void Engine::get_singletons(List<Singleton> *p_singletons) {
for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
p_singletons->push_back(E->get());
}
@ -217,7 +205,6 @@ Engine *Engine::get_singleton() {
}
Engine::Engine() {
singleton = this;
frames_drawn = 0;
ips = 60;

View file

@ -37,7 +37,6 @@
#include "core/vector.h"
class Engine {
public:
struct Singleton {
StringName name;

View file

@ -37,7 +37,6 @@
static ErrorHandlerList *error_handler_list = NULL;
void add_error_handler(ErrorHandlerList *p_handler) {
_global_lock();
p_handler->next = error_handler_list;
error_handler_list = p_handler;
@ -45,16 +44,13 @@ void add_error_handler(ErrorHandlerList *p_handler) {
}
void remove_error_handler(ErrorHandlerList *p_handler) {
_global_lock();
ErrorHandlerList *prev = NULL;
ErrorHandlerList *l = error_handler_list;
while (l) {
if (l == p_handler) {
if (prev)
prev->next = l->next;
else
@ -77,13 +73,11 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type) {
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, (Logger::ErrorType)p_type);
_global_lock();
ErrorHandlerList *l = error_handler_list;
while (l) {
l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_type);
l = l->next;
}
@ -104,7 +98,6 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
}
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool fatal) {
String fstr(fatal ? "FATAL: " : "");
String err(fstr + "Index " + p_index_str + " = " + itos(p_index) + " is out of bounds (" + p_size_str + " = " + itos(p_size) + ").");
_err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message);

View file

@ -61,7 +61,6 @@ class String;
typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
struct ErrorHandlerList {
ErrorHandlerFunc errfunc;
void *userdata;

View file

@ -31,7 +31,6 @@
#include "func_ref.h"
Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
if (id == 0) {
r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
return Variant();
@ -47,7 +46,6 @@ Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Variant::Call
}
Variant FuncRef::call_funcv(const Array &p_args) {
ERR_FAIL_COND_V(id == 0, Variant());
Object *obj = ObjectDB::get_instance(id);
@ -58,13 +56,11 @@ Variant FuncRef::call_funcv(const Array &p_args) {
}
void FuncRef::set_instance(Object *p_obj) {
ERR_FAIL_NULL(p_obj);
id = p_obj->get_instance_id();
}
void FuncRef::set_function(const StringName &p_func) {
function = p_func;
}
@ -84,7 +80,6 @@ bool FuncRef::is_valid() const {
}
void FuncRef::_bind_methods() {
{
MethodInfo mi;
mi.name = "call_func";

View file

@ -34,7 +34,6 @@
#include "core/reference.h"
class FuncRef : public Reference {
GDCLASS(FuncRef, Reference);
ObjectID id;
StringName function;

View file

@ -36,7 +36,6 @@
#include "core/variant.h"
struct _GlobalConstant {
#ifdef DEBUG_METHODS_ENABLED
StringName enum_name;
#endif
@ -92,7 +91,6 @@ VARIANT_ENUM_CAST(JoystickList);
VARIANT_ENUM_CAST(MidiMessageList);
void register_global_constants() {
//{ KEY_BACKSPACE, VK_BACK },// (0x08) // backspace
BIND_GLOBAL_ENUM_CONSTANT(MARGIN_LEFT);
@ -667,33 +665,27 @@ void register_global_constants() {
}
void unregister_global_constants() {
_global_constants.clear();
}
int GlobalConstants::get_global_constant_count() {
return _global_constants.size();
}
#ifdef DEBUG_METHODS_ENABLED
StringName GlobalConstants::get_global_constant_enum(int p_idx) {
return _global_constants[p_idx].enum_name;
}
#else
StringName GlobalConstants::get_global_constant_enum(int p_idx) {
return StringName();
}
#endif
const char *GlobalConstants::get_global_constant_name(int p_idx) {
return _global_constants[p_idx].name;
}
int GlobalConstants::get_global_constant_value(int p_idx) {
return _global_constants[p_idx].value;
}

View file

@ -59,7 +59,6 @@ template <class TKey, class TData, class Hasher = HashMapHasherDefault, class Co
class HashMap {
public:
struct Pair {
TKey key;
TData data;
@ -99,7 +98,6 @@ private:
uint32_t elements;
void make_hash_table() {
ERR_FAIL_COND(hash_table);
hash_table = memnew_arr(Element *, (1 << MIN_HASH_TABLE_POWER));
@ -111,7 +109,6 @@ private:
}
void erase_hash_table() {
ERR_FAIL_COND_MSG(elements, "Cannot erase hash table if there are still elements inside.");
memdelete_arr(hash_table);
@ -121,7 +118,6 @@ private:
}
void check_hash_table() {
int new_hash_table_power = -1;
if ((int)elements > ((1 << hash_table_power) * RELATIONSHIP)) {
@ -129,17 +125,14 @@ private:
new_hash_table_power = hash_table_power + 1;
while ((int)elements > ((1 << new_hash_table_power) * RELATIONSHIP)) {
new_hash_table_power++;
}
} else if ((hash_table_power > (int)MIN_HASH_TABLE_POWER) && ((int)elements < ((1 << (hash_table_power - 1)) * RELATIONSHIP))) {
/* rehash down */
new_hash_table_power = hash_table_power - 1;
while ((int)elements < ((1 << (new_hash_table_power - 1)) * RELATIONSHIP)) {
new_hash_table_power--;
}
@ -154,15 +147,12 @@ private:
ERR_FAIL_COND_MSG(!new_hash_table, "Out of memory.");
for (int i = 0; i < (1 << new_hash_table_power); i++) {
new_hash_table[i] = 0;
}
if (hash_table) {
for (int i = 0; i < (1 << hash_table_power); i++) {
while (hash_table[i]) {
Element *se = hash_table[i];
hash_table[i] = se->next;
int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
@ -179,17 +169,14 @@ private:
/* I want to have only one function.. */
_FORCE_INLINE_ const Element *get_element(const TKey &p_key) const {
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
Element *e = hash_table[index];
while (e) {
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) {
/* the pair exists in this hashtable, so just update data */
return e;
}
@ -201,7 +188,6 @@ private:
}
Element *create_element(const TKey &p_key) {
/* if element doesn't exist, create it */
Element *e = memnew(Element);
ERR_FAIL_COND_V_MSG(!e, NULL, "Out of memory.");
@ -219,7 +205,6 @@ private:
}
void copy_from(const HashMap &p_t) {
if (&p_t == this)
return; /* much less bother with that */
@ -233,13 +218,11 @@ private:
elements = p_t.elements;
for (int i = 0; i < (1 << p_t.hash_table_power); i++) {
hash_table[i] = NULL;
const Element *e = p_t.hash_table[i];
while (e) {
Element *le = memnew(Element); /* local element */
*le = *e; /* copy data */
@ -259,7 +242,6 @@ public:
}
Element *set(const Pair &p_pair) {
Element *e = NULL;
if (!hash_table)
make_hash_table(); // if no table, make one
@ -269,7 +251,6 @@ public:
/* if we made it up to here, the pair doesn't exist, create and assign */
if (!e) {
e = create_element(p_pair.key);
if (!e)
return NULL;
@ -281,7 +262,6 @@ public:
}
bool has(const TKey &p_key) const {
return getptr(p_key) != NULL;
}
@ -292,14 +272,12 @@ public:
*/
const TData &get(const TKey &p_key) const {
const TData *res = getptr(p_key);
CRASH_COND_MSG(!res, "Map key not found.");
return *res;
}
TData &get(const TKey &p_key) {
TData *res = getptr(p_key);
CRASH_COND_MSG(!res, "Map key not found.");
return *res;
@ -311,7 +289,6 @@ public:
*/
_FORCE_INLINE_ TData *getptr(const TKey &p_key) {
if (unlikely(!hash_table))
return NULL;
@ -324,7 +301,6 @@ public:
}
_FORCE_INLINE_ const TData *getptr(const TKey &p_key) const {
if (unlikely(!hash_table))
return NULL;
@ -343,7 +319,6 @@ public:
template <class C>
_FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) {
if (unlikely(!hash_table))
return NULL;
@ -353,10 +328,8 @@ public:
Element *e = hash_table[index];
while (e) {
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) {
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
}
@ -369,7 +342,6 @@ public:
template <class C>
_FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const {
if (unlikely(!hash_table))
return NULL;
@ -379,10 +351,8 @@ public:
const Element *e = hash_table[index];
while (e) {
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) {
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
}
@ -398,7 +368,6 @@ public:
*/
bool erase(const TKey &p_key) {
if (unlikely(!hash_table))
return false;
@ -408,12 +377,9 @@ public:
Element *e = hash_table[index];
Element *p = NULL;
while (e) {
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) {
if (p) {
p->next = e->next;
} else {
//begin of list
@ -451,7 +417,6 @@ public:
/* if we made it up to here, the pair doesn't exist, create */
if (!e) {
e = create_element(p_key);
CRASH_COND(!e);
check_hash_table(); // perform mantenience routine
@ -476,14 +441,12 @@ public:
*
*/
const TKey *next(const TKey *p_key) const {
if (unlikely(!hash_table))
return NULL;
if (!p_key) { /* get the first key */
for (int i = 0; i < (1 << hash_table_power); i++) {
if (hash_table[i]) {
return &hash_table[i]->pair.key;
}
@ -501,7 +464,6 @@ public:
uint32_t index = e->hash & ((1 << hash_table_power) - 1);
index++;
for (int i = index; i < (1 << hash_table_power); i++) {
if (hash_table[i]) {
return &hash_table[i]->pair.key;
}
@ -515,23 +477,18 @@ public:
}
inline unsigned int size() const {
return elements;
}
inline bool empty() const {
return elements == 0;
}
void clear() {
/* clean up */
if (hash_table) {
for (int i = 0; i < (1 << hash_table_power); i++) {
while (hash_table[i]) {
Element *e = hash_table[i];
hash_table[i] = e->next;
memdelete(e);
@ -547,7 +504,6 @@ public:
}
void operator=(const HashMap &p_table) {
copy_from(p_table);
}
@ -561,7 +517,6 @@ public:
if (unlikely(!hash_table))
return;
for (int i = 0; i < (1 << hash_table_power); i++) {
Element *e = hash_table[i];
while (e) {
*p_pairs = &e->pair;
@ -575,7 +530,6 @@ public:
if (unlikely(!hash_table))
return;
for (int i = 0; i < (1 << hash_table_power); i++) {
Element *e = hash_table[i];
while (e) {
p_keys->push_back(e->pair.key);
@ -585,7 +539,6 @@ public:
}
HashMap(const HashMap &p_table) {
hash_table = NULL;
elements = 0;
hash_table_power = 0;
@ -594,7 +547,6 @@ public:
}
~HashMap() {
clear();
}
};

View file

@ -48,7 +48,6 @@
* @return 32-bits hashcode
*/
static inline uint32_t hash_djb2(const char *p_cstr) {
const unsigned char *chr = (const unsigned char *)p_cstr;
uint32_t hash = 5381;
uint32_t c;
@ -60,7 +59,6 @@ static inline uint32_t hash_djb2(const char *p_cstr) {
}
static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32_t p_prev = 5381) {
uint32_t hash = p_prev;
for (int i = 0; i < p_len; i++)
@ -70,7 +68,6 @@ static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32
}
static inline uint32_t hash_djb2_one_32(uint32_t p_in, uint32_t p_prev = 5381) {
return ((p_prev << 5) + p_prev) + p_in;
}
@ -104,7 +101,6 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381)
template <class T>
static inline uint32_t make_uint32_t(T p_in) {
union {
T t;
uint32_t _u32;
@ -115,13 +111,11 @@ static inline uint32_t make_uint32_t(T p_in) {
}
static inline uint64_t hash_djb2_one_64(uint64_t p_in, uint64_t p_prev = 5381) {
return ((p_prev << 5) + p_prev) + p_in;
}
template <class T>
static inline uint64_t make_uint64_t(T p_in) {
union {
T t;
uint64_t _u64;
@ -133,7 +127,6 @@ static inline uint64_t make_uint64_t(T p_in) {
}
struct HashMapHasherDefault {
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }

File diff suppressed because it is too large Load diff

View file

@ -39,7 +39,6 @@ InputMap *InputMap::singleton = NULL;
int InputMap::ALL_DEVICES = -1;
void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.5f));
@ -60,7 +59,6 @@ void InputMap::_bind_methods() {
* matching action name (if possible).
*/
String InputMap::_suggest_actions(const StringName &p_action) const {
List<StringName> actions = get_actions();
StringName closest_action;
float closest_similarity = 0.0;
@ -85,7 +83,6 @@ String InputMap::_suggest_actions(const StringName &p_action) const {
}
void InputMap::add_action(const StringName &p_action, float p_deadzone) {
ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action \"" + String(p_action) + "\".");
input_map[p_action] = Action();
static int last_id = 1;
@ -95,21 +92,18 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) {
}
void InputMap::erase_action(const StringName &p_action) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
input_map.erase(p_action);
}
Array InputMap::_get_actions() {
Array ret;
List<StringName> actions = get_actions();
if (actions.empty())
return ret;
for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) {
ret.push_back(E->get());
}
@ -117,7 +111,6 @@ Array InputMap::_get_actions() {
}
List<StringName> InputMap::get_actions() const {
List<StringName> actions = List<StringName>();
if (input_map.empty()) {
return actions;
@ -134,7 +127,6 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re
ERR_FAIL_COND_V(!p_event.is_valid(), NULL);
for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
const Ref<InputEvent> e = E->get();
//if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here?
@ -152,19 +144,16 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re
}
bool InputMap::has_action(const StringName &p_action) const {
return input_map.has(p_action);
}
void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
input_map[p_action].deadzone = p_deadzone;
}
void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object.");
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
@ -175,14 +164,12 @@ void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent
}
bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, _suggest_actions(p_action));
return (_find_event(input_map[p_action], p_event) != NULL);
}
void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event);
@ -195,19 +182,16 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve
}
void InputMap::action_erase_events(const StringName &p_action) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
input_map[p_action].inputs.clear();
}
Array InputMap::_get_action_list(const StringName &p_action) {
Array ret;
const List<Ref<InputEvent>> *al = get_action_list(p_action);
if (al) {
for (const List<Ref<InputEvent>>::Element *E = al->front(); E; E = E->next()) {
ret.push_back(E->get());
}
}
@ -216,7 +200,6 @@ Array InputMap::_get_action_list(const StringName &p_action) {
}
const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) {
const Map<StringName, Action>::Element *E = input_map.find(p_action);
if (!E)
return NULL;
@ -260,7 +243,6 @@ const Map<StringName, InputMap::Action> &InputMap::get_action_map() const {
}
void InputMap::load_from_globals() {
input_map.clear();
List<PropertyInfo> pinfo;
@ -289,7 +271,6 @@ void InputMap::load_from_globals() {
}
void InputMap::load_default() {
Ref<InputEventKey> key;
add_action("ui_accept");
@ -368,7 +349,6 @@ void InputMap::load_default() {
}
InputMap::InputMap() {
ERR_FAIL_COND_MSG(singleton, "Singleton in InputMap already exist.");
singleton = this;
}

View file

@ -35,7 +35,6 @@
#include "core/os/input_event.h"
class InputMap : public Object {
GDCLASS(InputMap, Object);
public:

View file

@ -39,10 +39,8 @@
#include <zstd.h>
int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) {
switch (p_mode) {
case MODE_FASTLZ: {
if (p_src_size < 16) {
uint8_t src[16];
memset(&src[p_src_size], 0, 16 - p_src_size);
@ -55,7 +53,6 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@ -96,10 +93,8 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
}
int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
switch (p_mode) {
case MODE_FASTLZ: {
int ss = p_src_size + p_src_size * 6 / 100;
if (ss < 66)
ss = 66;
@ -108,7 +103,6 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@ -123,7 +117,6 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
return aout;
} break;
case MODE_ZSTD: {
return ZSTD_compressBound(p_src_size);
} break;
}
@ -132,10 +125,8 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
}
int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode) {
switch (p_mode) {
case MODE_FASTLZ: {
int ret_size = 0;
if (p_dst_max_size < 16) {
@ -149,7 +140,6 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;

View file

@ -34,7 +34,6 @@
#include "core/typedefs.h"
class Compression {
public:
static int zlib_level;
static int gzip_level;

View file

@ -35,14 +35,12 @@
#include "core/variant_parser.h"
PoolStringArray ConfigFile::_get_sections() const {
List<String> s;
get_sections(&s);
PoolStringArray arr;
arr.resize(s.size());
int idx = 0;
for (const List<String>::Element *E = s.front(); E; E = E->next()) {
arr.set(idx++, E->get());
}
@ -50,14 +48,12 @@ PoolStringArray ConfigFile::_get_sections() const {
}
PoolStringArray ConfigFile::_get_section_keys(const String &p_section) const {
List<String> s;
get_section_keys(p_section, &s);
PoolStringArray arr;
arr.resize(s.size());
int idx = 0;
for (const List<String>::Element *E = s.front(); E; E = E->next()) {
arr.set(idx++, E->get());
}
@ -65,7 +61,6 @@ PoolStringArray ConfigFile::_get_section_keys(const String &p_section) const {
}
void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) {
if (p_value.get_type() == Variant::NIL) {
//erase
if (!values.has(p_section))
@ -84,7 +79,6 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V
}
}
Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const {
if (!values.has(p_section) || !values[p_section].has(p_key)) {
ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(),
vformat("Couldn't find the given section \"%s\" and key \"%s\", and no default was given.", p_section, p_key));
@ -94,24 +88,20 @@ Variant ConfigFile::get_value(const String &p_section, const String &p_key, Vari
}
bool ConfigFile::has_section(const String &p_section) const {
return values.has(p_section);
}
bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const {
if (!values.has(p_section))
return false;
return values[p_section].has(p_key);
}
void ConfigFile::get_sections(List<String> *r_sections) const {
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::ConstElement E = values.front(); E; E = E.next()) {
r_sections->push_back(E.key());
}
}
void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const {
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot get keys from nonexistent section \"%s\".", p_section));
for (OrderedHashMap<String, Variant>::ConstElement E = values[p_section].front(); E; E = E.next()) {
@ -120,13 +110,11 @@ void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys)
}
void ConfigFile::erase_section(const String &p_section) {
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase nonexistent section \"%s\".", p_section));
values.erase(p_section);
}
void ConfigFile::erase_section_key(const String &p_section, const String &p_key) {
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase key \"%s\" from nonexistent section \"%s\".", p_key, p_section));
ERR_FAIL_COND_MSG(!values[p_section].has(p_key), vformat("Cannot erase nonexistent key \"%s\" from section \"%s\".", p_key, p_section));
@ -134,7 +122,6 @@ void ConfigFile::erase_section_key(const String &p_section, const String &p_key)
}
Error ConfigFile::save(const String &p_path) {
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
@ -148,7 +135,6 @@ Error ConfigFile::save(const String &p_path) {
}
Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
@ -166,7 +152,6 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_
}
Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
@ -185,15 +170,12 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass
}
Error ConfigFile::_internal_save(FileAccess *file) {
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) {
if (E != values.front())
file->store_string("\n");
file->store_string("[" + E.key() + "]\n\n");
for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) {
String vstr;
VariantWriter::write_to_string(F.get(), vstr);
file->store_string(F.key() + "=" + vstr + "\n");
@ -206,7 +188,6 @@ Error ConfigFile::_internal_save(FileAccess *file) {
}
Error ConfigFile::load(const String &p_path) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@ -217,7 +198,6 @@ Error ConfigFile::load(const String &p_path) {
}
Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@ -235,7 +215,6 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_
}
Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@ -254,7 +233,6 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass
}
Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
VariantParser::StreamFile stream;
stream.f = f;
@ -266,14 +244,12 @@ Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
}
Error ConfigFile::parse(const String &p_data) {
VariantParser::StreamString stream;
stream.s = p_data;
return _parse("<string>", &stream);
}
Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) {
String assign;
Variant value;
VariantParser::Tag next_tag;
@ -284,7 +260,6 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
String section;
while (true) {
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@ -311,7 +286,6 @@ void ConfigFile::clear() {
values.clear();
}
void ConfigFile::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value);
ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant()));

View file

@ -37,7 +37,6 @@
#include "core/variant_parser.h"
class ConfigFile : public Reference {
GDCLASS(ConfigFile, Reference);
OrderedHashMap<String, OrderedHashMap<String, Variant>> values;

View file

@ -36,7 +36,6 @@ DTLSServer *(*DTLSServer::_create)() = NULL;
bool DTLSServer::available = false;
DTLSServer *DTLSServer::create() {
if (_create) {
return _create();
}
@ -48,7 +47,6 @@ bool DTLSServer::is_available() {
}
void DTLSServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("setup", "key", "certificate", "chain"), &DTLSServer::setup, DEFVAL(Ref<X509Certificate>()));
ClassDB::bind_method(D_METHOD("take_connection", "udp_peer"), &DTLSServer::take_connection);
}

View file

@ -33,7 +33,6 @@
#include "core/print_string.h"
void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) {
magic = p_magic.ascii().get_data();
if (magic.length() > 4)
magic = magic.substr(0, 4);
@ -59,7 +58,6 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_
}
Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
f = p_base;
cmode = (Compression::Mode)f->get_32();
block_size = f->get_32();
@ -72,7 +70,6 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
int acc_ofs = f->get_position() + bc * 4;
int max_bs = 0;
for (int i = 0; i < bc; i++) {
ReadBlock rb;
rb.offset = acc_ofs;
rb.csize = f->get_32();
@ -98,7 +95,6 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
}
Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(p_mode_flags == READ_WRITE, ERR_UNAVAILABLE);
if (f)
@ -114,7 +110,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
}
if (p_mode_flags & WRITE) {
buffer.clear();
writing = true;
write_pos = 0;
@ -125,7 +120,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
//don't store anything else unless it's done saving!
} else {
char rmagic[5];
f->get_buffer((uint8_t *)rmagic, 4);
rmagic[4] = 0;
@ -139,7 +133,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
return OK;
}
void FileAccessCompressed::close() {
if (!f)
return;
@ -159,7 +152,6 @@ void FileAccessCompressed::close() {
Vector<int> block_sizes;
for (int i = 0; i < bc; i++) {
int bl = i == (bc - 1) ? write_max % block_size : block_size;
uint8_t *bp = &write_ptr[i * block_size];
@ -180,7 +172,6 @@ void FileAccessCompressed::close() {
buffer.clear();
} else {
comp_buffer.clear();
buffer.clear();
read_blocks.clear();
@ -191,21 +182,17 @@ void FileAccessCompressed::close() {
}
bool FileAccessCompressed::is_open() const {
return f != NULL;
}
void FileAccessCompressed::seek(size_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
if (writing) {
ERR_FAIL_COND(p_position > write_max);
write_pos = p_position;
} else {
ERR_FAIL_COND(p_position > read_total);
if (p_position == read_total) {
at_end = true;
@ -214,7 +201,6 @@ void FileAccessCompressed::seek(size_t p_position) {
read_eof = false;
int block_idx = p_position / block_size;
if (block_idx != read_block) {
read_block = block_idx;
f->seek(read_blocks[read_block].offset);
f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
@ -228,32 +214,24 @@ void FileAccessCompressed::seek(size_t p_position) {
}
void FileAccessCompressed::seek_end(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
if (writing) {
seek(write_max + p_position);
} else {
seek(read_total + p_position);
}
}
size_t FileAccessCompressed::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) {
return write_pos;
} else {
return read_block * block_size + read_pos;
}
}
size_t FileAccessCompressed::get_len() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
if (writing) {
return write_max;
} else {
return read_total;
@ -261,7 +239,6 @@ size_t FileAccessCompressed::get_len() const {
}
bool FileAccessCompressed::eof_reached() const {
ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use.");
if (writing) {
return false;
@ -271,7 +248,6 @@ bool FileAccessCompressed::eof_reached() const {
}
uint8_t FileAccessCompressed::get_8() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
@ -313,7 +289,6 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
}
for (int i = 0; i < p_length; i++) {
p_dst[i] = read_ptr[read_pos];
read_pos++;
if (read_pos >= read_block_size) {
@ -340,7 +315,6 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessCompressed::get_error() const {
return read_eof ? ERR_FILE_EOF : OK;
}
@ -352,7 +326,6 @@ void FileAccessCompressed::flush() {
}
void FileAccessCompressed::store_8(uint8_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
@ -361,7 +334,6 @@ void FileAccessCompressed::store_8(uint8_t p_dest) {
}
bool FileAccessCompressed::file_exists(const String &p_name) {
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
if (!fa)
return false;
@ -370,7 +342,6 @@ bool FileAccessCompressed::file_exists(const String &p_name) {
}
uint64_t FileAccessCompressed::_get_modified_time(const String &p_file) {
if (f)
return f->get_modified_time(p_file);
else
@ -410,7 +381,6 @@ FileAccessCompressed::FileAccessCompressed() :
}
FileAccessCompressed::~FileAccessCompressed() {
if (f)
close();
}

View file

@ -35,7 +35,6 @@
#include "core/os/file_access.h"
class FileAccessCompressed : public FileAccess {
Compression::Mode cmode;
bool writing;
uint32_t write_pos;

View file

@ -39,7 +39,6 @@
#define COMP_MAGIC 0x43454447
Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode) {
ERR_FAIL_COND_V_MSG(file != NULL, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open.");
ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER);
@ -47,7 +46,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
eofed = false;
if (p_mode == MODE_WRITE_AES256) {
data.clear();
writing = true;
file = p_base;
@ -55,7 +53,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
key = p_key;
} else if (p_mode == MODE_READ) {
writing = false;
key = p_key;
uint32_t magic = p_base->get_32();
@ -84,7 +81,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
ctx.set_decode_key(key.ptrw(), 256);
for (size_t i = 0; i < ds; i += 16) {
ctx.decrypt_ecb(&data.write[i], &data.write[i]);
}
@ -102,13 +98,11 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
}
Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const String &p_key, Mode p_mode) {
String cs = p_key.md5_text();
ERR_FAIL_COND_V(cs.length() != 32, ERR_INVALID_PARAMETER);
Vector<uint8_t> key;
key.resize(32);
for (int i = 0; i < 32; i++) {
key.write[i] = cs[i];
}
@ -116,16 +110,13 @@ Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const Str
}
Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) {
return OK;
}
void FileAccessEncrypted::close() {
if (!file)
return;
if (writing) {
Vector<uint8_t> compressed;
size_t len = data.size();
if (len % 16) {
@ -145,7 +136,6 @@ void FileAccessEncrypted::close() {
ctx.set_encode_key(key.ptrw(), 256);
for (size_t i = 0; i < len; i += 16) {
ctx.encrypt_ecb(&compressed.write[i], &compressed.write[i]);
}
@ -162,7 +152,6 @@ void FileAccessEncrypted::close() {
data.clear();
} else {
file->close();
memdelete(file);
data.clear();
@ -171,12 +160,10 @@ void FileAccessEncrypted::close() {
}
bool FileAccessEncrypted::is_open() const {
return file != NULL;
}
String FileAccessEncrypted::get_path() const {
if (file)
return file->get_path();
else
@ -184,7 +171,6 @@ String FileAccessEncrypted::get_path() const {
}
String FileAccessEncrypted::get_path_absolute() const {
if (file)
return file->get_path_absolute();
else
@ -192,7 +178,6 @@ String FileAccessEncrypted::get_path_absolute() const {
}
void FileAccessEncrypted::seek(size_t p_position) {
if (p_position > (size_t)data.size())
p_position = data.size();
@ -201,25 +186,20 @@ void FileAccessEncrypted::seek(size_t p_position) {
}
void FileAccessEncrypted::seek_end(int64_t p_position) {
seek(data.size() + p_position);
}
size_t FileAccessEncrypted::get_position() const {
return pos;
}
size_t FileAccessEncrypted::get_len() const {
return data.size();
}
bool FileAccessEncrypted::eof_reached() const {
return eofed;
}
uint8_t FileAccessEncrypted::get_8() const {
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
if (pos >= data.size()) {
eofed = true;
@ -238,7 +218,6 @@ int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
int to_copy = MIN(p_length, data.size() - pos);
for (int i = 0; i < to_copy; i++) {
p_dst[i] = data[pos++];
}
@ -250,25 +229,19 @@ int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessEncrypted::get_error() const {
return eofed ? ERR_FILE_EOF : OK;
}
void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
if (pos < data.size()) {
for (int i = 0; i < p_length; i++) {
store_8(p_src[i]);
}
} else if (pos == data.size()) {
data.resize(pos + p_length);
for (int i = 0; i < p_length; i++) {
data.write[pos + i] = p_src[i];
}
pos += p_length;
@ -282,7 +255,6 @@ void FileAccessEncrypted::flush() {
}
void FileAccessEncrypted::store_8(uint8_t p_dest) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
if (pos < data.size()) {
@ -295,7 +267,6 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) {
}
bool FileAccessEncrypted::file_exists(const String &p_name) {
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
if (!fa)
return false;
@ -304,12 +275,10 @@ bool FileAccessEncrypted::file_exists(const String &p_name) {
}
uint64_t FileAccessEncrypted::_get_modified_time(const String &p_file) {
return 0;
}
uint32_t FileAccessEncrypted::_get_unix_permissions(const String &p_file) {
return 0;
}
@ -319,7 +288,6 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t
}
FileAccessEncrypted::FileAccessEncrypted() {
file = NULL;
pos = 0;
eofed = false;
@ -328,7 +296,6 @@ FileAccessEncrypted::FileAccessEncrypted() {
}
FileAccessEncrypted::~FileAccessEncrypted() {
if (file)
close();
}

View file

@ -37,7 +37,6 @@
static Map<String, Vector<uint8_t>> *files = NULL;
void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {
if (!files) {
files = memnew((Map<String, Vector<uint8_t>>));
}
@ -53,7 +52,6 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {
}
void FileAccessMemory::cleanup() {
if (!files)
return;
@ -61,12 +59,10 @@ void FileAccessMemory::cleanup() {
}
FileAccess *FileAccessMemory::create() {
return memnew(FileAccessMemory);
}
bool FileAccessMemory::file_exists(const String &p_name) {
String name = fix_path(p_name);
//name = DirAccess::normalize_path(name);
@ -74,7 +70,6 @@ bool FileAccessMemory::file_exists(const String &p_name) {
}
Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) {
data = (uint8_t *)p_data;
length = p_len;
pos = 0;
@ -82,7 +77,6 @@ Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) {
}
Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);
String name = fix_path(p_path);
@ -99,46 +93,38 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessMemory::close() {
data = NULL;
}
bool FileAccessMemory::is_open() const {
return data != NULL;
}
void FileAccessMemory::seek(size_t p_position) {
ERR_FAIL_COND(!data);
pos = p_position;
}
void FileAccessMemory::seek_end(int64_t p_position) {
ERR_FAIL_COND(!data);
pos = length + p_position;
}
size_t FileAccessMemory::get_position() const {
ERR_FAIL_COND_V(!data, 0);
return pos;
}
size_t FileAccessMemory::get_len() const {
ERR_FAIL_COND_V(!data, 0);
return length;
}
bool FileAccessMemory::eof_reached() const {
return pos > length;
}
uint8_t FileAccessMemory::get_8() const {
uint8_t ret = 0;
if (pos < length) {
ret = data[pos];
@ -167,7 +153,6 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessMemory::get_error() const {
return pos >= length ? ERR_FILE_EOF : OK;
}
@ -176,14 +161,12 @@ void FileAccessMemory::flush() {
}
void FileAccessMemory::store_8(uint8_t p_byte) {
ERR_FAIL_COND(!data);
ERR_FAIL_COND(pos >= length);
data[pos++] = p_byte;
}
void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) {
int left = length - pos;
int write = MIN(p_length, left);
if (write < p_length) {
@ -195,6 +178,5 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) {
}
FileAccessMemory::FileAccessMemory() {
data = NULL;
}

View file

@ -34,7 +34,6 @@
#include "core/os/file_access.h"
class FileAccessMemory : public FileAccess {
uint8_t *data;
int length;
mutable int pos;

View file

@ -41,19 +41,16 @@
#define DEBUG_TIME(m_what)
void FileAccessNetworkClient::lock_mutex() {
mutex.lock();
lockcount++;
}
void FileAccessNetworkClient::unlock_mutex() {
lockcount--;
mutex.unlock();
}
void FileAccessNetworkClient::put_32(int p_32) {
uint8_t buf[4];
encode_uint32(p_32, buf);
client->put_data(buf, 4);
@ -61,7 +58,6 @@ void FileAccessNetworkClient::put_32(int p_32) {
}
void FileAccessNetworkClient::put_64(int64_t p_64) {
uint8_t buf[8];
encode_uint64(p_64, buf);
client->put_data(buf, 8);
@ -69,24 +65,20 @@ void FileAccessNetworkClient::put_64(int64_t p_64) {
}
int FileAccessNetworkClient::get_32() {
uint8_t buf[4];
client->get_data(buf, 4);
return decode_uint32(buf);
}
int64_t FileAccessNetworkClient::get_64() {
uint8_t buf[8];
client->get_data(buf, 8);
return decode_uint64(buf);
}
void FileAccessNetworkClient::_thread_func() {
client->set_no_delay(true);
while (!quit) {
DEBUG_PRINT("SEM WAIT - " + itos(sem->get()));
sem.wait();
DEBUG_TIME("sem_unlock");
@ -126,9 +118,7 @@ void FileAccessNetworkClient::_thread_func() {
fa = accesses[id];
switch (response) {
case FileAccessNetwork::RESPONSE_OPEN: {
DEBUG_TIME("sem_open");
int status = get_32();
if (status != OK) {
@ -142,7 +132,6 @@ void FileAccessNetworkClient::_thread_func() {
} break;
case FileAccessNetwork::RESPONSE_DATA: {
int64_t offset = get_64();
uint32_t len = get_32();
@ -155,14 +144,12 @@ void FileAccessNetworkClient::_thread_func() {
} break;
case FileAccessNetwork::RESPONSE_FILE_EXISTS: {
int status = get_32();
fa->exists_modtime = status != 0;
fa->sem.post();
} break;
case FileAccessNetwork::RESPONSE_GET_MODTIME: {
uint64_t status = get_64();
fa->exists_modtime = status;
fa->sem.post();
@ -175,14 +162,12 @@ void FileAccessNetworkClient::_thread_func() {
}
void FileAccessNetworkClient::_thread_func(void *s) {
FileAccessNetworkClient *self = (FileAccessNetworkClient *)s;
self->_thread_func();
}
Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const String &p_password) {
IP_Address ip;
if (p_host.is_valid_ip_address()) {
@ -221,7 +206,6 @@ Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const S
FileAccessNetworkClient *FileAccessNetworkClient::singleton = NULL;
FileAccessNetworkClient::FileAccessNetworkClient() {
quit = false;
singleton = this;
last_id = 0;
@ -230,7 +214,6 @@ FileAccessNetworkClient::FileAccessNetworkClient() {
}
FileAccessNetworkClient::~FileAccessNetworkClient() {
if (thread.is_started()) {
quit = true;
sem.post();
@ -239,7 +222,6 @@ FileAccessNetworkClient::~FileAccessNetworkClient() {
}
void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) {
int page = p_offset / page_size;
ERR_FAIL_INDEX(page, pages.size());
if (page < pages.size() - 1) {
@ -260,7 +242,6 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block)
}
void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status));
response = p_status;
if (response != OK)
@ -272,7 +253,6 @@ void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
}
Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE);
if (opened)
close();
@ -307,7 +287,6 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessNetwork::close() {
if (!opened)
return;
@ -322,12 +301,10 @@ void FileAccessNetwork::close() {
nc->unlock_mutex();
}
bool FileAccessNetwork::is_open() const {
return opened;
}
void FileAccessNetwork::seek(size_t p_position) {
ERR_FAIL_COND_MSG(!opened, "File must be opened before use.");
eof_flag = p_position > total_size;
@ -339,39 +316,32 @@ void FileAccessNetwork::seek(size_t p_position) {
}
void FileAccessNetwork::seek_end(int64_t p_position) {
seek(total_size + p_position);
}
size_t FileAccessNetwork::get_position() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return pos;
}
size_t FileAccessNetwork::get_len() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
return total_size;
}
bool FileAccessNetwork::eof_reached() const {
ERR_FAIL_COND_V_MSG(!opened, false, "File must be opened before use.");
return eof_flag;
}
uint8_t FileAccessNetwork::get_8() const {
uint8_t v;
get_buffer(&v, 1);
return v;
}
void FileAccessNetwork::_queue_page(int p_page) const {
if (p_page >= pages.size())
return;
if (pages[p_page].buffer.empty() && !pages[p_page].queued) {
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->blockrequest_mutex.lock();
@ -405,7 +375,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
uint8_t *buff = last_page_buff;
for (int i = 0; i < p_length; i++) {
int page = pos / page_size;
if (page != last_page) {
@ -413,7 +382,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
if (pages[page].buffer.empty()) {
waiting_on_page = page;
for (int j = 0; j < read_ahead; j++) {
_queue_page(page + j);
}
buffer_mutex.unlock();
@ -421,9 +389,7 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
page_sem.wait();
DEBUG_PRINT("done");
} else {
for (int j = 0; j < read_ahead; j++) {
_queue_page(page + j);
}
//queue pages
@ -443,7 +409,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessNetwork::get_error() const {
return pos == total_size ? ERR_FILE_EOF : OK;
}
@ -452,12 +417,10 @@ void FileAccessNetwork::flush() {
}
void FileAccessNetwork::store_8(uint8_t p_dest) {
ERR_FAIL();
}
bool FileAccessNetwork::file_exists(const String &p_path) {
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
nc->put_32(id);
@ -474,7 +437,6 @@ bool FileAccessNetwork::file_exists(const String &p_path) {
}
uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
nc->put_32(id);
@ -501,7 +463,6 @@ Error FileAccessNetwork::_set_unix_permissions(const String &p_file, uint32_t p_
}
void FileAccessNetwork::configure() {
GLOBAL_DEF("network/remote_fs/page_size", 65536);
ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_size", PropertyInfo(Variant::INT, "network/remote_fs/page_size", PROPERTY_HINT_RANGE, "1,65536,1,or_greater")); //is used as denominator and can't be zero
GLOBAL_DEF("network/remote_fs/page_read_ahead", 4);
@ -509,7 +470,6 @@ void FileAccessNetwork::configure() {
}
FileAccessNetwork::FileAccessNetwork() {
eof_flag = false;
opened = false;
pos = 0;
@ -526,7 +486,6 @@ FileAccessNetwork::FileAccessNetwork() {
}
FileAccessNetwork::~FileAccessNetwork() {
close();
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;

View file

@ -39,9 +39,7 @@
class FileAccessNetwork;
class FileAccessNetworkClient {
struct BlockRequest {
int id;
uint64_t offset;
int size;
@ -84,7 +82,6 @@ public:
};
class FileAccessNetwork : public FileAccess {
Semaphore sem;
Semaphore page_sem;
Mutex buffer_mutex;

View file

@ -35,11 +35,8 @@
#include <stdio.h>
Error PackedData::add_pack(const String &p_path, bool p_replace_files, size_t p_offset) {
for (int i = 0; i < sources.size(); i++) {
if (sources[i]->try_open_pack(p_path, p_replace_files, p_offset)) {
return OK;
};
};
@ -48,7 +45,6 @@ Error PackedData::add_pack(const String &p_path, bool p_replace_files, size_t p_
};
void PackedData::add_path(const String &pkg_path, const String &path, uint64_t ofs, uint64_t size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files) {
PathMD5 pmd5(path.md5_buffer());
//printf("adding path %ls, %lli, %lli\n", path.c_str(), pmd5.a, pmd5.b);
@ -75,9 +71,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
Vector<String> ds = p.get_base_dir().split("/");
for (int j = 0; j < ds.size(); j++) {
if (!cd->subdirs.has(ds[j])) {
PackedDir *pd = memnew(PackedDir);
pd->name = ds[j];
pd->parent = cd;
@ -97,7 +91,6 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
}
void PackedData::add_pack_source(PackSource *p_source) {
if (p_source != NULL) {
sources.push_back(p_source);
}
@ -106,7 +99,6 @@ void PackedData::add_pack_source(PackSource *p_source) {
PackedData *PackedData::singleton = NULL;
PackedData::PackedData() {
singleton = this;
root = memnew(PackedDir);
root->parent = NULL;
@ -116,14 +108,12 @@ PackedData::PackedData() {
}
void PackedData::_free_packed_dirs(PackedDir *p_dir) {
for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next())
_free_packed_dirs(E->get());
memdelete(p_dir);
}
PackedData::~PackedData() {
for (int i = 0; i < sources.size(); i++) {
memdelete(sources[i]);
}
@ -133,7 +123,6 @@ PackedData::~PackedData() {
//////////////////////////////////////////////////////////////////
bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f)
return false;
@ -155,7 +144,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
f->seek(f->get_position() - 4);
magic = f->get_32();
if (magic != PACK_HEADER_MAGIC) {
f->close();
memdelete(f);
return false;
@ -167,7 +155,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
magic = f->get_32();
if (magic != PACK_HEADER_MAGIC) {
f->close();
memdelete(f);
return false;
@ -198,7 +185,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
int file_count = f->get_32();
for (int i = 0; i < file_count; i++) {
uint32_t sl = f->get_32();
CharString cs;
cs.resize(sl + 1);
@ -221,30 +207,25 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
};
FileAccess *PackedSourcePCK::get_file(const String &p_path, PackedData::PackedFile *p_file) {
return memnew(FileAccessPack(p_path, *p_file));
};
//////////////////////////////////////////////////////////////////
Error FileAccessPack::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_V(ERR_UNAVAILABLE);
return ERR_UNAVAILABLE;
}
void FileAccessPack::close() {
f->close();
}
bool FileAccessPack::is_open() const {
return f->is_open();
}
void FileAccessPack::seek(size_t p_position) {
if (p_position > pf.size) {
eof = true;
} else {
@ -255,25 +236,20 @@ void FileAccessPack::seek(size_t p_position) {
pos = p_position;
}
void FileAccessPack::seek_end(int64_t p_position) {
seek(pf.size + p_position);
}
size_t FileAccessPack::get_position() const {
return pos;
}
size_t FileAccessPack::get_len() const {
return pf.size;
}
bool FileAccessPack::eof_reached() const {
return eof;
}
uint8_t FileAccessPack::get_8() const {
if (pos >= pf.size) {
eof = true;
return 0;
@ -311,36 +287,30 @@ void FileAccessPack::set_endian_swap(bool p_swap) {
}
Error FileAccessPack::get_error() const {
if (eof)
return ERR_FILE_EOF;
return OK;
}
void FileAccessPack::flush() {
ERR_FAIL();
}
void FileAccessPack::store_8(uint8_t p_dest) {
ERR_FAIL();
}
void FileAccessPack::store_buffer(const uint8_t *p_src, int p_length) {
ERR_FAIL();
}
bool FileAccessPack::file_exists(const String &p_name) {
return false;
}
FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) :
pf(p_file),
f(FileAccess::open(pf.pack, FileAccess::READ)) {
ERR_FAIL_COND_MSG(!f, "Can't open pack-referenced file '" + String(pf.pack) + "'.");
f->seek(pf.offset);
@ -358,17 +328,14 @@ FileAccessPack::~FileAccessPack() {
//////////////////////////////////////////////////////////////////////////////////
Error DirAccessPack::list_dir_begin() {
list_dirs.clear();
list_files.clear();
for (Map<String, PackedData::PackedDir *>::Element *E = current->subdirs.front(); E; E = E->next()) {
list_dirs.push_back(E->key());
}
for (Set<String>::Element *E = current->files.front(); E; E = E->next()) {
list_files.push_back(E->get());
}
@ -376,7 +343,6 @@ Error DirAccessPack::list_dir_begin() {
}
String DirAccessPack::get_next() {
if (list_dirs.size()) {
cdir = true;
String d = list_dirs.front()->get();
@ -392,30 +358,24 @@ String DirAccessPack::get_next() {
}
}
bool DirAccessPack::current_is_dir() const {
return cdir;
}
bool DirAccessPack::current_is_hidden() const {
return false;
}
void DirAccessPack::list_dir_end() {
list_dirs.clear();
list_files.clear();
}
int DirAccessPack::get_drive_count() {
return 0;
}
String DirAccessPack::get_drive(int p_drive) {
return "";
}
PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) {
String nd = p_dir.replace("\\", "/");
// Special handling since simplify_path() will forbid it
@ -449,7 +409,6 @@ PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) {
pd = current;
for (int i = 0; i < paths.size(); i++) {
String p = paths[i];
if (p == ".") {
continue;
@ -458,11 +417,9 @@ PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) {
pd = pd->parent;
}
} else if (pd->subdirs.has(p)) {
pd = pd->subdirs[p];
} else {
return NULL;
}
}
@ -471,7 +428,6 @@ PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) {
}
Error DirAccessPack::change_dir(String p_dir) {
PackedData::PackedDir *pd = _find_dir(p_dir);
if (pd) {
current = pd;
@ -482,7 +438,6 @@ Error DirAccessPack::change_dir(String p_dir) {
}
String DirAccessPack::get_current_dir() {
PackedData::PackedDir *pd = current;
String p = current->name;
@ -495,7 +450,6 @@ String DirAccessPack::get_current_dir() {
}
bool DirAccessPack::file_exists(String p_file) {
p_file = fix_path(p_file);
PackedData::PackedDir *pd = _find_dir(p_file.get_base_dir());
@ -506,28 +460,23 @@ bool DirAccessPack::file_exists(String p_file) {
}
bool DirAccessPack::dir_exists(String p_dir) {
p_dir = fix_path(p_dir);
return _find_dir(p_dir) != NULL;
}
Error DirAccessPack::make_dir(String p_dir) {
return ERR_UNAVAILABLE;
}
Error DirAccessPack::rename(String p_from, String p_to) {
return ERR_UNAVAILABLE;
}
Error DirAccessPack::remove(String p_name) {
return ERR_UNAVAILABLE;
}
size_t DirAccessPack::get_space_left() {
return 0;
}
@ -536,7 +485,6 @@ String DirAccessPack::get_filesystem_type() const {
}
DirAccessPack::DirAccessPack() {
current = PackedData::get_singleton()->root;
cdir = false;
}

View file

@ -52,7 +52,6 @@ class PackedData {
public:
struct PackedFile {
String pack;
uint64_t offset; //if offset is ZERO, the file was ERASED
uint64_t size;
@ -72,7 +71,6 @@ private:
uint64_t a;
uint64_t b;
bool operator<(const PathMD5 &p_md5) const {
if (p_md5.a == a) {
return b < p_md5.b;
} else {
@ -127,7 +125,6 @@ public:
};
class PackSource {
public:
virtual bool try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset) = 0;
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) = 0;
@ -135,14 +132,12 @@ public:
};
class PackedSourcePCK : public PackSource {
public:
virtual bool try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset);
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
};
class FileAccessPack : public FileAccess {
PackedData::PackedFile pf;
mutable size_t pos;
@ -185,7 +180,6 @@ public:
};
FileAccess *PackedData::try_open_path(const String &p_path) {
PathMD5 pmd5(p_path.md5_buffer());
Map<PathMD5, PackedFile>::Element *E = files.find(pmd5);
if (!E)
@ -197,12 +191,10 @@ FileAccess *PackedData::try_open_path(const String &p_path) {
}
bool PackedData::has_path(const String &p_path) {
return files.has(PathMD5(p_path.md5_buffer()));
}
bool PackedData::has_directory(const String &p_path) {
DirAccess *da = try_open_directory(p_path);
if (da) {
memdelete(da);
@ -213,7 +205,6 @@ bool PackedData::has_directory(const String &p_path) {
}
class DirAccessPack : public DirAccess {
PackedData::PackedDir *current;
List<String> list_dirs;
@ -252,7 +243,6 @@ public:
};
DirAccess *PackedData::try_open_directory(const String &p_path) {
DirAccess *da = memnew(DirAccessPack());
if (da->change_dir(p_path) != OK) {
memdelete(da);

View file

@ -39,7 +39,6 @@ ZipArchive *ZipArchive::instance = NULL;
extern "C" {
static void *godot_open(void *data, const char *p_fname, int mode) {
if (mode & ZLIB_FILEFUNC_MODE_WRITE) {
return NULL;
}
@ -51,30 +50,25 @@ static void *godot_open(void *data, const char *p_fname, int mode) {
}
static uLong godot_read(void *data, void *fdata, void *buf, uLong size) {
FileAccess *f = (FileAccess *)data;
f->get_buffer((uint8_t *)buf, size);
return size;
}
static uLong godot_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
return 0;
}
static long godot_tell(voidpf opaque, voidpf stream) {
FileAccess *f = (FileAccess *)opaque;
return f->get_position();
}
static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
FileAccess *f = (FileAccess *)opaque;
int pos = offset;
switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR:
pos = f->get_position() + offset;
break;
@ -90,32 +84,27 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
}
static int godot_close(voidpf opaque, voidpf stream) {
FileAccess *f = (FileAccess *)opaque;
f->close();
return 0;
}
static int godot_testerror(voidpf opaque, voidpf stream) {
FileAccess *f = (FileAccess *)opaque;
return f->get_error() != OK ? 1 : 0;
}
static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) {
return memalloc(items * size);
}
static void godot_free(voidpf opaque, voidpf address) {
memfree(address);
}
} // extern "C"
void ZipArchive::close_handle(unzFile p_file) const {
ERR_FAIL_COND_MSG(!p_file, "Cannot close a file if none is open.");
FileAccess *f = (FileAccess *)unzGetOpaque(p_file);
unzCloseCurrentFile(p_file);
@ -124,7 +113,6 @@ void ZipArchive::close_handle(unzFile p_file) const {
}
unzFile ZipArchive::get_file_handle(String p_file) const {
ERR_FAIL_COND_V_MSG(!file_exists(p_file), NULL, "File '" + p_file + " doesn't exist.");
File file = files[p_file];
@ -151,7 +139,6 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
ERR_FAIL_COND_V(!pkg, NULL);
int unz_err = unzGoToFilePos(pkg, &file.file_pos);
if (unz_err != UNZ_OK || unzOpenCurrentFile(pkg) != UNZ_OK) {
unzClose(pkg);
ERR_FAIL_V(NULL);
}
@ -160,7 +147,6 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
}
bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset = 0) {
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
// load with offset feature only supported for PCK files
ERR_FAIL_COND_V_MSG(p_offset != 0, false, "Invalid PCK data. Note that loading files with a non-zero offset isn't supported with ZIP archives.");
@ -197,7 +183,6 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_
int pkg_num = packages.size() - 1;
for (uint64_t i = 0; i < gi.number_entry; i++) {
char filename_inzip[256];
unz_file_info64 file_info;
@ -224,17 +209,14 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_
}
bool ZipArchive::file_exists(String p_name) const {
return files.has(p_name);
}
FileAccess *ZipArchive::get_file(const String &p_path, PackedData::PackedFile *p_file) {
return memnew(FileAccessZip(p_path, *p_file));
}
ZipArchive *ZipArchive::get_singleton() {
if (instance == NULL) {
instance = memnew(ZipArchive);
}
@ -243,15 +225,12 @@ ZipArchive *ZipArchive::get_singleton() {
}
ZipArchive::ZipArchive() {
instance = this;
//fa_create_func = FileAccess::get_create_func();
}
ZipArchive::~ZipArchive() {
for (int i = 0; i < packages.size(); i++) {
FileAccess *f = (FileAccess *)unzGetOpaque(packages[i].zfile);
unzClose(packages[i].zfile);
memdelete(f);
@ -261,7 +240,6 @@ ZipArchive::~ZipArchive() {
}
Error FileAccessZip::_open(const String &p_path, int p_mode_flags) {
close();
ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED);
@ -277,7 +255,6 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessZip::close() {
if (!zfile)
return;
@ -288,43 +265,36 @@ void FileAccessZip::close() {
}
bool FileAccessZip::is_open() const {
return zfile != NULL;
}
void FileAccessZip::seek(size_t p_position) {
ERR_FAIL_COND(!zfile);
unzSeekCurrentFile(zfile, p_position);
}
void FileAccessZip::seek_end(int64_t p_position) {
ERR_FAIL_COND(!zfile);
unzSeekCurrentFile(zfile, get_len() + p_position);
}
size_t FileAccessZip::get_position() const {
ERR_FAIL_COND_V(!zfile, 0);
return unztell(zfile);
}
size_t FileAccessZip::get_len() const {
ERR_FAIL_COND_V(!zfile, 0);
return file_info.uncompressed_size;
}
bool FileAccessZip::eof_reached() const {
ERR_FAIL_COND_V(!zfile, true);
return at_eof;
}
uint8_t FileAccessZip::get_8() const {
uint8_t ret = 0;
get_buffer(&ret, 1);
return ret;
@ -345,9 +315,7 @@ int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const {
}
Error FileAccessZip::get_error() const {
if (!zfile) {
return ERR_UNCONFIGURED;
}
if (eof_reached()) {
@ -358,17 +326,14 @@ Error FileAccessZip::get_error() const {
}
void FileAccessZip::flush() {
ERR_FAIL();
}
void FileAccessZip::store_8(uint8_t p_dest) {
ERR_FAIL();
}
bool FileAccessZip::file_exists(const String &p_name) {
return false;
}
@ -378,7 +343,6 @@ FileAccessZip::FileAccessZip(const String &p_path, const PackedData::PackedFile
}
FileAccessZip::~FileAccessZip() {
close();
}

View file

@ -41,14 +41,11 @@
#include <stdlib.h>
class ZipArchive : public PackSource {
public:
struct File {
int package;
unz_file_pos file_pos;
File() {
package = -1;
};
};

View file

@ -47,7 +47,6 @@ const char *HTTPClient::_methods[METHOD_MAX] = {
#ifndef JAVASCRIPT_ENABLED
Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) {
close();
conn_port = p_port;
@ -58,10 +57,8 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,
String host_lower = conn_host.to_lower();
if (host_lower.begins_with("http://")) {
conn_host = conn_host.substr(7, conn_host.length() - 7);
} else if (host_lower.begins_with("https://")) {
ssl = true;
conn_host = conn_host.substr(8, conn_host.length() - 8);
}
@ -97,7 +94,6 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,
}
void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) {
ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object.");
if (ssl) {
@ -115,7 +111,6 @@ void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) {
}
Ref<StreamPeer> HTTPClient::get_connection() const {
return connection;
}
@ -212,7 +207,6 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector
}
Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) {
ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(!_check_request_url(p_method, p_url), ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
@ -274,27 +268,22 @@ Error HTTPClient::request(Method p_method, const String &p_url, const Vector<Str
}
bool HTTPClient::has_response() const {
return response_headers.size() != 0;
}
bool HTTPClient::is_response_chunked() const {
return chunked;
}
int HTTPClient::get_response_code() const {
return response_num;
}
Error HTTPClient::get_response_headers(List<String> *r_response) {
if (!response_headers.size())
return ERR_INVALID_PARAMETER;
for (int i = 0; i < response_headers.size(); i++) {
r_response->push_back(response_headers[i]);
}
@ -304,7 +293,6 @@ Error HTTPClient::get_response_headers(List<String> *r_response) {
}
void HTTPClient::close() {
if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE)
tcp_connection->disconnect_from_host();
@ -312,7 +300,6 @@ void HTTPClient::close() {
status = STATUS_DISCONNECTED;
head_request = false;
if (resolving != IP::RESOLVER_INVALID_ID) {
IP::get_singleton()->erase_resolve_item(resolving);
resolving = IP::RESOLVER_INVALID_ID;
}
@ -329,9 +316,7 @@ void HTTPClient::close() {
}
Error HTTPClient::poll() {
switch (status) {
case STATUS_RESOLVING: {
ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG);
@ -341,7 +326,6 @@ Error HTTPClient::poll() {
return OK; // Still resolving
case IP::RESOLVER_STATUS_DONE: {
IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving);
Error err = tcp_connection->connect_to_host(host, conn_port);
IP::get_singleton()->erase_resolve_item(resolving);
@ -355,7 +339,6 @@ Error HTTPClient::poll() {
} break;
case IP::RESOLVER_STATUS_NONE:
case IP::RESOLVER_STATUS_ERROR: {
IP::get_singleton()->erase_resolve_item(resolving);
resolving = IP::RESOLVER_INVALID_ID;
close();
@ -365,10 +348,8 @@ Error HTTPClient::poll() {
}
} break;
case STATUS_CONNECTING: {
StreamPeerTCP::Status s = tcp_connection->get_status();
switch (s) {
case StreamPeerTCP::STATUS_CONNECTING: {
return OK;
} break;
@ -418,7 +399,6 @@ Error HTTPClient::poll() {
} break;
case StreamPeerTCP::STATUS_ERROR:
case StreamPeerTCP::STATUS_NONE: {
close();
status = STATUS_CANT_CONNECT;
return ERR_CANT_CONNECT;
@ -443,7 +423,6 @@ Error HTTPClient::poll() {
return OK;
} break;
case STATUS_REQUESTING: {
while (true) {
uint8_t byte;
int rec = 0;
@ -462,7 +441,6 @@ Error HTTPClient::poll() {
if (
(rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') ||
(rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) {
// End of response, parse.
response_str.push_back(0);
String response;
@ -484,7 +462,6 @@ Error HTTPClient::poll() {
bool keep_alive = true;
for (int i = 0; i < responses.size(); i++) {
String header = responses[i].strip_edges();
String s = header.to_lower();
if (s.length() == 0)
@ -503,11 +480,9 @@ Error HTTPClient::poll() {
}
if (i == 0 && responses[i].begins_with("HTTP")) {
String num = responses[i].get_slicec(' ', 1);
response_num = num.to_int();
} else {
response_headers.push_back(header);
}
}
@ -519,14 +494,11 @@ Error HTTPClient::poll() {
}
if (body_size != -1 || chunked) {
status = STATUS_BODY;
} else if (!keep_alive) {
read_until_eof = true;
status = STATUS_BODY;
} else {
status = STATUS_CONNECTED;
}
return OK;
@ -552,21 +524,17 @@ Error HTTPClient::poll() {
}
int HTTPClient::get_response_body_length() const {
return body_size;
}
PoolByteArray HTTPClient::read_response_body_chunk() {
ERR_FAIL_COND_V(status != STATUS_BODY, PoolByteArray());
PoolByteArray ret;
Error err = OK;
if (chunked) {
while (true) {
if (chunk_trailer_part) {
// We need to consume the trailer part too or keep-alive will break
uint8_t b;
@ -608,7 +576,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
}
if (chunk.size() > 2 && chunk[chunk.size() - 2] == '\r' && chunk[chunk.size() - 1] == '\n') {
int len = 0;
for (int i = 0; i < chunk.size() - 2; i++) {
char c = chunk[i];
@ -644,7 +611,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
chunk.resize(chunk_left);
}
} else {
int rec = 0;
err = _get_http_data(&chunk.write[chunk.size() - chunk_left], chunk_left, rec);
if (rec == 0) {
@ -653,7 +619,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
chunk_left -= rec;
if (chunk_left == 0) {
if (chunk[chunk.size() - 2] != '\r' || chunk[chunk.size() - 1] != '\n') {
ERR_PRINT("HTTP Invalid chunk terminator (not \\r\\n)");
status = STATUS_CONNECTION_ERROR;
@ -671,7 +636,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
}
} else {
int to_read = !read_until_eof ? MIN(body_left, read_chunk_size) : read_chunk_size;
ret.resize(to_read);
int _offset = 0;
@ -697,18 +661,14 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
}
if (err != OK) {
close();
if (err == ERR_FILE_EOF) {
status = STATUS_DISCONNECTED; // Server disconnected
} else {
status = STATUS_CONNECTION_ERROR;
}
} else if (body_left == 0 && !chunked && !read_until_eof) {
status = STATUS_CONNECTED;
}
@ -716,24 +676,19 @@ PoolByteArray HTTPClient::read_response_body_chunk() {
}
HTTPClient::Status HTTPClient::get_status() const {
return status;
}
void HTTPClient::set_blocking_mode(bool p_enable) {
blocking = p_enable;
}
bool HTTPClient::is_blocking_mode_enabled() const {
return blocking;
}
Error HTTPClient::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
if (blocking) {
// We can't use StreamPeer.get_data, since when reaching EOF we will get an
// error without knowing how many bytes we received.
Error err = ERR_FILE_EOF;
@ -768,7 +723,6 @@ int HTTPClient::get_read_chunk_size() const {
}
HTTPClient::HTTPClient() {
tcp_connection.instance();
resolving = IP::RESOLVER_INVALID_ID;
status = STATUS_DISCONNECTED;
@ -824,7 +778,6 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) {
}
Dictionary HTTPClient::_get_response_headers_as_dictionary() {
List<String> rh;
get_response_headers(&rh);
Dictionary ret;
@ -842,7 +795,6 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
}
PoolStringArray HTTPClient::_get_response_headers() {
List<String> rh;
get_response_headers(&rh);
PoolStringArray ret;
@ -856,7 +808,6 @@ PoolStringArray HTTPClient::_get_response_headers() {
}
void HTTPClient::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(-1), DEFVAL(false), DEFVAL(true));
ClassDB::bind_method(D_METHOD("set_connection", "connection"), &HTTPClient::set_connection);
ClassDB::bind_method(D_METHOD("get_connection"), &HTTPClient::get_connection);

View file

@ -37,7 +37,6 @@
#include "core/reference.h"
class HTTPClient : public Reference {
GDCLASS(HTTPClient, Reference);
public:

View file

@ -33,11 +33,9 @@
#include "core/print_string.h"
bool ImageFormatLoader::recognize(const String &p_extension) const {
List<String> extensions;
get_recognized_extensions(&extensions);
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
if (E->get().nocasecmp_to(p_extension) == 0)
return true;
}
@ -61,7 +59,6 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
String extension = p_file.get_extension();
for (int i = 0; i < loader.size(); i++) {
if (!loader[i]->recognize(extension))
continue;
Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale);
@ -70,7 +67,6 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
}
if (err != ERR_FILE_UNRECOGNIZED) {
if (!p_custom)
memdelete(f);
@ -85,17 +81,13 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
}
void ImageLoader::get_recognized_extensions(List<String> *p_extensions) {
for (int i = 0; i < loader.size(); i++) {
loader[i]->get_recognized_extensions(p_extensions);
}
}
ImageFormatLoader *ImageLoader::recognize(const String &p_extension) {
for (int i = 0; i < loader.size(); i++) {
if (loader[i]->recognize(p_extension))
return loader[i];
}
@ -106,22 +98,18 @@ ImageFormatLoader *ImageLoader::recognize(const String &p_extension) {
Vector<ImageFormatLoader *> ImageLoader::loader;
void ImageLoader::add_image_format_loader(ImageFormatLoader *p_loader) {
loader.push_back(p_loader);
}
void ImageLoader::remove_image_format_loader(ImageFormatLoader *p_loader) {
loader.erase(p_loader);
}
const Vector<ImageFormatLoader *> &ImageLoader::get_image_format_loaders() {
return loader;
}
void ImageLoader::cleanup() {
while (loader.size()) {
remove_image_format_loader(loader[0]);
}
@ -130,7 +118,6 @@ void ImageLoader::cleanup() {
/////////////////
RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
if (r_error) {
@ -192,16 +179,13 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin
}
void ResourceFormatLoaderImage::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("image");
}
bool ResourceFormatLoaderImage::handles_type(const String &p_type) const {
return p_type == "Image";
}
String ResourceFormatLoaderImage::get_resource_type(const String &p_path) const {
return p_path.get_extension().to_lower() == "image" ? "Image" : String();
}

View file

@ -53,7 +53,6 @@ public:
};
class ImageLoader {
static Vector<ImageFormatLoader *> loader;
friend class ResourceFormatLoaderImage;

View file

@ -39,9 +39,7 @@ VARIANT_ENUM_CAST(IP::ResolverStatus);
/************* RESOLVER ******************/
struct _IP_ResolverPrivate {
struct QueueItem {
SafeNumeric<IP::ResolverStatus> status;
IP_Address response;
String hostname;
@ -62,7 +60,6 @@ struct _IP_ResolverPrivate {
QueueItem queue[IP::RESOLVER_MAX_QUERIES];
IP::ResolverID find_empty_id() const {
for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) {
if (queue[i].status.get() == IP::RESOLVER_STATUS_NONE)
return i;
@ -78,9 +75,7 @@ struct _IP_ResolverPrivate {
bool thread_abort;
void resolve_queues() {
for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) {
if (queue[i].status.get() != IP::RESOLVER_STATUS_WAITING)
continue;
queue[i].response = IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type);
@ -93,11 +88,9 @@ struct _IP_ResolverPrivate {
}
static void _thread_function(void *self) {
_IP_ResolverPrivate *ipr = (_IP_ResolverPrivate *)self;
while (!ipr->thread_abort) {
ipr->sem.wait();
ipr->mutex.lock();
@ -114,7 +107,6 @@ struct _IP_ResolverPrivate {
};
IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) {
resolver->mutex.lock();
String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type);
@ -131,7 +123,6 @@ IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) {
}
IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Type p_type) {
resolver->mutex.lock();
ResolverID id = resolver->find_empty_id();
@ -162,7 +153,6 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ
}
IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const {
ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP::RESOLVER_STATUS_NONE);
resolver->mutex.lock();
@ -178,7 +168,6 @@ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const {
}
IP_Address IP::get_resolve_item_address(ResolverID p_id) const {
ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP_Address());
resolver->mutex.lock();
@ -196,7 +185,6 @@ IP_Address IP::get_resolve_item_address(ResolverID p_id) const {
}
void IP::erase_resolve_item(ResolverID p_id) {
ERR_FAIL_INDEX(p_id, IP::RESOLVER_MAX_QUERIES);
resolver->mutex.lock();
@ -207,7 +195,6 @@ void IP::erase_resolve_item(ResolverID p_id) {
}
void IP::clear_cache(const String &p_hostname) {
resolver->mutex.lock();
if (p_hostname.empty()) {
@ -223,7 +210,6 @@ void IP::clear_cache(const String &p_hostname) {
}
Array IP::_get_local_addresses() const {
Array addresses;
List<IP_Address> ip_addresses;
get_local_addresses(&ip_addresses);
@ -235,7 +221,6 @@ Array IP::_get_local_addresses() const {
}
Array IP::_get_local_interfaces() const {
Array results;
Map<String, Interface_Info> interfaces;
get_local_interfaces(&interfaces);
@ -259,7 +244,6 @@ Array IP::_get_local_interfaces() const {
}
void IP::get_local_addresses(List<IP_Address> *r_addresses) const {
Map<String, Interface_Info> interfaces;
get_local_interfaces(&interfaces);
for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) {
@ -270,7 +254,6 @@ void IP::get_local_addresses(List<IP_Address> *r_addresses) const {
}
void IP::_bind_methods() {
ClassDB::bind_method(D_METHOD("resolve_hostname", "host", "ip_type"), &IP::resolve_hostname, DEFVAL(IP::TYPE_ANY));
ClassDB::bind_method(D_METHOD("resolve_hostname_queue_item", "host", "ip_type"), &IP::resolve_hostname_queue_item, DEFVAL(IP::TYPE_ANY));
ClassDB::bind_method(D_METHOD("get_resolve_item_status", "id"), &IP::get_resolve_item_status);
@ -297,21 +280,18 @@ void IP::_bind_methods() {
IP *IP::singleton = NULL;
IP *IP::get_singleton() {
return singleton;
}
IP *(*IP::_create)() = NULL;
IP *IP::create() {
ERR_FAIL_COND_V_MSG(singleton, NULL, "IP singleton already exist.");
ERR_FAIL_COND_V(!_create, NULL);
return _create();
}
IP::IP() {
singleton = this;
resolver = memnew(_IP_ResolverPrivate);
@ -320,7 +300,6 @@ IP::IP() {
}
IP::~IP() {
resolver->thread_abort = true;
resolver->sem.post();
resolver->thread.wait_to_finish();

View file

@ -39,7 +39,6 @@ IP_Address::operator Variant() const {
#include <string.h>
IP_Address::operator String() const {
if (wildcard)
return "*";
@ -61,10 +60,8 @@ IP_Address::operator String() const {
}
static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
uint16_t ret = 0;
for (int i = p_start; i < p_start + 4; i++) {
if (i >= p_string.length()) {
break;
};
@ -72,7 +69,6 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
int n = 0;
CharType c = p_string[i];
if (c >= '0' && c <= '9') {
n = c - '0';
} else if (c >= 'a' && c <= 'f') {
n = 10 + (c - 'a');
@ -92,7 +88,6 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
};
void IP_Address::_parse_ipv6(const String &p_string) {
static const int parts_total = 8;
int parts[parts_total] = { 0 };
int parts_count = 0;
@ -102,10 +97,8 @@ void IP_Address::_parse_ipv6(const String &p_string) {
int parts_idx = 0;
for (int i = 0; i < p_string.length(); i++) {
CharType c = p_string[i];
if (c == ':') {
if (i == 0) {
continue; // next must be a ":"
};
@ -115,7 +108,6 @@ void IP_Address::_parse_ipv6(const String &p_string) {
};
part_found = false;
} else if (c == '.') {
part_ipv4 = true;
} else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
@ -136,9 +128,7 @@ void IP_Address::_parse_ipv6(const String &p_string) {
int idx = 0;
for (int i = 0; i < parts_idx; i++) {
if (parts[i] == -1) {
for (int j = 0; j < parts_extra; j++) {
field16[idx++] = 0;
};
@ -154,7 +144,6 @@ void IP_Address::_parse_ipv6(const String &p_string) {
};
void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) {
String ip;
if (p_start != 0) {
ip = p_string.substr(p_start, p_string.length() - p_start);
@ -170,7 +159,6 @@ void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret
};
void IP_Address::clear() {
memset(&field8[0], 0, sizeof(field8));
valid = false;
wildcard = false;
@ -204,7 +192,6 @@ void IP_Address::set_ipv6(const uint8_t *p_buf) {
}
IP_Address::IP_Address(const String &p_string) {
clear();
if (p_string == "*") {
@ -228,7 +215,6 @@ IP_Address::IP_Address(const String &p_string) {
}
_FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) {
p_dst[0] = (p_n >> 24) & 0xff;
p_dst[1] = (p_n >> 16) & 0xff;
p_dst[2] = (p_n >> 8) & 0xff;
@ -236,7 +222,6 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) {
};
IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) {
clear();
valid = true;
if (!is_v6) {
@ -247,7 +232,6 @@ IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, b
field8[14] = p_c;
field8[15] = p_d;
} else {
_32_to_buf(&field8[0], p_a);
_32_to_buf(&field8[4], p_b);
_32_to_buf(&field8[8], p_c);

View file

@ -34,7 +34,6 @@
#include "core/ustring.h"
struct IP_Address {
private:
union {
uint8_t field8[16];

View file

@ -46,7 +46,6 @@ const char *JSON::tk_name[TK_MAX] = {
};
static String _make_indent(const String &p_indent, int p_size) {
String indent_text = "";
if (!p_indent.empty()) {
for (int i = 0; i < p_size; i++)
@ -56,7 +55,6 @@ static String _make_indent(const String &p_indent, int p_size) {
}
String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) {
String colon = ":";
String end_statement = "";
@ -66,7 +64,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
}
switch (p_var.get_type()) {
case Variant::NIL:
return "null";
case Variant::BOOL:
@ -79,7 +76,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
case Variant::POOL_REAL_ARRAY:
case Variant::POOL_STRING_ARRAY:
case Variant::ARRAY: {
String s = "[";
s += end_statement;
Array a = p_var;
@ -94,7 +90,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
return s;
};
case Variant::DICTIONARY: {
String s = "{";
s += end_statement;
Dictionary d = p_var;
@ -105,7 +100,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
keys.sort();
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
if (E != keys.front()) {
s += ",";
s += end_statement;
@ -124,17 +118,13 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
}
String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys) {
return _print_var(p_var, p_indent, 0, p_sort_keys);
}
Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) {
while (p_len > 0) {
switch (p_str[index]) {
case '\n': {
line++;
index++;
break;
@ -144,43 +134,36 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return OK;
} break;
case '{': {
r_token.type = TK_CURLY_BRACKET_OPEN;
index++;
return OK;
};
case '}': {
r_token.type = TK_CURLY_BRACKET_CLOSE;
index++;
return OK;
};
case '[': {
r_token.type = TK_BRACKET_OPEN;
index++;
return OK;
};
case ']': {
r_token.type = TK_BRACKET_CLOSE;
index++;
return OK;
};
case ':': {
r_token.type = TK_COLON;
index++;
return OK;
};
case ',': {
r_token.type = TK_COMMA;
index++;
return OK;
};
case '"': {
index++;
String str;
while (true) {
@ -201,7 +184,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
CharType res = 0;
switch (next) {
case 'b':
res = 8;
break;
@ -227,7 +209,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return ERR_PARSE_ERROR;
}
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
r_err_str = "Malformed hex constant in string";
return ERR_PARSE_ERROR;
}
@ -277,7 +258,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
} break;
default: {
if (p_str[index] <= 32) {
index++;
break;
@ -293,11 +273,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
return OK;
} else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) {
String id;
while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) {
id += p_str[index];
index++;
}
@ -317,23 +295,19 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
}
Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
if (token.type == TK_CURLY_BRACKET_OPEN) {
Dictionary d;
Error err = _parse_object(d, p_str, index, p_len, line, r_err_str);
if (err)
return err;
value = d;
} else if (token.type == TK_BRACKET_OPEN) {
Array a;
Error err = _parse_array(a, p_str, index, p_len, line, r_err_str);
if (err)
return err;
value = a;
} else if (token.type == TK_IDENTIFIER) {
String id = token.value;
if (id == "true")
value = true;
@ -346,10 +320,8 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in
return ERR_PARSE_ERROR;
}
} else if (token.type == TK_NUMBER) {
value = token.value;
} else if (token.type == TK_STRING) {
value = token.value;
} else {
r_err_str = "Expected value, got " + String(tk_name[token.type]) + ".";
@ -360,25 +332,20 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in
}
Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
Token token;
bool need_comma = false;
while (index < p_len) {
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
if (err != OK)
return err;
if (token.type == TK_BRACKET_CLOSE) {
return OK;
}
if (need_comma) {
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
} else {
@ -401,29 +368,23 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_
}
Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) {
bool at_key = true;
String key;
Token token;
bool need_comma = false;
while (index < p_len) {
if (at_key) {
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
if (err != OK)
return err;
if (token.type == TK_CURLY_BRACKET_CLOSE) {
return OK;
}
if (need_comma) {
if (token.type != TK_COMMA) {
r_err_str = "Expected '}' or ','";
return ERR_PARSE_ERROR;
} else {
@ -433,7 +394,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
}
if (token.type != TK_STRING) {
r_err_str = "Expected key";
return ERR_PARSE_ERROR;
}
@ -443,13 +403,11 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
if (err != OK)
return err;
if (token.type != TK_COLON) {
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
}
at_key = false;
} else {
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
if (err != OK)
return err;
@ -469,7 +427,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
}
Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
const CharType *str = p_json.ptr();
int idx = 0;
int len = p_json.length();

View file

@ -34,7 +34,6 @@
#include "core/variant.h"
class JSON {
enum TokenType {
TK_CURLY_BRACKET_OPEN,
TK_CURLY_BRACKET_CLOSE,
@ -58,7 +57,6 @@ class JSON {
};
struct Token {
TokenType type;
Variant value;
};

View file

@ -66,7 +66,6 @@ public:
* Writes messages to stdout/stderr.
*/
class StdLogger : public Logger {
public:
virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_0;
virtual ~StdLogger();

View file

@ -49,7 +49,6 @@ void EncodedObjectAsID::set_object_id(ObjectID p_id) {
}
ObjectID EncodedObjectAsID::get_object_id() const {
return id;
}
@ -101,7 +100,6 @@ static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r
}
Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) {
const uint8_t *buf = p_buffer;
int len = p_len;
@ -117,13 +115,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
*r_len = 4;
switch (type & ENCODE_MASK) {
case Variant::NIL: {
r_variant = Variant();
} break;
case Variant::BOOL: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
bool val = decode_uint32(buf);
r_variant = val;
@ -131,7 +126,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
(*r_len) += 4;
} break;
case Variant::INT: {
if (type & ENCODE_FLAG_64) {
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
int64_t val = decode_uint64(buf);
@ -149,7 +143,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::REAL: {
if (type & ENCODE_FLAG_64) {
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
double val = decode_double(buf);
@ -166,7 +159,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::STRING: {
String str;
Error err = _decode_string(buf, len, r_len, str);
if (err)
@ -177,7 +169,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
// math types
case Variant::VECTOR2: {
ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA);
Vector2 val;
val.x = decode_float(&buf[0]);
@ -189,7 +180,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break; // 5
case Variant::RECT2: {
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Rect2 val;
val.position.x = decode_float(&buf[0]);
@ -203,7 +193,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::VECTOR3: {
ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA);
Vector3 val;
val.x = decode_float(&buf[0]);
@ -216,12 +205,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::TRANSFORM2D: {
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
Transform2D val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
}
}
@ -233,7 +220,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::PLANE: {
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Plane val;
val.normal.x = decode_float(&buf[0]);
@ -247,7 +233,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::QUAT: {
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Quat val;
val.x = decode_float(&buf[0]);
@ -261,7 +246,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::AABB: {
ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA);
AABB val;
val.position.x = decode_float(&buf[0]);
@ -277,12 +261,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::BASIS: {
ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA);
Basis val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}
@ -294,12 +276,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::TRANSFORM: {
ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA);
Transform val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}
@ -316,7 +296,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
// misc types
case Variant::COLOR: {
ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA);
Color val;
val.r = decode_float(&buf[0]);
@ -330,7 +309,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::NODE_PATH: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t strlen = decode_uint32(buf);
@ -356,7 +334,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
(*r_len) += 12;
for (uint32_t i = 0; i < total; i++) {
String str;
Error err = _decode_string(buf, len, r_len, str);
if (err)
@ -378,11 +355,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::_RID: {
r_variant = RID();
} break;
case Variant::OBJECT: {
if (type & ENCODE_FLAG_OBJECT_AS_ID) {
//this _is_ allowed
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
@ -411,7 +386,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
if (str == String()) {
r_variant = (Object *)NULL;
} else {
Object *obj = ClassDB::instance(str);
ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE);
@ -425,7 +399,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
}
for (int i = 0; i < count; i++) {
str = String();
err = _decode_string(buf, len, r_len, str);
if (err)
@ -457,7 +430,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::DICTIONARY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
// bool shared = count&0x80000000;
@ -473,7 +445,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Dictionary d;
for (int i = 0; i < count; i++) {
Variant key, value;
int used;
@ -502,7 +473,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
// bool shared = count&0x80000000;
@ -518,7 +488,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
Array varr;
for (int i = 0; i < count; i++) {
int used = 0;
Variant v;
Error err = decode_variant(v, buf, len, &used, p_allow_objects);
@ -537,7 +506,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
// arrays
case Variant::POOL_BYTE_ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@ -550,7 +518,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
PoolVector<uint8_t>::Write w = data.write();
for (int32_t i = 0; i < count; i++) {
w[i] = buf[i];
}
}
@ -565,7 +532,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::POOL_INT_ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@ -580,7 +546,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
PoolVector<int>::Write w = data.write();
for (int32_t i = 0; i < count; i++) {
w[i] = decode_uint32(&buf[i * 4]);
}
}
@ -591,7 +556,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::POOL_REAL_ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@ -606,7 +570,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
data.resize(count);
PoolVector<float>::Write w = data.write();
for (int32_t i = 0; i < count; i++) {
w[i] = decode_float(&buf[i * 4]);
}
}
@ -618,7 +581,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::POOL_STRING_ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
@ -631,7 +593,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
//printf("string count: %i\n",count);
for (int32_t i = 0; i < count; i++) {
String str;
Error err = _decode_string(buf, len, r_len, str);
if (err)
@ -644,7 +605,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::POOL_VECTOR2_ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@ -663,7 +623,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
PoolVector<Vector2>::Write w = varray.write();
for (int32_t i = 0; i < count; i++) {
w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0);
w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1);
}
@ -678,7 +637,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::POOL_VECTOR3_ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@ -698,7 +656,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
PoolVector<Vector3>::Write w = varray.write();
for (int32_t i = 0; i < count; i++) {
w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0);
w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1);
w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2);
@ -714,7 +671,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
} break;
case Variant::POOL_COLOR_ARRAY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t count = decode_uint32(buf);
buf += 4;
@ -734,7 +690,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
PoolVector<Color>::Write w = carray.write();
for (int32_t i = 0; i < count; i++) {
w[i].r = decode_float(buf + i * 4 * 4 + 4 * 0);
w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1);
w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2);
@ -759,7 +714,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
}
static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {
CharString utf8 = p_string.utf8();
if (buf) {
@ -779,7 +733,6 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) {
}
Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) {
uint8_t *buf = r_buffer;
r_len = 0;
@ -787,7 +740,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
uint32_t flags = 0;
switch (p_variant.get_type()) {
case Variant::INT: {
int64_t val = p_variant;
if (val > (int64_t)INT_MAX || val < (int64_t)INT_MIN) {
@ -795,7 +747,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::REAL: {
double d = p_variant;
float f = d;
if (double(f) != d) {
@ -830,13 +781,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
switch (p_variant.get_type()) {
case Variant::NIL: {
//nothing to do
} break;
case Variant::BOOL: {
if (buf) {
encode_uint32(p_variant.operator bool(), buf);
}
@ -845,7 +793,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::INT: {
if (flags & ENCODE_FLAG_64) {
//64 bits
if (buf) {
@ -862,7 +809,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} break;
case Variant::REAL: {
if (flags & ENCODE_FLAG_64) {
if (buf) {
encode_double(p_variant.operator double(), buf);
@ -871,7 +817,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 8;
} else {
if (buf) {
encode_float(p_variant.operator float(), buf);
}
@ -881,7 +826,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::NODE_PATH: {
NodePath np = p_variant;
if (buf) {
encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format
@ -900,7 +844,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
int total = np.get_name_count() + np.get_subname_count();
for (int i = 0; i < total; i++) {
String str;
if (i < np.get_name_count())
@ -927,14 +870,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::STRING: {
_encode_string(p_variant, buf, r_len);
} break;
// math types
case Variant::VECTOR2: {
if (buf) {
Vector2 v2 = p_variant;
encode_float(v2.x, &buf[0]);
@ -945,7 +886,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break; // 5
case Variant::RECT2: {
if (buf) {
Rect2 r2 = p_variant;
encode_float(r2.position.x, &buf[0]);
@ -957,7 +897,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::VECTOR3: {
if (buf) {
Vector3 v3 = p_variant;
encode_float(v3.x, &buf[0]);
@ -969,12 +908,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::TRANSFORM2D: {
if (buf) {
Transform2D val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
memcpy(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float));
}
}
@ -984,7 +921,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::PLANE: {
if (buf) {
Plane p = p_variant;
encode_float(p.normal.x, &buf[0]);
@ -997,7 +933,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::QUAT: {
if (buf) {
Quat q = p_variant;
encode_float(q.x, &buf[0]);
@ -1010,7 +945,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::AABB: {
if (buf) {
AABB aabb = p_variant;
encode_float(aabb.position.x, &buf[0]);
@ -1025,12 +959,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::BASIS: {
if (buf) {
Basis val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
memcpy(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float));
}
}
@ -1040,12 +972,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::TRANSFORM: {
if (buf) {
Transform val = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
memcpy(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float));
}
}
@ -1061,7 +991,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
// misc types
case Variant::COLOR: {
if (buf) {
Color c = p_variant;
encode_float(c.r, &buf[0]);
@ -1074,12 +1003,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::_RID: {
} break;
case Variant::OBJECT: {
if (p_full_objects) {
Object *obj = p_variant;
if (!obj) {
if (buf) {
@ -1095,7 +1021,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
int pc = 0;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
continue;
pc++;
@ -1109,7 +1034,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
continue;
@ -1127,7 +1051,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
}
} else {
if (buf) {
Object *obj = p_variant;
ObjectID id = 0;
if (obj && ObjectDB::instance_validate(obj)) {
@ -1142,7 +1065,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::DICTIONARY: {
Dictionary d = p_variant;
if (buf) {
@ -1155,7 +1077,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
d.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
/*
CharString utf8 = E->->utf8();
@ -1185,7 +1106,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::ARRAY: {
Array v = p_variant;
if (buf) {
@ -1196,7 +1116,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (int i = 0; i < v.size(); i++) {
int len;
encode_variant(v.get(i), buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
@ -1208,7 +1127,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
// arrays
case Variant::POOL_BYTE_ARRAY: {
PoolVector<uint8_t> data = p_variant;
int datalen = data.size();
int datasize = sizeof(uint8_t);
@ -1230,7 +1148,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::POOL_INT_ARRAY: {
PoolVector<int> data = p_variant;
int datalen = data.size();
int datasize = sizeof(int32_t);
@ -1247,7 +1164,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::POOL_REAL_ARRAY: {
PoolVector<real_t> data = p_variant;
int datalen = data.size();
int datasize = sizeof(real_t);
@ -1264,7 +1180,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::POOL_STRING_ARRAY: {
PoolVector<String> data = p_variant;
int len = data.size();
@ -1276,7 +1191,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (int i = 0; i < len; i++) {
CharString utf8 = data.get(i).utf8();
if (buf) {
@ -1296,7 +1210,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::POOL_VECTOR2_ARRAY: {
PoolVector<Vector2> data = p_variant;
int len = data.size();
@ -1308,9 +1221,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
for (int i = 0; i < len; i++) {
Vector2 v = data.get(i);
encode_float(v.x, &buf[0]);
@ -1323,7 +1234,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::POOL_VECTOR3_ARRAY: {
PoolVector<Vector3> data = p_variant;
int len = data.size();
@ -1335,9 +1245,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
for (int i = 0; i < len; i++) {
Vector3 v = data.get(i);
encode_float(v.x, &buf[0]);
@ -1351,7 +1259,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
} break;
case Variant::POOL_COLOR_ARRAY: {
PoolVector<Color> data = p_variant;
int len = data.size();
@ -1363,9 +1270,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
if (buf) {
for (int i = 0; i < len; i++) {
Color c = data.get(i);
encode_float(c.r, &buf[0]);

View file

@ -41,21 +41,17 @@
*/
union MarshallFloat {
uint32_t i; ///< int
float f; ///< float
};
union MarshallDouble {
uint64_t l; ///< long long
double d; ///< double
};
static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) {
for (int i = 0; i < 2; i++) {
*p_arr = p_uint & 0xFF;
p_arr++;
p_uint >>= 8;
@ -65,9 +61,7 @@ static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) {
}
static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) {
for (int i = 0; i < 4; i++) {
*p_arr = p_uint & 0xFF;
p_arr++;
p_uint >>= 8;
@ -77,7 +71,6 @@ static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) {
}
static inline unsigned int encode_float(float p_float, uint8_t *p_arr) {
MarshallFloat mf;
mf.f = p_float;
encode_uint32(mf.i, p_arr);
@ -86,9 +79,7 @@ static inline unsigned int encode_float(float p_float, uint8_t *p_arr) {
}
static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) {
for (int i = 0; i < 8; i++) {
*p_arr = p_uint & 0xFF;
p_arr++;
p_uint >>= 8;
@ -98,7 +89,6 @@ static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) {
}
static inline unsigned int encode_double(double p_double, uint8_t *p_arr) {
MarshallDouble md;
md.d = p_double;
encode_uint64(md.l, p_arr);
@ -107,13 +97,10 @@ static inline unsigned int encode_double(double p_double, uint8_t *p_arr) {
}
static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
int len = 0;
while (*p_string) {
if (p_data) {
*p_data = (uint8_t)*p_string;
p_data++;
}
@ -127,11 +114,9 @@ static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
}
static inline uint16_t decode_uint16(const uint8_t *p_arr) {
uint16_t u = 0;
for (int i = 0; i < 2; i++) {
uint16_t b = *p_arr;
b <<= (i * 8);
u |= b;
@ -142,11 +127,9 @@ static inline uint16_t decode_uint16(const uint8_t *p_arr) {
}
static inline uint32_t decode_uint32(const uint8_t *p_arr) {
uint32_t u = 0;
for (int i = 0; i < 4; i++) {
uint32_t b = *p_arr;
b <<= (i * 8);
u |= b;
@ -157,18 +140,15 @@ static inline uint32_t decode_uint32(const uint8_t *p_arr) {
}
static inline float decode_float(const uint8_t *p_arr) {
MarshallFloat mf;
mf.i = decode_uint32(p_arr);
return mf.f;
}
static inline uint64_t decode_uint64(const uint8_t *p_arr) {
uint64_t u = 0;
for (int i = 0; i < 8; i++) {
uint64_t b = (*p_arr) & 0xFF;
b <<= (i * 8);
u |= b;
@ -179,7 +159,6 @@ static inline uint64_t decode_uint64(const uint8_t *p_arr) {
}
static inline double decode_double(const uint8_t *p_arr) {
MarshallDouble md;
md.l = decode_uint64(p_arr);
return md.d;

View file

@ -38,9 +38,7 @@
#endif
_FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_master, bool &r_skip_rpc) {
switch (mode) {
case MultiplayerAPI::RPC_MODE_DISABLED: {
// Do nothing.
} break;
@ -71,7 +69,6 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
_FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, int p_remote_id) {
switch (mode) {
case MultiplayerAPI::RPC_MODE_DISABLED: {
return false;
} break;
@ -93,7 +90,6 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i
}
void MultiplayerAPI::poll() {
if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED)
return;
@ -103,7 +99,6 @@ void MultiplayerAPI::poll() {
return;
while (network_peer->get_available_packet_count()) {
int sender = network_peer->get_packet_peer();
const uint8_t *packet;
int len;
@ -141,7 +136,6 @@ Node *MultiplayerAPI::get_root_node() {
}
void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) {
if (p_peer == network_peer)
return; // Nothing to do
@ -173,7 +167,6 @@ Ref<NetworkedMultiplayerPeer> MultiplayerAPI::get_network_peer() const {
}
void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {
ERR_FAIL_COND_MSG(root_node == NULL, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it.");
ERR_FAIL_COND_MSG(p_packet_len < 1, "Invalid packet received. Size too small.");
@ -188,20 +181,16 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
uint8_t packet_type = p_packet[0];
switch (packet_type) {
case NETWORK_COMMAND_SIMPLIFY_PATH: {
_process_simplify_path(p_from, p_packet, p_packet_len);
} break;
case NETWORK_COMMAND_CONFIRM_PATH: {
_process_confirm_path(p_from, p_packet, p_packet_len);
} break;
case NETWORK_COMMAND_REMOTE_CALL:
case NETWORK_COMMAND_REMOTE_SET: {
ERR_FAIL_COND_MSG(p_packet_len < 6, "Invalid packet received. Size too small.");
Node *node = _process_get_node(p_from, p_packet, p_packet_len);
@ -221,25 +210,21 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
StringName name = String::utf8((const char *)&p_packet[5]);
if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {
_process_rpc(node, name, p_from, p_packet, p_packet_len, len_end + 1);
} else {
_process_rset(node, name, p_from, p_packet, p_packet_len, len_end + 1);
}
} break;
case NETWORK_COMMAND_RAW: {
_process_raw(p_from, p_packet, p_packet_len);
} break;
}
}
Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int p_packet_len) {
uint32_t target = decode_uint32(&p_packet[1]);
Node *node = NULL;
@ -280,7 +265,6 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
}
void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
// Check that remote can call the RPC on this node.
@ -312,7 +296,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
#endif
for (int i = 0; i < argc; i++) {
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
int vlen;
@ -334,7 +317,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
}
void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
// Check that remote can call the RSET on this node.
@ -372,7 +354,6 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p
}
void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
ERR_FAIL_COND_MSG(p_packet_len < 5, "Invalid packet received. Size too small.");
int id = decode_uint32(&p_packet[1]);
@ -407,7 +388,6 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
}
void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small.");
String paths;
@ -428,7 +408,6 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int
List<int> peers_to_add; // If one is missing, take note to add it.
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
if (p_target < 0 && E->get() == -p_target)
continue; // Continue, excluded.
@ -451,7 +430,6 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int
// Those that need to be added, send a message for this.
for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
// Encode function name.
CharString pname = String(p_path).utf8();
int len = encode_cstring(pname.get_data(), NULL);
@ -474,7 +452,6 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int
}
void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) {
ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree.");
@ -563,7 +540,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
if (has_all_peers) {
// They all have verified paths, so send fast.
network_peer->set_target_peer(p_to); // To all of you.
network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
@ -577,7 +553,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
encode_cstring(pname.get_data(), &(packet_cache.write[ofs]));
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
if (p_to < 0 && E->get() == -p_to)
continue; // Continue, excluded.
@ -624,22 +599,18 @@ void MultiplayerAPI::_del_peer(int p_id) {
}
void MultiplayerAPI::_connected_to_server() {
emit_signal("connected_to_server");
}
void MultiplayerAPI::_connection_failed() {
emit_signal("connection_failed");
}
void MultiplayerAPI::_server_disconnected() {
emit_signal("server_disconnected");
}
void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) {
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to call an RPC while no network peer is active.");
ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected.");
@ -668,7 +639,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
if (!skip_rpc) {
#ifdef DEBUG_ENABLED
if (profiling) {
ObjectID id = p_node->get_instance_id();
@ -713,7 +683,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) {
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to RSET while no network peer is active.");
ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to RSET on a node which is not inside SceneTree.");
ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to send an RSET via a network peer which is not connected.");
@ -727,7 +696,6 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
// Check that send mode can use local call.
const Map<StringName, RPCMode>::Element *E = p_node->get_node_rset_mode(p_property);
if (E) {
set_local = _should_call_local(E->get(), is_master, skip_rset);
}
@ -785,7 +753,6 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
Error MultiplayerAPI::send_bytes(PoolVector<uint8_t> p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) {
ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet.");
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no network peer is active.");
ERR_FAIL_COND_V_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a network peer which is not connected.");
@ -802,7 +769,6 @@ Error MultiplayerAPI::send_bytes(PoolVector<uint8_t> p_data, int p_to, Networked
}
void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) {
ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small.");
PoolVector<uint8_t> out;
@ -816,32 +782,27 @@ void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_pac
}
int MultiplayerAPI::get_network_unique_id() const {
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), 0, "No network peer is assigned. Unable to get unique network ID.");
return network_peer->get_unique_id();
}
bool MultiplayerAPI::is_network_server() const {
// XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier?
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. I can't be a server.");
return network_peer->is_server();
}
void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) {
ERR_FAIL_COND_MSG(!network_peer.is_valid(), "No network peer is assigned. Unable to set 'refuse_new_connections'.");
network_peer->set_refuse_new_connections(p_refuse);
}
bool MultiplayerAPI::is_refusing_new_network_connections() const {
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. Unable to get 'refuse_new_connections'.");
return network_peer->is_refusing_new_connections();
}
Vector<int> MultiplayerAPI::get_network_connected_peers() const {
ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), Vector<int>(), "No network peer is assigned. Assume no peers are connected.");
Vector<int> ret;
@ -853,12 +814,10 @@ Vector<int> MultiplayerAPI::get_network_connected_peers() const {
}
void MultiplayerAPI::set_allow_object_decoding(bool p_enable) {
allow_object_decoding = p_enable;
}
bool MultiplayerAPI::is_object_decoding_allowed() const {
return allow_object_decoding;
}

View file

@ -35,7 +35,6 @@
#include "core/reference.h"
class MultiplayerAPI : public Reference {
GDCLASS(MultiplayerAPI, Reference);
public:

View file

@ -33,7 +33,6 @@
NetSocket *(*NetSocket::_create)() = NULL;
NetSocket *NetSocket::create() {
if (_create)
return _create();

View file

@ -35,7 +35,6 @@
#include "core/reference.h"
class NetSocket : public Reference {
protected:
static NetSocket *(*_create)();

View file

@ -31,7 +31,6 @@
#include "networked_multiplayer_peer.h"
void NetworkedMultiplayerPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &NetworkedMultiplayerPeer::set_transfer_mode);
ClassDB::bind_method(D_METHOD("get_transfer_mode"), &NetworkedMultiplayerPeer::get_transfer_mode);
ClassDB::bind_method(D_METHOD("set_target_peer", "id"), &NetworkedMultiplayerPeer::set_target_peer);

View file

@ -34,7 +34,6 @@
#include "core/io/packet_peer.h"
class NetworkedMultiplayerPeer : public PacketPeer {
GDCLASS(NetworkedMultiplayerPeer, PacketPeer);
protected:

View file

@ -42,17 +42,14 @@ PacketPeer::PacketPeer() :
}
void PacketPeer::set_allow_object_decoding(bool p_enable) {
allow_object_decoding = p_enable;
}
bool PacketPeer::is_object_decoding_allowed() const {
return allow_object_decoding;
}
void PacketPeer::set_encode_buffer_max_size(int p_max_size) {
ERR_FAIL_COND_MSG(p_max_size < 1024, "Max encode buffer must be at least 1024 bytes");
ERR_FAIL_COND_MSG(p_max_size > 256 * 1024 * 1024, "Max encode buffer cannot exceed 256 MiB");
encode_buffer_max_size = next_power_of_2(p_max_size);
@ -60,12 +57,10 @@ void PacketPeer::set_encode_buffer_max_size(int p_max_size) {
}
int PacketPeer::get_encode_buffer_max_size() const {
return encode_buffer_max_size;
}
Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) {
const uint8_t *buffer;
int buffer_size;
Error err = get_packet(&buffer, buffer_size);
@ -84,7 +79,6 @@ Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) {
}
Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
int len = p_buffer.size();
if (len == 0)
return OK;
@ -94,7 +88,6 @@ Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
}
Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) {
const uint8_t *buffer;
int buffer_size;
Error err = get_packet(&buffer, buffer_size);
@ -105,7 +98,6 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) {
}
Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) {
int len;
Error err = encode_variant(p_packet, NULL, len, p_full_objects || allow_object_decoding); // compute len first
if (err)
@ -140,19 +132,16 @@ Error PacketPeer::_put_packet(const PoolVector<uint8_t> &p_buffer) {
return put_packet_buffer(p_buffer);
}
PoolVector<uint8_t> PacketPeer::_get_packet() {
PoolVector<uint8_t> raw;
last_get_error = get_packet_buffer(raw);
return raw;
}
Error PacketPeer::_get_packet_error() const {
return last_get_error;
}
void PacketPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_var", "allow_objects"), &PacketPeer::_bnd_get_var, DEFVAL(false));
ClassDB::bind_method(D_METHOD("put_var", "var", "full_objects"), &PacketPeer::put_var, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_packet"), &PacketPeer::_get_packet);
@ -172,13 +161,11 @@ void PacketPeer::_bind_methods() {
/***************/
void PacketPeerStream::_set_stream_peer(REF p_peer) {
ERR_FAIL_COND_MSG(p_peer.is_null(), "It's not a reference to a valid Resource object.");
set_stream_peer(p_peer);
}
void PacketPeerStream::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::set_stream_peer);
ClassDB::bind_method(D_METHOD("get_stream_peer"), &PacketPeerStream::get_stream_peer);
ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size);
@ -192,7 +179,6 @@ void PacketPeerStream::_bind_methods() {
}
Error PacketPeerStream::_poll_buffer() const {
ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
int read = 0;
@ -210,7 +196,6 @@ Error PacketPeerStream::_poll_buffer() const {
}
int PacketPeerStream::get_available_packet_count() const {
_poll_buffer();
uint32_t remaining = ring_buffer.data_left();
@ -219,7 +204,6 @@ int PacketPeerStream::get_available_packet_count() const {
int count = 0;
while (remaining >= 4) {
uint8_t lbuf[4];
ring_buffer.copy(lbuf, ofs, 4);
uint32_t len = decode_uint32(lbuf);
@ -236,7 +220,6 @@ int PacketPeerStream::get_available_packet_count() const {
}
Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
_poll_buffer();
@ -258,7 +241,6 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size)
}
Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
Error err = _poll_buffer(); //won't hurt to poll here too
@ -280,12 +262,10 @@ Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
}
int PacketPeerStream::get_max_packet_size() const {
return output_buffer.size();
}
void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) {
//ERR_FAIL_COND(p_peer.is_null());
if (p_peer.ptr() != peer.ptr()) {
@ -296,12 +276,10 @@ void PacketPeerStream::set_stream_peer(const Ref<StreamPeer> &p_peer) {
}
Ref<StreamPeer> PacketPeerStream::get_stream_peer() const {
return peer;
}
void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
ERR_FAIL_COND_MSG(p_max_size < 0, "Max size of input buffer size cannot be smaller than 0.");
//warning may lose packets
ERR_FAIL_COND_MSG(ring_buffer.data_left(), "Buffer in use, resizing would cause loss of data.");
@ -310,22 +288,18 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) {
}
int PacketPeerStream::get_input_buffer_max_size() const {
return input_buffer.size() - 4;
}
void PacketPeerStream::set_output_buffer_max_size(int p_max_size) {
output_buffer.resize(next_power_of_2(p_max_size + 4));
}
int PacketPeerStream::get_output_buffer_max_size() const {
return output_buffer.size() - 4;
}
PacketPeerStream::PacketPeerStream() {
int rbsize = GLOBAL_GET("network/limits/packet_peer_stream/max_buffer_po2");
ring_buffer.resize(rbsize);

View file

@ -36,7 +36,6 @@
#include "core/ring_buffer.h"
class PacketPeer : public Reference {
GDCLASS(PacketPeer, Reference);
Variant _bnd_get_var(bool p_allow_objects = false);
@ -80,7 +79,6 @@ public:
};
class PacketPeerStream : public PacketPeer {
GDCLASS(PacketPeerStream, PacketPeer);
//the way the buffers work sucks, will change later

View file

@ -36,7 +36,6 @@ PacketPeerDTLS *(*PacketPeerDTLS::_create)() = NULL;
bool PacketPeerDTLS::available = false;
PacketPeerDTLS *PacketPeerDTLS::create() {
if (_create) {
return _create();
}
@ -48,7 +47,6 @@ bool PacketPeerDTLS::is_available() {
}
void PacketPeerDTLS::_bind_methods() {
ClassDB::bind_method(D_METHOD("poll"), &PacketPeerDTLS::poll);
ClassDB::bind_method(D_METHOD("connect_to_peer", "packet_peer", "validate_certs", "for_hostname", "valid_certificate"), &PacketPeerDTLS::connect_to_peer, DEFVAL(true), DEFVAL(String()), DEFVAL(Ref<X509Certificate>()));
ClassDB::bind_method(D_METHOD("get_status"), &PacketPeerDTLS::get_status);

View file

@ -34,7 +34,6 @@
#include "core/io/udp_server.h"
void PacketPeerUDP::set_blocking_mode(bool p_enable) {
blocking = p_enable;
}
@ -68,12 +67,10 @@ Error PacketPeerUDP::leave_multicast_group(IP_Address p_multi_address, String p_
}
String PacketPeerUDP::_get_packet_ip() const {
return get_packet_address();
}
Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) {
IP_Address ip;
if (p_address.is_valid_ip_address()) {
ip = p_address;
@ -88,7 +85,6 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) {
}
int PacketPeerUDP::get_available_packet_count() const {
// TODO we should deprecate this, and expose poll instead!
Error err = const_cast<PacketPeerUDP *>(this)->_poll();
if (err != OK)
@ -98,7 +94,6 @@ int PacketPeerUDP::get_available_packet_count() const {
}
Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
Error err = _poll();
if (err != OK)
return err;
@ -119,7 +114,6 @@ Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
}
Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(!peer_addr.is_valid(), ERR_UNCONFIGURED);
@ -156,12 +150,10 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
}
int PacketPeerUDP::get_max_packet_size() const {
return 512; // uhm maybe not
}
Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@ -258,13 +250,11 @@ void PacketPeerUDP::close() {
}
Error PacketPeerUDP::wait() {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
return _sock->poll(NetSocket::POLL_TYPE_IN, -1);
}
Error PacketPeerUDP::_poll() {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
if (!_sock->is_open()) {
@ -318,29 +308,24 @@ Error PacketPeerUDP::store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_b
}
bool PacketPeerUDP::is_listening() const {
return _sock.is_valid() && _sock->is_open();
}
IP_Address PacketPeerUDP::get_packet_address() const {
return packet_ip;
}
int PacketPeerUDP::get_packet_port() const {
return packet_port;
}
void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) {
ERR_FAIL_COND_MSG(connected, "Destination address cannot be set for connected sockets");
peer_addr = p_address;
peer_port = p_port;
}
void PacketPeerUDP::_bind_methods() {
ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536));
ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close);
ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait);
@ -368,6 +353,5 @@ PacketPeerUDP::PacketPeerUDP() :
}
PacketPeerUDP::~PacketPeerUDP() {
close();
}

View file

@ -35,7 +35,6 @@
#include "core/version.h"
static uint64_t _align(uint64_t p_n, int p_alignment) {
if (p_alignment == 0)
return p_n;
@ -47,22 +46,18 @@ static uint64_t _align(uint64_t p_n, int p_alignment) {
};
static void _pad(FileAccess *p_file, int p_bytes) {
for (int i = 0; i < p_bytes; i++) {
p_file->store_8(0);
};
};
void PCKPacker::_bind_methods() {
ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment"), &PCKPacker::pck_start, DEFVAL(0));
ClassDB::bind_method(D_METHOD("add_file", "pck_path", "source_path"), &PCKPacker::add_file);
ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush, DEFVAL(false));
};
Error PCKPacker::pck_start(const String &p_file, int p_alignment) {
if (file != NULL) {
memdelete(file);
}
@ -80,7 +75,6 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) {
file->store_32(VERSION_PATCH);
for (int i = 0; i < 16; i++) {
file->store_32(0); // reserved
};
@ -90,7 +84,6 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) {
};
Error PCKPacker::add_file(const String &p_file, const String &p_src) {
FileAccess *f = FileAccess::open(p_src, FileAccess::READ);
if (!f) {
return ERR_FILE_CANT_OPEN;
@ -111,7 +104,6 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src) {
};
Error PCKPacker::flush(bool p_verbose) {
ERR_FAIL_COND_V_MSG(!file, ERR_INVALID_PARAMETER, "File must be opened before use.");
// write the index
@ -119,7 +111,6 @@ Error PCKPacker::flush(bool p_verbose) {
file->store_32(files.size());
for (int i = 0; i < files.size(); i++) {
file->store_pascal_string(files[i].path);
files.write[i].offset_offset = file->get_position();
file->store_64(0); // offset
@ -142,11 +133,9 @@ Error PCKPacker::flush(bool p_verbose) {
int count = 0;
for (int i = 0; i < files.size(); i++) {
FileAccess *src = FileAccess::open(files[i].src_path, FileAccess::READ);
uint64_t to_write = files[i].size;
while (to_write > 0) {
int read = src->get_buffer(buf, MIN(to_write, buf_max));
file->store_buffer(buf, read);
to_write -= read;
@ -181,7 +170,6 @@ Error PCKPacker::flush(bool p_verbose) {
};
PCKPacker::PCKPacker() {
file = NULL;
};

View file

@ -36,7 +36,6 @@
class FileAccess;
class PCKPacker : public Reference {
GDCLASS(PCKPacker, Reference);
FileAccess *file;
@ -45,7 +44,6 @@ class PCKPacker : public Reference {
static void _bind_methods();
struct File {
String path;
String src_path;
int size;

View file

@ -93,7 +93,6 @@ enum {
};
void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) {
uint32_t extra = 4 - (p_len % 4);
if (extra < 4) {
for (uint32_t i = 0; i < extra; i++)
@ -102,7 +101,6 @@ void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) {
}
StringName ResourceInteractiveLoaderBinary::_get_string() {
uint32_t id = f->get_32();
if (id & 0x80000000) {
uint32_t len = id & 0x7FFFFFFF;
@ -121,42 +119,32 @@ StringName ResourceInteractiveLoaderBinary::_get_string() {
}
Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
uint32_t type = f->get_32();
print_bl("find property of type: " + itos(type));
switch (type) {
case VARIANT_NIL: {
r_v = Variant();
} break;
case VARIANT_BOOL: {
r_v = bool(f->get_32());
} break;
case VARIANT_INT: {
r_v = int(f->get_32());
} break;
case VARIANT_INT64: {
r_v = int64_t(f->get_64());
} break;
case VARIANT_REAL: {
r_v = f->get_real();
} break;
case VARIANT_DOUBLE: {
r_v = f->get_double();
} break;
case VARIANT_STRING: {
r_v = get_unicode_string();
} break;
case VARIANT_VECTOR2: {
Vector2 v;
v.x = f->get_real();
v.y = f->get_real();
@ -164,7 +152,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_RECT2: {
Rect2 v;
v.position.x = f->get_real();
v.position.y = f->get_real();
@ -174,7 +161,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_VECTOR3: {
Vector3 v;
v.x = f->get_real();
v.y = f->get_real();
@ -182,7 +168,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
r_v = v;
} break;
case VARIANT_PLANE: {
Plane v;
v.normal.x = f->get_real();
v.normal.y = f->get_real();
@ -200,7 +185,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_AABB: {
AABB v;
v.position.x = f->get_real();
v.position.y = f->get_real();
@ -212,7 +196,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_MATRIX32: {
Transform2D v;
v.elements[0].x = f->get_real();
v.elements[0].y = f->get_real();
@ -224,7 +207,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_MATRIX3: {
Basis v;
v.elements[0].x = f->get_real();
v.elements[0].y = f->get_real();
@ -239,7 +221,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_TRANSFORM: {
Transform v;
v.basis.elements[0].x = f->get_real();
v.basis.elements[0].y = f->get_real();
@ -256,7 +237,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
r_v = v;
} break;
case VARIANT_COLOR: {
Color v;
v.r = f->get_real();
v.g = f->get_real();
@ -267,7 +247,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_NODE_PATH: {
Vector<StringName> names;
Vector<StringName> subnames;
bool absolute;
@ -291,15 +270,12 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_RID: {
r_v = f->get_32();
} break;
case VARIANT_OBJECT: {
uint32_t objtype = f->get_32();
switch (objtype) {
case OBJECT_EMPTY: {
//do none
@ -345,7 +321,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
WARN_PRINT("Broken external resource! (index out of size)");
r_v = Variant();
} else {
String exttype = external_resources[erindex].type;
String path = external_resources[erindex].path;
@ -364,14 +339,12 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
default: {
ERR_FAIL_V(ERR_FILE_CORRUPT);
} break;
}
} break;
case VARIANT_DICTIONARY: {
uint32_t len = f->get_32();
Dictionary d; //last bit means shared
len &= 0x7FFFFFFF;
@ -387,7 +360,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
r_v = d;
} break;
case VARIANT_ARRAY: {
uint32_t len = f->get_32();
Array a; //last bit means shared
len &= 0x7FFFFFFF;
@ -402,7 +374,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_RAW_ARRAY: {
uint32_t len = f->get_32();
PoolVector<uint8_t> array;
@ -415,7 +386,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_INT_ARRAY: {
uint32_t len = f->get_32();
PoolVector<int> array;
@ -426,7 +396,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len; i++) {
ptr[i] = BSWAP32(ptr[i]);
}
}
@ -436,7 +405,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
r_v = array;
} break;
case VARIANT_REAL_ARRAY: {
uint32_t len = f->get_32();
PoolVector<real_t> array;
@ -447,7 +415,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len; i++) {
ptr[i] = BSWAP32(ptr[i]);
}
}
@ -458,7 +425,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
r_v = array;
} break;
case VARIANT_STRING_ARRAY: {
uint32_t len = f->get_32();
PoolVector<String> array;
array.resize(len);
@ -470,7 +436,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_VECTOR2_ARRAY: {
uint32_t len = f->get_32();
PoolVector<Vector2> array;
@ -482,7 +447,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len * 2; i++) {
ptr[i] = BSWAP32(ptr[i]);
}
}
@ -497,7 +461,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_VECTOR3_ARRAY: {
uint32_t len = f->get_32();
PoolVector<Vector3> array;
@ -509,7 +472,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len * 3; i++) {
ptr[i] = BSWAP32(ptr[i]);
}
}
@ -524,7 +486,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_COLOR_ARRAY: {
uint32_t len = f->get_32();
PoolVector<Color> array;
@ -536,7 +497,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
{
uint32_t *ptr = (uint32_t *)w.ptr();
for (int i = 0; i < len * 4; i++) {
ptr[i] = BSWAP32(ptr[i]);
}
}
@ -567,7 +527,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
const uint32_t current_version = 0;
if (format_version > current_version) {
ERR_PRINT("Format version for encoded binary image is too new.");
return ERR_PARSE_ERROR;
}
@ -599,10 +558,8 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
Ref<Image> image;
if (encoding == IMAGE_ENCODING_LOSSY && Image::lossy_unpacker) {
image = Image::lossy_unpacker(data);
} else if (encoding == IMAGE_ENCODING_LOSSLESS && Image::lossless_unpacker) {
image = Image::lossless_unpacker(data);
}
_advance_padding(data.size());
@ -621,23 +578,19 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
}
void ResourceInteractiveLoaderBinary::set_local_path(const String &p_local_path) {
res_path = p_local_path;
}
Ref<Resource> ResourceInteractiveLoaderBinary::get_resource() {
return resource;
}
Error ResourceInteractiveLoaderBinary::poll() {
if (error != OK)
return error;
int s = stage;
if (s < external_resources.size()) {
String path = external_resources[s].path;
if (remaps.has(path)) {
@ -645,12 +598,9 @@ Error ResourceInteractiveLoaderBinary::poll() {
}
RES res = ResourceLoader::load(path, external_resources[s].type);
if (res.is_null()) {
if (!ResourceLoader::get_abort_on_missing_resources()) {
ResourceLoader::notify_dependency_error(local_path, path, external_resources[s].type);
} else {
error = ERR_FILE_MISSING_DEPENDENCIES;
ERR_FAIL_V_MSG(error, "Can't load dependency: " + path + ".");
}
@ -666,7 +616,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
s -= external_resources.size();
if (s >= internal_resources.size()) {
error = ERR_BUG;
ERR_FAIL_COND_V(s >= internal_resources.size(), error);
}
@ -678,7 +627,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
int subindex = 0;
if (!main) {
path = internal_resources[s].path;
if (path.begins_with("local://")) {
path = path.replace_first("local://", "");
@ -693,7 +641,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
return error;
}
} else {
if (!ResourceCache::has(res_path))
path = res_path;
}
@ -728,7 +675,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
//set properties
for (int i = 0; i < pc; i++) {
StringName name = _get_string();
if (name == StringName()) {
@ -752,7 +698,6 @@ Error ResourceInteractiveLoaderBinary::poll() {
resource_cache.push_back(res);
if (main) {
f->close();
resource = res;
resource->set_as_translation_remapped(translation_remapped);
@ -765,28 +710,23 @@ Error ResourceInteractiveLoaderBinary::poll() {
return OK;
}
int ResourceInteractiveLoaderBinary::get_stage() const {
return stage;
}
int ResourceInteractiveLoaderBinary::get_stage_count() const {
return external_resources.size() + internal_resources.size();
}
void ResourceInteractiveLoaderBinary::set_translation_remapped(bool p_remapped) {
translation_remapped = p_remapped;
}
static void save_ustring(FileAccess *f, const String &p_string) {
CharString utf8 = p_string.utf8();
f->store_32(utf8.length() + 1);
f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1);
}
static String get_ustring(FileAccess *f) {
int len = f->get_32();
Vector<char> str_buf;
str_buf.resize(len);
@ -797,7 +737,6 @@ static String get_ustring(FileAccess *f) {
}
String ResourceInteractiveLoaderBinary::get_unicode_string() {
int len = f->get_32();
if (len > str_buf.size()) {
str_buf.resize(len);
@ -811,13 +750,11 @@ String ResourceInteractiveLoaderBinary::get_unicode_string() {
}
void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) {
open(p_f);
if (error)
return;
for (int i = 0; i < external_resources.size(); i++) {
String dep = external_resources[i].path;
if (p_add_types && external_resources[i].type != String()) {
@ -829,7 +766,6 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f, List<Str
}
void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
error = OK;
f = p_f;
@ -874,7 +810,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
print_bl("format: " + itos(ver_format));
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
f->close();
ERR_FAIL_MSG(vformat("File '%s' can't be loaded, as it uses a format version (%d) or engine version (%d.%d) which are not supported by your engine version (%s).",
local_path, ver_format, ver_major, ver_minor, VERSION_BRANCH));
@ -891,7 +826,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
uint32_t string_table_size = f->get_32();
string_map.resize(string_table_size);
for (uint32_t i = 0; i < string_table_size; i++) {
StringName s = get_unicode_string();
string_map.write[i] = s;
}
@ -900,7 +834,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
uint32_t ext_resources_size = f->get_32();
for (uint32_t i = 0; i < ext_resources_size; i++) {
ExtResource er;
er.type = get_unicode_string();
@ -913,7 +846,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
uint32_t int_resources_size = f->get_32();
for (uint32_t i = 0; i < int_resources_size; i++) {
IntResource ir;
ir.path = get_unicode_string();
ir.offset = f->get_64();
@ -923,7 +855,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
print_bl("int resources: " + itos(int_resources_size));
if (f->eof_reached()) {
error = ERR_FILE_CORRUPT;
f->close();
ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + ".");
@ -931,7 +862,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) {
}
String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) {
error = OK;
f = p_f;
@ -965,7 +895,6 @@ String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) {
uint32_t ver_format = f->get_32();
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
f->close();
return "";
}
@ -983,13 +912,11 @@ ResourceInteractiveLoaderBinary::ResourceInteractiveLoaderBinary() :
}
ResourceInteractiveLoaderBinary::~ResourceInteractiveLoaderBinary() {
if (f)
memdelete(f);
}
Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
*r_error = ERR_FILE_CANT_OPEN;
@ -1009,7 +936,6 @@ Ref<ResourceInteractiveLoader> ResourceFormatLoaderBinary::load_interactive(cons
}
void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
if (p_type == "") {
get_recognized_extensions(p_extensions);
return;
@ -1026,7 +952,6 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String
}
}
void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_extensions) const {
List<String> extensions;
ClassDB::get_resource_base_extensions(&extensions);
extensions.sort();
@ -1038,12 +963,10 @@ void ResourceFormatLoaderBinary::get_recognized_extensions(List<String> *p_exten
}
bool ResourceFormatLoaderBinary::handles_type(const String &p_type) const {
return true; //handles all
}
void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_path + "'.");
@ -1055,7 +978,6 @@ void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List<Str
}
Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
//Error error=OK;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
@ -1121,7 +1043,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
uint32_t ver_format = f->get_32();
if (ver_format < FORMAT_VERSION_CAN_RENAME_DEPS) {
memdelete(f);
memdelete(fw);
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
@ -1157,7 +1078,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
}
if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) {
memdelete(f);
memdelete(fw);
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED,
@ -1188,7 +1108,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
fw->store_32(string_table_size);
for (uint32_t i = 0; i < string_table_size; i++) {
String s = get_ustring(f);
save_ustring(fw, s);
}
@ -1197,7 +1116,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
uint32_t ext_resources_size = f->get_32();
fw->store_32(ext_resources_size);
for (uint32_t i = 0; i < ext_resources_size; i++) {
String type = get_ustring(f);
String path = get_ustring(f);
@ -1228,7 +1146,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
fw->store_32(int_resources_size);
for (uint32_t i = 0; i < int_resources_size; i++) {
String path = get_ustring(f);
uint64_t offset = f->get_64();
save_ustring(fw, path);
@ -1262,7 +1179,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
}
String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
return ""; //could not rwead
@ -1281,7 +1197,6 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
///////////////////////////////////////////////////////////
void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) {
int extra = 4 - (p_bytes % 4);
if (extra < 4) {
for (int i = 0; i < extra; i++)
@ -1290,27 +1205,21 @@ void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes)
}
void ResourceFormatSaverBinaryInstance::_write_variant(const Variant &p_property, const PropertyInfo &p_hint) {
write_variant(f, p_property, resource_set, external_resources, string_map, p_hint);
}
void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Variant &p_property, Set<RES> &resource_set, Map<RES, int> &external_resources, Map<StringName, int> &string_map, const PropertyInfo &p_hint) {
switch (p_property.get_type()) {
case Variant::NIL: {
f->store_32(VARIANT_NIL);
// don't store anything
} break;
case Variant::BOOL: {
f->store_32(VARIANT_BOOL);
bool val = p_property;
f->store_32(val);
} break;
case Variant::INT: {
int64_t val = p_property;
if (val > 0x7FFFFFFF || val < -(int64_t)0x80000000) {
f->store_32(VARIANT_INT64);
@ -1323,28 +1232,24 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::REAL: {
double d = p_property;
float fl = d;
if (double(fl) != d) {
f->store_32(VARIANT_DOUBLE);
f->store_double(d);
} else {
f->store_32(VARIANT_REAL);
f->store_real(fl);
}
} break;
case Variant::STRING: {
f->store_32(VARIANT_STRING);
String val = p_property;
save_unicode_string(f, val);
} break;
case Variant::VECTOR2: {
f->store_32(VARIANT_VECTOR2);
Vector2 val = p_property;
f->store_real(val.x);
@ -1352,7 +1257,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::RECT2: {
f->store_32(VARIANT_RECT2);
Rect2 val = p_property;
f->store_real(val.position.x);
@ -1362,7 +1266,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::VECTOR3: {
f->store_32(VARIANT_VECTOR3);
Vector3 val = p_property;
f->store_real(val.x);
@ -1371,7 +1274,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::PLANE: {
f->store_32(VARIANT_PLANE);
Plane val = p_property;
f->store_real(val.normal.x);
@ -1381,7 +1283,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::QUAT: {
f->store_32(VARIANT_QUAT);
Quat val = p_property;
f->store_real(val.x);
@ -1391,7 +1292,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::AABB: {
f->store_32(VARIANT_AABB);
AABB val = p_property;
f->store_real(val.position.x);
@ -1403,7 +1303,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::TRANSFORM2D: {
f->store_32(VARIANT_MATRIX32);
Transform2D val = p_property;
f->store_real(val.elements[0].x);
@ -1415,7 +1314,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::BASIS: {
f->store_32(VARIANT_MATRIX3);
Basis val = p_property;
f->store_real(val.elements[0].x);
@ -1430,7 +1328,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::TRANSFORM: {
f->store_32(VARIANT_TRANSFORM);
Transform val = p_property;
f->store_real(val.basis.elements[0].x);
@ -1448,7 +1345,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::COLOR: {
f->store_32(VARIANT_COLOR);
Color val = p_property;
f->store_real(val.r);
@ -1483,14 +1379,12 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::_RID: {
f->store_32(VARIANT_RID);
WARN_PRINT("Can't save RIDs.");
RID val = p_property;
f->store_32(val.get_id());
} break;
case Variant::OBJECT: {
f->store_32(VARIANT_OBJECT);
RES res = p_property;
if (res.is_null()) {
@ -1502,7 +1396,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX);
f->store_32(external_resources[res]);
} else {
if (!resource_set.has(res)) {
f->store_32(OBJECT_EMPTY);
ERR_FAIL_MSG("Resource was not pre cached for the resource section, most likely due to circular reference.");
@ -1515,7 +1408,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::DICTIONARY: {
f->store_32(VARIANT_DICTIONARY);
Dictionary d = p_property;
f->store_32(uint32_t(d.size()));
@ -1524,7 +1416,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
d.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
/*
if (!_check_type(dict[E->get()]))
continue;
@ -1536,18 +1427,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::ARRAY: {
f->store_32(VARIANT_ARRAY);
Array a = p_property;
f->store_32(uint32_t(a.size()));
for (int i = 0; i < a.size(); i++) {
write_variant(f, a[i], resource_set, external_resources, string_map);
}
} break;
case Variant::POOL_BYTE_ARRAY: {
f->store_32(VARIANT_RAW_ARRAY);
PoolVector<uint8_t> arr = p_property;
int len = arr.size();
@ -1558,7 +1446,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::POOL_INT_ARRAY: {
f->store_32(VARIANT_INT_ARRAY);
PoolVector<int> arr = p_property;
int len = arr.size();
@ -1569,7 +1456,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::POOL_REAL_ARRAY: {
f->store_32(VARIANT_REAL_ARRAY);
PoolVector<real_t> arr = p_property;
int len = arr.size();
@ -1581,7 +1467,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::POOL_STRING_ARRAY: {
f->store_32(VARIANT_STRING_ARRAY);
PoolVector<String> arr = p_property;
int len = arr.size();
@ -1593,7 +1478,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::POOL_VECTOR3_ARRAY: {
f->store_32(VARIANT_VECTOR3_ARRAY);
PoolVector<Vector3> arr = p_property;
int len = arr.size();
@ -1607,7 +1491,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::POOL_VECTOR2_ARRAY: {
f->store_32(VARIANT_VECTOR2_ARRAY);
PoolVector<Vector2> arr = p_property;
int len = arr.size();
@ -1620,7 +1503,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
case Variant::POOL_COLOR_ARRAY: {
f->store_32(VARIANT_COLOR_ARRAY);
PoolVector<Color> arr = p_property;
int len = arr.size();
@ -1635,17 +1517,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
} break;
default: {
ERR_FAIL_MSG("Invalid variant.");
}
}
}
void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant, bool p_main) {
switch (p_variant.get_type()) {
case Variant::OBJECT: {
RES res = p_variant.operator RefPtr();
if (res.is_null() || external_resources.has(res))
@ -1669,9 +1548,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
res->get_property_list(&property_list);
for (List<PropertyInfo>::Element *E = property_list.front(); E; E = E->next()) {
if (E->get().usage & PROPERTY_USAGE_STORAGE) {
Variant value = res->get(E->get().name);
if (E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) {
RES sres = value;
@ -1695,11 +1572,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
} break;
case Variant::ARRAY: {
Array varray = p_variant;
int len = varray.size();
for (int i = 0; i < len; i++) {
const Variant &v = varray.get(i);
_find_resources(v);
}
@ -1707,12 +1582,10 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
} break;
case Variant::DICTIONARY: {
Dictionary d = p_variant;
List<Variant> keys;
d.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
_find_resources(E->get());
Variant v = d[E->get()];
_find_resources(v);
@ -1733,7 +1606,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
}
void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const String &p_string, bool p_bit_on_len) {
CharString utf8 = p_string.utf8();
if (p_bit_on_len) {
f->store_32((utf8.length() + 1) | 0x80000000);
@ -1744,7 +1616,6 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const
}
int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) {
StringName s = p_string;
if (string_map.has(s))
return string_map[s];
@ -1755,7 +1626,6 @@ int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string)
}
Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Error err;
if (p_flags & ResourceSaver::FLAG_COMPRESS) {
FileAccessCompressed *fac = memnew(FileAccessCompressed);
@ -1816,9 +1686,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
List<ResourceData> resources;
{
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
ResourceData &rd = resources.push_back(ResourceData())->get();
rd.type = E->get()->get_class();
@ -1826,7 +1694,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
E->get()->get_property_list(&property_list);
for (List<PropertyInfo>::Element *F = property_list.front(); F; F = F->next()) {
if (skip_editor && F->get().name.begins_with("__editor"))
continue;
if ((F->get().usage & PROPERTY_USAGE_STORAGE)) {
@ -1873,7 +1740,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
}
for (int i = 0; i < save_order.size(); i++) {
save_unicode_string(f, save_order[i]->get_save_class());
String path = save_order[i]->get_path();
path = relative_paths ? local_path.path_to_file(path) : path;
@ -1885,10 +1751,8 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
Set<int> used_indices;
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
RES r = E->get();
if (r->get_path() == "" || r->get_path().find("::") != -1) {
if (r->get_subindex() != 0) {
if (used_indices.has(r->get_subindex())) {
r->set_subindex(0); //repeated
@ -1900,7 +1764,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
}
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
RES r = E->get();
if (r->get_path() == "" || r->get_path().find("::") != -1) {
if (r->get_subindex() == 0) {
@ -1931,7 +1794,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
//now actually save the resources
for (List<ResourceData>::Element *E = resources.front(); E; E = E->next()) {
ResourceData &rd = E->get();
ofs_table.push_back(f->get_position());
@ -1939,7 +1801,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
f->store_32(rd.properties.size());
for (List<Property>::Element *F = rd.properties.front(); F; F = F->next()) {
Property &p = F->get();
f->store_32(p.name_idx);
_write_variant(p.value, F->get().pi);
@ -1968,19 +1829,16 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
}
Error ResourceFormatSaverBinary::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
ResourceFormatSaverBinaryInstance saver;
return saver.save(local_path, p_resource, p_flags);
}
bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const {
return true; //all recognized
}
void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
String base = p_resource->get_base_extension().to_lower();
p_extensions->push_back(base);
if (base != "res")
@ -1990,6 +1848,5 @@ void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource,
ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = NULL;
ResourceFormatSaverBinary::ResourceFormatSaverBinary() {
singleton = this;
}

View file

@ -36,7 +36,6 @@
#include "core/os/file_access.h"
class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader {
bool translation_remapped;
String local_path;
String res_path;
@ -111,7 +110,6 @@ public:
};
class ResourceFormatSaverBinaryInstance {
String local_path;
String path;
@ -144,7 +142,6 @@ class ResourceFormatSaverBinaryInstance {
};
struct ResourceData {
String type;
List<Property> properties;
};

View file

@ -38,7 +38,6 @@ bool ResourceFormatImporter::SortImporterByName::operator()(const Ref<ResourceIm
}
Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid) const {
Error err;
FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
@ -64,7 +63,6 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
String error_text;
bool path_found = false; //first match must have priority
while (true) {
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@ -118,12 +116,10 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
}
RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error) {
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
if (r_error)
*r_error = err;
@ -143,7 +139,6 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_
}
void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const {
Set<String> found;
for (int i = 0; i < importers.size(); i++) {
@ -159,7 +154,6 @@ void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extension
}
void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
if (p_type == "") {
get_recognized_extensions(p_extensions);
return;
@ -187,26 +181,21 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_
}
bool ResourceFormatImporter::exists(const String &p_path) const {
return FileAccess::exists(p_path + ".import");
}
bool ResourceFormatImporter::recognize_path(const String &p_path, const String &p_for_type) const {
return FileAccess::exists(p_path + ".import");
}
bool ResourceFormatImporter::can_be_imported(const String &p_path) const {
return ResourceFormatLoader::recognize_path(p_path);
}
int ResourceFormatImporter::get_import_order(const String &p_path) const {
Ref<ResourceImporter> importer;
if (FileAccess::exists(p_path + ".import")) {
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
@ -214,7 +203,6 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const {
importer = get_importer_by_name(pat.importer);
}
} else {
importer = get_importer_by_extension(p_path.get_extension().to_lower());
}
@ -225,9 +213,7 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const {
}
bool ResourceFormatImporter::handles_type(const String &p_type) const {
for (int i = 0; i < importers.size(); i++) {
String res_type = importers[i]->get_resource_type();
if (res_type == String())
continue;
@ -239,12 +225,10 @@ bool ResourceFormatImporter::handles_type(const String &p_type) const {
}
String ResourceFormatImporter::get_internal_resource_path(const String &p_path) const {
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
return String();
}
@ -252,7 +236,6 @@ String ResourceFormatImporter::get_internal_resource_path(const String &p_path)
}
void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List<String> *r_paths) {
Error err;
FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
@ -269,7 +252,6 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat
int lines = 0;
String error_text;
while (true) {
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@ -298,7 +280,6 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat
}
String ResourceFormatImporter::get_import_group_file(const String &p_path) const {
bool valid = true;
PathAndType pat;
_get_path_and_type(p_path, pat, &valid);
@ -306,7 +287,6 @@ String ResourceFormatImporter::get_import_group_file(const String &p_path) const
}
bool ResourceFormatImporter::is_import_valid(const String &p_path) const {
bool valid = true;
PathAndType pat;
_get_path_and_type(p_path, pat, &valid);
@ -314,12 +294,10 @@ bool ResourceFormatImporter::is_import_valid(const String &p_path) const {
}
String ResourceFormatImporter::get_resource_type(const String &p_path) const {
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
return "";
}
@ -331,7 +309,6 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
return Variant();
}
@ -339,12 +316,10 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons
}
void ResourceFormatImporter::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
PathAndType pat;
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
return;
}
@ -352,7 +327,6 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List<String>
}
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String &p_name) const {
for (int i = 0; i < importers.size(); i++) {
if (importers[i]->get_importer_name() == p_name) {
return importers[i];
@ -363,7 +337,6 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String
}
void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List<Ref<ResourceImporter>> *r_importers) {
for (int i = 0; i < importers.size(); i++) {
List<String> local_exts;
importers[i]->get_recognized_extensions(&local_exts);
@ -382,12 +355,10 @@ void ResourceFormatImporter::get_importers(List<Ref<ResourceImporter>> *r_import
}
Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const {
Ref<ResourceImporter> importer;
float priority = 0;
for (int i = 0; i < importers.size(); i++) {
List<String> local_exts;
importers[i]->get_recognized_extensions(&local_exts);
for (List<String>::Element *F = local_exts.front(); F; F = F->next()) {
@ -402,12 +373,10 @@ Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const St
}
String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const {
return "res://.import/" + p_for_file.get_file() + "-" + p_for_file.md5_text();
}
bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const {
bool valid = true;
PathAndType pat;
_get_path_and_type(p_path, pat, &valid);
@ -428,7 +397,6 @@ bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) con
}
String ResourceFormatImporter::get_import_settings_hash() const {
Vector<Ref<ResourceImporter>> sorted_importers = importers;
sorted_importers.sort_custom<SortImporterByName>();

View file

@ -36,7 +36,6 @@
class ResourceImporter;
class ResourceFormatImporter : public ResourceFormatLoader {
struct PathAndType {
String path;
String type;
@ -94,7 +93,6 @@ public:
};
class ResourceImporter : public Reference {
GDCLASS(ResourceImporter, Reference);
public:

View file

@ -44,7 +44,6 @@ Ref<ResourceFormatLoader> ResourceLoader::loader[ResourceLoader::MAX_LOADERS];
int ResourceLoader::loader_count = 0;
Error ResourceInteractiveLoader::wait() {
Error err = poll();
while (err == OK) {
err = poll();
@ -60,7 +59,6 @@ ResourceInteractiveLoader::~ResourceInteractiveLoader() {
}
bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_for_type) const {
String extension = p_path.get_extension();
List<String> extensions;
@ -71,7 +69,6 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_
}
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
if (E->get().nocasecmp_to(extension) == 0)
return true;
}
@ -80,7 +77,6 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_
}
bool ResourceFormatLoader::handles_type(const String &p_type) const {
if (get_script_instance() && get_script_instance()->has_method("handles_type")) {
// I guess custom loaders for custom resources should use "Resource"
return get_script_instance()->call("handles_type", p_type);
@ -90,7 +86,6 @@ bool ResourceFormatLoader::handles_type(const String &p_type) const {
}
String ResourceFormatLoader::get_resource_type(const String &p_path) const {
if (get_script_instance() && get_script_instance()->has_method("get_resource_type")) {
return get_script_instance()->call("get_resource_type", p_path);
}
@ -99,20 +94,17 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const {
}
void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
if (p_type == "" || handles_type(p_type))
get_recognized_extensions(p_extensions);
}
void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) {
for (int i = 0; i < loader_count; i++) {
loader[i]->get_recognized_extensions_for_type(p_type, p_extensions);
}
}
void ResourceInteractiveLoader::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_resource"), &ResourceInteractiveLoader::get_resource);
ClassDB::bind_method(D_METHOD("poll"), &ResourceInteractiveLoader::poll);
ClassDB::bind_method(D_METHOD("wait"), &ResourceInteractiveLoader::wait);
@ -121,7 +113,6 @@ void ResourceInteractiveLoader::_bind_methods() {
}
class ResourceInteractiveLoaderDefault : public ResourceInteractiveLoader {
GDCLASS(ResourceInteractiveLoaderDefault, ResourceInteractiveLoader);
public:
@ -139,7 +130,6 @@ public:
};
Ref<ResourceInteractiveLoader> ResourceFormatLoader::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) {
//either this
Ref<Resource> res = load(p_path, p_original_path, r_error);
if (res.is_null())
@ -155,7 +145,6 @@ bool ResourceFormatLoader::exists(const String &p_path) const {
}
void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const {
if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) {
PoolStringArray exts = get_script_instance()->call("get_recognized_extensions");
@ -169,17 +158,14 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions)
}
RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (get_script_instance() && get_script_instance()->has_method("load")) {
Variant res = get_script_instance()->call("load", p_path, p_original_path);
if (res.get_type() == Variant::INT) {
if (r_error)
*r_error = (Error)res.operator int64_t();
} else {
if (r_error)
*r_error = OK;
return res;
@ -193,7 +179,6 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa
ril->set_local_path(p_original_path);
while (true) {
Error err = ril->poll();
if (err == ERR_FILE_EOF) {
@ -210,7 +195,6 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa
}
void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
if (get_script_instance() && get_script_instance()->has_method("get_dependencies")) {
PoolStringArray deps = get_script_instance()->call("get_dependencies", p_path, p_add_types);
@ -224,9 +208,7 @@ void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *
}
Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
if (get_script_instance() && get_script_instance()->has_method("rename_dependencies")) {
Dictionary deps_dict;
for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) {
deps_dict[E->key()] = E->value();
@ -240,7 +222,6 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<
}
void ResourceFormatLoader::_bind_methods() {
{
MethodInfo info = MethodInfo(Variant::NIL, "load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path"));
info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
@ -257,12 +238,10 @@ void ResourceFormatLoader::_bind_methods() {
///////////////////////////////////
RES ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
bool found = false;
// Try all loaders and pick the first match for the type hint
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(p_path, p_type_hint)) {
continue;
}
@ -287,7 +266,6 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c
}
bool ResourceLoader::_add_to_loading_map(const String &p_path) {
bool success;
loading_map_mutex.lock();
@ -332,7 +310,6 @@ void ResourceLoader::_remove_from_loading_map_and_thread(const String &p_path, T
}
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
if (r_error)
*r_error = ERR_CANT_OPEN;
@ -343,7 +320,6 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
if (!p_no_cache) {
{
bool success = _add_to_loading_map(local_path);
ERR_FAIL_COND_V_MSG(!success, RES(), "Resource: '" + local_path + "' is already being loaded. Cyclic reference?");
@ -417,7 +393,6 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
}
bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
String local_path;
if (p_path.is_rel_path())
local_path = "res://" + p_path;
@ -425,7 +400,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
if (ResourceCache::has(local_path)) {
return true; // If cached, it probably exists
}
@ -434,7 +408,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
// Try all loaders and pick the first match for the type hint
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(path, p_type_hint)) {
continue;
}
@ -447,7 +420,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
}
Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
if (r_error)
*r_error = ERR_CANT_OPEN;
@ -458,12 +430,10 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
if (!p_no_cache) {
bool success = _add_to_loading_map(local_path);
ERR_FAIL_COND_V_MSG(!success, RES(), "Resource: '" + local_path + "' is already being loaded. Cyclic reference?");
if (ResourceCache::has(local_path)) {
print_verbose("Loading resource: " + local_path + " (cached)");
Ref<Resource> res_cached = ResourceCache::get(local_path);
Ref<ResourceInteractiveLoaderDefault> ril = Ref<ResourceInteractiveLoaderDefault>(memnew(ResourceInteractiveLoaderDefault));
@ -488,7 +458,6 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
bool found = false;
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(path, p_type_hint))
continue;
found = true;
@ -517,7 +486,6 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_
}
void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) {
ERR_FAIL_COND(p_format_loader.is_null());
ERR_FAIL_COND(loader_count >= MAX_LOADERS);
@ -533,7 +501,6 @@ void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_form
}
void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader) {
ERR_FAIL_COND(p_format_loader.is_null());
// Find loader
@ -554,7 +521,6 @@ void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_f
}
int ResourceLoader::get_import_order(const String &p_path) {
String path = _path_remap(p_path);
String local_path;
@ -564,7 +530,6 @@ int ResourceLoader::get_import_order(const String &p_path) {
local_path = ProjectSettings::get_singleton()->localize_path(path);
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(local_path))
continue;
/*
@ -588,7 +553,6 @@ String ResourceLoader::get_import_group_file(const String &p_path) {
local_path = ProjectSettings::get_singleton()->localize_path(path);
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(local_path))
continue;
/*
@ -603,7 +567,6 @@ String ResourceLoader::get_import_group_file(const String &p_path) {
}
bool ResourceLoader::is_import_valid(const String &p_path) {
String path = _path_remap(p_path);
String local_path;
@ -613,7 +576,6 @@ bool ResourceLoader::is_import_valid(const String &p_path) {
local_path = ProjectSettings::get_singleton()->localize_path(path);
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(local_path))
continue;
/*
@ -628,7 +590,6 @@ bool ResourceLoader::is_import_valid(const String &p_path) {
}
bool ResourceLoader::is_imported(const String &p_path) {
String path = _path_remap(p_path);
String local_path;
@ -638,7 +599,6 @@ bool ResourceLoader::is_imported(const String &p_path) {
local_path = ProjectSettings::get_singleton()->localize_path(path);
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(local_path))
continue;
/*
@ -653,7 +613,6 @@ bool ResourceLoader::is_imported(const String &p_path) {
}
void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
String path = _path_remap(p_path);
String local_path;
@ -663,7 +622,6 @@ void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_depe
local_path = ProjectSettings::get_singleton()->localize_path(path);
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(local_path))
continue;
/*
@ -676,7 +634,6 @@ void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_depe
}
Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
String path = _path_remap(p_path);
String local_path;
@ -686,7 +643,6 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String
local_path = ProjectSettings::get_singleton()->localize_path(path);
for (int i = 0; i < loader_count; i++) {
if (!loader[i]->recognize_path(local_path))
continue;
/*
@ -701,7 +657,6 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String
}
String ResourceLoader::get_resource_type(const String &p_path) {
String local_path;
if (p_path.is_rel_path())
local_path = "res://" + p_path;
@ -709,7 +664,6 @@ String ResourceLoader::get_resource_type(const String &p_path) {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
for (int i = 0; i < loader_count; i++) {
String result = loader[i]->get_resource_type(local_path);
if (result != "")
return result;
@ -719,7 +673,6 @@ String ResourceLoader::get_resource_type(const String &p_path) {
}
String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) {
String new_path = p_path;
if (translation_remaps.has(p_path)) {
@ -778,7 +731,6 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err);
if (f) {
VariantParser::StreamFile stream;
stream.f = f;
@ -789,7 +741,6 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
int lines = 0;
String error_text;
while (true) {
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
@ -818,9 +769,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
}
String ResourceLoader::import_remap(const String &p_path) {
if (ResourceFormatImporter::get_singleton()->recognize_path(p_path)) {
return ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_path);
}
@ -832,7 +781,6 @@ String ResourceLoader::path_remap(const String &p_path) {
}
void ResourceLoader::reload_translation_remaps() {
ResourceCache::lock.read_lock();
List<Resource *> to_reload;
@ -853,7 +801,6 @@ void ResourceLoader::reload_translation_remaps() {
}
void ResourceLoader::load_translation_remaps() {
if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
return;
@ -861,7 +808,6 @@ void ResourceLoader::load_translation_remaps() {
List<Variant> keys;
remaps.get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
Array langs = remaps[E->get()];
Vector<String> lang_remaps;
lang_remaps.resize(langs.size());
@ -881,7 +827,6 @@ void ResourceLoader::clear_translation_remaps() {
}
void ResourceLoader::load_path_remaps() {
if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths"))
return;
@ -891,13 +836,11 @@ void ResourceLoader::load_path_remaps() {
PoolVector<String>::Read r = remaps.read();
for (int i = 0; i < rc; i += 2) {
path_remaps[r[i]] = r[i + 1];
}
}
void ResourceLoader::clear_path_remaps() {
path_remaps.clear();
}
@ -917,7 +860,6 @@ Ref<ResourceFormatLoader> ResourceLoader::_find_custom_resource_format_loader(St
}
bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
if (_find_custom_resource_format_loader(script_path).is_valid())
return false;
@ -942,7 +884,6 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
}
void ResourceLoader::remove_custom_resource_format_loader(String script_path) {
Ref<ResourceFormatLoader> custom_loader = _find_custom_resource_format_loader(script_path);
if (custom_loader.is_valid())
remove_resource_format_loader(custom_loader);
@ -957,7 +898,6 @@ void ResourceLoader::add_custom_loaders() {
ScriptServer::get_global_class_list(&global_classes);
for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
StringName class_name = E->get();
StringName base_class = ScriptServer::get_global_class_native_base(class_name);
@ -969,7 +909,6 @@ void ResourceLoader::add_custom_loaders() {
}
void ResourceLoader::remove_custom_loaders() {
Vector<Ref<ResourceFormatLoader>> custom_loaders;
for (int i = 0; i < loader_count; ++i) {
if (loader[i]->get_script_instance()) {

View file

@ -35,7 +35,6 @@
#include "core/resource.h"
class ResourceInteractiveLoader : public Reference {
GDCLASS(ResourceInteractiveLoader, Reference);
friend class ResourceLoader;
String path_loading;
@ -58,7 +57,6 @@ public:
};
class ResourceFormatLoader : public Reference {
GDCLASS(ResourceFormatLoader, Reference);
protected:
@ -90,7 +88,6 @@ typedef Error (*ResourceLoaderImport)(const String &p_path);
typedef void (*ResourceLoadedCallback)(RES p_resource, const String &p_path);
class ResourceLoader {
enum {
MAX_LOADERS = 64
};
@ -131,7 +128,6 @@ class ResourceLoader {
}
};
struct LoadingMapKeyHasher {
static _FORCE_INLINE_ uint32_t hash(const LoadingMapKey &p_key) { return p_key.path.hash() + HashMapHasherDefault::hash(p_key.thread); }
};

View file

@ -41,7 +41,6 @@ bool ResourceSaver::timestamp_on_save = false;
ResourceSavedCallback ResourceSaver::save_callback = 0;
Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
if (get_script_instance() && get_script_instance()->has_method("save")) {
return (Error)get_script_instance()->call("save", p_path, p_resource, p_flags).operator int64_t();
}
@ -50,7 +49,6 @@ Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uin
}
bool ResourceFormatSaver::recognize(const RES &p_resource) const {
if (get_script_instance() && get_script_instance()->has_method("recognize")) {
return get_script_instance()->call("recognize", p_resource);
}
@ -59,7 +57,6 @@ bool ResourceFormatSaver::recognize(const RES &p_resource) const {
}
void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) {
PoolStringArray exts = get_script_instance()->call("get_recognized_extensions", p_resource);
@ -73,7 +70,6 @@ void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<
}
void ResourceFormatSaver::_bind_methods() {
{
PropertyInfo arg0 = PropertyInfo(Variant::STRING, "path");
PropertyInfo arg1 = PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource");
@ -86,12 +82,10 @@ void ResourceFormatSaver::_bind_methods() {
}
Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
String extension = p_path.get_extension();
Error err = ERR_FILE_UNRECOGNIZED;
for (int i = 0; i < saver_count; i++) {
if (!saver[i]->recognize(p_resource))
continue;
@ -100,7 +94,6 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
saver[i]->get_recognized_extensions(p_resource, &extensions);
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
if (E->get().nocasecmp_to(extension) == 0)
recognized = true;
}
@ -119,7 +112,6 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
err = saver[i]->save(p_path, p_resource, p_flags);
if (err == OK) {
#ifdef TOOLS_ENABLED
((Resource *)p_resource.ptr())->set_edited(false);
@ -144,20 +136,16 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
}
void ResourceSaver::set_save_callback(ResourceSavedCallback p_callback) {
save_callback = p_callback;
}
void ResourceSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) {
for (int i = 0; i < saver_count; i++) {
saver[i]->get_recognized_extensions(p_resource, p_extensions);
}
}
void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) {
ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object.");
ERR_FAIL_COND(saver_count >= MAX_SAVERS);
@ -173,7 +161,6 @@ void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_
}
void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) {
ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object.");
// Find saver
@ -203,7 +190,6 @@ Ref<ResourceFormatSaver> ResourceSaver::_find_custom_resource_format_saver(Strin
}
bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
if (_find_custom_resource_format_saver(script_path).is_valid())
return false;
@ -228,7 +214,6 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
}
void ResourceSaver::remove_custom_resource_format_saver(String script_path) {
Ref<ResourceFormatSaver> custom_saver = _find_custom_resource_format_saver(script_path);
if (custom_saver.is_valid())
remove_resource_format_saver(custom_saver);
@ -243,7 +228,6 @@ void ResourceSaver::add_custom_savers() {
ScriptServer::get_global_class_list(&global_classes);
for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
StringName class_name = E->get();
StringName base_class = ScriptServer::get_global_class_native_base(class_name);
@ -255,7 +239,6 @@ void ResourceSaver::add_custom_savers() {
}
void ResourceSaver::remove_custom_savers() {
Vector<Ref<ResourceFormatSaver>> custom_savers;
for (int i = 0; i < saver_count; ++i) {
if (saver[i]->get_script_instance()) {

View file

@ -50,7 +50,6 @@ public:
typedef void (*ResourceSavedCallback)(Ref<Resource> p_resource, const String &p_path);
class ResourceSaver {
enum {
MAX_SAVERS = 64
};

View file

@ -33,7 +33,6 @@
#include "core/io/marshalls.h"
Error StreamPeer::_put_data(const PoolVector<uint8_t> &p_data) {
int len = p_data.size();
if (len == 0)
return OK;
@ -42,7 +41,6 @@ Error StreamPeer::_put_data(const PoolVector<uint8_t> &p_data) {
}
Array StreamPeer::_put_partial_data(const PoolVector<uint8_t> &p_data) {
Array ret;
int len = p_data.size();
@ -65,13 +63,11 @@ Array StreamPeer::_put_partial_data(const PoolVector<uint8_t> &p_data) {
}
Array StreamPeer::_get_data(int p_bytes) {
Array ret;
PoolVector<uint8_t> data;
data.resize(p_bytes);
if (data.size() != p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
ret.push_back(PoolVector<uint8_t>());
return ret;
@ -86,13 +82,11 @@ Array StreamPeer::_get_data(int p_bytes) {
}
Array StreamPeer::_get_partial_data(int p_bytes) {
Array ret;
PoolVector<uint8_t> data;
data.resize(p_bytes);
if (data.size() != p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
ret.push_back(PoolVector<uint8_t>());
return ret;
@ -106,7 +100,6 @@ Array StreamPeer::_get_partial_data(int p_bytes) {
if (err != OK) {
data.resize(0);
} else if (received != data.size()) {
data.resize(received);
}
@ -116,12 +109,10 @@ Array StreamPeer::_get_partial_data(int p_bytes) {
}
void StreamPeer::set_big_endian(bool p_enable) {
big_endian = p_enable;
}
bool StreamPeer::is_big_endian_enabled() const {
return big_endian;
}
@ -130,11 +121,9 @@ void StreamPeer::put_u8(uint8_t p_val) {
}
void StreamPeer::put_8(int8_t p_val) {
put_data((const uint8_t *)&p_val, 1);
}
void StreamPeer::put_u16(uint16_t p_val) {
if (big_endian) {
p_val = BSWAP16(p_val);
}
@ -143,7 +132,6 @@ void StreamPeer::put_u16(uint16_t p_val) {
put_data(buf, 2);
}
void StreamPeer::put_16(int16_t p_val) {
if (big_endian) {
p_val = BSWAP16(p_val);
}
@ -152,7 +140,6 @@ void StreamPeer::put_16(int16_t p_val) {
put_data(buf, 2);
}
void StreamPeer::put_u32(uint32_t p_val) {
if (big_endian) {
p_val = BSWAP32(p_val);
}
@ -161,7 +148,6 @@ void StreamPeer::put_u32(uint32_t p_val) {
put_data(buf, 4);
}
void StreamPeer::put_32(int32_t p_val) {
if (big_endian) {
p_val = BSWAP32(p_val);
}
@ -170,7 +156,6 @@ void StreamPeer::put_32(int32_t p_val) {
put_data(buf, 4);
}
void StreamPeer::put_u64(uint64_t p_val) {
if (big_endian) {
p_val = BSWAP64(p_val);
}
@ -179,7 +164,6 @@ void StreamPeer::put_u64(uint64_t p_val) {
put_data(buf, 8);
}
void StreamPeer::put_64(int64_t p_val) {
if (big_endian) {
p_val = BSWAP64(p_val);
}
@ -188,7 +172,6 @@ void StreamPeer::put_64(int64_t p_val) {
put_data(buf, 8);
}
void StreamPeer::put_float(float p_val) {
uint8_t buf[4];
encode_float(p_val, buf);
@ -200,7 +183,6 @@ void StreamPeer::put_float(float p_val) {
put_data(buf, 4);
}
void StreamPeer::put_double(double p_val) {
uint8_t buf[8];
encode_double(p_val, buf);
if (big_endian) {
@ -210,19 +192,16 @@ void StreamPeer::put_double(double p_val) {
put_data(buf, 8);
}
void StreamPeer::put_string(const String &p_string) {
CharString cs = p_string.ascii();
put_u32(cs.length());
put_data((const uint8_t *)cs.get_data(), cs.length());
}
void StreamPeer::put_utf8_string(const String &p_string) {
CharString cs = p_string.utf8();
put_u32(cs.length());
put_data((const uint8_t *)cs.get_data(), cs.length());
}
void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) {
int len = 0;
Vector<uint8_t> buf;
encode_variant(p_variant, NULL, len, p_full_objects);
@ -233,19 +212,16 @@ void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) {
}
uint8_t StreamPeer::get_u8() {
uint8_t buf[1];
get_data(buf, 1);
return buf[0];
}
int8_t StreamPeer::get_8() {
uint8_t buf[1];
get_data(buf, 1);
return buf[0];
}
uint16_t StreamPeer::get_u16() {
uint8_t buf[2];
get_data(buf, 2);
uint16_t r = decode_uint16(buf);
@ -255,7 +231,6 @@ uint16_t StreamPeer::get_u16() {
return r;
}
int16_t StreamPeer::get_16() {
uint8_t buf[2];
get_data(buf, 2);
uint16_t r = decode_uint16(buf);
@ -265,7 +240,6 @@ int16_t StreamPeer::get_16() {
return r;
}
uint32_t StreamPeer::get_u32() {
uint8_t buf[4];
get_data(buf, 4);
uint32_t r = decode_uint32(buf);
@ -275,7 +249,6 @@ uint32_t StreamPeer::get_u32() {
return r;
}
int32_t StreamPeer::get_32() {
uint8_t buf[4];
get_data(buf, 4);
uint32_t r = decode_uint32(buf);
@ -285,7 +258,6 @@ int32_t StreamPeer::get_32() {
return r;
}
uint64_t StreamPeer::get_u64() {
uint8_t buf[8];
get_data(buf, 8);
uint64_t r = decode_uint64(buf);
@ -295,7 +267,6 @@ uint64_t StreamPeer::get_u64() {
return r;
}
int64_t StreamPeer::get_64() {
uint8_t buf[8];
get_data(buf, 8);
uint64_t r = decode_uint64(buf);
@ -305,7 +276,6 @@ int64_t StreamPeer::get_64() {
return r;
}
float StreamPeer::get_float() {
uint8_t buf[4];
get_data(buf, 4);
@ -318,7 +288,6 @@ float StreamPeer::get_float() {
}
double StreamPeer::get_double() {
uint8_t buf[8];
get_data(buf, 8);
@ -330,7 +299,6 @@ double StreamPeer::get_double() {
return decode_double(buf);
}
String StreamPeer::get_string(int p_bytes) {
if (p_bytes < 0)
p_bytes = get_u32();
ERR_FAIL_COND_V(p_bytes < 0, String());
@ -344,7 +312,6 @@ String StreamPeer::get_string(int p_bytes) {
return buf.ptr();
}
String StreamPeer::get_utf8_string(int p_bytes) {
if (p_bytes < 0)
p_bytes = get_u32();
ERR_FAIL_COND_V(p_bytes < 0, String());
@ -360,7 +327,6 @@ String StreamPeer::get_utf8_string(int p_bytes) {
return ret;
}
Variant StreamPeer::get_var(bool p_allow_objects) {
int len = get_32();
Vector<uint8_t> var;
Error err = var.resize(len);
@ -376,7 +342,6 @@ Variant StreamPeer::get_var(bool p_allow_objects) {
}
void StreamPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("put_data", "data"), &StreamPeer::_put_data);
ClassDB::bind_method(D_METHOD("put_partial_data", "data"), &StreamPeer::_put_partial_data);
@ -421,7 +386,6 @@ void StreamPeer::_bind_methods() {
////////////////////////////////
void StreamPeerBuffer::_bind_methods() {
ClassDB::bind_method(D_METHOD("seek", "position"), &StreamPeerBuffer::seek);
ClassDB::bind_method(D_METHOD("get_size"), &StreamPeerBuffer::get_size);
ClassDB::bind_method(D_METHOD("get_position"), &StreamPeerBuffer::get_position);
@ -435,7 +399,6 @@ void StreamPeerBuffer::_bind_methods() {
}
Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {
if (p_bytes <= 0)
return OK;
@ -451,13 +414,11 @@ Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {
}
Error StreamPeerBuffer::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
r_sent = p_bytes;
return put_data(p_data, p_bytes);
}
Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) {
int recv;
get_partial_data(p_buffer, p_bytes, recv);
if (recv != p_bytes)
@ -467,7 +428,6 @@ Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) {
}
Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
if (pointer + p_bytes > data.size()) {
r_received = data.size() - pointer;
if (r_received <= 0) {
@ -488,50 +448,41 @@ Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_
}
int StreamPeerBuffer::get_available_bytes() const {
return data.size() - pointer;
}
void StreamPeerBuffer::seek(int p_pos) {
ERR_FAIL_COND(p_pos < 0);
ERR_FAIL_COND(p_pos > data.size());
pointer = p_pos;
}
int StreamPeerBuffer::get_size() const {
return data.size();
}
int StreamPeerBuffer::get_position() const {
return pointer;
}
void StreamPeerBuffer::resize(int p_size) {
data.resize(p_size);
}
void StreamPeerBuffer::set_data_array(const PoolVector<uint8_t> &p_data) {
data = p_data;
pointer = 0;
}
PoolVector<uint8_t> StreamPeerBuffer::get_data_array() const {
return data;
}
void StreamPeerBuffer::clear() {
data.resize(0);
pointer = 0;
}
Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const {
Ref<StreamPeerBuffer> spb;
spb.instance();
spb->data = data;
@ -539,6 +490,5 @@ Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const {
}
StreamPeerBuffer::StreamPeerBuffer() {
pointer = 0;
}

View file

@ -93,7 +93,6 @@ public:
};
class StreamPeerBuffer : public StreamPeer {
GDCLASS(StreamPeerBuffer, StreamPeer);
PoolVector<uint8_t> data;

View file

@ -35,7 +35,6 @@
StreamPeerSSL *(*StreamPeerSSL::_create)() = NULL;
StreamPeerSSL *StreamPeerSSL::create() {
if (_create)
return _create();
return NULL;
@ -56,7 +55,6 @@ bool StreamPeerSSL::is_blocking_handshake_enabled() const {
}
void StreamPeerSSL::_bind_methods() {
ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll);
ClassDB::bind_method(D_METHOD("accept_stream", "stream", "private_key", "certificate", "chain"), &StreamPeerSSL::accept_stream, DEFVAL(Ref<X509Certificate>()));
ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname", "valid_certificate"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String()), DEFVAL(Ref<X509Certificate>()));

View file

@ -33,7 +33,6 @@
#include "core/project_settings.h"
Error StreamPeerTCP::_poll_connection() {
ERR_FAIL_COND_V(status != STATUS_CONNECTING || !_sock.is_valid() || !_sock->is_open(), FAILED);
Error err = _sock->connect_to_host(peer_host, peer_port);
@ -58,7 +57,6 @@ Error StreamPeerTCP::_poll_connection() {
}
void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port) {
_sock = p_sock;
_sock->set_blocking_enabled(false);
@ -70,7 +68,6 @@ void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint
}
Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER);
@ -103,18 +100,14 @@ Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port)
}
Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
if (status == STATUS_NONE || status == STATUS_ERROR) {
return FAILED;
}
if (status != STATUS_CONNECTED) {
if (_poll_connection() != OK) {
return FAILED;
}
@ -133,12 +126,10 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool
int total_sent = 0;
while (data_to_send) {
int sent_amount = 0;
err = _sock->send(offset, data_to_send, sent_amount);
if (err != OK) {
if (err != ERR_BUSY) {
disconnect_from_host();
return FAILED;
@ -156,7 +147,6 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool
return FAILED;
}
} else {
data_to_send -= sent_amount;
offset += sent_amount;
total_sent += sent_amount;
@ -169,16 +159,12 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool
}
Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) {
if (!is_connected_to_host()) {
return FAILED;
}
if (status == STATUS_CONNECTING) {
if (_poll_connection() != OK) {
return FAILED;
}
@ -194,12 +180,10 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool
r_received = 0;
while (to_read) {
int read = 0;
err = _sock->recv(p_buffer + total_read, to_read, read);
if (err != OK) {
if (err != ERR_BUSY) {
disconnect_from_host();
return FAILED;
@ -218,13 +202,11 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool
}
} else if (read == 0) {
disconnect_from_host();
r_received = total_read;
return ERR_FILE_EOF;
} else {
to_read -= read;
total_read += read;
@ -241,18 +223,15 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool
}
void StreamPeerTCP::set_no_delay(bool p_enabled) {
ERR_FAIL_COND(!is_connected_to_host());
_sock->set_tcp_no_delay_enabled(p_enabled);
}
bool StreamPeerTCP::is_connected_to_host() const {
return _sock.is_valid() && _sock->is_open() && (status == STATUS_CONNECTED || status == STATUS_CONNECTING);
}
StreamPeerTCP::Status StreamPeerTCP::get_status() {
if (status == STATUS_CONNECTING) {
_poll_connection();
} else if (status == STATUS_CONNECTED) {
@ -278,7 +257,6 @@ StreamPeerTCP::Status StreamPeerTCP::get_status() {
}
void StreamPeerTCP::disconnect_from_host() {
if (_sock.is_valid() && _sock->is_open())
_sock->close();
@ -289,45 +267,37 @@ void StreamPeerTCP::disconnect_from_host() {
}
Error StreamPeerTCP::put_data(const uint8_t *p_data, int p_bytes) {
int total;
return write(p_data, p_bytes, total, true);
}
Error StreamPeerTCP::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) {
return write(p_data, p_bytes, r_sent, false);
}
Error StreamPeerTCP::get_data(uint8_t *p_buffer, int p_bytes) {
int total;
return read(p_buffer, p_bytes, total, true);
}
Error StreamPeerTCP::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
return read(p_buffer, p_bytes, r_received, false);
}
int StreamPeerTCP::get_available_bytes() const {
ERR_FAIL_COND_V(!_sock.is_valid(), -1);
return _sock->get_available_bytes();
}
IP_Address StreamPeerTCP::get_connected_host() const {
return peer_host;
}
uint16_t StreamPeerTCP::get_connected_port() const {
return peer_port;
}
Error StreamPeerTCP::_connect(const String &p_address, int p_port) {
IP_Address ip;
if (p_address.is_valid_ip_address()) {
ip = p_address;
@ -341,7 +311,6 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) {
}
void StreamPeerTCP::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &StreamPeerTCP::_connect);
ClassDB::bind_method(D_METHOD("is_connected_to_host"), &StreamPeerTCP::is_connected_to_host);
ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status);
@ -364,6 +333,5 @@ StreamPeerTCP::StreamPeerTCP() :
}
StreamPeerTCP::~StreamPeerTCP() {
disconnect_from_host();
}

View file

@ -37,7 +37,6 @@
#include "core/io/stream_peer.h"
class StreamPeerTCP : public StreamPeer {
GDCLASS(StreamPeerTCP, StreamPeer);
OBJ_CATEGORY("Networking");

View file

@ -31,7 +31,6 @@
#include "tcp_server.h"
void TCP_Server::_bind_methods() {
ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*"));
ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available);
ClassDB::bind_method(D_METHOD("is_listening"), &TCP_Server::is_listening);
@ -40,7 +39,6 @@ void TCP_Server::_bind_methods() {
}
Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@ -62,7 +60,6 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
err = _sock->bind(p_bind_address, p_port);
if (err != OK) {
_sock->close();
return ERR_ALREADY_IN_USE;
}
@ -83,7 +80,6 @@ bool TCP_Server::is_listening() const {
}
bool TCP_Server::is_connection_available() const {
ERR_FAIL_COND_V(!_sock.is_valid(), false);
if (!_sock->is_open())
@ -94,7 +90,6 @@ bool TCP_Server::is_connection_available() const {
}
Ref<StreamPeerTCP> TCP_Server::take_connection() {
Ref<StreamPeerTCP> conn;
if (!is_connection_available()) {
return conn;
@ -113,7 +108,6 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() {
}
void TCP_Server::stop() {
if (_sock.is_valid()) {
_sock->close();
}
@ -124,6 +118,5 @@ TCP_Server::TCP_Server() :
}
TCP_Server::~TCP_Server() {
stop();
}

View file

@ -37,7 +37,6 @@
#include "core/io/stream_peer_tcp.h"
class TCP_Server : public Reference {
GDCLASS(TCP_Server, Reference);
protected:

View file

@ -57,13 +57,11 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
const String path = f->get_path();
while (!is_eof) {
String l = f->get_line().strip_edges();
is_eof = f->eof_reached();
// If we reached last line and it's not a content line, break, otherwise let processing that last loop
if (is_eof && l.empty()) {
if (status == STATUS_READING_ID) {
memdelete(f);
ERR_FAIL_V_MSG(RES(), "Unexpected EOF while reading 'msgid' at: " + path + ":" + itos(line));
@ -73,7 +71,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
if (l.begins_with("msgid")) {
if (status == STATUS_READING_ID) {
memdelete(f);
ERR_FAIL_V_MSG(RES(), "Unexpected 'msgid', was expecting 'msgstr' while parsing: " + path + ":" + itos(line));
@ -94,7 +91,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
if (l.begins_with("msgstr")) {
if (status != STATUS_READING_ID) {
memdelete(f);
ERR_FAIL_V_MSG(RES(), "Unexpected 'msgstr', was expecting 'msgid' while parsing: " + path + ":" + itos(line));
@ -121,7 +117,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
//find final quote
int end_pos = -1;
for (int i = 0; i < l.length(); i++) {
if (l[i] == '"' && (i == 0 || l[i - 1] != '\\')) {
end_pos = i;
break;
@ -147,7 +142,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
memdelete(f);
if (status == STATUS_READING_STRING) {
if (msg_id != "") {
if (!skip_this)
translation->add_message(msg_id, msg_str);
@ -159,7 +153,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
Vector<String> configs = config.split("\n");
for (int i = 0; i < configs.size(); i++) {
String c = configs[i].strip_edges();
int p = c.find(":");
if (p == -1)
@ -179,7 +172,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
*r_error = ERR_CANT_OPEN;
@ -190,16 +182,13 @@ RES TranslationLoaderPO::load(const String &p_path, const String &p_original_pat
}
void TranslationLoaderPO::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("po");
}
bool TranslationLoaderPO::handles_type(const String &p_type) const {
return (p_type == "Translation");
}
String TranslationLoaderPO::get_resource_type(const String &p_path) const {
if (p_path.get_extension().to_lower() == "po")
return "Translation";
return "";

View file

@ -31,7 +31,6 @@
#include "udp_server.h"
void UDPServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &UDPServer::listen, DEFVAL("*"));
ClassDB::bind_method(D_METHOD("poll"), &UDPServer::poll);
ClassDB::bind_method(D_METHOD("is_connection_available"), &UDPServer::is_connection_available);
@ -88,7 +87,6 @@ Error UDPServer::poll() {
}
Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@ -124,7 +122,6 @@ bool UDPServer::is_listening() const {
}
bool UDPServer::is_connection_available() const {
ERR_FAIL_COND_V(!_sock.is_valid(), false);
if (!_sock->is_open())
@ -151,7 +148,6 @@ int UDPServer::get_max_pending_connections() const {
}
Ref<PacketPeerUDP> UDPServer::take_connection() {
Ref<PacketPeerUDP> conn;
if (!is_connection_available()) {
return conn;
@ -174,7 +170,6 @@ void UDPServer::remove_peer(IP_Address p_ip, int p_port) {
}
void UDPServer::stop() {
if (_sock.is_valid()) {
_sock->close();
}
@ -200,6 +195,5 @@ UDPServer::UDPServer() :
}
UDPServer::~UDPServer() {
stop();
}

View file

@ -48,7 +48,6 @@ static bool _equalsn(const CharType *str1, const CharType *str2, int len) {
}
String XMLParser::_replace_special_characters(const String &origstr) {
int pos = origstr.find("&");
int oldPos = 0;
@ -148,7 +147,6 @@ void XMLParser::_ignore_definition() {
}
bool XMLParser::_parse_cdata() {
if (*(P + 1) != '[')
return false;
@ -190,7 +188,6 @@ bool XMLParser::_parse_cdata() {
}
void XMLParser::_parse_comment() {
node_type = NODE_COMMENT;
P += 1;
@ -217,7 +214,6 @@ void XMLParser::_parse_comment() {
}
void XMLParser::_parse_opening_xml_element() {
node_type = NODE_ELEMENT;
node_empty = false;
attributes.clear();
@ -304,7 +300,6 @@ void XMLParser::_parse_opening_xml_element() {
}
void XMLParser::_parse_current_node() {
char *start = P;
node_offset = P - data;
@ -342,12 +337,10 @@ void XMLParser::_parse_current_node() {
}
uint64_t XMLParser::get_node_offset() const {
return node_offset;
};
Error XMLParser::seek(uint64_t p_pos) {
ERR_FAIL_COND_V(!data, ERR_FILE_EOF);
ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF);
@ -357,7 +350,6 @@ Error XMLParser::seek(uint64_t p_pos) {
};
void XMLParser::_bind_methods() {
ClassDB::bind_method(D_METHOD("read"), &XMLParser::read);
ClassDB::bind_method(D_METHOD("get_node_type"), &XMLParser::get_node_type);
ClassDB::bind_method(D_METHOD("get_node_name"), &XMLParser::get_node_name);
@ -386,7 +378,6 @@ void XMLParser::_bind_methods() {
};
Error XMLParser::read() {
// if not end reached, parse the node
if (P && (P - data) < (int64_t)length - 1 && *P != 0) {
_parse_current_node();
@ -397,11 +388,9 @@ Error XMLParser::read() {
}
XMLParser::NodeType XMLParser::get_node_type() {
return node_type;
}
String XMLParser::get_node_data() const {
ERR_FAIL_COND_V(node_type != NODE_TEXT, "");
return node_name;
}
@ -411,21 +400,17 @@ String XMLParser::get_node_name() const {
return node_name;
}
int XMLParser::get_attribute_count() const {
return attributes.size();
}
String XMLParser::get_attribute_name(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, attributes.size(), "");
return attributes[p_idx].name;
}
String XMLParser::get_attribute_value(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, attributes.size(), "");
return attributes[p_idx].value;
}
bool XMLParser::has_attribute(const String &p_name) const {
for (int i = 0; i < attributes.size(); i++) {
if (attributes[i].name == p_name)
return true;
@ -434,7 +419,6 @@ bool XMLParser::has_attribute(const String &p_name) const {
return false;
}
String XMLParser::get_attribute_value(const String &p_name) const {
int idx = -1;
for (int i = 0; i < attributes.size(); i++) {
if (attributes[i].name == p_name) {
@ -449,7 +433,6 @@ String XMLParser::get_attribute_value(const String &p_name) const {
}
String XMLParser::get_attribute_value_safe(const String &p_name) const {
int idx = -1;
for (int i = 0; i < attributes.size(); i++) {
if (attributes[i].name == p_name) {
@ -463,12 +446,10 @@ String XMLParser::get_attribute_value_safe(const String &p_name) const {
return attributes[idx].value;
}
bool XMLParser::is_empty() const {
return node_empty;
}
Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) {
ERR_FAIL_COND_V(p_buffer.size() == 0, ERR_INVALID_DATA);
if (data) {
@ -484,7 +465,6 @@ Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) {
}
Error XMLParser::open(const String &p_path) {
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::READ, &err);
@ -508,7 +488,6 @@ Error XMLParser::open(const String &p_path) {
}
void XMLParser::skip_section() {
// skip if this element is empty anyway.
if (is_empty())
return;
@ -526,7 +505,6 @@ void XMLParser::skip_section() {
}
void XMLParser::close() {
if (data)
memdelete_arr(data);
data = NULL;
@ -538,12 +516,10 @@ void XMLParser::close() {
}
int XMLParser::get_current_line() const {
return 0;
}
XMLParser::XMLParser() {
data = NULL;
close();
special_characters.push_back("&amp;");
@ -553,7 +529,6 @@ XMLParser::XMLParser() {
special_characters.push_back("'apos;");
}
XMLParser::~XMLParser() {
if (data)
memdelete_arr(data);
}

View file

@ -41,7 +41,6 @@
*/
class XMLParser : public Reference {
GDCLASS(XMLParser, Reference);
public:

View file

@ -31,7 +31,6 @@
#include "zip_io.h"
void *zipio_open(void *data, const char *p_fname, int mode) {
FileAccess *&f = *(FileAccess **)data;
String fname;
@ -40,7 +39,6 @@ void *zipio_open(void *data, const char *p_fname, int mode) {
if (mode & ZLIB_FILEFUNC_MODE_WRITE) {
f = FileAccess::open(fname, FileAccess::WRITE);
} else {
f = FileAccess::open(fname, FileAccess::READ);
}
@ -51,31 +49,26 @@ void *zipio_open(void *data, const char *p_fname, int mode) {
}
uLong zipio_read(void *data, void *fdata, void *buf, uLong size) {
FileAccess *f = *(FileAccess **)data;
return f->get_buffer((uint8_t *)buf, size);
}
uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) {
FileAccess *f = *(FileAccess **)opaque;
f->store_buffer((uint8_t *)buf, size);
return size;
}
long zipio_tell(voidpf opaque, voidpf stream) {
FileAccess *f = *(FileAccess **)opaque;
return f->get_position();
}
long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
FileAccess *f = *(FileAccess **)opaque;
int pos = offset;
switch (origin) {
case ZLIB_FILEFUNC_SEEK_CUR:
pos = f->get_position() + offset;
break;
@ -91,7 +84,6 @@ long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) {
}
int zipio_close(voidpf opaque, voidpf stream) {
FileAccess *&f = *(FileAccess **)opaque;
if (f) {
f->close();
@ -102,25 +94,21 @@ int zipio_close(voidpf opaque, voidpf stream) {
}
int zipio_testerror(voidpf opaque, voidpf stream) {
FileAccess *f = *(FileAccess **)opaque;
return (f && f->get_error() != OK) ? 1 : 0;
}
voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) {
voidpf ptr = memalloc(items * size);
memset(ptr, 0, items * size);
return ptr;
}
void zipio_free(voidpf opaque, voidpf address) {
memfree(address);
}
zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file) {
zlib_filefunc_def io;
io.opaque = p_file;
io.zopen_file = zipio_open;

View file

@ -49,7 +49,6 @@ class List {
public:
class Element {
private:
friend class List<T, A>;
@ -63,14 +62,12 @@ public:
* Get NEXT Element iterator, for constant lists.
*/
_FORCE_INLINE_ const Element *next() const {
return next_ptr;
};
/**
* Get NEXT Element iterator,
*/
_FORCE_INLINE_ Element *next() {
return next_ptr;
};
@ -78,14 +75,12 @@ public:
* Get PREV Element iterator, for constant lists.
*/
_FORCE_INLINE_ const Element *prev() const {
return prev_ptr;
};
/**
* Get PREV Element iterator,
*/
_FORCE_INLINE_ Element *prev() {
return prev_ptr;
};
@ -99,7 +94,6 @@ public:
* operator->, for using as iterator->, when iterators are defined on stack, for constant lists.
*/
_FORCE_INLINE_ const T *operator->() const {
return &value;
};
/**
@ -135,7 +129,6 @@ public:
};
void erase() {
data->erase(this);
}
@ -148,13 +141,11 @@ public:
private:
struct _Data {
Element *first;
Element *last;
int size_cache;
bool erase(const Element *p_I) {
ERR_FAIL_COND_V(!p_I, false);
ERR_FAIL_COND_V(p_I->data != this, false);
@ -185,7 +176,6 @@ public:
* return a const iterator to the beginning of the list.
*/
_FORCE_INLINE_ const Element *front() const {
return _data ? _data->first : 0;
};
@ -200,7 +190,6 @@ public:
* return a const iterator to the last member of the list.
*/
_FORCE_INLINE_ const Element *back() const {
return _data ? _data->last : 0;
};
@ -208,7 +197,6 @@ public:
* return an iterator to the last member of the list.
*/
_FORCE_INLINE_ Element *back() {
return _data ? _data->last : 0;
};
@ -216,9 +204,7 @@ public:
* store a new element at the end of the list
*/
Element *push_back(const T &value) {
if (!_data) {
_data = memnew_allocator(_Data, A);
_data->first = NULL;
_data->last = NULL;
@ -233,7 +219,6 @@ public:
n->data = _data;
if (_data->last) {
_data->last->next_ptr = n;
}
@ -248,7 +233,6 @@ public:
};
void pop_back() {
if (_data && _data->last)
erase(_data->last);
}
@ -257,9 +241,7 @@ public:
* store a new element at the beginning of the list
*/
Element *push_front(const T &value) {
if (!_data) {
_data = memnew_allocator(_Data, A);
_data->first = NULL;
_data->last = NULL;
@ -273,7 +255,6 @@ public:
n->data = _data;
if (_data->first) {
_data->first->prev_ptr = n;
}
@ -288,7 +269,6 @@ public:
};
void pop_front() {
if (_data && _data->first)
erase(_data->first);
}
@ -350,7 +330,6 @@ public:
*/
template <class T_v>
Element *find(const T_v &p_val) {
Element *it = front();
while (it) {
if (it->value == p_val)
@ -365,7 +344,6 @@ public:
* erase an element in the list, by iterator pointing to it. Return true if it was found/erased.
*/
bool erase(const Element *p_I) {
if (_data) {
bool ret = _data->erase(p_I);
@ -384,7 +362,6 @@ public:
* erase the first element in the list, that contains value
*/
bool erase(const T &value) {
Element *I = find(value);
return erase(I);
};
@ -393,7 +370,6 @@ public:
* return whether the list is empty
*/
_FORCE_INLINE_ bool empty() const {
return (!_data || !_data->size_cache);
}
@ -401,19 +377,16 @@ public:
* clear the list
*/
void clear() {
while (front()) {
erase(front());
};
};
_FORCE_INLINE_ int size() const {
return _data ? _data->size_cache : 0;
}
void swap(Element *p_A, Element *p_B) {
ERR_FAIL_COND(!p_A || !p_B);
ERR_FAIL_COND(p_A->data != _data);
ERR_FAIL_COND(p_B->data != _data);
@ -455,26 +428,21 @@ public:
* copy the list
*/
void operator=(const List &p_list) {
clear();
const Element *it = p_list.front();
while (it) {
push_back(it->get());
it = it->next();
}
}
T &operator[](int p_index) {
CRASH_BAD_INDEX(p_index, size());
Element *I = front();
int c = 0;
while (I) {
if (c == p_index) {
return I->get();
}
I = I->next();
@ -485,15 +453,12 @@ public:
}
const T &operator[](int p_index) const {
CRASH_BAD_INDEX(p_index, size());
const Element *I = front();
int c = 0;
while (I) {
if (c == p_index) {
return I->get();
}
I = I->next();
@ -504,7 +469,6 @@ public:
}
void move_to_back(Element *p_I) {
ERR_FAIL_COND(p_I->data != _data);
if (!p_I->next_ptr)
return;
@ -528,12 +492,10 @@ public:
}
void invert() {
int s = size() / 2;
Element *F = front();
Element *B = back();
for (int i = 0; i < s; i++) {
SWAP(F->value, B->value);
F = F->next();
B = B->prev();
@ -541,7 +503,6 @@ public:
}
void move_to_front(Element *p_I) {
ERR_FAIL_COND(p_I->data != _data);
if (!p_I->prev_ptr)
return;
@ -565,7 +526,6 @@ public:
}
void move_before(Element *value, Element *where) {
if (value->prev_ptr) {
value->prev_ptr->next_ptr = value->next_ptr;
} else {
@ -600,13 +560,11 @@ public:
*/
void sort() {
sort_custom<Comparator<T>>();
}
template <class C>
void sort_custom_inplace() {
if (size() < 2)
return;
@ -615,18 +573,15 @@ public:
Element *to = from;
while (current) {
Element *next = current->next_ptr;
if (from != current) {
current->prev_ptr = NULL;
current->next_ptr = from;
Element *find = from;
C less;
while (find && less(find->value, current->value)) {
current->prev_ptr = find;
current->next_ptr = find->next_ptr;
find = find->next_ptr;
@ -642,7 +597,6 @@ public:
else
to = current;
} else {
current->prev_ptr = NULL;
current->next_ptr = NULL;
}
@ -655,17 +609,14 @@ public:
template <class C>
struct AuxiliaryComparator {
C compare;
_FORCE_INLINE_ bool operator()(const Element *a, const Element *b) const {
return compare(a->value, b->value);
}
};
template <class C>
void sort_custom() {
//this version uses auxiliary memory for speed.
//if you don't want to use auxiliary memory, use the in_place version
@ -677,7 +628,6 @@ public:
int idx = 0;
for (Element *E = front(); E; E = E->next_ptr) {
aux_buffer[idx] = E;
idx++;
}
@ -694,7 +644,6 @@ public:
aux_buffer[s - 1]->next_ptr = NULL;
for (int i = 1; i < s - 1; i++) {
aux_buffer[i]->prev_ptr = aux_buffer[i - 1];
aux_buffer[i]->next_ptr = aux_buffer[i + 1];
}
@ -710,11 +659,9 @@ public:
* copy constructor for the list
*/
List(const List &p_list) {
_data = NULL;
const Element *it = p_list.front();
while (it) {
push_back(it->get());
it = it->next();
}
@ -726,7 +673,6 @@ public:
~List() {
clear();
if (_data) {
ERR_FAIL_COND(_data->size_cache);
memdelete_allocator<_Data, A>(_data);
}

View file

@ -39,7 +39,6 @@
template <class K, class V, class C = Comparator<K>, class A = DefaultAllocator>
class Map {
enum Color {
RED,
BLACK
@ -48,7 +47,6 @@ class Map {
public:
class Element {
private:
friend class Map<K, V, C, A>;
int color;
@ -63,19 +61,15 @@ public:
public:
const Element *next() const {
return _next;
}
Element *next() {
return _next;
}
const Element *prev() const {
return _prev;
}
Element *prev() {
return _prev;
}
const K &key() const {
@ -105,7 +99,6 @@ public:
private:
struct _Data {
Element *_root;
Element *_nil;
int size_cache;
@ -123,14 +116,12 @@ private:
}
void _create_root() {
_root = memnew_allocator(Element, A);
_root->parent = _root->left = _root->right = _nil;
_root->color = BLACK;
}
void _free_root() {
if (_root) {
memdelete_allocator<Element, A>(_root);
_root = NULL;
@ -138,7 +129,6 @@ private:
}
~_Data() {
_free_root();
#ifdef GLOBALNIL_DISABLED
@ -150,13 +140,11 @@ private:
_Data _data;
inline void _set_color(Element *p_node, int p_color) {
ERR_FAIL_COND(p_node == _data._nil && p_color == RED);
p_node->color = p_color;
}
inline void _rotate_left(Element *p_node) {
Element *r = p_node->right;
p_node->right = r->left;
if (r->left != _data._nil)
@ -172,7 +160,6 @@ private:
}
inline void _rotate_right(Element *p_node) {
Element *l = p_node->left;
p_node->left = l->right;
if (l->right != _data._nil)
@ -188,18 +175,15 @@ private:
}
inline Element *_successor(Element *p_node) const {
Element *node = p_node;
if (node->right != _data._nil) {
node = node->right;
while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */
node = node->left;
}
return node;
} else {
while (node == node->parent->right) {
node = node->parent;
}
@ -214,14 +198,12 @@ private:
Element *node = p_node;
if (node->left != _data._nil) {
node = node->left;
while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */
node = node->right;
}
return node;
} else {
while (node == node->parent->left) {
node = node->parent;
}
@ -233,7 +215,6 @@ private:
}
Element *_find(const K &p_key) const {
Element *node = _data._root->left;
C less;
@ -250,7 +231,6 @@ private:
}
Element *_find_closest(const K &p_key) const {
Element *node = _data._root->left;
Element *prev = NULL;
C less;
@ -276,7 +256,6 @@ private:
}
void _insert_rb_fix(Element *p_new_node) {
Element *node = p_new_node;
Element *nparent = node->parent;
Element *ngrand_parent;
@ -325,13 +304,11 @@ private:
}
Element *_insert(const K &p_key, const V &p_value) {
Element *new_parent = _data._root;
Element *node = _data._root->left;
C less;
while (node != _data._nil) {
new_parent = node;
if (less(p_key, node->_key))
@ -371,7 +348,6 @@ private:
}
void _erase_fix_rb(Element *p_node) {
Element *root = _data._root->left;
Element *node = _data._nil;
Element *sibling = p_node;
@ -433,7 +409,6 @@ private:
}
void _erase(Element *p_node) {
Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : p_node->_next;
Element *node = (rp->left == _data._nil) ? rp->right : rp->left;
@ -454,7 +429,6 @@ private:
}
if (rp != p_node) {
ERR_FAIL_COND(rp == _data._nil);
rp->left = p_node->left;
@ -484,7 +458,6 @@ private:
}
void _calculate_depth(Element *p_element, int &max_d, int d) const {
if (p_element == _data._nil)
return;
@ -496,7 +469,6 @@ private:
}
void _cleanup_tree(Element *p_element) {
if (p_element == _data._nil)
return;
@ -506,18 +478,15 @@ private:
}
void _copy_from(const Map &p_map) {
clear();
// not the fastest way, but safeset to write.
for (Element *I = p_map.front(); I; I = I->next()) {
insert(I->key(), I->value());
}
}
public:
const Element *find(const K &p_key) const {
if (!_data._root)
return NULL;
@ -526,7 +495,6 @@ public:
}
Element *find(const K &p_key) {
if (!_data._root)
return NULL;
@ -535,7 +503,6 @@ public:
}
const Element *find_closest(const K &p_key) const {
if (!_data._root)
return NULL;
@ -544,7 +511,6 @@ public:
}
Element *find_closest(const K &p_key) {
if (!_data._root)
return NULL;
@ -553,19 +519,16 @@ public:
}
bool has(const K &p_key) const {
return find(p_key) != NULL;
}
Element *insert(const K &p_key, const V &p_value) {
if (!_data._root)
_data._create_root();
return _insert(p_key, p_value);
}
void erase(Element *p_element) {
if (!_data._root || !p_element)
return;
@ -575,7 +538,6 @@ public:
}
bool erase(const K &p_key) {
if (!_data._root)
return false;
@ -590,7 +552,6 @@ public:
}
const V &operator[](const K &p_key) const {
CRASH_COND(!_data._root);
const Element *e = find(p_key);
CRASH_COND(!e);
@ -598,7 +559,6 @@ public:
}
V &operator[](const K &p_key) {
if (!_data._root)
_data._create_root();
@ -610,7 +570,6 @@ public:
}
Element *front() const {
if (!_data._root)
return NULL;
@ -625,7 +584,6 @@ public:
}
Element *back() const {
if (!_data._root)
return NULL;
@ -653,7 +611,6 @@ public:
}
void clear() {
if (!_data._root)
return;
@ -664,12 +621,10 @@ public:
}
void operator=(const Map &p_map) {
_copy_from(p_map);
}
Map(const Map &p_map) {
_copy_from(p_map);
}
@ -677,7 +632,6 @@ public:
}
~Map() {
clear();
}
};

View file

@ -35,7 +35,6 @@
#include "scene/scene_string_names.h"
int AStar::get_available_point_id() const {
if (points.empty()) {
return 1;
}
@ -54,7 +53,6 @@ int AStar::get_available_point_id() const {
}
void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
ERR_FAIL_COND(p_id < 0);
ERR_FAIL_COND(p_weight_scale < 1);
@ -78,7 +76,6 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
}
Vector3 AStar::get_point_position(int p_id) const {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, Vector3());
@ -87,7 +84,6 @@ Vector3 AStar::get_point_position(int p_id) const {
}
void AStar::set_point_position(int p_id, const Vector3 &p_pos) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
@ -96,7 +92,6 @@ void AStar::set_point_position(int p_id, const Vector3 &p_pos) {
}
real_t AStar::get_point_weight_scale(int p_id) const {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, 0);
@ -105,7 +100,6 @@ real_t AStar::get_point_weight_scale(int p_id) const {
}
void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
@ -115,13 +109,11 @@ void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) {
}
void AStar::remove_point(int p_id) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
for (OAHashMap<int, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
Segment s(p_id, (*it.key));
segments.erase(s);
@ -130,7 +122,6 @@ void AStar::remove_point(int p_id) {
}
for (OAHashMap<int, Point *>::Iterator it = p->unlinked_neighbours.iter(); it.valid; it = p->unlinked_neighbours.next_iter(it)) {
Segment s(p_id, (*it.key));
segments.erase(s);
@ -144,7 +135,6 @@ void AStar::remove_point(int p_id) {
}
void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
ERR_FAIL_COND(p_id == p_with_id);
Point *a;
@ -182,7 +172,6 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
}
void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
Point *a;
bool a_exists = points.lookup(p_id, a);
ERR_FAIL_COND(!a_exists);
@ -221,12 +210,10 @@ void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
}
bool AStar::has_point(int p_id) const {
return points.has(p_id);
}
Array AStar::get_points() {
Array point_list;
for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) {
@ -237,7 +224,6 @@ Array AStar::get_points() {
}
PoolVector<int> AStar::get_point_connections(int p_id) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, PoolVector<int>());
@ -252,7 +238,6 @@ PoolVector<int> AStar::get_point_connections(int p_id) {
}
bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) const {
Segment s(p_id, p_with_id);
const Set<Segment>::Element *element = segments.find(s);
@ -261,7 +246,6 @@ bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) co
}
void AStar::clear() {
last_free_id = 0;
for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) {
memdelete(*(it.value));
@ -285,12 +269,10 @@ void AStar::reserve_space(int p_num_nodes) {
}
int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) const {
int closest_id = -1;
real_t closest_dist = 1e20;
for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) {
if (!p_include_disabled && !(*it.value)->enabled)
continue; // Disabled points should not be considered.
@ -311,12 +293,10 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co
}
Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
real_t closest_dist = 1e20;
Vector3 closest_point;
for (const Set<Segment>::Element *E = segments.front(); E; E = E->next()) {
Point *from_point = nullptr, *to_point = nullptr;
points.lookup(E->get().u, from_point);
points.lookup(E->get().v, to_point);
@ -333,7 +313,6 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
Vector3 p = Geometry::get_closest_point_to_segment(p_point, segment);
real_t d = p_point.distance_squared_to(p);
if (d < closest_dist) {
closest_point = p;
closest_dist = d;
}
@ -343,7 +322,6 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
}
bool AStar::_solve(Point *begin_point, Point *end_point) {
pass++;
if (!end_point->enabled)
@ -359,7 +337,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
open_list.push_back(begin_point);
while (!open_list.empty()) {
Point *p = open_list[0]; // The currently processed point
if (p == end_point) {
@ -372,7 +349,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
p->closed_pass = pass; // Mark the point as closed
for (OAHashMap<int, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
Point *e = *(it.value); // The neighbour point
if (!e->enabled || e->closed_pass == pass) {
@ -407,7 +383,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
}
real_t AStar::_estimate_cost(int p_from_id, int p_to_id) {
if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost))
return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id);
@ -423,7 +398,6 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) {
}
real_t AStar::_compute_cost(int p_from_id, int p_to_id) {
if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost))
return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id);
@ -439,7 +413,6 @@ real_t AStar::_compute_cost(int p_from_id, int p_to_id) {
}
PoolVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
Point *a;
bool from_exists = points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, PoolVector<Vector3>());
@ -488,7 +461,6 @@ PoolVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
}
PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
Point *a;
bool from_exists = points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, PoolVector<int>());
@ -537,7 +509,6 @@ PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
}
void AStar::set_point_disabled(int p_id, bool p_disabled) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
@ -546,7 +517,6 @@ void AStar::set_point_disabled(int p_id, bool p_disabled) {
}
bool AStar::is_point_disabled(int p_id) const {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, false);
@ -555,7 +525,6 @@ bool AStar::is_point_disabled(int p_id) const {
}
void AStar::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar::get_available_point_id);
ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar::add_point, DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar::get_point_position);
@ -687,7 +656,6 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const {
}
real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) {
if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost))
return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id);
@ -703,7 +671,6 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) {
}
real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) {
if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost))
return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id);
@ -719,7 +686,6 @@ real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) {
}
PoolVector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) {
AStar::Point *a;
bool from_exists = astar.points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, PoolVector<Vector2>());
@ -768,7 +734,6 @@ PoolVector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) {
}
PoolVector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) {
AStar::Point *a;
bool from_exists = astar.points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, PoolVector<int>());
@ -817,7 +782,6 @@ PoolVector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) {
}
bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
astar.pass++;
if (!end_point->enabled)
@ -833,7 +797,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
open_list.push_back(begin_point);
while (!open_list.empty()) {
AStar::Point *p = open_list[0]; // The currently processed point
if (p == end_point) {
@ -846,7 +809,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
p->closed_pass = astar.pass; // Mark the point as closed
for (OAHashMap<int, AStar::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
AStar::Point *e = *(it.value); // The neighbour point
if (!e->enabled || e->closed_pass == astar.pass) {
@ -881,7 +843,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
}
void AStar2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar2D::get_available_point_id);
ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar2D::add_point, DEFVAL(1.0));
ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar2D::get_point_position);

View file

@ -41,12 +41,10 @@
*/
class AStar : public Reference {
GDCLASS(AStar, Reference);
friend class AStar2D;
struct Point {
Point() :
neighbours(4u),
unlinked_neighbours(4u) {}

View file

@ -33,21 +33,17 @@
#include "core/print_string.h"
real_t AABB::get_area() const {
return size.x * size.y * size.z;
}
bool AABB::operator==(const AABB &p_rval) const {
return ((position == p_rval.position) && (size == p_rval.size));
}
bool AABB::operator!=(const AABB &p_rval) const {
return ((position != p_rval.position) || (size != p_rval.size));
}
void AABB::merge_with(const AABB &p_aabb) {
Vector3 beg_1, beg_2;
Vector3 end_1, end_2;
Vector3 min, max;
@ -70,12 +66,10 @@ void AABB::merge_with(const AABB &p_aabb) {
}
bool AABB::is_equal_approx(const AABB &p_aabb) const {
return position.is_equal_approx(p_aabb.position) && size.is_equal_approx(p_aabb.size);
}
AABB AABB::intersection(const AABB &p_aabb) const {
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@ -86,7 +80,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.x > dst_max.x || src_max.x < dst_min.x)
return AABB();
else {
min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x;
max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x;
}
@ -94,7 +87,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.y > dst_max.y || src_max.y < dst_min.y)
return AABB();
else {
min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y;
max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y;
}
@ -102,7 +94,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
if (src_min.z > dst_max.z || src_max.z < dst_min.z)
return AABB();
else {
min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z;
max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z;
}
@ -111,7 +102,6 @@ AABB AABB::intersection(const AABB &p_aabb) const {
}
bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const {
Vector3 c1, c2;
Vector3 end = position + size;
real_t near = -1e20;
@ -154,7 +144,6 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
}
bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip, Vector3 *r_normal) const {
real_t min = 0, max = 1;
int axis = 0;
real_t sign = 0;
@ -168,7 +157,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
real_t csign;
if (seg_from < seg_to) {
if (seg_from > box_end || seg_to < box_begin)
return false;
real_t length = seg_to - seg_from;
@ -177,7 +165,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
csign = -1.0;
} else {
if (seg_to > box_end || seg_from < box_begin)
return false;
real_t length = seg_to - seg_from;
@ -212,7 +199,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
}
bool AABB::intersects_plane(const Plane &p_plane) const {
Vector3 points[8] = {
Vector3(position.x, position.y, position.z),
Vector3(position.x, position.y, position.z + size.z),
@ -228,7 +214,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
bool under = false;
for (int i = 0; i < 8; i++) {
if (p_plane.distance_to(points[i]) > 0)
over = true;
else
@ -239,7 +224,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
}
Vector3 AABB::get_longest_axis() const {
Vector3 axis(1, 0, 0);
real_t max_size = size.x;
@ -255,7 +239,6 @@ Vector3 AABB::get_longest_axis() const {
return axis;
}
int AABB::get_longest_axis_index() const {
int axis = 0;
real_t max_size = size.x;
@ -272,7 +255,6 @@ int AABB::get_longest_axis_index() const {
}
Vector3 AABB::get_shortest_axis() const {
Vector3 axis(1, 0, 0);
real_t max_size = size.x;
@ -288,7 +270,6 @@ Vector3 AABB::get_shortest_axis() const {
return axis;
}
int AABB::get_shortest_axis_index() const {
int axis = 0;
real_t max_size = size.x;
@ -305,7 +286,6 @@ int AABB::get_shortest_axis_index() const {
}
AABB AABB::merge(const AABB &p_with) const {
AABB aabb = *this;
aabb.merge_with(p_with);
return aabb;
@ -316,24 +296,19 @@ AABB AABB::expand(const Vector3 &p_vector) const {
return aabb;
}
AABB AABB::grow(real_t p_by) const {
AABB aabb = *this;
aabb.grow_by(p_by);
return aabb;
}
void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
ERR_FAIL_INDEX(p_edge, 12);
switch (p_edge) {
case 0: {
r_from = Vector3(position.x + size.x, position.y, position.z);
r_to = Vector3(position.x, position.y, position.z);
} break;
case 1: {
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
r_to = Vector3(position.x + size.x, position.y, position.z);
} break;
@ -343,18 +318,15 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
} break;
case 3: {
r_from = Vector3(position.x, position.y, position.z);
r_to = Vector3(position.x, position.y, position.z + size.z);
} break;
case 4: {
r_from = Vector3(position.x, position.y + size.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 5: {
r_from = Vector3(position.x + size.x, position.y + size.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
} break;
@ -364,31 +336,26 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
} break;
case 7: {
r_from = Vector3(position.x, position.y + size.y, position.z + size.z);
r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 8: {
r_from = Vector3(position.x, position.y, position.z + size.z);
r_to = Vector3(position.x, position.y + size.y, position.z + size.z);
} break;
case 9: {
r_from = Vector3(position.x, position.y, position.z);
r_to = Vector3(position.x, position.y + size.y, position.z);
} break;
case 10: {
r_from = Vector3(position.x + size.x, position.y, position.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
} break;
case 11: {
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
@ -397,6 +364,5 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
}
AABB::operator String() const {
return String() + position + " - " + size;
}

View file

@ -47,12 +47,10 @@ public:
real_t get_area() const; /// get area
_FORCE_INLINE_ bool has_no_area() const {
return (size.x <= 0 || size.y <= 0 || size.z <= 0);
}
_FORCE_INLINE_ bool has_no_surface() const {
return (size.x <= 0 && size.y <= 0 && size.z <= 0);
}
@ -115,7 +113,6 @@ public:
};
inline bool AABB::intersects(const AABB &p_aabb) const {
if (position.x >= (p_aabb.position.x + p_aabb.size.x))
return false;
if ((position.x + size.x) <= p_aabb.position.x)
@ -133,7 +130,6 @@ inline bool AABB::intersects(const AABB &p_aabb) const {
}
inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
if (position.x > (p_aabb.position.x + p_aabb.size.x))
return false;
if ((position.x + size.x) < p_aabb.position.x)
@ -151,7 +147,6 @@ inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
}
inline bool AABB::encloses(const AABB &p_aabb) const {
Vector3 src_min = position;
Vector3 src_max = position + size;
Vector3 dst_min = p_aabb.position;
@ -167,7 +162,6 @@ inline bool AABB::encloses(const AABB &p_aabb) const {
}
Vector3 AABB::get_support(const Vector3 &p_normal) const {
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@ -179,7 +173,6 @@ Vector3 AABB::get_support(const Vector3 &p_normal) const {
}
Vector3 AABB::get_endpoint(int p_point) const {
switch (p_point) {
case 0:
return Vector3(position.x, position.y, position.z);
@ -203,7 +196,6 @@ Vector3 AABB::get_endpoint(int p_point) const {
}
bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const {
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@ -224,7 +216,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con
int bad_point_counts_negative[3] = { 0 };
for (int k = 0; k < 3; k++) {
for (int i = 0; i < p_point_count; i++) {
if (p_points[i].coord[k] > ofs.coord[k] + half_extents.coord[k]) {
bad_point_counts_positive[k]++;
@ -246,7 +237,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con
}
bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
Vector3 half_extents = size * 0.5;
Vector3 ofs = position + half_extents;
@ -265,7 +255,6 @@ bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
}
bool AABB::has_point(const Vector3 &p_point) const {
if (p_point.x < position.x)
return false;
if (p_point.y < position.y)
@ -283,7 +272,6 @@ bool AABB::has_point(const Vector3 &p_point) const {
}
inline void AABB::expand_to(const Vector3 &p_vector) {
Vector3 begin = position;
Vector3 end = position + size;
@ -306,7 +294,6 @@ inline void AABB::expand_to(const Vector3 &p_vector) {
}
void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const {
Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5);
Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z);
@ -317,7 +304,6 @@ void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r
}
inline real_t AABB::get_longest_axis_size() const {
real_t max_size = size.x;
if (size.y > max_size) {
@ -332,7 +318,6 @@ inline real_t AABB::get_longest_axis_size() const {
}
inline real_t AABB::get_shortest_axis_size() const {
real_t max_size = size.x;
if (size.y < max_size) {
@ -347,7 +332,6 @@ inline real_t AABB::get_shortest_axis_size() const {
}
bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const {
real_t divx = 1.0 / p_dir.x;
real_t divy = 1.0 / p_dir.y;
real_t divz = 1.0 / p_dir.z;
@ -391,7 +375,6 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real
}
void AABB::grow_by(real_t p_amount) {
position.x -= p_amount;
position.y -= p_amount;
position.z -= p_amount;

View file

@ -51,7 +51,6 @@ static const float AUDIO_PEAK_OFFSET = 0.0000000001f;
static const float AUDIO_MIN_PEAK_DB = -200.0f; // linear2db(AUDIO_PEAK_OFFSET)
struct AudioFrame {
//left and right samples
float l, r;
@ -108,7 +107,6 @@ struct AudioFrame {
}
_FORCE_INLINE_ AudioFrame linear_interpolate(const AudioFrame &p_b, float p_t) const {
AudioFrame res = *this;
res.l += (p_t * (p_b.l - l));

View file

@ -37,16 +37,13 @@
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
void Basis::from_z(const Vector3 &p_z) {
if (Math::abs(p_z.z) > Math_SQRT12) {
// choose p in y-z plane
real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2];
real_t k = 1.0 / Math::sqrt(a);
elements[0] = Vector3(0, -p_z[2] * k, p_z[1] * k);
elements[1] = Vector3(a * k, -p_z[0] * elements[0][2], p_z[0] * elements[0][1]);
} else {
// choose p in x-y plane
real_t a = p_z.x * p_z.x + p_z.y * p_z.y;
real_t k = 1.0 / Math::sqrt(a);
@ -57,7 +54,6 @@ void Basis::from_z(const Vector3 &p_z) {
}
void Basis::invert() {
real_t co[3] = {
cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)
};
@ -75,7 +71,6 @@ void Basis::invert() {
}
void Basis::orthonormalize() {
// Gram-Schmidt Process
Vector3 x = get_axis(0);
@ -94,7 +89,6 @@ void Basis::orthonormalize() {
}
Basis Basis::orthonormalized() const {
Basis c = *this;
c.orthonormalize();
return c;
@ -119,7 +113,6 @@ bool Basis::is_rotation() const {
}
bool Basis::is_symmetric() const {
if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], UNIT_EPSILON))
return false;
if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], UNIT_EPSILON))
@ -131,7 +124,6 @@ bool Basis::is_symmetric() const {
}
Basis Basis::diagonalize() {
//NOTE: only implemented for symmetric matrices
//with the Jacobi iterative method method
#ifdef MATH_CHECKS
@ -192,21 +184,18 @@ Basis Basis::diagonalize() {
}
Basis Basis::inverse() const {
Basis inv = *this;
inv.invert();
return inv;
}
void Basis::transpose() {
SWAP(elements[0][1], elements[1][0]);
SWAP(elements[0][2], elements[2][0]);
SWAP(elements[1][2], elements[2][1]);
}
Basis Basis::transposed() const {
Basis tr = *this;
tr.transpose();
return tr;
@ -215,7 +204,6 @@ Basis Basis::transposed() const {
// Multiplies the matrix from left by the scaling matrix: M -> S.M
// See the comment for Basis::rotated for further explanation.
void Basis::scale(const Vector3 &p_scale) {
elements[0][0] *= p_scale.x;
elements[0][1] *= p_scale.x;
elements[0][2] *= p_scale.x;
@ -247,7 +235,6 @@ Basis Basis::scaled_local(const Vector3 &p_scale) const {
}
Vector3 Basis::get_scale_abs() const {
return Vector3(
Vector3(elements[0][0], elements[1][0], elements[2][0]).length(),
Vector3(elements[0][1], elements[1][1], elements[2][1]).length(),
@ -328,7 +315,6 @@ void Basis::rotate_local(const Vector3 &p_axis, real_t p_phi) {
*this = rotated_local(p_axis, p_phi);
}
Basis Basis::rotated_local(const Vector3 &p_axis, real_t p_phi) const {
return (*this) * Basis(p_axis, p_phi);
}
@ -417,7 +403,6 @@ void Basis::get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) cons
// the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates
// around the z-axis by a and so on.
Vector3 Basis::get_euler_xyz() const {
// Euler angles in XYZ convention.
// See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix
//
@ -458,7 +443,6 @@ Vector3 Basis::get_euler_xyz() const {
// and similar for other axes.
// The current implementation uses XYZ convention (Z is the first rotation).
void Basis::set_euler_xyz(const Vector3 &p_euler) {
real_t c, s;
c = Math::cos(p_euler.x);
@ -620,7 +604,6 @@ Vector3 Basis::get_euler_yxz() const {
// and similar for other axes.
// The current implementation uses YXZ convention (Z is the first rotation).
void Basis::set_euler_yxz(const Vector3 &p_euler) {
real_t c, s;
c = Math::cos(p_euler.x);
@ -734,12 +717,10 @@ void Basis::set_euler_zyx(const Vector3 &p_euler) {
}
bool Basis::is_equal_approx(const Basis &p_basis) const {
return elements[0].is_equal_approx(p_basis.elements[0]) && elements[1].is_equal_approx(p_basis.elements[1]) && elements[2].is_equal_approx(p_basis.elements[2]);
}
bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsilon) const {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon))
@ -751,7 +732,6 @@ bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsil
}
bool Basis::operator==(const Basis &p_matrix) const {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (elements[i][j] != p_matrix.elements[i][j])
@ -763,17 +743,13 @@ bool Basis::operator==(const Basis &p_matrix) const {
}
bool Basis::operator!=(const Basis &p_matrix) const {
return (!(*this == p_matrix));
}
Basis::operator String() const {
String mtx;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i != 0 || j != 0)
mtx += ", ";
@ -785,7 +761,6 @@ Basis::operator String() const {
}
Quat Basis::get_quat() const {
#ifdef MATH_CHECKS
ERR_FAIL_COND_V_MSG(!is_rotation(), Quat(), "Basis must be normalized in order to be casted to a Quaternion. Use get_rotation_quat() or call orthonormalized() instead.");
#endif
@ -849,12 +824,10 @@ static const Basis _ortho_bases[24] = {
};
int Basis::get_orthogonal_index() const {
//could be sped up if i come up with a way
Basis orth = *this;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
real_t v = orth[i][j];
if (v > 0.5)
v = 1.0;
@ -868,7 +841,6 @@ int Basis::get_orthogonal_index() const {
}
for (int i = 0; i < 24; i++) {
if (_ortho_bases[i] == orth)
return i;
}
@ -877,7 +849,6 @@ int Basis::get_orthogonal_index() const {
}
void Basis::set_orthogonal_index(int p_index) {
//there only exist 24 orthogonal bases in r3
ERR_FAIL_INDEX(p_index, 24);
@ -962,7 +933,6 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
}
void Basis::set_quat(const Quat &p_quat) {
real_t d = p_quat.length_squared();
real_t s = 2.0 / d;
real_t xs = p_quat.x * s, ys = p_quat.y * s, zs = p_quat.z * s;
@ -1034,7 +1004,6 @@ void Basis::set_diagonal(const Vector3 &p_diag) {
}
Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const {
//consider scale
Quat from(*this);
Quat to(p_to);

Some files were not shown because too many files have changed in this diff Show more