MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / attachToParent

Method attachToParent

Engine/source/scene/sceneObject.cpp:1926–1982  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1924
1925
1926bool SceneObject::attachToParent(SceneObject *newParent, MatrixF *atThisOffset/* = NULL */, S32 node )
1927{
1928 SceneObject *oldParent = mGraph.parent;
1929
1930 if (oldParent == newParent)
1931 return true;
1932
1933 // cycles in the scene hierarchy are forbidden!
1934 // that is: a SceneObject cannot be a child of its progeny
1935 if (newParent && newParent->isChildOf(this))
1936 return false;
1937
1938 mGraph.parent = newParent;
1939
1940 if (oldParent) {
1941
1942 clearNotify(oldParent);
1943
1944 // remove this SceneObject from the list of children of oldParent
1945 SceneObject *cur = oldParent->mGraph.firstChild;
1946 if (cur == this) { // if we are the first child, this is easy
1947 oldParent->mGraph.firstChild = mGraph.nextSibling;
1948 } else {
1949 while (cur->mGraph.nextSibling != this) {
1950 cur = cur->mGraph.nextSibling;
1951 // ASSERT cur != NULL;
1952 }
1953 cur->mGraph.nextSibling = mGraph.nextSibling;
1954 }
1955 oldParent->onLostChild(this);
1956 }
1957
1958 if (newParent) {
1959
1960 deleteNotify(newParent); // if we are deleted, inform our parent
1961
1962 // add this SceneObject to the list of children of oldParent
1963 mGraph.nextSibling = newParent->mGraph.firstChild;
1964 newParent->mGraph.firstChild = this;
1965 mGraph.parent = newParent;
1966
1967 newParent->onNewChild(this);
1968
1969 if (atThisOffset)
1970 mGraph.objToParent = *atThisOffset;
1971 } else {
1972 mGraph.parent = NULL;
1973 mGraph.nextSibling = NULL;
1974 mGraph.objToParent = mObjToWorld;
1975 }
1976
1977 onLostParent(oldParent);
1978 onNewParent(newParent);
1979
1980 setMaskBits(MountedMask);
1981 return true;
1982}
1983

Callers 6

attachChildAtMethod · 0.80
attachChildMethod · 0.80
sceneObject.cppFile · 0.80
DefineEngineMethodFunction · 0.80
updateAttachmentMethod · 0.80
gameBase.cppFile · 0.80

Calls 3

onLostChildMethod · 0.80
onNewChildMethod · 0.80
isChildOfMethod · 0.45

Tested by

no test coverage detected