浏览代码

*** empty log message ***

Joe Shochet 25 年之前
父节点
当前提交
c13b89fe87
共有 3 个文件被更改,包括 119 次插入20 次删除
  1. 9 4
      direct/src/fsm/FSM.py
  2. 10 2
      direct/src/fsm/State.py
  3. 100 14
      direct/src/leveleditor/LevelEditor.py

+ 9 - 4
direct/src/fsm/FSM.py

@@ -35,10 +35,9 @@ class FSM(DirectObject):
         # Flag to see if we are inspecting
         # Flag to see if we are inspecting
         self.inspecting = 0
         self.inspecting = 0
 
 
-        # Enter the initial state.
-        # It is assumed that the initial state takes no arguments.
-        self.__currentState = self.__initialState
-        #self.__enter(self.__initialState)
+        # We do not enter the initial state to separate
+        # construction from activation
+        self.__currentState = None
         return None
         return None
 
 
     # I know this isn't how __repr__ is supposed to be used, but it
     # I know this isn't how __repr__ is supposed to be used, but it
@@ -169,6 +168,12 @@ class FSM(DirectObject):
         false otherwise. 
         false otherwise. 
         """
         """
 
 
+        if not self.__currentState:
+            # Make this a warning for now
+            FSM.notify.warning("[%s]: request: never entered initial state" %
+                               (self.__name))
+            self.__currentState = self.__initialState
+
         if isinstance(aStateName, types.StringType):
         if isinstance(aStateName, types.StringType):
             aState = self.getStateNamed(aStateName)
             aState = self.getStateNamed(aStateName)
         else:
         else:

+ 10 - 2
direct/src/fsm/State.py

@@ -188,8 +188,16 @@ class State(DirectObject):
         Enter all child FSMs"""
         Enter all child FSMs"""
         if self.hasChildren():
         if self.hasChildren():
             for fsm in self.__FSMList:
             for fsm in self.__FSMList:
-                fsm.request((fsm.getInitialState()).getName())
-
+                # Check to see if the child fsm is already in a state
+                # if it is, politely request the initial state
+                if fsm.getCurrentState():
+                    fsm.request((fsm.getInitialState()).getName())
+                # If it has no current state, I assume this means it
+                # has never entered the initial state, so enter it
+                # explicitly
+                else:
+                    fsm.enterInitialState()
+                    
     def __exitChildren(self, argList):
     def __exitChildren(self, argList):
         """__exitChildren(self, argList)
         """__exitChildren(self, argList)
         Exit all child FSMs"""
         Exit all child FSMs"""

+ 100 - 14
direct/src/leveleditor/LevelEditor.py

@@ -15,7 +15,8 @@ if sys.argv[1:]:
 # If you do not run from the command line, we just load all of them
 # If you do not run from the command line, we just load all of them
 # or you can hack this up for your own purposes.
 # or you can hack this up for your own purposes.
 else:
 else:
-    hoods = ['TT', 'DD', 'BR', 'DG', 'DL', 'MM']
+    # hoods = ['TT', 'DD', 'BR', 'DG', 'DL', 'MM']
+    hoods = ['BR' ]
 
 
 print "Loading LevelEditor for hoods: ", hoods
 print "Loading LevelEditor for hoods: ", hoods
 
 
@@ -406,6 +407,7 @@ class LevelEditor(NodePath, PandaObject):
         # Used to store whatever edges and points are loaded in the level
         # Used to store whatever edges and points are loaded in the level
         self.edgeDict = {}
         self.edgeDict = {}
         self.pointDict = {}
         self.pointDict = {}
+        self.point2edgeDict = {}
         self.cellDict = {}
         self.cellDict = {}
         
         
         # Initialize LevelEditor variables DNAData, DNAToplevel, NPToplevel
         # Initialize LevelEditor variables DNAData, DNAToplevel, NPToplevel
