netGraphGui.gui 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. function execNetGraphGuiGUI()
  2. {
  3. if ( isObject( NetGraphGui ) )
  4. NetGraphGui.delete();
  5. if ( isObject( NetGraphProfile ) )
  6. NetGraphProfile.delete();
  7. if ( isObject( NetGraphGhostsActiveProfile ) )
  8. NetGraphGhostsActiveProfile.delete();
  9. if ( isObject( NetGraphGhostUpdatesProfile ) )
  10. NetGraphGhostUpdatesProfile.delete();
  11. if ( isObject( NetGraphBitsSentProfile ) )
  12. NetGraphBitsSentProfile.delete();
  13. if ( isObject( NetGraphBitsReceivedProfile ) )
  14. NetGraphBitsReceivedProfile.delete();
  15. if ( isObject( NetGraphLatencyProfile ) )
  16. NetGraphLatencyProfile.delete();
  17. if ( isObject( NetGraphPacketLossProfile ) )
  18. NetGraphPacketLossProfile.delete();
  19. exec( "./NetGraphGui.gui" );
  20. }
  21. // Profiles
  22. new GuiControlProfile (NetGraphProfile)
  23. {
  24. modal = false;
  25. opaque = false;
  26. canKeyFocus = false;
  27. };
  28. new GuiControlProfile (NetGraphKeyContainerProfile)
  29. {
  30. border = true;
  31. opaque = true;
  32. fillColor = "100 100 100 200";
  33. };
  34. new GuiControlProfile (NetGraphGhostsActiveProfile)
  35. {
  36. border = false;
  37. fontColor = "255 255 255";
  38. };
  39. new GuiControlProfile (NetGraphGhostUpdatesProfile)
  40. {
  41. border = false;
  42. fontColor = "255 0 0";
  43. };
  44. new GuiControlProfile (NetGraphBitsSentProfile)
  45. {
  46. border = false;
  47. fontColor = "0 255 0";
  48. };
  49. new GuiControlProfile (NetGraphBitsReceivedProfile)
  50. {
  51. border = false;
  52. fontColor = "0 0 255";
  53. };
  54. new GuiControlProfile (NetGraphLatencyProfile)
  55. {
  56. border = false;
  57. fontColor = "0 255 255";
  58. };
  59. new GuiControlProfile (NetGraphPacketLossProfile)
  60. {
  61. border = false;
  62. fontColor = "0 0 0";
  63. };
  64. //--- OBJECT WRITE BEGIN ---
  65. $guiContent = new GuiControl(NetGraphGui) {
  66. position = "0 0";
  67. extent = "1024 768";
  68. minExtent = "8 2";
  69. horizSizing = "left";
  70. vertSizing = "bottom";
  71. profile = "NetGraphProfile";
  72. visible = "1";
  73. active = "1";
  74. tooltipProfile = "GuiToolTipProfile";
  75. hovertime = "1000";
  76. isContainer = "1";
  77. canSave = "1";
  78. canSaveDynamicFields = "1";
  79. noCursor = "1";
  80. new GuiGraphCtrl(NetGraph) {
  81. centerY = "1";
  82. plotColor[0] = "1 1 1 1";
  83. plotColor[1] = "1 0 0 1";
  84. plotColor[2] = "0 1 0 1";
  85. plotColor[3] = "0 0 1 1";
  86. plotColor[4] = "0 1 1 1";
  87. plotColor[5] = "0 0 0 1";
  88. plotType[0] = "PolyLine";
  89. plotType[1] = "PolyLine";
  90. plotType[2] = "PolyLine";
  91. plotType[3] = "PolyLine";
  92. plotType[4] = "PolyLine";
  93. plotType[5] = "PolyLine";
  94. plotInterval[0] = "0";
  95. plotInterval[1] = "0";
  96. plotInterval[2] = "0";
  97. plotInterval[3] = "0";
  98. plotInterval[4] = "0";
  99. plotInterval[5] = "0";
  100. position = "816 5";
  101. extent = "200 200";
  102. minExtent = "8 2";
  103. horizSizing = "left";
  104. vertSizing = "bottom";
  105. profile = "NetGraphKeyContainerProfile";
  106. visible = "1";
  107. active = "1";
  108. tooltipProfile = "GuiToolTipProfile";
  109. hovertime = "1000";
  110. isContainer = "0";
  111. canSave = "1";
  112. canSaveDynamicFields = "0";
  113. };
  114. new GuiControl() {
  115. position = "816 205";
  116. extent = "200 104";
  117. minExtent = "8 2";
  118. horizSizing = "left";
  119. vertSizing = "bottom";
  120. profile = "NetGraphKeyContainerProfile";
  121. visible = "1";
  122. active = "1";
  123. tooltipProfile = "GuiToolTipProfile";
  124. hovertime = "1000";
  125. isContainer = "1";
  126. canSave = "1";
  127. canSaveDynamicFields = "0";
  128. new GuiTextCtrl(GhostsActive) {
  129. text = "Ghosts Active";
  130. maxLength = "255";
  131. margin = "0 0 0 0";
  132. padding = "0 0 0 0";
  133. anchorTop = "1";
  134. anchorBottom = "0";
  135. anchorLeft = "1";
  136. anchorRight = "0";
  137. position = "0 0";
  138. extent = "100 18";
  139. minExtent = "8 2";
  140. horizSizing = "left";
  141. vertSizing = "bottom";
  142. profile = "NetGraphGhostsActiveProfile";
  143. visible = "1";
  144. active = "1";
  145. tooltipProfile = "GuiToolTipProfile";
  146. hovertime = "1000";
  147. isContainer = "1";
  148. canSave = "1";
  149. canSaveDynamicFields = "0";
  150. };
  151. new GuiTextCtrl(GhostUpdates) {
  152. text = "Ghost Updates";
  153. maxLength = "255";
  154. margin = "0 0 0 0";
  155. padding = "0 0 0 0";
  156. anchorTop = "1";
  157. anchorBottom = "0";
  158. anchorLeft = "1";
  159. anchorRight = "0";
  160. position = "100 0";
  161. extent = "100 18";
  162. minExtent = "8 2";
  163. horizSizing = "left";
  164. vertSizing = "bottom";
  165. profile = "NetGraphGhostUpdatesProfile";
  166. visible = "1";
  167. active = "1";
  168. tooltipProfile = "GuiToolTipProfile";
  169. hovertime = "1000";
  170. isContainer = "1";
  171. canSave = "1";
  172. canSaveDynamicFields = "0";
  173. };
  174. new GuiTextCtrl(BitsSent) {
  175. text = "Bytes Sent";
  176. maxLength = "255";
  177. margin = "0 0 0 0";
  178. padding = "0 0 0 0";
  179. anchorTop = "1";
  180. anchorBottom = "0";
  181. anchorLeft = "1";
  182. anchorRight = "0";
  183. position = "0 18";
  184. extent = "100 18";
  185. minExtent = "8 2";
  186. horizSizing = "left";
  187. vertSizing = "bottom";
  188. profile = "NetGraphBitsSentProfile";
  189. visible = "1";
  190. active = "1";
  191. tooltipProfile = "GuiToolTipProfile";
  192. hovertime = "1000";
  193. isContainer = "1";
  194. canSave = "1";
  195. canSaveDynamicFields = "0";
  196. };
  197. new GuiTextCtrl(BitsReceived) {
  198. text = "Bytes Received";
  199. maxLength = "255";
  200. margin = "0 0 0 0";
  201. padding = "0 0 0 0";
  202. anchorTop = "1";
  203. anchorBottom = "0";
  204. anchorLeft = "1";
  205. anchorRight = "0";
  206. position = "100 18";
  207. extent = "100 18";
  208. minExtent = "8 2";
  209. horizSizing = "left";
  210. vertSizing = "bottom";
  211. profile = "NetGraphBitsReceivedProfile";
  212. visible = "1";
  213. active = "1";
  214. tooltipProfile = "GuiToolTipProfile";
  215. hovertime = "1000";
  216. isContainer = "1";
  217. canSave = "1";
  218. canSaveDynamicFields = "0";
  219. };
  220. new GuiTextCtrl(Latency) {
  221. text = "Latency";
  222. maxLength = "255";
  223. margin = "0 0 0 0";
  224. padding = "0 0 0 0";
  225. anchorTop = "1";
  226. anchorBottom = "0";
  227. anchorLeft = "1";
  228. anchorRight = "0";
  229. position = "0 36";
  230. extent = "100 18";
  231. minExtent = "8 2";
  232. horizSizing = "left";
  233. vertSizing = "bottom";
  234. profile = "NetGraphLatencyProfile";
  235. visible = "1";
  236. active = "1";
  237. tooltipProfile = "GuiToolTipProfile";
  238. hovertime = "1000";
  239. isContainer = "1";
  240. canSave = "1";
  241. canSaveDynamicFields = "0";
  242. };
  243. new GuiTextCtrl(PacketLoss) {
  244. text = "Packet Loss";
  245. maxLength = "255";
  246. margin = "0 0 0 0";
  247. padding = "0 0 0 0";
  248. anchorTop = "1";
  249. anchorBottom = "0";
  250. anchorLeft = "1";
  251. anchorRight = "0";
  252. position = "100 36";
  253. extent = "59 18";
  254. minExtent = "8 2";
  255. horizSizing = "left";
  256. vertSizing = "bottom";
  257. profile = "NetGraphPacketLossProfile";
  258. visible = "1";
  259. active = "1";
  260. tooltipProfile = "GuiToolTipProfile";
  261. hovertime = "1000";
  262. isContainer = "1";
  263. canSave = "1";
  264. canSaveDynamicFields = "0";
  265. };
  266. new GuiTextCtrl() {
  267. text = "Network Simulation:";
  268. maxLength = "255";
  269. margin = "0 0 0 0";
  270. padding = "0 0 0 0";
  271. anchorTop = "1";
  272. anchorBottom = "0";
  273. anchorLeft = "1";
  274. anchorRight = "0";
  275. position = "0 52";
  276. extent = "97 18";
  277. minExtent = "8 2";
  278. horizSizing = "left";
  279. vertSizing = "bottom";
  280. profile = "NetGraphPacketLossProfile";
  281. visible = "1";
  282. active = "1";
  283. tooltipProfile = "GuiToolTipProfile";
  284. hovertime = "1000";
  285. isContainer = "1";
  286. canSave = "1";
  287. canSaveDynamicFields = "0";
  288. };
  289. new GuiTextCtrl() {
  290. text = "Simulated Latency:";
  291. maxLength = "255";
  292. margin = "0 0 0 0";
  293. padding = "0 0 0 0";
  294. anchorTop = "1";
  295. anchorBottom = "0";
  296. anchorLeft = "1";
  297. anchorRight = "0";
  298. position = "0 68";
  299. extent = "91 18";
  300. minExtent = "8 2";
  301. horizSizing = "left";
  302. vertSizing = "bottom";
  303. profile = "NetGraphPacketLossProfile";
  304. visible = "1";
  305. active = "1";
  306. tooltipProfile = "GuiToolTipProfile";
  307. hovertime = "1000";
  308. isContainer = "1";
  309. canSave = "1";
  310. canSaveDynamicFields = "0";
  311. };
  312. new GuiTextCtrl() {
  313. text = "ms";
  314. maxLength = "255";
  315. margin = "0 0 0 0";
  316. padding = "0 0 0 0";
  317. anchorTop = "1";
  318. anchorBottom = "0";
  319. anchorLeft = "1";
  320. anchorRight = "0";
  321. position = "179 68";
  322. extent = "20 18";
  323. minExtent = "8 2";
  324. horizSizing = "left";
  325. vertSizing = "bottom";
  326. profile = "NetGraphPacketLossProfile";
  327. visible = "1";
  328. active = "1";
  329. tooltipProfile = "GuiToolTipProfile";
  330. hovertime = "1000";
  331. isContainer = "1";
  332. canSave = "1";
  333. canSaveDynamicFields = "0";
  334. };
  335. new GuiTextEditCtrl(NetGraphSimLatency) {
  336. historySize = "0";
  337. tabComplete = "0";
  338. sinkAllKeyEvents = "0";
  339. password = "0";
  340. passwordMask = "*";
  341. text = "0";
  342. maxLength = "1024";
  343. margin = "0 0 0 0";
  344. padding = "0 0 0 0";
  345. anchorTop = "1";
  346. anchorBottom = "0";
  347. anchorLeft = "1";
  348. anchorRight = "0";
  349. position = "112 67";
  350. extent = "64 18";
  351. minExtent = "8 2";
  352. horizSizing = "right";
  353. vertSizing = "bottom";
  354. profile = "GuiTextEditProfile";
  355. visible = "1";
  356. active = "1";
  357. tooltipProfile = "GuiToolTipProfile";
  358. hovertime = "1000";
  359. isContainer = "1";
  360. canSave = "1";
  361. canSaveDynamicFields = "0";
  362. };
  363. new GuiTextCtrl() {
  364. text = "Simulated Packet Loss:";
  365. maxLength = "255";
  366. margin = "0 0 0 0";
  367. padding = "0 0 0 0";
  368. anchorTop = "1";
  369. anchorBottom = "0";
  370. anchorLeft = "1";
  371. anchorRight = "0";
  372. position = "0 83";
  373. extent = "111 18";
  374. minExtent = "8 2";
  375. horizSizing = "left";
  376. vertSizing = "bottom";
  377. profile = "NetGraphPacketLossProfile";
  378. visible = "1";
  379. active = "1";
  380. tooltipProfile = "GuiToolTipProfile";
  381. hovertime = "1000";
  382. isContainer = "1";
  383. canSave = "1";
  384. canSaveDynamicFields = "0";
  385. };
  386. new GuiTextCtrl() {
  387. text = "%";
  388. maxLength = "255";
  389. margin = "0 0 0 0";
  390. padding = "0 0 0 0";
  391. anchorTop = "1";
  392. anchorBottom = "0";
  393. anchorLeft = "1";
  394. anchorRight = "0";
  395. position = "179 84";
  396. extent = "20 18";
  397. minExtent = "8 2";
  398. horizSizing = "left";
  399. vertSizing = "bottom";
  400. profile = "NetGraphPacketLossProfile";
  401. visible = "1";
  402. active = "1";
  403. tooltipProfile = "GuiToolTipProfile";
  404. hovertime = "1000";
  405. isContainer = "1";
  406. canSave = "1";
  407. canSaveDynamicFields = "0";
  408. };
  409. new GuiTextEditCtrl(NetGraphSimPacket) {
  410. historySize = "0";
  411. tabComplete = "0";
  412. sinkAllKeyEvents = "0";
  413. password = "0";
  414. passwordMask = "*";
  415. text = "0";
  416. maxLength = "1024";
  417. margin = "0 0 0 0";
  418. padding = "0 0 0 0";
  419. anchorTop = "1";
  420. anchorBottom = "0";
  421. anchorLeft = "1";
  422. anchorRight = "0";
  423. position = "112 85";
  424. extent = "64 18";
  425. minExtent = "8 2";
  426. horizSizing = "right";
  427. vertSizing = "bottom";
  428. profile = "GuiTextEditProfile";
  429. visible = "1";
  430. active = "1";
  431. command = "if(NetGraphSimLatency.text $= \"\" || NetGraphSimLatency.text < 0)\n{\n NetGraphSimLatency.text = 0;\n}\n\nif(NetGraphSimPacket.text $= \"\" || NetGraphSimPacket.text < 0)\n{\n NetGraphSimLatency.text = 0;\n}\nelse if(NetGraphSimPacket.text > 100)\n{\n NetGraphSimPacket.text = 100;\n}\n\nnetSimulateLag( NetGraphSimLatency.text, NetGraphSimPacket.text );";
  432. tooltipProfile = "GuiToolTipProfile";
  433. hovertime = "1000";
  434. isContainer = "1";
  435. canSave = "1";
  436. canSaveDynamicFields = "0";
  437. };
  438. };
  439. };
  440. //--- OBJECT WRITE END ---
  441. // Functions
  442. function toggleNetGraph()
  443. {
  444. if(!$NetGraph::isInitialized)
  445. {
  446. NetGraph::updateStats();
  447. $NetGraph::isInitialized = true;
  448. }
  449. if(!Canvas.isMember(NetGraphGui))
  450. {
  451. Canvas.add(NetGraphGui);
  452. }
  453. else
  454. {
  455. Canvas.remove(NetGraphGui);
  456. netSimulateLag( 0, 0 );
  457. }
  458. }
  459. function NetGraph::updateStats()
  460. {
  461. $NetGraphThread = NetGraph.schedule(32, "updateStats");
  462. if(!$Stats::netGhostUpdates)
  463. return;
  464. if(isobject(NetGraph))
  465. {
  466. if(isobject(ServerConnection))
  467. NetGraph.addDatum(0,ServerConnection.getGhostsActive());
  468. GhostsActive.setText("Ghosts Active: " @ ServerConnection.getGhostsActive());
  469. NetGraph.addDatum(1,$Stats::netGhostUpdates);
  470. GhostUpdates.setText("Ghost Updates: " @ $Stats::netGhostUpdates);
  471. NetGraph.addDatum(2,$Stats::netBitsSent);
  472. BitsSent.setText("Bytes Sent: " @ $Stats::netBitsSent);
  473. NetGraph.addDatum(3,$Stats::netBitsReceived);
  474. BitsReceived.setText("Bytes Received: " @ $Stats::netBitsReceived);
  475. NetGraph.matchScale(2,3);
  476. NetGraph.addDatum(4,ServerConnection.getPing());
  477. Latency.setText("Latency: " @ ServerConnection.getPing());
  478. NetGraph.addDatum(5,ServerConnection.getPacketLoss());
  479. PacketLoss.setText("Packet Loss: " @ ServerConnection.getPacketLoss());
  480. }
  481. }
  482. function NetGraph::toggleKey()
  483. {
  484. if(!GhostsActive.visible)
  485. {
  486. GhostsActive.visible = 1;
  487. GhostUpdates.visible = 1;
  488. BitsSent.visible = 1;
  489. BitsReceived.visible = 1;
  490. Latency.visible = 1;
  491. PacketLoss.visible = 1;
  492. }
  493. else
  494. {
  495. GhostsActive.visible = 0;
  496. GhostUpdates.visible = 0;
  497. BitsSent.visible = 0;
  498. BitsReceived.visible = 0;
  499. Latency.visible = 0;
  500. PacketLoss.visible = 0;
  501. }
  502. }
  503. function NetGraphSimLatency::onReturn(%this)
  504. {
  505. NetGraph.updateNetworkSimulation();
  506. }
  507. function NetGraphSimPacket::onReturn(%this)
  508. {
  509. NetGraph.updateNetworkSimulation();
  510. }
  511. function NetGraph::updateNetworkSimulation(%this)
  512. {
  513. %latency = NetGraphSimLatency.getText();
  514. if(%latency $= "" || %latency < 0)
  515. {
  516. NetGraphSimLatency.text = 0;
  517. %latency = 0;
  518. }
  519. %packetLoss = NetGraphSimPacket.getText();
  520. if(%packetLoss $= "" || %packetLoss < 0)
  521. {
  522. NetGraphSimLatency.text = 0;
  523. %packetLoss = 0;
  524. }
  525. else if(%packetLoss > 100)
  526. {
  527. NetGraphSimPacket.text = 100;
  528. %packetLoss = 100;
  529. }
  530. netSimulateLag( %latency, %packetLoss );
  531. }