void AnimationTarget::cloneInto(AnimationTarget* target, NodeCloneContext &context) const { if (_animationChannels) { for (std::vector<Animation::Channel*>::const_iterator it = _animationChannels->begin(); it != _animationChannels->end(); ++it) { Animation::Channel* channel = *it; GP_ASSERT(channel); GP_ASSERT(channel->_animation); Animation* animation = context.findClonedAnimation(channel->_animation); if (animation != NULL) { Animation::Channel* channelCopy = new Animation::Channel(*channel, animation, target); animation->addChannel(channelCopy); } else { // Clone the animation and register it with the context so that it only gets cloned once. animation = channel->_animation->clone(channel, target); context.registerClonedAnimation(channel->_animation, animation); } } } }
int lua_NodeCloneContext_findClonedAnimation(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA) && (lua_type(state, 2) == LUA_TUSERDATA || lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TNIL)) { // Get parameter 1 off the stack. bool param1Valid; gameplay::ScriptUtil::LuaArray<Animation> param1 = gameplay::ScriptUtil::getObjectPointer<Animation>(2, "Animation", false, ¶m1Valid); if (!param1Valid) { lua_pushstring(state, "Failed to convert parameter 1 to type 'Animation'."); lua_error(state); } NodeCloneContext* instance = getInstance(state); void* returnPtr = (void*)instance->findClonedAnimation(param1); if (returnPtr) { gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject)); object->instance = returnPtr; object->owns = false; luaL_getmetatable(state, "Animation"); lua_setmetatable(state, -2); } else { lua_pushnil(state); } return 1; } lua_pushstring(state, "lua_NodeCloneContext_findClonedAnimation - Failed to match the given parameters to a valid function signature."); lua_error(state); break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; }