1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_AnimSoundFileReader.cpp
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: $
16  *---------------------------------------------------------------------------*/
17 
18 #include "precompiled.h"
19 
20 #include <nw/ut/ut_BinaryFileFormat.h>
21 #include <nw/snd/snd_AnimSoundFileReader.h>
22 
23 namespace nw {
24 namespace snd {
25 namespace internal {
26 
27 
28 namespace {
29 
30 const u32 SIGNATURE_FILE       = NW_UT_MAKE_SIGWORD( 'C', 'A', 'S', 'D' );
31 const u32 SIGNATURE_DATA_BLOCK = NW_UT_MAKE_SIGWORD( 'D', 'A', 'T', 'A' );
32 
33 const u32 SUPPORTED_FILE_VERSION = 0x01000000;  // サポートする最低バージョン
34 const u32 CURRENT_FILE_VERSION   = 0x01000000;  // サポートする最新バージョン
35 
IsValidFileHeader(const void * bcasdFile)36 bool IsValidFileHeader( const void* bcasdFile )
37 {
38     const ut::BinaryFileHeader& header =
39         *reinterpret_cast<const ut::BinaryFileHeader*>( bcasdFile );
40 
41     // シグニチャ確認
42     NW_ASSERTMSG( header.signature == SIGNATURE_FILE, "invalid file signature." );
43     if ( header.signature != SIGNATURE_FILE )
44     {
45         return false;
46     }
47 
48     // バージョン確認
49     NW_ASSERTMSG(
50             header.version >= SUPPORTED_FILE_VERSION,
51             "bcasd file is not supported version.\n"
52             "please reconvert file using new version tools.\n"
53             "(SUPPORTED_FILE_VERSION:0x%08x >= your version:0x%08x)\n",
54             SUPPORTED_FILE_VERSION, header.version
55     );
56     if ( header.version < SUPPORTED_FILE_VERSION )
57     {
58         return false;
59     }
60     NW_ASSERTMSG(
61             header.version <= CURRENT_FILE_VERSION,
62             "bcasd file is not supported version.\n"
63             "please reconvert file using new version tools.\n"
64             "(CURRENT_FILE_VERSION:0x%08x <= your version:0x%08x)\n",
65             CURRENT_FILE_VERSION, header.version
66     );
67     if ( header.version > CURRENT_FILE_VERSION )
68     {
69         return false;
70     }
71     return true;
72 }
73 
74 } // anonymous namespace
75 
AnimSoundFileReader()76 AnimSoundFileReader::AnimSoundFileReader()
77 : m_pAnimEventTable( NULL ),
78   m_FrameSize( 0 )
79 {}
80 
Initialize(const void * bcasdFile)81 bool AnimSoundFileReader::Initialize( const void* bcasdFile )
82 {
83     if ( ! IsValidFileHeader( bcasdFile ) )
84     {
85         return false;
86     }
87 
88     const AnimSoundFile::FileHeader* header =
89         reinterpret_cast<const AnimSoundFile::FileHeader*>( bcasdFile );
90 
91     const AnimSoundFile::DataBlockBody* body = &header->GetDataBlock()->body;
92     NW_NULL_ASSERT( body );
93 
94     if ( ! body )
95     {
96         return false;
97     }
98 
99     const AnimSoundFile::AnimEventTable* table = body->GetAnimEventTable();
100     NW_NULL_ASSERT( table );
101     if ( ! table )
102     {
103         return false;
104     }
105 
106     m_pAnimEventTable = table;
107     m_FrameSize = body->frameSize;
108     return true;
109 }
110 
Finalize()111 void AnimSoundFileReader::Finalize()
112 {
113     m_pAnimEventTable = NULL;
114     m_FrameSize = 0;
115 }
116 
117 
118 } // namespace nw::snd::internal
119 } // namespace nw::snd
120 } // namespace nw
121 
122