Ticket #66: gamestate_double_hash.2.patch

File gamestate_double_hash.2.patch, 3.4 KB (added by saritor, 10 years ago)

Changes Gamestate.objects to a double hash of map ids and then object ids. UPDATED for rev. 313

  • scripts/engine.py

     
    150150           @param instance: FIFE instance of object 
    151151           @return: Nothing 
    152152        """ 
    153          
    154         ref = self.game_state.getObjectById(obj.ID)  
     153 
     154        ref = self.game_state.getObjectById(obj.ID, self.game_state.currentMapName)  
    155155        if ref is None: 
    156156            # no, add it to the game state 
    157             obj.map_id = self.game_state.current_map 
    158             self.game_state.objects[obj.ID] = obj 
     157            self.game_state.objects[self.game_state.currentMapName][obj.ID] = obj 
    159158        else: 
    160159            # yes, use the current game state data 
    161160            obj.X = ref.X 
     
    179178           @param ident: ID of object 
    180179           @rtype: boolean 
    181180           @return: Status of result (True/False)""" 
    182         for i in self.game_state.getObjectsFromMap(self.game_state.current_map): 
     181        for i in self.game_state.getObjectsFromMap(self.game_state.currentMapName): 
    183182            if (i.ID == ident): 
    184183                # we found a match 
    185184                return i 
     
    194193           @return: List of text and callbacks""" 
    195194        actions=[] 
    196195        # note: ALWAYS check NPC's first! 
    197         obj = self.game_state.getObjectById(obj_id) 
     196        obj = self.game_state.getObjectById(obj_id, self.game_state.currentMapName) 
    198197         
    199198        if obj is not None: 
    200199            if obj.trueAttr("NPC"): 
     
    231230        """ Starts the PC talking to an NPC. """ 
    232231        # TODO: work more on this when we get NPCData and HeroData straightened 
    233232        # out 
    234         npc = self.game_state.getObjectById(npcInfo.ID) 
     233        npc = self.game_state.getObjectById(npcInfo.ID, self.game_state.currentMapName) 
    235234        self.game_state.PC.approach([npc.getLocation().\ 
    236235                                     getLayerCoordinates().x, \ 
    237236                                     npc.getLocation().\ 
  • scripts/gamestate.py

     
    3131           @type map: String 
    3232           @param map: The map name. 
    3333           @returns: The list of objects on this map.""" 
    34         return [i for i in self.objects.values() if i.map_id == map_id] 
     34        return [i for i in self.objects[map_id].values() if map_id in self.objects] 
    3535     
    36     def getObjectById(self, id): 
     36    def getObjectById(self, obj_id, map_id): 
    3737        """Gets an object by it's id 
    3838           @type id: String 
    3939           @param id: The id of the object. 
    4040           @returns: The object or None.""" 
    41         if id in self.objects: 
    42             return self.objects[id] 
     41        if not map_id in self.objects: 
     42                    self.objects[map_id] = {} 
     43        if obj_id in self.objects[map_id]: 
     44            return self.objects[map_id][obj_id] 
    4345 
  • scripts/map.py

     
    130130        """Enable or disable a renderer. 
    131131           @return: None""" 
    132132        renderer = self.cameras['main'].getRenderer(str(r_name)) 
    133         renderer.setEnabled(not renderer.isEnabled()) 
    134  No newline at end of file 
     133        renderer.setEnabled(not renderer.isEnabled()) 
     134