SWF_Main.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../idlib/precompiled.h"
  22. #include "../renderer/image.h"
  23. #pragma warning(disable: 4355) // 'this' : used in base member initializer list
  24. idCVar swf_loadBinary( "swf_loadBinary", "1", CVAR_INTEGER, "used to set whether to load binary swf from generated" );
  25. int idSWF::mouseX = -1;
  26. int idSWF::mouseY = -1;
  27. bool idSWF::isMouseInClientArea = false;
  28. extern idCVar in_useJoystick;
  29. /*
  30. ===================
  31. idSWF::idSWF
  32. ===================
  33. */
  34. idSWF::idSWF( const char * filename_, idSoundWorld * soundWorld_ ) {
  35. atlasMaterial = NULL;
  36. swfScale = 1.0f;
  37. scaleToVirtual.Set( 1.0f, 1.0f );
  38. random.SetSeed( Sys_Milliseconds() );
  39. guiSolid = declManager->FindMaterial( "guiSolid" );
  40. guiCursor_arrow = declManager->FindMaterial( "ui/assets/guicursor_arrow" );
  41. guiCursor_hand = declManager->FindMaterial( "ui/assets/guicursor_hand" );
  42. white = declManager->FindMaterial( "_white" );
  43. tooltipButtonImage.Append( keyButtonImages_t( "<JOY1>", "guis/assets/hud/controller/xb360/a", "guis/assets/hud/controller/ps3/cross", 37, 37, 0 ) );
  44. tooltipButtonImage.Append( keyButtonImages_t( "<JOY2>", "guis/assets/hud/controller/xb360/b", "guis/assets/hud/controller/ps3/circle", 37, 37, 0 ) );
  45. tooltipButtonImage.Append( keyButtonImages_t( "<JOY3>", "guis/assets/hud/controller/xb360/x", "guis/assets/hud/controller/ps3/square", 37, 37, 0 ) );
  46. tooltipButtonImage.Append( keyButtonImages_t( "<JOY4>", "guis/assets/hud/controller/xb360/y", "guis/assets/hud/controller/ps3/triangle", 37, 37, 0 ) );
  47. tooltipButtonImage.Append( keyButtonImages_t( "<JOY_TRIGGER2>", "guis/assets/hud/controller/xb360/rt", "guis/assets/hud/controller/ps3/r2", 64, 52, 0 ) );
  48. tooltipButtonImage.Append( keyButtonImages_t( "<JOY_TRIGGER1>", "guis/assets/hud/controller/xb360/lt", "guis/assets/hud/controller/ps3/l2", 64, 52, 0 ) );
  49. tooltipButtonImage.Append( keyButtonImages_t( "<JOY5>", "guis/assets/hud/controller/xb360/lb", "guis/assets/hud/controller/ps3/l1", 52, 32, 0 ) );
  50. tooltipButtonImage.Append( keyButtonImages_t( "<JOY6>", "guis/assets/hud/controller/xb360/rb", "guis/assets/hud/controller/ps3/r1", 52, 32, 0 ) );
  51. tooltipButtonImage.Append( keyButtonImages_t( "<MOUSE1>", "guis/assets/hud/controller/mouse1", "", 64, 52, 0 ) );
  52. tooltipButtonImage.Append( keyButtonImages_t( "<MOUSE2>", "guis/assets/hud/controller/mouse2", "", 64, 52, 0 ) );
  53. tooltipButtonImage.Append( keyButtonImages_t( "<MOUSE3>", "guis/assets/hud/controller/mouse3", "", 64, 52, 0 ) );
  54. for ( int index = 0; index < tooltipButtonImage.Num(); index++ ) {
  55. if ( ( tooltipButtonImage[index].xbImage != NULL ) && ( tooltipButtonImage[index].xbImage[0] != '\0' ) ) {
  56. declManager->FindMaterial( tooltipButtonImage[index].xbImage );
  57. }
  58. if ( ( tooltipButtonImage[index].psImage != NULL ) && ( tooltipButtonImage[index].psImage[0] != '\0' ) ) {
  59. declManager->FindMaterial( tooltipButtonImage[index].psImage );
  60. }
  61. }
  62. frameWidth = 0;
  63. frameHeight = 0;
  64. frameRate = 0;
  65. lastRenderTime = 0;
  66. isActive = false;
  67. inhibitControl = false;
  68. useInhibtControl = true;
  69. crop = false;
  70. blackbars = false;
  71. paused = false;
  72. hasHitObject = false;
  73. useMouse = true;
  74. mouseEnabled = false;
  75. renderBorder = 0;
  76. mouseObject = NULL;
  77. hoverObject = NULL;
  78. soundWorld = NULL;
  79. forceNonPCPlatform = false;
  80. if ( idStr::Cmpn( filename_, "swf/", 4 ) != 0 ) {
  81. // if it doesn't already have swf/ in front of it, add it
  82. filename = "swf/";
  83. filename += filename_;
  84. } else {
  85. filename = filename_;
  86. }
  87. filename.ToLower();
  88. filename.BackSlashesToSlashes();
  89. filename.SetFileExtension( ".swf" );
  90. timestamp = fileSystem->GetTimestamp( filename );
  91. mainsprite = new (TAG_SWF) idSWFSprite( this );
  92. mainspriteInstance = NULL;
  93. idStr binaryFileName = "generated/";
  94. binaryFileName += filename;
  95. binaryFileName.SetFileExtension( ".bswf" );
  96. if ( swf_loadBinary.GetBool() ) {
  97. ID_TIME_T sourceTime = fileSystem->GetTimestamp( filename );
  98. if ( !LoadBinary( binaryFileName, sourceTime ) ) {
  99. if ( LoadSWF( filename ) ) {
  100. WriteBinary( binaryFileName );
  101. }
  102. }
  103. } else {
  104. LoadSWF( filename );
  105. }
  106. idStr atlasFileName = binaryFileName;
  107. atlasFileName.SetFileExtension( ".tga" );
  108. atlasMaterial = declManager->FindMaterial( atlasFileName );
  109. globals = idSWFScriptObject::Alloc();
  110. globals->Set( "_global", globals );
  111. globals->Set( "Object", &scriptFunction_Object );
  112. mainspriteInstance = spriteInstanceAllocator.Alloc();
  113. mainspriteInstance->Init( mainsprite, NULL, 0 );
  114. shortcutKeys = idSWFScriptObject::Alloc();
  115. scriptFunction_shortcutKeys_clear.Bind( this );
  116. scriptFunction_shortcutKeys_clear.Call( shortcutKeys, idSWFParmList() );
  117. globals->Set( "shortcutKeys", shortcutKeys );
  118. globals->Set( "deactivate", scriptFunction_deactivate.Bind( this ) );
  119. globals->Set( "inhibitControl", scriptFunction_inhibitControl.Bind( this ) );
  120. globals->Set( "useInhibit", scriptFunction_useInhibit.Bind( this ) );
  121. globals->Set( "precacheSound", scriptFunction_precacheSound.Bind( this ) );
  122. globals->Set( "playSound", scriptFunction_playSound.Bind( this ) );
  123. globals->Set( "stopSounds",scriptFunction_stopSounds.Bind( this ) );
  124. globals->Set( "getPlatform", scriptFunction_getPlatform.Bind( this ) );
  125. globals->Set( "getTruePlatform", scriptFunction_getTruePlatform.Bind( this ) );
  126. globals->Set( "getLocalString", scriptFunction_getLocalString.Bind( this ) );
  127. globals->Set( "swapPS3Buttons", scriptFunction_swapPS3Buttons.Bind( this ) );
  128. globals->Set( "_root", mainspriteInstance->scriptObject );
  129. globals->Set( "strReplace", scriptFunction_strReplace.Bind( this ) );
  130. globals->Set( "getCVarInteger", scriptFunction_getCVarInteger.Bind( this ) );
  131. globals->Set( "setCVarInteger", scriptFunction_setCVarInteger.Bind( this ) );
  132. globals->Set( "acos", scriptFunction_acos.Bind( this ) );
  133. globals->Set( "cos", scriptFunction_cos.Bind( this ) );
  134. globals->Set( "sin", scriptFunction_sin.Bind( this ) );
  135. globals->Set( "round", scriptFunction_round.Bind( this ) );
  136. globals->Set( "pow", scriptFunction_pow.Bind( this ) );
  137. globals->Set( "sqrt", scriptFunction_sqrt.Bind( this ) );
  138. globals->Set( "abs", scriptFunction_abs.Bind( this ) );
  139. globals->Set( "rand", scriptFunction_rand.Bind( this ) );
  140. globals->Set( "floor", scriptFunction_floor.Bind( this ) );
  141. globals->Set( "ceil", scriptFunction_ceil.Bind( this ) );
  142. globals->Set( "toUpper", scriptFunction_toUpper.Bind( this ) );
  143. globals->SetNative( "platform", swfScriptVar_platform.Bind( &scriptFunction_getPlatform ) );
  144. globals->SetNative( "blackbars", swfScriptVar_blackbars.Bind( this ) );
  145. globals->SetNative( "cropToHeight", swfScriptVar_crop.Bind( this ) );
  146. globals->SetNative( "cropToFit", swfScriptVar_crop.Bind( this ) );
  147. globals->SetNative( "crop", swfScriptVar_crop.Bind( this ) );
  148. // Do this to touch any external references (like sounds)
  149. // But disable script warnings because many globals won't have been created yet
  150. extern idCVar swf_debug;
  151. int debug = swf_debug.GetInteger();
  152. swf_debug.SetInteger( 0 );
  153. mainspriteInstance->Run();
  154. mainspriteInstance->RunActions();
  155. mainspriteInstance->RunTo( 0 );
  156. swf_debug.SetInteger( debug );
  157. if ( mouseX == -1 ) {
  158. mouseX = ( frameWidth / 2 );
  159. }
  160. if ( mouseY == -1 ) {
  161. mouseY = ( frameHeight / 2 );
  162. }
  163. soundWorld = soundWorld_;
  164. }
  165. /*
  166. ===================
  167. idSWF::~idSWF
  168. ===================
  169. */
  170. idSWF::~idSWF() {
  171. spriteInstanceAllocator.Free( mainspriteInstance );
  172. delete mainsprite;
  173. for ( int i = 0 ; i < dictionary.Num() ; i++ ) {
  174. if ( dictionary[i].sprite ) {
  175. delete dictionary[i].sprite;
  176. dictionary[i].sprite = NULL;
  177. }
  178. if ( dictionary[i].shape ) {
  179. delete dictionary[i].shape;
  180. dictionary[i].shape = NULL;
  181. }
  182. if ( dictionary[i].font ) {
  183. delete dictionary[i].font;
  184. dictionary[i].font = NULL;
  185. }
  186. if ( dictionary[i].text ) {
  187. delete dictionary[i].text;
  188. dictionary[i].text = NULL;
  189. }
  190. if ( dictionary[i].edittext ) {
  191. delete dictionary[i].edittext;
  192. dictionary[i].edittext = NULL;
  193. }
  194. }
  195. globals->Clear();
  196. tooltipButtonImage.Clear();
  197. globals->Release();
  198. shortcutKeys->Clear();
  199. shortcutKeys->Release();
  200. }
  201. /*
  202. ===================
  203. idSWF::Activate
  204. when a SWF is deactivated, it rewinds the timeline back to the start
  205. ===================
  206. */
  207. void idSWF::Activate( bool b ) {
  208. if ( !isActive && b ) {
  209. inhibitControl = false;
  210. lastRenderTime = Sys_Milliseconds();
  211. mainspriteInstance->FreeDisplayList();
  212. mainspriteInstance->Play();
  213. mainspriteInstance->Run();
  214. mainspriteInstance->RunActions();
  215. }
  216. isActive = b;
  217. }
  218. /*
  219. ===================
  220. idSWF::InhibitControl
  221. ===================
  222. */
  223. bool idSWF::InhibitControl() {
  224. if ( !IsLoaded() || !IsActive() ) {
  225. return false;
  226. }
  227. return ( inhibitControl && useInhibtControl );
  228. }
  229. /*
  230. ===================
  231. idSWF::PlaySound
  232. ===================
  233. */
  234. int idSWF::PlaySound( const char * sound, int channel, bool blocking ) {
  235. if ( !IsActive() ) {
  236. return -1;
  237. }
  238. if ( soundWorld != NULL ) {
  239. return soundWorld->PlayShaderDirectly( sound, channel );
  240. } else {
  241. idLib::Warning( "No playing sound world on soundSystem in swf play sound!" );
  242. return -1;
  243. }
  244. }
  245. /*
  246. ===================
  247. idSWF::PlaySound
  248. ===================
  249. */
  250. void idSWF::StopSound( int channel ) {
  251. if ( soundWorld != NULL ) {
  252. soundWorld->PlayShaderDirectly( NULL, channel );
  253. } else {
  254. idLib::Warning( "No playing sound world on soundSystem in swf play sound!" );
  255. }
  256. }
  257. /*
  258. ===================
  259. idSWF::idSWFScriptFunction_inhibitControl::Call
  260. ===================
  261. */
  262. idSWFScriptVar idSWF::idSWFScriptFunction_inhibitControl::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  263. pThis->inhibitControl = parms[0].ToBool();
  264. return idSWFScriptVar();
  265. }
  266. /*
  267. ===================
  268. idSWF::idSWFScriptFunction_inhibitControl::Call
  269. ===================
  270. */
  271. idSWFScriptVar idSWF::idSWFScriptFunction_useInhibit::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  272. pThis->useInhibtControl = parms[0].ToBool();
  273. return idSWFScriptVar();
  274. }
  275. /*
  276. ===================
  277. idSWF::idSWFScriptFunction_deactivate::Call
  278. ===================
  279. */
  280. idSWFScriptVar idSWF::idSWFScriptFunction_deactivate::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  281. pThis->Activate( false );
  282. return idSWFScriptVar();
  283. }
  284. /*
  285. ===================
  286. idSWF::idSWFScriptFunction_precacheSound::Call
  287. ===================
  288. */
  289. idSWFScriptVar idSWF::idSWFScriptFunction_precacheSound::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  290. const idSoundShader * soundShader = declManager->FindSound( parms[0].ToString(), true );
  291. return soundShader->GetName();
  292. }
  293. /*
  294. ===================
  295. idSWF::idSWFScriptFunction_playSound::Call
  296. ===================
  297. */
  298. idSWFScriptVar idSWF::idSWFScriptFunction_playSound::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  299. int channel = SCHANNEL_ANY;
  300. // specific channel passed in
  301. if ( parms.Num() > 1 ) {
  302. channel = parms[1].ToInteger();
  303. }
  304. pThis->PlaySound( parms[0].ToString(), channel );
  305. return idSWFScriptVar();
  306. }
  307. /*
  308. ===================
  309. idSWF::idSWFScriptFunction_stopSounds::Call
  310. ===================
  311. */
  312. idSWFScriptVar idSWF::idSWFScriptFunction_stopSounds::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  313. int channel = SCHANNEL_ANY;
  314. if ( parms.Num() == 1 ) {
  315. channel = parms[0].ToInteger();
  316. }
  317. pThis->StopSound( channel );
  318. return idSWFScriptVar();
  319. }
  320. /*
  321. ========================
  322. idSWFScriptFunction_GetPlatform::Call
  323. ========================
  324. */
  325. idSWFScriptVar idSWF::idSWFScriptFunction_getPlatform::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  326. return pThis->GetPlatform();
  327. }
  328. /*
  329. ========================
  330. idSWFScriptFunction_GetPlatform::Call
  331. ========================
  332. */
  333. idSWFScriptVar idSWF::idSWFScriptFunction_getTruePlatform::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  334. return 2;
  335. }
  336. /*
  337. ========================
  338. idSWFScriptFunction_GetPlatform::Call
  339. ========================
  340. */
  341. idSWFScriptVar idSWF::idSWFScriptFunction_strReplace::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  342. if ( parms.Num() != 3 ) {
  343. return "";
  344. }
  345. idStr str = parms[0].ToString();
  346. idStr repString = parms[1].ToString();
  347. idStr val = parms[2].ToString();
  348. str.Replace( repString, val );
  349. return str;
  350. }
  351. /*
  352. ========================
  353. idSWFScriptFunction_GetPlatform::Call
  354. ========================
  355. */
  356. idSWFScriptVar idSWF::idSWFScriptFunction_getLocalString::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  357. if ( parms.Num() == 0 ) {
  358. return idSWFScriptVar();
  359. }
  360. idStr val = idLocalization::GetString( parms[0].ToString() );
  361. return val;
  362. }
  363. /*
  364. ========================
  365. idSWF::UseCircleForAccept
  366. ========================
  367. */
  368. bool idSWF::UseCircleForAccept() {
  369. return false;
  370. }
  371. /*
  372. ========================
  373. idSWF::GetPlatform
  374. ========================
  375. */
  376. int idSWF::GetPlatform() {
  377. if ( in_useJoystick.GetBool() || forceNonPCPlatform ) {
  378. forceNonPCPlatform = false;
  379. return 0;
  380. }
  381. return 2;
  382. }
  383. /*
  384. ========================
  385. idSWFScriptFunction_swapPS3Buttons::Call
  386. ========================
  387. */
  388. idSWFScriptVar idSWF::idSWFScriptFunction_swapPS3Buttons::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  389. return pThis->UseCircleForAccept();
  390. }
  391. /*
  392. ========================
  393. idSWFScriptFunction_getCVarInteger::Call
  394. ========================
  395. */
  396. idSWFScriptVar idSWF::idSWFScriptFunction_getCVarInteger::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  397. return cvarSystem->GetCVarInteger( parms[0].ToString() );
  398. }
  399. /*
  400. ========================
  401. idSWFScriptFunction_setCVarInteger::Call
  402. ========================
  403. */
  404. idSWFScriptVar idSWF::idSWFScriptFunction_setCVarInteger::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  405. cvarSystem->SetCVarInteger( parms[0].ToString(), parms[1].ToInteger() );
  406. return idSWFScriptVar();
  407. }
  408. /*
  409. ===================
  410. idSWF::idSWFScriptFunction_acos::Call
  411. ===================
  412. */
  413. idSWFScriptVar idSWF::idSWFScriptFunction_acos::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  414. if ( parms.Num() != 1 ) {
  415. return idSWFScriptVar();
  416. }
  417. return idMath::ACos( parms[0].ToFloat() );
  418. }
  419. /*
  420. ===================
  421. idSWF::idSWFScriptFunction_cos::Call
  422. ===================
  423. */
  424. idSWFScriptVar idSWF::idSWFScriptFunction_cos::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  425. if ( parms.Num() != 1 ) {
  426. return idSWFScriptVar();
  427. }
  428. return idMath::Cos( parms[0].ToFloat() );
  429. }
  430. /*
  431. ===================
  432. idSWF::idSWFScriptFunction_sin::Call
  433. ===================
  434. */
  435. idSWFScriptVar idSWF::idSWFScriptFunction_sin::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  436. if ( parms.Num() != 1 ) {
  437. return idSWFScriptVar();
  438. }
  439. return ( idMath::Sin( parms[0].ToFloat() ) );
  440. }
  441. /*
  442. ===================
  443. idSWF::idSWFScriptFunction_round::Call
  444. ===================
  445. */
  446. idSWFScriptVar idSWF::idSWFScriptFunction_round::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  447. if ( parms.Num() != 1 ) {
  448. return idSWFScriptVar();
  449. }
  450. int value = idMath::Ftoi( parms[0].ToFloat() + 0.5f );
  451. return value;
  452. }
  453. /*
  454. ===================
  455. idSWF::idSWFScriptFunction_pow::Call
  456. ===================
  457. */
  458. idSWFScriptVar idSWF::idSWFScriptFunction_pow::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  459. if ( parms.Num() != 2 ) {
  460. return idSWFScriptVar();
  461. }
  462. float value = parms[0].ToFloat();
  463. float power = parms[1].ToFloat();
  464. return ( idMath::Pow( value, power ) );
  465. }
  466. /*
  467. ===================
  468. idSWF::idSWFScriptFunction_pow::Call
  469. ===================
  470. */
  471. idSWFScriptVar idSWF::idSWFScriptFunction_sqrt::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  472. if ( parms.Num() != 1 ) {
  473. return idSWFScriptVar();
  474. }
  475. float value = parms[0].ToFloat();
  476. return ( idMath::Sqrt( value ) );
  477. }
  478. /*
  479. ===================
  480. idSWF::idSWFScriptFunction_abs::Call
  481. ===================
  482. */
  483. idSWFScriptVar idSWF::idSWFScriptFunction_abs::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  484. if ( parms.Num() != 1 ) {
  485. return idSWFScriptVar();
  486. }
  487. float value = idMath::Fabs( parms[0].ToFloat() );
  488. return value;
  489. }
  490. /*
  491. ===================
  492. idSWF::idSWFScriptFunction_rand::Call
  493. ===================
  494. */
  495. idSWFScriptVar idSWF::idSWFScriptFunction_rand::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  496. float min = 0.0f;
  497. float max = 1.0f;
  498. switch ( parms.Num() ) {
  499. case 0:
  500. break;
  501. case 1:
  502. max = parms[0].ToFloat();
  503. break;
  504. default:
  505. min = parms[0].ToFloat();
  506. max = parms[1].ToFloat();
  507. break;
  508. }
  509. return min + pThis->GetRandom().RandomFloat() * ( max - min );
  510. }
  511. /*
  512. ========================
  513. idSWFScriptFunction_floor::Call
  514. ========================
  515. */
  516. idSWFScriptVar idSWF::idSWFScriptFunction_floor::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  517. if ( parms.Num() != 1 || !parms[0].IsNumeric() ) {
  518. idLib::Warning( "Invalid parameters specified for floor" );
  519. return idSWFScriptVar();
  520. }
  521. float num = parms[0].ToFloat();
  522. return idSWFScriptVar( idMath::Floor( num ) );
  523. }
  524. /*
  525. ========================
  526. idSWFScriptFunction_ceil::Call
  527. ========================
  528. */
  529. idSWFScriptVar idSWF::idSWFScriptFunction_ceil::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  530. if ( parms.Num() != 1 || !parms[0].IsNumeric() ) {
  531. idLib::Warning( "Invalid parameters specified for ceil" );
  532. return idSWFScriptVar();
  533. }
  534. float num = parms[0].ToFloat();
  535. return idSWFScriptVar( idMath::Ceil( num ) );
  536. }
  537. /*
  538. ========================
  539. idSWFScriptFunction_toUpper::Call
  540. ========================
  541. */
  542. idSWFScriptVar idSWF::idSWFScriptFunction_toUpper::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  543. if ( parms.Num() != 1 || !parms[0].IsString() ) {
  544. idLib::Warning( "Invalid parameters specified for toUpper" );
  545. return idSWFScriptVar();
  546. }
  547. idStr val = idLocalization::GetString( parms[0].ToString() );
  548. val.ToUpper();
  549. return val;
  550. }
  551. /*
  552. ===================
  553. idSWF::idSWFScriptFunction_shortcutKeys_clear::Call
  554. ===================
  555. */
  556. idSWFScriptVar idSWF::idSWFScriptFunction_shortcutKeys_clear::Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ) {
  557. idSWFScriptObject * object = pThis->shortcutKeys;
  558. object->Clear();
  559. object->Set( "clear", this );
  560. object->Set( "JOY1", "ENTER" );
  561. object->Set( "JOY2", "BACKSPACE" );
  562. object->Set( "JOY3", "START" );
  563. object->Set( "JOY5", "LB" );
  564. object->Set( "JOY6", "RB" );
  565. object->Set( "JOY9", "START" );
  566. object->Set( "JOY10", "BACKSPACE" );
  567. object->Set( "JOY_DPAD_UP", "UP" );
  568. object->Set( "JOY_DPAD_DOWN", "DOWN" );
  569. object->Set( "JOY_DPAD_LEFT", "LEFT" );
  570. object->Set( "JOY_DPAD_RIGHT", "RIGHT" );
  571. object->Set( "JOY_STICK1_UP", "STICK1_UP" );
  572. object->Set( "JOY_STICK1_DOWN", "STICK1_DOWN" );
  573. object->Set( "JOY_STICK1_LEFT", "STICK1_LEFT" );
  574. object->Set( "JOY_STICK1_RIGHT", "STICK1_RIGHT" );
  575. object->Set( "JOY_STICK2_UP", "STICK2_UP" );
  576. object->Set( "JOY_STICK2_DOWN", "STICK2_DOWN" );
  577. object->Set( "JOY_STICK2_LEFT", "STICK2_LEFT" );
  578. object->Set( "JOY_STICK2_RIGHT", "STICK2_RIGHT" );
  579. object->Set( "KP_ENTER", "ENTER" );
  580. object->Set( "MWHEELDOWN", "MWHEEL_DOWN" );
  581. object->Set( "MWHEELUP", "MWHEEL_UP" );
  582. object->Set( "K_TAB", "TAB" );
  583. // FIXME: I'm an RTARD and didn't realize the keys all have "ARROW" after them
  584. object->Set( "LEFTARROW", "LEFT" );
  585. object->Set( "RIGHTARROW", "RIGHT" );
  586. object->Set( "UPARROW", "UP" );
  587. object->Set( "DOWNARROW", "DOWN" );
  588. return idSWFScriptVar();
  589. }
  590. idSWFScriptVar idSWF::idSWFScriptNativeVar_blackbars::Get( idSWFScriptObject * object ) {
  591. return pThis->blackbars;
  592. }
  593. void idSWF::idSWFScriptNativeVar_blackbars::Set( idSWFScriptObject * object, const idSWFScriptVar & value ) {
  594. pThis->blackbars = value.ToBool();
  595. }
  596. idSWFScriptVar idSWF::idSWFScriptNativeVar_crop::Get( idSWFScriptObject * object ) {
  597. return pThis->crop;
  598. }
  599. void idSWF::idSWFScriptNativeVar_crop::Set( idSWFScriptObject * object, const idSWFScriptVar & value ) {
  600. pThis->crop = value.ToBool();
  601. }