开发者

Python iteration too fast?

开发者 https://www.devze.com 2023-03-24 13:54 出处:网络
i have a really annoying problem with python. Essentially, i am creating a dynamic multiplayer system in python for Blender 3D GE.

i have a really annoying problem with python. Essentially, i am creating a dynamic multiplayer system in python for Blender 3D GE. Because of the nature of the problem, it is not a Blender issue. Here is what i am doing:

  1. looping through a list of client's to get each one's data to get DATA
  2. looping through another dict in that client's data to get TYPE
  3. looping through that dict (TYPE) to get ID

Here is an example of data:

    ['a1a1a4', 'NAME13' {'position': {7316: [[-0.23014163970947266, 7.419361591339111, -1.518202424049774], 'Sphere', 'Cube']}}]
    ['a1a1a4', 'NAME16' {'position': {5982: [开发者_如何学C[-0.23014163970947266, 4.099361419677734, -1.518202424049774], 'Sphere', 'Cube']}}]
    ['a1a1a4', 'NAME90' {'position': {7858: [[-0.23014163970947266, 4.659361362457275, -1.518202424049774], 'Sphere', 'Cube']}}]

Here is the processing code

    for set in data: # for each packaged set of data
        print(set)
        client_status = set[0]
        client_id = set[1]
        if client_status == "a1a1a4":

            client_dic = set[2]
            if client_id == gd["player_name"]:
                continue

            if client_id not in gd["registered_client_objects"]:
                gd["registered_client_objects"][client_id] = {}
                continue    
            #for each type in the client dic    
            for type in [i for i in client_dic if i == self.plugin_type]:

                #if relevant to current plugin
                if type in  gd["registered_client_objects"][client_id]:

                    #for the id of each plugin of this type sent from the client
                    for id in client_dic[type]:

                        #if the sender plugin isn't registered:
                        if not id in gd["registered_client_objects"][client_id][type]:
                            #creates a plugin listener for that sender                          
                            create_plugin(client_dic[type],id,type,client_id)   
                        else:
                            use_data(client_dic[type],id,client_id,type)

                else:
                    gd["registered_client_objects"][client_id][type] = {}
        elif client_status == "a1a1a5":
            remove_plugin(client_id)       

the end result is i use the ID to match some settings and retreive the appropriate item to apply some data on. The important part is "use data" which processes the data This works fine with two clients, but any more and the Game objects start to jitter. I think this means that i am assigning the data (position) to them too fast. The script runs 60 times a second, but because of the iterations within, i can assume that the iterations are the issue, as i receive no lag. Therefore: How can i slow down an iteration?

0

精彩评论

暂无评论...
验证码 换一张
取 消