Changeset 91
- Timestamp:
- 10/05/08 21:04:58 (1 month ago)
- Files:
-
- trunk/bin/yage3d.exe (modified) (previous)
- trunk/src/demo1/gameobj.d (modified) (1 diff)
- trunk/src/demo1/main.d (modified) (3 diffs)
- trunk/src/demo1/ship.d (modified) (1 diff)
- trunk/src/demo2/main.d (modified) (1 diff)
- trunk/src/yage/core/tree.d (modified) (3 diffs)
- trunk/src/yage/scene/movable.d (modified) (1 diff)
- trunk/src/yage/scene/node.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/demo1/gameobj.d
r90 r91 1 1 /** 2 * Copyright: none2 * Copyright: Public Domain 3 3 * Authors: Eric Poggel 4 * License: Public Domain4 * Warranty: none 5 5 * 6 6 * This module is not technically part of the engine, but merely uses it. trunk/src/demo1/main.d
r90 r91 1 1 /** 2 * Copyright: none2 * Copyright: Public Domain 3 3 * Authors: Eric Poggel 4 * License: Public Domain4 * Warranty: none 5 5 * 6 6 * This module is not technically part of the engine, but merely uses it. 7 * This is a demo to show off some of the cool features of Yage. 7 8 */ 8 9 … … 27 28 //Device.init(1024, 768, 32, true); 28 29 //Device.init(1440, 900, 32, true); 30 31 /* 32 // test 33 auto t = new MovableNode(); 34 t.setPosition(Vec3f(0, 1, 0)); 35 auto r = t.addChild(new MovableNode()); 36 r.setPosition(Vec3f(0, 2, 0)); 37 writefln(r.getAbsolutePosition()); 38 return 1; 39 */ 29 40 30 41 // Paths … … 91 102 window.onMouseOver = &onMouseOver; 92 103 window.onMouseOut = &onMouseOut; 93 104 94 105 // Events for main surface. 95 106 view.onKeyDown = delegate void (Surface self, int key, int modifier){ trunk/src/demo1/ship.d
r90 r91 1 1 /** 2 * Copyright: none2 * Copyright: Public Domain 3 3 * Authors: Eric Poggel 4 * License: Public Domain4 * Warranty: none 5 5 * 6 6 * This module is not technically part of the engine, but merely uses it. trunk/src/demo2/main.d
r90 r91 1 1 /** 2 * Copyright: none2 * Copyright: Public Domain 3 3 * Authors: Eric Poggel 4 * License: Public Domain4 * Warranty: none 5 5 * 6 6 * This module is not technically part of the engine, but merely uses it. trunk/src/yage/core/tree.d
r90 r91 16 16 * class Node : Tree!(Node) {} 17 17 * auto n = new Node(); 18 * n.addChild(new Node());18 * auto n2 = n.addChild(new Node()); 19 19 * -------------------------------- 20 20 */ … … 29 29 * Automatically detaches it from any other element's children. 30 30 * Params: 31 * child = 32 * Returns: A reference to the child. 33 */ 31 * child = Node to add as a child of this element. 32 * Returns: A reference to the child. */ 34 33 S addChild(S : T)(S child) 35 34 in { … … 74 73 } 75 74 75 S removeChild(S : T)(S child) 76 { if (child.index > 0) 77 { //yage.core.all.remove(parent.children, index, false); 78 children.remove(index, false); 79 if (index < parent.children.length) 80 parent.children[index].index = index; 81 child.index = -1; // so remove can't be called twice. 82 child.parent = null; 83 } 84 return child; 85 } 86 76 87 /// Remove this element from its parent. 77 88 /// TODO: replace with removeChild trunk/src/yage/scene/movable.d
r90 r91 82 82 return cache[scene.transform_read].transform_abs; 83 83 if (transform_dirty) 84 calcTransform(); 84 { calcTransform(); 85 } 85 86 return transform_abs; 86 87 } trunk/src/yage/scene/node.d
r90 r91 99 99 100 100 merge(child); 101 auto old_parent = child.getParent(); 101 102 super.addChild(child); 102 103 setTransformDirty(); // seems like this should be child.setTransformDirty(), but that breaks things. 104 child.parentChange(old_parent); 103 105 return child; 104 106 } … … 166 168 167 169 168 169 170 170 /// Get the Scene at the top of the tree that this node belongs to, or null if this is part of a sceneless node tree. 171 171 Scene getScene() … … 266 266 protected void calcTransform() 267 267 { 268 // Errors occur here 269 // could this function be called by two different threads on the same Node? 270 // and then the path gets messed up? 271 Node path[16384] = void; // surely no one will have a scene graph deeper than this! 272 Node node = this; 273 274 // build a path up to the first node that does not have transform_dirty set. 275 int i=0; 276 synchronized(this) // section references the node's parent, which could be changed by another thread. 277 { do 278 { path[i] = node; 279 i++; 280 // If parent isn't a Scene 281 if (cast(Node)node.parent) 282 node = cast(Node)node.parent; 283 else break; 284 }while (node.parent !is null && node.transform_dirty) 285 286 // Follow back down that path calculating absolute matrices. 287 foreach_reverse(Node n; path[0..i]) 288 { // If parent isn't a Scene 289 if (cast(Node)n.parent) 290 n.transform_abs = n.transform * (cast(Node)n.parent).transform_abs; 291 else // since scene's don't have a transform matrix 292 n.transform_abs = n.transform; 293 n.transform_dirty = false; 294 } 295 } 268 if (transform_dirty) 269 { synchronized(this) 270 { if (parent) 271 { synchronized(this.parent) 272 { parent.calcTransform(); 273 transform_abs = transform * parent.transform_abs; 274 transform_dirty = false; 275 } } 276 else 277 transform_abs = transform; 278 } } 279 } 280 281 /* 282 * Called after a node's parent changes. */ 283 protected void parentChange(Node old_parent) 284 { 285 296 286 } 297 287 }
