From 5072134f419f749b8b47021565dad3b0ee15c979 Mon Sep 17 00:00:00 2001 From: Saracen Date: Sat, 4 Jul 2015 00:59:03 +0100 Subject: [PATCH 01/24] Fixed canvas clipping on offscreen viewports. --- drivers/gles2/rasterizer_gles2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index d84ee5a7589..0bb58708eef 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -9349,7 +9349,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const int h = current_clip->final_clip_rect.size.y; */ int x = current_clip->final_clip_rect.pos.x; - int y = window_size.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); + int y = viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); int w = current_clip->final_clip_rect.size.x; int h = current_clip->final_clip_rect.size.y; From ff363c94db0d456e171aeacf10f11f5a51ca2ee3 Mon Sep 17 00:00:00 2001 From: Saracen Date: Sat, 31 Oct 2015 09:05:03 +0000 Subject: [PATCH 02/24] Another clipping fix: default back to using window size to calculate clipping on viewports which don't have a rendertarget which fixes clipping on the editor viewport. --- drivers/gles2/rasterizer_gles2.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 0bb58708eef..daac4123e0e 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -9348,10 +9348,23 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const int w = current_clip->final_clip_rect.size.x; int h = current_clip->final_clip_rect.size.y; */ - int x = current_clip->final_clip_rect.pos.x; - int y = viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); - int w = current_clip->final_clip_rect.size.x; - int h = current_clip->final_clip_rect.size.y; + int x; + int y; + int w; + int h; + + if (current_rt) { + x = current_clip->final_clip_rect.pos.x; + y = viewport.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y); + w = current_clip->final_clip_rect.size.x; + h = current_clip->final_clip_rect.size.y; + } + else { + x = current_clip->final_clip_rect.pos.x; + y = window_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y); + w = current_clip->final_clip_rect.size.x; + h = current_clip->final_clip_rect.size.y; + } glScissor(x,y,w,h); From f7e4c4e35939474928a8ec8798ba6759f173250a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 20 Nov 2015 00:19:44 +0100 Subject: [PATCH 03/24] Fix call to _snprintf on GCC Was a regression from ddbf2ff. This commit also introduce a "#define snprintf _snprintf", so the rest of the file was simplified to make use of this instead of distinguishing between snprintf and _snprintf in the various functions. --- core/ustring.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index f3c89a7908a..bf2494e9b53 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -897,17 +897,8 @@ String String::num(double p_num,int p_decimals) { } char buf[256]; -#if defined(__GNUC__) -#ifdef MINGW_ENABLED - //snprintf is inexplicably broken in mingw - //sprintf(buf,fmt,p_num); - _snprintf(buf,256,fmt,p_num); -#else +#if defined(__GNUC__) || defined(_MSC_VER) snprintf(buf,256,fmt,p_num); -#endif - -#elif defined(_MSC_VER) - _snprintf(buf,256,fmt,p_num); #else sprintf(buf,fmt,p_num); #endif @@ -1178,10 +1169,7 @@ String String::num_scientific(double p_num) { char buf[256]; -#if defined(_MSC_VER) || defined(MINGW_ENABLED) - - _snprintf(buf,256,"%lg",p_num); -#elif defined(__GNUC__) +#if defined(__GNUC__) || defined(_MSC_VER) snprintf(buf,256,"%lg",p_num); #else sprintf(buf,"%.16lg",p_num); @@ -3096,7 +3084,11 @@ String String::http_escape() const { res += ord; } else { char h_Val[3]; - snprintf(h_Val, 3, "%.2X", ord); +#if defined(__GNUC__) || defined(_MSC_VER) + snprintf(h_Val, 3, "%.2X", ord); +#else + sprintf(h_Val, "%.2X", ord); +#endif res += "%"; res += h_Val; } From 2cc52bc3ffde14dd7685588e9b4884bf7f8cfa4e Mon Sep 17 00:00:00 2001 From: Saracen Date: Thu, 19 Nov 2015 23:47:25 +0000 Subject: [PATCH 04/24] Modification to GUI in 3D demo to show resolved viewport clipping bug and small fix to bug causing viewport clipping to be inverted. --- demos/viewport/gui_in_3d/gui.scn | Bin 2270 -> 3267 bytes drivers/gles2/rasterizer_gles2.cpp | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/viewport/gui_in_3d/gui.scn b/demos/viewport/gui_in_3d/gui.scn index 4d665226b70ba79844e8c20a654a8e1068f75eb6..5e8c04754e8d6572215ef00407db124508e5b3fa 100644 GIT binary patch literal 3267 zcmXw64|o*i(VxA&%O<(}A@xaaxJ z?auz@oq1>Gz1i#R@_Hfp$pN^x7~r%3@R1dO1Bi2AiKlSDF&;7)pV=V?`jwupfD%?< zUlGeO>i~Gx1X+yFiYmG`7!4>jVR=A-G?pv)y9dKPA*Dx}ouUV#Y9v+@PhrLJJ&?|X z^pF;iLrZIFYT*paL@MHBmL#7hi1T2;EvNrVW6Dl{$L0 zz@T2E2E$rZ@egQ&x&pZ-%;fc$7BTW*Cd-?tt0RiPHzWu3nm#S6j%eYS9D+R4R%jhk zqA`_ilP(H=|9}#c{eJ1PwL=aoAt}wWO73Q9Vxh6$7E*d+U}tScHrpf@SYpa>{1O*Y z+s5fmSy4~*cwxCiopoUF8laq&~>i8_$zY;MmS$sqeD$;PgBxOhr4Jwe$j>fZj zWjNx;7vnQPD}BtO^!TN6&?TRHkEP!qprB&%o0w(S{aV=Htwnp3s4o4KZ|e%FEJLa> z;eA*ny=IFih_DCw!np`^6B}F}n_@s0T+-h?9 zusEq|NQxy%(P(n#x!Q&DJDx`%?EZ(~kI1n;9cH`lL-0N)X0vClx~hf2*Wx>bPORet zS~z@o3-DOOAWhu zWB7Giz=?Nrbv~&Yuj339()6$#@ki8QC1hIX`{Ghj`4lI|+{m_-evaq(2h+dZjLVSc zMzr#$Fpp1tZEp+a;OA09`b9G)(P?t0 z4yT#cgW@`<-?ol+z7TgH^nBN43dR4va%x90(_M=dR~gae9HOuRT^LF;K4#?3~4d;#Xe zJ!Wb?`XI!7l|O>0^ry3J-s^K>DSjn9q(-&Tx3BOWcnw|bQEQ(T)WUPtoBV8i$`a9Z zd8WyO`Sk>XXfwY^m@g;9i{9@|mds79{D*h<*$FHu8|CG}P^@aGY-jhwiIR3FFAsF9 zb56udD&Dt*w5a6dA3j*voS?WWrm)|;>mA!y6YbuAN`-S{6_1-%#T&Magq5T3^1nZS zei^Q8|G&gRUXKR5r8>%RvA2^IODDWfaQ@*yt7U2HH>Dj=z$&MqfQt@RjN6o0ObrLm zIlcE`D?U`+RNV&t>RvjD4xF^k53zE6?o+!;yq}`)GTcTBHcw}4ox7D&!gIDF6V*Al zdoNR9m*N8a-4M9lo_IFQ>zQipZaV|4eHxY;b;<4($x?vp4B~arW-Nt^h5!#r9T=(}WKQR$~kC1;{5966O%9rPn>Lw$Dn@fzgn zo6PX^$tM|j_M@FuOLlRZj%N~IL3`_~Xcu=9PN0A*(Ls&jxk!hm-#d+dq=D7%?ZXvV zM$qsWp@qO>kk~=Adq=UUbs08^zeC5W7jIa%SJ2}zEHh_~;aa*#q6N2-H$q|zU!ZQ^ z;CqHh_V#S7T>Tj~kWYN;_LDe{FPO8&$zq&VUyFB806bXR$xM=!SVliecAznfYr#gmBC<&iVLJ#n zSgAK;njv64x@aV1qfS@ZNf#O9qL}e)w^=YoD~&-qt07rJ7HiQ<5&k#UG29HZS*6Hh z6XY^G?e?V`d4Wonfn97jcRi2UMLQimJK8VvPD%--2wbcR$2e+5%91IJ{o0A&A$>i# z$w@svLg{mIr9gdLM*dbnxgkIWT}{9olFnp&w@`dl6yLMl_536U!E{WZX7UrbNo>Lm z=86eQ>;{<2zAJ8kYC|9+@g8ELr&_8L&$h#L%2f6!20c44D85Jgw^RCs$pZ-;>ewCPC{gWb zWgs>XeIwBYb5_4+E%sCH`%y^rqu=Yg?C3Z7%}~!q*~sO*elg(rvB`fZI&l-l*)R%= z%-N%!qb5J`Nyg;{0UB;H#L1gROGqW2B9@qJ z?;GnhCRH`0!ik%zrKCa%U=$l}s+y9jN>agX?4}Y|mLGYi;3&NW>h$2nakFN0`6M=3 zlVe%$`z7Tm9~>+-SLsn>a(77at6`d@G#d22zahLhC8aK(n;PpI9Ow?qYDg8}9CM}Y z>R7WPGrb6lt(om@zD_pJMhS$f)V3+tub=9Fp5A@;w)@1duD}2Nhkm!wQk(bfwb2=a z&wOKhUG;0O`|p19u@5fhyAqXu&%Zc$q4_}U+K~^tH|>+3+q>^ztX6W(-_wyZlJik5 zUl{#VZ+_4nx^4F4vdJfB{UW~-_d1Me*9SK1>t`SNeR$&17bkwP{^OUgc24JA$nyP< z_+Dg5@f+`Dx_;vQ$z=Ew^;ds>Jm9PS;hKA2Xgs*;nXFGf|KfD<$&$9O9CuCMbARlv z>W2yfZ`=tvo}s1RdGy-pJ68ipf1FY9`s(M>U1!(jJlYa)99r|zGn-#I(fQ<_)|yin z1bE`%jb}E@Y3!MH?JseUfB((mKV--AJ+~hmuiLTnKU@oz45rV_|5nJ<@)l+ z*Zc*1#+3Bx)(@7sj{IfljCbD;%C3F-*_Z!rJXAB&pDyM=;fA=yY%+dns||1m~}3#<1f}HzG-=F3AgbFaBE_wdtvJH+^GxO d@lb$Yk&y-M%h&jR>XEhsbar)mJL&Js{{yB+7Qp}j literal 2270 zcmX|D4Q$l*6@NZo&dFWANPv7CA^*z-4npB5f$||np6!J2)q#jsSc_)+?tFI^7yD%U zl8{cV*{ae})=WierB-5QsAFn1A+6QMrb!$`UAED6laR)=O^eeYMU)My(rQwtHhW>x zEdTufdjI!(AAkG#=!h)C($x&`R4c&O1pt==pxfhs^CBuhJ*$Zx(XuD?+(=e8b=DAU z0|>J{ssfFyw$audt72#Mw5g5iP{)=DN~U7wN_tLR9dWX@QFhZ_gst*+LX-*7l9km; zyVB{+@N3q95D1qs3nA7Hos0*8P(z3?9*vL#J**CPQvds*Ld8%!B1be+FF`9?5gjue zBV&{d_f%SqawRywoxd$>I1)7$XKpxjlv4nBjl}Y#Zk!99>^rtN75xd@51sR+8%bTGOP@uZQcoJ z3!)vqjt^A5F>Mq~%hr`qtK#Uetok^YcG%PYa#WW)#-y&~OIpE67cJYEv`kkksjmj1 zj_{anyGG)o#s{IcddIbOH(OL}%{8pk4%yq?ZbYlN*0`;CZ$v8PvTkR!gapm(TNq2+ z2j#|I+!Q`!nEDWwyuSz&N=Y{hZc&Zn3!q7s^s|toXA_$^sAa=i2gkOkTdD)B5!Y~1 zrDvn}QYdFQxEpfnT?%KRP!d0coOib_TQagI70Xo0$%^-9&d9PIa(m*B;A#h0FIQI7 ze+66x`hyyJsGX60BPAoJ+iGXx#NGDoY|9)?N<_q4)pf~grV0$mX zE>)yl_Ho`dlG*2PfzVs6@JepGxZhs~zR%!2Uw~h!Z18(8z74zl6a@au@Ox@MQ&aef zaHQfC*^_!gJ4oy|QS(j%^H0Gux%ct-i|4Axq0jGzGo<3Tz6zfPp#Jzd*rlx#f3vqQ z;sB%XaYIiVEc$>pDQFygm368R@ULJ}G%=3*F+ThnzKw5C{}u}3KL`aBq!4aDP>&$p zKzXPO1$0o^e-1||7tq4$k;gZoi^Xu5bUu&$1OW>e-@kxU2X^BWDuiQ%IBp;a|HnH> zpXqn1mk#_Clfw+h57;Qkjl_2ayN7;+QxIo|P=HlTz!99r#o-^&sGGH6w|E`}E&-?8 z$b^IMBQNqqnnIXs<#CnR@gXfdoJ-EYxfinal_clip_rect.pos.x; - y = viewport.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y); + y = current_clip->final_clip_rect.pos.y; w = current_clip->final_clip_rect.size.x; h = current_clip->final_clip_rect.size.y; } From 0931eed7be854ee6e0d0473b715dda2b6f2839e2 Mon Sep 17 00:00:00 2001 From: Anton Yabchinskiy Date: Thu, 20 Nov 2014 00:09:39 +0300 Subject: [PATCH 05/24] Enable ALSA only for Linux --- platform/x11/detect.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 9a52a7c92b1..5ec7eb1afc7 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -1,6 +1,7 @@ import os import sys +import platform def is_active(): @@ -145,7 +146,9 @@ def configure(env): env.Append(CPPFLAGS=['-DOPENGL_ENABLED','-DGLEW_ENABLED']) - env.Append(CPPFLAGS=["-DALSA_ENABLED"]) + if platform.platform() == 'Linux': + env.Append(CPPFLAGS=["-DALSA_ENABLED"]) + env.Append(LIBS=['asound']) if (env["pulseaudio"]=="yes"): if not os.system("pkg-config --exists libpulse-simple"): @@ -156,7 +159,7 @@ def configure(env): print("PulseAudio development libraries not found, disabling driver") env.Append(CPPFLAGS=['-DX11_ENABLED','-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLES_OVER_GL']) - env.Append(LIBS=['GL', 'GLU', 'pthread','asound','z']) #TODO detect linux/BSD! + env.Append(LIBS=['GL', 'GLU', 'pthread', 'z']) #env.Append(CPPFLAGS=['-DMPC_FIXED_POINT']) #host compiler is default.. From 52f1bab6d5dffe163bb20886bc725530495dc8c2 Mon Sep 17 00:00:00 2001 From: Anton Yabchinskiy Date: Thu, 20 Nov 2014 00:12:01 +0300 Subject: [PATCH 06/24] Include stdlib.h for alloca() on OpenBSD --- platform/x11/platform_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/x11/platform_config.h b/platform/x11/platform_config.h index c01d0aa3802..1556b560586 100644 --- a/platform/x11/platform_config.h +++ b/platform/x11/platform_config.h @@ -29,7 +29,7 @@ #ifdef __linux__ #include #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__OpenBSD__) #include #endif From 523e64d30bdb68a904a9f1aebe2ff6b7985f8b86 Mon Sep 17 00:00:00 2001 From: Anton Yabchinskiy Date: Thu, 20 Nov 2014 00:16:00 +0300 Subject: [PATCH 07/24] Include string.h for memset() on OpenBSD --- platform/x11/os_x11.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 74ebad748a2..189f0f3acb7 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -32,6 +32,7 @@ #include "key_mapping_x11.h" #include #include +#include #include "print_string.h" #include "servers/physics/physics_server_sw.h" #include "errno.h" From b14c90801f99fe97cb445a56036eefeedfe720db Mon Sep 17 00:00:00 2001 From: Anton Yabchinskiy Date: Thu, 20 Nov 2014 00:20:27 +0300 Subject: [PATCH 08/24] Disable X11 joystick functions also for OpenBSD --- platform/x11/os_x11.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 189f0f3acb7..4f1b475d062 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1673,7 +1673,7 @@ void OS_X11::close_joystick(int p_id) { }; void OS_X11::probe_joystick(int p_id) { - #ifndef __FreeBSD__ + #if !defined(__FreeBSD__) && !defined(__OpenBSD__) if (p_id == -1) { @@ -1728,7 +1728,7 @@ void OS_X11::move_window_to_foreground() { } void OS_X11::process_joysticks() { - #ifndef __FreeBSD__ + #if !defined(__FreeBSD__) && !defined(__OpenBSD__) int bytes; js_event events[32]; InputEvent ievent; From 49f4ec2b71da7fe5d9e7d9fda8e9fb0bf3a7b711 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 22 Nov 2015 13:49:58 +0800 Subject: [PATCH 09/24] Added additional token checks for the shader if..else.. statement. Fixes issue #2791. --- servers/visual/shader_language.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 6532c3f0ac3..8a2117c171a 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2340,19 +2340,27 @@ Error ShaderLanguage::parse_flow_if(Parser& parser,Node *p_parent,Node **r_state parser.advance(); + if (parser.get_token_type()!=TK_CURLY_BRACKET_OPEN) { + parser.set_error("Expected statement block after 'if()'"); + return ERR_PARSE_ERROR; + } + Node *substatement=NULL; err = parse_statement(parser,cf,&substatement); if (err) return err; - cf->statements.push_back(substatement); - - if (parser.get_token_type()==TK_CF_ELSE) { parser.advance(); + + if (parser.get_token_type()!=TK_CURLY_BRACKET_OPEN) { + parser.set_error("Expected statement block after 'else'"); + return ERR_PARSE_ERROR; + } + substatement=NULL; err = parse_statement(parser,cf,&substatement); if (err) From f33d9dab5bf05356f9a2c882537e83390a710e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 22 Nov 2015 14:14:07 +0100 Subject: [PATCH 10/24] Fix can_move_to and rename it for more clarity Fixes #2416. The KinematicBody::can_move_to function was likely designed for two behaviours: - discrete: check if the body can "teleport" to the destination - continuous: check if the direct path to the destination is valid The continuous behaviour was however not implemented, and the discrete behaviour was broken too due to a wrong call to intersect_shape. The discrete behaviour has thus been fixed and the function renamed to can_teleport_to for more clarity. --- scene/3d/physics_body.cpp | 15 ++++----------- scene/3d/physics_body.h | 2 +- servers/physics/space_sw.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index d61859a3d06..de50484a1e2 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -1073,7 +1073,7 @@ Vector3 KinematicBody::move_to(const Vector3& p_position) { return move(p_position-get_global_transform().origin); } -bool KinematicBody::can_move_to(const Vector3& p_position, bool p_discrete) { +bool KinematicBody::can_teleport_to(const Vector3& p_position) { ERR_FAIL_COND_V(!is_inside_tree(),false); PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(get_world()->get_space()); @@ -1089,25 +1089,18 @@ bool KinematicBody::can_move_to(const Vector3& p_position, bool p_discrete) { if (collide_character) mask|=PhysicsDirectSpaceState::TYPE_MASK_CHARACTER_BODY; - Vector3 motion = p_position-get_global_transform().origin; Transform xform=get_global_transform(); - - if (true || p_discrete) { - - xform.origin+=motion; - motion=Vector3(); - } + xform.origin=p_position; Set exclude; exclude.insert(get_rid()); - //fill exclude list.. for(int i=0;iintersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,0,exclude,get_layer_mask(),mask); + bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,1,exclude,get_layer_mask(),mask); if (col) return false; } @@ -1205,7 +1198,7 @@ void KinematicBody::_bind_methods() { ObjectTypeDB::bind_method(_MD("move","rel_vec"),&KinematicBody::move); ObjectTypeDB::bind_method(_MD("move_to","position"),&KinematicBody::move_to); - ObjectTypeDB::bind_method(_MD("can_move_to","position"),&KinematicBody::can_move_to); + ObjectTypeDB::bind_method(_MD("can_teleport_to","position"),&KinematicBody::can_teleport_to); ObjectTypeDB::bind_method(_MD("is_colliding"),&KinematicBody::is_colliding); diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index 66490ba9258..0e63b771187 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -304,7 +304,7 @@ public: Vector3 move(const Vector3& p_motion); Vector3 move_to(const Vector3& p_position); - bool can_move_to(const Vector3& p_position,bool p_discrete=false); + bool can_teleport_to(const Vector3& p_position); bool is_colliding() const; Vector3 get_collision_pos() const; Vector3 get_collision_normal() const; diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index ba1c737530f..4b59f2d0ba3 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -175,6 +175,10 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transfo if (!CollisionSolverSW::solve_static(shape,p_xform,col_obj->get_shape(shape_idx),col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), NULL,NULL,NULL,p_margin,0)) continue; + cc++; + + if (!r_results) + continue; r_results[cc].collider_id=col_obj->get_instance_id(); if (r_results[cc].collider_id!=0) r_results[cc].collider=ObjectDB::get_instance(r_results[cc].collider_id); @@ -183,8 +187,6 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transfo r_results[cc].rid=col_obj->get_self(); r_results[cc].shape=shape_idx; - cc++; - } return cc; From e57dfe26632beeaf65cf15352db57424f2094deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 22 Nov 2015 14:21:04 +0100 Subject: [PATCH 11/24] Update doc for can_teleport_to --- doc/base/classes.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 44a7cccfe5c..ba29d534d75 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -15038,14 +15038,13 @@ returns:= "username=user&password=pass" - + - - + Returns whether the KinematicBody can be teleported to the destination given as an argument, checking all collision shapes of the body against potential colliders at the destination. From d1a75a67577368b7168fbca080036b5ac4754740 Mon Sep 17 00:00:00 2001 From: eska Date: Mon, 23 Nov 2015 02:09:19 +0100 Subject: [PATCH 12/24] Remove unexpected GDScript built-in type aliases --- modules/gdscript/gd_tokenizer.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index b591ed3b4b0..e4457016695 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -774,20 +774,15 @@ void GDTokenizerText::_advance() { {Variant::INT,"int"}, {Variant::REAL,"float"}, {Variant::STRING,"String"}, - {Variant::VECTOR2,"vec2"}, {Variant::VECTOR2,"Vector2"}, {Variant::RECT2,"Rect2"}, {Variant::MATRIX32,"Matrix32"}, - {Variant::MATRIX32,"mat32"}, - {Variant::VECTOR3,"vec3"}, {Variant::VECTOR3,"Vector3"}, {Variant::_AABB,"AABB"}, {Variant::_AABB,"Rect3"}, {Variant::PLANE,"Plane"}, {Variant::QUAT,"Quat"}, - {Variant::MATRIX3,"mat3"}, {Variant::MATRIX3,"Matrix3"}, - {Variant::TRANSFORM,"trn"}, {Variant::TRANSFORM,"Transform"}, {Variant::COLOR,"Color"}, {Variant::IMAGE,"Image"}, @@ -795,7 +790,6 @@ void GDTokenizerText::_advance() { {Variant::OBJECT,"Object"}, {Variant::INPUT_EVENT,"InputEvent"}, {Variant::NODE_PATH,"NodePath"}, - {Variant::DICTIONARY,"dict"}, {Variant::DICTIONARY,"Dictionary"}, {Variant::ARRAY,"Array"}, {Variant::RAW_ARRAY,"RawArray"}, From dc9ddfc6a0facca230612e6ef1c88fc80afc9e0b Mon Sep 17 00:00:00 2001 From: neikeq Date: Sun, 22 Nov 2015 19:11:17 +0100 Subject: [PATCH 13/24] Editor layouts menu --- tools/editor/editor_layout_dialog.cpp | 59 ++++++++ tools/editor/editor_layout_dialog.h | 53 +++++++ tools/editor/editor_node.cpp | 210 +++++++++++++++++++++++--- tools/editor/editor_node.h | 16 +- 4 files changed, 317 insertions(+), 21 deletions(-) create mode 100644 tools/editor/editor_layout_dialog.cpp create mode 100644 tools/editor/editor_layout_dialog.h diff --git a/tools/editor/editor_layout_dialog.cpp b/tools/editor/editor_layout_dialog.cpp new file mode 100644 index 00000000000..e37f263c0cd --- /dev/null +++ b/tools/editor/editor_layout_dialog.cpp @@ -0,0 +1,59 @@ +/*************************************************************************/ +/* editor_node.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2015 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 "editor_layout_dialog.h" +#include "object_type_db.h" + +void EditorLayoutDialog::clear_layout_name() { + + layout_name->clear(); +} + +void EditorLayoutDialog::ok_pressed() { + + if (layout_name->get_text()!="") { + emit_signal("layout_selected", layout_name->get_text()); + } +} + +void EditorLayoutDialog::_bind_methods() { + + ADD_SIGNAL(MethodInfo("layout_selected",PropertyInfo( Variant::STRING,"layout_name"))); +} + +EditorLayoutDialog::EditorLayoutDialog() +{ + + layout_name = memnew( LineEdit ); + layout_name->set_margin(MARGIN_TOP,5); + layout_name->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5); + layout_name->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,5); + add_child(layout_name); + move_child(layout_name, get_label()->get_index()+1); +} diff --git a/tools/editor/editor_layout_dialog.h b/tools/editor/editor_layout_dialog.h new file mode 100644 index 00000000000..7e3b9e3d8a6 --- /dev/null +++ b/tools/editor/editor_layout_dialog.h @@ -0,0 +1,53 @@ +/*************************************************************************/ +/* editor_layout_dialog.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2015 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 EDITOR_LAYOUT_DIALOG_H +#define EDITOR_LAYOUT_DIALOG_H + +#include "scene/gui/dialogs.h" +#include "scene/gui/line_edit.h" + +class EditorLayoutDialog : public ConfirmationDialog { + + OBJ_TYPE( EditorLayoutDialog, ConfirmationDialog ); + + LineEdit *layout_name; + +protected: + + static void _bind_methods(); + virtual void ok_pressed(); + +public: + void clear_layout_name(); + + EditorLayoutDialog(); +}; + +#endif // EDITOR_LAYOUT_DIALOG_H diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 7d837f3211d..b59db3d381c 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -533,7 +533,6 @@ void EditorNode::save_resource_as(const Ref& p_resource) { } - void EditorNode::_menu_option(int p_option) { _menu_option_confirm(p_option,false); @@ -1399,6 +1398,69 @@ void EditorNode::_dialog_action(String p_file) { save_resource_in_path(current_res,p_file); + } break; + case SETTINGS_LAYOUT_SAVE: { + + if (p_file.empty()) + return; + + if (p_file=="Default") { + confirm_error->set_text("Cannot overwrite default layout!"); + confirm_error->popup_centered_minsize(); + return; + } + + Ref config; + config.instance(); + Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + if (err!=OK && err!=ERR_FILE_NOT_FOUND) { + return; //no config + } + + _save_docks_to_config(config, p_file); + + config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + + layout_dialog->hide(); + _update_layouts_menu(); + + } break; + case SETTINGS_LAYOUT_DELETE: { + + if (p_file.empty()) + return; + + if (p_file=="Default") { + confirm_error->set_text("Cannot delete default layout!"); + confirm_error->popup_centered_minsize(); + return; + } + + Ref config; + config.instance(); + Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + if (err!=OK) { + return; //no config + } + + if (!config->has_section(p_file)) { + confirm_error->set_text("Layout name not found!"); + confirm_error->popup_centered_minsize(); + return; + } + + // erase + List keys; + config->get_section_keys(p_file, &keys); + for (List::Element *E=keys.front();E;E=E->next()) { + config->set_value(p_file, E->get(), Variant()); + } + + config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + + layout_dialog->hide(); + _update_layouts_menu(); + } break; default: { //save scene? @@ -4013,6 +4075,9 @@ void EditorNode::_bind_methods() { ObjectTypeDB::bind_method("_dock_move_left",&EditorNode::_dock_move_left); ObjectTypeDB::bind_method("_dock_move_right",&EditorNode::_dock_move_right); + ObjectTypeDB::bind_method("_layout_menu_option",&EditorNode::_layout_menu_option); + ObjectTypeDB::bind_method("_layout_dialog_action",&EditorNode::_dialog_action); + ObjectTypeDB::bind_method("set_current_scene",&EditorNode::set_current_scene); ObjectTypeDB::bind_method("set_current_version",&EditorNode::set_current_version); ObjectTypeDB::bind_method("_scene_tab_changed",&EditorNode::_scene_tab_changed); @@ -4305,6 +4370,15 @@ void EditorNode::_save_docks() { Ref config; config.instance(); + _save_docks_to_config(config, "docks"); + editor_data.get_plugin_window_layout(config); + + config->save(EditorSettings::get_singleton()->get_project_settings_path().plus_file("editor_layout.cfg")); + +} + +void EditorNode::_save_docks_to_config(Ref p_layout, const String& p_section) { + for(int i=0;iget_tab_count();j++) { @@ -4315,7 +4389,7 @@ void EditorNode::_save_docks() { } if (names!="") { - config->set_value("docks","dock_"+itos(i+1),names); + p_layout->set_value(p_section,"dock_"+itos(i+1),names); } } @@ -4329,7 +4403,7 @@ void EditorNode::_save_docks() { for(int i=0;iis_visible()) { - config->set_value("docks","dock_split_"+itos(i+1),splits[i]->get_split_offset()); + p_layout->set_value(p_section,"dock_split_"+itos(i+1),splits[i]->get_split_offset()); } } @@ -4343,13 +4417,9 @@ void EditorNode::_save_docks() { for(int i=0;i<4;i++) { - config->set_value("docks","dock_hsplit_"+itos(i+1),h_splits[i]->get_split_offset()); + p_layout->set_value(p_section,"dock_hsplit_"+itos(i+1),h_splits[i]->get_split_offset()); } - editor_data.get_plugin_window_layout(config); - - config->save(EditorSettings::get_singleton()->get_project_settings_path().plus_file("editor_layout.cfg")); - } void EditorNode::save_layout() { @@ -4371,12 +4441,19 @@ void EditorNode::_load_docks() { return; //no config } + _load_docks_from_config(config, "docks"); + editor_data.set_plugin_window_layout(config); + +} + +void EditorNode::_load_docks_from_config(Ref p_layout, const String& p_section) { + for(int i=0;ihas_section_key("docks","dock_"+itos(i+1))) + if (!p_layout->has_section_key(p_section,"dock_"+itos(i+1))) continue; - Vector names = String(config->get_value("docks","dock_"+itos(i+1))).split(","); + Vector names = String(p_layout->get_value(p_section,"dock_"+itos(i+1))).split(","); for(int j=0;jraise(); continue; } @@ -4411,7 +4488,6 @@ void EditorNode::_load_docks() { dock_slot[i]->add_child(node); dock_slot[i]->show(); } - } VSplitContainer*splits[DOCK_SLOT_MAX/2]={ @@ -4423,14 +4499,14 @@ void EditorNode::_load_docks() { for(int i=0;ihas_section_key("docks","dock_split_"+itos(i+1))) + if (!p_layout->has_section_key(p_section,"dock_split_"+itos(i+1))) continue; - int ofs = config->get_value("docks","dock_split_"+itos(i+1)); + int ofs = p_layout->get_value(p_section,"dock_split_"+itos(i+1)); splits[i]->set_split_offset(ofs); } - HSplitContainer *h_splits[4]={ + HSplitContainer*h_splits[4]={ left_l_hsplit, left_r_hsplit, main_hsplit, @@ -4438,9 +4514,9 @@ void EditorNode::_load_docks() { }; for(int i=0;i<4;i++) { - if (!config->has_section_key("docks","dock_hsplit_"+itos(i+1))) + if (!p_layout->has_section_key(p_section,"dock_hsplit_"+itos(i+1))) continue; - int ofs = config->get_value("docks","dock_hsplit_"+itos(i+1)); + int ofs = p_layout->get_value(p_section,"dock_hsplit_"+itos(i+1)); h_splits[i]->set_split_offset(ofs); } @@ -4458,8 +4534,78 @@ void EditorNode::_load_docks() { dock_slot[i]->set_current_tab(0); } } +} - editor_data.set_plugin_window_layout(config); + +void EditorNode::_update_layouts_menu() { + + editor_layouts->clear(); + editor_layouts->set_size(Vector2()); + editor_layouts->add_item("Save Layout", SETTINGS_LAYOUT_SAVE); + editor_layouts->add_item("Delete Layout", SETTINGS_LAYOUT_DELETE); + editor_layouts->add_separator(); + editor_layouts->add_item("Default", SETTINGS_LAYOUT_DEFAULT); + + Ref config; + config.instance(); + Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + if (err!=OK) { + return; //no config + } + + List layouts; + config.ptr()->get_sections(&layouts); + + for (List::Element *E=layouts.front();E;E=E->next()) { + + String layout=E->get(); + + if (layout!="Default") + editor_layouts->add_item(layout); + } + +} + +void EditorNode::_layout_menu_option(int p_id) { + + switch (p_id) { + + case SETTINGS_LAYOUT_SAVE: { + + current_option=p_id; + layout_dialog->clear_layout_name(); + layout_dialog->set_title("Save Layout"); + layout_dialog->get_ok()->set_text("Save"); + layout_dialog->popup_centered(); + } break; + case SETTINGS_LAYOUT_DELETE: { + + current_option=p_id; + layout_dialog->clear_layout_name(); + layout_dialog->set_title("Delete Layout"); + layout_dialog->get_ok()->set_text("Delete"); + layout_dialog->popup_centered(); + } break; + case SETTINGS_LAYOUT_DEFAULT: { + + _load_docks_from_config(default_theme, "docks"); + _save_docks(); + } break; + default: { + + Ref config; + config.instance(); + Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts.cfg")); + if (err!=OK) { + return; //no config + } + + int idx=editor_layouts->get_item_index(p_id); + _load_docks_from_config(config, editor_layouts->get_item_text(idx)); + _save_docks(); + + } + } } @@ -5179,17 +5325,29 @@ EditorNode::EditorNode() { right_menu_hb->add_child( settings_menu ); p=settings_menu->get_popup(); - //p->add_item("Export Settings",SETTINGS_EXPORT_PREFERENCES); p->add_item("Editor Settings",SETTINGS_PREFERENCES); //p->add_item("Optimization Presets",SETTINGS_OPTIMIZED_PRESETS); p->add_separator(); + editor_layouts = memnew( PopupMenu ); + editor_layouts->set_name("Layouts"); + p->add_child(editor_layouts); + editor_layouts->connect("item_pressed",this,"_layout_menu_option"); + p->add_submenu_item("Editor Layout", "Layouts"); + p->add_separator(); p->add_check_item("Show Animation",SETTINGS_SHOW_ANIMATION,KEY_MASK_CMD+KEY_N); p->add_separator(); p->add_item("Install Export Templates",SETTINGS_LOAD_EXPORT_TEMPLATES); p->add_separator(); p->add_item("About",SETTINGS_ABOUT); + layout_dialog = memnew( EditorLayoutDialog ); + gui_base->add_child(layout_dialog); + layout_dialog->set_hide_on_ok(false); + layout_dialog->set_size(Size2(175, 70)); + confirm_error = memnew( AcceptDialog ); + layout_dialog->add_child(confirm_error); + layout_dialog->connect("layout_selected", this,"_layout_dialog_action"); sources_button = memnew( ToolButton ); right_menu_hb->add_child(sources_button); @@ -5353,7 +5511,19 @@ EditorNode::EditorNode() { scenes_dock->connect("open",this,"open_request"); scenes_dock->connect("instance",this,"_instance_request"); + const String docks_section = "docks"; + default_theme.instance(); + default_theme->set_value(docks_section, "dock_3", "Scene"); + default_theme->set_value(docks_section, "dock_4", "FileSystem"); + default_theme->set_value(docks_section, "dock_5", "Inspector"); + + for(int i=0;iset_value(docks_section, "dock_hsplit_"+itos(i+1), 0); + for(int i=0;iset_value(docks_section, "dock_split_"+itos(i+1), 0); + + _update_layouts_menu(); log = memnew( EditorLog ); center_split->add_child(log); @@ -5660,7 +5830,7 @@ EditorNode::EditorNode() { resource_preview->add_preview_generator( Ref( memnew(EditorMeshPreviewPlugin ))); circle_step_msec=OS::get_singleton()->get_ticks_msec(); - circle_step_frame=OS::get_singleton()->get_frames_drawn();; + circle_step_frame=OS::get_singleton()->get_frames_drawn(); circle_step=0; _rebuild_import_menu(); diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index 002df0f3eab..d9015ea8073 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -76,6 +76,7 @@ #include "editor_reimport_dialog.h" #include "import_settings.h" #include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_layout_dialog.h" #include "fileserver/editor_file_server.h" #include "editor_resource_preview.h" @@ -166,6 +167,9 @@ class EditorNode : public Node { SETTINGS_EXPORT_PREFERENCES, SETTINGS_PREFERENCES, SETTINGS_OPTIMIZED_PRESETS, + SETTINGS_LAYOUT_SAVE, + SETTINGS_LAYOUT_DELETE, + SETTINGS_LAYOUT_DEFAULT, SETTINGS_SHOW_ANIMATION, SETTINGS_LOAD_EXPORT_TEMPLATES, SETTINGS_HELP, @@ -278,6 +282,11 @@ class EditorNode : public Node { AcceptDialog *about; AcceptDialog *warning; + Ref default_theme; + PopupMenu *editor_layouts; + EditorLayoutDialog *layout_dialog; + AcceptDialog *confirm_error; + //OptimizedPresetsDialog *optimized_presets; EditorSettingsDialog *settings_config_dialog; RunSettingsDialog *run_settings_dialog; @@ -516,10 +525,15 @@ class EditorNode : public Node { void _save_docks(); void _load_docks(); + void _save_docks_to_config(Ref p_layout, const String& p_section); + void _load_docks_from_config(Ref p_layout, const String& p_section); + + void _update_layouts_menu(); + void _layout_menu_option(int p_idx); protected: void _notification(int p_what); - static void _bind_methods(); + static void _bind_methods(); public: static EditorNode* get_singleton() { return singleton; } From 0b4830f3bebaaec75cecf48253068d35bb344859 Mon Sep 17 00:00:00 2001 From: romulox_x Date: Thu, 26 Nov 2015 13:44:06 -0800 Subject: [PATCH 14/24] Added set_hidden method to Spatial and CanvasItem --- scene/2d/canvas_item.cpp | 10 ++++++++++ scene/2d/canvas_item.h | 1 + scene/3d/spatial.cpp | 10 ++++++++++ scene/3d/spatial.h | 1 + 4 files changed, 22 insertions(+) diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 357aaa225ba..abd532c156b 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -309,6 +309,15 @@ void CanvasItem::hide() { _change_notify("visibility/visible"); } +void CanvasItem::set_hidden(bool p_hidden) { + + if (hidden == p_hidden) { + return; + } + + _set_visible_(!p_hidden); +} + Variant CanvasItem::edit_get_state() const { @@ -1043,6 +1052,7 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_hidden"),&CanvasItem::is_hidden); ObjectTypeDB::bind_method(_MD("show"),&CanvasItem::show); ObjectTypeDB::bind_method(_MD("hide"),&CanvasItem::hide); + ObjectTypeDB::bind_method(_MD("set_hidden","hidden"),&CanvasItem::set_hidden); ObjectTypeDB::bind_method(_MD("update"),&CanvasItem::update); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 4885256c648..667fedc9566 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -190,6 +190,7 @@ public: bool is_hidden() const; void show(); void hide(); + void set_hidden(bool p_hidden); void update(); diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index a65f68ed2ce..7d48420a83b 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -594,6 +594,15 @@ bool Spatial::is_hidden() const{ return !data.visible; } +void Spatial::set_hidden(bool p_hidden) { + + if (data.visible != p_hidden) { + return; + } + + _set_visible_(!p_hidden); +} + void Spatial::_set_visible_(bool p_visible) { if (p_visible) @@ -742,6 +751,7 @@ void Spatial::_bind_methods() { ObjectTypeDB::bind_method(_MD("hide"), &Spatial::hide); ObjectTypeDB::bind_method(_MD("is_visible"), &Spatial::is_visible); ObjectTypeDB::bind_method(_MD("is_hidden"), &Spatial::is_hidden); + ObjectTypeDB::bind_method(_MD("set_hidden","hidden"), &Spatial::set_hidden); ObjectTypeDB::bind_method(_MD("_set_visible_"), &Spatial::_set_visible_); ObjectTypeDB::bind_method(_MD("_is_visible_"), &Spatial::_is_visible_); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 7fa6099d7a7..b1e3a82868a 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -191,6 +191,7 @@ public: void hide(); bool is_visible() const; bool is_hidden() const; + void set_hidden(bool p_hidden); #ifdef TOOLS_ENABLED void set_import_transform(const Transform& p_transform) ; From 15f6d3cebf9e8c9288132454816f1152e16dde36 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 30 Nov 2015 01:26:51 +0100 Subject: [PATCH 15/24] Add way to look for templates at system wide level too Useful for everybody wanting to package godot. Fixes #1026. -> Retain the old behaviour: path in error msg only when exporting. -> User templates override system templates --- .gitignore | 1 + SConstruct | 1 + platform/android/export/export.cpp | 29 ++++++----- platform/bb10/export/export.cpp | 16 +++--- platform/javascript/export/export.cpp | 27 ++++++---- platform/osx/export/export.cpp | 21 ++++---- tools/editor/SCsub | 9 ++++ tools/editor/editor_import_export.cpp | 75 +++++++++++++++++++++------ tools/editor/editor_import_export.h | 2 + tools/editor/editor_settings.h | 1 + 10 files changed, 128 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index f24d91a7ee0..cfdb0af68a6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ core/global_defaults.cpp tools/editor/register_exporters.cpp tools/editor/doc_data_compressed.h tools/editor/editor_icons.cpp +tools/editor/editor_global_settings.cpp -fpic .fscache make.bat diff --git a/SConstruct b/SConstruct index 46edf06a42c..e44091d7833 100644 --- a/SConstruct +++ b/SConstruct @@ -126,6 +126,7 @@ opts.Add("CXX", "Compiler"); opts.Add("CCFLAGS", "Custom flags for the C++ compiler"); opts.Add("CFLAGS", "Custom flags for the C compiler"); opts.Add("LINKFLAGS", "Custom flags for the linker"); +opts.Add('global_settings_path', 'Path to system-wide settings. Currently only used by templates.','') opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no") opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no") opts.Add('colored', 'Enable colored output for the compilation (yes/no)', 'no') diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 1deeb3457a8..7d550f4fa05 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -1020,18 +1020,24 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d EditorProgress ep("export","Exporting for Android",104); - String apk_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (p_debug) { - - src_apk=custom_debug_package!=""?custom_debug_package:apk_path+"android_debug.apk"; - } else { - - src_apk=custom_release_package!=""?custom_release_package:apk_path+"android_release.apk"; + if (p_debug) + src_apk=custom_debug_package; + else + src_apk=custom_release_package; + if (src_apk=="") { + String err; + if (p_debug) { + src_apk=find_export_template("android_debug.apk", &err); + } else { + src_apk=find_export_template("android_release.apk", &err); + } + if (src_apk=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } } - FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); @@ -1659,10 +1665,7 @@ bool EditorExportPlatformAndroid::can_export(String *r_error) const { err+="Debug Keystore not configured in editor settings.\n"; } - - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (!FileAccess::exists(exe_path+"android_debug.apk") || !FileAccess::exists(exe_path+"android_release.apk")) { + if (!exists_export_template("android_debug.apk") || !exists_export_template("android_release.apk")) { valid=false; err+="No export templates found.\nDownload and install export templates.\n"; } diff --git a/platform/bb10/export/export.cpp b/platform/bb10/export/export.cpp index 434aaff4147..2acd920f316 100644 --- a/platform/bb10/export/export.cpp +++ b/platform/bb10/export/export.cpp @@ -275,10 +275,16 @@ Error EditorExportPlatformBB10::export_project(const String& p_path, bool p_debu EditorProgress ep("export","Exporting for BlackBerry 10",104); - String template_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - String src_template=custom_package!=""?custom_package:template_path.plus_file("bb10.zip"); + String src_template=custom_package; + if (src_template=="") { + String err; + src_template = find_export_template("bb10.zip", &err); + if (src_template=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } + } FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); @@ -733,9 +739,7 @@ bool EditorExportPlatformBB10::can_export(String *r_error) const { err+="Blackberry host tools not configured in editor settings.\n"; } - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (!FileAccess::exists(exe_path+"bb10.zip")) { + if (!exists_export_template("bb10.zip")) { valid=false; err+="No export template found.\nDownload and install export templates.\n"; } diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 9e2595f4a16..acbcbb46524 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -205,18 +205,24 @@ Error EditorExportPlatformJavaScript::export_project(const String& p_path, bool EditorProgress ep("export","Exporting for javascript",104); - String template_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (p_debug) { - - src_template=custom_debug_package!=""?custom_debug_package:template_path+"javascript_debug.zip"; - } else { - - src_template=custom_release_package!=""?custom_release_package:template_path+"javascript_release.zip"; + if (p_debug) + src_template=custom_debug_package; + else + src_template=custom_release_package; + if (src_template=="") { + String err; + if (p_debug) { + src_template=find_export_template("javascript_debug.zip", &err); + } else { + src_template=find_export_template("javascript_release.zip", &err); + } + if (src_template=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } } - FileAccess *src_f=NULL; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); @@ -337,9 +343,8 @@ bool EditorExportPlatformJavaScript::can_export(String *r_error) const { bool valid=true; String err; - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - if (!FileAccess::exists(exe_path+"javascript_debug.zip") || !FileAccess::exists(exe_path+"javascript_release.zip")) { + if (!exists_export_template("javascript_debug.zip") || !exists_export_template("javascript_release.zip")) { valid=false; err+="No export templates found.\nDownload and install export templates.\n"; } diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 79ee91bc61b..0bece6ec760 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -251,15 +251,19 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug EditorProgress ep("export","Exporting for OSX",104); - String pkg_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/osx.zip"; - if (p_debug) { - - src_pkg=custom_debug_package!=""?custom_debug_package:pkg_path; - } else { - - src_pkg=custom_release_package!=""?custom_release_package:pkg_path; + if (p_debug) + src_pkg=custom_debug_package; + else + src_pkg=custom_release_package; + if (src_pkg=="") { + String err; + src_pkg=find_export_template("osx.zip", &err); + if (src_pkg=="") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } } @@ -464,9 +468,8 @@ bool EditorExportPlatformOSX::can_export(String *r_error) const { bool valid=true; String err; - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - if (!FileAccess::exists(exe_path+"osx.zip")) { + if (!exists_export_template("osx.zip")) { valid=false; err+="No export templates found.\nDownload and install export templates.\n"; } diff --git a/tools/editor/SCsub b/tools/editor/SCsub index cd46ff83533..c96386fb18d 100644 --- a/tools/editor/SCsub +++ b/tools/editor/SCsub @@ -44,6 +44,15 @@ if (env["tools"]=="yes"): f.write(reg_exporters) f.close() + ed_gl_set='#include "editor_settings.h"\n' + ed_gl_set+='String EditorSettings::get_global_settings_path() const {\n' + ed_gl_set+='\treturn "' + env["global_settings_path"]+'";\n' + ed_gl_set+='}\n' + reg_exporters+='}\n' + f = open("editor_global_settings.cpp","wb") + f.write(ed_gl_set) + f.close() + env.Depends("#tools/editor/doc_data_compressed.h","#doc/base/classes.xml") env.Command("#tools/editor/doc_data_compressed.h","#doc/base/classes.xml",make_doc_header) diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp index f52c6e67a26..5ecc6f67042 100644 --- a/tools/editor/editor_import_export.cpp +++ b/tools/editor/editor_import_export.cpp @@ -399,6 +399,40 @@ Vector EditorExportPlatform::get_dependencies(bool p_bundles) const } +String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { + String user_file = EditorSettings::get_singleton()->get_settings_path() + +"/templates/"+template_file_name; + String system_file=EditorSettings::get_singleton()->get_global_settings_path(); + bool has_system_path=(system_file!=""); + system_file+="/templates/"+template_file_name; + + // Prefer user file + if (FileAccess::exists(user_file)) { + return user_file; + } + + // Now check system file + if (has_system_path) { + if (FileAccess::exists(system_file)) { + return system_file; + } + } + + // Not found + if (err) { + *err+="No export template found at \""+user_file+"\""; + if (has_system_path) + *err+="\n or \""+system_file+"\"."; + else + *err+="."; + } + return ""; +} + +bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const { + return find_export_template(template_file_name,err)!=""; +} + /////////////////////////////////////// @@ -1131,19 +1165,32 @@ Error EditorExportPlatformPC::export_project(const String& p_path, bool p_debug, ep.step("Setting Up..",0); - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - if (use64) { - if (p_debug) - exe_path=custom_debug_binary!=""?custom_debug_binary:exe_path+debug_binary64; - else - exe_path=custom_release_binary!=""?custom_release_binary:exe_path+release_binary64; - } else { + String exe_path=""; - if (p_debug) - exe_path=custom_debug_binary!=""?custom_debug_binary:exe_path+debug_binary32; - else - exe_path=custom_release_binary!=""?custom_release_binary:exe_path+release_binary32; + if (p_debug) + exe_path=custom_debug_binary; + else + exe_path=custom_release_binary; + if (exe_path=="") { + String fname; + if (use64) { + if (p_debug) + fname=debug_binary64; + else + fname=release_binary64; + } else { + if (p_debug) + fname=debug_binary32; + else + fname=release_binary32; + } + String err=""; + exe_path=find_export_template(fname,&err); + if (exe_path=="") { + EditorNode::add_io_error(err); + return ERR_FILE_CANT_READ; + } } FileAccess *src_exe=FileAccess::open(exe_path,FileAccess::READ); @@ -1207,14 +1254,12 @@ bool EditorExportPlatformPC::can_export(String *r_error) const { String err; bool valid=true; - String exe_path = EditorSettings::get_singleton()->get_settings_path()+"/templates/"; - - if (use64 && (!FileAccess::exists(exe_path+debug_binary64) || !FileAccess::exists(exe_path+release_binary64))) { + if (use64 && (!exists_export_template(debug_binary64)) || !exists_export_template(release_binary64)) { valid=false; err="No 64 bits export templates found.\nDownload and install export templates.\n"; } - if (!use64 && (!FileAccess::exists(exe_path+debug_binary32) || !FileAccess::exists(exe_path+release_binary32))) { + if (!use64 && (!exists_export_template(debug_binary32) || !exists_export_template(release_binary32))) { valid=false; err="No 32 bits export templates found.\nDownload and install export templates.\n"; } diff --git a/tools/editor/editor_import_export.h b/tools/editor/editor_import_export.h index 1a3171e66ba..1147a3abf5b 100644 --- a/tools/editor/editor_import_export.h +++ b/tools/editor/editor_import_export.h @@ -86,6 +86,8 @@ protected: Vector get_exported_file_default(String& p_fname) const; virtual Vector get_exported_file(String& p_fname) const; virtual Vector get_dependencies(bool p_bundles) const; + virtual String find_export_template(String template_file_name, String *err=NULL) const; + virtual bool exists_export_template(String template_file_name, String *err=NULL) const; struct TempData { diff --git a/tools/editor/editor_settings.h b/tools/editor/editor_settings.h index 4ba940cd1c9..bdfa5160d6f 100644 --- a/tools/editor/editor_settings.h +++ b/tools/editor/editor_settings.h @@ -107,6 +107,7 @@ public: static EditorSettings *get_singleton(); void erase(String p_var); String get_settings_path() const; + String get_global_settings_path() const; String get_project_settings_path() const; const Map& get_plugins() const { return plugins; } From e1d02e4831fdec372771956aa2ac70954ab3fe7b Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 30 Nov 2015 02:35:59 +0100 Subject: [PATCH 16/24] Make the setting unix-only. For this, put the detection into the OS class and its subclass. --- .gitignore | 2 +- SConstruct | 2 +- core/os/os.h | 1 + drivers/unix/SCsub | 8 ++++++++ drivers/unix/os_unix.cpp | 8 ++++++++ drivers/unix/os_unix.h | 3 +++ tools/editor/SCsub | 9 --------- tools/editor/editor_import_export.cpp | 4 ++-- 8 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index cfdb0af68a6..d9473065585 100644 --- a/.gitignore +++ b/.gitignore @@ -15,10 +15,10 @@ core/method_bind.inc core/method_bind_ext.inc core/script_encryption_key.cpp core/global_defaults.cpp +drivers/unix/os_unix_global_settings_path.cpp tools/editor/register_exporters.cpp tools/editor/doc_data_compressed.h tools/editor/editor_icons.cpp -tools/editor/editor_global_settings.cpp -fpic .fscache make.bat diff --git a/SConstruct b/SConstruct index e44091d7833..caf9ce1eea9 100644 --- a/SConstruct +++ b/SConstruct @@ -126,7 +126,7 @@ opts.Add("CXX", "Compiler"); opts.Add("CCFLAGS", "Custom flags for the C++ compiler"); opts.Add("CFLAGS", "Custom flags for the C compiler"); opts.Add("LINKFLAGS", "Custom flags for the linker"); -opts.Add('global_settings_path', 'Path to system-wide settings. Currently only used by templates.','') +opts.Add('unix_global_settings_path', 'unix-specific path to system-wide settings. Currently only used by templates.','') opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no") opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no") opts.Add('colored', 'Enable colored output for the compilation (yes/no)', 'no') diff --git a/core/os/os.h b/core/os/os.h index e5338b4a02f..e908177df76 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -184,6 +184,7 @@ public: virtual void set_low_processor_usage_mode(bool p_enabled); virtual bool is_in_low_processor_usage_mode() const; + virtual String get_installed_templates_path() const { return ""; }; virtual String get_executable_path() const; virtual Error execute(const String& p_path, const List& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL)=0; virtual Error kill(const ProcessID& p_pid)=0; diff --git a/drivers/unix/SCsub b/drivers/unix/SCsub index 9fbb467baa1..e8b3cadfc77 100644 --- a/drivers/unix/SCsub +++ b/drivers/unix/SCsub @@ -1,5 +1,13 @@ Import('env') +ed_gl_set='#include "os_unix.h"\n' +ed_gl_set+='String OS_Unix::get_global_settings_path() const {\n' +ed_gl_set+='\treturn "' + env["unix_global_settings_path"]+'";\n' +ed_gl_set+='}\n' +f = open("os_unix_global_settings_path.cpp","wb") +f.write(ed_gl_set) +f.close() + env.add_source_files(env.drivers_sources,"*.cpp") Export('env') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index fd8c26f6d9a..94a7b03f451 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -477,6 +477,14 @@ String OS_Unix::get_data_dir() const { } +String OS_Unix::get_installed_templates_path() const { + String p=get_global_settings_path(); + if (p!="") + return p+"/templates/"; + else + return ""; +} + String OS_Unix::get_executable_path() const { #ifdef __linux__ diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 2ee6102164d..9ac18c90557 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -64,6 +64,8 @@ protected: String stdin_buf; + String get_global_settings_path() const; + public: @@ -111,6 +113,7 @@ public: virtual void debug_break(); + virtual String get_installed_templates_path() const; virtual String get_executable_path() const; virtual String get_data_dir() const; diff --git a/tools/editor/SCsub b/tools/editor/SCsub index c96386fb18d..cd46ff83533 100644 --- a/tools/editor/SCsub +++ b/tools/editor/SCsub @@ -44,15 +44,6 @@ if (env["tools"]=="yes"): f.write(reg_exporters) f.close() - ed_gl_set='#include "editor_settings.h"\n' - ed_gl_set+='String EditorSettings::get_global_settings_path() const {\n' - ed_gl_set+='\treturn "' + env["global_settings_path"]+'";\n' - ed_gl_set+='}\n' - reg_exporters+='}\n' - f = open("editor_global_settings.cpp","wb") - f.write(ed_gl_set) - f.close() - env.Depends("#tools/editor/doc_data_compressed.h","#doc/base/classes.xml") env.Command("#tools/editor/doc_data_compressed.h","#doc/base/classes.xml",make_doc_header) diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp index 5ecc6f67042..2bd4fb52c05 100644 --- a/tools/editor/editor_import_export.cpp +++ b/tools/editor/editor_import_export.cpp @@ -402,9 +402,9 @@ Vector EditorExportPlatform::get_dependencies(bool p_bundles) const String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { String user_file = EditorSettings::get_singleton()->get_settings_path() +"/templates/"+template_file_name; - String system_file=EditorSettings::get_singleton()->get_global_settings_path(); + String system_file=OS::get_singleton()->get_installed_templates_path(); bool has_system_path=(system_file!=""); - system_file+="/templates/"+template_file_name; + system_file+=template_file_name; // Prefer user file if (FileAccess::exists(user_file)) { From d6d335f20c09efc19825d77824d6784fc304680e Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Thu, 3 Dec 2015 14:59:59 -0300 Subject: [PATCH 17/24] Make ItemListEditor plugin functional --- .../plugins/item_list_editor_plugin.cpp | 395 ++++++++---------- .../editor/plugins/item_list_editor_plugin.h | 142 +++++-- tools/editor/property_editor.cpp | 14 +- tools/editor/property_editor.h | 4 +- 4 files changed, 298 insertions(+), 257 deletions(-) diff --git a/tools/editor/plugins/item_list_editor_plugin.cpp b/tools/editor/plugins/item_list_editor_plugin.cpp index fa261edea30..9c53c73afdf 100644 --- a/tools/editor/plugins/item_list_editor_plugin.cpp +++ b/tools/editor/plugins/item_list_editor_plugin.cpp @@ -30,7 +30,6 @@ #include "io/resource_loader.h" - bool ItemListPlugin::_set(const StringName& p_name, const Variant& p_value) { String name = p_name; @@ -45,12 +44,10 @@ bool ItemListPlugin::_set(const StringName& p_name, const Variant& p_value) { set_item_checkable(idx,p_value); else if (what=="checked") set_item_checked(idx,p_value); - else if (what=="enabled") - set_item_enabled(idx,p_value); - else if (what=="accel") - set_item_accel(idx,p_value); else if (what=="id") set_item_id(idx,p_value); + else if (what=="enabled") + set_item_enabled(idx,p_value); else if (what=="separator") set_item_separator(idx,p_value); else @@ -60,6 +57,7 @@ bool ItemListPlugin::_set(const StringName& p_name, const Variant& p_value) { } bool ItemListPlugin::_get(const StringName& p_name,Variant &r_ret) const { + String name = p_name; int idx = name.get_slice("/",0).to_int(); String what=name.get_slice("/",1); @@ -72,12 +70,10 @@ bool ItemListPlugin::_get(const StringName& p_name,Variant &r_ret) const { r_ret=is_item_checkable(idx); else if (what=="checked") r_ret=is_item_checked(idx); - else if (what=="enabled") - r_ret=is_item_enabled(idx); - else if (what=="accel") - r_ret=get_item_accel(idx); else if (what=="id") r_ret=get_item_id(idx); + else if (what=="enabled") + r_ret=is_item_enabled(idx); else if (what=="separator") r_ret=is_item_separator(idx); else @@ -93,35 +89,112 @@ void ItemListPlugin::_get_property_list( List *p_list) const { p_list->push_back( PropertyInfo(Variant::STRING,base+"text") ); p_list->push_back( PropertyInfo(Variant::OBJECT,base+"icon",PROPERTY_HINT_RESOURCE_TYPE,"Texture") ); - if (get_flags()&FLAG_CHECKABLE) { + int flags = get_flags(); + + if (flags&FLAG_CHECKABLE) { p_list->push_back( PropertyInfo(Variant::BOOL,base+"checkable") ); p_list->push_back( PropertyInfo(Variant::BOOL,base+"checked") ); - } - if (get_flags()&FLAG_ENABLE) { - - p_list->push_back( PropertyInfo(Variant::BOOL,base+"enabled") ); - - } - if (get_flags()&FLAG_ACCEL) { - - p_list->push_back( PropertyInfo(Variant::INT,base+"accel",PROPERTY_HINT_KEY_ACCEL) ); - - } - if (get_flags()&FLAG_ID) { + if (flags&FLAG_ID) p_list->push_back( PropertyInfo(Variant::INT,base+"id",PROPERTY_HINT_RANGE,"-1,4096") ); - } - if (get_flags()&FLAG_SEPARATOR) { + if (flags&FLAG_ENABLE) + p_list->push_back( PropertyInfo(Variant::BOOL,base+"enabled") ); + if (flags&FLAG_SEPARATOR) p_list->push_back( PropertyInfo(Variant::BOOL,base+"separator") ); - - } } } +/////////////////////////////////////////////////////////////// +///////////////////////// PLUGINS ///////////////////////////// +/////////////////////////////////////////////////////////////// + +void ItemListOptionButtonPlugin::set_object(Object *p_object) { + + ob = p_object->cast_to(); +} + +bool ItemListOptionButtonPlugin::handles(Object *p_object) const { + + return p_object->is_type("OptionButton"); +} + +int ItemListOptionButtonPlugin::get_flags() const { + + return FLAG_ICON|FLAG_ID|FLAG_ENABLE; +} + +void ItemListOptionButtonPlugin::add_item() { + + ob->add_item( "Item "+itos(ob->get_item_count())); + _change_notify(); +} + +int ItemListOptionButtonPlugin::get_item_count() const { + + return ob->get_item_count(); +} + +void ItemListOptionButtonPlugin::erase(int p_idx) { + + ob->remove_item(p_idx); + _change_notify(); +} + +ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() { + + ob=NULL; +} + +/////////////////////////////////////////////////////////////// + +void ItemListPopupMenuPlugin::set_object(Object *p_object) { + + if (p_object->is_type("MenuButton")) + pp = p_object->cast_to()->get_popup(); + else + pp = p_object->cast_to(); +} + +bool ItemListPopupMenuPlugin::handles(Object *p_object) const { + + return p_object->is_type("PopupMenu") || p_object->is_type("MenuButton"); +} + +int ItemListPopupMenuPlugin::get_flags() const { + + return FLAG_ICON|FLAG_CHECKABLE|FLAG_ID|FLAG_ENABLE|FLAG_SEPARATOR; +} + +void ItemListPopupMenuPlugin::add_item() { + + pp->add_item( "Item "+itos(pp->get_item_count())); + _change_notify(); +} + +int ItemListPopupMenuPlugin::get_item_count() const { + + return pp->get_item_count(); +} + +void ItemListPopupMenuPlugin::erase(int p_idx) { + + pp->remove_item(p_idx); + _change_notify(); +} + +ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() { + + pp=NULL; +} + +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////// + void ItemListEditor::_node_removed(Node *p_node) { if(p_node==item_list) { @@ -129,30 +202,6 @@ void ItemListEditor::_node_removed(Node *p_node) { hide(); dialog->hide(); } - - -} - -void ItemListEditor::_delete_pressed() { - - String p = prop_editor->get_selected_path(); - - if (p.find("/")!=-1) { - - if (selected_idx<0 || selected_idx>=item_plugins.size()) - return; - - item_plugins[selected_idx]->erase(p.get_slice("/",0).to_int());; - } - -} - -void ItemListEditor::_add_pressed() { - - if (selected_idx<0 || selected_idx>=item_plugins.size()) - return; - - item_plugins[selected_idx]->add_item(); } void ItemListEditor::_notification(int p_notification) { @@ -160,57 +209,73 @@ void ItemListEditor::_notification(int p_notification) { if (p_notification==NOTIFICATION_ENTER_TREE) { add_button->set_icon(get_icon("Add","EditorIcons")); - del_button->set_icon(get_icon("Del","EditorIcons")); + del_button->set_icon(get_icon("Remove","EditorIcons")); } } +void ItemListEditor::_add_pressed() { -void ItemListEditor::_menu_option(int p_option) { + if (selected_idx==-1) + return; - - switch(p_option) { - - case MENU_EDIT_ITEMS: { - - dialog->popup_centered_ratio(); - } break; - } + item_plugins[selected_idx]->add_item(); } +void ItemListEditor::_delete_pressed() { + + TreeItem *ti = tree->get_selected(); + + if (!ti) + return; + + if (ti->get_parent()!=tree->get_root()) + return; + + int idx = ti->get_text(0).to_int(); + + if (selected_idx==-1) + return; + + item_plugins[selected_idx]->erase(idx); +} + +void ItemListEditor::_edit_items() { + + dialog->popup_centered(Vector2(300, 400)); +} void ItemListEditor::edit(Node *p_item_list) { item_list=p_item_list; + if (!item_list) { + selected_idx=-1; + property_editor->edit(NULL); + return; + } + for(int i=0;ihandles(p_item_list)) { item_plugins[i]->set_object(p_item_list); - prop_editor->edit(item_plugins[i]); + property_editor->edit(item_plugins[i]); + + if (has_icon(item_list->get_type(), "EditorIcons")) + toolbar_button->set_icon(get_icon(item_list->get_type(), "EditorIcons")); + else + toolbar_button->set_icon(Ref()); + selected_idx=i; return; } } selected_idx=-1; - - prop_editor->edit(NULL); - -} - - -void ItemListEditor::_bind_methods() { - - ObjectTypeDB::bind_method("_menu_option",&ItemListEditor::_menu_option); - ObjectTypeDB::bind_method("_add_button",&ItemListEditor::_add_pressed); - ObjectTypeDB::bind_method("_delete_button",&ItemListEditor::_delete_pressed); - - //ObjectTypeDB::bind_method("_populate",&ItemListEditor::_populate); - + property_editor->edit(NULL); } bool ItemListEditor::handles(Object *p_object) const { - return false; + for(int i=0;ihandles(p_object)) { return true; @@ -218,56 +283,64 @@ bool ItemListEditor::handles(Object *p_object) const { } return false; - } + +void ItemListEditor::_bind_methods() { + + ObjectTypeDB::bind_method("_edit_items",&ItemListEditor::_edit_items); + ObjectTypeDB::bind_method("_add_button",&ItemListEditor::_add_pressed); + ObjectTypeDB::bind_method("_delete_button",&ItemListEditor::_delete_pressed); +} + ItemListEditor::ItemListEditor() { selected_idx=-1; - options = memnew( MenuButton ); - add_child(options); - options->set_area_as_parent_rect(); - options->set_text("Items"); - options->get_popup()->add_item("Edit Items",MENU_EDIT_ITEMS); - //options->get_popup()->add_item("Clear",MENU_CLEAR); + add_child( memnew( VSeparator ) ); - options->get_popup()->connect("item_pressed", this,"_menu_option"); + toolbar_button = memnew( ToolButton ); + toolbar_button->set_text("Items"); + add_child(toolbar_button); + toolbar_button->connect("pressed",this,"_edit_items"); dialog = memnew( AcceptDialog ); + dialog->set_title("Item List Editor"); add_child( dialog ); - + VBoxContainer *vbc = memnew( VBoxContainer ); + dialog->add_child(vbc); + dialog->set_child_rect(vbc); HBoxContainer *hbc = memnew( HBoxContainer ); - - dialog->add_child(hbc); - dialog->set_child_rect(hbc); - - prop_editor = memnew( PropertyEditor ); - - hbc->add_child(prop_editor); - prop_editor->set_h_size_flags(SIZE_EXPAND_FILL); - - VBoxContainer *vbc = memnew( VBoxContainer ); - hbc->add_child(vbc); + hbc->set_h_size_flags(SIZE_EXPAND_FILL); + vbc->add_child(hbc); add_button = memnew( Button ); - //add_button->set_text("Add"); + add_button->set_text("Add"); + hbc->add_child(add_button); add_button->connect("pressed",this,"_add_button"); - vbc->add_child(add_button); + + hbc->add_spacer(); del_button = memnew( Button ); - //del_button->set_text("Del"); + del_button->set_text("Delete"); + hbc->add_child(del_button); del_button->connect("pressed",this,"_delete_button"); - vbc->add_child(del_button); - - dialog->set_title("Item List"); - prop_editor->hide_top_label(); - + property_editor = memnew( PropertyEditor ); + property_editor->hide_top_label(); + property_editor->set_subsection_selectable(true); + vbc->add_child(property_editor); + property_editor->set_v_size_flags(SIZE_EXPAND_FILL); + tree = property_editor->get_scene_tree(); } +ItemListEditor::~ItemListEditor() { + + for(int i=0;ihide(); item_list_editor->edit(NULL); } - } - -ItemListEditor::~ItemListEditor() { - - for(int i=0;icast_to(); } - - virtual bool handles(Object *p_object) const { return p_object->cast_to()!=NULL; } - - virtual int get_flags() const { return FLAG_ICON|FLAG_ID|FLAG_ENABLE; } - - virtual void set_item_text(int p_idx,const String& p_text){ ob->set_item_text(p_idx,p_text);} - virtual void set_item_icon(int p_idx,const Ref& p_tex){ ob->set_item_icon(p_idx,p_tex);} - virtual void set_item_enabled(int p_idx,int p_enabled){ ob->set_item_disabled(p_idx,!p_enabled);} - virtual void set_item_id(int p_idx,int p_id){ ob->set_item_ID(p_idx,p_id);} - - - virtual String get_item_text(int p_idx) const{ return ob->get_item_text(p_idx); }; - virtual Ref get_item_icon(int p_idx) const{ return ob->get_item_icon(p_idx); }; - virtual bool is_item_enabled(int p_idx) const{ return !ob->is_item_disabled(p_idx); }; - virtual int get_item_id(int p_idx) const{ return ob->get_item_ID(p_idx); }; - - virtual void add_item() { ob->add_item( "New Item "+itos(ob->get_item_count())); _change_notify();} - virtual int get_item_count() const { return ob->get_item_count(); } - virtual void erase(int p_idx) { ob->remove_item(p_idx); _change_notify();} - - - ItemListOptionButtonPlugin() { ob=NULL; } -}; - -class ItemListPopupMenuPlugin : public ItemListPlugin { - - OBJ_TYPE(ItemListPopupMenuPlugin,ItemListPlugin); - - PopupMenu *pp; -public: - - virtual void set_object(Object *p_object) { - if (p_object->cast_to()) - pp = p_object->cast_to()->get_popup(); - else - pp = p_object->cast_to(); - } - - virtual bool handles(Object *p_object) const { return p_object->cast_to()!=NULL || p_object->cast_to()!=NULL; } - - virtual int get_flags() const { return FLAG_ICON|FLAG_ID|FLAG_ENABLE|FLAG_CHECKABLE|FLAG_SEPARATOR|FLAG_ACCEL; } - - virtual void set_item_text(int p_idx,const String& p_text){ pp->set_item_text(p_idx,p_text); } - virtual void set_item_icon(int p_idx,const Ref& p_tex){ pp->set_item_icon(p_idx,p_tex);} - virtual void set_item_checkable(int p_idx,bool p_check){ pp->set_item_as_checkable(p_idx,p_check);} - virtual void set_item_checked(int p_idx,bool p_checked){ pp->set_item_checked(p_idx,p_checked);} - virtual void set_item_accel(int p_idx,int p_accel){ pp->set_item_accelerator(p_idx,p_accel);} - virtual void set_item_enabled(int p_idx,int p_enabled){ pp->set_item_disabled(p_idx,!p_enabled);} - virtual void set_item_id(int p_idx,int p_id){ pp->set_item_ID(p_idx,p_idx);} - virtual void set_item_separator(int p_idx,bool p_separator){ pp->set_item_as_separator(p_idx,p_separator);} - - - virtual String get_item_text(int p_idx) const{ return pp->get_item_text(p_idx); }; - virtual Ref get_item_icon(int p_idx) const{ return pp->get_item_icon(p_idx); }; - virtual bool is_item_checkable(int p_idx) const{ return pp->is_item_checkable(p_idx); }; - virtual bool is_item_checked(int p_idx) const{ return pp->is_item_checked(p_idx); }; - virtual int get_item_accel(int p_idx) const{ return pp->get_item_accelerator(p_idx); }; - virtual bool is_item_enabled(int p_idx) const{ return !pp->is_item_disabled(p_idx); }; - virtual int get_item_id(int p_idx) const{ return pp->get_item_ID(p_idx); }; - virtual bool is_item_separator(int p_idx) const{ return pp->is_item_separator(p_idx); }; - - - - virtual void add_item() { pp->add_item( "New Item "+itos(pp->get_item_count())); _change_notify();} - virtual int get_item_count() const { return pp->get_item_count(); } - virtual void erase(int p_idx) { pp->remove_item(p_idx); _change_notify();} - - - ItemListPopupMenuPlugin() { pp=NULL; } -}; - - - - - - ItemListEditorPlugin::ItemListEditorPlugin(EditorNode *p_node) { editor=p_node; item_list_editor = memnew( ItemListEditor ); - editor->get_viewport()->add_child(item_list_editor); - -// item_list_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END); -// item_list_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END); - item_list_editor->set_margin(MARGIN_LEFT,180); - item_list_editor->set_margin(MARGIN_RIGHT,230); - item_list_editor->set_margin(MARGIN_TOP,0); - item_list_editor->set_margin(MARGIN_BOTTOM,10); - + CanvasItemEditor::get_singleton()->add_control_to_menu_panel(item_list_editor); item_list_editor->hide(); - item_list_editor->add_plugin( memnew( ItemListOptionButtonPlugin) ); - item_list_editor->add_plugin( memnew( ItemListPopupMenuPlugin) ); + item_list_editor->add_plugin( memnew( ItemListOptionButtonPlugin ) ); + item_list_editor->add_plugin( memnew( ItemListPopupMenuPlugin ) ); } - ItemListEditorPlugin::~ItemListEditorPlugin() { } diff --git a/tools/editor/plugins/item_list_editor_plugin.h b/tools/editor/plugins/item_list_editor_plugin.h index 351dbb800d4..b40a2c22f85 100644 --- a/tools/editor/plugins/item_list_editor_plugin.h +++ b/tools/editor/plugins/item_list_editor_plugin.h @@ -31,10 +31,11 @@ #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_node.h" +#include "canvas_item_editor_plugin.h" + #include "scene/gui/option_button.h" #include "scene/gui/menu_button.h" #include "scene/gui/popup_menu.h" -#include "scene/gui/spin_box.h" /** @author Juan Linietsky @@ -51,43 +52,42 @@ protected: bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List *p_list) const; - public: enum Flags { FLAG_ICON=1, FLAG_CHECKABLE=2, - FLAG_ACCEL=4, - FLAG_ID=8, - FLAG_ENABLE=16, - FLAG_SEPARATOR=32 + FLAG_ID=4, + FLAG_ENABLE=8, + FLAG_SEPARATOR=16 }; virtual void set_object(Object *p_object)=0; - virtual bool handles(Object *p_object) const=0; virtual int get_flags() const=0; - virtual void set_item_text(int p_idx,const String& p_text){} - virtual void set_item_icon(int p_idx,const Ref& p_tex){} - virtual void set_item_checkable(int p_idx,bool p_check){} - virtual void set_item_checked(int p_idx,bool p_checked){} - virtual void set_item_accel(int p_idx,int p_accel){} - virtual void set_item_enabled(int p_idx,int p_enabled){} - virtual void set_item_id(int p_idx,int p_id){} - virtual void set_item_separator(int p_idx,bool p_separator){} - - + virtual void set_item_text(int p_idx, const String& p_text) {} virtual String get_item_text(int p_idx) const{ return ""; }; + + virtual void set_item_icon(int p_idx, const Ref& p_tex) {} virtual Ref get_item_icon(int p_idx) const{ return Ref(); }; + + virtual void set_item_checkable(int p_idx, bool p_check) {} virtual bool is_item_checkable(int p_idx) const{ return false; }; + + virtual void set_item_checked(int p_idx, bool p_checked) {} virtual bool is_item_checked(int p_idx) const{ return false; }; - virtual int get_item_accel(int p_idx) const{ return 0; }; + + virtual void set_item_enabled(int p_idx, int p_enabled) {} virtual bool is_item_enabled(int p_idx) const{ return false; }; + + virtual void set_item_id(int p_idx, int p_id) {} virtual int get_item_id(int p_idx) const{ return -1; }; - virtual bool is_item_separator(int p_idx) const{ return false; }; + + virtual void set_item_separator(int p_idx, bool p_separator) {} + virtual bool is_item_separator(int p_idx) const { return false; }; virtual void add_item()=0; virtual int get_item_count() const=0; @@ -96,41 +96,107 @@ public: ItemListPlugin() {} }; -class ItemListEditor : public Control { +/////////////////////////////////////////////////////////////// - OBJ_TYPE(ItemListEditor, Control ); +class ItemListOptionButtonPlugin : public ItemListPlugin { + + OBJ_TYPE(ItemListOptionButtonPlugin,ItemListPlugin); + + OptionButton *ob; +public: + + virtual void set_object(Object *p_object); + virtual bool handles(Object *p_object) const; + virtual int get_flags() const; + + virtual void set_item_text(int p_idx, const String& p_text) { ob->set_item_text(p_idx,p_text); } + virtual String get_item_text(int p_idx) const { return ob->get_item_text(p_idx); } + + virtual void set_item_icon(int p_idx, const Ref& p_tex) { ob->set_item_icon(p_idx, p_tex); } + virtual Ref get_item_icon(int p_idx) const { return ob->get_item_icon(p_idx); } + + virtual void set_item_enabled(int p_idx, int p_enabled) { ob->set_item_disabled(p_idx, !p_enabled); } + virtual bool is_item_enabled(int p_idx) const { return !ob->is_item_disabled(p_idx); } + + virtual void set_item_id(int p_idx, int p_id) { ob->set_item_ID(p_idx,p_id); } + virtual int get_item_id(int p_idx) const { return ob->get_item_ID(p_idx); } + + virtual void add_item(); + virtual int get_item_count() const; + virtual void erase(int p_idx); + + ItemListOptionButtonPlugin(); +}; + +class ItemListPopupMenuPlugin : public ItemListPlugin { + + OBJ_TYPE(ItemListPopupMenuPlugin,ItemListPlugin); + + PopupMenu *pp; +public: + + virtual void set_object(Object *p_object); + virtual bool handles(Object *p_object) const; + virtual int get_flags() const; + + virtual void set_item_text(int p_idx, const String& p_text) { pp->set_item_text(p_idx,p_text); } + virtual String get_item_text(int p_idx) const { return pp->get_item_text(p_idx); } + + virtual void set_item_icon(int p_idx, const Ref& p_tex) { pp->set_item_icon(p_idx,p_tex); } + virtual Ref get_item_icon(int p_idx) const { return pp->get_item_icon(p_idx); } + + virtual void set_item_checkable(int p_idx, bool p_check) { pp->set_item_as_checkable(p_idx,p_check); } + virtual bool is_item_checkable(int p_idx) const { return pp->is_item_checkable(p_idx); } + + virtual void set_item_checked(int p_idx, bool p_checked) { pp->set_item_checked(p_idx,p_checked); } + virtual bool is_item_checked(int p_idx) const { return pp->is_item_checked(p_idx); } + + virtual void set_item_enabled(int p_idx, int p_enabled) { pp->set_item_disabled(p_idx,!p_enabled); } + virtual bool is_item_enabled(int p_idx) const { return !pp->is_item_disabled(p_idx); } + + virtual void set_item_id(int p_idx, int p_id) { pp->set_item_ID(p_idx,p_idx); } + virtual int get_item_id(int p_idx) const { return pp->get_item_ID(p_idx); } + + virtual void set_item_separator(int p_idx, bool p_separator) { pp->set_item_as_separator(p_idx,p_separator); } + virtual bool is_item_separator(int p_idx) const { return pp->is_item_separator(p_idx); } + + virtual void add_item(); + virtual int get_item_count() const; + virtual void erase(int p_idx); + + ItemListPopupMenuPlugin(); +}; + +/////////////////////////////////////////////////////////////// + +class ItemListEditor : public HBoxContainer { + + OBJ_TYPE(ItemListEditor,HBoxContainer); Node *item_list; - enum { - - MENU_EDIT_ITEMS, - MENU_CLEAR - }; + ToolButton *toolbar_button; AcceptDialog *dialog; - - PropertyEditor *prop_editor; - - MenuButton * options; - int selected_idx; - + PropertyEditor *property_editor; + Tree *tree; Button *add_button; Button *del_button; - -// FileDialog *emission_file_dialog; - void _menu_option(int); + int selected_idx; Vector item_plugins; - void _node_removed(Node *p_node); + void _edit_items(); + void _add_pressed(); void _delete_pressed(); + + void _node_removed(Node *p_node); + protected: void _notification(int p_notification); - static void _bind_methods(); public: @@ -143,7 +209,7 @@ public: class ItemListEditorPlugin : public EditorPlugin { - OBJ_TYPE( ItemListEditorPlugin, EditorPlugin ); + OBJ_TYPE(ItemListEditorPlugin,EditorPlugin); ItemListEditor *item_list_editor; EditorNode *editor; diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 0fe3dee2ea4..7ab09f04874 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -2207,9 +2207,9 @@ TreeItem *PropertyEditor::get_parent_node(String p_path,HashMapset_editable(0,false); - item->set_selectable(0,false); + item->set_selectable(0,subsection_selectable); item->set_editable(1,false); - item->set_selectable(1,false); + item->set_selectable(1,subsection_selectable); if (item->get_parent()==root) { @@ -3511,7 +3511,15 @@ void PropertyEditor::register_text_enter(Node* p_line_edit) { if (search_box) search_box->connect("text_changed",this,"_filter_changed"); +} +void PropertyEditor::set_subsection_selectable(bool p_selectable) { + + if (p_selectable==subsection_selectable) + return; + + subsection_selectable=p_selectable; + update_tree(); } PropertyEditor::PropertyEditor() { @@ -3573,8 +3581,8 @@ PropertyEditor::PropertyEditor() { show_categories=false; refresh_countdown=0; use_doc_hints=false; - use_filter=false; + subsection_selectable=false; } diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h index 5fb8386b1b3..f004616c081 100644 --- a/tools/editor/property_editor.h +++ b/tools/editor/property_editor.h @@ -163,8 +163,8 @@ class PropertyEditor : public Control { bool show_categories; float refresh_countdown; bool use_doc_hints; - bool use_filter; + bool subsection_selectable; HashMap pending; String selected_property; @@ -239,6 +239,8 @@ public: void set_use_filter(bool p_use); void register_text_enter(Node *p_line_edit); + void set_subsection_selectable(bool p_selectable); + PropertyEditor(); ~PropertyEditor(); From c7b730c655583e83cd08cb429acebac79df639b8 Mon Sep 17 00:00:00 2001 From: koalefant Date: Fri, 4 Dec 2015 05:43:48 +0100 Subject: [PATCH 18/24] Vector<>::_ptr is now typed and points to the beginning of array rather than reference count block --- core/vector.h | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/core/vector.h b/core/vector.h index d1034006226..78dff5eadbf 100644 --- a/core/vector.h +++ b/core/vector.h @@ -42,7 +42,7 @@ template class Vector { - mutable void* _ptr; + mutable T* _ptr; // internal helpers @@ -51,21 +51,21 @@ class Vector { if (!_ptr) return NULL; - return reinterpret_cast(_ptr); + return reinterpret_cast((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount)); } _FORCE_INLINE_ int* _get_size() const { if (!_ptr) return NULL; - return reinterpret_cast(((uint8_t*)(_ptr))+sizeof(SafeRefCount)); + return reinterpret_cast((uint8_t*)_ptr-sizeof(int)); } _FORCE_INLINE_ T* _get_data() const { if (!_ptr) return NULL; - return reinterpret_cast(((uint8_t*)(_ptr))+sizeof(SafeRefCount)+sizeof(int)); + return reinterpret_cast(_ptr); } @@ -88,11 +88,11 @@ public: _FORCE_INLINE_ void clear() { resize(0); } _FORCE_INLINE_ int size() const { - - if (!_ptr) - return 0; + int* size = _get_size(); + if (size) + return *size; else - return *reinterpret_cast(((uint8_t*)(_ptr))+sizeof(SafeRefCount)); + return 0; } _FORCE_INLINE_ bool empty() const { return _ptr == 0; } Error resize(int p_size); @@ -174,7 +174,7 @@ void Vector::_unref(void *p_data) { if (!p_data) return; - SafeRefCount *src = reinterpret_cast(p_data); + SafeRefCount *src = reinterpret_cast((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount)); if (!src->unref()) return; // still in use @@ -189,7 +189,7 @@ void Vector::_unref(void *p_data) { } // free mem - memfree(p_data); + memfree((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount)); } @@ -201,7 +201,8 @@ void Vector::_copy_on_write() { if (_get_refcount()->get() > 1 ) { /* in use by more than me */ - SafeRefCount *src_new=(SafeRefCount *)memalloc(_get_alloc_size(*_get_size())); + void* mem_new = memalloc(_get_alloc_size(*_get_size())); + SafeRefCount *src_new=(SafeRefCount *)mem_new; src_new->init(); int * _size = (int*)(src_new+1); *_size=*_get_size(); @@ -215,7 +216,7 @@ void Vector::_copy_on_write() { } _unref(_ptr); - _ptr=src_new; + _ptr=_data; } } @@ -260,16 +261,17 @@ Error Vector::resize(int p_size) { if (size()==0) { // alloc from scratch - _ptr = (T*)memalloc(_get_alloc_size(p_size)); - ERR_FAIL_COND_V( !_ptr ,ERR_OUT_OF_MEMORY); + void* ptr=memalloc(_get_alloc_size(p_size)); + ERR_FAIL_COND_V( !ptr ,ERR_OUT_OF_MEMORY); + _ptr=(T*)((uint8_t*)ptr+sizeof(int)+sizeof(SafeRefCount)); _get_refcount()->init(); // init refcount *_get_size()=0; // init size (currently, none) } else { - void *_ptrnew = (T*)memrealloc(_ptr,_get_alloc_size(p_size)); + void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount),_get_alloc_size(p_size)); ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY); - _ptr=_ptrnew; + _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount)); } // construct the newly created elements @@ -291,10 +293,10 @@ Error Vector::resize(int p_size) { t->~T(); } - void *_ptrnew = (T*)memrealloc(_ptr,_get_alloc_size(p_size)); + void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount),_get_alloc_size(p_size)); ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY); - _ptr=_ptrnew; + _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount)); *_get_size()=p_size; From 9457211f8fd673eb5ef7d32c7ddb0157d2735753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 4 Dec 2015 09:31:01 +0100 Subject: [PATCH 19/24] Fix wrong index being used to populate r_results Regression from f33d9da. --- servers/physics/space_sw.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 4b59f2d0ba3..778d20d3f15 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -175,17 +175,17 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transfo if (!CollisionSolverSW::solve_static(shape,p_xform,col_obj->get_shape(shape_idx),col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), NULL,NULL,NULL,p_margin,0)) continue; - cc++; + if (r_results) { + r_results[cc].collider_id=col_obj->get_instance_id(); + if (r_results[cc].collider_id!=0) + r_results[cc].collider=ObjectDB::get_instance(r_results[cc].collider_id); + else + r_results[cc].collider=NULL; + r_results[cc].rid=col_obj->get_self(); + r_results[cc].shape=shape_idx; + } - if (!r_results) - continue; - r_results[cc].collider_id=col_obj->get_instance_id(); - if (r_results[cc].collider_id!=0) - r_results[cc].collider=ObjectDB::get_instance(r_results[cc].collider_id); - else - r_results[cc].collider=NULL; - r_results[cc].rid=col_obj->get_self(); - r_results[cc].shape=shape_idx; + cc++; } From d0ddf150d9c7207f87409b5899297dae0fc0b708 Mon Sep 17 00:00:00 2001 From: Zher Huei Lee Date: Fri, 4 Dec 2015 21:18:41 +0000 Subject: [PATCH 20/24] updated the RegEx library nrex to v0.1 After implementing unit testing to nrex I caught and fixed some errors so it should behave more like Python's RegEx In addition, I've added version numbering so it should be able to tell if the library needs updating. Here are a list of changes: - Fixed zero count quantifiers failing. - Fixed infinite recursion if quantifying zero length token. - Fixed `$` (as a string pattern on its own) not matching. - Fixed look behind rewinding beyond the start of the string. - Added support for alternative back reference format `\g{1}` similar to Python. This allows digits to be used immediately after back references. - Number of capture groups are still limited to 9 by default but can now be manually set, with option for no limit at all. (Python has no limit) - Curly bracket quantifiers `{0}` no longer interpreted as a literal string if previous token is not quantifiable. (Python behaviour) --- drivers/nrex/README.md | 4 +- drivers/nrex/nrex.cpp | 101 +++++++++++++++++++++++++++-------------- drivers/nrex/nrex.hpp | 41 ++++++++++++++--- drivers/nrex/regex.cpp | 6 +-- drivers/nrex/regex.h | 2 +- 5 files changed, 108 insertions(+), 46 deletions(-) diff --git a/drivers/nrex/README.md b/drivers/nrex/README.md index 951b301c1ed..9ff67992dca 100644 --- a/drivers/nrex/README.md +++ b/drivers/nrex/README.md @@ -1,5 +1,7 @@ # NREX: Node RegEx +Version 0.1 + Small node-based regular expression library. It only does text pattern matchhing, not replacement. To use add the files `nrex.hpp`, `nrex.cpp` and `nrex_config.h` to your project and follow the example: @@ -32,7 +34,7 @@ Currently supported features: * Unicode `\uFFFF` code points * Positive `(?=)` and negative `(?!)` lookahead * Positive `(?<=)` and negative `(?test(s, pos - offset); @@ -450,7 +459,7 @@ struct nrex_node_char : public nrex_node int test(nrex_search* s, int pos) const { - if (s->end == pos || s->at(pos) != ch) + if (s->end <= pos || 0 > pos || s->at(pos) != ch) { return -1; } @@ -473,7 +482,7 @@ struct nrex_node_range : public nrex_node int test(nrex_search* s, int pos) const { - if (s->end == pos) + if (s->end <= pos || 0 > pos) { return -1; } @@ -555,7 +564,7 @@ struct nrex_node_class : public nrex_node int test(nrex_search* s, int pos) const { - if (s->end == pos) + if (s->end <= pos || 0 > pos) { return -1; } @@ -727,7 +736,7 @@ struct nrex_node_shorthand : public nrex_node int test(nrex_search* s, int pos) const { - if (s->end == pos) + if (s->end <= pos || 0 > pos) { return -1; } @@ -811,16 +820,12 @@ struct nrex_node_quantifier : public nrex_node int test(nrex_search* s, int pos) const { - return test_step(s, pos, 1); + return test_step(s, pos, 0, pos); } - int test_step(nrex_search* s, int pos, int level) const + int test_step(nrex_search* s, int pos, int level, int start) const { - if (max == 0) - { - return pos; - } - if ((max >= 1 && level > max) || pos > s->end) + if (pos > s->end) { return -1; } @@ -840,14 +845,26 @@ struct nrex_node_quantifier : public nrex_node return res; } } - int res = child->test(s, pos); - if (s->complete) + if (max >= 0 && level > max) { - return res; + return -1; + } + if (level > 1 && level > min + 1 && pos == start) + { + return -1; + } + int res = pos; + if (level >= 1) + { + res = child->test(s, pos); + if (s->complete) + { + return res; + } } if (res >= 0) { - int res_step = test_step(s, res, level + 1); + int res_step = test_step(s, res, level + 1, start); if (res_step >= 0) { return res_step; @@ -983,6 +1000,13 @@ nrex::nrex() { } +nrex::nrex(const nrex_char* pattern, int captures) + : _capturing(0) + , _root(NULL) +{ + compile(pattern, captures); +} + nrex::~nrex() { if (_root) @@ -1008,10 +1032,14 @@ void nrex::reset() int nrex::capture_size() const { - return _capturing + 1; + if (_root) + { + return _capturing + 1; + } + return 0; } -bool nrex::compile(const nrex_char* pattern, bool extended) +bool nrex::compile(const nrex_char* pattern, int captures) { reset(); nrex_node_group* root = NREX_NEW(nrex_node_group(_capturing)); @@ -1053,7 +1081,7 @@ bool nrex::compile(const nrex_char* pattern, bool extended) NREX_COMPILE_ERROR("unrecognised qualifier for group"); } } - else if ((!extended && _capturing < 9) || (extended && _capturing < 99)) + else if (captures >= 0 && _capturing < captures) { nrex_node_group* group = NREX_NEW(nrex_node_group(++_capturing)); stack.top()->add_child(group); @@ -1190,15 +1218,6 @@ bool nrex::compile(const nrex_char* pattern, bool extended) } else if (nrex_is_quantifier(c[0])) { - if (stack.top()->back == NULL || !stack.top()->back->quantifiable) - { - if (c[0] == '{') - { - stack.top()->add_child(NREX_NEW(nrex_node_char('{'))); - continue; - } - NREX_COMPILE_ERROR("element not quantifiable"); - } int min = 0; int max = -1; bool valid_quantifier = true; @@ -1270,6 +1289,10 @@ bool nrex::compile(const nrex_char* pattern, bool extended) } if (valid_quantifier) { + if (stack.top()->back == NULL || !stack.top()->back->quantifiable) + { + NREX_COMPILE_ERROR("element not quantifiable"); + } nrex_node_quantifier* quant = NREX_NEW(nrex_node_quantifier(min, max)); if (min == max) { @@ -1323,20 +1346,26 @@ bool nrex::compile(const nrex_char* pattern, bool extended) stack.top()->add_child(NREX_NEW(nrex_node_shorthand(c[1]))); ++c; } - else if ('1' <= c[1] && c[1] <= '9') + else if (('1' <= c[1] && c[1] <= '9') || (c[1] == 'g' && c[2] == '{')) { int ref = 0; - if (extended && '0' <= c[2] && c[2] <= '9') + bool unclosed = false; + if (c[1] == 'g') { - ref = int(c[1] - '0') * 10 + int(c[2] - '0'); + unclosed = true; c = &c[2]; } - else + while ('0' <= c[1] && c[1] <= '9') { - ref = int(c[1] - '0'); + ref = ref * 10 + int(c[1] - '0'); ++c; } - if (ref > _capturing) + if (c[1] == '}') + { + unclosed = false; + ++c; + } + if (ref > _capturing || ref <= 0 || unclosed) { NREX_COMPILE_ERROR("backreference to non-existent capture"); } @@ -1377,6 +1406,10 @@ bool nrex::compile(const nrex_char* pattern, bool extended) bool nrex::match(const nrex_char* str, nrex_result* captures, int offset, int end) const { + if (!_root) + { + return false; + } nrex_search s(str, captures); if (end >= offset) { @@ -1386,7 +1419,7 @@ bool nrex::match(const nrex_char* str, nrex_result* captures, int offset, int en { s.end = NREX_STRLEN(str); } - for (int i = offset; i < s.end; ++i) + for (int i = offset; i <= s.end; ++i) { for (int c = 0; c <= _capturing; ++c) { diff --git a/drivers/nrex/nrex.hpp b/drivers/nrex/nrex.hpp index e26a61c39ae..44e950c5178 100644 --- a/drivers/nrex/nrex.hpp +++ b/drivers/nrex/nrex.hpp @@ -1,4 +1,5 @@ // NREX: Node RegEx +// Version 0.1 // // Copyright (c) 2015, Zher Huei Lee // All rights reserved. @@ -59,7 +60,32 @@ class nrex int _capturing; nrex_node* _root; public: + + /*! + * \brief Initialises an empty regex container + */ nrex(); + + /*! + * \brief Initialises and compiles the regex pattern + * + * This calls nrex::compile() with the same arguments. To check whether + * the compilation was successfull, use nrex::valid(). + * + * If the NREX_THROW_ERROR was defined it would automatically throw a + * runtime error nrex_compile_error if it encounters a problem when + * parsing the pattern. + * + * \param pattern The regex pattern + * \param captures The maximum number of capture groups to allow. Any + * extra would be converted to non-capturing groups. + * If negative, no limit would be imposed. Defaults + * to 9. + * + * \see nrex::compile() + */ + nrex(const nrex_char* pattern, int captures = 9); + ~nrex(); /*! @@ -78,9 +104,9 @@ class nrex * * This is used to provide the array size of the captures needed for * nrex::match() to work. The size is actually the number of capture - * groups + one for the matching of the entire pattern. The result is - * always capped at 10 or 100, depending on the extend option given in - * nrex::compile() (default 10). + * groups + one for the matching of the entire pattern. This can be + * capped using the extra argument given in nrex::compile() + * (default 10). * * \return The number of captures */ @@ -97,12 +123,13 @@ class nrex * parsing the pattern. * * \param pattern The regex pattern - * \param extended If true, raises the limit on number of capture - * groups and back-references to 99. Otherwise limited - * to 9. Defaults to false. + * \param captures The maximum number of capture groups to allow. Any + * extra would be converted to non-capturing groups. + * If negative, no limit would be imposed. Defaults + * to 9. * \return True if the pattern was succesfully compiled */ - bool compile(const nrex_char* pattern, bool extended = false); + bool compile(const nrex_char* pattern, int captures = 9); /*! * \brief Uses the pattern to search through the provided string diff --git a/drivers/nrex/regex.cpp b/drivers/nrex/regex.cpp index 246384b10a6..e8578221a99 100644 --- a/drivers/nrex/regex.cpp +++ b/drivers/nrex/regex.cpp @@ -15,7 +15,7 @@ void RegEx::_bind_methods() { - ObjectTypeDB::bind_method(_MD("compile","pattern", "expanded"),&RegEx::compile, DEFVAL(true)); + ObjectTypeDB::bind_method(_MD("compile","pattern", "capture"),&RegEx::compile, DEFVAL(9)); ObjectTypeDB::bind_method(_MD("find","text","start","end"),&RegEx::find, DEFVAL(0), DEFVAL(-1)); ObjectTypeDB::bind_method(_MD("clear"),&RegEx::clear); ObjectTypeDB::bind_method(_MD("is_valid"),&RegEx::is_valid); @@ -68,11 +68,11 @@ String RegEx::get_capture(int capture) const { } -Error RegEx::compile(const String& p_pattern, bool expanded) { +Error RegEx::compile(const String& p_pattern, int capture) { clear(); - exp.compile(p_pattern.c_str(), expanded); + exp.compile(p_pattern.c_str(), capture); ERR_FAIL_COND_V( !exp.valid(), FAILED ); diff --git a/drivers/nrex/regex.h b/drivers/nrex/regex.h index be52da81495..76aab2aea65 100644 --- a/drivers/nrex/regex.h +++ b/drivers/nrex/regex.h @@ -36,7 +36,7 @@ public: bool is_valid() const; int get_capture_count() const; String get_capture(int capture) const; - Error compile(const String& p_pattern, bool expanded = false); + Error compile(const String& p_pattern, int capture = 9); int find(const String& p_text, int p_start = 0, int p_end = -1) const; RegEx(); From d957749179f7310995e994b45df72291a57bd0d7 Mon Sep 17 00:00:00 2001 From: Zher Huei Lee Date: Fri, 4 Dec 2015 22:19:53 +0000 Subject: [PATCH 21/24] updated nrex documentation --- doc/base/classes.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/base/classes.xml b/doc/base/classes.xml index fd5df945bab..1b1f1d9f3f8 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -26945,7 +26945,7 @@ This method controls whether the position between two cached points is interpola Lazy (non-greedy) quantifiers [code]*?[/code] Begining [code]^[/code] and end [code]$[/code] anchors Alternation [code]|[/code] - Backreferences [code]\1[/code] to [code]\9[/code] + Backreferences [code]\1[/code] and [code]\g{1}[/code] POSIX character classes [code][[:alnum:]][/code] Lookahead [code](?=)[/code], [code](?!)[/code] and lookbehind [code](?<=)[/code], [code](?<!)[/code] ASCII [code]\xFF[/code] and Unicode [code]\uFFFF[/code] code points (in a style similar to Python) @@ -26957,9 +26957,10 @@ This method controls whether the position between two cached points is interpola - + + Compiles and assign the regular expression pattern to use. The limit on the number of capturing groups can be specified or made unlimited if negative. From 118f3cdcf66b3847180cdccdfd7ee0c53974b0b9 Mon Sep 17 00:00:00 2001 From: Franklin Sobrinho Date: Thu, 26 Nov 2015 14:59:04 -0300 Subject: [PATCH 22/24] Update Groups Editor --- tools/editor/groups_editor.cpp | 177 +++++++++++++++------------------ tools/editor/groups_editor.h | 38 +++---- 2 files changed, 97 insertions(+), 118 deletions(-) diff --git a/tools/editor/groups_editor.cpp b/tools/editor/groups_editor.cpp index 2e82854014c..bb5e93da348 100644 --- a/tools/editor/groups_editor.cpp +++ b/tools/editor/groups_editor.cpp @@ -27,151 +27,130 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "groups_editor.h" -#include "scene/gui/box_container.h" +#include "scene/gui/box_container.h" #include "scene/gui/label.h" +void GroupsEditor::_add_group(const String& p_group) { -#include "print_string.h" - -void GroupsEditor::_notification(int p_what) { - - if (p_what==NOTIFICATION_ENTER_TREE) { - connect("confirmed", this,"_close"); - } - if (p_what==NOTIFICATION_EXIT_TREE) { - disconnect("confirmed", this,"_close"); - } -} - -void GroupsEditor::_close() { - - hide(); - -} -void GroupsEditor::_add() { - if (!node) return; - - undo_redo->create_action("Add To Group"); - undo_redo->add_do_method(node,"add_to_group",group_name->get_text(),true); - undo_redo->add_undo_method(node,"remove_from_group",group_name->get_text()); + String name = group_name->get_text(); + if (name.strip_edges()=="") + return; + + if (node->is_in_group(name)) + return; + + undo_redo->create_action("Add to Group"); + + undo_redo->add_do_method(node,"add_to_group",name,true); undo_redo->add_do_method(this,"update_tree"); + undo_redo->add_undo_method(node,"remove_from_group",name,get_text()); undo_redo->add_undo_method(this,"update_tree"); undo_redo->commit_action(); } +void GroupsEditor::_remove_group(Object *p_item, int p_column, int p_id) { -void GroupsEditor::_remove() { - - if (!tree->get_selected()) - return; if (!node) return; - TreeItem *sel = tree->get_selected(); - if (!sel) + TreeItem *ti = p_item->cast_to(); + if (!ti) return; - - node->remove_from_group( sel->get_text(0) ); - update_tree(); + + String name = ti->get_text(0); + + undo_redo->create_action("Remove from Group"); + + undo_redo->add_do_method(node,"remove_from_group",name); + undo_redo->add_do_method(this,"update_tree"); + undo_redo->add_undo_method(node,"add_to_group",name,true); + undo_redo->add_undo_method(this,"update_tree"); + + undo_redo->commit_action(); } +struct _GroupInfoComparator { + + bool operator()(const Node::GroupInfo& p_a, const Node::GroupInfo& p_b) const { + return p_a.name.operator String() < p_b.name.operator String(); + } +}; + void GroupsEditor::update_tree() { - tree->clear(); - + if (!node) return; - - List groups; - node->get_groups(&groups); - - TreeItem *root=tree->create_item(); - - for(List::Element *E=groups.front();E;E=E->next()) { - - if (!E->get().persistent) - continue; - TreeItem *item=tree->create_item(root); - item->set_text(0, E->get().name); - - } + List groups; + node->get_groups(&groups); + groups.sort_custom<_GroupInfoComparator>(); + + TreeItem *root=tree->create_item(); + + for(List::Element *E=groups.front();E;E=E->next()) { + + Node::GroupInfo gi = E->get(); + if (!gi.persistent) + continue; + + TreeItem *item=tree->create_item(root); + item->set_text(0, gi.name); + item->add_button(0, get_icon("Remove", "EditorIcons"), 0); + } } void GroupsEditor::set_current(Node* p_node) { - + node=p_node; update_tree(); - } void GroupsEditor::_bind_methods() { - - ObjectTypeDB::bind_method("_add",&GroupsEditor::_add); - ObjectTypeDB::bind_method("_close",&GroupsEditor::_close); - ObjectTypeDB::bind_method("_remove",&GroupsEditor::_remove); + + ObjectTypeDB::bind_method("_add_group",&GroupsEditor::_add_group); + ObjectTypeDB::bind_method("_remove_group",&GroupsEditor::_remove_group); ObjectTypeDB::bind_method("update_tree",&GroupsEditor::update_tree); } GroupsEditor::GroupsEditor() { + node=NULL; + set_title("Group Editor"); - - Label * label = memnew( Label ); - label->set_pos( Point2( 8,11) ); - label->set_text("Groups:"); - - add_child(label); - - group_name = memnew(LineEdit); - group_name->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - group_name->set_begin( Point2( 15,28) ); - group_name->set_end( Point2( 94,48 ) ); - - add_child(group_name); - - tree = memnew( Tree ); - tree->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); - tree->set_begin( Point2( 15,52) ); - tree->set_end( Point2( 94,42 ) ); - tree->set_hide_root(true); - add_child(tree); - + + VBoxContainer *vbc = memnew( VBoxContainer ); + add_child(vbc); + set_child_rect(vbc); + + HBoxContainer *hbc = memnew( HBoxContainer ); + vbc->add_margin_child("Group", hbc); + + group_name = memnew( LineEdit ); + group_name->set_h_size_flags(SIZE_EXPAND_FILL); + hbc->add_child(group_name); + group_name->connect("text_entered",this,"_add_group"); + add = memnew( Button ); - add->set_anchor( MARGIN_LEFT, ANCHOR_END ); - add->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - add->set_begin( Point2( 90, 28 ) ); - add->set_end( Point2( 15, 48 ) ); add->set_text("Add"); - - add_child(add); - - remove = memnew( Button ); - remove->set_anchor( MARGIN_LEFT, ANCHOR_END ); - remove->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - remove->set_begin( Point2( 90, 52 ) ); - remove->set_end( Point2( 15, 72 ) ); - remove->set_text("Remove"); - - add_child(remove); + hbc->add_child(add); + add->connect("pressed", this,"_add_group", varray(String())); + + tree = memnew( Tree ); + tree->set_hide_root(true); + tree->set_v_size_flags(SIZE_EXPAND_FILL); + vbc->add_margin_child("Node Group(s)", tree, true); + tree->connect("button_pressed",this,"_remove_group"); get_ok()->set_text("Close"); - - add->connect("pressed", this,"_add"); - remove->connect("pressed", this,"_remove"); - - - node=NULL; } - GroupsEditor::~GroupsEditor() { } diff --git a/tools/editor/groups_editor.h b/tools/editor/groups_editor.h index 09883a150f2..3a9cc777274 100644 --- a/tools/editor/groups_editor.h +++ b/tools/editor/groups_editor.h @@ -29,42 +29,42 @@ #ifndef GROUPS_EDITOR_H #define GROUPS_EDITOR_H - #include "scene/gui/dialogs.h" #include "scene/gui/button.h" #include "scene/gui/tree.h" #include "scene/gui/line_edit.h" #include "undo_redo.h" + /** @author Juan Linietsky */ -class GroupsEditor : public ConfirmationDialog { - - OBJ_TYPE( GroupsEditor, ConfirmationDialog ); - - LineEdit *group_name; - Tree *tree; - Button *add; - Button *remove; + +class GroupsEditor : public AcceptDialog { + + OBJ_TYPE(GroupsEditor,AcceptDialog); + Node *node; + + LineEdit *group_name; + Button *add; + Tree *tree; + UndoRedo *undo_redo; - + void update_tree(); - void _add(); - void _remove(); + void _add_group(const String& p_group=""); + void _remove_group(Object *p_item, int p_column, int p_id); void _close(); - protected: - - void _notification(int p_what); - static void _bind_methods(); + + static void _bind_methods(); public: - + void set_undo_redo(UndoRedo *p_undoredo) { undo_redo=p_undoredo; } void set_current(Node* p_node); - + GroupsEditor(); ~GroupsEditor(); - }; + #endif From 157b97b0872221224ba80099f4c11fd78123e576 Mon Sep 17 00:00:00 2001 From: Saracen Date: Mon, 7 Dec 2015 13:25:36 +0000 Subject: [PATCH 23/24] Extended clipping fix to missing clipping-related features. --- drivers/gles2/rasterizer_gles2.cpp | 42 ++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 8b70e7cfbfc..136e8162e92 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -9155,10 +9155,23 @@ void RasterizerGLES2::_canvas_item_render_commands(CanvasItem *p_item,CanvasItem //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); - int x = current_clip->final_clip_rect.pos.x; - int y = window_size.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); - int w = current_clip->final_clip_rect.size.x; - int h = current_clip->final_clip_rect.size.y; + int x; + int y; + int w; + int h; + + if (current_rt) { + x = current_clip->final_clip_rect.pos.x; + y = current_clip->final_clip_rect.pos.y; + w = current_clip->final_clip_rect.size.x; + h = current_clip->final_clip_rect.size.y; + } + else { + x = current_clip->final_clip_rect.pos.x; + y = window_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y); + w = current_clip->final_clip_rect.size.x; + h = current_clip->final_clip_rect.size.y; + } glScissor(x,y,w,h); @@ -9666,10 +9679,23 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const //glScissor(viewport.x+current_clip->final_clip_rect.pos.x,viewport.y+ (viewport.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.height)), //current_clip->final_clip_rect.size.width,current_clip->final_clip_rect.size.height); - int x = current_clip->final_clip_rect.pos.x; - int y = window_size.height-(current_clip->final_clip_rect.pos.y+current_clip->final_clip_rect.size.y); - int w = current_clip->final_clip_rect.size.x; - int h = current_clip->final_clip_rect.size.y; + int x; + int y; + int w; + int h; + + if (current_rt) { + x = current_clip->final_clip_rect.pos.x; + y = current_clip->final_clip_rect.pos.y; + w = current_clip->final_clip_rect.size.x; + h = current_clip->final_clip_rect.size.y; + } + else { + x = current_clip->final_clip_rect.pos.x; + y = window_size.height - (current_clip->final_clip_rect.pos.y + current_clip->final_clip_rect.size.y); + w = current_clip->final_clip_rect.size.x; + h = current_clip->final_clip_rect.size.y; + } glScissor(x,y,w,h); From 43b2c9c7a43ef7cb2830698917cc0555de30947c Mon Sep 17 00:00:00 2001 From: Ovnuniarchos Date: Tue, 8 Dec 2015 18:44:29 +0100 Subject: [PATCH 24/24] Areas now calculate their dampenings the same way as their gravity. --- servers/physics/body_sw.cpp | 22 ++++++++++++++-------- servers/physics/body_sw.h | 2 +- servers/physics_2d/body_2d_sw.cpp | 25 +++++++++++++++---------- servers/physics_2d/body_2d_sw.h | 2 +- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index 8edbaf0b89b..c66e73b4304 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -382,7 +382,7 @@ void BodySW::set_space(SpaceSW *p_space){ } -void BodySW::_compute_area_gravity(const AreaSW *p_area) { +void BodySW::_compute_area_gravity_and_dampenings(const AreaSW *p_area) { if (p_area->is_gravity_point()) { if(p_area->get_gravity_distance_scale() > 0) { @@ -394,6 +394,9 @@ void BodySW::_compute_area_gravity(const AreaSW *p_area) { } else { gravity += p_area->get_gravity_vector() * p_area->get_gravity(); } + + area_linear_damp += p_area->get_linear_damp(); + area_angular_damp += p_area->get_angular_damp(); } void BodySW::integrate_forces(real_t p_step) { @@ -409,13 +412,15 @@ void BodySW::integrate_forces(real_t p_step) { int ac = areas.size(); bool replace = false; - gravity=Vector3(0,0,0); + gravity = Vector3(0,0,0); + area_linear_damp = 0; + area_angular_damp = 0; if (ac) { areas.sort(); const AreaCMP *aa = &areas[0]; damp_area = aa[ac-1].area; for(int i=ac-1;i>=0;i--) { - _compute_area_gravity(aa[i].area); + _compute_area_gravity_and_dampenings(aa[i].area); if (aa[i].area->get_space_override_mode() == PhysicsServer::AREA_SPACE_OVERRIDE_REPLACE) { replace = true; break; @@ -424,20 +429,21 @@ void BodySW::integrate_forces(real_t p_step) { } if( !replace ) { - _compute_area_gravity(def_area); + _compute_area_gravity_and_dampenings(def_area); } gravity*=gravity_scale; + // If less than 0, override dampenings with that of the Body if (angular_damp>=0) area_angular_damp=angular_damp; - else - area_angular_damp=damp_area->get_angular_damp(); + //else + // area_angular_damp=damp_area->get_angular_damp(); if (linear_damp>=0) area_linear_damp=linear_damp; - else - area_linear_damp=damp_area->get_linear_damp(); + //else + // area_linear_damp=damp_area->get_linear_damp(); Vector3 motion; diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h index 66d814bfd16..4c4c7818c54 100644 --- a/servers/physics/body_sw.h +++ b/servers/physics/body_sw.h @@ -130,7 +130,7 @@ class BodySW : public CollisionObjectSW { BodySW *island_next; BodySW *island_list_next; - _FORCE_INLINE_ void _compute_area_gravity(const AreaSW *p_area); + _FORCE_INLINE_ void _compute_area_gravity_and_dampenings(const AreaSW *p_area); _FORCE_INLINE_ void _update_inertia_tensor(); diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index 3afbbe5455b..d0c5cbc77bf 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -380,7 +380,7 @@ void Body2DSW::set_space(Space2DSW *p_space){ } -void Body2DSW::_compute_area_gravity(const Area2DSW *p_area) { +void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) { if (p_area->is_gravity_point()) { if(p_area->get_gravity_distance_scale() > 0) { @@ -393,6 +393,8 @@ void Body2DSW::_compute_area_gravity(const Area2DSW *p_area) { gravity += p_area->get_gravity_vector() * p_area->get_gravity(); } + area_linear_damp += p_area->get_linear_damp(); + area_angular_damp += p_area->get_angular_damp(); } void Body2DSW::integrate_forces(real_t p_step) { @@ -406,13 +408,15 @@ void Body2DSW::integrate_forces(real_t p_step) { int ac = areas.size(); bool replace = false; - gravity=Vector2(0,0); + gravity = Vector2(0,0); + area_angular_damp = 0; + area_linear_damp = 0; if (ac) { areas.sort(); const AreaCMP *aa = &areas[0]; damp_area = aa[ac-1].area; for(int i=ac-1;i>=0;i--) { - _compute_area_gravity(aa[i].area); + _compute_area_gravity_and_dampenings(aa[i].area); if (aa[i].area->get_space_override_mode() == Physics2DServer::AREA_SPACE_OVERRIDE_REPLACE) { replace = true; break; @@ -420,19 +424,20 @@ void Body2DSW::integrate_forces(real_t p_step) { } } if( !replace ) { - _compute_area_gravity(def_area); + _compute_area_gravity_and_dampenings(def_area); } gravity*=gravity_scale; + // If less than 0, override dampenings with that of the Body2D if (angular_damp>=0) - area_angular_damp=angular_damp; - else - area_angular_damp=damp_area->get_angular_damp(); + area_angular_damp = angular_damp; + //else + // area_angular_damp=damp_area->get_angular_damp(); if (linear_damp>=0) - area_linear_damp=linear_damp; - else - area_linear_damp=damp_area->get_linear_damp(); + area_linear_damp = linear_damp; + //else + // area_linear_damp=damp_area->get_linear_damp(); Vector2 motion; bool do_motion=false; diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h index 2fbfcaca600..8418c5dcd79 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -132,7 +132,7 @@ class Body2DSW : public CollisionObject2DSW { Body2DSW *island_next; Body2DSW *island_list_next; - _FORCE_INLINE_ void _compute_area_gravity(const Area2DSW *p_area); + _FORCE_INLINE_ void _compute_area_gravity_and_dampenings(const Area2DSW *p_area); friend class Physics2DDirectBodyStateSW; // i give up, too many functions to expose