@@ -489,7 +491,7 @@ class LevelEditor(NodePath, PandaObject):
                                            'y-ring', 'y-disc',
                                            'y-ring', 'y-disc',
                                            'z-post'])
                                            'z-post'])
         # Initialize camera
         # Initialize camera
-        base.cam.node().setNear(5.0)
+        base.cam.node().setNear(1.0)
         base.cam.node().setFar(3000)
         base.cam.node().setFar(3000)
         direct.camera.setPos(0,-10,10)
         direct.camera.setPos(0,-10,10)
         # Hide (disable) grid initially
         # Hide (disable) grid initially
@@ -555,6 +557,11 @@ class LevelEditor(NodePath, PandaObject):
         Reset level and re-initialize main class variables
         Reset level and re-initialize main class variables
         Pass in the new top level group
         Pass in the new top level group
         """
         """
+        # Reset path markers
+        self.resetPathMarkers()
+        # Reset battle cell markers
+        self.resetBattleCellMarkers()
+
         if fDeleteToplevel:
         if fDeleteToplevel:
             # First destroy existing scene-graph/DNA hierarchy
             # First destroy existing scene-graph/DNA hierarchy
             self.deleteToplevel()
             self.deleteToplevel()
@@ -596,10 +603,6 @@ class LevelEditor(NodePath, PandaObject):
         self.snapList = []
         self.snapList = []
         # Last menu used
         # Last menu used
         self.activeMenu = None
         self.activeMenu = None
-        # Reset path markers
-        self.resetPathMarkers()
-        # Reset battle cell markers
-        self.resetBattleCellMarkers()
 
 
     def deleteToplevel(self):
     def deleteToplevel(self):
         # Destory old toplevel node path and DNA
         # Destory old toplevel node path and DNA
@@ -830,6 +833,31 @@ class LevelEditor(NodePath, PandaObject):
                         self.setLastAngle(h)
                         self.setLastAngle(h)
                     # Update DNA
                     # Update DNA
                     self.updatePose(dnaObject, selectedNode)
                     self.updatePose(dnaObject, selectedNode)
+            else:
+                possiblePoint = self.findSuitPointMarker(selectedNode)
+                if possiblePoint:
+                    point = self.getSuitPointFromNodePath(possiblePoint)
+                    if point:
+                        print "Found suit point!", point
+                        # First snap selected node path to grid
+                        pos = selectedNode.getPos(direct.grid)
+                        snapPos = direct.grid.computeSnapPoint(pos)
+                        if self.panel.fPlaneSnap.get():
+                            zheight = 0
+                        else:
+                            zheight = snapPos[2]
+                        selectedNode.setPos(direct.grid,
+                                            snapPos[0], snapPos[1], zheight)
+                        newPos = selectedNode.getPos(self.NPToplevel)
+                        point.setPos(newPos)
+                        # Ok, now update all the lines into that node
+                        for edge in self.point2edgeDict[point]:
+                            oldEdgeLine = self.edgeDict[edge]
+                            del self.edgeDict[edge]
+                            oldEdgeLine.reset()
+                            del oldEdgeLine
+                            newEdgeLine = self.drawSuitEdge(edge, self.NPParent)
+                            self.edgeDict[edge] = newEdgeLine
 
 
     def updatePose(self, dnaObject, nodePath):
     def updatePose(self, dnaObject, nodePath):
         """
         """
@@ -1499,7 +1527,15 @@ class LevelEditor(NodePath, PandaObject):
             if DNAClassEqual(dnaNode, DNA_STREET):
             if DNAClassEqual(dnaNode, DNA_STREET):
                 self.snapList = OBJECT_SNAP_POINTS[dnaNode.getCode()]
                 self.snapList = OBJECT_SNAP_POINTS[dnaNode.getCode()]
         else:
         else:
