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


Python PriorityQueue._Add_Entity方法代码示例

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


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

示例1: Entity_Manager

# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import _Add_Entity [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

示例2: Entity_PQueue

# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import _Add_Entity [as 别名]
class Entity_PQueue(Entity):
    """Like the name says, this will store Entities. And it will update/render those entities accordingly."""
    def __init__(self, sName, sType, iDrawPriority, dAttribs):

        Entity.__init__(self, sName, sType, iDrawPriority, {})

        #This takes all of the entities out of the dComponents
        dEntities = dAttribs.pop("entity", {})

        #"These are the entities that are being loaded into the Entity_PQueue"
        #print dEntities

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

        #This is Pymunk's Space() class basically. But it's in a component.
        #   It will contain the collidable object for Entities.
        Entity._Add_Component( self, getClass("Collision_Space")( {"componentID":"EntityPool",     \
                                                                 "gravity":dAttribs["gravity"].split(",")} ) )

        #This will insert the entities into the PriorityQueue through the proper method.
        for entity in dEntities.values():

            self._Add_Entity(entity)

        

    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."""


        print "%s:%sEntity is being added into the PriorityQueue"%(entity._Get_Type(), entity._Get_Name())


        self._pqEntities._Add_Entity(entity)

        if entity._Get_All_Components("CBODY") != []:
            #The ENtity must first be flagged so that its render updates
            #   take care of the continuously moving collision shapes.
            entity._Set_Collidable(True)

            #This is a 2d array that holds shapes for each body inside of an entity
            shapesOfBodies = []

            #This holds the bodies for the shapes of the same index in shapesOfBodies
            bodies = []

            #Iterate through all of the shapes within an entity.
            for shape in entity._Get_All_Components("CBODY"):
                newBody = -1

                #This iterates through the previous bodies
                for shapeIndx in xrange(len(shapesOfBodies)):

                    #Check to see if this shape has the same body
                    if (bodies[shapeIndx] == shape._Get_Body()):
                        newBody = shapeIndx

                if (newBody == -1):
                    #Create a new list for the body that was found
                    shapesOfBodies.append([shape._Get_Shapes()])
                    #And add the new body
                    bodies.append(shape._Get_Body())

                else:
                    #Add to a existing bodies' list of shapes.
                    shapesOfBodies[shapeIndx].append(shape._Get_Shapes())

            cSpace = self._Get_Component("CSPACE:EntityPool")
                    
            #Now we need to add the bodies along with their shapes into the collision space.
            for bodyIndx in xrange(len(bodies)):
                cSpace._Add_Shape(bodies[bodyIndx], shapesOfBodies[bodyIndx])

            #print "About to add entity's constraints to the space."

            #Now that we've added the CBODY's into the CSPACE, we need to add CCONSTRAINTS as well.
            #   Then those components can be removed from the entity as they are unneeded thereafter.
            for constraintComponent in entity._Get_All_Components("CCONSTRAINT"):

                print "This should be a constraint that is being added to the cSpace:", constraintComponent._Get_Constraint()
                cSpace._Add_Constraint(constraintComponent._Get_Constraint())

                #entity._Remove_Component(constraintComponent._Get_Name())
                
        else:
                entity._Set_Collidable(False)

    def _Remove_Entity(self, sEntityTypeName, sEntityName):
        """When an entity expires it will be removed with this."""

        #Entities that aren't within the priority queue will be ignored.
        self._pqDrawableEntities._Remove_Entity(sEntityTypeName, sEntityName)
#.........这里部分代码省略.........
开发者ID:WaffleTime,项目名称:TileGame,代码行数:103,代码来源:Entity_PQueue.py


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