diff --git a/ropy-07.blend b/ropy-07.blend index ac635cd..c75c328 100644 Binary files a/ropy-07.blend and b/ropy-07.blend differ diff --git a/rp.py b/rp.py index 0792482..82a50df 100644 --- a/rp.py +++ b/rp.py @@ -176,19 +176,12 @@ def terrain_run (): scene.objects['Run'].suspendPhysics() scene.objects['Run-Hl'].setVisible(False,False) scene.objects['Pause']. restorePhysics() - scene.objects['Pause-Hl'].setVisible(True,False) + scene.objects['Pause'].setVisible(True,False) # Démarrage de la map - if scene.objects['Terrain']['thread_run']==False: - scene.objects['Stop'].setVisible(True,False) - scene.objects['Stop']. restorePhysics() - runpy.run_module('rp_cmd', run_name='stop') # Stop du script utilisateur - - # Mise à zéro des compteurs - rp_map.map_reset() - - # Scripts utilisateur et vagues - scene.objects['Terrain']['thread_run']=True + if scene.objects['Terrain']['thread_cmd']==False: + scene.objects['Terrain']['thread_cmd']=True + rp_map.map_reset() # Mise à zéro des compteurs runpy.run_module('rp_cmd', run_name='start') # Execution du script utilisateur # Arrêt de la pause @@ -197,41 +190,27 @@ def terrain_run (): pass ## -# Arrêt et réinitialisation du cycle +# Arrêt et réinitialisation du cycle (forçage) ## def terrain_stop (): - - # Arrêt des threads utilisateurs - scene.objects['Terrain']['run']=False - scene.objects['Terrain']['thread_run']=False - runpy.run_module('rp_cmd', run_name='stop') # Stop du script utilisateur - - # Commandes - scene.objects['Pause'].setVisible(False,False) - scene.objects['Pause'].suspendPhysics() - scene.objects['Pause-Hl'].setVisible(False,False) - scene.objects['Run'].setVisible(True,False) - scene.objects['Run']. restorePhysics() - scene.objects['Stop'].setVisible(False,False) - scene.objects['Stop'].suspendPhysics() - scene.objects['Stop-Hl'].setVisible(False,False) - scene.objects['Cmd-text'].setVisible(False,False) + scene.objects['Terrain']['thread_cmd']=False ## -# Fin de la map +# Fin naturelle du cycle ## -def terrain_end (): - scene.objects['Terrain']['run']=False - scene.objects['Terrain']['thread_run']=False +def terrain_end (cont): + if cont.sensors['End cycle'].positive: + scene.objects['Terrain']['run']=False + runpy.run_module('rp_cmd', run_name='stop') # Fin du script utilisateur - # Commandes - scene.objects['Pause'].setVisible(False,False) - scene.objects['Pause-Hl'].setVisible(False,False) - scene.objects['Run'].setVisible(True,False) - scene.objects['Stop'].setVisible(False,False) - scene.objects['Stop-Hl'].setVisible(False,False) + # Commandes + scene.objects['Pause'].setVisible(False,False) + scene.objects['Pause'].suspendPhysics() + scene.objects['Pause-Hl'].setVisible(False,False) + scene.objects['Run'].setVisible(True,False) + scene.objects['Run']. restorePhysics() ## # Vitesse du jeu @@ -340,8 +319,6 @@ def cmd_init(): scene.objects['Pause'].setVisible(False,False) scene.objects['Pause'].suspendPhysics() scene.objects['Pause-Hl'].setVisible(False,False) - scene.objects['Stop'].setVisible(False,False) - scene.objects['Stop'].suspendPhysics() scene.objects['Stop-Hl'].setVisible(False,False) scene.objects['Objective-Hl'].setVisible(False,False) scene.objects['Doc-cmd-Hl'].setVisible(False,False) @@ -426,9 +403,8 @@ def cmd_hl(cont): # Stop if obj.name=="Stop": - if scene.objects['Terrain']['thread_run']==True: - scene.objects['Stop'].setVisible(False,False) - scene.objects['Stop-Hl'].setVisible(True,False) + scene.objects['Stop'].setVisible(False,False) + scene.objects['Stop-Hl'].setVisible(True,False) # Text text_hl ={"Run":"Exécuter (F5)", @@ -475,9 +451,8 @@ def cmd_hl(cont): # Stop if obj.name=="Stop": - if scene.objects['Terrain']['thread_run']==True: - scene.objects['Stop-Hl'].setVisible(False,False) - scene.objects['Stop'].setVisible(True,False) + scene.objects['Stop-Hl'].setVisible(False,False) + scene.objects['Stop'].setVisible(True,False) # Sound if obj.name=="NoSound-cmd" and scene.objects['Commands']['sound']==False: @@ -506,9 +481,11 @@ def cmd_click (cont): if obj.name=="Objective": sound_play (snd_grid) terrain_grid () + if obj.name=="Speed_up" or obj.name=="Speed_down": sound_play (snd_click) terrain_speed (obj) + if obj.name=="ResetView": sound_play (snd_click) manip_reset() @@ -517,6 +494,7 @@ def cmd_click (cont): if obj.name=="NoSound-cmd": sound_set () sound_play (snd_click) + if obj.name=="Doc-cmd": sound_play (snd_open) tablet_open () @@ -604,8 +582,9 @@ def mode(cont): # Touche F6 -> Stop / Init if JUST_ACTIVATED in keyboard.inputs[bge.events.F6KEY].queue: - if scene.objects['Terrain']['thread_run']==True: - terrain_stop () + terrain_stop () + # if scene.objects['Terrain']['thread_cmd']==True: # FIXME : bien utile ? + # terrain_stop () # Touche +/- du pad -> Vitesse + ou / if JUST_ACTIVATED in keyboard.inputs[bge.events.PADPLUSKEY].queue: @@ -711,7 +690,6 @@ def manip(cont): # distance_cam_past= math.sqrt(scene.objects['Camera']['past_ly']**2+scene.objects['Camera']['past_lz']**2) # distance_cam = math.sqrt((scene.objects['Camera'].worldPosition.y**2+scene.objects['Camera'].worldPosition.z**2)) # size_scale = (distance_cam/distance_cam_past) * 0.23 - print ("scene.objects['Camera']", scene.objects['Camera'].worldPosition.x, scene.objects['Camera'].worldPosition.y, scene.objects['Camera'].worldPosition.z) if scene.objects['Camera'].worldPosition.z >0.5 and scene.objects['Camera'].worldPosition.z <57: scene.objects['Camera'].applyMovement((0, 0, (delta_x+delta_y)*sensibilite_zoom), True) if scene.objects['Camera'].worldPosition.z <=0.5 or scene.objects['Camera'].worldPosition.z >=57 : @@ -740,7 +718,6 @@ def manip_wheel(cont): # # size_scale = (distance_cam/distance_cam_past) * 0.23 # size_scale = 0.2 # # size_scale = 0.23 - print ("scene.objects['Camera']", scene.objects['Camera'].worldPosition.x, scene.objects['Camera'].worldPosition.y, scene.objects['Camera'].worldPosition.z) if cont.sensors['WheelUp'].positive : scene.objects['Camera'].applyMovement((0, 0, -sensibilite_wheel), True) # if scene.objects['Mouse_main']['mouse_graphic']: @@ -880,8 +857,8 @@ def tablet_close (): scene.objects['Pause'].setVisible(False,False) scene.objects['Pause'].suspendPhysics() scene.objects['Pause-Hl'].setVisible(False,False) - scene.objects['Stop'].setVisible(False,False) - scene.objects['Stop'].suspendPhysics() + # scene.objects['Stop'].setVisible(False,False) + # scene.objects['Stop'].suspendPhysics() scene.objects['Stop-Hl'].setVisible(False,False) scene.objects['Objective-Hl'].setVisible(False,False) scene.objects['Doc-cmd-Hl'].setVisible(False,False) diff --git a/rp_cmd.py b/rp_cmd.py index 7b87734..cc18a5b 100644 --- a/rp_cmd.py +++ b/rp_cmd.py @@ -7,25 +7,6 @@ from rp_lib import * # Bibliothèque Ropy # @project: Ropy (Blender-EduTech) ############################################################################### -############################################################################### -# En: Threads management << DONT CHANGE THIS SECTION >> -# Fr: Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >> -############################################################################### - -scene = bge.logic.getCurrentScene() - -def start(): - scene.objects['Terrain']['thread_cmd']=True - thread_cmd_start(commands) - -def stop(): - thread_cmd_stop() - -def end(): - rp_sleep (2) - print ("Thread commands is arrived.") - scene.objects['Terrain']['thread_cmd']=False - ############################################################################### # Fonctions ############################################################################### @@ -38,10 +19,13 @@ def end(): def commands(): print("Go !!") + rp_sleep (0.5) rp_gauche() + rp_sleep (0.5) rp_avancer() - end() + rp_sleep (2) + rp_fin() ############################################################################### # En: Externals calls << DONT CHANGE THIS SECTION >> @@ -49,7 +33,7 @@ def commands(): ############################################################################### if __name__=='start': - start() + thread_cmd_start(commands) if __name__=='stop': - stop() + thread_cmd_stop() diff --git a/rp_config.xml b/rp_config.xml index a3e7f19..595e299 100644 --- a/rp_config.xml +++ b/rp_config.xml @@ -1,11 +1,11 @@ - 10.0 + 0.25 True - -4.190211772918701 - -12.807374954223633 - 12.73536491394043 + 0.0057830810546875 + -26.440298080444336 + 20.22315788269043 diff --git a/rp_lib.py b/rp_lib.py index 1de9ec6..bce0aa2 100644 --- a/rp_lib.py +++ b/rp_lib.py @@ -1,4 +1,4 @@ -import bge # Blender Game Engine (UPBGE) ++import bge # Blender Game Engine (UPBGE) import aud # Sounds import threading # Multithreading import trace @@ -129,6 +129,7 @@ def thread_stop(threads, type_txt): i +=1 if zombie_flag==False: print ("All threads",type_txt, "are closed.") + scene.objects['Terrain']['thread_cmd']=False return True else: print ("There are zombies threads",type_txt, ".") @@ -140,6 +141,17 @@ def thread_cmd_start(fct): def thread_cmd_stop(): thread_stop(threads_cmd, "commands") +def rp_end(): + rp_sleep (0.5) + print ("Thread commands is arrived.") + scene.objects['Terrain']['thread_cmd']=False + +def rp_fin(): + rp_end() + +def rp_quit(): + rp_end() + ############################################################################### # Sounds ###############################################################################