/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_VertexLight.cpp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include #include #if defined(NW_GFX_VERTEX_LIGHT_ENABLED) namespace nw { namespace gfx { NW_UT_RUNTIME_TYPEINFO_DEFINITION(VertexLight, Light); //---------------------------------------- VertexLight* VertexLight::DynamicBuilder::Create( os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); // CreateResVertexLight で名前を指定するようにしたら // GetMemorySize も修正する必要がある。 ResPtr resource( CreateResVertexLight(allocator), ResVertexLightDataDestroyer(allocator)); void* memory = allocator->Alloc(sizeof(VertexLight)); NW_NULL_ASSERT(memory); VertexLight* light = new(memory) VertexLight( allocator, resource, m_Description); Result result = light->Initialize(allocator); NW_ASSERT(result.IsSuccess()); return light; } //---------------------------------------------------------- size_t VertexLight::DynamicBuilder::GetMemorySize( size_t alignment ) const { NW_ASSERT(this->m_Description.isFixedSizeMemory); os::MemorySizeCalculator size(alignment); // VertexLight::CreateResAmbientLight size += sizeof(ResVertexLightData); size += sizeof(VertexLight); // VertexLight::Initialize TransformNode::GetMemorySizeForInitialize( &size, ResTransformNode(), m_Description); // AmbientLight::CreateOriginalValue size += sizeof(ResVertexLightData); // Light::CreateAnimGroup // DynamicBuilder 使用時には何も行なわれない。 return size.GetSizeWithPadding(alignment); } //---------------------------------------- VertexLight* VertexLight::Create( SceneNode* parent, ResSceneObject resource, const VertexLight::Description& description, os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); ResVertexLight resNode = ResDynamicCast(resource); NW_ASSERT(resNode.IsValid()); NW_ASSERT( internal::ResCheckRevision( resNode ) ); void* memory = allocator->Alloc(sizeof(VertexLight)); NW_NULL_ASSERT(memory); VertexLight* light = new(memory) VertexLight( allocator, resNode, description); Result result = light->Initialize(allocator); NW_ASSERT(result.IsSuccess()); if (parent) { bool isAttached = parent->AttachChild(light); NW_ASSERT(isAttached); } return light; } //---------------------------------------- void VertexLight::UpdateDirection() { ResVertexLight resLight = this->GetResVertexLight(); if (ut::CheckFlag(resLight.GetFlags(), ResFragmentLightData::FLAG_IS_INHERITING_DIRECTION_ROTATE)) { this->CalcInheritingDiretion(this->Direction(), resLight.GetDirection()); } else { this->Direction() = resLight.GetDirection(); } } //---------------------------------------- void VertexLight::Accept( ISceneVisitor* visitor ) { visitor->VisitVertexLight(this); AcceptChildren(visitor); } //----------------------------------------- /* static*/ ResVertexLightData* VertexLight::CreateResVertexLight(os::IAllocator* allocator, const char* name /* = NULL */) { const int MAX_NAME_LENGTH = 256; // TODO: 細かくアロケートする実装になっているが、まとめて確保できる仕組みも追加予定。 ResVertexLightData* resVertexLight = AllocateAndFillN(allocator, sizeof(ResVertexLightData), 0); //-------------------------------- // ResSceneObjectData のメンバ初期化 resVertexLight->typeInfo = ResVertexLight::TYPE_INFO; resVertexLight->m_Header.revision = ResLight::BINARY_REVISION; resVertexLight->m_Header.signature = ResLight::SIGNATURE; resVertexLight->m_UserDataDicCount = 0; resVertexLight->toUserDataDic.set_ptr( NULL ); resVertexLight->toName.set_ptr(AllocateAndCopyString(name, allocator, MAX_NAME_LENGTH)); //-------------------------------- // ResSceneNodeData のメンバ初期化 resVertexLight->m_ChildrenTableCount = 0; resVertexLight->toChildrenTable.set_ptr( NULL ); resVertexLight->m_AnimGroupsDicCount = 0; resVertexLight->toAnimGroupsDic.set_ptr( NULL ); //-------------------------------- // ResTransformNode のメンバ初期化 const math::VEC3 scale(1.0f, 1.0f, 1.0f); const math::VEC3 rotate(0.0f, 0.0f, 0.0f); const math::VEC3 translate(0.0f, 0.0f, 0.0f); resVertexLight->m_Transform = math::Transform3(scale, rotate, translate); resVertexLight->m_WorldMatrix = math::MTX34::Identity(); ResTransformNode(resVertexLight).SetBranchVisible(true); return resVertexLight; } //----------------------------------------- /* static */ void VertexLight::DestroyResVertexLight(os::IAllocator* allocator, ResVertexLightData* resVertexLight) { NW_NULL_ASSERT( allocator ); NW_NULL_ASSERT( resVertexLight ); if ( resVertexLight->toName.to_ptr() != NULL ) { allocator->Free( const_cast( resVertexLight->toName.to_ptr() ) ); } allocator->Free( resVertexLight ); } //----------------------------------------- Result VertexLight::CreateOriginalValue(os::IAllocator* allocator) { Result result = INITIALIZE_RESULT_OK; void* buffer = allocator->Alloc(sizeof(ResVertexLightData)); NW_NULL_ASSERT(buffer); // リソースをコピー ResVertexLightData* originalValue = new(buffer) ResVertexLightData(GetResVertexLight().ref()); m_OriginalValue = ResVertexLight(originalValue); m_OriginalTransform = this->GetResTransformNode().GetTransform(); return result; } //---------------------------------------- Result VertexLight::Initialize(os::IAllocator* allocator) { Result result = INITIALIZE_RESULT_OK; result |= TransformNode::Initialize(allocator); NW_ENSURE_AND_RETURN(result); result |= CreateOriginalValue(allocator); NW_ENSURE_AND_RETURN(result); result |= CreateAnimGroup(allocator); NW_ENSURE_AND_RETURN(result); return result; } //---------------------------------------------------------- void VertexLight:: GetMemorySizeInternal( os::MemorySizeCalculator* pSize, ResVertexLight resVertexLight, Description description ) { NW_ASSERT(description.isFixedSizeMemory); os::MemorySizeCalculator& size = *pSize; size += sizeof(VertexLight); // VertexLight::Initialize TransformNode::GetMemorySizeForInitialize( &size, resVertexLight, description); size += sizeof(ResVertexLightData); if (description.isAnimationEnabled && resVertexLight.GetAnimGroupsCount() > 0) { AnimGroup::Builder() .ResAnimGroup(resVertexLight.GetAnimGroups(0)) .UseOriginalValue(true) .GetMemorySizeInternal(&size); } } } // namespace gfx } // namespace nw #endif