summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp58
-rw-r--r--core/bind/core_bind.h13
-rw-r--r--core/hash_map.h15
-rw-r--r--core/hashfuncs.h4
-rw-r--r--core/image.cpp25
-rw-r--r--core/image.h1
-rw-r--r--core/io/file_access_encrypted.cpp5
-rw-r--r--core/io/ip.cpp13
-rw-r--r--core/io/ip.h3
-rw-r--r--core/io/packet_peer.cpp1
-rw-r--r--core/math/geometry.h80
-rw-r--r--core/os/file_access.cpp2
-rw-r--r--core/os/input.cpp2
-rw-r--r--core/os/main_loop.cpp2
-rw-r--r--core/os/main_loop.h3
-rw-r--r--core/os/os.cpp4
-rw-r--r--core/os/os.h2
-rw-r--r--core/script_language.h1
-rw-r--r--core/ustring.cpp2
-rw-r--r--core/variant.cpp10
20 files changed, 225 insertions, 21 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index fd6a91d125..960cdbac20 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -98,6 +98,13 @@ void _ResourceSaver::_bind_methods() {
ObjectTypeDB::bind_method(_MD("save","path","resource:Resource"),&_ResourceSaver::save, DEFVAL(0));
ObjectTypeDB::bind_method(_MD("get_recognized_extensions","type"),&_ResourceSaver::get_recognized_extensions);
+
+ BIND_CONSTANT(FLAG_RELATIVE_PATHS);
+ BIND_CONSTANT(FLAG_BUNDLE_RESOURCES);
+ BIND_CONSTANT(FLAG_CHANGE_PATH);
+ BIND_CONSTANT(FLAG_OMIT_EDITOR_PROPERTIES);
+ BIND_CONSTANT(FLAG_SAVE_BIG_ENDIAN);
+ BIND_CONSTANT(FLAG_COMPRESS);
}
_ResourceSaver::_ResourceSaver() {
@@ -479,10 +486,54 @@ void _OS::print_all_textures_by_size() {
print_line(E->get().path+" - "+String::humanize_size(E->get().vram)+" ("+E->get().size+") - total:"+String::humanize_size(total) );
total-=E->get().vram;
}
+}
+void _OS::print_resources_by_type(const Vector<String>& p_types) {
+ Map<String,int> type_count;
+
+ List<Ref<Resource> > resources;
+ ResourceCache::get_cached_resources(&resources);
+
+ List<Ref<Resource> > rsrc;
+ ResourceCache::get_cached_resources(&rsrc);
+
+ for (List<Ref<Resource> >::Element *E=rsrc.front();E;E=E->next()) {
+
+ Ref<Resource> r = E->get();
+
+ bool found = false;
+
+ for (int i=0; i<p_types.size(); i++) {
+ if (r->is_type(p_types[i]))
+ found = true;
+ }
+ if (!found)
+ continue;
+
+ if (!type_count.has(r->get_type())) {
+ type_count[r->get_type()]=0;
+ }
+
+
+ type_count[r->get_type()]++;
+
+ print_line(r->get_type()+": "+r->get_path());
+
+ List<String> metas;
+ r->get_meta_list(&metas);
+ for (List<String>::Element* me = metas.front(); me; me = me->next()) {
+ print_line(" "+String(me->get()) + ": " + r->get_meta(me->get()));
+ };
+ }
+
+ for(Map<String,int>::Element *E=type_count.front();E;E=E->next()) {
+
+ print_line(E->key()+" count: "+itos(E->get()));
+ }
+
+};
-}
void _OS::print_all_resources(const String& p_to_file ) {
@@ -509,9 +560,9 @@ float _OS::get_frames_per_second() const {
return OS::get_singleton()->get_frames_per_second();
}
-Error _OS::native_video_play(String p_path) {
+Error _OS::native_video_play(String p_path, float p_volume) {
- return OS::get_singleton()->native_video_play(p_path);
+ return OS::get_singleton()->native_video_play(p_path, p_volume);
};
bool _OS::native_video_is_playing() {
@@ -614,6 +665,7 @@ void _OS::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_frames_per_second"),&_OS::get_frames_per_second);
ObjectTypeDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
+ ObjectTypeDB::bind_method(_MD("print_resources_by_type"),&_OS::print_resources_by_type);
ObjectTypeDB::bind_method(_MD("native_video_play"),&_OS::native_video_play);
ObjectTypeDB::bind_method(_MD("native_video_is_playing"),&_OS::native_video_is_playing);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index f5c94dcf06..bb68bbaad8 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -39,6 +39,16 @@ protected:
static _ResourceSaver *singleton;
public:
+ enum SaverFlags {
+
+ FLAG_RELATIVE_PATHS=1,
+ FLAG_BUNDLE_RESOURCES=2,
+ FLAG_CHANGE_PATH=4,
+ FLAG_OMIT_EDITOR_PROPERTIES=8,
+ FLAG_SAVE_BIG_ENDIAN=16,
+ FLAG_COMPRESS=32,
+ };
+
static _ResourceSaver *get_singleton() { return singleton; }
Error save(const String &p_path,const RES& p_resource, uint32_t p_flags);
@@ -98,7 +108,7 @@ public:
bool is_video_mode_resizable(int p_screen=0) const;
Array get_fullscreen_mode_list(int p_screen=0) const;
- Error native_video_play(String p_path);
+ Error native_video_play(String p_path, float p_volume);
bool native_video_is_playing();
void native_video_pause();
void native_video_stop();
@@ -139,6 +149,7 @@ public:
void print_resources_in_use(bool p_short=false);
void print_all_resources(const String& p_to_file);
void print_all_textures_by_size();
+ void print_resources_by_type(const Vector<String>& p_types);
bool has_touchscreen_ui_hint() const;
diff --git a/core/hash_map.h b/core/hash_map.h
index 02a6600c3b..da8f038490 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -285,14 +285,12 @@ public:
}
void set( const Pair& p_pair ) {
-
+
+ Entry *e=NULL;
if (!hash_table)
make_hash_table(); // if no table, make one
else
- check_hash_table(); // perform mantenience routine
-
- /* As said, i want to have only one get_entry */
- Entry *e = const_cast<Entry*>( get_entry(p_pair.key) );
+ e = const_cast<Entry*>( get_entry(p_pair.key) );
/* if we made it up to here, the pair doesn't exist, create and assign */
@@ -301,6 +299,7 @@ public:
e=create_entry(p_pair.key);
if (!e)
return;
+ check_hash_table(); // perform mantenience routine
}
e->pair.data = p_pair.data;
@@ -478,12 +477,11 @@ public:
}
inline TData& operator[](const TKey& p_key ) { //assignment
+ Entry *e=NULL;
if (!hash_table)
make_hash_table(); // if no table, make one
else
- check_hash_table(); // perform mantenience routine
-
- Entry *e = const_cast<Entry*>( get_entry(p_key) );
+ e = const_cast<Entry*>( get_entry(p_key) );
/* if we made it up to here, the pair doesn't exist, create */
if (!e) {
@@ -491,6 +489,7 @@ public:
e=create_entry(p_key);
if (!e)
return *(TData*)NULL; /* panic! */
+ check_hash_table(); // perform mantenience routine
}
return e->pair.data;
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index 6dae82bc55..3b6715a4cd 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -54,9 +54,9 @@ static inline uint32_t hash_djb2(const char *p_cstr) {
return hash;
}
-static inline uint32_t hash_djb2_buffer(uint8_t *p_buff, int p_len) {
+static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len,uint32_t p_prev=5381) {
- uint32_t hash = 5381;
+ uint32_t hash = p_prev;
for(int i=0;i<p_len;i++)
hash = ((hash << 5) + hash) + p_buff[i]; /* hash * 33 + c */
diff --git a/core/image.cpp b/core/image.cpp
index ccabd04d6f..db20862af5 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -1660,6 +1660,31 @@ void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
}
+
+void Image::premultiply_alpha() {
+
+ if (data.size()==0)
+ return;
+
+ if (format!=FORMAT_RGBA)
+ return; //not needed
+
+ DVector<uint8_t>::Write wp = data.write();
+ unsigned char *data_ptr=wp.ptr();
+
+
+ for(int i=0;i<height;i++) {
+ for(int j=0;j<width;j++) {
+
+ BColor bc = _get_pixel(j,i,data_ptr,0);
+ bc.r=(int(bc.r)*int(bc.a))>>8;
+ bc.g=(int(bc.g)*int(bc.a))>>8;
+ bc.b=(int(bc.b)*int(bc.a))>>8;
+ _put_pixel(j,i,bc,data_ptr);
+ }
+ }
+}
+
void Image::fix_alpha_edges() {
if (data.size()==0)
diff --git a/core/image.h b/core/image.h
index 186aceb1bf..99300fc3af 100644
--- a/core/image.h
+++ b/core/image.h
@@ -320,6 +320,7 @@ public:
void decompress();
void fix_alpha_edges();
+ void premultiply_alpha();
void blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest);
void brush_transfer(const Image& p_src, const Image& p_brush, const Point2& p_dest);
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index bcd4197e11..29f27dcbda 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -25,6 +25,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base,const Vector<uint8_
} else if (p_mode==MODE_READ) {
+ writing=false;
key=p_key;
uint32_t magic = p_base->get_32();
print_line("MAGIC: "+itos(magic));
@@ -278,6 +279,10 @@ uint64_t FileAccessEncrypted::_get_modified_time(const String& p_file){
FileAccessEncrypted::FileAccessEncrypted() {
file=NULL;
+ pos=0;
+ eofed=false;
+ mode=MODE_MAX;
+ writing=false;
}
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index 503a009444..d2a685f6b0 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -188,6 +188,18 @@ void IP::erase_resolve_item(ResolverID p_id) {
}
+Array IP::_get_local_addresses() const {
+
+ Array addresses;
+ List<IP_Address> ip_addresses;
+ get_local_addresses(&ip_addresses);
+ for(List<IP_Address>::Element *E=ip_addresses.front();E;E=E->next()) {
+ addresses.push_back(E->get());
+ }
+
+ return addresses;
+}
+
void IP::_bind_methods() {
ObjectTypeDB::bind_method(_MD("resolve_hostname","host"),&IP::resolve_hostname);
@@ -195,6 +207,7 @@ void IP::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_resolve_item_status","id"),&IP::get_resolve_item_status);
ObjectTypeDB::bind_method(_MD("get_resolve_item_address","id"),&IP::get_resolve_item_address);
ObjectTypeDB::bind_method(_MD("erase_resolve_item","id"),&IP::erase_resolve_item);
+ ObjectTypeDB::bind_method(_MD("get_local_addresses"),&IP::_get_local_addresses);
BIND_CONSTANT( RESOLVER_STATUS_NONE );
BIND_CONSTANT( RESOLVER_STATUS_WAITING );
diff --git a/core/io/ip.h b/core/io/ip.h
index f1ef5fe794..0181dc7d12 100644
--- a/core/io/ip.h
+++ b/core/io/ip.h
@@ -66,16 +66,19 @@ protected:
static void _bind_methods();
virtual IP_Address _resolve_hostname(const String& p_hostname)=0;
+ Array _get_local_addresses() const;
static IP* (*_create)();
public:
+
IP_Address resolve_hostname(const String& p_hostname);
// async resolver hostname
ResolverID resolve_hostname_queue_item(const String& p_hostname);
ResolverStatus get_resolve_item_status(ResolverID p_id) const;
IP_Address get_resolve_item_address(ResolverID p_id) const;
+ virtual void get_local_addresses(List<IP_Address> *r_addresses) const=0;
void erase_resolve_item(ResolverID p_id);
static IP* get_singleton();
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index f67a10df2e..37fc9c4a0a 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -112,6 +112,7 @@ void PacketPeer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_var"),&PacketPeer::_bnd_get_var);
ObjectTypeDB::bind_method(_MD("put_var", "var:Variant"),&PacketPeer::put_var);
+ ObjectTypeDB::bind_method(_MD("get_available_packet_count"),&PacketPeer::get_available_packet_count);
};
/***************/
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 826e4697b5..5b21c25bec 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -695,6 +695,86 @@ public:
}
+
+ static inline Vector<Vector3> clip_polygon(const Vector<Vector3>& polygon,const Plane& p_plane) {
+
+ enum LocationCache {
+ LOC_INSIDE=1,
+ LOC_BOUNDARY=0,
+ LOC_OUTSIDE=-1
+ };
+
+ if (polygon.size()==0)
+ return polygon;
+
+ int *location_cache = (int*)alloca(sizeof(int)*polygon.size());
+ int inside_count = 0;
+ int outside_count = 0;
+
+ for (int a = 0; a < polygon.size(); a++) {
+ //float p_plane.d = (*this) * polygon[a];
+ float dist = p_plane.distance_to(polygon[a]);
+ if (dist <-CMP_POINT_IN_PLANE_EPSILON) {
+ location_cache[a] = LOC_INSIDE;
+ inside_count++;
+ } else {
+ if (dist > CMP_POINT_IN_PLANE_EPSILON) {
+ location_cache[a] = LOC_OUTSIDE;
+ outside_count++;
+ } else {
+ location_cache[a] = LOC_BOUNDARY;
+ }
+ }
+ }
+
+ if (outside_count == 0) {
+
+ return polygon; // no changes
+
+ } else if (inside_count == 0) {
+
+ return Vector<Vector3>(); //empty
+ }
+
+// long count = 0;
+ long previous = polygon.size() - 1;
+
+ Vector<Vector3> clipped;
+
+ for (int index = 0; index < polygon.size(); index++) {
+ int loc = location_cache[index];
+ if (loc == LOC_OUTSIDE) {
+ if (location_cache[previous] == LOC_INSIDE) {
+ const Vector3& v1 = polygon[previous];
+ const Vector3& v2 = polygon[index];
+
+ Vector3 segment= v1 - v2;
+ double den=p_plane.normal.dot( segment );
+ double dist=p_plane.distance_to( v1 ) / den;
+ dist=-dist;
+ clipped.push_back( v1 + segment * dist );
+ }
+ } else {
+ const Vector3& v1 = polygon[index];
+ if ((loc == LOC_INSIDE) && (location_cache[previous] == LOC_OUTSIDE)) {
+ const Vector3& v2 = polygon[previous];
+ Vector3 segment= v1 - v2;
+ double den=p_plane.normal.dot( segment );
+ double dist=p_plane.distance_to( v1 ) / den;
+ dist=-dist;
+ clipped.push_back( v1 + segment * dist );
+ }
+
+ clipped.push_back(v1);
+ }
+
+ previous = index;
+ }
+
+ return clipped;
+ }
+
+
static Vector<int> triangulate_polygon(const Vector<Vector2>& p_polygon) {
Vector<int> triangles;
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 31e7d19bae..ffa0cad8e4 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -100,7 +100,7 @@ FileAccess *FileAccess::open(const String& p_path, int p_mode_flags, Error *r_er
FileAccess *ret=NULL;
if (!(p_mode_flags&WRITE) && PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled()) {
ret = PackedData::get_singleton()->try_open_path(p_path);
- if (ret) {
+ if (ret) {
if (r_error)
*r_error=OK;
return ret;
diff --git a/core/os/input.cpp b/core/os/input.cpp
index d7c0d86d64..70733aadec 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -211,6 +211,8 @@ void InputDefault::parse_input_event(const InputEvent& p_event) {
if (p_event.key.scancode==0)
break;
+ // print_line(p_event);
+
if (p_event.key.pressed)
keys_pressed.insert(p_event.key.scancode);
else
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index a8e02526b9..d01331a256 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -37,7 +37,7 @@ void MainLoop::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_WM_FOCUS_OUT);
BIND_CONSTANT(NOTIFICATION_WM_QUIT_REQUEST);
BIND_CONSTANT(NOTIFICATION_WM_UNFOCUS_REQUEST);
-
+ BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING);
};
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index b84d2841e1..6eb5881175 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -50,7 +50,8 @@ public:
NOTIFICATION_WM_FOCUS_IN = 5,
NOTIFICATION_WM_FOCUS_OUT = 6,
NOTIFICATION_WM_QUIT_REQUEST = 7,
- NOTIFICATION_WM_UNFOCUS_REQUEST = 8
+ NOTIFICATION_WM_UNFOCUS_REQUEST = 8,
+ NOTIFICATION_OS_MEMORY_WARNING = 9,
};
virtual void input_event( const InputEvent& p_event );
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 65d6ed50b2..11290409d5 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -225,7 +225,7 @@ void OS::print_all_resources(String p_to_file) {
void OS::print_resources_in_use(bool p_short) {
- //ResourceCache::dump(NULL,p_short);
+ ResourceCache::dump(NULL,p_short);
}
void OS::dump_resources_to_file(const char* p_file) {
@@ -438,7 +438,7 @@ int OS::get_processor_count() const {
return 1;
}
-Error OS::native_video_play(String p_path) {
+Error OS::native_video_play(String p_path, float p_volume) {
return FAILED;
};
diff --git a/core/os/os.h b/core/os/os.h
index e7fe0cb09e..24e2b4f2d4 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -321,7 +321,7 @@ public:
virtual String get_unique_ID() const;
- virtual Error native_video_play(String p_path);
+ virtual Error native_video_play(String p_path, float p_volume);
virtual bool native_video_is_playing() const;
virtual void native_video_pause();
virtual void native_video_stop();
diff --git a/core/script_language.h b/core/script_language.h
index 9731273610..560de520ca 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -141,6 +141,7 @@ public:
virtual int find_function(const String& p_function,const String& p_code) const=0;
virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const=0;
virtual Error complete_keyword(const String& p_code, int p_line, const String& p_base_path, const String& p_keyword, List<String>* r_options) { return ERR_UNAVAILABLE; }
+ virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const=0;
/* DEBUGGER FUNCTIONS */
diff --git a/core/ustring.cpp b/core/ustring.cpp
index d119e341c3..188818bc2a 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -2640,7 +2640,7 @@ String String::right(int p_pos) const {
if (p_pos<0)
return "";
- return substr(p_pos+1,(length()-p_pos)-1);
+ return substr(p_pos,(length()-p_pos));
}
CharType String::ord_at(int p_idx) const {
diff --git a/core/variant.cpp b/core/variant.cpp
index 6b3b25a103..fdb14c0c0f 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1337,6 +1337,10 @@ Variant::operator Matrix3() const {
if (type==MATRIX3)
return *_data._matrix3;
+ else if (type==QUAT)
+ return *reinterpret_cast<const Quat*>(_data._mem);
+ else if (type==TRANSFORM)
+ return _data._transform->basis;
else
return Matrix3();
}
@@ -1345,6 +1349,10 @@ Variant::operator Quat() const {
if (type==QUAT)
return *reinterpret_cast<const Quat*>(_data._mem);
+ else if (type==MATRIX3)
+ return *_data._matrix3;
+ else if (type==TRANSFORM)
+ return _data._transform->basis;
else
return Quat();
}
@@ -1357,6 +1365,8 @@ Variant::operator Transform() const {
return *_data._transform;
else if (type==MATRIX3)
return Transform(*_data._matrix3,Vector3());
+ else if (type==QUAT)
+ return Transform(Matrix3(*reinterpret_cast<const Quat*>(_data._mem)),Vector3());
else
return Transform();
}