当前位置: 首页>>代码示例>>Python>>正文


Python PriorityQueue._Clear方法代码示例

本文整理汇总了Python中PriorityQueue.PriorityQueue._Clear方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue._Clear方法的具体用法?Python PriorityQueue._Clear怎么用?Python PriorityQueue._Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PriorityQueue.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue._Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Entity_Manager

# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import _Clear [as 别名]
class Entity_Manager(object):
    def __init__(self):
        #This allows access to specific entities
        #sEntityType:(sEntityName:entity)
        self._dEntities = {}

        #This orders the entities so that the ones with the highest draw
        #   priority will be first in the list (highest priority is 0.)
        self._pqDrawableEntities = PQ()

    def _Empty_Entity_Containers(self):
        """This is for cleaning up the Entity Containers for when we need to change
        the buttons for the next state."""

        #If this was in C++ (Python may be fine without the proposal below)
        #I think it'd be good to loop through all of the entities and give each of them to a system that would
        #check to see if their component dictionaries contained a component that needs cleaned up a special way.
        
        self._dEntities.clear()

        self._pqDrawableEntities._Clear()

    def _Add_Entity(self, entity):
        """This will add entities into our dictionary of lists of entities.
        And it will also add the Entity to the PriorityQueue so that it can be drawn.
        @param entity This should be an actual instance of the Entity class. So it
            holds components and that's about it.
        @param iPriority This is the draw priority for the Entity that it being
            added. Zero is the highest draw priority (gets drawn first,) -1 means
            the Entity doesn't need added to the PriorityQueue."""

        if self._dEntities.get(entity._Get_Type(), None) == None:
            #If there wasn't already a dictionary, then we'll make one
            self._dEntities[entity._Get_Type()] = {}

        #This will overwrite or create a new entity of the given name.
        self._dEntities[entity._Get_Type()][entity._Get_Name()] = entity

        #THis filters out the entities with -1 priorities to being added
        #   To the list of drawable Entities.
        if (entity._Get_Draw_Priority() != -1):
            self._pqDrawableEntities._Add_Entity(entity)

        

    def _Remove_Entity(self, sEntityTypeName, sEntityName):
        """When an entity expires it will be removed with this."""
        #This just prevents errors from occuring in the dictionary accessing.
        if self._dEntities.get(sEntityTypeName,None) != None:
            self._dEntities[sEntityTypeName].pop(sEntityName)

        #Entities that aren't within the priority queue will be ignored.
        self._pqDrawableEntities._Remove_Entity(entity._Get_Name(), entity._Get_Type())

    def _Get_Entity(self, sEntityTypeName, sEntityName):
        """This is for retrieving entities from the dictionary. It so far
        is only used for the System functions in the ChangeState() function."""

        if self._dEntities.get(sEntityTypeName,None) != None    \
           and self._dEntities[sEntityTypeName].get(sEntityName,None) != None:

            return self._dEntities[sEntityTypeName][sEntityName]

        #If the entity wasn't found, we'll look for it within the
        #   containers of entities.
        elif self._dEntities.get("EntityManager") != None:

            for key in self._dEntities["EntityManager"].keys():

                tmp = self._dEntities["EntityManager"][key]._Get_Entity(sEntityTypeName, sEntityName)

                #This checks to see if the entity was in that container
                if tmp != None:

                    return tmp

        #If the entity still wasn't found, then it doesn't exist at this point in time
        else:
            print "EntityType: %s, EntityName: %s doesn't exist in the EntityManager's container of entities!" % (sEntityTypeName, sEntityName)

        return None

    def _Call_System_Func(self, sSystemFuncName, lEntities):
        """This will call a system function from the systems.py file. And it will provide the appropriate entities that are needed to be passed to the function.
        This will also return a variable from the system function.
        @param sSystemFuncName This is the name of the System function that is to be called.
        @param lEntities This is a list of tuples containing information on the entities
            that will have to be passed to the system function that is to be called. This allows
            systems to act upon entities, so the components can be changed."""

        #If one entity to pass to the systemFunc
        #lEntities == [(sEntityType, sEntityName, sComponentName)]
        #If two entities to pass to the systemFunc
        #lEntities == [(sEntityType, sEntityName, sComponentName),(sEntityType, sEntityName, sComponentName)]
        
        module = importlib.import_module('systems')
        systemFunc = getattr(module, sSystemFuncName)

        #I'm sure that this is suppose to be an empty list
        if lEntities == []:
#.........这里部分代码省略.........
开发者ID:WaffleTime,项目名称:TileGame,代码行数:103,代码来源:main.py


注:本文中的PriorityQueue.PriorityQueue._Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。