diff --git a/README.md b/README.md index ac01ca9..0efa3d8 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,4 @@ The Python script is the file **ct_cmd.py** (in the game folder), you have to ed - Return your level (integer) * **Time management (temporization) : ct_sleep (delay)** - - delay : delay in seconds (float) + - delay : duration in seconds (float) diff --git a/codetower-23.blend b/codetower-23.blend index ee5a4e3..8cbdec5 100644 Binary files a/codetower-23.blend and b/codetower-23.blend differ diff --git a/ct.py b/ct.py index 77452a3..6108f92 100644 --- a/ct.py +++ b/ct.py @@ -35,6 +35,11 @@ import ct_map1 as ct_map # waves script # ############################################################################### +# Debug flag +scene = bge.logic.getCurrentScene() +scene.objects['Commands']['debug_fps']=False + +# Memory sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender # Dynamic import user file @@ -43,7 +48,6 @@ sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut # ct_cmd = importlib.import_module('ct_cmd') # User script (commands) -> segfault de Blender # UPBGE scene -scene = bge.logic.getCurrentScene() eevee = bpy.context.scene.eevee fps_time=0.0 @@ -139,7 +143,7 @@ def points_maj (cont): global fps_time - # Synchronisation des threads + # Synchronisation des threads : attente dela création d'une tour ou de l'apparition d'un minion while scene.objects['Terrain']['thread_cmd_lock'] == True: # print ("UPBGE : thread_cmd_lock =True") time.sleep(0.01) @@ -153,23 +157,33 @@ def points_maj (cont): # Texte de la vague if scene.objects['Map_text']['anim']: - if scene.objects['Map_text']['timer']>0: - scene.objects['Map_text'].worldPosition.x = scene.objects['Map_text']['position_init'][0]+(scene.objects['Map_text']['position_end'][0]-scene.objects['Map_text']['position_init'][0])*(scene.objects['Map_text']['timer']/120) - scene.objects['Map_text'].worldPosition.y = scene.objects['Map_text']['position_init'][1]+(scene.objects['Map_text']['position_end'][1]-scene.objects['Map_text']['position_init'][1])*(scene.objects['Map_text']['timer']/120) - scene.objects['Map_text'].worldPosition.z = scene.objects['Map_text']['position_init'][2]+(scene.objects['Map_text']['position_end'][2]-scene.objects['Map_text']['position_init'][2])*(scene.objects['Map_text']['timer']/120) - scene.objects['Map_text']['timer']-=1 - if scene.objects['Map_text']['timer']==0: + if scene.objects['Map_text']['timer']<120: + scene.objects['Map_text'].worldPosition.x += scene.objects['Map_text']['position_delta'][0] + scene.objects['Map_text'].worldPosition.y += scene.objects['Map_text']['position_delta'][1] + scene.objects['Map_text'].worldPosition.z += scene.objects['Map_text']['position_delta'][2] + # scene.objects['Map_text'].worldPosition.x = scene.objects['Map_text']['position_init'][0]+(scene.objects['Map_text']['position_end'][0]-scene.objects['Map_text']['position_init'][0])*(scene.objects['Map_text']['timer']/120) + # scene.objects['Map_text'].worldPosition.y = scene.objects['Map_text']['position_init'][1]+(scene.objects['Map_text']['position_end'][1]-scene.objects['Map_text']['position_init'][1])*(scene.objects['Map_text']['timer']/120) + # scene.objects['Map_text'].worldPosition.z = scene.objects['Map_text']['position_init'][2]+(scene.objects['Map_text']['position_end'][2]-scene.objects['Map_text']['position_init'][2])*(scene.objects['Map_text']['timer']/120) + print (scene.objects['Map_text']['position_init']) + print (scene.objects['Map_text']['timer']) + scene.objects['Map_text']['timer']+=1 + if int(scene.objects['Map_text']['timer'])>=120: scene.objects['Map_text'].color = color_text - scene.objects['Map_text'].worldPosition= scene.objects['Map_text']['position_end'] + scene.objects['Map_text'].worldPosition= scene.objects['Map_text']['position_init'] scene.objects['Map_text']['anim']=False + print (scene.objects['Map_text']['position_init']) + print (scene.objects['Map_text']['timer']) - # Gestion du FPS + # Gestion du FPS - Tous les tics if scene.objects['Commands']['debug_fps']: - if scene.objects['Points']['tics']%60 ==0: # Toutes les 60 tics - milliseconds = int(time.time() * 1000) - print (milliseconds-fps_time) - print ("Tics/second, coins :", milliseconds-fps_time, str(scene.objects['Points']['coins'])) - fps_time = milliseconds + # if scene.objects['Points']['tics']%60 ==0: # Toutes les 60 tics + milliseconds = int(time.time() * 1000) # Tous les tics + if milliseconds != fps_time: + fps = int(1000/(milliseconds-fps_time)) + else: + fps= "----" + print ("Durée entre deux tics (16 ms), fps (60), coins :", milliseconds-fps_time, fps, str(scene.objects['Points']['coins'])) + fps_time = milliseconds # Augmentation d'un niveau if scene.objects['Points']['coins']>=100: @@ -851,7 +865,6 @@ def applyRotationTo(obj, rx=None, ry=None, rz=None, Local=True): # Reset de la manipulation de la vue def manip_reset(): - # if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Terrain']['manip_mode']==0: scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx'] scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly'] scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz'] diff --git a/ct_config.xml b/ct_config.xml index cd730e0..d6a9fea 100644 --- a/ct_config.xml +++ b/ct_config.xml @@ -1,6 +1,6 @@ - 4.0 - True + 2.0 + False \ No newline at end of file diff --git a/ct_lib.py b/ct_lib.py index df8eaf3..bd073a6 100644 --- a/ct_lib.py +++ b/ct_lib.py @@ -189,11 +189,14 @@ def ct_minion_details(x,y,cat,level,body="Knight_m_A_common"): while scene.objects['Terrain']['run'] == False: time.sleep(0.01) - # Synchronisation des threads + # Synchronisation des threads : attente de la création d'une tour while scene.objects['Terrain']['thread_cmd_lock'] == True: # print ("ct_minion : thread_cmd_lock =True") time.sleep(0.01) + # Blocage des autres threads pendant l'apparition du minion + scene.objects['Terrain']['thread_cmd_lock'] = True + # Object 3D minion= scene.addObject(body, scene.objects['Terrain']) minion.worldScale=[0.25,0.25,0.25] @@ -231,6 +234,9 @@ def ct_minion_details(x,y,cat,level,body="Knight_m_A_common"): # minion.actuators['Steering'].distance=0.5 minion.actuators['Steering'].velocity=minion['speed_base']*scene.objects['Terrain']['speed'] + # Déblocage des autres threads après l'apparition du minion + scene.objects['Terrain']['thread_cmd_lock'] = False + # Destruction d'un minion def scn_minion_dead(cont): obj = cont.owner @@ -257,6 +263,9 @@ def scn_minion_affect(cont): obj['dist_last_x']=obj.worldPosition.x obj['dist_last_y']=obj.worldPosition.y + # Lod + # print(obj.currentLodLevel) + # Etats actif for debuff_i in obj['buff']: if debuff_i[1] <= 0: @@ -346,6 +355,7 @@ def ct_build_details(x,y, cat='Archer tower', tower_name="Tower", color=tower_pu tour.sensors['Near'].distance=tour['range'] tour.sensors['Near'].skippedTicks =round(1/(tour['speed']*scene.objects['Terrain']['speed'])) + # Déblocage des autres threads après la construction scene.objects['Terrain']['thread_cmd_lock'] = False return True @@ -484,11 +494,36 @@ def ct_map_text_wave(wave): scene.objects['Map_text']['Text']=("Wave " + str(wave)) scene.objects['Map_text'].setVisible(True,False) scene.objects['Map_text'].color = color_text_yellow - scene.objects['Map_text']['timer']=120 - scene.objects['Map_text']['position_init']=[8.37716, -2.39401, 5.56759] - scene.objects['Map_text']['position_end']=[11.1751, 5.99318, 0.480557] - scene.objects['Map_text'].worldPosition= scene.objects['Map_text']['position_init'] + scene.objects['Map_text']['timer']=0 + # scene.objects['Map_text']['position_init']=[8.37716, -2.39401, 5.56759] + # scene.objects['Map_text']['position_end']=[11.1751, 5.99318, 0.480557] + scene.objects['Map_text']['position_init']=[0,0,0] + scene.objects['Map_text']['position_init'][0]=scene.objects['Points'].worldPosition.x+(11.1751-11.5819) + scene.objects['Map_text']['position_init'][1]=scene.objects['Points'].worldPosition.y+(5.99318-7.25838) + scene.objects['Map_text']['position_init'][2]=scene.objects['Points'].worldPosition.z+(0.480557-1.23784) + scene.objects['Map_text']['position_delta']=[-2.79794/120, -8.38719/120, 5.087033/120] + + # 11.5819 m + # 7.25838 m + # 1.23784 m + + # scene.objects['Map_text']['position_end']=scene.objects['Map_text'].worldPosition + # scene.objects['Map_text']['position_init']=scene.objects['Map_text'].worldPosition + # scene.objects['Map_text']['position_init'][0]=scene.objects['Map_text']['position_end'][0]-scene.objects['Map_text']['position_delta'][0] + # scene.objects['Map_text']['position_init'][1]=scene.objects['Map_text']['position_end'][1]-scene.objects['Map_text']['position_delta'][1] + # scene.objects['Map_text']['position_init'][2]=scene.objects['Map_text']['position_end'][2]-scene.objects['Map_text']['position_delta'][2] + # scene.objects['Map_text'].worldPosition=scene.objects['Map_text']['position_init'] scene.objects['Map_text']['anim']=True + print (scene.objects['Map_text']['position_init']) + print (scene.objects['Map_text']['timer']) + + # scene.objects['Map_text']['position_end']=scene.objects['Map_text'].worldPosition + # scene.objects['Map_text']['position_init']=[0,0,0] + # scene.objects['Map_text']['position_init'][0]=scene.objects['Map_text']['position_end'][0]-scene.objects['Map_text']['position_delta'][0] + # scene.objects['Map_text']['position_init'][1]=scene.objects['Map_text']['position_end'][1]-scene.objects['Map_text']['position_delta'][1] + # scene.objects['Map_text']['position_init'][2]=scene.objects['Map_text']['position_end'][2]-scene.objects['Map_text']['position_delta'][2] + # scene.objects['Map_text'].worldPosition=scene.objects['Map_text']['position_init'] + # scene.objects['Map_text']['anim']=True # Texte de carte def ct_map_text(text):