Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Manager.py 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. #"""
  2. #Modified BGE Gameplay Recorder Version 2
  3. #originally written by Nicholas Anderson, aka Red Frost Games.
  4. #"""
  5. #####Tweakables###############
  6. #Watch out! These numbers might bite!
  7. frame_rate = 60 #Set this to the framerate of your game.
  8. optimization = 1 #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
  9. recording_cutoff = 7300 #3600 #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
  10. recorder_state = 1 #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
  11. allow_playback_break = True #Allow the player to resume playing from the position in the recording.
  12. #####Sensor names#############
  13. record_sensor = "Record"
  14. save_recording_sensor = "Save"
  15. load_recording_sensor = "Load"
  16. track_left_sensor = "Left"
  17. track_right_sensor = "Right"
  18. break_sensor = "Break"
  19. ##############################
  20. from bge import logic
  21. import Record
  22. import SortData
  23. cont = logic.getCurrentController()
  24. own = cont.owner
  25. cont.sensors[record_sensor].skippedTicks = optimization
  26. dict = logic.globalDict
  27. #dict['recorder_on'] = recorder_on
  28. recorder_on = dict.get('recorder_on')
  29. own['recorder_on'] = recorder_on
  30. #print("recorder on: ", recorder_on)
  31. if recorder_on == 1:
  32. #----
  33. scene = logic.getCurrentScene()
  34. scene_list = logic.getSceneList()
  35. camList = scene.cameras
  36. followcam = camList["followcam"]
  37. freecam = camList["freecam"]
  38. skater = scene.objects["Char4"]
  39. cube = scene.objects["control_cube.002"]
  40. deck = scene.objects["deck"]
  41. trucks = scene.objects["trucks"]
  42. replay_cam_axis = own['replay_cam_axis']
  43. cam = own.actuators['Camera']
  44. #----
  45. joybutsens = "joyBut"
  46. #butt = cont.sensors[joybutsens]
  47. #aXis = cont.sensors["joysticksens"]
  48. #bk_but = 4
  49. back_on = dict['bkBut']
  50. #a_but = 0
  51. a_on = dict['aBut']
  52. #b_but = 1
  53. b_on = dict['bBut']
  54. #print(a on)
  55. last_back = own['last_back_but']
  56. #last_back = own['last_a_but']
  57. # reduction = 400000
  58. # axisTh = 0.03
  59. # lt = 4
  60. # rt = 5
  61. # lts_pr = 7
  62. # rts_pr = 8
  63. # lar_lts = 0
  64. # uad_lts = 1
  65. # lar_rts = 2
  66. # uad_rts = 3
  67. #lts_pr = 7
  68. #rts_pr = 8
  69. # lTrig = aXis.axisValues[lt] / reduction
  70. # rTrig = aXis.axisValues[rt] / reduction
  71. # lLR = aXis.axisValues[lar_lts] / reduction
  72. # lUD = aXis.axisValues[uad_lts] / reduction
  73. # rLR = aXis.axisValues[lar_rts] / reduction
  74. # rUD = aXis.axisValues[uad_rts] / reduction
  75. # ltsBut = butt.getButtonStatus(lts_pr)
  76. # rtsBut = butt.getButtonStatus(rts_pr)
  77. #
  78. lLR = dict['lLR']
  79. lUD = dict['lUD']
  80. rLR = dict['rLR']
  81. rUD = dict['rUD']
  82. lTrig = dict['lTrig']
  83. rTrig = dict['rTrig']
  84. aBut = dict['aBut']
  85. bBut = dict['bBut']
  86. xBut = dict['xBut']
  87. yBut = dict['yBut']
  88. lBump = dict['lBump']
  89. rBump = dict['rBump']
  90. bkBut = dict['bkBut']
  91. stBut = dict['stBut']
  92. xbBut = dict['xbBut']
  93. ltsBut = dict['ltsBut']
  94. rtsBut = dict['rtsBut']
  95. ldPad = dict['ldPad']
  96. rdPad = dict['rdPad']
  97. udPad = dict['udPad']
  98. ddPad = dict['ddPad']
  99. #trigs results range 0 - .08
  100. #print(lTrig, rTrig)
  101. #if cont.sensors[record_sensor].positive:
  102. if own["playback"] != True:
  103. Record.main(recording_cutoff)
  104. if cont.sensors[save_recording_sensor].positive:
  105. SortData.writeData.saveAll()
  106. #if cont.sensors[load_recording_sensor].positive or (cube["sel"] == 1 and cube["last_sel"] == 0):
  107. if own['back_state'] == 1 and back_on == 1 and last_back == 0:
  108. cube["last_sel"] == 1
  109. SortData.writeData.saveAll()
  110. own["playback"] = True
  111. own["playbackBroken"] = False
  112. freecam.worldPosition = own.worldPosition
  113. followcam.worldPosition = own.worldPosition
  114. if own["playback"]:
  115. Record.loadData()
  116. #..................
  117. if cont.sensors[track_left_sensor].positive:
  118. own["objIndex"] -= 2
  119. logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
  120. if cont.sensors[track_right_sensor].positive:
  121. own["objIndex"] += 2
  122. logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
  123. if own["playback"] == True:
  124. if rTrig > .01 and rTrig < .02:
  125. own["objIndex"] += 2
  126. logic.setLogicTicRate(frame_rate*.5)
  127. if (rTrig >= .02 and rTrig < .06) or own['loop_play'] == 1:
  128. own["objIndex"] += 2
  129. logic.setLogicTicRate(frame_rate*1)
  130. #print(own['objIndex'])
  131. if rTrig >= .06 and rTrig < .09:
  132. own["objIndex"] += 2
  133. logic.setLogicTicRate(frame_rate*1.5)
  134. if lTrig > .01 and lTrig < .02:
  135. own["objIndex"] -= 2
  136. logic.setLogicTicRate(frame_rate*.5)
  137. if lTrig >= .02 and lTrig < .06:
  138. own["objIndex"] -= 2
  139. logic.setLogicTicRate(frame_rate*1)
  140. if lTrig >= .06 and lTrig < .09:
  141. if own['loop_play'] == 1:
  142. own["objIndex"] -= 6
  143. #logic.setLogicTicRate(frame_rate*1.5)
  144. else:
  145. own["objIndex"] -= 2
  146. logic.setLogicTicRate(frame_rate*1.5)
  147. if b_on == True:
  148. print("bbut_on")
  149. own['objIndex'] = 0
  150. own['valueIndex'] = 0
  151. logic.setLogicTicRate(frame_rate*1)
  152. #....................
  153. if allow_playback_break:
  154. if own['back_state'] == 0 and back_on == 1 and last_back == 0:
  155. own["playbackBroken"] = True
  156. own["playback"] = False
  157. #print("break - add hud, remove stance (back_state == False)")
  158. #cont.activate(own.actuators['add_hud'])
  159. #cont.activate(own.actuators['remove_stance'])
  160. #removescene = cont.actuators["remove_hud"]
  161. #removescene.scene = "replay_HUD"
  162. #addscene = cont.actuators["add_hud"]
  163. #addscene.scene = "stance"
  164. #cont.activate(addscene)
  165. #cont.activate(removescene)
  166. elif own["playbackBroken"] and back_on == 0:
  167. Record.breakOut()
  168. #cont.activate(own.actuators['remove_hud'])
  169. #cont.activate(own.actuators['add_stance'])
  170. #addscene = cont.actuators["add_hud"]
  171. #addscene.scene = "replay_HUD"
  172. #removescene = cont.actuators["remove_hud"]
  173. #removescene.scene = "stance"
  174. #cont.activate(addscene)
  175. #cont.activate(removescene)
  176. logic.setLogicTicRate(frame_rate)
  177. #set value index
  178. own.state = recorder_state
  179. own["playbackBroken"] = False
  180. skater.stopAction(9999)
  181. deck.stopAction(9999)
  182. trucks.stopAction(9999)
  183. cont.activate(own.actuators['replayCam'])
  184. print("unbreak")
  185. own['loop_play'] = 0
  186. #own['valueIndex'] = 0
  187. #own["objIndex"] += 2
  188. #logic.setLogicTicRate(frame_rate*1)
  189. #own['objectIndex'] = 0
  190. #print("valueIndex = ", own['valueIndex'])
  191. if back_on == 1 and own['back_but'] == 0:
  192. print("change back state")
  193. if own['back_state'] == True:
  194. own['back_state'] = False
  195. #elif own['back_state'] == False:
  196. else:
  197. own['back_state'] = True
  198. ###
  199. if own['last_playback'] != own['playback']:
  200. if own['last_playback'] == True:
  201. cont.activate(own.actuators['remove_hud'])
  202. cont.activate(own.actuators['add_stance'])
  203. own['camnum'] = 0
  204. cam = camList["Camera.003"]
  205. scene.active_camera = cam
  206. print("turning replay off", own['playback'])
  207. if own['last_playback'] == False:
  208. print("turning replay on", own['playback'])
  209. cont.activate(own.actuators['add_hud'])
  210. cont.activate(own.actuators['remove_stance'])
  211. own['objIndex'] = 0
  212. own['valueIndex'] = 3
  213. logic.setLogicTicRate(frame_rate*1)
  214. ####
  215. if a_on == 1 and own['a_but'] == False:
  216. if own['loop_play'] == 1:
  217. own['loop_play'] = 0
  218. else:
  219. own['loop_play'] = 1
  220. if rLR > .05 and own["playback"]:
  221. act = cont.actuators["replayCam"]
  222. if rLR > .07:
  223. act.dLoc = [ .06, 0.0, 0.0]
  224. else:
  225. act.dLoc = [ .03, 0.0, 0.0]
  226. #cont.deactivate(own.actuators['Camera'])
  227. cont.activate(own.actuators['replayCam'])
  228. #print("move")
  229. elif rLR < -.05 and own["playback"]:
  230. act = cont.actuators["replayCam"]
  231. if rLR < -.07:
  232. act.dLoc = [ -.06, 0.0, 0.0]
  233. else:
  234. act.dLoc = [ -.03, 0.0, 0.0]
  235. #cont.deactivate(own.actuators['Camera'])
  236. #act.damping = 6
  237. cont.activate(own.actuators['replayCam'])
  238. #print("move")
  239. else:
  240. #pass
  241. cont.deactivate(own.actuators['replayCam'])
  242. #cont.activate(own.actuators['Camera'])
  243. #print("back state: ", own['back_state'], "last_back_but: ", own['last_back_but'], "back_but :", own['back_but'])
  244. #integer
  245. #
  246. #0 = +X axis
  247. #
  248. #1 = +Y axis
  249. #
  250. #2 = +Z axis
  251. #
  252. #3 = -X axis
  253. #
  254. #4 = -Y axis
  255. #
  256. #5 = -Z axis
  257. # if rLR > .05 and own["playback"]:
  258. # if own['last_rtsBut'] == True and rtsBut == False:
  259. # if replay_cam_axis == 0:
  260. # replay_cam_axis = 1
  261. # elif replay_cam_axis == 1:
  262. # replay_cam_axis = 3
  263. # elif replay_cam_axis == 3 :
  264. # replay_cam_axis = 4
  265. # elif replay_cam_axis == 4:
  266. # replay_cam_axis = 0
  267. # cam.axis = replay_cam_axis
  268. # cont.activate(cam)
  269. # print("set replay_cam_axis: ", replay_cam_axis)
  270. # own['replay_cam_axis'] = replay_cam_axis
  271. if own['last_ltsBut'] == True and ltsBut == False and own['playback']:
  272. # get camera named SecurityCam
  273. if own['camnum'] == 1:
  274. own['camnum'] = 2
  275. elif own['camnum'] == 0:
  276. own['camnum'] = 1
  277. elif own['camnum'] == 2:
  278. own['camnum'] = 0
  279. if own['last_rtsBut'] == True and rtsBut == False and own['playback']:
  280. # get camera named SecurityCam
  281. if "replay_HUD" in scene_list:
  282. cont.activate(own.actuators['remove_hud'])
  283. else:
  284. cont.activate(own.actuators['add_hud'])
  285. if own['camnum'] == 1 and own['playback']:
  286. scene.active_camera = followcam
  287. #################
  288. camspeed1 = .04 #.015
  289. camspeed2 = .1 #.055
  290. camrot1 = .02 #.005
  291. camrot2 = .04 #.02
  292. #up
  293. if lUD < -0.080:
  294. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  295. cont.activate(followcam.actuators["up"])
  296. #print("fastup")
  297. else:
  298. cont.deactivate(followcam.actuators["up"])
  299. # #down
  300. if lUD > .080:
  301. followcam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  302. cont.activate(followcam.actuators["down"])
  303. else:
  304. cont.deactivate(followcam.actuators["down"])
  305. # #left
  306. if lLR < -0.080:
  307. followcam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  308. cont.activate(followcam.actuators["left"])
  309. else:
  310. cont.deactivate(followcam.actuators["left"])
  311. # #right
  312. if lLR > 0.080:
  313. followcam.actuators["right"].dLoc = [camspeed2, 0, 0]
  314. cont.activate(followcam.actuators["right"])
  315. else:
  316. cont.deactivate(followcam.actuators["right"])
  317. #up
  318. if rUD < -0.080:
  319. followcam.actuators["rotup"].dLoc = [0, 0, camrot2]
  320. cont.activate(followcam.actuators["rotup"])
  321. #print("uppppppppppppppppppppppppppp")
  322. else:
  323. cont.deactivate(followcam.actuators["rotup"])
  324. # #down
  325. if rUD > .080:
  326. followcam.actuators["rotdown"].dLoc = [0, 0, -camrot2]
  327. cont.activate(followcam.actuators["rotdown"])
  328. else:
  329. cont.deactivate(followcam.actuators["rotdown"])
  330. # #left
  331. if rLR < -0.080:
  332. followcam.actuators["rotleft"].dRot = [0, 0, camrot2]
  333. cont.activate(followcam.actuators["rotleft"])
  334. else:
  335. cont.deactivate(followcam.actuators["rotleft"])
  336. # #right
  337. if rLR > 0.080:
  338. followcam.actuators["rotright"].dRot = [0, 0, -camrot2]
  339. cont.activate(followcam.actuators["rotright"])
  340. else:
  341. cont.deactivate(followcam.actuators["rotright"])
  342. #*********************************************
  343. if lUD > -0.080 and lUD < -0.030:
  344. followcam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  345. cont.activate(followcam.actuators["up"])
  346. #print(lUD)
  347. else:
  348. cont.deactivate(followcam.actuators["up"])
  349. # #down
  350. if lUD < .080 and lUD > .03:
  351. followcam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  352. cont.activate(followcam.actuators["down"])
  353. else:
  354. cont.deactivate(followcam.actuators["down"])
  355. # #left
  356. if lLR > -0.080 and lLR < -0.030:
  357. followcam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  358. cont.activate(followcam.actuators["left"])
  359. else:
  360. cont.deactivate(followcam.actuators["left"])
  361. # #right
  362. if lLR < .080 and lLR > .03:
  363. followcam.actuators["right"].dLoc = [camspeed1, 0, 0]
  364. cont.activate(followcam.actuators["right"])
  365. else:
  366. cont.deactivate(followcam.actuators["right"])
  367. #up
  368. if rUD > -0.080 and rUD < -0.030:
  369. followcam.actuators["rotup"].dRot = [camrot1, 0, 0]
  370. cont.activate(followcam.actuators["rotup"])
  371. else:
  372. cont.deactivate(followcam.actuators["rotup"])
  373. # #down
  374. if rUD < .080 and rUD > .03:
  375. followcam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  376. cont.activate(followcam.actuators["rotdown"])
  377. else:
  378. cont.deactivate(followcam.actuators["rotdown"])
  379. # #left
  380. if rLR > -0.080 and rLR < -0.030:
  381. followcam.actuators["rotleft"].dRot = [0, 0, camrot1]
  382. cont.activate(followcam.actuators["rotleft"])
  383. else:
  384. cont.deactivate(followcam.actuators["rotleft"])
  385. # #right
  386. if rLR < .080 and rLR > .03:
  387. followcam.actuators["rotright"].dRot = [0, 0, -camrot1]
  388. cont.activate(followcam.actuators["rotright"])
  389. else:
  390. cont.deactivate(followcam.actuators["rotright"])
  391. #################
  392. if own['camnum'] == 2 and own['playback']:
  393. scene.active_camera = freecam
  394. #act = freecam.actuators[
  395. camspeed1 = .015
  396. camspeed2 = .055
  397. camrot1 = .005
  398. camrot2 = .02
  399. #up
  400. if lUD < -0.080:
  401. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
  402. cont.activate(freecam.actuators["up"])
  403. #print("fastup")
  404. else:
  405. cont.deactivate(freecam.actuators["up"])
  406. # #down
  407. if lUD > .080:
  408. freecam.actuators["down"].dLoc = [ 0, 0, camspeed2]
  409. cont.activate(freecam.actuators["down"])
  410. else:
  411. cont.deactivate(freecam.actuators["down"])
  412. # #left
  413. if lLR < -0.080:
  414. freecam.actuators["left"].dLoc = [-camspeed2, 0, 0]
  415. cont.activate(freecam.actuators["left"])
  416. else:
  417. cont.deactivate(freecam.actuators["left"])
  418. # #right
  419. if lLR > 0.080:
  420. freecam.actuators["right"].dLoc = [camspeed2, 0, 0]
  421. cont.activate(freecam.actuators["right"])
  422. else:
  423. cont.deactivate(freecam.actuators["right"])
  424. #up
  425. if rUD < -0.080:
  426. freecam.actuators["rotup"].dRot = [camrot2, 0, 0]
  427. cont.activate(freecam.actuators["rotup"])
  428. else:
  429. cont.deactivate(freecam.actuators["rotup"])
  430. # #down
  431. if rUD > .080:
  432. freecam.actuators["rotdown"].dRot = [-camrot2, 0, 0]
  433. cont.activate(freecam.actuators["rotdown"])
  434. else:
  435. cont.deactivate(freecam.actuators["rotdown"])
  436. # #left
  437. if rLR < -0.080:
  438. freecam.actuators["rotleft"].dRot = [0, 0, camrot2]
  439. cont.activate(freecam.actuators["rotleft"])
  440. else:
  441. cont.deactivate(freecam.actuators["rotleft"])
  442. # #right
  443. if rLR > 0.080:
  444. freecam.actuators["rotright"].dRot = [0, 0, -camrot2]
  445. cont.activate(freecam.actuators["rotright"])
  446. else:
  447. cont.deactivate(freecam.actuators["rotright"])
  448. #*********************************************
  449. if lUD > -0.080 and lUD < -0.030:
  450. freecam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
  451. cont.activate(freecam.actuators["up"])
  452. #print(lUD)
  453. else:
  454. cont.deactivate(freecam.actuators["up"])
  455. # #down
  456. if lUD < .080 and lUD > .03:
  457. freecam.actuators["down"].dLoc = [ 0, 0, camspeed1]
  458. cont.activate(freecam.actuators["down"])
  459. else:
  460. cont.deactivate(freecam.actuators["down"])
  461. # #left
  462. if lLR > -0.080 and lLR < -0.030:
  463. freecam.actuators["left"].dLoc = [-camspeed1, 0, 0]
  464. cont.activate(freecam.actuators["left"])
  465. else:
  466. cont.deactivate(freecam.actuators["left"])
  467. # #right
  468. if lLR < .080 and lLR > .03:
  469. freecam.actuators["right"].dLoc = [camspeed1, 0, 0]
  470. cont.activate(freecam.actuators["right"])
  471. else:
  472. cont.deactivate(freecam.actuators["right"])
  473. #up
  474. if rUD > -0.080 and rUD < -0.030:
  475. freecam.actuators["rotup"].dRot = [camrot1, 0, 0]
  476. cont.activate(freecam.actuators["rotup"])
  477. else:
  478. cont.deactivate(freecam.actuators["rotup"])
  479. # #down
  480. if rUD < .080 and rUD > .03:
  481. freecam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
  482. cont.activate(freecam.actuators["rotdown"])
  483. else:
  484. cont.deactivate(freecam.actuators["rotdown"])
  485. # #left
  486. if rLR > -0.080 and rLR < -0.030:
  487. freecam.actuators["rotleft"].dRot = [0, 0, camrot1]
  488. cont.activate(freecam.actuators["rotleft"])
  489. else:
  490. cont.deactivate(freecam.actuators["rotleft"])
  491. # #right
  492. if rLR < .080 and rLR > .03:
  493. freecam.actuators["rotright"].dRot = [0, 0, -camrot1]
  494. cont.activate(freecam.actuators["rotright"])
  495. else:
  496. cont.deactivate(freecam.actuators["rotright"])
  497. ########################################
  498. if own['camnum'] == 0:
  499. cam = camList["Camera.003"]
  500. scene.active_camera = cam
  501. valueIndex = own['valueIndex']
  502. n = (valueIndex / recording_cutoff) * 1000
  503. n = int(round(n))
  504. #n = 10
  505. #print("n: ", n, "--", valueIndex, recording_cutoff)
  506. #dict = logic.globalDict #Get the global dictionary
  507. dict['playhead'] = n
  508. own['last_back_but'] = own['back_but']
  509. own['back_but'] = back_on
  510. own['last_a_but'] = own['a_but']
  511. own['a_but'] = a_on
  512. own['last_ltsBut'] = ltsBut
  513. own['last_rtsBut'] = rtsBut
  514. own['last_playback'] = own['playback']