Game Development Community

iT2D 1.4 Release - Mount Broken During Copy Paste - RESOLVED

by Mark Grossnickle · in iTorque 2D · 03/29/2011 (10:55 am) · 5 replies

Build: 1.4 Release

Platform: OS 10.6.6

Target: Editor

Issues: Copy and Pasting mounted objects has unexpected results.

Steps to Repeat
Example 1 (Grouping):
1. Open any project (or create a new one) in the TGB editor.
2. Add 2 visual assets to the scene. In my case I am using a body image and a head image.
3. Mount one asset to the other. In my case I am mounting the head to the body.
4. Group the two.
5. Select the group in the Object tree.
6. Copy!
7. Move the 1st group out of the way.
8. Paste!
9. A new group appears, but notice how the head of the 1st group is now mounted to the body of the second group. The mount is crossed.

Note A. If you save and reload after #7, before pasting, the paste will work w/out losing anyone's head.
Note B. You can skip #7 and not move the object out of the way and just paste on top. Same Results, just harder to tell until you move them afterwards.

Example 2 (Multi-Select):
1. Repeat steps 1-3 from Example 1.
2. Select both the head and the body (But do NOT group them).
3. Copy!
4. Paste!
5. Move your newly pasted objects to the side. Looks good so far!
6. Grab the Body and ONLY the body. Move it!
7. Notice that the head is not attached to the body and stays behind. The mount is lost.

Example 3 (Single-Select):
1. Repeat steps 1-3 from Example 1.
2. Select just the body.
3. Copy!
4. Paste!
5. Only the body will paste. This could be the expected result for some, but personally I would expect the head to come with it.



Suggested Fixes:
Partial Fix for Example 2 and 3. I modified the copy procedure to check for mounts and ensure that all mounted objects are saved and the MountID and MountToIDs are assigned. This only gets us halfway though, as pasting still breaks exactly the same way as Example 1 - Cross Mounting!

Fix For Example 1. None... yet.

I am going to work on this today, but would like more eyes on the code so I don't break legacy logic. The problem occurs in the following code when linkPoints are added during addToScene of pasted objects:

// Link points are now being reference counted as well so as to match the functionality of  
   // mount nodes. This is necessary for proper working with level loading. ADL.  
  
   // Check if the node exists.  
   for ( U32 nodeIndex = 0; nodeIndex < mMountNodes.size(); nodeIndex++ )  
   {  
      // Fetch Node Reference.  
      tMountNode& mountNode = mMountNodes[nodeIndex];  
  
      // Yes, so does this nodes' local mount position match?  
      if ( mountNode.mLocalMountPosition.isEqual(nodeOffset) )  
      {  
         // Yes, so increase reference count.  
         mountNode.mMountReferenceCount++;   
  
         // Return Node Index.  
         return mountNode.mMountID;  
      }  
   }

Basically, when objects are added to the scene it is looking for LinkPoint locations and checking if a location already exists. If it does, it gives the item the existing mountID which causes all subsequent 'heads' to be mounted to 1 body.

About to look into this more but would love some feedback on this bug.
- Is there already a solution for copy/paste of mounted objects?
- Would you expect mounting to be maintained in all 3 examples laid out above?

#1
03/29/2011 (11:08 am)
Blows the detail of my bug reports out of the water =P
#2
03/29/2011 (12:33 pm)
Logged as ITGB-147.
#3
03/29/2011 (1:32 pm)
Correction... The code I listed above should not be causing the problem. I'll update once I can narrow this down a bit more as I understand it (seriously, 10,000+ lines of code for t2dSceneObject? crazy!). But just wanted to post a heads up now to prevent sending anyone on a wild goose chase, if I haven't already.
#4
03/30/2011 (12:12 pm)
Created a fix and posted the steps I took. Feel free to check out the resource here:

www.garagegames.com/community/resources/view/20931
#5
09/27/2011 (7:25 pm)
Fixed in 1.5.

Note that due to how the engine creates object and handles the bin sorting you can occassionally end up with the rendering order of the objects reversed if both are on the same layer. If they are on different layers then everything is fine 100% of the time.