aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub1
-rw-r--r--core/bind/core_bind.cpp27
-rw-r--r--core/bind/core_bind.h6
-rw-r--r--core/dvector.h11
-rw-r--r--core/helper/SCsub7
-rw-r--r--core/helper/math_fieldwise.cpp171
-rw-r--r--core/helper/math_fieldwise.h40
-rw-r--r--core/math/math_funcs.h2
-rw-r--r--core/os/os.cpp10
-rw-r--r--core/os/os.h6
-rw-r--r--core/os/power.h44
-rw-r--r--core/variant_call.cpp2
12 files changed, 326 insertions, 1 deletions
diff --git a/core/SCsub b/core/SCsub
index a9721a105..77c828884 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -61,6 +61,7 @@ SConscript('os/SCsub')
SConscript('math/SCsub')
SConscript('io/SCsub')
SConscript('bind/SCsub')
+SConscript('helper/SCsub')
lib = env.Library("core", env.core_sources)
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 54ab51657..e4348cc40 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -450,6 +450,17 @@ bool _OS::is_vsync_enabled() const {
return OS::get_singleton()->is_vsync_enabled();
}
+PowerState _OS::get_power_state() {
+ return OS::get_singleton()->get_power_state();
+}
+
+int _OS::get_power_seconds_left() {
+ return OS::get_singleton()->get_power_seconds_left();
+}
+
+int _OS::get_power_percent_left() {
+ return OS::get_singleton()->get_power_percent_left();
+}
/*
enum Weekday {
@@ -1113,6 +1124,10 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_use_vsync","enable"),&_OS::set_use_vsync);
ClassDB::bind_method(D_METHOD("is_vsync_enabled"),&_OS::is_vsync_enabled);
+ ClassDB::bind_method(D_METHOD("get_power_state"),&_OS::get_power_state);
+ ClassDB::bind_method(D_METHOD("get_power_seconds_left"),&_OS::get_power_seconds_left);
+ ClassDB::bind_method(D_METHOD("get_power_percent_left"),&_OS::get_power_percent_left);
+
BIND_CONSTANT( DAY_SUNDAY );
BIND_CONSTANT( DAY_MONDAY );
BIND_CONSTANT( DAY_TUESDAY );
@@ -1150,6 +1165,12 @@ void _OS::_bind_methods() {
BIND_CONSTANT( SYSTEM_DIR_MUSIC );
BIND_CONSTANT( SYSTEM_DIR_PICTURES );
BIND_CONSTANT( SYSTEM_DIR_RINGTONES );
+
+ BIND_CONSTANT( POWERSTATE_UNKNOWN );
+ BIND_CONSTANT( POWERSTATE_ON_BATTERY );
+ BIND_CONSTANT( POWERSTATE_NO_BATTERY );
+ BIND_CONSTANT( POWERSTATE_CHARGING );
+ BIND_CONSTANT( POWERSTATE_CHARGED );
}
@@ -1221,6 +1242,11 @@ PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3
return r;
}
+Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2& p_point, const Vector2& p_a,const Vector2& p_b) {
+
+ Vector2 s[2]={p_a,p_b};
+ return Geometry::get_closest_point_to_segment_2d(p_point,s);
+}
Vector3 _Geometry::get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b) {
Vector3 s[2]={p_a,p_b};
@@ -1342,6 +1368,7 @@ void _Geometry::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_closest_points_between_segments_2d","p1","q1","p2","q2"),&_Geometry::get_closest_points_between_segments_2d);
ClassDB::bind_method(D_METHOD("get_closest_points_between_segments","p1","p2","q1","q2"),&_Geometry::get_closest_points_between_segments);
+ ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_2d","point","s1","s2"),&_Geometry::get_closest_point_to_segment_2d);
ClassDB::bind_method(D_METHOD("get_closest_point_to_segment","point","s1","s2"),&_Geometry::get_closest_point_to_segment);
ClassDB::bind_method(D_METHOD("get_uv84_normal_bit","normal"),&_Geometry::get_uv84_normal_bit);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 00cbb254d..b6aa87376 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -35,6 +35,7 @@
#include "os/dir_access.h"
#include "os/thread.h"
#include "os/semaphore.h"
+#include "os/power.h"
class _ResourceLoader : public Object {
@@ -308,6 +309,10 @@ public:
void set_use_vsync(bool p_enable);
bool is_vsync_enabled() const;
+ PowerState get_power_state();
+ int get_power_seconds_left();
+ int get_power_percent_left();
+
static _OS *get_singleton() { return singleton; }
_OS();
@@ -334,6 +339,7 @@ public:
Variant segment_intersects_segment_2d(const Vector2& p_from_a,const Vector2& p_to_a,const Vector2& p_from_b,const Vector2& p_to_b);
PoolVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2);
PoolVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2);
+ Vector2 get_closest_point_to_segment_2d(const Vector2& p_point, const Vector2& p_a,const Vector2& p_b);
Vector3 get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b);
Variant ray_intersects_triangle( const Vector3& p_from, const Vector3& p_dir, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
Variant segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2);
diff --git a/core/dvector.h b/core/dvector.h
index 53a29738f..456be4128 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -34,6 +34,7 @@
#include "pool_allocator.h"
#include "safe_refcount.h"
#include "os/rw_lock.h"
+#include "ustring.h"
struct MemoryPool {
@@ -466,6 +467,16 @@ public:
return OK;
}
+ String join(String delimiter) {
+ String rs = "";
+ int s = size();
+ Read r = read();
+ for(int i=0;i<s;i++) {
+ rs += r[i] + delimiter;
+ }
+ rs.erase( rs.length()-delimiter.length(), delimiter.length());
+ return rs;
+ }
bool is_locked() const { return alloc && alloc->lock>0; }
diff --git a/core/helper/SCsub b/core/helper/SCsub
new file mode 100644
index 000000000..4efc90271
--- /dev/null
+++ b/core/helper/SCsub
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+
+Import('env')
+
+env.add_source_files(env.core_sources, "*.cpp")
+
+Export('env')
diff --git a/core/helper/math_fieldwise.cpp b/core/helper/math_fieldwise.cpp
new file mode 100644
index 000000000..204c431e1
--- /dev/null
+++ b/core/helper/math_fieldwise.cpp
@@ -0,0 +1,171 @@
+/*************************************************************************/
+/* fieldwise.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 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. */
+/*************************************************************************/
+
+#ifdef TOOLS_ENABLED
+
+#include "core/helper/math_fieldwise.h"
+
+#define SETUP_TYPE(m_type) m_type source=p_source; m_type target=p_target;
+#define TRY_TRANSFER_FIELD(m_name,m_member) if (p_field==m_name) { target.m_member=source.m_member; }
+
+Variant fieldwise_assign(const Variant& p_target, const Variant& p_source, const String& p_field) {
+
+ ERR_FAIL_COND_V(p_target.get_type()!=p_source.get_type(),p_target);
+
+ switch (p_source.get_type()) {
+
+ case Variant::VECTOR2: {
+
+ SETUP_TYPE(Vector2)
+
+ /**/ TRY_TRANSFER_FIELD("x",x)
+ else TRY_TRANSFER_FIELD("y",y)
+
+ return target;
+ }
+
+ case Variant::RECT2: {
+
+ SETUP_TYPE(Rect2)
+
+ /**/ TRY_TRANSFER_FIELD("x",pos.x)
+ else TRY_TRANSFER_FIELD("y",pos.y)
+ else TRY_TRANSFER_FIELD("w",size.x)
+ else TRY_TRANSFER_FIELD("h",size.y)
+
+ return target;
+ }
+
+ case Variant::VECTOR3: {
+
+ SETUP_TYPE(Vector3)
+
+ /**/ TRY_TRANSFER_FIELD("x",x)
+ else TRY_TRANSFER_FIELD("y",y)
+ else TRY_TRANSFER_FIELD("z",z)
+
+ return target;
+ }
+
+ case Variant::PLANE: {
+
+ SETUP_TYPE(Plane)
+
+ /**/ TRY_TRANSFER_FIELD("x",normal.x)
+ else TRY_TRANSFER_FIELD("y",normal.y)
+ else TRY_TRANSFER_FIELD("z",normal.z)
+ else TRY_TRANSFER_FIELD("d",d)
+
+ return target;
+ }
+
+ case Variant::QUAT: {
+
+ SETUP_TYPE(Quat)
+
+ /**/ TRY_TRANSFER_FIELD("x",x)
+ else TRY_TRANSFER_FIELD("y",y)
+ else TRY_TRANSFER_FIELD("z",z)
+ else TRY_TRANSFER_FIELD("w",w)
+
+ return target;
+ }
+
+ case Variant::RECT3: {
+
+ SETUP_TYPE(Rect3)
+
+ /**/ TRY_TRANSFER_FIELD("px",pos.x)
+ else TRY_TRANSFER_FIELD("py",pos.y)
+ else TRY_TRANSFER_FIELD("pz",pos.z)
+ else TRY_TRANSFER_FIELD("sx",size.x)
+ else TRY_TRANSFER_FIELD("sy",size.y)
+ else TRY_TRANSFER_FIELD("sz",size.z)
+
+ return target;
+ }
+
+ case Variant::TRANSFORM2D: {
+
+ SETUP_TYPE(Transform2D)
+
+ /**/ TRY_TRANSFER_FIELD("xx",elements[0][0])
+ else TRY_TRANSFER_FIELD("xy",elements[0][1])
+ else TRY_TRANSFER_FIELD("yx",elements[1][0])
+ else TRY_TRANSFER_FIELD("yy",elements[1][1])
+ else TRY_TRANSFER_FIELD("ox",elements[2][0])
+ else TRY_TRANSFER_FIELD("oy",elements[2][1])
+
+ return target;
+ }
+
+ case Variant::BASIS: {
+
+ SETUP_TYPE(Basis)
+
+ /**/ TRY_TRANSFER_FIELD("xx",elements[0][0])
+ else TRY_TRANSFER_FIELD("xy",elements[0][1])
+ else TRY_TRANSFER_FIELD("xz",elements[0][2])
+ else TRY_TRANSFER_FIELD("yx",elements[1][0])
+ else TRY_TRANSFER_FIELD("yy",elements[1][1])
+ else TRY_TRANSFER_FIELD("yz",elements[1][2])
+ else TRY_TRANSFER_FIELD("zx",elements[2][0])
+ else TRY_TRANSFER_FIELD("zy",elements[2][1])
+ else TRY_TRANSFER_FIELD("zz",elements[2][2])
+
+ return target;
+ }
+
+ case Variant::TRANSFORM: {
+
+ SETUP_TYPE(Transform)
+
+ /**/ TRY_TRANSFER_FIELD("xx",basis.elements[0][0])
+ else TRY_TRANSFER_FIELD("xy",basis.elements[0][1])
+ else TRY_TRANSFER_FIELD("xz",basis.elements[0][2])
+ else TRY_TRANSFER_FIELD("yx",basis.elements[1][0])
+ else TRY_TRANSFER_FIELD("yy",basis.elements[1][1])
+ else TRY_TRANSFER_FIELD("yz",basis.elements[1][2])
+ else TRY_TRANSFER_FIELD("zx",basis.elements[2][0])
+ else TRY_TRANSFER_FIELD("zy",basis.elements[2][1])
+ else TRY_TRANSFER_FIELD("zz",basis.elements[2][2])
+ else TRY_TRANSFER_FIELD("xo",origin.x)
+ else TRY_TRANSFER_FIELD("yo",origin.y)
+ else TRY_TRANSFER_FIELD("zo",origin.z)
+
+ return target;
+ }
+
+ default: {
+ ERR_FAIL_V(p_target);
+ }
+ }
+}
+
+#endif // TOOLS_ENABLED
diff --git a/core/helper/math_fieldwise.h b/core/helper/math_fieldwise.h
new file mode 100644
index 000000000..31f9af8d0
--- /dev/null
+++ b/core/helper/math_fieldwise.h
@@ -0,0 +1,40 @@
+/*************************************************************************/
+/* fieldwise.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 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 MATH_FIELDWISE_H
+#define MATH_FIELDWISE_H
+
+#ifdef TOOLS_ENABLED
+
+#include "core/variant.h"
+
+Variant fieldwise_assign(const Variant& p_target, const Variant& p_source, const String& p_field);
+
+#endif // TOOLS_ENABLED
+
+#endif // MATH_FIELDWISE_H
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index da7d534a4..ae461eda2 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -50,7 +50,7 @@ public:
Math() {} // useless to instance
enum {
- RANDOM_MAX=2147483647L
+ RANDOM_MAX=4294967295L
};
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 912f7f0b0..1d670b446 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -513,6 +513,16 @@ bool OS::is_vsync_enabled() const{
}
+PowerState OS::get_power_state() {
+ return POWERSTATE_UNKNOWN;
+}
+int OS::get_power_seconds_left() {
+ return -1;
+}
+int OS::get_power_percent_left() {
+ return -1;
+}
+
OS::OS() {
last_error=NULL;
singleton=this;
diff --git a/core/os/os.h b/core/os/os.h
index e179b82da..7c8100679 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -34,8 +34,10 @@
#include "vector.h"
#include "engine.h"
#include "os/main_loop.h"
+#include "power.h"
#include <stdarg.h>
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -402,6 +404,10 @@ public:
virtual void set_use_vsync(bool p_enable);
virtual bool is_vsync_enabled() const;
+
+ virtual PowerState get_power_state();
+ virtual int get_power_seconds_left();
+ virtual int get_power_percent_left();
virtual bool check_feature_support(const String& p_feature)=0;
diff --git a/core/os/power.h b/core/os/power.h
new file mode 100644
index 000000000..c858d391a
--- /dev/null
+++ b/core/os/power.h
@@ -0,0 +1,44 @@
+/*************************************************************************/
+/* power.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 CORE_OS_POWER_H_
+#define CORE_OS_POWER_H_
+
+
+typedef enum
+{
+ POWERSTATE_UNKNOWN, /**< cannot determine power status */
+ POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
+ POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
+ POWERSTATE_CHARGING, /**< Plugged in, charging battery */
+ POWERSTATE_CHARGED /**< Plugged in, battery charged */
+} PowerState;
+
+
+#endif /* CORE_OS_POWER_H_ */
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index b75dfe73e..376e646fc 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -564,6 +564,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM1(PoolStringArray,append);
VCALL_LOCALMEM1(PoolStringArray,append_array);
VCALL_LOCALMEM0(PoolStringArray,invert);
+ VCALL_LOCALMEM1R(PoolStringArray,join);
VCALL_LOCALMEM0R(PoolVector2Array,size);
VCALL_LOCALMEM2(PoolVector2Array,set);
@@ -1637,6 +1638,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_scs_create(#m_method),VCA
ADDFUNC2(POOL_STRING_ARRAY,INT,PoolStringArray,insert,INT,"idx",STRING,"string",varray());
ADDFUNC1(POOL_STRING_ARRAY,NIL,PoolStringArray,resize,INT,"idx",varray());
ADDFUNC0(POOL_STRING_ARRAY,NIL,PoolStringArray,invert,varray());
+ ADDFUNC1(POOL_STRING_ARRAY,STRING,PoolStringArray,join,STRING,"string",varray());
ADDFUNC0(POOL_VECTOR2_ARRAY,INT,PoolVector2Array,size,varray());
ADDFUNC2(POOL_VECTOR2_ARRAY,NIL,PoolVector2Array,set,INT,"idx",VECTOR2,"vector2",varray());