-            pass
+            possiblePoint = self.findSuitPointMarker(nodePath)
+            if possiblePoint:
+                point = self.getSuitPointFromNodePath(possiblePoint)
+                if point:
+                    print "Found suit point!", point
+                else:
+                    pass
+            else:
+                pass
         # Let others know that something new may be selected:
         # Let others know that something new may be selected:
         for i in self.selectedNodePathHookHooks:
         for i in self.selectedNodePathHookHooks:
                 i()
                 i()
@@ -1540,6 +1576,22 @@ class LevelEditor(NodePath, PandaObject):
                 # Try parent
                 # Try parent
                 return self.findDNARoot(nodePath.getParent())
                 return self.findDNARoot(nodePath.getParent())
 
 
+
+    def findSuitPointMarker(self, nodePath):
+        """ Walk up a node path's ancestry looking for its DNA Root """
+        # Check current node's name for root marker
+        if (nodePath.getName() == 'suitPointMarker'):
+            # Its a root!
+            return nodePath
+        else:
+            # If reached the top: fail
+            if not nodePath.hasParent():
+                return None
+            else:
+                # Try parent
+                return self.findSuitPointMarker(nodePath.getParent())
+
+
     # MANIPULATION FUNCTIONS
     # MANIPULATION FUNCTIONS
     def keyboardRotateSelected(self, arrowDirection):
     def keyboardRotateSelected(self, arrowDirection):
         """ Rotate selected objects using arrow keys """
         """ Rotate selected objects using arrow keys """
@@ -1893,7 +1945,8 @@ class LevelEditor(NodePath, PandaObject):
         # Reset level, destroying existing scene/DNA hierarcy
         # Reset level, destroying existing scene/DNA hierarcy
         self.reset(fDeleteToplevel = 1, fCreateToplevel = 0)
         self.reset(fDeleteToplevel = 1, fCreateToplevel = 0)
         # Now load in new file
         # Now load in new file
-        newNPToplevel = loadDNAFile(DNASTORE, filename, CSDefault, 1)
+        node = loadDNAFile(DNASTORE, filename, CSDefault, 1)
+        newNPToplevel = hidden.attachNewNode(node)
         # Make sure the topmost file DNA object gets put under DNARoot
         # Make sure the topmost file DNA object gets put under DNARoot
         newDNAToplevel = self.findDNANode(newNPToplevel)
         newDNAToplevel = self.findDNANode(newNPToplevel)
         
         
@@ -2066,7 +2119,7 @@ class LevelEditor(NodePath, PandaObject):
             self.outputDir = 'DonaldsDock'
             self.outputDir = 'DonaldsDock'
         elif neighborhood == 'minnies_melody_land':
         elif neighborhood == 'minnies_melody_land':
             self.outputDir = 'MinniesMelodyLand'
             self.outputDir = 'MinniesMelodyLand'
-        elif neighborhood == 'the_burrgh':
+        elif neighborhood == 'the_burrrgh':
             self.outputDir = 'TheBurrrgh'
             self.outputDir = 'TheBurrrgh'
         elif neighborhood == 'daisys_garden':
         elif neighborhood == 'daisys_garden':
             self.outputDir = 'DaisysGarden'
             self.outputDir = 'DaisysGarden'
@@ -2169,7 +2222,8 @@ class LevelEditor(NodePath, PandaObject):
         return edgeLine
         return edgeLine
 
 
     def drawSuitPoint(self, pos, type, parent):
     def drawSuitPoint(self, pos, type, parent):
-        marker = self.suitPointMarker.instanceTo(parent)
+        marker = self.suitPointMarker.copyTo(parent)
+        marker.setName("suitPointMarker")
         marker.setPos(pos)
         marker.setPos(pos)
         if (type == DNASuitPoint.STREETPOINT):
         if (type == DNASuitPoint.STREETPOINT):
             marker.setColor(0,0,0.6)
             marker.setColor(0,0,0.6)
