/*---------------------------------------------------------------------------* Project: NintendoWare File: gfx_HemiSphereLight.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Revision: 29649 $ *---------------------------------------------------------------------------*/ #include "precompiled.h" #include #include #include #include namespace nw { namespace gfx { NW_UT_RUNTIME_TYPEINFO_DEFINITION(HemiSphereLight, Light); //---------------------------------------- HemiSphereLight* HemiSphereLight::DynamicBuilder::Create( os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); // CreateResHemiSphereLight で名前を指定するようにしたら // GetMemorySize も修正する必要がある。 ResPtr resource( CreateResHemiSphereLight(allocator), ResHemiSphereLightDataDestroyer(allocator)); void* memory = allocator->Alloc(sizeof(HemiSphereLight)); NW_NULL_ASSERT(memory); HemiSphereLight* light = new(memory) HemiSphereLight( allocator, resource, m_Description); Result result = light->Initialize(allocator); NW_ASSERT(result.IsSuccess()); return light; } //---------------------------------------------------------- size_t HemiSphereLight::DynamicBuilder::GetMemorySize( size_t alignment ) const { NW_ASSERT(this->m_Description.isFixedSizeMemory); os::MemorySizeCalculator size(alignment); // HemiSphereLight::CreateResHemiSphereLight size += sizeof(ResHemiSphereLightData); size += sizeof(HemiSphereLight); // HemiSphereLight::Initialize TransformNode::GetMemorySizeForInitialize( &size, ResTransformNode(), m_Description); // HemiSphereLight::CreateOriginalValue size += sizeof(ResHemiSphereLightData); // Light::CreateAnimGroup // DynamicBuilder 使用時には何も行なわれない。 return size.GetSizeWithPadding(alignment); } //---------------------------------------- HemiSphereLight* HemiSphereLight::Create( SceneNode* parent, ResSceneObject resource, const HemiSphereLight::Description& description, os::IAllocator* allocator ) { NW_NULL_ASSERT(allocator); ResHemiSphereLight resNode = ResDynamicCast(resource); NW_ASSERT(resNode.IsValid()); NW_ASSERT( internal::ResCheckRevision( resNode ) ); void* memory = allocator->Alloc(sizeof(HemiSphereLight)); NW_NULL_ASSERT(memory); HemiSphereLight* light = new(memory) HemiSphereLight( 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 HemiSphereLight::Accept( ISceneVisitor* visitor ) { visitor->VisitHemiSphereLight(this); AcceptChildren(visitor); } //----------------------------------------- /* static*/ ResHemiSphereLightData* HemiSphereLight::CreateResHemiSphereLight(os::IAllocator* allocator, const char* name /* = NULL */) { // TODO: 細かくアロケートする実装になっているが、まとめて確保できる仕組みも追加予定。 ResHemiSphereLightData* resHemiSphereLight = AllocateAndFillN(allocator, sizeof(ResHemiSphereLightData), 0); //-------------------------------- // ResSceneObjectData のメンバ初期化 resHemiSphereLight->typeInfo = ResHemiSphereLight::TYPE_INFO; resHemiSphereLight->m_Header.revision = ResLight::BINARY_REVISION; resHemiSphereLight->m_Header.signature = ResLight::SIGNATURE; resHemiSphereLight->m_UserDataDicCount = 0; resHemiSphereLight->toUserDataDic.set_ptr( NULL ); resHemiSphereLight->toName.set_ptr(AllocateAndCopyString(name, allocator, MAX_NAME_LENGTH)); //-------------------------------- // ResSceneNodeData のメンバ初期化 resHemiSphereLight->m_ChildrenTableCount = 0; resHemiSphereLight->toChildrenTable.set_ptr( NULL ); resHemiSphereLight->m_AnimGroupsDicCount = 0; resHemiSphereLight->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); resHemiSphereLight->m_Transform = math::Transform3(scale, rotate, translate); resHemiSphereLight->m_WorldMatrix = math::MTX34::Identity(); ResTransformNode(resHemiSphereLight).SetBranchVisible(true); return resHemiSphereLight; } //----------------------------------------- /* static */ void HemiSphereLight::DestroyResHemiSphereLight(os::IAllocator* allocator, ResHemiSphereLightData* resHemiSphereLight) { NW_NULL_ASSERT( allocator ); NW_NULL_ASSERT( resHemiSphereLight ); if ( resHemiSphereLight->toName.to_ptr() != NULL ) { allocator->Free( const_cast( resHemiSphereLight->toName.to_ptr() ) ); } allocator->Free( resHemiSphereLight ); } //----------------------------------------- Result HemiSphereLight::CreateOriginalValue(os::IAllocator* allocator) { Result result = INITIALIZE_RESULT_OK; void* buffer = allocator->Alloc(sizeof(ResHemiSphereLightData)); NW_NULL_ASSERT(buffer); // リソースをコピー ResHemiSphereLightData* originalValue = new(buffer) ResHemiSphereLightData(GetResHemiSphereLight().ref()); m_OriginalValue = ResHemiSphereLight(originalValue); m_OriginalTransform = this->GetResTransformNode().GetTransform(); return result; } //---------------------------------------- Result HemiSphereLight::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 HemiSphereLight::GetMemorySizeInternal( os::MemorySizeCalculator* pSize, ResHemiSphereLight resHemiSphereLight, Description description ) { NW_ASSERT(description.isFixedSizeMemory); os::MemorySizeCalculator& size = *pSize; size += sizeof(HemiSphereLight); // HemiSphereLight::Initialize TransformNode::GetMemorySizeForInitialize( &size, resHemiSphereLight, description); size += sizeof(ResHemiSphereLightData); if (description.isAnimationEnabled && resHemiSphereLight.GetAnimGroupsCount() > 0) { AnimGroup::Builder() .ResAnimGroup(resHemiSphereLight.GetAnimGroups(0)) .UseOriginalValue(true) .GetMemorySizeInternal(&size); } } } // namespace gfx } // namespace nw