diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/io/http_client.cpp | 4 | ||||
-rw-r--r-- | core/io/http_client.h | 4 | ||||
-rw-r--r-- | core/range_iterator.cpp | 169 | ||||
-rw-r--r-- | core/range_iterator.h | 72 | ||||
-rw-r--r-- | core/register_core_types.cpp | 3 | ||||
-rw-r--r-- | core/variant.cpp | 15 | ||||
-rw-r--r-- | core/variant.h | 2 | ||||
-rw-r--r-- | core/variant_op.cpp | 53 |
8 files changed, 72 insertions, 250 deletions
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index b070e52f0a..dd53c8f8eb 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -31,10 +31,6 @@ VARIANT_ENUM_CAST(HTTPClient::Status); -Error HTTPClient::connect_url(const String& p_url) { - - return OK; -} Error HTTPClient::connect(const String &p_host, int p_port, bool p_ssl,bool p_verify_host){ diff --git a/core/io/http_client.h b/core/io/http_client.h index e138681396..e795646c70 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -164,7 +164,7 @@ private: public: - Error connect_url(const String& p_url); //connects to a full url and perform request + //Error connect_and_get(const String& p_url,bool p_verify_host=true); //connects to a full url and perform request Error connect(const String &p_host,int p_port,bool p_ssl=false,bool p_verify_host=true); void set_connection(const Ref<StreamPeer>& p_connection); @@ -192,7 +192,7 @@ public: Error poll(); - String query_string_from_dict(const Dictionary& p_dict); + String query_string_from_dict(const Dictionary& p_dict); HTTPClient(); ~HTTPClient(); diff --git a/core/range_iterator.cpp b/core/range_iterator.cpp deleted file mode 100644 index 9534e011d7..0000000000 --- a/core/range_iterator.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/*************************************************************************/ -/* range_iterator.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "range_iterator.h" -#include "object_type_db.h" - -void RangeIterator::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_iter_init","arg"),&RangeIterator::_iter_init); - ObjectTypeDB::bind_method(_MD("_iter_next","arg"),&RangeIterator::_iter_next); - ObjectTypeDB::bind_method(_MD("_iter_get","arg"),&RangeIterator::_iter_get); - ObjectTypeDB::bind_method(_MD("is_finished"),&RangeIterator::is_finished); - ObjectTypeDB::bind_method(_MD("to_array"),&RangeIterator::to_array); - ObjectTypeDB::bind_method(_MD("set_range","arg1","arg2","arg3"),&RangeIterator::_set_range,DEFVAL(Variant()),DEFVAL(Variant())); -} - -bool RangeIterator::_iter_init(Variant arg) { - return !is_finished(); -} - -bool RangeIterator::_iter_next(Variant arg) { - current += step; - return !is_finished(); -} - -Variant RangeIterator::_iter_get(Variant arg) { - return Variant(current); -} - -bool RangeIterator::is_finished() { - if(step > 0) - { - return current >= stop; - } - else - { - return current <= stop; - } -} - -Array RangeIterator::to_array() { - if (step==0) { - ERR_EXPLAIN("step is zero!"); - ERR_FAIL_V(Array()); - } - - Array arr(true); - if (current >= stop && step > 0) { - return arr; - } - if (current <= stop && step < 0) { - return arr; - } - - //calculate how many - int count=0; - if (step > 0) { - count=((stop-current-1)/step)+1; - } else { - count=((current-stop-1)/-step)+1; - } - - arr.resize(count); - - if (step > 0) { - int idx=0; - for(int i=current;i<stop;i+=step) { - arr[idx++]=i; - } - } else { - int idx=0; - for(int i=current;i>stop;i+=step) { - arr[idx++]=i; - } - } - - return arr; -} - -void RangeIterator::set_range(int stop) { - this->current = 0; - this->stop = stop; - this->step = (stop > 0)?(1):(-1); -} - -void RangeIterator::set_range(int start, int stop) { - this->current = start; - this->stop = stop; - this->step = (stop > start)?(1):(-1); -} - -void RangeIterator::set_range(int start, int stop, int step) { - if(step == 0) - { - ERR_EXPLAIN("step is zero!"); - ERR_FAIL(); - } - - this->current = start; - this->stop = stop; - this->step = step; -} - -Ref<RangeIterator> RangeIterator::_set_range(Variant arg1, Variant arg2, Variant arg3) -{ - bool valid = true; - if(arg1.get_type() == Variant::INT) - { - if(arg2.get_type() == Variant::INT) - { - if(arg3.get_type() == Variant::INT) set_range((int)arg1, (int)arg2, (int)arg3); // (start, end, step) - else if(arg3.get_type() == Variant::NIL) set_range((int)arg1, (int)arg2); // (start, end) - else valid = false; - } - else if(arg2.get_type() == Variant::NIL) set_range((int)arg1); // (end) - else valid = false; - } - else valid = false; - - if(!valid) - { - ERR_EXPLAIN("Invalid type in function 'set_range' in base 'RangeIterator'. Expected 1, 2, or 3 ints."); - ERR_FAIL_V(Ref<RangeIterator>()); - } - return Ref<RangeIterator>(this); -} - -RangeIterator::RangeIterator() { - current = 0; - stop = 0; - step = 0; -} - -RangeIterator::RangeIterator(int stop) { - set_range(stop); -} - -RangeIterator::RangeIterator(int start, int stop) { - set_range(start, stop); -} - -RangeIterator::RangeIterator(int start, int stop, int step) { - set_range(start, stop, step); -} diff --git a/core/range_iterator.h b/core/range_iterator.h deleted file mode 100644 index c3e38a9094..0000000000 --- a/core/range_iterator.h +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************/ -/* range_iterator.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef RANGE_ITERATOR_H -#define RANGE_ITERATOR_H - -#include "reference.h" -#include "variant.h" -#include "array.h" - -class RangeIterator : public Reference -{ -protected: - OBJ_TYPE( RangeIterator, Reference ); - - static void _bind_methods(); - -private: - int current; - int stop; - int step; - - bool _iter_init(Variant arg); - bool _iter_next(Variant arg); - Variant _iter_get(Variant arg); - -public: - - bool is_finished(); - - Array to_array(); - - void set_range(int stop); - void set_range(int start, int stop); - void set_range(int start, int stop, int step); - - Ref<RangeIterator> _set_range(Variant arg1, Variant arg2 = Variant(), Variant arg3 = Variant()); - - void _init(Variant arg1, Variant arg2, Variant arg3); - - RangeIterator(); - RangeIterator(int stop); - RangeIterator(int start, int stop); - RangeIterator(int start, int stop, int step); -}; - -#endif // RANGE_ITERATOR_H diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index c516059cfb..54431cf381 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -52,7 +52,6 @@ #include "func_ref.h" #include "input_map.h" #include "undo_redo.h" -#include "range_iterator.h" #ifdef XML_ENABLED static ResourceFormatSaverXML *resource_saver_xml=NULL; @@ -131,8 +130,6 @@ void register_core_types() { ObjectTypeDB::register_type<Translation>(); ObjectTypeDB::register_type<PHashTranslation>(); ObjectTypeDB::register_type<UndoRedo>(); - ObjectTypeDB::register_type<RangeIterator>(); - ObjectTypeDB::register_type<HTTPClient>(); ObjectTypeDB::register_virtual_type<ResourceInteractiveLoader>(); diff --git a/core/variant.cpp b/core/variant.cpp index 3bd8d80528..1fdbc9f753 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -1116,6 +1116,21 @@ void Variant::reference(const Variant& p_variant) { } +void Variant::zero() { + switch(type) { + case NIL: break; + case BOOL: this->_data._bool = false; break; + case INT: this->_data._int = 0; break; + case REAL: this->_data._real = 0; break; + case VECTOR2: *reinterpret_cast<Vector2*>(this->_data._mem) = Vector2(); break; + case RECT2: *reinterpret_cast<Rect2*>(this->_data._mem) = Rect2(); break; + case VECTOR3: *reinterpret_cast<Vector3*>(this->_data._mem) = Vector3(); break; + case PLANE: *reinterpret_cast<Plane*>(this->_data._mem) = Plane(); break; + case QUAT: *reinterpret_cast<Quat*>(this->_data._mem) = Quat(); break; + case COLOR: *reinterpret_cast<Color*>(this->_data._mem) = Color(); break; + default: this->clear(); break; + } +} void Variant::clear() { switch(type) { diff --git a/core/variant.h b/core/variant.h index b58c781bdd..d8813c4937 100644 --- a/core/variant.h +++ b/core/variant.h @@ -372,6 +372,8 @@ public: return res; } + void zero(); + static void blend(const Variant& a, const Variant& b, float c,Variant &r_dst); static void interpolate(const Variant& a, const Variant& b, float c,Variant &r_dst); struct CallError { diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 204a00e1d5..5463e1cabb 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -3431,6 +3431,59 @@ Variant Variant::iter_get(const Variant& r_iter,bool &r_valid) const { } +void Variant::blend(const Variant& a, const Variant& b, float c, Variant &r_dst) { + if (a.type!=b.type) { + if(a.is_num() && b.is_num()) { + real_t va=a; + real_t vb=b; + r_dst=va + vb * c; + } else { + r_dst=a; + } + return; + } + + switch(a.type) { + case NIL: { r_dst=Variant(); } return; + case INT:{ + int va=a._data._int; + int vb=b._data._int; + r_dst=int(va + vb * c + 0.5); + } return; + case REAL:{ + double ra=a._data._real; + double rb=b._data._real; + r_dst=ra + rb * c; + } return; + case VECTOR2:{ r_dst=*reinterpret_cast<const Vector2*>(a._data._mem)+*reinterpret_cast<const Vector2*>(b._data._mem)*c; } return; + case RECT2:{ + const Rect2 *ra = reinterpret_cast<const Rect2*>(a._data._mem); + const Rect2 *rb = reinterpret_cast<const Rect2*>(b._data._mem); + r_dst=Rect2(ra->pos + rb->pos * c, ra->size + rb->size * c); + } return; + case VECTOR3:{ r_dst=*reinterpret_cast<const Vector2*>(a._data._mem)+*reinterpret_cast<const Vector2*>(b._data._mem)*c; } return; + case _AABB:{ + const AABB *ra = reinterpret_cast<const AABB*>(a._data._mem); + const AABB *rb = reinterpret_cast<const AABB*>(b._data._mem); + r_dst=AABB(ra->pos + rb->pos * c, ra->size + rb->size * c); + } return; + case COLOR:{ + const Color *ca = reinterpret_cast<const Color*>(a._data._mem); + const Color *cb = reinterpret_cast<const Color*>(b._data._mem); + float r = ca->r + cb->r * c; + float g = ca->g + cb->g * c; + float b = ca->b + cb->b * c; + float a = ca->a + cb->a * c; + r = r > 1.0 ? 1.0 : r; + g = g > 1.0 ? 1.0 : g; + b = b > 1.0 ? 1.0 : b; + a = a > 1.0 ? 1.0 : a; + r_dst=Color(r, g, b, a); + } return; + default:{ r_dst = c<0.5 ? a : b; } return; + } +} + void Variant::interpolate(const Variant& a, const Variant& b, float c,Variant &r_dst) { if (a.type!=b.type) { |