@@ -2210,6 +2264,14 @@ class LevelEditor(NodePath, PandaObject):
                 edgeLine = self.drawSuitEdge(suitEdge, self.NPParent)
                 edgeLine = self.drawSuitEdge(suitEdge, self.NPParent)
                 # Store the line in a dict so we can hide/show them
                 # Store the line in a dict so we can hide/show them
                 self.edgeDict[suitEdge] = edgeLine
                 self.edgeDict[suitEdge] = edgeLine
+                # Store the edge on each point in case we move the point
+                # we can update the edge
+                for point in [self.startSuitPoint, self.endSuitPoint]:
+                    if self.point2edgeDict.has_key(point):
+                        self.point2edgeDict[point].append(suitEdge)
+                    else:
+                        self.point2edgeDict[point] = [suitEdge]
+                
                 print 'Added dnaSuitEdge to zone: ' + zoneId
                 print 'Added dnaSuitEdge to zone: ' + zoneId
             else:
             else:
                 print 'Error: DNAParent is not a dnaVisGroup. Did not add edge'
                 print 'Error: DNAParent is not a dnaVisGroup. Did not add edge'
@@ -2222,7 +2284,7 @@ class LevelEditor(NodePath, PandaObject):
             self.startSuitPoint = suitPoint
             self.startSuitPoint = suitPoint
 
 
     def drawBattleCell(self, cell, parent):
     def drawBattleCell(self, cell, parent):
-        marker = self.battleCellMarker.instanceTo(parent)
+        marker = self.battleCellMarker.copyTo(parent)
         # Greenish
         # Greenish
         marker.setColor(0.25,0.75,0.25,0.5)
         marker.setColor(0.25,0.75,0.25,0.5)
         marker.setPos(cell.getPos())
         marker.setPos(cell.getPos())
@@ -2276,13 +2338,36 @@ class LevelEditor(NodePath, PandaObject):
                 edge = dnaVisGroup.getSuitEdge(i)
                 edge = dnaVisGroup.getSuitEdge(i)
                 edgeLine = self.drawSuitEdge(edge, np)
                 edgeLine = self.drawSuitEdge(edge, np)
                 self.edgeDict[edge] = edgeLine
                 self.edgeDict[edge] = edgeLine
+                # Store the edge on each point in case we move the point
+                # we can update the edge
+                for point in [edge.getStartPoint(), edge.getEndPoint()]:
+                    if self.point2edgeDict.has_key(point):
+                        self.point2edgeDict[point].append(edge)
+                    else:
+                        self.point2edgeDict[point] = [edge]
+
+
+    def getSuitPointFromNodePath(self, nodePath):
+        """
+        Given a node path, attempt to find the point,nodePath pair
+        in the pointDict. If it is there, return the point. If we
+        cannot find it, return None.
+        TODO: a reverse lookup pointDict would speed this up quite a bit
+        """
+        for point, marker in self.pointDict.items():
+            if marker.eq(nodePath):
+                return point
+        return None
 
 
     def resetPathMarkers(self):
     def resetPathMarkers(self):
         for edge, edgeLine in self.edgeDict.items():
         for edge, edgeLine in self.edgeDict.items():
-            edgeLine.remove()
+            if not edgeLine.isEmpty():
+                edgeLine.reset()
+                edgeLine.removeNode()
         self.edgeDict = {}
         self.edgeDict = {}
         for point, marker in self.pointDict.items():
         for point, marker in self.pointDict.items():
-            marker.remove()
+            if not marker.isEmpty():
+                marker.removeNode()
         self.pointDict = {}
         self.pointDict = {}
                 
                 
     def hideSuitPaths(self):
     def hideSuitPaths(self):
@@ -2311,7 +2396,8 @@ class LevelEditor(NodePath, PandaObject):
 
 
     def resetBattleCellMarkers(self):
     def resetBattleCellMarkers(self):
         for cell, marker in self.cellDict.items():
         for cell, marker in self.cellDict.items():
-            marker.remove()
+            if not marker.isEmpty():
+                marker.remove()
         self.cellDict = {}
         self.cellDict = {}
 
 
     def hideBattleCells(self):
     def hideBattleCells(self):