/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_AmbientLight.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 namespace nw { namespace gfx { NW_UT_RUNTIME_TYPEINFO_DEFINITION(AmbientLight, Light); //---------------------------------------- AmbientLight* AmbientLight::DynamicBuilder::Create( os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); // CreateResAmbientLight で名前を指定するようにしたら // GetMemorySize も修正する必要がある。 ResPtr resource( CreateResAmbientLight(allocator), ResAmbientLightDataDestroyer(allocator)); void* memory = allocator->Alloc(sizeof(AmbientLight)); NW_NULL_ASSERT(memory); AmbientLight* light = new(memory) AmbientLight( allocator, resource, m_Description); Result result = light->Initialize(allocator); NW_ASSERT(result.IsSuccess()); return light; } //---------------------------------------------------------- size_t AmbientLight::DynamicBuilder::GetMemorySize( size_t alignment ) const { NW_ASSERT(this->m_Description.isFixedSizeMemory); os::MemorySizeCalculator size(alignment); // AmbientLight::CreateResAmbientLight size += sizeof(ResAmbientLightData); size += sizeof(AmbientLight); // AmbientLight::Initialize TransformNode::GetMemorySizeForInitialize( &size, ResTransformNode(), m_Description); // AmbientLight::CreateOriginalValue size += sizeof(ResAmbientLightData); // Light::CreateAnimGroup // DynamicBuilder 使用時には何も行なわれない。 return size.GetSizeWithPadding(alignment); } //---------------------------------------- AmbientLight* AmbientLight::Create( SceneNode* parent, ResSceneObject resource, const AmbientLight::Description& description, os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); ResAmbientLight resNode = ResDynamicCast(resource); NW_ASSERT(resNode.IsValid()); NW_ASSERT( internal::ResCheckRevision( resNode ) ); void* memory = allocator->Alloc(sizeof(AmbientLight)); NW_NULL_ASSERT(memory); AmbientLight* light = new(memory) AmbientLight( 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 AmbientLight::Accept( ISceneVisitor* visitor ) { visitor->VisitAmbientLight(this); AcceptChildren(visitor); } //----------------------------------------- /* static*/ ResAmbientLightData* AmbientLight::CreateResAmbientLight(os::IAllocator* allocator, const char* name /* = NULL */) { // TODO: 細かくアロケートする実装になっているが、まとめて確保できる仕組みも追加予定。 ResAmbientLightData* resAmbientLight = AllocateAndFillN(allocator, sizeof(ResAmbientLightData), 0); //-------------------------------- // ResSceneObjectData のメンバ初期化 resAmbientLight->typeInfo = ResAmbientLight::TYPE_INFO; resAmbientLight->m_Header.revision = ResLight::BINARY_REVISION; resAmbientLight->m_Header.signature = ResLight::SIGNATURE; resAmbientLight->m_UserDataDicCount = 0; resAmbientLight->toUserDataDic.set_ptr( NULL ); //resAmbientLight->toName.set_ptr(CopyString(name, allocator)); resAmbientLight->toName.set_ptr(AllocateAndCopyString(name, allocator, MAX_NAME_LENGTH)); //-------------------------------- // ResSceneNodeData のメンバ初期化 resAmbientLight->m_ChildrenTableCount = 0; resAmbientLight->toChildrenTable.set_ptr( NULL ); resAmbientLight->m_AnimGroupsDicCount = NULL; resAmbientLight->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); resAmbientLight->m_Transform = math::Transform3(scale, rotate, translate); resAmbientLight->m_WorldMatrix = math::MTX34::Identity(); ResTransformNode(resAmbientLight).SetBranchVisible(true); return resAmbientLight; } //----------------------------------------- /* static */ void AmbientLight::DestroyResAmbientLight(os::IAllocator* allocator, ResAmbientLightData* resAmbientLight) { NW_NULL_ASSERT( allocator ); NW_NULL_ASSERT( resAmbientLight ); if ( resAmbientLight->toName.to_ptr() != NULL ) { allocator->Free( const_cast( resAmbientLight->toName.to_ptr() ) ); } allocator->Free( resAmbientLight ); } //----------------------------------------- Result AmbientLight::CreateOriginalValue(os::IAllocator* allocator) { Result result = INITIALIZE_RESULT_OK; void* buffer = allocator->Alloc(sizeof(ResAmbientLightData)); NW_NULL_ASSERT(buffer); // リソースをコピー ResAmbientLightData* originalValue = new(buffer) ResAmbientLightData(GetResAmbientLight().ref()); m_OriginalValue = ResAmbientLight(originalValue); m_OriginalTransform = this->GetResTransformNode().GetTransform(); return result; } //---------------------------------------- Result AmbientLight::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 AmbientLight::GetMemorySizeInternal( os::MemorySizeCalculator* pSize, ResAmbientLight resAmbientLight, Description description ) { NW_ASSERT(description.isFixedSizeMemory); os::MemorySizeCalculator& size = *pSize; size += sizeof(AmbientLight); // AmbientLight::Initialize TransformNode::GetMemorySizeForInitialize( &size, resAmbientLight, description); size += sizeof(ResAmbientLightData); if (description.isAnimationEnabled && resAmbientLight.GetAnimGroupsCount() > 0) { AnimGroup::Builder() .ResAnimGroup(resAmbientLight.GetAnimGroups(0)) .UseOriginalValue(true) .GetMemorySizeInternal(&size); } } } // namespace gfx } // namespace nw