variant_op.cpp 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812
  1. /*************************************************************************/
  2. /* variant_op.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "variant.h"
  31. #include "core/core_string_names.h"
  32. #include "core/object.h"
  33. #include "core/object_rc.h"
  34. #include "core/script_language.h"
  35. #define CASE_TYPE_ALL(PREFIX, OP) \
  36. CASE_TYPE(PREFIX, OP, INT) \
  37. CASE_TYPE_ALL_BUT_INT(PREFIX, OP)
  38. #define CASE_TYPE_ALL_BUT_INT(PREFIX, OP) \
  39. CASE_TYPE(PREFIX, OP, NIL) \
  40. CASE_TYPE(PREFIX, OP, BOOL) \
  41. CASE_TYPE(PREFIX, OP, REAL) \
  42. CASE_TYPE(PREFIX, OP, STRING) \
  43. CASE_TYPE(PREFIX, OP, VECTOR2) \
  44. CASE_TYPE(PREFIX, OP, RECT2) \
  45. CASE_TYPE(PREFIX, OP, VECTOR3) \
  46. CASE_TYPE(PREFIX, OP, TRANSFORM2D) \
  47. CASE_TYPE(PREFIX, OP, PLANE) \
  48. CASE_TYPE(PREFIX, OP, QUAT) \
  49. CASE_TYPE(PREFIX, OP, AABB) \
  50. CASE_TYPE(PREFIX, OP, BASIS) \
  51. CASE_TYPE(PREFIX, OP, TRANSFORM) \
  52. CASE_TYPE(PREFIX, OP, COLOR) \
  53. CASE_TYPE(PREFIX, OP, NODE_PATH) \
  54. CASE_TYPE(PREFIX, OP, _RID) \
  55. CASE_TYPE(PREFIX, OP, OBJECT) \
  56. CASE_TYPE(PREFIX, OP, DICTIONARY) \
  57. CASE_TYPE(PREFIX, OP, ARRAY) \
  58. CASE_TYPE(PREFIX, OP, POOL_BYTE_ARRAY) \
  59. CASE_TYPE(PREFIX, OP, POOL_INT_ARRAY) \
  60. CASE_TYPE(PREFIX, OP, POOL_REAL_ARRAY) \
  61. CASE_TYPE(PREFIX, OP, POOL_STRING_ARRAY) \
  62. CASE_TYPE(PREFIX, OP, POOL_VECTOR2_ARRAY) \
  63. CASE_TYPE(PREFIX, OP, POOL_VECTOR3_ARRAY) \
  64. CASE_TYPE(PREFIX, OP, POOL_COLOR_ARRAY)
  65. #ifdef __GNUC__
  66. #define TYPE(PREFIX, OP, TYPE) &&PREFIX##_##OP##_##TYPE
  67. /* clang-format off */
  68. #define TYPES(PREFIX, OP) { \
  69. TYPE(PREFIX, OP, NIL), \
  70. TYPE(PREFIX, OP, BOOL), \
  71. TYPE(PREFIX, OP, INT), \
  72. TYPE(PREFIX, OP, REAL), \
  73. TYPE(PREFIX, OP, STRING), \
  74. TYPE(PREFIX, OP, VECTOR2), \
  75. TYPE(PREFIX, OP, RECT2), \
  76. TYPE(PREFIX, OP, VECTOR3), \
  77. TYPE(PREFIX, OP, TRANSFORM2D), \
  78. TYPE(PREFIX, OP, PLANE), \
  79. TYPE(PREFIX, OP, QUAT), \
  80. TYPE(PREFIX, OP, AABB), \
  81. TYPE(PREFIX, OP, BASIS), \
  82. TYPE(PREFIX, OP, TRANSFORM), \
  83. TYPE(PREFIX, OP, COLOR), \
  84. TYPE(PREFIX, OP, NODE_PATH), \
  85. TYPE(PREFIX, OP, _RID), \
  86. TYPE(PREFIX, OP, OBJECT), \
  87. TYPE(PREFIX, OP, DICTIONARY), \
  88. TYPE(PREFIX, OP, ARRAY), \
  89. TYPE(PREFIX, OP, POOL_BYTE_ARRAY), \
  90. TYPE(PREFIX, OP, POOL_INT_ARRAY), \
  91. TYPE(PREFIX, OP, POOL_REAL_ARRAY), \
  92. TYPE(PREFIX, OP, POOL_STRING_ARRAY), \
  93. TYPE(PREFIX, OP, POOL_VECTOR2_ARRAY), \
  94. TYPE(PREFIX, OP, POOL_VECTOR3_ARRAY), \
  95. TYPE(PREFIX, OP, POOL_COLOR_ARRAY), \
  96. }
  97. /* clang-format on */
  98. #define CASES(PREFIX) static const void *switch_table_##PREFIX[25][27] = { \
  99. TYPES(PREFIX, OP_EQUAL), \
  100. TYPES(PREFIX, OP_NOT_EQUAL), \
  101. TYPES(PREFIX, OP_LESS), \
  102. TYPES(PREFIX, OP_LESS_EQUAL), \
  103. TYPES(PREFIX, OP_GREATER), \
  104. TYPES(PREFIX, OP_GREATER_EQUAL), \
  105. TYPES(PREFIX, OP_ADD), \
  106. TYPES(PREFIX, OP_SUBTRACT), \
  107. TYPES(PREFIX, OP_MULTIPLY), \
  108. TYPES(PREFIX, OP_DIVIDE), \
  109. TYPES(PREFIX, OP_NEGATE), \
  110. TYPES(PREFIX, OP_POSITIVE), \
  111. TYPES(PREFIX, OP_MODULE), \
  112. TYPES(PREFIX, OP_STRING_CONCAT), \
  113. TYPES(PREFIX, OP_SHIFT_LEFT), \
  114. TYPES(PREFIX, OP_SHIFT_RIGHT), \
  115. TYPES(PREFIX, OP_BIT_AND), \
  116. TYPES(PREFIX, OP_BIT_OR), \
  117. TYPES(PREFIX, OP_BIT_XOR), \
  118. TYPES(PREFIX, OP_BIT_NEGATE), \
  119. TYPES(PREFIX, OP_AND), \
  120. TYPES(PREFIX, OP_OR), \
  121. TYPES(PREFIX, OP_XOR), \
  122. TYPES(PREFIX, OP_NOT), \
  123. TYPES(PREFIX, OP_IN), \
  124. }
  125. #define SWITCH(PREFIX, op, val) goto *switch_table_##PREFIX[op][val];
  126. #define SWITCH_OP(PREFIX, OP, val)
  127. #define CASE_TYPE(PREFIX, OP, TYPE) PREFIX##_##OP##_##TYPE:
  128. #else
  129. #define CASES(PREFIX)
  130. #define SWITCH(PREFIX, op, val) switch (op)
  131. #define SWITCH_OP(PREFIX, OP, val) \
  132. case OP: \
  133. switch (val)
  134. #define CASE_TYPE(PREFIX, OP, TYPE) case TYPE:
  135. #endif
  136. Variant::operator bool() const {
  137. return booleanize();
  138. }
  139. // We consider all uninitialized or empty types to be false based on the type's
  140. // zeroiness.
  141. bool Variant::booleanize() const {
  142. return !is_zero();
  143. }
  144. #define _RETURN(m_what) \
  145. { \
  146. r_ret = m_what; \
  147. return; \
  148. }
  149. #define _RETURN_FAIL \
  150. { \
  151. r_valid = false; \
  152. return; \
  153. }
  154. #define DEFAULT_OP_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \
  155. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  156. if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \
  157. if (p_b.type == REAL) _RETURN(p_a._data.m_type m_op p_b._data._real); \
  158. \
  159. _RETURN_FAIL \
  160. };
  161. #define DEFAULT_OP_NUM_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
  162. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  163. if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \
  164. if (p_b.type == REAL) _RETURN(p_a._data.m_type m_op p_b._data._real); \
  165. if (p_b.type == NIL) _RETURN(!(p_b.type m_op NIL)); \
  166. \
  167. _RETURN_FAIL \
  168. };
  169. #ifdef DEBUG_ENABLED
  170. #define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \
  171. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  172. if (p_b.type == INT) { \
  173. if (p_b._data._int == 0) { \
  174. r_valid = false; \
  175. _RETURN("Division By Zero"); \
  176. } \
  177. _RETURN(p_a._data.m_type / p_b._data._int); \
  178. } \
  179. if (p_b.type == REAL) { \
  180. if (p_b._data._real == 0) { \
  181. r_valid = false; \
  182. _RETURN("Division By Zero"); \
  183. } \
  184. _RETURN(p_a._data.m_type / p_b._data._real); \
  185. } \
  186. \
  187. _RETURN_FAIL \
  188. };
  189. #else
  190. #define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \
  191. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  192. if (p_b.type == INT) _RETURN(p_a._data.m_type / p_b._data._int); \
  193. if (p_b.type == REAL) _RETURN(p_a._data.m_type / p_b._data._real); \
  194. \
  195. _RETURN_FAIL \
  196. };
  197. #endif
  198. #define DEFAULT_OP_NUM_NEG(m_prefix, m_op_name, m_name, m_type) \
  199. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  200. _RETURN(-p_a._data.m_type); \
  201. };
  202. #define DEFAULT_OP_NUM_POS(m_prefix, m_op_name, m_name, m_type) \
  203. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  204. _RETURN(p_a._data.m_type); \
  205. };
  206. #define DEFAULT_OP_NUM_VEC(m_prefix, m_op_name, m_name, m_op, m_type) \
  207. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  208. if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \
  209. if (p_b.type == REAL) _RETURN(p_a._data.m_type m_op p_b._data._real); \
  210. if (p_b.type == VECTOR2) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2 *>(p_b._data._mem)); \
  211. if (p_b.type == VECTOR3) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3 *>(p_b._data._mem)); \
  212. \
  213. _RETURN_FAIL \
  214. };
  215. #define DEFAULT_OP_STR_REV(m_prefix, m_op_name, m_name, m_op, m_type) \
  216. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  217. if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const String *>(p_a._data._mem)); \
  218. if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const NodePath *>(p_a._data._mem)); \
  219. \
  220. _RETURN_FAIL \
  221. };
  222. #define DEFAULT_OP_STR(m_prefix, m_op_name, m_name, m_op, m_type) \
  223. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  224. if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
  225. if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \
  226. \
  227. _RETURN_FAIL \
  228. };
  229. #define DEFAULT_OP_STR_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
  230. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  231. if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
  232. if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \
  233. if (p_b.type == NIL) _RETURN(!(p_b.type m_op NIL)); \
  234. \
  235. _RETURN_FAIL \
  236. };
  237. #define DEFAULT_OP_LOCALMEM_REV(m_prefix, m_op_name, m_name, m_op, m_type) \
  238. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  239. if (p_b.type == m_name) \
  240. _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const m_type *>(p_a._data._mem)); \
  241. \
  242. _RETURN_FAIL \
  243. };
  244. #define DEFAULT_OP_LOCALMEM(m_prefix, m_op_name, m_name, m_op, m_type) \
  245. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  246. if (p_b.type == m_name) \
  247. _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
  248. \
  249. _RETURN_FAIL \
  250. };
  251. #define DEFAULT_OP_LOCALMEM_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \
  252. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  253. if (p_b.type == m_name) \
  254. _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
  255. if (p_b.type == NIL) \
  256. _RETURN(!(p_b.type m_op NIL)); \
  257. \
  258. _RETURN_FAIL \
  259. };
  260. #define DEFAULT_OP_LOCALMEM_NEG(m_prefix, m_op_name, m_name, m_type) \
  261. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  262. _RETURN(-*reinterpret_cast<const m_type *>(p_a._data._mem)); \
  263. }
  264. #define DEFAULT_OP_LOCALMEM_POS(m_prefix, m_op_name, m_name, m_type) \
  265. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  266. _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem)); \
  267. }
  268. #define DEFAULT_OP_LOCALMEM_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \
  269. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  270. if (p_b.type == m_name) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
  271. if (p_b.type == INT) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._int); \
  272. if (p_b.type == REAL) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._real); \
  273. \
  274. _RETURN_FAIL \
  275. }
  276. #define DEFAULT_OP_PTR(m_op, m_name, m_sub) \
  277. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  278. if (p_b.type == m_name) \
  279. _RETURN(p_a._data.m_sub m_op p_b._data.m_sub); \
  280. \
  281. _RETURN_FAIL \
  282. }
  283. #define DEFAULT_OP_PTRREF(m_prefix, m_op_name, m_name, m_op, m_sub) \
  284. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  285. if (p_b.type == m_name) \
  286. _RETURN(*p_a._data.m_sub m_op *p_b._data.m_sub); \
  287. \
  288. _RETURN_FAIL \
  289. }
  290. #define DEFAULT_OP_PTRREF_NULL(m_prefix, m_op_name, m_name, m_op, m_sub) \
  291. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  292. if (p_b.type == m_name) \
  293. _RETURN(*p_a._data.m_sub m_op *p_b._data.m_sub); \
  294. if (p_b.type == NIL) \
  295. _RETURN(!(p_b.type m_op NIL)); \
  296. \
  297. _RETURN_FAIL \
  298. }
  299. #define DEFAULT_OP_ARRAY_EQ(m_prefix, m_op_name, m_name, m_type) \
  300. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  301. if (p_b.type == NIL) \
  302. _RETURN(false) \
  303. DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, !=, !=, true, false, false) \
  304. }
  305. #define DEFAULT_OP_ARRAY_NEQ(m_prefix, m_op_name, m_name, m_type) \
  306. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  307. if (p_b.type == NIL) \
  308. _RETURN(true) \
  309. DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, !=, !=, false, true, true) \
  310. }
  311. #define DEFAULT_OP_ARRAY_LT(m_prefix, m_op_name, m_name, m_type) \
  312. DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, <, !=, false, a_len < array_b.size(), true)
  313. #define DEFAULT_OP_ARRAY_GT(m_prefix, m_op_name, m_name, m_type) \
  314. DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, >, !=, false, a_len < array_b.size(), true)
  315. #define DEFAULT_OP_ARRAY_OP(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
  316. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  317. DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
  318. }
  319. #define DEFAULT_OP_ARRAY_OP_BODY(m_prefix, m_op_name, m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
  320. if (p_a.type != p_b.type) \
  321. _RETURN_FAIL \
  322. \
  323. const PoolVector<m_type> &array_a = *reinterpret_cast<const PoolVector<m_type> *>(p_a._data._mem); \
  324. const PoolVector<m_type> &array_b = *reinterpret_cast<const PoolVector<m_type> *>(p_b._data._mem); \
  325. \
  326. int a_len = array_a.size(); \
  327. if (a_len m_opa array_b.size()) { \
  328. _RETURN(m_ret_s); \
  329. } else { \
  330. \
  331. PoolVector<m_type>::Read ra = array_a.read(); \
  332. PoolVector<m_type>::Read rb = array_b.read(); \
  333. \
  334. for (int i = 0; i < a_len; i++) { \
  335. if (ra[i] m_opb rb[i]) \
  336. _RETURN(m_ret_f); \
  337. } \
  338. \
  339. _RETURN(m_ret_def); \
  340. }
  341. #define DEFAULT_OP_ARRAY_ADD(m_prefix, m_op_name, m_name, m_type) \
  342. CASE_TYPE(m_prefix, m_op_name, m_name) { \
  343. if (p_a.type != p_b.type) \
  344. _RETURN_FAIL; \
  345. \
  346. const PoolVector<m_type> &array_a = *reinterpret_cast<const PoolVector<m_type> *>(p_a._data._mem); \
  347. const PoolVector<m_type> &array_b = *reinterpret_cast<const PoolVector<m_type> *>(p_b._data._mem); \
  348. PoolVector<m_type> sum = array_a; \
  349. sum.append_array(array_b); \
  350. _RETURN(sum); \
  351. }
  352. void Variant::evaluate(const Operator &p_op, const Variant &p_a,
  353. const Variant &p_b, Variant &r_ret, bool &r_valid) {
  354. CASES(math);
  355. r_valid = true;
  356. SWITCH(math, p_op, p_a.type) {
  357. SWITCH_OP(math, OP_EQUAL, p_a.type) {
  358. CASE_TYPE(math, OP_EQUAL, NIL) {
  359. if (p_b.type == NIL) _RETURN(true);
  360. if (p_b.type == OBJECT)
  361. _RETURN(_OBJ_PTR(p_b) == NULL);
  362. _RETURN(false);
  363. }
  364. CASE_TYPE(math, OP_EQUAL, BOOL) {
  365. if (p_b.type != BOOL) {
  366. if (p_b.type == NIL)
  367. _RETURN(false);
  368. _RETURN_FAIL;
  369. }
  370. _RETURN(p_a._data._bool == p_b._data._bool);
  371. }
  372. CASE_TYPE(math, OP_EQUAL, OBJECT) {
  373. if (p_b.type == OBJECT)
  374. _RETURN(_OBJ_PTR(p_a) == _OBJ_PTR(p_b));
  375. if (p_b.type == NIL)
  376. _RETURN(_OBJ_PTR(p_a) == NULL);
  377. _RETURN_FAIL;
  378. }
  379. CASE_TYPE(math, OP_EQUAL, DICTIONARY) {
  380. if (p_b.type != DICTIONARY) {
  381. if (p_b.type == NIL)
  382. _RETURN(false);
  383. _RETURN_FAIL;
  384. }
  385. const Dictionary *arr_a = reinterpret_cast<const Dictionary *>(p_a._data._mem);
  386. const Dictionary *arr_b = reinterpret_cast<const Dictionary *>(p_b._data._mem);
  387. _RETURN(*arr_a == *arr_b);
  388. }
  389. CASE_TYPE(math, OP_EQUAL, ARRAY) {
  390. if (p_b.type != ARRAY) {
  391. if (p_b.type == NIL)
  392. _RETURN(false);
  393. _RETURN_FAIL;
  394. }
  395. const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
  396. const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
  397. int l = arr_a->size();
  398. if (arr_b->size() != l)
  399. _RETURN(false);
  400. for (int i = 0; i < l; i++) {
  401. if (!((*arr_a)[i] == (*arr_b)[i])) {
  402. _RETURN(false);
  403. }
  404. }
  405. _RETURN(true);
  406. }
  407. DEFAULT_OP_NUM_NULL(math, OP_EQUAL, INT, ==, _int);
  408. DEFAULT_OP_NUM_NULL(math, OP_EQUAL, REAL, ==, _real);
  409. DEFAULT_OP_STR_NULL(math, OP_EQUAL, STRING, ==, String);
  410. DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR2, ==, Vector2);
  411. DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, RECT2, ==, Rect2);
  412. DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, TRANSFORM2D, ==, _transform2d);
  413. DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR3, ==, Vector3);
  414. DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, PLANE, ==, Plane);
  415. DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, QUAT, ==, Quat);
  416. DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, AABB, ==, _aabb);
  417. DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, BASIS, ==, _basis);
  418. DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, TRANSFORM, ==, _transform);
  419. DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, COLOR, ==, Color);
  420. DEFAULT_OP_STR_NULL(math, OP_EQUAL, NODE_PATH, ==, NodePath);
  421. DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, _RID, ==, RID);
  422. DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_BYTE_ARRAY, uint8_t);
  423. DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_INT_ARRAY, int);
  424. DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_REAL_ARRAY, real_t);
  425. DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_STRING_ARRAY, String);
  426. DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_VECTOR2_ARRAY, Vector2);
  427. DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_VECTOR3_ARRAY, Vector3);
  428. DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, POOL_COLOR_ARRAY, Color);
  429. }
  430. SWITCH_OP(math, OP_NOT_EQUAL, p_a.type) {
  431. CASE_TYPE(math, OP_NOT_EQUAL, NIL) {
  432. if (p_b.type == NIL) _RETURN(false);
  433. if (p_b.type == OBJECT)
  434. _RETURN(_OBJ_PTR(p_b) != NULL);
  435. _RETURN(true);
  436. }
  437. CASE_TYPE(math, OP_NOT_EQUAL, BOOL) {
  438. if (p_b.type != BOOL) {
  439. if (p_b.type == NIL)
  440. _RETURN(true);
  441. _RETURN_FAIL;
  442. }
  443. _RETURN(p_a._data._bool != p_b._data._bool);
  444. }
  445. CASE_TYPE(math, OP_NOT_EQUAL, OBJECT) {
  446. if (p_b.type == OBJECT)
  447. _RETURN((_OBJ_PTR(p_a) != _OBJ_PTR(p_b)));
  448. if (p_b.type == NIL)
  449. _RETURN(_OBJ_PTR(p_a) != NULL);
  450. _RETURN_FAIL;
  451. }
  452. CASE_TYPE(math, OP_NOT_EQUAL, DICTIONARY) {
  453. if (p_b.type != DICTIONARY) {
  454. if (p_b.type == NIL)
  455. _RETURN(true);
  456. _RETURN_FAIL;
  457. }
  458. const Dictionary *arr_a = reinterpret_cast<const Dictionary *>(p_a._data._mem);
  459. const Dictionary *arr_b = reinterpret_cast<const Dictionary *>(p_b._data._mem);
  460. _RETURN(*arr_a != *arr_b);
  461. }
  462. CASE_TYPE(math, OP_NOT_EQUAL, ARRAY) {
  463. if (p_b.type != ARRAY) {
  464. if (p_b.type == NIL)
  465. _RETURN(true);
  466. _RETURN_FAIL;
  467. }
  468. const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
  469. const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
  470. int l = arr_a->size();
  471. if (arr_b->size() != l)
  472. _RETURN(true);
  473. for (int i = 0; i < l; i++) {
  474. if (((*arr_a)[i] != (*arr_b)[i])) {
  475. _RETURN(true);
  476. }
  477. }
  478. _RETURN(false);
  479. }
  480. DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, INT, !=, _int);
  481. DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, REAL, !=, _real);
  482. DEFAULT_OP_STR_NULL(math, OP_NOT_EQUAL, STRING, !=, String);
  483. DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR2, !=, Vector2);
  484. DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, RECT2, !=, Rect2);
  485. DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, TRANSFORM2D, !=, _transform2d);
  486. DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR3, !=, Vector3);
  487. DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, PLANE, !=, Plane);
  488. DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, QUAT, !=, Quat);
  489. DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, AABB, !=, _aabb);
  490. DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, BASIS, !=, _basis);
  491. DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, TRANSFORM, !=, _transform);
  492. DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, COLOR, !=, Color);
  493. DEFAULT_OP_STR_NULL(math, OP_NOT_EQUAL, NODE_PATH, !=, NodePath);
  494. DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, _RID, !=, RID);
  495. DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, POOL_BYTE_ARRAY, uint8_t);
  496. DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, POOL_INT_ARRAY, int);
  497. DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, POOL_REAL_ARRAY, real_t);
  498. DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, POOL_STRING_ARRAY, String);
  499. DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, POOL_VECTOR2_ARRAY, Vector2);
  500. DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, POOL_VECTOR3_ARRAY, Vector3);
  501. DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, POOL_COLOR_ARRAY, Color);
  502. }
  503. SWITCH_OP(math, OP_LESS, p_a.type) {
  504. CASE_TYPE(math, OP_LESS, BOOL) {
  505. if (p_b.type != BOOL)
  506. _RETURN_FAIL;
  507. if (p_a._data._bool == p_b._data._bool)
  508. _RETURN(false);
  509. if (p_a._data._bool && !p_b._data._bool)
  510. _RETURN(false);
  511. _RETURN(true);
  512. }
  513. CASE_TYPE(math, OP_LESS, OBJECT) {
  514. if (p_b.type != OBJECT)
  515. _RETURN_FAIL;
  516. _RETURN(_OBJ_PTR(p_a) < _OBJ_PTR(p_b));
  517. }
  518. CASE_TYPE(math, OP_LESS, ARRAY) {
  519. if (p_b.type != ARRAY)
  520. _RETURN_FAIL;
  521. const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
  522. const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
  523. int l = arr_a->size();
  524. if (arr_b->size() < l)
  525. _RETURN(false);
  526. for (int i = 0; i < l; i++) {
  527. if (!((*arr_a)[i] < (*arr_b)[i])) {
  528. _RETURN(true);
  529. }
  530. }
  531. _RETURN(false);
  532. }
  533. DEFAULT_OP_NUM(math, OP_LESS, INT, <, _int);
  534. DEFAULT_OP_NUM(math, OP_LESS, REAL, <, _real);
  535. DEFAULT_OP_STR(math, OP_LESS, STRING, <, String);
  536. DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR2, <, Vector2);
  537. DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR3, <, Vector3);
  538. DEFAULT_OP_LOCALMEM(math, OP_LESS, _RID, <, RID);
  539. DEFAULT_OP_ARRAY_LT(math, OP_LESS, POOL_BYTE_ARRAY, uint8_t);
  540. DEFAULT_OP_ARRAY_LT(math, OP_LESS, POOL_INT_ARRAY, int);
  541. DEFAULT_OP_ARRAY_LT(math, OP_LESS, POOL_REAL_ARRAY, real_t);
  542. DEFAULT_OP_ARRAY_LT(math, OP_LESS, POOL_STRING_ARRAY, String);
  543. DEFAULT_OP_ARRAY_LT(math, OP_LESS, POOL_VECTOR2_ARRAY, Vector3);
  544. DEFAULT_OP_ARRAY_LT(math, OP_LESS, POOL_VECTOR3_ARRAY, Vector3);
  545. DEFAULT_OP_ARRAY_LT(math, OP_LESS, POOL_COLOR_ARRAY, Color);
  546. CASE_TYPE(math, OP_LESS, NIL)
  547. CASE_TYPE(math, OP_LESS, RECT2)
  548. CASE_TYPE(math, OP_LESS, TRANSFORM2D)
  549. CASE_TYPE(math, OP_LESS, PLANE)
  550. CASE_TYPE(math, OP_LESS, QUAT)
  551. CASE_TYPE(math, OP_LESS, AABB)
  552. CASE_TYPE(math, OP_LESS, BASIS)
  553. CASE_TYPE(math, OP_LESS, TRANSFORM)
  554. CASE_TYPE(math, OP_LESS, COLOR)
  555. CASE_TYPE(math, OP_LESS, NODE_PATH)
  556. CASE_TYPE(math, OP_LESS, DICTIONARY)
  557. _RETURN_FAIL;
  558. }
  559. SWITCH_OP(math, OP_LESS_EQUAL, p_a.type) {
  560. CASE_TYPE(math, OP_LESS_EQUAL, OBJECT) {
  561. if (p_b.type != OBJECT)
  562. _RETURN_FAIL;
  563. _RETURN(_OBJ_PTR(p_a) <= _OBJ_PTR(p_b));
  564. }
  565. DEFAULT_OP_NUM(math, OP_LESS_EQUAL, INT, <=, _int);
  566. DEFAULT_OP_NUM(math, OP_LESS_EQUAL, REAL, <=, _real);
  567. DEFAULT_OP_STR(math, OP_LESS_EQUAL, STRING, <=, String);
  568. DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR2, <=, Vector2);
  569. DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR3, <=, Vector3);
  570. DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, _RID, <=, RID);
  571. CASE_TYPE(math, OP_LESS_EQUAL, NIL)
  572. CASE_TYPE(math, OP_LESS_EQUAL, BOOL)
  573. CASE_TYPE(math, OP_LESS_EQUAL, RECT2)
  574. CASE_TYPE(math, OP_LESS_EQUAL, TRANSFORM2D)
  575. CASE_TYPE(math, OP_LESS_EQUAL, PLANE)
  576. CASE_TYPE(math, OP_LESS_EQUAL, QUAT)
  577. CASE_TYPE(math, OP_LESS_EQUAL, AABB)
  578. CASE_TYPE(math, OP_LESS_EQUAL, BASIS)
  579. CASE_TYPE(math, OP_LESS_EQUAL, TRANSFORM)
  580. CASE_TYPE(math, OP_LESS_EQUAL, COLOR)
  581. CASE_TYPE(math, OP_LESS_EQUAL, NODE_PATH)
  582. CASE_TYPE(math, OP_LESS_EQUAL, DICTIONARY)
  583. CASE_TYPE(math, OP_LESS_EQUAL, ARRAY)
  584. CASE_TYPE(math, OP_LESS_EQUAL, POOL_BYTE_ARRAY);
  585. CASE_TYPE(math, OP_LESS_EQUAL, POOL_INT_ARRAY);
  586. CASE_TYPE(math, OP_LESS_EQUAL, POOL_REAL_ARRAY);
  587. CASE_TYPE(math, OP_LESS_EQUAL, POOL_STRING_ARRAY);
  588. CASE_TYPE(math, OP_LESS_EQUAL, POOL_VECTOR2_ARRAY);
  589. CASE_TYPE(math, OP_LESS_EQUAL, POOL_VECTOR3_ARRAY);
  590. CASE_TYPE(math, OP_LESS_EQUAL, POOL_COLOR_ARRAY);
  591. _RETURN_FAIL;
  592. }
  593. SWITCH_OP(math, OP_GREATER, p_a.type) {
  594. CASE_TYPE(math, OP_GREATER, BOOL) {
  595. if (p_b.type != BOOL)
  596. _RETURN_FAIL;
  597. if (p_a._data._bool == p_b._data._bool)
  598. _RETURN(false);
  599. if (!p_a._data._bool && p_b._data._bool)
  600. _RETURN(false);
  601. _RETURN(true);
  602. }
  603. CASE_TYPE(math, OP_GREATER, OBJECT) {
  604. if (p_b.type != OBJECT)
  605. _RETURN_FAIL;
  606. _RETURN(_OBJ_PTR(p_a) > _OBJ_PTR(p_b));
  607. }
  608. CASE_TYPE(math, OP_GREATER, ARRAY) {
  609. if (p_b.type != ARRAY)
  610. _RETURN_FAIL;
  611. const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
  612. const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
  613. int l = arr_a->size();
  614. if (arr_b->size() > l)
  615. _RETURN(false);
  616. for (int i = 0; i < l; i++) {
  617. if (((*arr_a)[i] < (*arr_b)[i])) {
  618. _RETURN(false);
  619. }
  620. }
  621. _RETURN(true);
  622. }
  623. DEFAULT_OP_NUM(math, OP_GREATER, INT, >, _int);
  624. DEFAULT_OP_NUM(math, OP_GREATER, REAL, >, _real);
  625. DEFAULT_OP_STR_REV(math, OP_GREATER, STRING, <, String);
  626. DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR2, <, Vector2);
  627. DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR3, <, Vector3);
  628. DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, _RID, <, RID);
  629. DEFAULT_OP_ARRAY_GT(math, OP_GREATER, POOL_BYTE_ARRAY, uint8_t);
  630. DEFAULT_OP_ARRAY_GT(math, OP_GREATER, POOL_INT_ARRAY, int);
  631. DEFAULT_OP_ARRAY_GT(math, OP_GREATER, POOL_REAL_ARRAY, real_t);
  632. DEFAULT_OP_ARRAY_GT(math, OP_GREATER, POOL_STRING_ARRAY, String);
  633. DEFAULT_OP_ARRAY_GT(math, OP_GREATER, POOL_VECTOR2_ARRAY, Vector3);
  634. DEFAULT_OP_ARRAY_GT(math, OP_GREATER, POOL_VECTOR3_ARRAY, Vector3);
  635. DEFAULT_OP_ARRAY_GT(math, OP_GREATER, POOL_COLOR_ARRAY, Color);
  636. CASE_TYPE(math, OP_GREATER, NIL)
  637. CASE_TYPE(math, OP_GREATER, RECT2)
  638. CASE_TYPE(math, OP_GREATER, TRANSFORM2D)
  639. CASE_TYPE(math, OP_GREATER, PLANE)
  640. CASE_TYPE(math, OP_GREATER, QUAT)
  641. CASE_TYPE(math, OP_GREATER, AABB)
  642. CASE_TYPE(math, OP_GREATER, BASIS)
  643. CASE_TYPE(math, OP_GREATER, TRANSFORM)
  644. CASE_TYPE(math, OP_GREATER, COLOR)
  645. CASE_TYPE(math, OP_GREATER, NODE_PATH)
  646. CASE_TYPE(math, OP_GREATER, DICTIONARY)
  647. _RETURN_FAIL;
  648. }
  649. SWITCH_OP(math, OP_GREATER_EQUAL, p_a.type) {
  650. CASE_TYPE(math, OP_GREATER_EQUAL, OBJECT) {
  651. if (p_b.type != OBJECT)
  652. _RETURN_FAIL;
  653. _RETURN(_OBJ_PTR(p_a) >= _OBJ_PTR(p_b));
  654. }
  655. DEFAULT_OP_NUM(math, OP_GREATER_EQUAL, INT, >=, _int);
  656. DEFAULT_OP_NUM(math, OP_GREATER_EQUAL, REAL, >=, _real);
  657. DEFAULT_OP_STR_REV(math, OP_GREATER_EQUAL, STRING, <=, String);
  658. DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR2, <=, Vector2);
  659. DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR3, <=, Vector3);
  660. DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, _RID, <=, RID);
  661. CASE_TYPE(math, OP_GREATER_EQUAL, NIL)
  662. CASE_TYPE(math, OP_GREATER_EQUAL, BOOL)
  663. CASE_TYPE(math, OP_GREATER_EQUAL, RECT2)
  664. CASE_TYPE(math, OP_GREATER_EQUAL, TRANSFORM2D)
  665. CASE_TYPE(math, OP_GREATER_EQUAL, PLANE)
  666. CASE_TYPE(math, OP_GREATER_EQUAL, QUAT)
  667. CASE_TYPE(math, OP_GREATER_EQUAL, AABB)
  668. CASE_TYPE(math, OP_GREATER_EQUAL, BASIS)
  669. CASE_TYPE(math, OP_GREATER_EQUAL, TRANSFORM)
  670. CASE_TYPE(math, OP_GREATER_EQUAL, COLOR)
  671. CASE_TYPE(math, OP_GREATER_EQUAL, NODE_PATH)
  672. CASE_TYPE(math, OP_GREATER_EQUAL, DICTIONARY)
  673. CASE_TYPE(math, OP_GREATER_EQUAL, ARRAY)
  674. CASE_TYPE(math, OP_GREATER_EQUAL, POOL_BYTE_ARRAY);
  675. CASE_TYPE(math, OP_GREATER_EQUAL, POOL_INT_ARRAY);
  676. CASE_TYPE(math, OP_GREATER_EQUAL, POOL_REAL_ARRAY);
  677. CASE_TYPE(math, OP_GREATER_EQUAL, POOL_STRING_ARRAY);
  678. CASE_TYPE(math, OP_GREATER_EQUAL, POOL_VECTOR2_ARRAY);
  679. CASE_TYPE(math, OP_GREATER_EQUAL, POOL_VECTOR3_ARRAY);
  680. CASE_TYPE(math, OP_GREATER_EQUAL, POOL_COLOR_ARRAY);
  681. _RETURN_FAIL;
  682. }
  683. SWITCH_OP(math, OP_ADD, p_a.type) {
  684. CASE_TYPE(math, OP_ADD, ARRAY) {
  685. if (p_a.type != p_b.type)
  686. _RETURN_FAIL;
  687. const Array &array_a = *reinterpret_cast<const Array *>(p_a._data._mem);
  688. const Array &array_b = *reinterpret_cast<const Array *>(p_b._data._mem);
  689. Array sum;
  690. int asize = array_a.size();
  691. int bsize = array_b.size();
  692. sum.resize(asize + bsize);
  693. for (int i = 0; i < asize; i++)
  694. sum[i] = array_a[i];
  695. for (int i = 0; i < bsize; i++)
  696. sum[i + asize] = array_b[i];
  697. _RETURN(sum);
  698. }
  699. DEFAULT_OP_NUM(math, OP_ADD, INT, +, _int);
  700. DEFAULT_OP_NUM(math, OP_ADD, REAL, +, _real);
  701. DEFAULT_OP_STR(math, OP_ADD, STRING, +, String);
  702. DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR2, +, Vector2);
  703. DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR3, +, Vector3);
  704. DEFAULT_OP_LOCALMEM(math, OP_ADD, QUAT, +, Quat);
  705. DEFAULT_OP_LOCALMEM(math, OP_ADD, COLOR, +, Color);
  706. DEFAULT_OP_ARRAY_ADD(math, OP_ADD, POOL_BYTE_ARRAY, uint8_t);
  707. DEFAULT_OP_ARRAY_ADD(math, OP_ADD, POOL_INT_ARRAY, int);
  708. DEFAULT_OP_ARRAY_ADD(math, OP_ADD, POOL_REAL_ARRAY, real_t);
  709. DEFAULT_OP_ARRAY_ADD(math, OP_ADD, POOL_STRING_ARRAY, String);
  710. DEFAULT_OP_ARRAY_ADD(math, OP_ADD, POOL_VECTOR2_ARRAY, Vector2);
  711. DEFAULT_OP_ARRAY_ADD(math, OP_ADD, POOL_VECTOR3_ARRAY, Vector3);
  712. DEFAULT_OP_ARRAY_ADD(math, OP_ADD, POOL_COLOR_ARRAY, Color);
  713. CASE_TYPE(math, OP_ADD, NIL)
  714. CASE_TYPE(math, OP_ADD, BOOL)
  715. CASE_TYPE(math, OP_ADD, RECT2)
  716. CASE_TYPE(math, OP_ADD, TRANSFORM2D)
  717. CASE_TYPE(math, OP_ADD, PLANE)
  718. CASE_TYPE(math, OP_ADD, AABB)
  719. CASE_TYPE(math, OP_ADD, BASIS)
  720. CASE_TYPE(math, OP_ADD, TRANSFORM)
  721. CASE_TYPE(math, OP_ADD, NODE_PATH)
  722. CASE_TYPE(math, OP_ADD, _RID)
  723. CASE_TYPE(math, OP_ADD, OBJECT)
  724. CASE_TYPE(math, OP_ADD, DICTIONARY)
  725. _RETURN_FAIL;
  726. }
  727. SWITCH_OP(math, OP_SUBTRACT, p_a.type) {
  728. DEFAULT_OP_NUM(math, OP_SUBTRACT, INT, -, _int);
  729. DEFAULT_OP_NUM(math, OP_SUBTRACT, REAL, -, _real);
  730. DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR2, -, Vector2);
  731. DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR3, -, Vector3);
  732. DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, QUAT, -, Quat);
  733. DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, COLOR, -, Color);
  734. CASE_TYPE(math, OP_SUBTRACT, NIL)
  735. CASE_TYPE(math, OP_SUBTRACT, BOOL)
  736. CASE_TYPE(math, OP_SUBTRACT, STRING)
  737. CASE_TYPE(math, OP_SUBTRACT, RECT2)
  738. CASE_TYPE(math, OP_SUBTRACT, TRANSFORM2D)
  739. CASE_TYPE(math, OP_SUBTRACT, PLANE)
  740. CASE_TYPE(math, OP_SUBTRACT, AABB)
  741. CASE_TYPE(math, OP_SUBTRACT, BASIS)
  742. CASE_TYPE(math, OP_SUBTRACT, TRANSFORM)
  743. CASE_TYPE(math, OP_SUBTRACT, NODE_PATH)
  744. CASE_TYPE(math, OP_SUBTRACT, _RID)
  745. CASE_TYPE(math, OP_SUBTRACT, OBJECT)
  746. CASE_TYPE(math, OP_SUBTRACT, DICTIONARY)
  747. CASE_TYPE(math, OP_SUBTRACT, ARRAY)
  748. CASE_TYPE(math, OP_SUBTRACT, POOL_BYTE_ARRAY);
  749. CASE_TYPE(math, OP_SUBTRACT, POOL_INT_ARRAY);
  750. CASE_TYPE(math, OP_SUBTRACT, POOL_REAL_ARRAY);
  751. CASE_TYPE(math, OP_SUBTRACT, POOL_STRING_ARRAY);
  752. CASE_TYPE(math, OP_SUBTRACT, POOL_VECTOR2_ARRAY);
  753. CASE_TYPE(math, OP_SUBTRACT, POOL_VECTOR3_ARRAY);
  754. CASE_TYPE(math, OP_SUBTRACT, POOL_COLOR_ARRAY);
  755. _RETURN_FAIL;
  756. }
  757. SWITCH_OP(math, OP_MULTIPLY, p_a.type) {
  758. CASE_TYPE(math, OP_MULTIPLY, TRANSFORM2D) {
  759. switch (p_b.type) {
  760. case TRANSFORM2D: {
  761. _RETURN(*p_a._data._transform2d * *p_b._data._transform2d);
  762. }
  763. case VECTOR2: {
  764. _RETURN(p_a._data._transform2d->xform(*(const Vector2 *)p_b._data._mem));
  765. }
  766. default: _RETURN_FAIL;
  767. }
  768. }
  769. CASE_TYPE(math, OP_MULTIPLY, QUAT) {
  770. switch (p_b.type) {
  771. case VECTOR3: {
  772. _RETURN(reinterpret_cast<const Quat *>(p_a._data._mem)->xform(*(const Vector3 *)p_b._data._mem));
  773. }
  774. case QUAT: {
  775. _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * *reinterpret_cast<const Quat *>(p_b._data._mem));
  776. }
  777. case REAL: {
  778. _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._real);
  779. }
  780. default: _RETURN_FAIL;
  781. }
  782. }
  783. CASE_TYPE(math, OP_MULTIPLY, BASIS) {
  784. switch (p_b.type) {
  785. case VECTOR3: {
  786. _RETURN(p_a._data._basis->xform(*(const Vector3 *)p_b._data._mem));
  787. }
  788. case BASIS: {
  789. _RETURN(*p_a._data._basis * *p_b._data._basis);
  790. }
  791. default: _RETURN_FAIL;
  792. }
  793. }
  794. CASE_TYPE(math, OP_MULTIPLY, TRANSFORM) {
  795. switch (p_b.type) {
  796. case VECTOR3: {
  797. _RETURN(p_a._data._transform->xform(*(const Vector3 *)p_b._data._mem));
  798. }
  799. case TRANSFORM: {
  800. _RETURN(*p_a._data._transform * *p_b._data._transform);
  801. }
  802. default: _RETURN_FAIL;
  803. }
  804. }
  805. DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, INT, *, _int);
  806. DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, REAL, *, _real);
  807. DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2, *, Vector2);
  808. DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3, *, Vector3);
  809. DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, COLOR, *, Color);
  810. CASE_TYPE(math, OP_MULTIPLY, NIL)
  811. CASE_TYPE(math, OP_MULTIPLY, BOOL)
  812. CASE_TYPE(math, OP_MULTIPLY, STRING)
  813. CASE_TYPE(math, OP_MULTIPLY, RECT2)
  814. CASE_TYPE(math, OP_MULTIPLY, PLANE)
  815. CASE_TYPE(math, OP_MULTIPLY, AABB)
  816. CASE_TYPE(math, OP_MULTIPLY, NODE_PATH)
  817. CASE_TYPE(math, OP_MULTIPLY, _RID)
  818. CASE_TYPE(math, OP_MULTIPLY, OBJECT)
  819. CASE_TYPE(math, OP_MULTIPLY, DICTIONARY)
  820. CASE_TYPE(math, OP_MULTIPLY, ARRAY)
  821. CASE_TYPE(math, OP_MULTIPLY, POOL_BYTE_ARRAY);
  822. CASE_TYPE(math, OP_MULTIPLY, POOL_INT_ARRAY);
  823. CASE_TYPE(math, OP_MULTIPLY, POOL_REAL_ARRAY);
  824. CASE_TYPE(math, OP_MULTIPLY, POOL_STRING_ARRAY);
  825. CASE_TYPE(math, OP_MULTIPLY, POOL_VECTOR2_ARRAY);
  826. CASE_TYPE(math, OP_MULTIPLY, POOL_VECTOR3_ARRAY);
  827. CASE_TYPE(math, OP_MULTIPLY, POOL_COLOR_ARRAY);
  828. _RETURN_FAIL;
  829. }
  830. SWITCH_OP(math, OP_DIVIDE, p_a.type) {
  831. CASE_TYPE(math, OP_DIVIDE, QUAT) {
  832. if (p_b.type != REAL)
  833. _RETURN_FAIL;
  834. #ifdef DEBUG_ENABLED
  835. if (p_b._data._real == 0) {
  836. r_valid = false;
  837. _RETURN("Division By Zero");
  838. }
  839. #endif
  840. _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) / p_b._data._real);
  841. }
  842. DEFAULT_OP_NUM_DIV(math, OP_DIVIDE, INT, _int);
  843. DEFAULT_OP_NUM_DIV(math, OP_DIVIDE, REAL, _real);
  844. DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR2, /, Vector2);
  845. DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR3, /, Vector3);
  846. DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, COLOR, /, Color);
  847. CASE_TYPE(math, OP_DIVIDE, NIL)
  848. CASE_TYPE(math, OP_DIVIDE, BOOL)
  849. CASE_TYPE(math, OP_DIVIDE, STRING)
  850. CASE_TYPE(math, OP_DIVIDE, RECT2)
  851. CASE_TYPE(math, OP_DIVIDE, TRANSFORM2D)
  852. CASE_TYPE(math, OP_DIVIDE, PLANE)
  853. CASE_TYPE(math, OP_DIVIDE, AABB)
  854. CASE_TYPE(math, OP_DIVIDE, BASIS)
  855. CASE_TYPE(math, OP_DIVIDE, TRANSFORM)
  856. CASE_TYPE(math, OP_DIVIDE, NODE_PATH)
  857. CASE_TYPE(math, OP_DIVIDE, _RID)
  858. CASE_TYPE(math, OP_DIVIDE, OBJECT)
  859. CASE_TYPE(math, OP_DIVIDE, DICTIONARY)
  860. CASE_TYPE(math, OP_DIVIDE, ARRAY)
  861. CASE_TYPE(math, OP_DIVIDE, POOL_BYTE_ARRAY);
  862. CASE_TYPE(math, OP_DIVIDE, POOL_INT_ARRAY);
  863. CASE_TYPE(math, OP_DIVIDE, POOL_REAL_ARRAY);
  864. CASE_TYPE(math, OP_DIVIDE, POOL_STRING_ARRAY);
  865. CASE_TYPE(math, OP_DIVIDE, POOL_VECTOR2_ARRAY);
  866. CASE_TYPE(math, OP_DIVIDE, POOL_VECTOR3_ARRAY);
  867. CASE_TYPE(math, OP_DIVIDE, POOL_COLOR_ARRAY);
  868. _RETURN_FAIL;
  869. }
  870. SWITCH_OP(math, OP_POSITIVE, p_a.type) {
  871. DEFAULT_OP_NUM_POS(math, OP_POSITIVE, INT, _int);
  872. DEFAULT_OP_NUM_POS(math, OP_POSITIVE, REAL, _real);
  873. DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR3, Vector3);
  874. DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, PLANE, Plane);
  875. DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, QUAT, Quat);
  876. DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR2, Vector2);
  877. CASE_TYPE(math, OP_POSITIVE, NIL)
  878. CASE_TYPE(math, OP_POSITIVE, BOOL)
  879. CASE_TYPE(math, OP_POSITIVE, STRING)
  880. CASE_TYPE(math, OP_POSITIVE, RECT2)
  881. CASE_TYPE(math, OP_POSITIVE, TRANSFORM2D)
  882. CASE_TYPE(math, OP_POSITIVE, AABB)
  883. CASE_TYPE(math, OP_POSITIVE, BASIS)
  884. CASE_TYPE(math, OP_POSITIVE, TRANSFORM)
  885. CASE_TYPE(math, OP_POSITIVE, COLOR)
  886. CASE_TYPE(math, OP_POSITIVE, NODE_PATH)
  887. CASE_TYPE(math, OP_POSITIVE, _RID)
  888. CASE_TYPE(math, OP_POSITIVE, OBJECT)
  889. CASE_TYPE(math, OP_POSITIVE, DICTIONARY)
  890. CASE_TYPE(math, OP_POSITIVE, ARRAY)
  891. CASE_TYPE(math, OP_POSITIVE, POOL_BYTE_ARRAY)
  892. CASE_TYPE(math, OP_POSITIVE, POOL_INT_ARRAY)
  893. CASE_TYPE(math, OP_POSITIVE, POOL_REAL_ARRAY)
  894. CASE_TYPE(math, OP_POSITIVE, POOL_STRING_ARRAY)
  895. CASE_TYPE(math, OP_POSITIVE, POOL_VECTOR2_ARRAY)
  896. CASE_TYPE(math, OP_POSITIVE, POOL_VECTOR3_ARRAY)
  897. CASE_TYPE(math, OP_POSITIVE, POOL_COLOR_ARRAY)
  898. _RETURN_FAIL;
  899. }
  900. SWITCH_OP(math, OP_NEGATE, p_a.type) {
  901. DEFAULT_OP_NUM_NEG(math, OP_NEGATE, INT, _int);
  902. DEFAULT_OP_NUM_NEG(math, OP_NEGATE, REAL, _real);
  903. DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR2, Vector2);
  904. DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR3, Vector3);
  905. DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, PLANE, Plane);
  906. DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, QUAT, Quat);
  907. DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, COLOR, Color);
  908. CASE_TYPE(math, OP_NEGATE, NIL)
  909. CASE_TYPE(math, OP_NEGATE, BOOL)
  910. CASE_TYPE(math, OP_NEGATE, STRING)
  911. CASE_TYPE(math, OP_NEGATE, RECT2)
  912. CASE_TYPE(math, OP_NEGATE, TRANSFORM2D)
  913. CASE_TYPE(math, OP_NEGATE, AABB)
  914. CASE_TYPE(math, OP_NEGATE, BASIS)
  915. CASE_TYPE(math, OP_NEGATE, TRANSFORM)
  916. CASE_TYPE(math, OP_NEGATE, NODE_PATH)
  917. CASE_TYPE(math, OP_NEGATE, _RID)
  918. CASE_TYPE(math, OP_NEGATE, OBJECT)
  919. CASE_TYPE(math, OP_NEGATE, DICTIONARY)
  920. CASE_TYPE(math, OP_NEGATE, ARRAY)
  921. CASE_TYPE(math, OP_NEGATE, POOL_BYTE_ARRAY)
  922. CASE_TYPE(math, OP_NEGATE, POOL_INT_ARRAY)
  923. CASE_TYPE(math, OP_NEGATE, POOL_REAL_ARRAY)
  924. CASE_TYPE(math, OP_NEGATE, POOL_STRING_ARRAY)
  925. CASE_TYPE(math, OP_NEGATE, POOL_VECTOR2_ARRAY)
  926. CASE_TYPE(math, OP_NEGATE, POOL_VECTOR3_ARRAY)
  927. CASE_TYPE(math, OP_NEGATE, POOL_COLOR_ARRAY)
  928. _RETURN_FAIL;
  929. }
  930. SWITCH_OP(math, OP_MODULE, p_a.type) {
  931. CASE_TYPE(math, OP_MODULE, INT) {
  932. if (p_b.type != INT)
  933. _RETURN_FAIL;
  934. #ifdef DEBUG_ENABLED
  935. if (p_b._data._int == 0) {
  936. r_valid = false;
  937. _RETURN("Division By Zero");
  938. }
  939. #endif
  940. _RETURN(p_a._data._int % p_b._data._int);
  941. }
  942. CASE_TYPE(math, OP_MODULE, STRING) {
  943. const String *format = reinterpret_cast<const String *>(p_a._data._mem);
  944. String result;
  945. bool error;
  946. if (p_b.type == ARRAY) {
  947. // e.g. "frog %s %d" % ["fish", 12]
  948. const Array *args = reinterpret_cast<const Array *>(p_b._data._mem);
  949. result = format->sprintf(*args, &error);
  950. } else {
  951. // e.g. "frog %d" % 12
  952. Array args;
  953. args.push_back(p_b);
  954. result = format->sprintf(args, &error);
  955. }
  956. r_valid = !error;
  957. _RETURN(result);
  958. }
  959. CASE_TYPE(math, OP_MODULE, NIL)
  960. CASE_TYPE(math, OP_MODULE, BOOL)
  961. CASE_TYPE(math, OP_MODULE, REAL)
  962. CASE_TYPE(math, OP_MODULE, VECTOR2)
  963. CASE_TYPE(math, OP_MODULE, RECT2)
  964. CASE_TYPE(math, OP_MODULE, VECTOR3)
  965. CASE_TYPE(math, OP_MODULE, TRANSFORM2D)
  966. CASE_TYPE(math, OP_MODULE, PLANE)
  967. CASE_TYPE(math, OP_MODULE, QUAT)
  968. CASE_TYPE(math, OP_MODULE, AABB)
  969. CASE_TYPE(math, OP_MODULE, BASIS)
  970. CASE_TYPE(math, OP_MODULE, TRANSFORM)
  971. CASE_TYPE(math, OP_MODULE, COLOR)
  972. CASE_TYPE(math, OP_MODULE, NODE_PATH)
  973. CASE_TYPE(math, OP_MODULE, _RID)
  974. CASE_TYPE(math, OP_MODULE, OBJECT)
  975. CASE_TYPE(math, OP_MODULE, DICTIONARY)
  976. CASE_TYPE(math, OP_MODULE, ARRAY)
  977. CASE_TYPE(math, OP_MODULE, POOL_BYTE_ARRAY)
  978. CASE_TYPE(math, OP_MODULE, POOL_INT_ARRAY)
  979. CASE_TYPE(math, OP_MODULE, POOL_REAL_ARRAY)
  980. CASE_TYPE(math, OP_MODULE, POOL_STRING_ARRAY)
  981. CASE_TYPE(math, OP_MODULE, POOL_VECTOR2_ARRAY)
  982. CASE_TYPE(math, OP_MODULE, POOL_VECTOR3_ARRAY)
  983. CASE_TYPE(math, OP_MODULE, POOL_COLOR_ARRAY)
  984. _RETURN_FAIL;
  985. }
  986. SWITCH_OP(math, OP_STRING_CONCAT, p_a.type) {
  987. CASE_TYPE_ALL(math, OP_STRING_CONCAT)
  988. _RETURN(p_a.operator String() + p_b.operator String());
  989. }
  990. SWITCH_OP(math, OP_SHIFT_LEFT, p_a.type) {
  991. CASE_TYPE(math, OP_SHIFT_LEFT, INT) {
  992. if (p_b.type != INT)
  993. _RETURN_FAIL;
  994. if (p_b._data._int < 0 || p_b._data._int >= 64)
  995. _RETURN_FAIL;
  996. _RETURN(p_a._data._int << p_b._data._int);
  997. }
  998. CASE_TYPE_ALL_BUT_INT(math, OP_SHIFT_LEFT)
  999. _RETURN_FAIL;
  1000. }
  1001. SWITCH_OP(math, OP_SHIFT_RIGHT, p_a.type) {
  1002. CASE_TYPE(math, OP_SHIFT_RIGHT, INT) {
  1003. if (p_b.type != INT)
  1004. _RETURN_FAIL;
  1005. if (p_b._data._int < 0 || p_b._data._int >= 64)
  1006. _RETURN_FAIL;
  1007. _RETURN(p_a._data._int >> p_b._data._int);
  1008. }
  1009. CASE_TYPE_ALL_BUT_INT(math, OP_SHIFT_RIGHT)
  1010. _RETURN_FAIL;
  1011. }
  1012. SWITCH_OP(math, OP_BIT_AND, p_a.type) {
  1013. CASE_TYPE(math, OP_BIT_AND, INT) {
  1014. if (p_b.type != INT)
  1015. _RETURN_FAIL;
  1016. _RETURN(p_a._data._int & p_b._data._int);
  1017. }
  1018. CASE_TYPE_ALL_BUT_INT(math, OP_BIT_AND)
  1019. _RETURN_FAIL;
  1020. }
  1021. SWITCH_OP(math, OP_BIT_OR, p_a.type) {
  1022. CASE_TYPE(math, OP_BIT_OR, INT) {
  1023. if (p_b.type != INT)
  1024. _RETURN_FAIL;
  1025. _RETURN(p_a._data._int | p_b._data._int);
  1026. }
  1027. CASE_TYPE_ALL_BUT_INT(math, OP_BIT_OR)
  1028. _RETURN_FAIL;
  1029. }
  1030. SWITCH_OP(math, OP_BIT_XOR, p_a.type) {
  1031. CASE_TYPE(math, OP_BIT_XOR, INT) {
  1032. if (p_b.type != INT)
  1033. _RETURN_FAIL;
  1034. _RETURN(p_a._data._int ^ p_b._data._int);
  1035. }
  1036. CASE_TYPE_ALL_BUT_INT(math, OP_BIT_XOR)
  1037. _RETURN_FAIL;
  1038. }
  1039. SWITCH_OP(math, OP_BIT_NEGATE, p_a.type) {
  1040. CASE_TYPE(math, OP_BIT_NEGATE, INT) {
  1041. _RETURN(~p_a._data._int);
  1042. }
  1043. CASE_TYPE_ALL_BUT_INT(math, OP_BIT_NEGATE)
  1044. _RETURN_FAIL;
  1045. }
  1046. SWITCH_OP(math, OP_AND, p_a.type) {
  1047. CASE_TYPE_ALL(math, OP_AND) {
  1048. bool l = p_a.booleanize();
  1049. bool r = p_b.booleanize();
  1050. _RETURN(l && r);
  1051. }
  1052. }
  1053. SWITCH_OP(math, OP_OR, p_a.type) {
  1054. CASE_TYPE_ALL(math, OP_OR) {
  1055. bool l = p_a.booleanize();
  1056. bool r = p_b.booleanize();
  1057. _RETURN(l || r);
  1058. }
  1059. }
  1060. SWITCH_OP(math, OP_XOR, p_a.type) {
  1061. CASE_TYPE_ALL(math, OP_XOR) {
  1062. bool l = p_a.booleanize();
  1063. bool r = p_b.booleanize();
  1064. _RETURN((l || r) && !(l && r));
  1065. }
  1066. }
  1067. SWITCH_OP(math, OP_NOT, p_a.type) {
  1068. CASE_TYPE_ALL(math, OP_NOT) {
  1069. bool l = p_a.booleanize();
  1070. _RETURN(!l);
  1071. }
  1072. }
  1073. SWITCH_OP(math, OP_IN, p_a.type) {
  1074. CASE_TYPE_ALL(math, OP_IN)
  1075. _RETURN(p_b.in(p_a, &r_valid));
  1076. }
  1077. }
  1078. }
  1079. void Variant::set_named(const StringName &p_index, const Variant &p_value, bool *r_valid) {
  1080. bool valid = false;
  1081. switch (type) {
  1082. case VECTOR2: {
  1083. if (p_value.type == Variant::INT) {
  1084. Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
  1085. if (p_index == CoreStringNames::singleton->x) {
  1086. v->x = p_value._data._int;
  1087. valid = true;
  1088. } else if (p_index == CoreStringNames::singleton->y) {
  1089. v->y = p_value._data._int;
  1090. valid = true;
  1091. }
  1092. } else if (p_value.type == Variant::REAL) {
  1093. Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
  1094. if (p_index == CoreStringNames::singleton->x) {
  1095. v->x = p_value._data._real;
  1096. valid = true;
  1097. } else if (p_index == CoreStringNames::singleton->y) {
  1098. v->y = p_value._data._real;
  1099. valid = true;
  1100. }
  1101. }
  1102. } break;
  1103. case RECT2: {
  1104. if (p_value.type == Variant::VECTOR2) {
  1105. Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem);
  1106. //scalar name
  1107. if (p_index == CoreStringNames::singleton->position) {
  1108. v->position = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
  1109. valid = true;
  1110. } else if (p_index == CoreStringNames::singleton->size) {
  1111. v->size = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
  1112. valid = true;
  1113. } else if (p_index == CoreStringNames::singleton->end) {
  1114. v->size = *reinterpret_cast<const Vector2 *>(p_value._data._mem) - v->position;
  1115. valid = true;
  1116. }
  1117. }
  1118. } break;
  1119. case TRANSFORM2D: {
  1120. if (p_value.type == Variant::VECTOR2) {
  1121. Transform2D *v = _data._transform2d;
  1122. if (p_index == CoreStringNames::singleton->x) {
  1123. v->elements[0] = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
  1124. valid = true;
  1125. } else if (p_index == CoreStringNames::singleton->y) {
  1126. v->elements[1] = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
  1127. valid = true;
  1128. } else if (p_index == CoreStringNames::singleton->origin) {
  1129. v->elements[2] = *reinterpret_cast<const Vector2 *>(p_value._data._mem);
  1130. valid = true;
  1131. }
  1132. }
  1133. } break;
  1134. case VECTOR3: {
  1135. if (p_value.type == Variant::INT) {
  1136. Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
  1137. if (p_index == CoreStringNames::singleton->x) {
  1138. v->x = p_value._data._int;
  1139. valid = true;
  1140. } else if (p_index == CoreStringNames::singleton->y) {
  1141. v->y = p_value._data._int;
  1142. valid = true;
  1143. } else if (p_index == CoreStringNames::singleton->z) {
  1144. v->z = p_value._data._int;
  1145. valid = true;
  1146. }
  1147. } else if (p_value.type == Variant::REAL) {
  1148. Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
  1149. if (p_index == CoreStringNames::singleton->x) {
  1150. v->x = p_value._data._real;
  1151. valid = true;
  1152. } else if (p_index == CoreStringNames::singleton->y) {
  1153. v->y = p_value._data._real;
  1154. valid = true;
  1155. } else if (p_index == CoreStringNames::singleton->z) {
  1156. v->z = p_value._data._real;
  1157. valid = true;
  1158. }
  1159. }
  1160. } break;
  1161. case PLANE: {
  1162. if (p_value.type == Variant::INT) {
  1163. Plane *v = reinterpret_cast<Plane *>(_data._mem);
  1164. if (p_index == CoreStringNames::singleton->x) {
  1165. v->normal.x = p_value._data._int;
  1166. valid = true;
  1167. } else if (p_index == CoreStringNames::singleton->y) {
  1168. v->normal.y = p_value._data._int;
  1169. valid = true;
  1170. } else if (p_index == CoreStringNames::singleton->z) {
  1171. v->normal.z = p_value._data._int;
  1172. valid = true;
  1173. } else if (p_index == CoreStringNames::singleton->d) {
  1174. v->d = p_value._data._int;
  1175. valid = true;
  1176. }
  1177. } else if (p_value.type == Variant::REAL) {
  1178. Plane *v = reinterpret_cast<Plane *>(_data._mem);
  1179. if (p_index == CoreStringNames::singleton->x) {
  1180. v->normal.x = p_value._data._real;
  1181. valid = true;
  1182. } else if (p_index == CoreStringNames::singleton->y) {
  1183. v->normal.y = p_value._data._real;
  1184. valid = true;
  1185. } else if (p_index == CoreStringNames::singleton->z) {
  1186. v->normal.z = p_value._data._real;
  1187. valid = true;
  1188. } else if (p_index == CoreStringNames::singleton->d) {
  1189. v->d = p_value._data._real;
  1190. valid = true;
  1191. }
  1192. } else if (p_value.type == Variant::VECTOR3) {
  1193. Plane *v = reinterpret_cast<Plane *>(_data._mem);
  1194. if (p_index == CoreStringNames::singleton->normal) {
  1195. v->normal = *reinterpret_cast<const Vector3 *>(p_value._data._mem);
  1196. valid = true;
  1197. }
  1198. }
  1199. } break;
  1200. case QUAT: {
  1201. if (p_value.type == Variant::INT) {
  1202. Quat *v = reinterpret_cast<Quat *>(_data._mem);
  1203. if (p_index == CoreStringNames::singleton->x) {
  1204. v->x = p_value._data._int;
  1205. valid = true;
  1206. } else if (p_index == CoreStringNames::singleton->y) {
  1207. v->y = p_value._data._int;
  1208. valid = true;
  1209. } else if (p_index == CoreStringNames::singleton->z) {
  1210. v->z = p_value._data._int;
  1211. valid = true;
  1212. } else if (p_index == CoreStringNames::singleton->w) {
  1213. v->w = p_value._data._int;
  1214. valid = true;
  1215. }
  1216. } else if (p_value.type == Variant::REAL) {
  1217. Quat *v = reinterpret_cast<Quat *>(_data._mem);
  1218. if (p_index == CoreStringNames::singleton->x) {
  1219. v->x = p_value._data._real;
  1220. valid = true;
  1221. } else if (p_index == CoreStringNames::singleton->y) {
  1222. v->y = p_value._data._real;
  1223. valid = true;
  1224. } else if (p_index == CoreStringNames::singleton->z) {
  1225. v->z = p_value._data._real;
  1226. valid = true;
  1227. } else if (p_index == CoreStringNames::singleton->w) {
  1228. v->w = p_value._data._real;
  1229. valid = true;
  1230. }
  1231. }
  1232. } break; // 10
  1233. case AABB: {
  1234. if (p_value.type == Variant::VECTOR3) {
  1235. ::AABB *v = _data._aabb;
  1236. //scalar name
  1237. if (p_index == CoreStringNames::singleton->position) {
  1238. v->position = *reinterpret_cast<const Vector3 *>(p_value._data._mem);
  1239. valid = true;
  1240. } else if (p_index == CoreStringNames::singleton->size) {
  1241. v->size = *reinterpret_cast<const Vector3 *>(p_value._data._mem);
  1242. valid = true;
  1243. } else if (p_index == CoreStringNames::singleton->end) {
  1244. v->size = *reinterpret_cast<const Vector3 *>(p_value._data._mem) - v->position;
  1245. valid = true;
  1246. }
  1247. }
  1248. } break;
  1249. case BASIS: {
  1250. if (p_value.type == Variant::VECTOR3) {
  1251. Basis *v = _data._basis;
  1252. //scalar name
  1253. if (p_index == CoreStringNames::singleton->x) {
  1254. v->set_axis(0, *reinterpret_cast<const Vector3 *>(p_value._data._mem));
  1255. valid = true;
  1256. } else if (p_index == CoreStringNames::singleton->y) {
  1257. v->set_axis(1, *reinterpret_cast<const Vector3 *>(p_value._data._mem));
  1258. valid = true;
  1259. } else if (p_index == CoreStringNames::singleton->z) {
  1260. v->set_axis(2, *reinterpret_cast<const Vector3 *>(p_value._data._mem));
  1261. valid = true;
  1262. }
  1263. }
  1264. } break;
  1265. case TRANSFORM: {
  1266. if (p_value.type == Variant::BASIS && p_index == CoreStringNames::singleton->basis) {
  1267. _data._transform->basis = *p_value._data._basis;
  1268. valid = true;
  1269. } else if (p_value.type == Variant::VECTOR3 && p_index == CoreStringNames::singleton->origin) {
  1270. _data._transform->origin = *reinterpret_cast<const Vector3 *>(p_value._data._mem);
  1271. valid = true;
  1272. }
  1273. } break;
  1274. case COLOR: {
  1275. if (p_value.type == Variant::INT) {
  1276. Color *v = reinterpret_cast<Color *>(_data._mem);
  1277. if (p_index == CoreStringNames::singleton->r) {
  1278. v->r = p_value._data._int;
  1279. valid = true;
  1280. } else if (p_index == CoreStringNames::singleton->g) {
  1281. v->g = p_value._data._int;
  1282. valid = true;
  1283. } else if (p_index == CoreStringNames::singleton->b) {
  1284. v->b = p_value._data._int;
  1285. valid = true;
  1286. } else if (p_index == CoreStringNames::singleton->a) {
  1287. v->a = p_value._data._int;
  1288. valid = true;
  1289. } else if (p_index == CoreStringNames::singleton->r8) {
  1290. v->r = p_value._data._int / 255.0;
  1291. valid = true;
  1292. } else if (p_index == CoreStringNames::singleton->g8) {
  1293. v->g = p_value._data._int / 255.0;
  1294. valid = true;
  1295. } else if (p_index == CoreStringNames::singleton->b8) {
  1296. v->b = p_value._data._int / 255.0;
  1297. valid = true;
  1298. } else if (p_index == CoreStringNames::singleton->a8) {
  1299. v->a = p_value._data._int / 255.0;
  1300. valid = true;
  1301. } else if (p_index == CoreStringNames::singleton->h) {
  1302. v->set_hsv(p_value._data._int, v->get_s(), v->get_v(), v->a);
  1303. valid = true;
  1304. } else if (p_index == CoreStringNames::singleton->s) {
  1305. v->set_hsv(v->get_h(), p_value._data._int, v->get_v(), v->a);
  1306. valid = true;
  1307. } else if (p_index == CoreStringNames::singleton->v) {
  1308. v->set_hsv(v->get_h(), v->get_v(), p_value._data._int, v->a);
  1309. valid = true;
  1310. }
  1311. } else if (p_value.type == Variant::REAL) {
  1312. Color *v = reinterpret_cast<Color *>(_data._mem);
  1313. if (p_index == CoreStringNames::singleton->r) {
  1314. v->r = p_value._data._real;
  1315. valid = true;
  1316. } else if (p_index == CoreStringNames::singleton->g) {
  1317. v->g = p_value._data._real;
  1318. valid = true;
  1319. } else if (p_index == CoreStringNames::singleton->b) {
  1320. v->b = p_value._data._real;
  1321. valid = true;
  1322. } else if (p_index == CoreStringNames::singleton->a) {
  1323. v->a = p_value._data._real;
  1324. valid = true;
  1325. } else if (p_index == CoreStringNames::singleton->r8) {
  1326. v->r = p_value._data._real / 255.0;
  1327. valid = true;
  1328. } else if (p_index == CoreStringNames::singleton->g8) {
  1329. v->g = p_value._data._real / 255.0;
  1330. valid = true;
  1331. } else if (p_index == CoreStringNames::singleton->b8) {
  1332. v->b = p_value._data._real / 255.0;
  1333. valid = true;
  1334. } else if (p_index == CoreStringNames::singleton->a8) {
  1335. v->a = p_value._data._real / 255.0;
  1336. valid = true;
  1337. } else if (p_index == CoreStringNames::singleton->h) {
  1338. v->set_hsv(p_value._data._real, v->get_s(), v->get_v(), v->a);
  1339. valid = true;
  1340. } else if (p_index == CoreStringNames::singleton->s) {
  1341. v->set_hsv(v->get_h(), p_value._data._real, v->get_v(), v->a);
  1342. valid = true;
  1343. } else if (p_index == CoreStringNames::singleton->v) {
  1344. v->set_hsv(v->get_h(), v->get_s(), p_value._data._real, v->a);
  1345. valid = true;
  1346. }
  1347. }
  1348. } break;
  1349. case OBJECT: {
  1350. Object *obj = _OBJ_PTR(*this);
  1351. #ifdef DEBUG_ENABLED
  1352. if (unlikely(!obj)) {
  1353. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  1354. WARN_PRINT("Attempted set on a deleted object.");
  1355. }
  1356. break;
  1357. }
  1358. #endif
  1359. obj->set(p_index, p_value, &valid);
  1360. } break;
  1361. default: {
  1362. set(p_index.operator String(), p_value, &valid);
  1363. } break;
  1364. }
  1365. if (r_valid) {
  1366. *r_valid = valid;
  1367. }
  1368. }
  1369. Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
  1370. if (r_valid) {
  1371. *r_valid = true;
  1372. }
  1373. switch (type) {
  1374. case VECTOR2: {
  1375. const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
  1376. if (p_index == CoreStringNames::singleton->x) {
  1377. return v->x;
  1378. } else if (p_index == CoreStringNames::singleton->y) {
  1379. return v->y;
  1380. }
  1381. } break;
  1382. case RECT2: {
  1383. const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem);
  1384. //scalar name
  1385. if (p_index == CoreStringNames::singleton->position) {
  1386. return v->position;
  1387. } else if (p_index == CoreStringNames::singleton->size) {
  1388. return v->size;
  1389. } else if (p_index == CoreStringNames::singleton->end) {
  1390. return v->size + v->position;
  1391. }
  1392. } break;
  1393. case TRANSFORM2D: {
  1394. const Transform2D *v = _data._transform2d;
  1395. if (p_index == CoreStringNames::singleton->x) {
  1396. return v->elements[0];
  1397. } else if (p_index == CoreStringNames::singleton->y) {
  1398. return v->elements[1];
  1399. } else if (p_index == CoreStringNames::singleton->origin) {
  1400. return v->elements[2];
  1401. }
  1402. } break;
  1403. case VECTOR3: {
  1404. const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
  1405. if (p_index == CoreStringNames::singleton->x) {
  1406. return v->x;
  1407. } else if (p_index == CoreStringNames::singleton->y) {
  1408. return v->y;
  1409. } else if (p_index == CoreStringNames::singleton->z) {
  1410. return v->z;
  1411. }
  1412. } break;
  1413. case PLANE: {
  1414. const Plane *v = reinterpret_cast<const Plane *>(_data._mem);
  1415. if (p_index == CoreStringNames::singleton->x) {
  1416. return v->normal.x;
  1417. } else if (p_index == CoreStringNames::singleton->y) {
  1418. return v->normal.y;
  1419. } else if (p_index == CoreStringNames::singleton->z) {
  1420. return v->normal.z;
  1421. } else if (p_index == CoreStringNames::singleton->d) {
  1422. return v->d;
  1423. } else if (p_index == CoreStringNames::singleton->normal) {
  1424. return v->normal;
  1425. }
  1426. } break;
  1427. case QUAT: {
  1428. const Quat *v = reinterpret_cast<const Quat *>(_data._mem);
  1429. if (p_index == CoreStringNames::singleton->x) {
  1430. return v->x;
  1431. } else if (p_index == CoreStringNames::singleton->y) {
  1432. return v->y;
  1433. } else if (p_index == CoreStringNames::singleton->z) {
  1434. return v->z;
  1435. } else if (p_index == CoreStringNames::singleton->w) {
  1436. return v->w;
  1437. }
  1438. } break; // 10
  1439. case AABB: {
  1440. const ::AABB *v = _data._aabb;
  1441. //scalar name
  1442. if (p_index == CoreStringNames::singleton->position) {
  1443. return v->position;
  1444. } else if (p_index == CoreStringNames::singleton->size) {
  1445. return v->size;
  1446. } else if (p_index == CoreStringNames::singleton->end) {
  1447. return v->size + v->position;
  1448. }
  1449. } break;
  1450. case BASIS: {
  1451. const Basis *v = _data._basis;
  1452. //scalar name
  1453. if (p_index == CoreStringNames::singleton->x) {
  1454. return v->get_axis(0);
  1455. } else if (p_index == CoreStringNames::singleton->y) {
  1456. return v->get_axis(1);
  1457. } else if (p_index == CoreStringNames::singleton->z) {
  1458. return v->get_axis(2);
  1459. }
  1460. } break;
  1461. case TRANSFORM: {
  1462. if (p_index == CoreStringNames::singleton->basis) {
  1463. return _data._transform->basis;
  1464. } else if (p_index == CoreStringNames::singleton->origin) {
  1465. return _data._transform->origin;
  1466. }
  1467. } break;
  1468. case COLOR: {
  1469. const Color *v = reinterpret_cast<const Color *>(_data._mem);
  1470. if (p_index == CoreStringNames::singleton->r) {
  1471. return v->r;
  1472. } else if (p_index == CoreStringNames::singleton->g) {
  1473. return v->g;
  1474. } else if (p_index == CoreStringNames::singleton->b) {
  1475. return v->b;
  1476. } else if (p_index == CoreStringNames::singleton->a) {
  1477. return v->a;
  1478. } else if (p_index == CoreStringNames::singleton->r8) {
  1479. return int(Math::round(v->r * 255.0));
  1480. } else if (p_index == CoreStringNames::singleton->g8) {
  1481. return int(Math::round(v->g * 255.0));
  1482. } else if (p_index == CoreStringNames::singleton->b8) {
  1483. return int(Math::round(v->b * 255.0));
  1484. } else if (p_index == CoreStringNames::singleton->a8) {
  1485. return int(Math::round(v->a * 255.0));
  1486. } else if (p_index == CoreStringNames::singleton->h) {
  1487. return v->get_h();
  1488. } else if (p_index == CoreStringNames::singleton->s) {
  1489. return v->get_s();
  1490. } else if (p_index == CoreStringNames::singleton->v) {
  1491. return v->get_v();
  1492. }
  1493. } break;
  1494. case OBJECT: {
  1495. Object *obj = _OBJ_PTR(*this);
  1496. #ifdef DEBUG_ENABLED
  1497. if (unlikely(!obj)) {
  1498. if (r_valid)
  1499. *r_valid = false;
  1500. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  1501. WARN_PRINT("Attempted get on a deleted object.");
  1502. }
  1503. return Variant();
  1504. }
  1505. #endif
  1506. return obj->get(p_index, r_valid);
  1507. } break;
  1508. default: {
  1509. return get(p_index.operator String(), r_valid);
  1510. }
  1511. }
  1512. if (r_valid) {
  1513. *r_valid = false;
  1514. }
  1515. return Variant();
  1516. }
  1517. #define DEFAULT_OP_ARRAY_CMD(m_name, m_type, skip_test, cmd) \
  1518. case m_name: { \
  1519. skip_test; \
  1520. \
  1521. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { \
  1522. int index = p_index; \
  1523. m_type *arr = reinterpret_cast<m_type *>(_data._mem); \
  1524. \
  1525. if (index < 0) \
  1526. index += arr->size(); \
  1527. if (index >= 0 && index < arr->size()) { \
  1528. valid = true; \
  1529. cmd; \
  1530. } \
  1531. } \
  1532. } break;
  1533. #define DEFAULT_OP_DVECTOR_SET(m_name, dv_type, skip_cond) \
  1534. DEFAULT_OP_ARRAY_CMD(m_name, PoolVector<dv_type>, if (skip_cond) return;, arr->set(index, p_value); return )
  1535. #define DEFAULT_OP_DVECTOR_GET(m_name, dv_type) \
  1536. DEFAULT_OP_ARRAY_CMD(m_name, const PoolVector<dv_type>, ;, return arr->get(index))
  1537. void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) {
  1538. static bool _dummy = false;
  1539. bool &valid = r_valid ? *r_valid : _dummy;
  1540. valid = false;
  1541. switch (type) {
  1542. case NIL: {
  1543. return;
  1544. } break;
  1545. case BOOL: {
  1546. return;
  1547. } break;
  1548. case INT: {
  1549. return;
  1550. } break;
  1551. case REAL: {
  1552. return;
  1553. } break;
  1554. case STRING: {
  1555. if (p_index.type != Variant::INT && p_index.type != Variant::REAL)
  1556. return;
  1557. int idx = p_index;
  1558. String *str = reinterpret_cast<String *>(_data._mem);
  1559. int len = str->length();
  1560. if (idx < 0)
  1561. idx += len;
  1562. if (idx < 0 || idx >= len)
  1563. return;
  1564. String chr;
  1565. if (p_value.type == Variant::INT || p_value.type == Variant::REAL) {
  1566. chr = String::chr(p_value);
  1567. } else if (p_value.type == Variant::STRING) {
  1568. chr = p_value;
  1569. } else {
  1570. return;
  1571. }
  1572. *str = str->substr(0, idx) + chr + str->substr(idx + 1, len);
  1573. valid = true;
  1574. return;
  1575. } break;
  1576. case VECTOR2: {
  1577. if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
  1578. return;
  1579. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  1580. // scalar index
  1581. int idx = p_index;
  1582. if (idx < 0)
  1583. idx += 2;
  1584. if (idx >= 0 && idx < 2) {
  1585. Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
  1586. valid = true;
  1587. (*v)[idx] = p_value;
  1588. return;
  1589. }
  1590. } else if (p_index.get_type() == Variant::STRING) {
  1591. //scalar name
  1592. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1593. Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
  1594. if (*str == "x") {
  1595. valid = true;
  1596. v->x = p_value;
  1597. return;
  1598. } else if (*str == "y") {
  1599. valid = true;
  1600. v->y = p_value;
  1601. return;
  1602. }
  1603. }
  1604. } break; // 5
  1605. case RECT2: {
  1606. if (p_value.type != Variant::VECTOR2)
  1607. return;
  1608. if (p_index.get_type() == Variant::STRING) {
  1609. //scalar name
  1610. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1611. Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem);
  1612. if (*str == "position") {
  1613. valid = true;
  1614. v->position = p_value;
  1615. return;
  1616. } else if (*str == "size") {
  1617. valid = true;
  1618. v->size = p_value;
  1619. return;
  1620. } else if (*str == "end") {
  1621. valid = true;
  1622. v->size = Vector2(p_value) - v->position;
  1623. return;
  1624. }
  1625. }
  1626. } break;
  1627. case TRANSFORM2D: {
  1628. if (p_value.type != Variant::VECTOR2)
  1629. return;
  1630. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  1631. int index = p_index;
  1632. if (index < 0)
  1633. index += 3;
  1634. if (index >= 0 && index < 3) {
  1635. Transform2D *v = _data._transform2d;
  1636. valid = true;
  1637. v->elements[index] = p_value;
  1638. return;
  1639. }
  1640. } else if (p_index.get_type() == Variant::STRING && p_value.get_type() == Variant::VECTOR2) {
  1641. //scalar name
  1642. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1643. Transform2D *v = _data._transform2d;
  1644. if (*str == "x") {
  1645. valid = true;
  1646. v->elements[0] = p_value;
  1647. return;
  1648. } else if (*str == "y") {
  1649. valid = true;
  1650. v->elements[1] = p_value;
  1651. return;
  1652. } else if (*str == "origin") {
  1653. valid = true;
  1654. v->elements[2] = p_value;
  1655. return;
  1656. }
  1657. }
  1658. } break;
  1659. case VECTOR3: {
  1660. if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
  1661. return;
  1662. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  1663. //scalar index
  1664. int idx = p_index;
  1665. if (idx < 0)
  1666. idx += 3;
  1667. if (idx >= 0 && idx < 3) {
  1668. Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
  1669. valid = true;
  1670. (*v)[idx] = p_value;
  1671. return;
  1672. }
  1673. } else if (p_index.get_type() == Variant::STRING) {
  1674. //scalar name
  1675. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1676. Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
  1677. if (*str == "x") {
  1678. valid = true;
  1679. v->x = p_value;
  1680. return;
  1681. } else if (*str == "y") {
  1682. valid = true;
  1683. v->y = p_value;
  1684. return;
  1685. } else if (*str == "z") {
  1686. valid = true;
  1687. v->z = p_value;
  1688. return;
  1689. }
  1690. }
  1691. } break;
  1692. case PLANE: {
  1693. if (p_index.get_type() == Variant::STRING) {
  1694. //scalar name
  1695. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1696. Plane *v = reinterpret_cast<Plane *>(_data._mem);
  1697. if (*str == "x") {
  1698. if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
  1699. return;
  1700. valid = true;
  1701. v->normal.x = p_value;
  1702. return;
  1703. } else if (*str == "y") {
  1704. if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
  1705. return;
  1706. valid = true;
  1707. v->normal.y = p_value;
  1708. return;
  1709. } else if (*str == "z") {
  1710. if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
  1711. return;
  1712. valid = true;
  1713. v->normal.z = p_value;
  1714. return;
  1715. } else if (*str == "normal") {
  1716. if (p_value.type != Variant::VECTOR3)
  1717. return;
  1718. valid = true;
  1719. v->normal = p_value;
  1720. return;
  1721. } else if (*str == "d") {
  1722. valid = true;
  1723. v->d = p_value;
  1724. return;
  1725. }
  1726. }
  1727. } break;
  1728. case QUAT: {
  1729. if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
  1730. return;
  1731. if (p_index.get_type() == Variant::STRING) {
  1732. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1733. Quat *v = reinterpret_cast<Quat *>(_data._mem);
  1734. if (*str == "x") {
  1735. valid = true;
  1736. v->x = p_value;
  1737. return;
  1738. } else if (*str == "y") {
  1739. valid = true;
  1740. v->y = p_value;
  1741. return;
  1742. } else if (*str == "z") {
  1743. valid = true;
  1744. v->z = p_value;
  1745. return;
  1746. } else if (*str == "w") {
  1747. valid = true;
  1748. v->w = p_value;
  1749. return;
  1750. }
  1751. }
  1752. } break; // 10
  1753. case AABB: {
  1754. if (p_value.type != Variant::VECTOR3)
  1755. return;
  1756. if (p_index.get_type() == Variant::STRING) {
  1757. //scalar name
  1758. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1759. ::AABB *v = _data._aabb;
  1760. if (*str == "position") {
  1761. valid = true;
  1762. v->position = p_value;
  1763. return;
  1764. } else if (*str == "size") {
  1765. valid = true;
  1766. v->size = p_value;
  1767. return;
  1768. } else if (*str == "end") {
  1769. valid = true;
  1770. v->size = Vector3(p_value) - v->position;
  1771. return;
  1772. }
  1773. }
  1774. } break;
  1775. case BASIS: {
  1776. if (p_value.type != Variant::VECTOR3)
  1777. return;
  1778. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  1779. int index = p_index;
  1780. if (index < 0)
  1781. index += 3;
  1782. if (index >= 0 && index < 3) {
  1783. Basis *v = _data._basis;
  1784. valid = true;
  1785. v->set_axis(index, p_value);
  1786. return;
  1787. }
  1788. } else if (p_index.get_type() == Variant::STRING) {
  1789. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1790. Basis *v = _data._basis;
  1791. if (*str == "x") {
  1792. valid = true;
  1793. v->set_axis(0, p_value);
  1794. return;
  1795. } else if (*str == "y") {
  1796. valid = true;
  1797. v->set_axis(1, p_value);
  1798. return;
  1799. } else if (*str == "z") {
  1800. valid = true;
  1801. v->set_axis(2, p_value);
  1802. return;
  1803. }
  1804. }
  1805. } break;
  1806. case TRANSFORM: {
  1807. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  1808. if (p_value.type != Variant::VECTOR3)
  1809. return;
  1810. int index = p_index;
  1811. if (index < 0)
  1812. index += 4;
  1813. if (index >= 0 && index < 4) {
  1814. Transform *v = _data._transform;
  1815. valid = true;
  1816. if (index == 3)
  1817. v->origin = p_value;
  1818. else
  1819. v->basis.set_axis(index, p_value);
  1820. return;
  1821. }
  1822. } else if (p_index.get_type() == Variant::STRING) {
  1823. Transform *v = _data._transform;
  1824. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1825. if (*str == "basis") {
  1826. if (p_value.type != Variant::BASIS)
  1827. return;
  1828. valid = true;
  1829. v->basis = p_value;
  1830. return;
  1831. }
  1832. if (*str == "origin") {
  1833. if (p_value.type != Variant::VECTOR3)
  1834. return;
  1835. valid = true;
  1836. v->origin = p_value;
  1837. return;
  1838. }
  1839. }
  1840. } break;
  1841. case COLOR: {
  1842. if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
  1843. return;
  1844. if (p_index.get_type() == Variant::STRING) {
  1845. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1846. Color *v = reinterpret_cast<Color *>(_data._mem);
  1847. if (*str == "r") {
  1848. valid = true;
  1849. v->r = p_value;
  1850. return;
  1851. } else if (*str == "g") {
  1852. valid = true;
  1853. v->g = p_value;
  1854. return;
  1855. } else if (*str == "b") {
  1856. valid = true;
  1857. v->b = p_value;
  1858. return;
  1859. } else if (*str == "a") {
  1860. valid = true;
  1861. v->a = p_value;
  1862. return;
  1863. } else if (*str == "h") {
  1864. valid = true;
  1865. v->set_hsv(p_value, v->get_s(), v->get_v(), v->a);
  1866. return;
  1867. } else if (*str == "s") {
  1868. valid = true;
  1869. v->set_hsv(v->get_h(), p_value, v->get_v(), v->a);
  1870. return;
  1871. } else if (*str == "v") {
  1872. valid = true;
  1873. v->set_hsv(v->get_h(), v->get_s(), p_value, v->a);
  1874. return;
  1875. } else if (*str == "r8") {
  1876. valid = true;
  1877. v->r = float(p_value) / 255.0;
  1878. return;
  1879. } else if (*str == "g8") {
  1880. valid = true;
  1881. v->g = float(p_value) / 255.0;
  1882. return;
  1883. } else if (*str == "b8") {
  1884. valid = true;
  1885. v->b = float(p_value) / 255.0;
  1886. return;
  1887. } else if (*str == "a8") {
  1888. valid = true;
  1889. v->a = float(p_value) / 255.0;
  1890. return;
  1891. }
  1892. } else if (p_index.get_type() == Variant::INT) {
  1893. int idx = p_index;
  1894. if (idx < 0)
  1895. idx += 4;
  1896. if (idx >= 0 && idx < 4) {
  1897. Color *v = reinterpret_cast<Color *>(_data._mem);
  1898. (*v)[idx] = p_value;
  1899. valid = true;
  1900. }
  1901. }
  1902. } break;
  1903. case NODE_PATH: {
  1904. } break; // 15
  1905. case _RID: {
  1906. } break;
  1907. case OBJECT: {
  1908. Object *obj = _OBJ_PTR(*this);
  1909. if (unlikely(!obj)) {
  1910. #ifdef DEBUG_ENABLED
  1911. valid = false;
  1912. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  1913. WARN_PRINT("Attempted set on a deleted object.");
  1914. }
  1915. #endif
  1916. return;
  1917. }
  1918. if (p_index.get_type() != Variant::STRING) {
  1919. obj->setvar(p_index, p_value, r_valid);
  1920. return;
  1921. }
  1922. obj->set(p_index, p_value, r_valid);
  1923. return;
  1924. } break;
  1925. case DICTIONARY: {
  1926. Dictionary *dic = reinterpret_cast<Dictionary *>(_data._mem);
  1927. dic->operator[](p_index) = p_value;
  1928. valid = true; //always valid, i guess? should this really be ok?
  1929. return;
  1930. } break;
  1931. DEFAULT_OP_ARRAY_CMD(ARRAY, Array, ;, (*arr)[index] = p_value; return ) // 20
  1932. DEFAULT_OP_DVECTOR_SET(POOL_BYTE_ARRAY, uint8_t, p_value.type != Variant::REAL && p_value.type != Variant::INT)
  1933. DEFAULT_OP_DVECTOR_SET(POOL_INT_ARRAY, int, p_value.type != Variant::REAL && p_value.type != Variant::INT)
  1934. DEFAULT_OP_DVECTOR_SET(POOL_REAL_ARRAY, real_t, p_value.type != Variant::REAL && p_value.type != Variant::INT)
  1935. DEFAULT_OP_DVECTOR_SET(POOL_STRING_ARRAY, String, p_value.type != Variant::STRING)
  1936. DEFAULT_OP_DVECTOR_SET(POOL_VECTOR2_ARRAY, Vector2, p_value.type != Variant::VECTOR2) // 25
  1937. DEFAULT_OP_DVECTOR_SET(POOL_VECTOR3_ARRAY, Vector3, p_value.type != Variant::VECTOR3)
  1938. DEFAULT_OP_DVECTOR_SET(POOL_COLOR_ARRAY, Color, p_value.type != Variant::COLOR)
  1939. default:
  1940. return;
  1941. }
  1942. }
  1943. Variant Variant::get(const Variant &p_index, bool *r_valid) const {
  1944. static bool _dummy = false;
  1945. bool &valid = r_valid ? *r_valid : _dummy;
  1946. valid = false;
  1947. switch (type) {
  1948. case NIL: {
  1949. return Variant();
  1950. } break;
  1951. case BOOL: {
  1952. return Variant();
  1953. } break;
  1954. case INT: {
  1955. return Variant();
  1956. } break;
  1957. case REAL: {
  1958. return Variant();
  1959. } break;
  1960. case STRING: {
  1961. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  1962. //string index
  1963. int idx = p_index;
  1964. const String *str = reinterpret_cast<const String *>(_data._mem);
  1965. if (idx < 0)
  1966. idx += str->length();
  1967. if (idx >= 0 && idx < str->length()) {
  1968. valid = true;
  1969. return str->substr(idx, 1);
  1970. }
  1971. }
  1972. } break;
  1973. case VECTOR2: {
  1974. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  1975. // scalar index
  1976. int idx = p_index;
  1977. if (idx < 0)
  1978. idx += 2;
  1979. if (idx >= 0 && idx < 2) {
  1980. const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
  1981. valid = true;
  1982. return (*v)[idx];
  1983. }
  1984. } else if (p_index.get_type() == Variant::STRING) {
  1985. //scalar name
  1986. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  1987. const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
  1988. if (*str == "x") {
  1989. valid = true;
  1990. return v->x;
  1991. } else if (*str == "y") {
  1992. valid = true;
  1993. return v->y;
  1994. }
  1995. }
  1996. } break; // 5
  1997. case RECT2: {
  1998. if (p_index.get_type() == Variant::STRING) {
  1999. //scalar name
  2000. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2001. const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem);
  2002. if (*str == "position") {
  2003. valid = true;
  2004. return v->position;
  2005. } else if (*str == "size") {
  2006. valid = true;
  2007. return v->size;
  2008. } else if (*str == "end") {
  2009. valid = true;
  2010. return v->size + v->position;
  2011. }
  2012. }
  2013. } break;
  2014. case VECTOR3: {
  2015. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  2016. //scalar index
  2017. int idx = p_index;
  2018. if (idx < 0)
  2019. idx += 3;
  2020. if (idx >= 0 && idx < 3) {
  2021. const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
  2022. valid = true;
  2023. return (*v)[idx];
  2024. }
  2025. } else if (p_index.get_type() == Variant::STRING) {
  2026. //scalar name
  2027. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2028. const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
  2029. if (*str == "x") {
  2030. valid = true;
  2031. return v->x;
  2032. } else if (*str == "y") {
  2033. valid = true;
  2034. return v->y;
  2035. } else if (*str == "z") {
  2036. valid = true;
  2037. return v->z;
  2038. }
  2039. }
  2040. } break;
  2041. case TRANSFORM2D: {
  2042. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  2043. int index = p_index;
  2044. if (index < 0)
  2045. index += 3;
  2046. if (index >= 0 && index < 3) {
  2047. const Transform2D *v = _data._transform2d;
  2048. valid = true;
  2049. return v->elements[index];
  2050. }
  2051. } else if (p_index.get_type() == Variant::STRING) {
  2052. //scalar name
  2053. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2054. const Transform2D *v = _data._transform2d;
  2055. if (*str == "x") {
  2056. valid = true;
  2057. return v->elements[0];
  2058. } else if (*str == "y") {
  2059. valid = true;
  2060. return v->elements[1];
  2061. } else if (*str == "origin") {
  2062. valid = true;
  2063. return v->elements[2];
  2064. }
  2065. }
  2066. } break;
  2067. case PLANE: {
  2068. if (p_index.get_type() == Variant::STRING) {
  2069. //scalar name
  2070. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2071. const Plane *v = reinterpret_cast<const Plane *>(_data._mem);
  2072. if (*str == "x") {
  2073. valid = true;
  2074. return v->normal.x;
  2075. } else if (*str == "y") {
  2076. valid = true;
  2077. return v->normal.y;
  2078. } else if (*str == "z") {
  2079. valid = true;
  2080. return v->normal.z;
  2081. } else if (*str == "normal") {
  2082. valid = true;
  2083. return v->normal;
  2084. } else if (*str == "d") {
  2085. valid = true;
  2086. return v->d;
  2087. }
  2088. }
  2089. } break;
  2090. case QUAT: {
  2091. if (p_index.get_type() == Variant::STRING) {
  2092. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2093. const Quat *v = reinterpret_cast<const Quat *>(_data._mem);
  2094. if (*str == "x") {
  2095. valid = true;
  2096. return v->x;
  2097. } else if (*str == "y") {
  2098. valid = true;
  2099. return v->y;
  2100. } else if (*str == "z") {
  2101. valid = true;
  2102. return v->z;
  2103. } else if (*str == "w") {
  2104. valid = true;
  2105. return v->w;
  2106. }
  2107. }
  2108. } break; // 10
  2109. case AABB: {
  2110. if (p_index.get_type() == Variant::STRING) {
  2111. //scalar name
  2112. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2113. const ::AABB *v = _data._aabb;
  2114. if (*str == "position") {
  2115. valid = true;
  2116. return v->position;
  2117. } else if (*str == "size") {
  2118. valid = true;
  2119. return v->size;
  2120. } else if (*str == "end") {
  2121. valid = true;
  2122. return v->size + v->position;
  2123. }
  2124. }
  2125. } break;
  2126. case BASIS: {
  2127. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  2128. int index = p_index;
  2129. if (index < 0)
  2130. index += 3;
  2131. if (index >= 0 && index < 3) {
  2132. const Basis *v = _data._basis;
  2133. valid = true;
  2134. return v->get_axis(index);
  2135. }
  2136. } else if (p_index.get_type() == Variant::STRING) {
  2137. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2138. const Basis *v = _data._basis;
  2139. if (*str == "x") {
  2140. valid = true;
  2141. return v->get_axis(0);
  2142. } else if (*str == "y") {
  2143. valid = true;
  2144. return v->get_axis(1);
  2145. } else if (*str == "z") {
  2146. valid = true;
  2147. return v->get_axis(2);
  2148. }
  2149. }
  2150. } break;
  2151. case TRANSFORM: {
  2152. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  2153. int index = p_index;
  2154. if (index < 0)
  2155. index += 4;
  2156. if (index >= 0 && index < 4) {
  2157. const Transform *v = _data._transform;
  2158. valid = true;
  2159. return index == 3 ? v->origin : v->basis.get_axis(index);
  2160. }
  2161. } else if (p_index.get_type() == Variant::STRING) {
  2162. const Transform *v = _data._transform;
  2163. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2164. if (*str == "basis") {
  2165. valid = true;
  2166. return v->basis;
  2167. }
  2168. if (*str == "origin") {
  2169. valid = true;
  2170. return v->origin;
  2171. }
  2172. }
  2173. } break;
  2174. case COLOR: {
  2175. if (p_index.get_type() == Variant::STRING) {
  2176. const String *str = reinterpret_cast<const String *>(p_index._data._mem);
  2177. const Color *v = reinterpret_cast<const Color *>(_data._mem);
  2178. if (*str == "r") {
  2179. valid = true;
  2180. return v->r;
  2181. } else if (*str == "g") {
  2182. valid = true;
  2183. return v->g;
  2184. } else if (*str == "b") {
  2185. valid = true;
  2186. return v->b;
  2187. } else if (*str == "a") {
  2188. valid = true;
  2189. return v->a;
  2190. } else if (*str == "h") {
  2191. valid = true;
  2192. return v->get_h();
  2193. } else if (*str == "s") {
  2194. valid = true;
  2195. return v->get_s();
  2196. } else if (*str == "v") {
  2197. valid = true;
  2198. return v->get_v();
  2199. } else if (*str == "r8") {
  2200. valid = true;
  2201. return (int)Math::round(v->r * 255.0);
  2202. } else if (*str == "g8") {
  2203. valid = true;
  2204. return (int)Math::round(v->g * 255.0);
  2205. } else if (*str == "b8") {
  2206. valid = true;
  2207. return (int)Math::round(v->b * 255.0);
  2208. } else if (*str == "a8") {
  2209. valid = true;
  2210. return (int)Math::round(v->a * 255.0);
  2211. }
  2212. } else if (p_index.get_type() == Variant::INT) {
  2213. int idx = p_index;
  2214. if (idx < 0)
  2215. idx += 4;
  2216. if (idx >= 0 && idx < 4) {
  2217. const Color *v = reinterpret_cast<const Color *>(_data._mem);
  2218. valid = true;
  2219. return (*v)[idx];
  2220. }
  2221. }
  2222. } break;
  2223. case NODE_PATH: {
  2224. } break; // 15
  2225. case _RID: {
  2226. } break;
  2227. case OBJECT: {
  2228. Object *obj = _OBJ_PTR(*this);
  2229. if (unlikely(!obj)) {
  2230. #ifdef DEBUG_ENABLED
  2231. valid = false;
  2232. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  2233. WARN_PRINT("Attempted get on a deleted object.");
  2234. }
  2235. #endif
  2236. return Variant();
  2237. }
  2238. if (p_index.get_type() != Variant::STRING) {
  2239. return obj->getvar(p_index, r_valid);
  2240. } else {
  2241. return obj->get(p_index, r_valid);
  2242. }
  2243. } break;
  2244. case DICTIONARY: {
  2245. const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
  2246. const Variant *res = dic->getptr(p_index);
  2247. if (res) {
  2248. valid = true;
  2249. return *res;
  2250. }
  2251. } break;
  2252. DEFAULT_OP_ARRAY_CMD(ARRAY, const Array, ;, return (*arr)[index]) // 20
  2253. DEFAULT_OP_DVECTOR_GET(POOL_BYTE_ARRAY, uint8_t)
  2254. DEFAULT_OP_DVECTOR_GET(POOL_INT_ARRAY, int)
  2255. DEFAULT_OP_DVECTOR_GET(POOL_REAL_ARRAY, real_t)
  2256. DEFAULT_OP_DVECTOR_GET(POOL_STRING_ARRAY, String)
  2257. DEFAULT_OP_DVECTOR_GET(POOL_VECTOR2_ARRAY, Vector2) // 25
  2258. DEFAULT_OP_DVECTOR_GET(POOL_VECTOR3_ARRAY, Vector3)
  2259. DEFAULT_OP_DVECTOR_GET(POOL_COLOR_ARRAY, Color)
  2260. default:
  2261. return Variant();
  2262. }
  2263. return Variant();
  2264. }
  2265. bool Variant::in(const Variant &p_index, bool *r_valid) const {
  2266. if (r_valid)
  2267. *r_valid = true;
  2268. switch (type) {
  2269. case STRING: {
  2270. if (p_index.get_type() == Variant::STRING) {
  2271. //string index
  2272. String idx = p_index;
  2273. const String *str = reinterpret_cast<const String *>(_data._mem);
  2274. return str->find(idx) != -1;
  2275. }
  2276. } break;
  2277. case OBJECT: {
  2278. Object *obj = _OBJ_PTR(*this);
  2279. if (unlikely(!obj)) {
  2280. #ifdef DEBUG_ENABLED
  2281. if (r_valid) {
  2282. *r_valid = false;
  2283. }
  2284. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  2285. WARN_PRINT("Attempted 'in' on a deleted object.");
  2286. }
  2287. #endif
  2288. return false;
  2289. }
  2290. bool result;
  2291. if (p_index.get_type() != Variant::STRING) {
  2292. obj->getvar(p_index, &result);
  2293. } else {
  2294. obj->get(p_index, &result);
  2295. }
  2296. return result;
  2297. } break;
  2298. case DICTIONARY: {
  2299. const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
  2300. return dic->has(p_index);
  2301. } break; // 20
  2302. case ARRAY: {
  2303. const Array *arr = reinterpret_cast<const Array *>(_data._mem);
  2304. int l = arr->size();
  2305. if (l) {
  2306. for (int i = 0; i < l; i++) {
  2307. if (evaluate(OP_EQUAL, (*arr)[i], p_index))
  2308. return true;
  2309. }
  2310. }
  2311. return false;
  2312. } break;
  2313. case POOL_BYTE_ARRAY: {
  2314. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  2315. int index = p_index;
  2316. const PoolVector<uint8_t> *arr = reinterpret_cast<const PoolVector<uint8_t> *>(_data._mem);
  2317. int l = arr->size();
  2318. if (l) {
  2319. PoolVector<uint8_t>::Read r = arr->read();
  2320. for (int i = 0; i < l; i++) {
  2321. if (r[i] == index)
  2322. return true;
  2323. }
  2324. }
  2325. return false;
  2326. }
  2327. } break;
  2328. case POOL_INT_ARRAY: {
  2329. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  2330. int index = p_index;
  2331. const PoolVector<int> *arr = reinterpret_cast<const PoolVector<int> *>(_data._mem);
  2332. int l = arr->size();
  2333. if (l) {
  2334. PoolVector<int>::Read r = arr->read();
  2335. for (int i = 0; i < l; i++) {
  2336. if (r[i] == index)
  2337. return true;
  2338. }
  2339. }
  2340. return false;
  2341. }
  2342. } break;
  2343. case POOL_REAL_ARRAY: {
  2344. if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
  2345. real_t index = p_index;
  2346. const PoolVector<real_t> *arr = reinterpret_cast<const PoolVector<real_t> *>(_data._mem);
  2347. int l = arr->size();
  2348. if (l) {
  2349. PoolVector<real_t>::Read r = arr->read();
  2350. for (int i = 0; i < l; i++) {
  2351. if (r[i] == index)
  2352. return true;
  2353. }
  2354. }
  2355. return false;
  2356. }
  2357. } break;
  2358. case POOL_STRING_ARRAY: {
  2359. if (p_index.get_type() == Variant::STRING) {
  2360. String index = p_index;
  2361. const PoolVector<String> *arr = reinterpret_cast<const PoolVector<String> *>(_data._mem);
  2362. int l = arr->size();
  2363. if (l) {
  2364. PoolVector<String>::Read r = arr->read();
  2365. for (int i = 0; i < l; i++) {
  2366. if (r[i] == index)
  2367. return true;
  2368. }
  2369. }
  2370. return false;
  2371. }
  2372. } break; //25
  2373. case POOL_VECTOR2_ARRAY: {
  2374. if (p_index.get_type() == Variant::VECTOR2) {
  2375. Vector2 index = p_index;
  2376. const PoolVector<Vector2> *arr = reinterpret_cast<const PoolVector<Vector2> *>(_data._mem);
  2377. int l = arr->size();
  2378. if (l) {
  2379. PoolVector<Vector2>::Read r = arr->read();
  2380. for (int i = 0; i < l; i++) {
  2381. if (r[i] == index)
  2382. return true;
  2383. }
  2384. }
  2385. return false;
  2386. }
  2387. } break;
  2388. case POOL_VECTOR3_ARRAY: {
  2389. if (p_index.get_type() == Variant::VECTOR3) {
  2390. Vector3 index = p_index;
  2391. const PoolVector<Vector3> *arr = reinterpret_cast<const PoolVector<Vector3> *>(_data._mem);
  2392. int l = arr->size();
  2393. if (l) {
  2394. PoolVector<Vector3>::Read r = arr->read();
  2395. for (int i = 0; i < l; i++) {
  2396. if (r[i] == index)
  2397. return true;
  2398. }
  2399. }
  2400. return false;
  2401. }
  2402. } break;
  2403. case POOL_COLOR_ARRAY: {
  2404. if (p_index.get_type() == Variant::COLOR) {
  2405. Color index = p_index;
  2406. const PoolVector<Color> *arr = reinterpret_cast<const PoolVector<Color> *>(_data._mem);
  2407. int l = arr->size();
  2408. if (l) {
  2409. PoolVector<Color>::Read r = arr->read();
  2410. for (int i = 0; i < l; i++) {
  2411. if (r[i] == index)
  2412. return true;
  2413. }
  2414. }
  2415. return false;
  2416. }
  2417. } break;
  2418. default: {
  2419. }
  2420. }
  2421. if (r_valid)
  2422. *r_valid = false;
  2423. return false;
  2424. }
  2425. void Variant::get_property_list(List<PropertyInfo> *p_list) const {
  2426. switch (type) {
  2427. case VECTOR2: {
  2428. p_list->push_back(PropertyInfo(Variant::REAL, "x"));
  2429. p_list->push_back(PropertyInfo(Variant::REAL, "y"));
  2430. } break; // 5
  2431. case RECT2: {
  2432. p_list->push_back(PropertyInfo(Variant::VECTOR2, "position"));
  2433. p_list->push_back(PropertyInfo(Variant::VECTOR2, "size"));
  2434. p_list->push_back(PropertyInfo(Variant::VECTOR2, "end"));
  2435. } break;
  2436. case VECTOR3: {
  2437. p_list->push_back(PropertyInfo(Variant::REAL, "x"));
  2438. p_list->push_back(PropertyInfo(Variant::REAL, "y"));
  2439. p_list->push_back(PropertyInfo(Variant::REAL, "z"));
  2440. } break;
  2441. case TRANSFORM2D: {
  2442. p_list->push_back(PropertyInfo(Variant::VECTOR2, "x"));
  2443. p_list->push_back(PropertyInfo(Variant::VECTOR2, "y"));
  2444. p_list->push_back(PropertyInfo(Variant::VECTOR2, "origin"));
  2445. } break;
  2446. case PLANE: {
  2447. p_list->push_back(PropertyInfo(Variant::VECTOR3, "normal"));
  2448. p_list->push_back(PropertyInfo(Variant::REAL, "x"));
  2449. p_list->push_back(PropertyInfo(Variant::REAL, "y"));
  2450. p_list->push_back(PropertyInfo(Variant::REAL, "z"));
  2451. p_list->push_back(PropertyInfo(Variant::REAL, "d"));
  2452. } break;
  2453. case QUAT: {
  2454. p_list->push_back(PropertyInfo(Variant::REAL, "x"));
  2455. p_list->push_back(PropertyInfo(Variant::REAL, "y"));
  2456. p_list->push_back(PropertyInfo(Variant::REAL, "z"));
  2457. p_list->push_back(PropertyInfo(Variant::REAL, "w"));
  2458. } break; // 10
  2459. case AABB: {
  2460. p_list->push_back(PropertyInfo(Variant::VECTOR3, "position"));
  2461. p_list->push_back(PropertyInfo(Variant::VECTOR3, "size"));
  2462. p_list->push_back(PropertyInfo(Variant::VECTOR3, "end"));
  2463. } break;
  2464. case BASIS: {
  2465. p_list->push_back(PropertyInfo(Variant::VECTOR3, "x"));
  2466. p_list->push_back(PropertyInfo(Variant::VECTOR3, "y"));
  2467. p_list->push_back(PropertyInfo(Variant::VECTOR3, "z"));
  2468. } break;
  2469. case TRANSFORM: {
  2470. p_list->push_back(PropertyInfo(Variant::BASIS, "basis"));
  2471. p_list->push_back(PropertyInfo(Variant::VECTOR3, "origin"));
  2472. } break;
  2473. case COLOR: {
  2474. p_list->push_back(PropertyInfo(Variant::REAL, "r"));
  2475. p_list->push_back(PropertyInfo(Variant::REAL, "g"));
  2476. p_list->push_back(PropertyInfo(Variant::REAL, "b"));
  2477. p_list->push_back(PropertyInfo(Variant::REAL, "a"));
  2478. p_list->push_back(PropertyInfo(Variant::REAL, "h"));
  2479. p_list->push_back(PropertyInfo(Variant::REAL, "s"));
  2480. p_list->push_back(PropertyInfo(Variant::REAL, "v"));
  2481. p_list->push_back(PropertyInfo(Variant::INT, "r8"));
  2482. p_list->push_back(PropertyInfo(Variant::INT, "g8"));
  2483. p_list->push_back(PropertyInfo(Variant::INT, "b8"));
  2484. p_list->push_back(PropertyInfo(Variant::INT, "a8"));
  2485. } break;
  2486. case NODE_PATH: {
  2487. } break; // 15
  2488. case _RID: {
  2489. } break;
  2490. case OBJECT: {
  2491. Object *obj = _OBJ_PTR(*this);
  2492. if (unlikely(!obj)) {
  2493. #ifdef DEBUG_ENABLED
  2494. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  2495. WARN_PRINT("Attempted get property list on a deleted object.");
  2496. }
  2497. #endif
  2498. return;
  2499. }
  2500. obj->get_property_list(p_list);
  2501. } break;
  2502. case DICTIONARY: {
  2503. const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
  2504. List<Variant> keys;
  2505. dic->get_key_list(&keys);
  2506. for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
  2507. if (E->get().get_type() == Variant::STRING) {
  2508. p_list->push_back(PropertyInfo(Variant::STRING, E->get()));
  2509. }
  2510. }
  2511. } break;
  2512. case ARRAY: // 20
  2513. case POOL_BYTE_ARRAY:
  2514. case POOL_INT_ARRAY:
  2515. case POOL_REAL_ARRAY:
  2516. case POOL_STRING_ARRAY:
  2517. case POOL_VECTOR2_ARRAY: // 25
  2518. case POOL_VECTOR3_ARRAY:
  2519. case POOL_COLOR_ARRAY: {
  2520. //nothing
  2521. } break;
  2522. default: {
  2523. }
  2524. }
  2525. }
  2526. bool Variant::iter_init(Variant &r_iter, bool &valid) const {
  2527. valid = true;
  2528. switch (type) {
  2529. case INT: {
  2530. r_iter = 0;
  2531. return _data._int > 0;
  2532. } break;
  2533. case REAL: {
  2534. r_iter = 0;
  2535. return _data._real > 0.0;
  2536. } break;
  2537. case VECTOR2: {
  2538. int64_t from = reinterpret_cast<const Vector2 *>(_data._mem)->x;
  2539. int64_t to = reinterpret_cast<const Vector2 *>(_data._mem)->y;
  2540. r_iter = from;
  2541. return from < to;
  2542. } break;
  2543. case VECTOR3: {
  2544. int64_t from = reinterpret_cast<const Vector3 *>(_data._mem)->x;
  2545. int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
  2546. int64_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
  2547. r_iter = from;
  2548. if (from == to) {
  2549. return false;
  2550. } else if (from < to) {
  2551. return step > 0;
  2552. } else {
  2553. return step < 0;
  2554. }
  2555. //return true;
  2556. } break;
  2557. case OBJECT: {
  2558. Object *obj = _OBJ_PTR(*this);
  2559. #ifdef DEBUG_ENABLED
  2560. if (unlikely(!obj)) {
  2561. valid = false;
  2562. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  2563. WARN_PRINT("Attempted iteration start on a deleted object.");
  2564. }
  2565. return false;
  2566. }
  2567. #endif
  2568. Variant::CallError ce;
  2569. ce.error = Variant::CallError::CALL_OK;
  2570. Array ref;
  2571. ref.push_back(r_iter);
  2572. Variant vref = ref;
  2573. const Variant *refp[] = { &vref };
  2574. Variant ret = obj->call(CoreStringNames::get_singleton()->_iter_init, refp, 1, ce);
  2575. if (ref.size() != 1 || ce.error != Variant::CallError::CALL_OK) {
  2576. valid = false;
  2577. return false;
  2578. }
  2579. r_iter = ref[0];
  2580. return ret;
  2581. } break;
  2582. case STRING: {
  2583. const String *str = reinterpret_cast<const String *>(_data._mem);
  2584. if (str->empty())
  2585. return false;
  2586. r_iter = 0;
  2587. return true;
  2588. } break;
  2589. case DICTIONARY: {
  2590. const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
  2591. if (dic->empty())
  2592. return false;
  2593. const Variant *next = dic->next(NULL);
  2594. r_iter = *next;
  2595. return true;
  2596. } break;
  2597. case ARRAY: {
  2598. const Array *arr = reinterpret_cast<const Array *>(_data._mem);
  2599. if (arr->empty())
  2600. return false;
  2601. r_iter = 0;
  2602. return true;
  2603. } break;
  2604. case POOL_BYTE_ARRAY: {
  2605. const PoolVector<uint8_t> *arr = reinterpret_cast<const PoolVector<uint8_t> *>(_data._mem);
  2606. if (arr->size() == 0)
  2607. return false;
  2608. r_iter = 0;
  2609. return true;
  2610. } break;
  2611. case POOL_INT_ARRAY: {
  2612. const PoolVector<int> *arr = reinterpret_cast<const PoolVector<int> *>(_data._mem);
  2613. if (arr->size() == 0)
  2614. return false;
  2615. r_iter = 0;
  2616. return true;
  2617. } break;
  2618. case POOL_REAL_ARRAY: {
  2619. const PoolVector<real_t> *arr = reinterpret_cast<const PoolVector<real_t> *>(_data._mem);
  2620. if (arr->size() == 0)
  2621. return false;
  2622. r_iter = 0;
  2623. return true;
  2624. } break;
  2625. case POOL_STRING_ARRAY: {
  2626. const PoolVector<String> *arr = reinterpret_cast<const PoolVector<String> *>(_data._mem);
  2627. if (arr->size() == 0)
  2628. return false;
  2629. r_iter = 0;
  2630. return true;
  2631. } break;
  2632. case POOL_VECTOR2_ARRAY: {
  2633. const PoolVector<Vector2> *arr = reinterpret_cast<const PoolVector<Vector2> *>(_data._mem);
  2634. if (arr->size() == 0)
  2635. return false;
  2636. r_iter = 0;
  2637. return true;
  2638. } break;
  2639. case POOL_VECTOR3_ARRAY: {
  2640. const PoolVector<Vector3> *arr = reinterpret_cast<const PoolVector<Vector3> *>(_data._mem);
  2641. if (arr->size() == 0)
  2642. return false;
  2643. r_iter = 0;
  2644. return true;
  2645. } break;
  2646. case POOL_COLOR_ARRAY: {
  2647. const PoolVector<Color> *arr = reinterpret_cast<const PoolVector<Color> *>(_data._mem);
  2648. if (arr->size() == 0)
  2649. return false;
  2650. r_iter = 0;
  2651. return true;
  2652. } break;
  2653. default: {
  2654. }
  2655. }
  2656. valid = false;
  2657. return false;
  2658. }
  2659. bool Variant::iter_next(Variant &r_iter, bool &valid) const {
  2660. valid = true;
  2661. switch (type) {
  2662. case INT: {
  2663. int64_t idx = r_iter;
  2664. idx++;
  2665. if (idx >= _data._int)
  2666. return false;
  2667. r_iter = idx;
  2668. return true;
  2669. } break;
  2670. case REAL: {
  2671. int64_t idx = r_iter;
  2672. idx++;
  2673. if (idx >= _data._real)
  2674. return false;
  2675. r_iter = idx;
  2676. return true;
  2677. } break;
  2678. case VECTOR2: {
  2679. int64_t to = reinterpret_cast<const Vector2 *>(_data._mem)->y;
  2680. int64_t idx = r_iter;
  2681. idx++;
  2682. if (idx >= to)
  2683. return false;
  2684. r_iter = idx;
  2685. return true;
  2686. } break;
  2687. case VECTOR3: {
  2688. int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
  2689. int64_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
  2690. int64_t idx = r_iter;
  2691. idx += step;
  2692. if (step < 0 && idx <= to)
  2693. return false;
  2694. if (step > 0 && idx >= to)
  2695. return false;
  2696. r_iter = idx;
  2697. return true;
  2698. } break;
  2699. case OBJECT: {
  2700. Object *obj = _OBJ_PTR(*this);
  2701. #ifdef DEBUG_ENABLED
  2702. if (unlikely(!obj)) {
  2703. valid = false;
  2704. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  2705. WARN_PRINT("Attempted iteration check next on a deleted object.");
  2706. }
  2707. return false;
  2708. }
  2709. #endif
  2710. Variant::CallError ce;
  2711. ce.error = Variant::CallError::CALL_OK;
  2712. Array ref;
  2713. ref.push_back(r_iter);
  2714. Variant vref = ref;
  2715. const Variant *refp[] = { &vref };
  2716. Variant ret = obj->call(CoreStringNames::get_singleton()->_iter_next, refp, 1, ce);
  2717. if (ref.size() != 1 || ce.error != Variant::CallError::CALL_OK) {
  2718. valid = false;
  2719. return false;
  2720. }
  2721. r_iter = ref[0];
  2722. return ret;
  2723. } break;
  2724. case STRING: {
  2725. const String *str = reinterpret_cast<const String *>(_data._mem);
  2726. int idx = r_iter;
  2727. idx++;
  2728. if (idx >= str->length())
  2729. return false;
  2730. r_iter = idx;
  2731. return true;
  2732. } break;
  2733. case DICTIONARY: {
  2734. const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
  2735. const Variant *next = dic->next(&r_iter);
  2736. if (!next)
  2737. return false;
  2738. r_iter = *next;
  2739. return true;
  2740. } break;
  2741. case ARRAY: {
  2742. const Array *arr = reinterpret_cast<const Array *>(_data._mem);
  2743. int idx = r_iter;
  2744. idx++;
  2745. if (idx >= arr->size())
  2746. return false;
  2747. r_iter = idx;
  2748. return true;
  2749. } break;
  2750. case POOL_BYTE_ARRAY: {
  2751. const PoolVector<uint8_t> *arr = reinterpret_cast<const PoolVector<uint8_t> *>(_data._mem);
  2752. int idx = r_iter;
  2753. idx++;
  2754. if (idx >= arr->size())
  2755. return false;
  2756. r_iter = idx;
  2757. return true;
  2758. } break;
  2759. case POOL_INT_ARRAY: {
  2760. const PoolVector<int> *arr = reinterpret_cast<const PoolVector<int> *>(_data._mem);
  2761. int idx = r_iter;
  2762. idx++;
  2763. if (idx >= arr->size())
  2764. return false;
  2765. r_iter = idx;
  2766. return true;
  2767. } break;
  2768. case POOL_REAL_ARRAY: {
  2769. const PoolVector<real_t> *arr = reinterpret_cast<const PoolVector<real_t> *>(_data._mem);
  2770. int idx = r_iter;
  2771. idx++;
  2772. if (idx >= arr->size())
  2773. return false;
  2774. r_iter = idx;
  2775. return true;
  2776. } break;
  2777. case POOL_STRING_ARRAY: {
  2778. const PoolVector<String> *arr = reinterpret_cast<const PoolVector<String> *>(_data._mem);
  2779. int idx = r_iter;
  2780. idx++;
  2781. if (idx >= arr->size())
  2782. return false;
  2783. r_iter = idx;
  2784. return true;
  2785. } break;
  2786. case POOL_VECTOR2_ARRAY: {
  2787. const PoolVector<Vector2> *arr = reinterpret_cast<const PoolVector<Vector2> *>(_data._mem);
  2788. int idx = r_iter;
  2789. idx++;
  2790. if (idx >= arr->size())
  2791. return false;
  2792. r_iter = idx;
  2793. return true;
  2794. } break;
  2795. case POOL_VECTOR3_ARRAY: {
  2796. const PoolVector<Vector3> *arr = reinterpret_cast<const PoolVector<Vector3> *>(_data._mem);
  2797. int idx = r_iter;
  2798. idx++;
  2799. if (idx >= arr->size())
  2800. return false;
  2801. r_iter = idx;
  2802. return true;
  2803. } break;
  2804. case POOL_COLOR_ARRAY: {
  2805. const PoolVector<Color> *arr = reinterpret_cast<const PoolVector<Color> *>(_data._mem);
  2806. int idx = r_iter;
  2807. idx++;
  2808. if (idx >= arr->size())
  2809. return false;
  2810. r_iter = idx;
  2811. return true;
  2812. } break;
  2813. default: {
  2814. }
  2815. }
  2816. valid = false;
  2817. return false;
  2818. }
  2819. Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
  2820. r_valid = true;
  2821. switch (type) {
  2822. case INT: {
  2823. return r_iter;
  2824. } break;
  2825. case REAL: {
  2826. return r_iter;
  2827. } break;
  2828. case VECTOR2: {
  2829. return r_iter;
  2830. } break;
  2831. case VECTOR3: {
  2832. return r_iter;
  2833. } break;
  2834. case OBJECT: {
  2835. Object *obj = _OBJ_PTR(*this);
  2836. #ifdef DEBUG_ENABLED
  2837. if (unlikely(!obj)) {
  2838. r_valid = false;
  2839. if (ScriptDebugger::get_singleton() && _get_obj().rc && !ObjectDB::get_instance(_get_obj().rc->instance_id)) {
  2840. WARN_PRINT("Attempted iteration get next on a deleted object.");
  2841. }
  2842. return Variant();
  2843. }
  2844. #endif
  2845. Variant::CallError ce;
  2846. ce.error = Variant::CallError::CALL_OK;
  2847. const Variant *refp[] = { &r_iter };
  2848. Variant ret = obj->call(CoreStringNames::get_singleton()->_iter_get, refp, 1, ce);
  2849. if (ce.error != Variant::CallError::CALL_OK) {
  2850. r_valid = false;
  2851. return Variant();
  2852. }
  2853. //r_iter=ref[0];
  2854. return ret;
  2855. } break;
  2856. case STRING: {
  2857. const String *str = reinterpret_cast<const String *>(_data._mem);
  2858. return str->substr(r_iter, 1);
  2859. } break;
  2860. case DICTIONARY: {
  2861. return r_iter; //iterator is the same as the key
  2862. } break;
  2863. case ARRAY: {
  2864. const Array *arr = reinterpret_cast<const Array *>(_data._mem);
  2865. int idx = r_iter;
  2866. #ifdef DEBUG_ENABLED
  2867. if (idx < 0 || idx >= arr->size()) {
  2868. r_valid = false;
  2869. return Variant();
  2870. }
  2871. #endif
  2872. return arr->get(idx);
  2873. } break;
  2874. case POOL_BYTE_ARRAY: {
  2875. const PoolVector<uint8_t> *arr = reinterpret_cast<const PoolVector<uint8_t> *>(_data._mem);
  2876. int idx = r_iter;
  2877. #ifdef DEBUG_ENABLED
  2878. if (idx < 0 || idx >= arr->size()) {
  2879. r_valid = false;
  2880. return Variant();
  2881. }
  2882. #endif
  2883. return arr->get(idx);
  2884. } break;
  2885. case POOL_INT_ARRAY: {
  2886. const PoolVector<int> *arr = reinterpret_cast<const PoolVector<int> *>(_data._mem);
  2887. int idx = r_iter;
  2888. #ifdef DEBUG_ENABLED
  2889. if (idx < 0 || idx >= arr->size()) {
  2890. r_valid = false;
  2891. return Variant();
  2892. }
  2893. #endif
  2894. return arr->get(idx);
  2895. } break;
  2896. case POOL_REAL_ARRAY: {
  2897. const PoolVector<real_t> *arr = reinterpret_cast<const PoolVector<real_t> *>(_data._mem);
  2898. int idx = r_iter;
  2899. #ifdef DEBUG_ENABLED
  2900. if (idx < 0 || idx >= arr->size()) {
  2901. r_valid = false;
  2902. return Variant();
  2903. }
  2904. #endif
  2905. return arr->get(idx);
  2906. } break;
  2907. case POOL_STRING_ARRAY: {
  2908. const PoolVector<String> *arr = reinterpret_cast<const PoolVector<String> *>(_data._mem);
  2909. int idx = r_iter;
  2910. #ifdef DEBUG_ENABLED
  2911. if (idx < 0 || idx >= arr->size()) {
  2912. r_valid = false;
  2913. return Variant();
  2914. }
  2915. #endif
  2916. return arr->get(idx);
  2917. } break;
  2918. case POOL_VECTOR2_ARRAY: {
  2919. const PoolVector<Vector2> *arr = reinterpret_cast<const PoolVector<Vector2> *>(_data._mem);
  2920. int idx = r_iter;
  2921. #ifdef DEBUG_ENABLED
  2922. if (idx < 0 || idx >= arr->size()) {
  2923. r_valid = false;
  2924. return Variant();
  2925. }
  2926. #endif
  2927. return arr->get(idx);
  2928. } break;
  2929. case POOL_VECTOR3_ARRAY: {
  2930. const PoolVector<Vector3> *arr = reinterpret_cast<const PoolVector<Vector3> *>(_data._mem);
  2931. int idx = r_iter;
  2932. #ifdef DEBUG_ENABLED
  2933. if (idx < 0 || idx >= arr->size()) {
  2934. r_valid = false;
  2935. return Variant();
  2936. }
  2937. #endif
  2938. return arr->get(idx);
  2939. } break;
  2940. case POOL_COLOR_ARRAY: {
  2941. const PoolVector<Color> *arr = reinterpret_cast<const PoolVector<Color> *>(_data._mem);
  2942. int idx = r_iter;
  2943. #ifdef DEBUG_ENABLED
  2944. if (idx < 0 || idx >= arr->size()) {
  2945. r_valid = false;
  2946. return Variant();
  2947. }
  2948. #endif
  2949. return arr->get(idx);
  2950. } break;
  2951. default: {
  2952. }
  2953. }
  2954. r_valid = false;
  2955. return Variant();
  2956. }
  2957. Variant Variant::duplicate(bool deep) const {
  2958. switch (type) {
  2959. case OBJECT: {
  2960. /* breaks stuff :(
  2961. if (deep && !_get_obj().ref.is_null()) {
  2962. Ref<Resource> resource = _get_obj().ref;
  2963. if (resource.is_valid()) {
  2964. return resource->duplicate(true);
  2965. }
  2966. }
  2967. */
  2968. return *this;
  2969. } break;
  2970. case DICTIONARY:
  2971. return operator Dictionary().duplicate(deep);
  2972. case ARRAY:
  2973. return operator Array().duplicate(deep);
  2974. default:
  2975. return *this;
  2976. }
  2977. }
  2978. void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) {
  2979. if (a.type != b.type) {
  2980. if (a.is_num() && b.is_num()) {
  2981. real_t va = a;
  2982. real_t vb = b;
  2983. r_dst = va + vb * c;
  2984. } else {
  2985. r_dst = a;
  2986. }
  2987. return;
  2988. }
  2989. switch (a.type) {
  2990. case NIL: {
  2991. r_dst = Variant();
  2992. }
  2993. return;
  2994. case INT: {
  2995. int64_t va = a._data._int;
  2996. int64_t vb = b._data._int;
  2997. r_dst = int(va + vb * c + 0.5);
  2998. }
  2999. return;
  3000. case REAL: {
  3001. double ra = a._data._real;
  3002. double rb = b._data._real;
  3003. r_dst = ra + rb * c;
  3004. }
  3005. return;
  3006. case VECTOR2: {
  3007. r_dst = *reinterpret_cast<const Vector2 *>(a._data._mem) + *reinterpret_cast<const Vector2 *>(b._data._mem) * c;
  3008. }
  3009. return;
  3010. case RECT2: {
  3011. const Rect2 *ra = reinterpret_cast<const Rect2 *>(a._data._mem);
  3012. const Rect2 *rb = reinterpret_cast<const Rect2 *>(b._data._mem);
  3013. r_dst = Rect2(ra->position + rb->position * c, ra->size + rb->size * c);
  3014. }
  3015. return;
  3016. case VECTOR3: {
  3017. r_dst = *reinterpret_cast<const Vector3 *>(a._data._mem) + *reinterpret_cast<const Vector3 *>(b._data._mem) * c;
  3018. }
  3019. return;
  3020. case AABB: {
  3021. const ::AABB *ra = reinterpret_cast<const ::AABB *>(a._data._mem);
  3022. const ::AABB *rb = reinterpret_cast<const ::AABB *>(b._data._mem);
  3023. r_dst = ::AABB(ra->position + rb->position * c, ra->size + rb->size * c);
  3024. }
  3025. return;
  3026. case QUAT: {
  3027. Quat empty_rot;
  3028. const Quat *qa = reinterpret_cast<const Quat *>(a._data._mem);
  3029. const Quat *qb = reinterpret_cast<const Quat *>(b._data._mem);
  3030. r_dst = *qa * empty_rot.slerp(*qb, c);
  3031. }
  3032. return;
  3033. case COLOR: {
  3034. const Color *ca = reinterpret_cast<const Color *>(a._data._mem);
  3035. const Color *cb = reinterpret_cast<const Color *>(b._data._mem);
  3036. float new_r = ca->r + cb->r * c;
  3037. float new_g = ca->g + cb->g * c;
  3038. float new_b = ca->b + cb->b * c;
  3039. float new_a = ca->a + cb->a * c;
  3040. new_r = new_r > 1.0 ? 1.0 : new_r;
  3041. new_g = new_g > 1.0 ? 1.0 : new_g;
  3042. new_b = new_b > 1.0 ? 1.0 : new_b;
  3043. new_a = new_a > 1.0 ? 1.0 : new_a;
  3044. r_dst = Color(new_r, new_g, new_b, new_a);
  3045. }
  3046. return;
  3047. default: {
  3048. r_dst = c < 0.5 ? a : b;
  3049. }
  3050. return;
  3051. }
  3052. }
  3053. void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst) {
  3054. if (a.type != b.type) {
  3055. if (a.is_num() && b.is_num()) {
  3056. //not as efficient but..
  3057. real_t va = a;
  3058. real_t vb = b;
  3059. r_dst = va + (vb - va) * c;
  3060. } else {
  3061. r_dst = a;
  3062. }
  3063. return;
  3064. }
  3065. switch (a.type) {
  3066. case NIL: {
  3067. r_dst = Variant();
  3068. }
  3069. return;
  3070. case BOOL: {
  3071. r_dst = a;
  3072. }
  3073. return;
  3074. case INT: {
  3075. int64_t va = a._data._int;
  3076. int64_t vb = b._data._int;
  3077. r_dst = int(va + (vb - va) * c);
  3078. }
  3079. return;
  3080. case REAL: {
  3081. real_t va = a._data._real;
  3082. real_t vb = b._data._real;
  3083. r_dst = va + (vb - va) * c;
  3084. }
  3085. return;
  3086. case STRING: {
  3087. //this is pretty funny and bizarre, but artists like to use it for typewritter effects
  3088. String sa = *reinterpret_cast<const String *>(a._data._mem);
  3089. String sb = *reinterpret_cast<const String *>(b._data._mem);
  3090. String dst;
  3091. int sa_len = sa.length();
  3092. int sb_len = sb.length();
  3093. int csize = sa_len + (sb_len - sa_len) * c;
  3094. if (csize == 0) {
  3095. r_dst = "";
  3096. return;
  3097. }
  3098. dst.resize(csize + 1);
  3099. dst[csize] = 0;
  3100. int split = csize / 2;
  3101. for (int i = 0; i < csize; i++) {
  3102. CharType chr = ' ';
  3103. if (i < split) {
  3104. if (i < sa.length())
  3105. chr = sa[i];
  3106. else if (i < sb.length())
  3107. chr = sb[i];
  3108. } else {
  3109. if (i < sb.length())
  3110. chr = sb[i];
  3111. else if (i < sa.length())
  3112. chr = sa[i];
  3113. }
  3114. dst[i] = chr;
  3115. }
  3116. r_dst = dst;
  3117. }
  3118. return;
  3119. case VECTOR2: {
  3120. r_dst = reinterpret_cast<const Vector2 *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector2 *>(b._data._mem), c);
  3121. }
  3122. return;
  3123. case RECT2: {
  3124. r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->position.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->position, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c));
  3125. }
  3126. return;
  3127. case VECTOR3: {
  3128. r_dst = reinterpret_cast<const Vector3 *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector3 *>(b._data._mem), c);
  3129. }
  3130. return;
  3131. case TRANSFORM2D: {
  3132. r_dst = a._data._transform2d->interpolate_with(*b._data._transform2d, c);
  3133. }
  3134. return;
  3135. case PLANE: {
  3136. r_dst = a;
  3137. }
  3138. return;
  3139. case QUAT: {
  3140. r_dst = reinterpret_cast<const Quat *>(a._data._mem)->slerp(*reinterpret_cast<const Quat *>(b._data._mem), c);
  3141. }
  3142. return;
  3143. case AABB: {
  3144. r_dst = ::AABB(a._data._aabb->position.linear_interpolate(b._data._aabb->position, c), a._data._aabb->size.linear_interpolate(b._data._aabb->size, c));
  3145. }
  3146. return;
  3147. case BASIS: {
  3148. r_dst = Transform(*a._data._basis).interpolate_with(Transform(*b._data._basis), c).basis;
  3149. }
  3150. return;
  3151. case TRANSFORM: {
  3152. r_dst = a._data._transform->interpolate_with(*b._data._transform, c);
  3153. }
  3154. return;
  3155. case COLOR: {
  3156. r_dst = reinterpret_cast<const Color *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Color *>(b._data._mem), c);
  3157. }
  3158. return;
  3159. case NODE_PATH: {
  3160. r_dst = a;
  3161. }
  3162. return;
  3163. case _RID: {
  3164. r_dst = a;
  3165. }
  3166. return;
  3167. case OBJECT: {
  3168. r_dst = a;
  3169. }
  3170. return;
  3171. case DICTIONARY: {
  3172. }
  3173. return;
  3174. case ARRAY: {
  3175. r_dst = a;
  3176. }
  3177. return;
  3178. case POOL_BYTE_ARRAY: {
  3179. r_dst = a;
  3180. }
  3181. return;
  3182. case POOL_INT_ARRAY: {
  3183. const PoolVector<int> *arr_a = reinterpret_cast<const PoolVector<int> *>(a._data._mem);
  3184. const PoolVector<int> *arr_b = reinterpret_cast<const PoolVector<int> *>(b._data._mem);
  3185. int sz = arr_a->size();
  3186. if (sz == 0 || arr_b->size() != sz) {
  3187. r_dst = a;
  3188. } else {
  3189. PoolVector<int> v;
  3190. v.resize(sz);
  3191. {
  3192. PoolVector<int>::Write vw = v.write();
  3193. PoolVector<int>::Read ar = arr_a->read();
  3194. PoolVector<int>::Read br = arr_b->read();
  3195. Variant va;
  3196. for (int i = 0; i < sz; i++) {
  3197. Variant::interpolate(ar[i], br[i], c, va);
  3198. vw[i] = va;
  3199. }
  3200. }
  3201. r_dst = v;
  3202. }
  3203. }
  3204. return;
  3205. case POOL_REAL_ARRAY: {
  3206. const PoolVector<real_t> *arr_a = reinterpret_cast<const PoolVector<real_t> *>(a._data._mem);
  3207. const PoolVector<real_t> *arr_b = reinterpret_cast<const PoolVector<real_t> *>(b._data._mem);
  3208. int sz = arr_a->size();
  3209. if (sz == 0 || arr_b->size() != sz) {
  3210. r_dst = a;
  3211. } else {
  3212. PoolVector<real_t> v;
  3213. v.resize(sz);
  3214. {
  3215. PoolVector<real_t>::Write vw = v.write();
  3216. PoolVector<real_t>::Read ar = arr_a->read();
  3217. PoolVector<real_t>::Read br = arr_b->read();
  3218. Variant va;
  3219. for (int i = 0; i < sz; i++) {
  3220. Variant::interpolate(ar[i], br[i], c, va);
  3221. vw[i] = va;
  3222. }
  3223. }
  3224. r_dst = v;
  3225. }
  3226. }
  3227. return;
  3228. case POOL_STRING_ARRAY: {
  3229. r_dst = a;
  3230. }
  3231. return;
  3232. case POOL_VECTOR2_ARRAY: {
  3233. const PoolVector<Vector2> *arr_a = reinterpret_cast<const PoolVector<Vector2> *>(a._data._mem);
  3234. const PoolVector<Vector2> *arr_b = reinterpret_cast<const PoolVector<Vector2> *>(b._data._mem);
  3235. int sz = arr_a->size();
  3236. if (sz == 0 || arr_b->size() != sz) {
  3237. r_dst = a;
  3238. } else {
  3239. PoolVector<Vector2> v;
  3240. v.resize(sz);
  3241. {
  3242. PoolVector<Vector2>::Write vw = v.write();
  3243. PoolVector<Vector2>::Read ar = arr_a->read();
  3244. PoolVector<Vector2>::Read br = arr_b->read();
  3245. for (int i = 0; i < sz; i++) {
  3246. vw[i] = ar[i].linear_interpolate(br[i], c);
  3247. }
  3248. }
  3249. r_dst = v;
  3250. }
  3251. }
  3252. return;
  3253. case POOL_VECTOR3_ARRAY: {
  3254. const PoolVector<Vector3> *arr_a = reinterpret_cast<const PoolVector<Vector3> *>(a._data._mem);
  3255. const PoolVector<Vector3> *arr_b = reinterpret_cast<const PoolVector<Vector3> *>(b._data._mem);
  3256. int sz = arr_a->size();
  3257. if (sz == 0 || arr_b->size() != sz) {
  3258. r_dst = a;
  3259. } else {
  3260. PoolVector<Vector3> v;
  3261. v.resize(sz);
  3262. {
  3263. PoolVector<Vector3>::Write vw = v.write();
  3264. PoolVector<Vector3>::Read ar = arr_a->read();
  3265. PoolVector<Vector3>::Read br = arr_b->read();
  3266. for (int i = 0; i < sz; i++) {
  3267. vw[i] = ar[i].linear_interpolate(br[i], c);
  3268. }
  3269. }
  3270. r_dst = v;
  3271. }
  3272. }
  3273. return;
  3274. case POOL_COLOR_ARRAY: {
  3275. const PoolVector<Color> *arr_a = reinterpret_cast<const PoolVector<Color> *>(a._data._mem);
  3276. const PoolVector<Color> *arr_b = reinterpret_cast<const PoolVector<Color> *>(b._data._mem);
  3277. int sz = arr_a->size();
  3278. if (sz == 0 || arr_b->size() != sz) {
  3279. r_dst = a;
  3280. } else {
  3281. PoolVector<Color> v;
  3282. v.resize(sz);
  3283. {
  3284. PoolVector<Color>::Write vw = v.write();
  3285. PoolVector<Color>::Read ar = arr_a->read();
  3286. PoolVector<Color>::Read br = arr_b->read();
  3287. for (int i = 0; i < sz; i++) {
  3288. vw[i] = ar[i].linear_interpolate(br[i], c);
  3289. }
  3290. }
  3291. r_dst = v;
  3292. }
  3293. }
  3294. return;
  3295. default: {
  3296. r_dst = a;
  3297. }
  3298. }
  3299. }
  3300. static const char *_op_names[Variant::OP_MAX] = {
  3301. "==",
  3302. "!=",
  3303. "<",
  3304. "<=",
  3305. ">",
  3306. ">=",
  3307. "+",
  3308. "-",
  3309. "*",
  3310. "/",
  3311. "- (negation)",
  3312. "+ (positive)",
  3313. "%",
  3314. "+ (concatenation)",
  3315. "<<",
  3316. ">>",
  3317. "&",
  3318. "|",
  3319. "^",
  3320. "~",
  3321. "and",
  3322. "or",
  3323. "xor",
  3324. "not",
  3325. "in"
  3326. };
  3327. String Variant::get_operator_name(Operator p_op) {
  3328. ERR_FAIL_INDEX_V(p_op, OP_MAX, "");
  3329. return _op_names[p_op];
  3330. }